﻿//-------------------------------------------------------------------------------------------------
//Author      : Mauricio Beltran
//Date        : 10/4/2007 11:17:03 AM
//Version     : 1.0
//Description : Default javascript functions for the site
//-------------------------------------------------------------------------------------------------

var bHTML = false;

function displayCenterPopup(url, name, height, width, scrollbar, toolbar, statusbar) {
    var properties = 'scrollbars=' + scrollbar + ',toolbar=' + toolbar + ',status=' + statusbar;
	var iLeft = (window.screen.width - width) / 2;
	var iTop = (window.screen.height - height) / 2 - 15;
	
	window.open(url, name, properties + ',width=' + width + ',height=' + height + ',left=' + iLeft + ',top=' + iTop);
}

function displayLeftPopup(url, name, height) {
    var halfWidth = window.screen.width / 2; //half the width of the screen
	window.open(url, name, 'scrollbars=no, toolbar=no, status=no ,width=' + halfWidth + ',height=' + height + ',left=0 ,top=0');
 }

function goToURL(obj) {
    var strURL = obj.options[obj.selectedIndex].value;
    if ((strURL != "") &&  (strURL != "Select")) {
        window.location = strURL;
    }
}

function getObj(objName) {
	if (document.getElementById) {
		return document.getElementById(objName);
	}
	else if (document.all) {
		return document.all[objName];
	}
	else if (document.layers) {
		return document.layers[objName];
	}
}

function setLinkStyle(objLI,iNum,bOver) {
    if (bOver) {
        objLI.className = 'landing_li_over';
        getObj("aItemLand_" + iNum).style.color = "white";
    }
    else {
        objLI.className = 'landing_li_off';
        getObj("aItemLand_" + iNum).style.color = "";
    }
}

function getPDF(strPDF){
    window.open(strPDF);
}

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showErrorMessage(strMsg) { alert( strMsg ); }

function openPopupVideo(idProgram,bLow) {
    if (bLow) { 
        displayCenterPopup("videoPlayer.aspx?idProgram=" + idProgram + "&videoRes=Low","Video","300","420","yes","no","yes"); 
        }
    else { 
        displayCenterPopup("videoPlayer.aspx?idProgram=" + idProgram + "&videoRes=Hi","Video","400","420","yes","no","yes"); 
    }
}

function openPopupPrivacy() { displayCenterPopup("privacy.aspx","Privacy","600","420","yes","no","yes"); }


function openFullSizeImage(imgName) {
    var imgPath = "../assets/images/features/";
        
    if(imgName) { window.open(imgPath + resize(imgName)); } 
    else alert("error opening image:");
}

function resize(imgName)
{

}

function isPhoneKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 32) && (charCode != 40) && (charCode != 41) && (charCode != 43) && (charCode != 45) && (charCode != 46) )
       return false;
    return true;
    }

function processMultiCheckBox(strNameListBox, strNameCheckBox, strFieldValues, strFieldText, iDiv) {
    var bChkEnd = false;
    var chkObj, labelObj;
    var strValue = '';
    var strText = '';
    
    for (var iCounter=0;;iCounter++) {
        chkObj = getObj(strNameCheckBox + '_' + iCounter);
        labelObj = getObj(strNameCheckBox + '_Label_' + iCounter);
        
        if (chkObj) {
            if (chkObj.checked) {
                if (strValue != "") { strValue += "," }; strValue += chkObj.value;
                if (strText != "") { strText += "," }; strText += labelObj.innerHTML;
                }
            }
        else { break; }
        }

        if (strText == '') {
            getObj(strNameListBox).options[0].value = "0";
            getObj(strNameListBox).options[0].text = "-- Select Choices --";
            getObj(strFieldValues).value = ""
            getObj(strFieldText).value = ""
            }
        else {
            getObj(strNameListBox).options[0].value = strValue;
            getObj(strNameListBox).options[0].text = strText;
            getObj(strFieldValues).value = strValue;
            getObj(strFieldText).value = strText;
        }

    if (iDiv>0) { getObj("multiselect_" + iDiv).style.display = 'none'; }

    return false;
    }


function showMultiSelect(id) {
    for (var i = 1; i<=4; i++) {
        if (i != id) {
            document.getElementById('multiselect_' + i).style.display = 'none';
            }
        }

    if ( (document.getElementById('multiselect_' + id).style.display == 'none') || (document.getElementById('multiselect_' + id).style.display == '') ) {
        document.getElementById('multiselect_' + id).style.display = 'block';
        }
    else {
        document.getElementById('multiselect_' + id).style.display = 'none';
        }
    }

function getServices() {
    document.getElementById('multiselect_1').style.visibility='hidden';
    
    for(i = 0; i < document.all.length; i++) {
        if (document.all("chkServicesFor_").checked==true) {
            if (document.all(i).tagName=="LABEL") {
                document.all("TextBox1").value=document.all(i).innerText;
                break;
                }
            }
        }
    }

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	    }
    else {
//		limitCount.value = limitNum - limitField.value.length;
	    }
    }

