function ClosePopUp(srcId) {
    document.getElementById(srcId).style.visibility = "hidden";
}

function getAbsPos(elem) {
    var pos = { x: 0, y: 0 };
    while(elem!=null)
    {
        pos.x += elem.offsetLeft;
        pos.y += elem.offsetTop;
        elem = elem.offsetParent;
    }
    return pos;
}



function DivPlace(imgId, text, srcId) {
    var posParent = getAbsPos(document.getElementById('right_text'));
    var posImage = getAbsPos(imgId);
    var d = document.getElementById(srcId);
    d.style.visibility = 'visible';
    d.style.left = posImage.x - posParent.x;
    d.style.top = posImage.y - posParent.y + 120;
    document.getElementById('spnText').innerHTML = text;
}

function DivPlaceOLD(imgId,text,srcId)
{
    var imgPos;
    if(imgId.offsetParent)
       imgPos =getAbsPos(imgId );
    else
        imgPos=imgId;
    
    document.getElementById(srcId).style.visibility = "visible";
    document.getElementById(srcId).style.top = imgPos.y;
    document.getElementById(srcId).style.left = imgPos.x;

    document.getElementById("spnText").innerHTML =text;
}

function HelpPopUp(id,obj,SrId) 
{
    if (id == 1) 
    {
        DivPlace(obj,"Gross Income: All income before taxes, benefits and other deductions are removed",SrId);
    }
    else if(id==2)
    {
        DivPlace(obj,"Household: Total number of people (adults and children) residing in the home",SrId);
    }
    else if(id==3)
    {
        DivPlace(obj,"Select The County/City Where You Want To Live. Up to 3 Max",SrId);
    }
}

function HelpPopUpEs(id, obj, SrId) {

    if (id == 1) {
        DivPlace(obj, "Ingresos brutos: Son todos los ingresos antes de descontar impuestos, beneficios y otras deducciones", SrId);
    }
    else if (id == 2) {
    DivPlace(obj, "Grupo familiar: La cantidad total de personas (adultos y niņos) que residen en el hogar", SrId);
    }
    else if (id == 3) {
    DivPlace(obj, "Seleccione el condado/la ciudad donde desea vivir. Puede seleccionar hasta tres opciones.", SrId);
    }
}


function CalcValidate()
{
    var IncomeVal=document.getElementById(IncomeId).value;
    var CountyVal=document.getElementById(CountyId).value;
  

    if (IncomeVal=="")
    {
        alert("Please Enter Your Income");
        document.getElementById(IncomeId).focus();
        return false;
    }
    if(IncomeVal!="")
    {
        var IncomePat=/(^-?\d\d*$)/;
        var matchArray = IncomeVal.match(IncomePat);
        if (matchArray == null)
        {
            alert("Please Enter Only Integer Values In Income Field.");
            document.getElementById(IncomeId).focus();
            return false;
        }
    }


    var options = document.getElementById(CountyId).getElementsByTagName('input');
    var ischecked=false;
    var j;
    j=0;
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.type=="checkbox")
        {
            if(opt.checked)
            {
                j=j+1;             
            }
        } 
        
        
        if(j==4)
        {
            alert("You Cannot Select More Than 3 Counties");
            return false;
        }
    }
    if(j==0)
        {
        alert("Please Select the County -Communities");
            return false;
        }

return true;
}



function delConfirm()
{
if(confirm("Are You Sure You Want To Delete The Record:"))
{
return true;
}
return false;

}


function SetSortParam(sort)
{

if(document.getElementById(SortID).value==sort)
document.getElementById(SortCritID).value=Number(!Number(document.getElementById(SortCritID).value));
else
{
document.getElementById(SortCritID).value="1";
document.getElementById(SortID).value=sort;
}
document.forms[0].submit();
}


function winDownload(Id,DName,type)
{
var win=window.open('FileDownload.aspx?Fid='+ Id + '&FName=' + DName + '&Type=' + type);
if(type=="1")
{
document.getElementById(Download).value=Id;
document.forms[0].submit();
}
}