﻿//-------------------------------------------------------------------------------------------------
//Author      : Mauricio Beltran
//Date        : 10/4/2007 11:17:03 AM
//Version     : 1.0
//Description : Default javascript functions for the site
//-------------------------------------------------------------------------------------------------

/* Added by CA on 3.24.10 */
/* validates a checkbox list for any checked value by storing the value in a textbox */
/*
$(function() {
    function checkBoxClicked() {
        var n1 = $("#<%= chklstDaysYouWork.ClientID %> input:checked").length;
        $("input:#<%= txtHiddenDaysWorkValue.ClientID %>").val(n1 == 0 ? "" : n1);
    }                    
    $("#<%= chklstDaysYouWork.ClientID %> :checkbox").click(checkBoxClicked);
});

function HighlightRowOn(obj){
    if(obj != null) {
        obj.originalClassName = obj.className;obj.className = obj.className + ‘_highlight’;
    }
}

function HighlightRowOff(obj){
    if(obj != null) {
        obj.className = obj.originalClassName;
    }
}
*/
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i];
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

function switchSiteToFlashVersion() {
    if (window.name == "BerlitzPopup") {
        window.location = "/web/content/Default.aspx";
    }
    else {
        displayCenterPopup("/web/content/Default.aspx","BerlitzPopup","650","1050","yes","no","yes");
        window.location = "/web/Default.aspx?noflashdetect=true";
    }
}

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 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 changeBanner(){
    if(counter > 2)
        counter = 0;

    document.banner.src = bannerArray[counter].src;
    counter++;
}
        
function showMenu(id) {
    for (var i = 1; i<=4; i++) {
        if (i == id){
            if (document.getElementById('box_home_menu_sub_' + i).style.visibility=='visible'){
                document.getElementById('box_home_menu_sub_' + i).style.visibility='hidden';
            }
            else{
                document.getElementById('box_home_menu_sub_' + i).style.visibility='visible';
            }
        }
        else{
            document.getElementById('box_home_menu_sub_' + i).style.visibility='hidden';
        }
    }
}

function showContentPage(idTemplate) {
    if (bHTML) { window.location = "/web/html/content.aspx?idTemplate=" + idTemplate; }
    else { thisMovie("container").showContentPage(idTemplate); }
}

function showLocationsLandingPage() {
    if (bHTML) { window.location = "/web/html/locations.aspx"; }
    else { thisMovie("container").showLocationsLandingPage(); }
}

function showServicesLandingPage() {
    if (bHTML) { window.location = "/web/html/corporateservices.aspx"; }
    else { thisMovie("container").showServicesLandingPage(); }
}

function showProgramsLandingPage() {
    if (bHTML) { window.location = "/web/html/programs.aspx"; }
    else { thisMovie("container").showProgramsLandingPage(); }
}

function showLanguagesLandingPage() {
    if (bHTML) { window.location = "/web/html/languages.aspx"; }
    else { thisMovie("container").showLanguagesLandingPage(); }
}

function showContactUsPage() {
    if (bHTML) { window.location = "/web/html/contact.aspx"; }
    else { thisMovie("container").showContactUsPage(); }
}

function showProgramPage(idProgram, idProgramCategory) {
    if (bHTML) { window.location = "/web/html/programs.aspx?idProgram=" + idProgram + "&idProgramCategory=" + idProgramCategory; }
    else { thisMovie("container").showProgramPage(idProgramCategory, idProgram); }
}

function showLanguageCenterPage(idLanguageCenter) {
    if (bHTML) { window.location = "/web/html/locations.aspx?idLanguageCenter=" + idLanguageCenter; }
    else { thisMovie("container").showLanguageCenterPage(idLanguageCenter); }
}

function showServiceContactForm(idSales,idLanguageCenter) { thisMovie("container").showServiceContactForm(idSales,idLanguageCenter); }

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; }
    else { return document[movieName]; }
}

function showErrorMessage(strMsg) { alert( strMsg ); }

function openPopupMap(strURL) { window.open(strURL); }

function openGroupMemberWindow(idGroup) {
    displayCenterPopup("group-member.aspx?idGroup=" + idGroup,"GroupMember","300","420","yes","no","yes"); 
}


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 openPopupVideoPromotion(idPromotion,bLow) {
    if (bLow) { 
        displayCenterPopup("../content/videoPlayer.aspx?idPromotion=" + idPromotion + "&videoRes=Low","Video","300","420","yes","no","yes"); 
        }
    else { 
        displayCenterPopup("../content/videoPlayer.aspx?idPromotion=" + idPromotion + "&videoRes=Hi","Video","400","420","yes","no","yes"); 
    }
}

function openPopupIntermediate(idProgram) { displayCenterPopup("intermediatePage.aspx?idProgram=" + idProgram + "","Ecommerce","480","820","yes","no","yes"); }

function openPopupPrivacy() { displayCenterPopup("privacy.aspx","Privacy","600","420","yes","no","yes"); }

function openPopupSalesReps() { displayCenterPopup("salesReps2.aspx","Sales","480","820","yes","no","yes");  }

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 processYesNoList(strNameRadioList, strFieldValue) {
    var chkObj;
    var strValue = '';

    chkObj = getObj(strNameRadioList);
    if (chkObj) { 
       if( chkObj.checked) {
            if (strValue == '') { strValue += chkObj.value; }
        else { //break; }
    
        if (strValue == '') { getObj(strFieldValue).value = ""  }
        else {  getObj(strFieldValue).value = strValue; }   
       } 
    }
    return false;
}

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 displayLanguageHistory(bShow) {
    if (bShow) { getObj('divLangHistory').style.display = 'block'; }
    else { getObj('divLangHistory').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;
	    }
    }

function openMagazinePopup() {
    window.open("/web/magazine/index.htm","BerlitzMagazine","resizable=yes,location=no,menubar=no,status=no,scrollbars=no,width=" + (screen.width - 60) + ",height=" + (screen.height - 130) + "");
    }

// this function is needed to work around a bug in IE related to element attributes
function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
}