// JavaScript Document

var submitOK = true;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
function show_div(id){
	var imgdiv='img_'+id;

	if (document.getElementById(id).style.display =='block') 
		{document.getElementById(id).style.display ='none';document.getElementById(imgdiv).src ='images/leftnav/rtArrow.gif';}
	else
		{document.getElementById(id).style.display ='block';document.getElementById(imgdiv).src ='images/leftnav/dnArrow.gif';}
}
function validateKeyword(f,flg,val){
    switch (flg)
    {   case 0: if (document.getElementById(f).value==val){document.getElementById(f).value='';} break;
        case 1: if (document.getElementById(f).value==''){document.getElementById(f).value=val;} break;
    }
}
function updateHidden(fieldId, updateField){
    document.getElementById(updateField).value = document.getElementById(fieldId).value;
}
function submitForm(){
    var rtrnVal = submitOK;
    submitOK = true;
    return rtrnVal;
}
function trim(source) {

	var result;

	result = leftTrim(source);
	return rightTrim(result);

}

function leftTrim(source) {


	var result;
	var i;

	if (source == null) return "";
	text = source;

	if (text.length == 0) return "";

	result = "";
	for (i = 0; i < text.length && text.charAt(i) == " " ; i++);
	if (i == text.length) return "";
	return text.substring(i, text.length);
}

function rightTrim(source) {

	var result;
	var i;

	if (source == null) return "";
	text = source;

	if (text.length == 0) return "";

	result = "";
	for (i = text.length - 1; i >= 0 && text.charAt(i) == " " ; i -= 1);
	if (i < 0) return "";
	return text.substring(0, i + 1);
}

function isValidEmail(sEmail) {
     var str = sEmail;

     var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
     var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

     if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
         return true;
     }
     else {
         return false;
     }
 }
     
 function trimText(txt) {
     if (txt == "") return txt;
     var first = 0;
     var last = txt.length;
     while (txt.charAt(first) == " ") first++;
     while (txt.charAt(last - 1) == " ") last--;
     //if txt have all spaces then last is < first
     if (last < first) last = first = 0;
     return txt.substring(first, last);
 }

 function validateCntrls(cntrl1, cntrl2, cntrl3, cntrl4) {
     
     if (trimText(document.getElementById(cntrl1).value) == "") {         
         alert(ynameerr);
         document.getElementById(cntrl1).focus();
         return false;             
     }
     if (trimText(document.getElementById(cntrl2).value) == "") {
         alert(yemlerr);
         document.getElementById(cntrl2).focus();
         return false;
     }
     else if (!isValidEmail(document.getElementById(cntrl2).value)) {
         alert(yemlerrfor);
         document.getElementById(cntrl2).focus();
         return false;
     }
     if (trimText(document.getElementById(cntrl3).value) == "") {
         alert(fnameerr);
         document.getElementById(cntrl3).focus();
         return false;
     }
     if (trimText(document.getElementById(cntrl4).value) == "") {
         alert(femlerr);
         document.getElementById(cntrl4).focus();
         return false;
     }
     else if (!isValidEmail(document.getElementById(cntrl4).value)) {
         alert(femlerrfor);
         document.getElementById(cntrl4).focus();
         return false;
     }
 }
 function validateCntrlsNameEmail(nameCcntrl, emailCntrl) {
     
     if (trimText(document.getElementById(nameCcntrl).value) == "" ||trimText(document.getElementById(nameCcntrl).value) == "Name") {         
         alert("Please enter your name");
         document.getElementById(nameCcntrl).focus();
         return false;             
     }
     if (trimText(document.getElementById(emailCntrl).value) == "") {
         alert("Please enter your e-mail");
         document.getElementById(emailCntrl).focus();
         return false;
     }
     else if (!isValidEmail(document.getElementById(emailCntrl).value)) {
         alert("Please enter your e-mail in correct format");
         document.getElementById(emailCntrl).focus();
         return false;
     }
 }
function navClick(d1,d2){
    resetNav();
    document.getElementById(d1).style.display='none';
    document.getElementById(d2).style.display='block';
}

function resetNav(){
    document.getElementById("wc").style.display='none';
    document.getElementById("ta").style.display='none';
    document.getElementById("ut").style.display='none';
    
    document.getElementById("wcclose").style.display='block';
    document.getElementById("taclose").style.display='block';
    document.getElementById("utclose").style.display='block';
}

function openlink(pageUrl){
    window.open(pageUrl);
}

function languageSubmit(){
    if(document.getElementById("langChng") != null){
        document.getElementById("langChng").value = "y";
    } 
    document.forms[1].submit();
}

function HideFld(inVal, radiusID, optCityID) {
    if (document.getElementById(radiusID) != null) {
        if (inVal == 0) {
            document.getElementById(radiusID).style.display = 'block';
        }
        else {
            document.getElementById(radiusID).style.display = 'none';
            document.getElementById(radiusID).selectedIndex = 4;
            if (document.getElementById(optCityID) != null) { document.getElementById(optCityID).checked = true; }
        }
    }
}

function changeJobsrchFlds1(cntrlFld, chgFld1,chgFld2,chgFld3,inVal) {
    if (document.getElementById(cntrlFld) != null) {
        var selCntry = document.getElementById(cntrlFld).options[document.getElementById(cntrlFld).selectedIndex].value;
        
        if (selCntry == "US" || selCntry == "CA" || selCntry == "XX") {
            if (document.getElementById(chgFld1) != null) { document.getElementById(chgFld1).style.display = 'block'; }
            if (document.getElementById(chgFld2) != null) { document.getElementById(chgFld2).style.display = 'block'; }
            if (document.getElementById(chgFld3) != null) {
                document.getElementById(chgFld3).className = "jobsearch_sub"; //document.getElementById(chgFld3).className.replace('/\bjobsearch_list\b/', 'jobsearch_sub');
            }
            
        }
//        else {
//            if (document.getElementById(chgFld1) != null) { document.getElementById(chgFld1).style.display = 'none'; }
//            if (document.getElementById(chgFld2) != null) { document.getElementById(chgFld2).style.display = 'none'; }
//            if (document.getElementById(chgFld3) != null) {
//                if (inVal != "true") { document.getElementById(chgFld3).className = "jobsearch_list"; }   //document.getElementById(chgFld3).className.replace('/\bjobsearch_sub\b/', 'jobsearch_list');
//            }                                 
//        }
    }
}

function disableFld(chgFld1, inVal, chgFld2, chgFld3,zipDisp) {
    if (document.getElementById(chgFld1) != null) {
        if (inVal == 'true') {
            document.getElementById(chgFld1).selectedIndex = 0;
            document.getElementById(chgFld1).disabled = true;
            if (document.getElementById(chgFld2) != null) {document.getElementById(chgFld2).selectedIndex = 0; }
        }
        else {
            document.getElementById(chgFld1).disabled = false;
            if (document.getElementById(chgFld3) != null) { document.getElementById(chgFld3).value = zipDisp; }
        }
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}



