<!--

var validated=true;  // global
var firstCtrlWithErr = '';

function setErrorBlock(errId, lblId, fldId, msg) {
    if (YAHOO.showTip.container.olTip) YAHOO.showTip.container.olTip.hide();//from yui.tpl.php
    setObjVisibility(errId, 'true'); 
    setDivMsg(errId, msg);  
    // highlight text label
//  if (elId(lblId)) {
//     elId(lblId).style.color = "red";
//  }
    // highlight field
//  if (elId(fldId)) {
//     elId(fldId).className = "text-error";
//  }

}

function unsetErrorBlock(errId, lblId, fldId) {
    setDivMsg(errId, '');
    setObjVisibility(errId,'false'); 
    // highlight text field
//  if (elId(lblId)) {
//      elId(lblId).style.color = "#000000";
//      elId(lblId).style.fontWeight = "normal";
//    }
    // highlight field
//  if (elId(fldId)) {
//      elId(fldId).className = "text";
//    }
}

// call this from onchange
function valid(vl,errm, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId) // varying number of arguments
{
    var i;
    var arrTypo = new Array();
    //validated=true;
    // error message for typo error
    //typoErrMsg = "WARNING: Your email address might contain a spelling error. Please check again.";

    // Regular expression for typo errors
    arrTypo[0] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{0,}(rediff|htomail|htomil|htomai|htomal|htomial|hotmil|hotmai|hotmial|hotamil|hatmail|hotnail|hotrmail)s*.co[m]{0,1}[\\w\\.\\@]{0,}";
    arrTypo[1] = "[\\w-\\.]{1,}\\@[\\w-\\.]{1,}(rediff|rediffmail|hotmail|hotm[ail]s?).com[\\w-\\.\\@]{0,}";
    arrTypo[2] = "[\\w-\\.]{1,}\\@[\\w-\\.]{1,}(rediffmail|hotmail|hotm[ail]s?)[\\w-\\.]{1,}.com[\\w\\.\\@]{0,}";
    arrTypo[3] = "[\\w-\\.]{1,}\\@(rediffmail|hotmail)[\\w-\\.]{1,}.co[m]{0,1}[\\w-\\.\\@]{0,}";
    arrTypo[4] = "[\\w-\\.]{1,}\\@(rediffmail|hotmail).com[\\w-\\.\\@]{1,}";
    arrTypo[5] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}yahoo[\\w\\.]{1,}.(com|co.uk|co.in)";
    arrTypo[6] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}yahoo.(com|co.uk|co.in)";
    arrTypo[7] = "[\\w\\.\\@]{1,}\\@yahoo[\\w-\\.]{1,}.(com|co.uk|co.in)";
    arrTypo[8] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{0,}yahoo[\\w]{0,}.com.in";
    arrTypo[9] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{0,}yahoo[\\w]{0,}.com.uk";
    arrTypo[10] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{0,}y(o|a)*ho{3,}[\\w]{0,}.(com|co.uk|co.in)";
    arrTypo[11] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{0,}yahoo.uk.co[\\w-\\.]{0,}";
    arrTypo[12] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}tm[.,]net[.,]my[\\w]{1,}";
    arrTypo[13] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}tm[.,]net[.,]my";
    arrTypo[14] = "[\\w-\\.]{1,}\\@tm[.,]net[.,]my[\\w]{1,}";
    arrTypo[15] = "[\\w-\\.]{1,}\\@usa[.,]net[\\w-\\.\\@]{1,}";
    arrTypo[16] = "[\\w-\\.\\@]{1,}\\@[\\w-\\.\\@]{1,}usa[.,]net[\\w-\\.\\@]{1,}";
    arrTypo[17] = "[\\w-\\.\\@]{1,}\\@[\\w-\\.\\@]{1,}usa[.,]net";
    arrTypo[18] = "[\\w-\\.]{1,}\\@pacific[.,]net[.,]sg[\\w-\\.\\@]{1,}";
    arrTypo[19] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}pacific[.,]net[.,]sg";
    arrTypo[20] = "[\\w-\\.]{1,}\\@[\\w-\\.\\@]{1,}pacific[.,]net[.,]sg[\\w-\\.\\@]{1,}";
    arrTypo[21] = "[\\w-\\.]{1,}\\@www\\.[\\w-\\.]{0,}\\.[\\w-\\.]{0,}";
    arrTypo[22] = "[\\w-\\.]{1,}\\@(ya[\\w-]{1,}hoo|yh[\\w-]{1,}oo|yaho|yhoo).(com|co.uk|co.in)";
    arrTypo[23] = "[\\w-\\.]{1,}\\@tm(.net|net.com.my)";
    arrTypo[24] = "newmail@wipro.com";

    // check email format
    //rx=new RegExp("[\\w-_]+(\\.[\\w-_]+)*\\@+[\\w-_]+(\\.[\\w-_]+)+");
    for (i=7;i<valid.arguments.length;i++) 
        rx=new RegExp(valid.arguments[i]);

    if ((a=rx.exec(vl))!=null && a[0].length==vl.length)
    {
        //validated=true;
        unsetErrorBlock(errOverlayId, lblId, fieldId);
    }
    else{
        // return false once it finds any format error
        setErrorBlock(errOverlayId, lblId, fieldId, errm);
        validated=false;
        return false;
    }

    // if the email don't have any format error
    // check for any typo error
    // the loop will exit once it found any typo error
    if (validated)
    {
        for (i=0;i<arrTypo.length;i++) 
        {
            var rx;
            //alert(arrTypo[i]);
            rx=new RegExp(arrTypo[i]);
            if ((a=rx.exec(vl))!=null && a[0].length==vl.length) {
                //setErrorBlock(errOverlayId, lblId, fieldId, typoErrMsg);
                setErrorBlock(errOverlayId, lblId, fieldId, msgTypo);
                validated=false;
                return false; 
            }
        }

        return validated;
    }

}

function ValidateOneEmail(ctl, msgId, msgId2, msgId3, msgDont, msgFree, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId)
{
    var vl = ctl.value.toLowerCase();
    vl = Trim(vl);
    var validErr = true;
    //validated = true;
    
    // scan for typo errors for the following domains:
    //   - hotmail.com
    //   - yahoo.com, yahoo.co.uk, yahoo.co.in
    //   - rediffmail.com
    //   - tm.net.my
    
    //var errMsg = "Please enter a valid email address. Don't have an email account? <a href=\"javascript: showForm(4)\" class=\"tip\">Get a FREE email account here!</a>";
    var errMsg = msgId + " " + msgDont + " <a href=\'javascript: showForm(4)\' class=\'tip\'>" + msgFree + "</a>";
    var errPattern = "[\\w-_]+((\\.)[\\w-_]+)*\\@[\\w-_]+(\\.[\\w-_]+){1,5}";
    validErr=valid(vl, errMsg, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId, errPattern);
 
    if (!validErr) {
       validated = false;
       focusCtrl(ctl);
    } else {
        if (vl.indexOf('@jobstreet.com') > 0) {
            //str = "WARNING: You cannot use a JobStreet.com email address. Don't have an email account? <a href=\"javascript: showForm(4)\" class=\"tip\">Get a FREE email account here!</a>";
            str = msgId2 + " " + msgDont + " <a href=\'javascript: showForm(4)\' class=\'tip\'>" + msgFree + "</a>";
            setErrorBlock(errOverlayId, lblId, fieldId, str);
            focusCtrl(ctl);
            validErr = false;
           validated = false;
        } 
        else if (vl.indexOf('@bdonline') > 0) {
            //str = "WARNING: Please change your email address. BDOnline is blocking emails from us. <a href=\"javascript: showForm(4)\" class=\"tip\">Get a FREE email account here!</a>";
            str = msgId3 + " " + msgDont + " <a href=\'javascript: showForm(4)\' class=\'tip\'>" + msgFree + "</a>";
            setErrorBlock(errOverlayId, lblId, fieldId, str);        
           focusCtrl(ctl);
           validErr = false;
           validated = false;
        } 
        else{
           unsetErrorBlock(errOverlayId, lblId, fieldId);
        }
    }
    return validErr;
}

function ValidateTwoEmail(email1, email2, msgId, msgId2, tipOverlayId, errOverlayId, lblId, fieldId) {
    if (Trim(email2.value) == "") {
       //msg = "Please re-enter your email.";
       setErrorBlock(errOverlayId, lblId, fieldId, msgId);  
        focusCtrl(email2);
        validated = false;
        return false;
    } else if (Trim(email1.value) == Trim(email2.value)) {
        unsetErrorBlock(errOverlayId, lblId, fieldId);
        //validated = true;
        return true;
    } else {
       //msg = "Your email confirmation does not match.";
       setErrorBlock(errOverlayId, lblId, fieldId, msgId2);  
        focusCtrl(email2);
        validated = false;
        return false;
    }
}

function ValidateAltEmail(ctl, email, msgId, msgId2, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId)
{
    var vl = ctl.value;
    vl = Trim(vl);

    if (vl == '') {
        unsetErrorBlock(errOverlayId, lblId, fieldId);
        //validated = true;
        return true;
    } else {
        // scan for typo errors for the following domains:
        //   - hotmail.com
        //   - yahoo.com, yahoo.co.uk, yahoo.co.in
        //   - rediffmail.com
        //   - tm.net.my
        //var errMsg = "Invalid email address. Please enter a valid email address.";
        errPattern = "[\\w-_]+((\\.|')[\\w-_]+)*\\@[\\w-_]+(\\.[\\w-_]+){1,5}";
        validErr=valid(vl, msgId, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId, errPattern);
        if (!validErr && vl != '') {
              focusCtrl(ctl);
              validated = false;
              return false;
            }
        else if(ctl.value == email.value){
                focusCtrl(ctl);
                //errMsg = "This alternate email address is similar to your existing email address. Please enter a different email address.";
                setErrorBlock(errOverlayId, lblId, fieldId, msgId2);
                validated = false;
                return false;
            }
    }
}

function ValidateEmail(ctl, errMsg, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId)
{
    var vl = ctl.value;
    vl = Trim(vl);

    // scan for typo errors for the following domains:
    //   - hotmail.com
    //   - yahoo.com, yahoo.co.uk, yahoo.co.in
    //   - rediffmail.com
    //   - tm.net.my
    //var errMsg = "Invalid email. Please enter a valid email address.";
    errPattern = "[\\w-_]+((\\.|')[\\w-_]+)*\\@[\\w-_]+(\\.[\\w-_]+){1,5}";
    validErr=valid(vl, errMsg, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId, errPattern);

    if (!validErr && vl != '') {
          focusCtrl(ctl);
          validated = false;            
          return false;
        }
    else{
        unsetErrorBlock(errOverlayId, lblId, fieldId);
        //validated = true;
        return true;
    }
}

// used in email-resume.tpl.php
function ValidateCompanyEmail(strBannedEmail, ctl, errMsg, msgId, msgId2, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId, errOverlayId2)
{
    var vl = ctl.value.toLowerCase();  
    strBannedEmail = strBannedEmail.toLowerCase();
    jsEmail = ",lina@jobstreet.com,info@jobstreet.com,siva_auto_mailer@jobstreet.com,lina01@jobstreet.com,advert@jobstreet.com,auth-admin-ph@jobstreet.com,myjobstreet@jobstreet.com,lina-in@jobstreet.com,auth-admin-my@jobstreet.com,lina-ph@jobstreet.com,policy@jobstreet.com,marcom@jobstreet.com,webmaster@jobstreet.com,usercare@jobstreet.com,usercare-my@jobstreet.com,";  
    vl = Trim(vl);
    strBannedEmail = Trim(strBannedEmail);

    // scan for typo errors for the following domains:
    //   - hotmail.com
    //   - yahoo.com, yahoo.co.uk, yahoo.co.in
    //   - rediffmail.com
    //   - tm.net.my
    errPattern = "[\\w-_]+((\\.|')[\\w-_]+)*\\@[\\w-_]+(\\.[\\w-_]+){1,5}";
    validErr=valid(vl, errMsg, msgTypo, tipOverlayId, errOverlayId, lblId, fieldId, errPattern);
    unsetErrorBlock(errOverlayId2, lblId, fieldId);

    if (!validErr || vl == '') {
          focusCtrl(ctl);        
          validated = false;        
        }
    else {
        if (String(jsEmail).indexOf(vl) > 0) {
            //str = "Sorry, JobStreet.com does not accept resumes sent to " + ctl.value;
            str = msgId + " " + ctl.value;
            setErrorBlock(errOverlayId, lblId, fieldId, str);
            focusCtrl(ctl);
            validated = false;
            validErr = false;
        } 
        else if (String(strBannedEmail).indexOf(vl) > 0) {
            //str = "Sorry, we cannot email your resume to this email address. Please contact the company directly for your application.";
            setErrorBlock(errOverlayId2, lblId, fieldId, msgId2);
            focusCtrl(ctl);
            validated = false;
            validErr = false;
        }
        else{
           unsetErrorBlock(errOverlayId, lblId, fieldId);
           unsetErrorBlock(errOverlayId2, lblId, fieldId);
        }
    }
    return validErr;
}

function isConfirm(msg) {
    var reply;
    
    reply = confirm(msg);
    if (reply)
        return true;
    else
        return false;   
}

function checkChkBoxLimit(ctrl, intLimit, msgId, msgId2, tipOverlayId, errOverlayId, lblId, fieldId, compulsory, ctrl2)
{
    intTotal = 0;
    for(i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].checked && (!ctrl[i].disabled))
            intTotal++;         
    }
    try {
        if (ctrl2 != undefined) {
            for(var j=0; j<ctrl2.length;j++) {
                if(ctrl2[j].checked && (!ctrl2[j].disabled))
                    intTotal++;
            }
        }
    } catch (e) {
        // do nothing
    }
    if(compulsory && intTotal == 0)
    {
        //if (msg == "")
            //msg = "Please select an option.";
        //else 
            //msg = msg;
        setErrorBlock(errOverlayId, lblId, fieldId, msgId);  
        if (ctrl[0]) focusCtrl(ctrl[0]);
        validated = false;
        return false;
    }
    else if(intTotal > intLimit)
    {
        //msg = "Please do not select more than " + intLimit + " options.";        
        msg = msgId2.replace("#intLimit#", intLimit);
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        if (ctrl[0]) focusCtrl(ctrl[0]);
        validated = false;
        return false;
    }
    else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);
        //validated = true;
        return true;
    }
}

function ValidatePassword(ctlPwd, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    if (Trim(ctlPwd.value).length < 6) {
            //msg = "Password must be at least 6 characters.";
            setErrorBlock(errOverlayId, lblId, fieldId, msgId);  
            focusCtrl(ctlPwd);
            validated = false;
            return false;
    }   else {
         unsetErrorBlock(errOverlayId, lblId, fieldId);  
    }
    
}

function ValidateConfirmPassword(ctlPwd, ctlCfPwd, msgId, msgId2, tipOverlayId, errOverlayId, lblId, fieldId) {
    if (Trim(ctlCfPwd.value) == "") {
        //msg = "Please re-enter your password.";
        setErrorBlock(errOverlayId, lblId, fieldId, msgId);  
        focusCtrl(ctlCfPwd);
        validated = false;
        return false;
    } else if (Trim(ctlPwd.value) == Trim(ctlCfPwd.value)) {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    } else {
        //msg = "Your password confirmation does not match.";
        setErrorBlock(errOverlayId, lblId, fieldId, msgId2);  
        focusCtrl(ctlCfPwd);
        validated = false;
        return false;
    }
}

function ValidatePhones (telCtryCode, telNo, HpCtryCode, hpNo, msg, msgHp, msgHpValid, msgHpCtry, msgTelCtry, msgTelValid, tipOverlayId, errOverlayId, lblId, fieldId, errOverlayId2)
{
    tel = Trim(telNo.value);
    hp = Trim(hpNo.value);
    isvalid = true;
    if (tel == '' && hp == '')
    {
        isvalid = false;
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please enter either mobile number or telephone number.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msg);
    } 
    else 
    {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        unsetErrorBlock(errOverlayId2, '', '');  
        if (hp != '') {
            isvalid = ValidateHp(HpCtryCode, hpNo, msgHp, msgHpValid, msgHpCtry, tipOverlayId,errOverlayId,lblId,fieldId);
        } 
        //if (tel != '' || telCtryCode.value != '')
        //{
            //isvalid = ValidatePhone (telCtryCode, telNo, 'Your telephone number is not valid. Please enter BOTH your area code and telephone number.', msgId, tipOverlayId, errOverlayId2, lblId, fieldId);
            isvalid = ValidatePhone (telCtryCode, telNo, msgTelCtry, msgTelValid, tipOverlayId, errOverlayId2, lblId, fieldId);
        //}
    }
    if (!isvalid) {
        validated = false;
    }
    return isvalid;
}

function ValidatePhone (ctl1, ctl2, msgTelCtry, msgTelValid, tipOverlayId, errOverlayId, lblId, fieldId) {
    var temp_str = Trim(ctl1.value) + Trim(ctl2.value);
    var validPhone = /^[\d\-\(\)\[\]\s\+]{5,}$/;
    if (temp_str == "") {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    } else if (Trim(ctl2.value) != '' && Trim(ctl1.value) == "") {
        //ctl2.value = "";
        setErrorBlock(errOverlayId, lblId, fieldId, msgTelCtry);  
        focusCtrl(ctl2);
        validated = false;
        return false;
    } else if (!validPhone.test(temp_str)) {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Your telephone number is not valid. Only numbers and some symbols such as "-" are allowed.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msgTelValid);
        focusCtrl(ctl2);
        validated = false;
        return false;
    } 
    else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    }
}

function ValidateHp(ctl1,ctl2,msgHp,msgHpValid,msgHpCtry,tipOverlayId,errOverlayId,lblId,fieldId) {
    // Regular expression for typo errors
    var validMY = /^0?1[02346789]\d{7}$/;
    var validMY2 = /^0?1[02346789]\-\d{7}$/;
    
    var validSG = /^[89]\d{7}$/;
    var validBD = /^01[156789]\d{6,8}$/;
    var validID = /^0?\d{8,}$/;
    var validPH = /^0?9\d{9}$/;
    var validIN = /^9\d{9}$/;
    var validTH = /^0?8\d{8}$/;
    var validDF = /^[0-9()+-.,\\*#]+$/;
    
    aNum = Trim(ctl1.options[ctl1.selectedIndex].value);
    hpNum = Trim(ctl2.value);
    message = '';
    if (aNum == '' && hpNum == '') { } 
    else {
        if (aNum == '') {  
            //message = "Please select your mobile's Country Code.";
            message = msgHpCtry; 
        } 
        else if (hpNum == '') {  
            //message = 'Please enter your mobile number.';
            message = msgHp;
        } 
        else {
            var strExp = validDF;
            var strExp2 = '';   
            switch (aNum) {
                case '60': 
                    strExp = validMY; 
                    strExp2 = validMY2;
                    break;
                case '65': strExp = validSG; break;
                case '63': strExp = validPH; break;
                case '91': strExp = validIN; break;
                case '62': strExp = validID; break;
                case '880': strExp = validBD; break;
                case '66': strExp = validTH; break;
            }
            if (aNum == '60') {
                if (!strExp.test(hpNum) && !strExp2.test(hpNum)) {
                    //message = "Your mobile number is not valid.<br /><a href='javascript: showForm(5)' style='font: 7.5pt verdana'>How to enter?</a>";
                    message = msgHpValid;
                }
            }
            else {
                if (!strExp.test(hpNum)) {
                    //message = "Your mobile number is not valid.<br /><a href='javascript: showForm(5)' style='font: 7.5pt verdana'>How to enter?</a>";
                    message = msgHpValid;
                }
            }                

        }
    }
    if (message != '') {
        setErrorBlock(errOverlayId, lblId, fieldId, message);  
        focusCtrl(ctl2);
        validated = false;
        return false;
    } else {
        ctl2.value = hpNum.replace(/[^0-9]+/gi, '');
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function ValidateText(ctl, msg, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    var temp_str = Trim(ctl.value);
    if (temp_str == "") {
        ctl.value = "";
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;      
        return false;
    } else {
        ctl.value = temp_str;
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    }
}

function ValidateReal(ctl, msg, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    var temp_str = Trim(ctl.value);
    if (isReal(temp_str)) {
        ctl.value = temp_str;
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    } else {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;      
        return false;
    }
}

function ValidateSkills(ctl, msg, errOverlayId, lblId, fieldId) {
    var strRegex = new RegExp(/^([-,&()\\\/\w\.\s]+)$/);
    if (ctl.value == '' || strRegex.test(ctl.value)) {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true; 
    }
    else {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        validated = false;
        return false;
    }
}

function ValidateName(name1, name2, msg1, msg2, msg3, msgId, tipOverlayId, errOverlayId, lblId, field1Id, field2Id) {
    var temp_str1 = Trim(name1.value);
    var temp_str2 = Trim(name2.value);
    if (temp_str1 == "" && temp_str2 == "") {
        setErrorBlock("", "", field1Id, "");  
        //setErrorBlock(errOverlayId, lblId, field2Id, "Please fill in your First and Last Name.");  
        setErrorBlock(errOverlayId, lblId, field2Id, msg1);
        focusCtrl(name1);
        validated = false;
        return false;
    }
    else if (temp_str1 == "") {
        name1.value = "";
        //setErrorBlock(errOverlayId, lblId, field1Id, "Please fill in your First Name.");  
        setErrorBlock(errOverlayId, lblId, field1Id, msg2);
        focusCtrl(name1);
        validated = false;
        return false;
    } else if (temp_str2 == "") {
        name2.value = "";
        //setErrorBlock(errOverlayId, lblId, field2Id, "Please fill in your Family/Last Name.");  
        setErrorBlock(errOverlayId, lblId, field2Id, msg3);
        focusCtrl(name2);
        validated = false;
        return false;
    } else {
        name1.value = temp_str1;
        name2.value = temp_str2;
        unsetErrorBlock("", "", field1Id);  
        unsetErrorBlock(errOverlayId, lblId, field2Id);  
        //validated = true;
        return true;
    }
}

function ValidateUpload(ctl, mode, msg, errId, lblId, fieldId) {
    //mode(bitwise) : 1 - doc, 2 - .txt, 4 - .pdf, 8 - .htm
    var temp_str = String(Trim(ctl.value));
    var str_len = temp_str.length;
    var str_ext = temp_str.substring(str_len, temp_str.lastIndexOf("."));
    
    //if (temp_str == "") {
    //  unsetErrorBlock(errId, lblId, fieldId);  
    //  return true;
    //}
    if ( ((mode&1)==1 && (str_ext.toLowerCase()==".doc") || str_ext.toLowerCase()==".docx") || ((mode&2)==2 && str_ext.toLowerCase()==".txt") || ((mode&4)==4 && str_ext.toLowerCase()==".pdf") || ((mode&8)==8 && str_ext.toLowerCase()==".htm")) {
        //validated = true;
        unsetErrorBlock(errId, lblId, fieldId);  
        return true;
    }
    else {
        setErrorBlock(errId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;
        return false;
    }
}

function CountText(ctl, indicator) {
    indicator.value = ctl.value.length;
}


function ValidateTextLimit(ctl,min_val,max_val,msg, errId, lblId, fieldId) {
    var strTemp = Trim(ctl.value);
    if (strTemp.length < min_val || strTemp.length > max_val) {
        setErrorBlock(errId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;
        return false;
    }
    else {
        ctl.value = strTemp;
        unsetErrorBlock(errId, lblId, fieldId);  
        return true;
    }
}

function ValidateCtl(ctl, msg, compulsory, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    if (GetValueFromCtl(ctl) == "" && compulsory=="1") {
        //alert(msg);
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;
        return false;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    }
}

function ValidateNonEmptyCtl(ctl, msg, compulsory, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    if (ctl.value == "" && compulsory=="1") {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        ctl.focus();
        validated = false;
        return false;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function ValidateRdo(ctl, msg, compulsory, msgId, tipOverlayId, errOverlayId, lblId, fieldId){
    var rdo = "";
    for (var i=0; i < ctl.length; i++) {
        if (ctl[i].checked) {
            rdo = ctl[i].value;
        }
    }
    if (rdo == "" && compulsory == 1) {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        if ((ctl[0])) 
            focusCtrl(ctl[0]);
        else 
            focusCtrl(ctl);
        validated = false;
        return false;
    } else {
       unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    }    
}

function ValidateList(ctl,msg,ctlfocus) {
    var temp_str = Trim(ctl.value);
    
    if (temp_str == "") {
      alert(msg);
      focusCtrl(ctlfocus);
      validated = false;
      return false;
    }
    else {
      ctl.value = temp_str;
      //validated = true;
      return true;
    }
}

function GetValueFromCtl (ctl) {
    for (var i=0; i < ctl.options.length; i++) {        
        if(ctl.options[i].selected ) {
            if (ctl.options[i].value == "" || ctl.options[i].value == "0" || ctl.options[i].value == "-" || ctl.options[i].value == "00" || ctl.options[i].value == "000") {
                return "";
            } else
                return ctl.options[i].value;
        }
    }
    return "";
}

function GetValueFromRdo (ctl) {
    var cv = "";
    if (ctl.length == undefined) {
        if (ctl.checked) cv = ctl.value;
    } else {
        for (var i=0; i < ctl.length; i++) {
            if (ctl[i].checked) {
                cv = ctl[i].value;
            }
        }
    }
    return cv;
}

function GetRdoFromValue (ctl, val) {
    var cv = "";
    if (ctl.length != undefined) {
        for (var i=0; i < ctl.length; i++) {
            if (ctl[i].value == val) {
                cv = i;
            }
        }
    }
    return cv;
}

function ValidateNotDuplicate(ctlValue,arrCtl,ctlSize,errOverlayId, lblId, fieldId, msg)
{
//  var err=false;
    var countDup = 0;
    var arrControl = new Array();

    for(var c=0; c<ctlSize; c++)
        arrControl[c] = arrCtl[c].value;
    
    for(var i=0;i<ctlSize;i++){
        if(arrControl[i] == ctlValue && arrControl[i] != "" && ctlValue != ""){
            countDup = countDup+1;
        }
    }

    if (countDup > 1) {     
        setErrorBlock(errOverlayId, lblId, fieldId, msg);       
        validated = false;  
        return false;
    }
    else
    {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function ValidateSkillSet(ctlSkill, ctlYOE, ctlProficiency, errOverlayId, msgYOE, msgAnd, msgProficiency, msgSelect, msgSkill)
{   
    var lblId, fieldId, msg;
    msg = "";
    if(trim(ctlSkill.value) != "")
    {   
        if(ctlYOE.value == "" || ctlProficiency.value == "")
        {
            validated=false;
            if(ctlYOE.value == "")
            {
                //msg="years of experience";
                msg = msgYOE;
                if(ctlProficiency.value == "")
                    //msg=msg+" and ";
                    msg = msg + " " + msgAnd + " ";
            }
            if(ctlProficiency.value == "")
            {
                //msg=msg+"proficiency";
                msg = msg + msgProficiency;
            }
            //msg = "Please select " + msg + " of selected skill."
            msg = msgSelect.replace("#OPTION#", msg);
            setErrorBlock(errOverlayId, lblId, fieldId, msg);
            return false;
        }
        else
        {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    }
    else
    {
        if(ctlYOE.value != "" || ctlProficiency.value != "")
        {
            //msg='Please enter your skill description.';
            setErrorBlock(errOverlayId, lblId, fieldId, msgSkill);
            validated = false;
            return false;
        }
        else
        {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    }
}
function ValidateLanguageSet(ctlLanguage, ctlWritten, ctlSpoken, errOverlayId, msgBoth, msgSpoken, msgWritten, msgLanguage)
{
    var lblId, fieldId, msg;
    msg = "";
    if((ctlLanguage.value) != "")
    {
        if(ctlWritten.value == "" || ctlSpoken.value == "")
        {
            if(ctlWritten.value == "" && ctlSpoken.value == "")
                //msg="Please select written and spoken language proficiency.";
                msg = msgBoth;
            else if(ctlSpoken.value == "")
                //msg="Please select spoken language proficiency.";
                msg = msgSpoken
            else if(ctlWritten.value == "")
                //msg="Please select written language proficiency.";
                msg = msgWritten
                
            if (msg != "") {
            setErrorBlock(errOverlayId, lblId, fieldId, msg);
            validated = false;
            return false;
            }
        }
        else
        {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    }
    else
    {
        if(ctlWritten.value != "" || ctlSpoken.value != "")
        {
            //msg='Please select your language code.';
            msg = msgLanguage;
            setErrorBlock(errOverlayId, lblId, fieldId, msg);
            validated = false;
            return false;
        }
        else
        {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    }
}
/*
function ValidateSecondaryRole(ctlPrimary, ctlSecondary, errOverlayId)
{
    var lblId, fieldId, msg;
    var ctl1 = GetValueFromCtl(ctlPrimary);
    var ctl2 = GetValueFromCtl(ctlSecondary);
    
    if(ctl1 == "")
    {
//      msg = 'Please select your primary role';
//      setErrorBlock(errOverlayId, lblId, fieldId, msg);
//      validated = false;
//      return false;
    }
    else
    {
        if(ctl1 == ctl2)
        {
            msg = 'Duplicate role. Please select another';
            setErrorBlock(errOverlayId, lblId, fieldId, msg);
            validated = false;
            return false;
        }
        else
        {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    }
    
}
*/
/*function ValidateDup(frm,clt,drp){

    var err=0;
    var arrSkill = new Array();
    arrSkill[0] = frm.skill1.value;
    arrSkill[1] = frm.skill2.value;
    arrSkill[2] = frm.skill3.value;
    arrSkill[3] = frm.skill4.value;
    arrSkill[4] = frm.skill5.value;

    if(Trim(clt.value)!=""){
        if(GetValueFromCtl(drp) == ""){
            alert("Please give your Years of Experience with this skill.");
            focusCtrl(drp);
            validated = false;
            return false;
        }
    }
    else{
        if(GetValueFromCtl(drp) != ""){
            alert("Please enter the Skill.");
            focusCtrl(clt);
            validated = false;
            return false;
        }
    }

    for(var i=0;i<5;i++){
        for(var j=0;j<5;j++){
            if(arrSkill[i] == arrSkill[j] && arrSkill[i] != "" && arrSkill[j] != "" && i!=j){
                err=1;
            }
        }       
    }

    if (err==1) {
        alert("You have entered one or more duplicate skills. Please enter another Skill.");
        focusCtrl(frm.skill1);
        validated = false;
        return false;
    }   
    
}*/

function GetTextFromCtl (ctl) {
    for (var i=0; i < ctl.options.length; i++) {
        if(ctl.options[i].selected ) {
            return ctl.options[i].text;
        }
    }
    return "";
}

function ValidateDate(aday,amonth,ayear,maxyear,intType,msg, msg2, compulsory,msgId, tipOverlayId, errOverlayId, lblId, fieldId, field2Id, field3Id) {
    var tempDate; //= aday.value + amonth.value + ayear.value;
    var tempDay;
    var tempMonth;
    var tempYear;
    var isvalid;
    if (intType & 1)
        tempDay = GetValueFromCtl(aday);
    else
        tempDay = 1;

    if (intType & 2)
        tempMonth = GetValueFromCtl(amonth);
    else
        tempMonth = 1;

    if (intType & 4)
        if (ayear.type=='select') tempYear = GetValueFromCtl(ayear);
        else tempYear = ayear.value;
    else
        tempYear = 1900;

    if (maxyear == 0)
        maxyear = 2999;

    tempDate = tempDay + tempMonth + tempYear;
    if (tempYear != '' && tempYear < 1900  || tempYear > maxyear) {
        isvalid = false;
        var today = new Date();
        //msg = 'You must be above ' + (today.getFullYear() - maxyear) + ' years old to register on this site.';
        msg = msg2.replace("13", (today.getFullYear() - maxyear));
    }
    else 
    {
        var test = new Date(tempYear,tempMonth-1,tempDay);
            if ((test.getFullYear() == tempYear) && (tempMonth - 1 == test.getMonth()) && (tempDay == test.getDate())) {
                isvalid = true;
            }
            else
            isvalid = false;
    }    

    if (compulsory == '0' && tempDate == '') {
    }

    if (isvalid == false) {
        if ((tempDay =="0" || tempDay =="") && (intType & 1)) {
            focusCtrl(aday);
        } else if ((tempMonth =="0" || tempMonth =="") && (intType & 2)) {
            focusCtrl(amonth);
        } else {
            focusCtrl(ayear);
        }
        setErrorBlock(errOverlayId, lblId, fieldId, msg);
        setErrorBlock("", "", field2Id, "");  
        setErrorBlock("", "", field3Id, "");   
        validated = false;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        unsetErrorBlock("", "", field2Id);  
        unsetErrorBlock("", "", field3Id);          
    }
    return isvalid;
}

function ValidateAvailability(aday, amonth, ayear, msg, msg2, msg3, compulsory, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    var tempDay = GetValueFromCtl(aday);
    var tempMonth = GetValueFromCtl(amonth);
    var tempYear = ayear.value;
    var tempDate = tempDay + tempMonth + tempYear;
    var today = new Date();

    if (compulsory == 0 && tempDate == '') {
        //validated = true;
        unsetErrorBlock(errOverlayId, lblId, fieldId); 
    }
    else if (tempYear == '') {
        validated = false;
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
    }
    else 
    {
        var test = new Date(tempYear,tempMonth-1,tempDay);
            if ((test.getFullYear() == tempYear) && (tempMonth - 1 == test.getMonth()) && (tempDay == test.getDate())) {
                if (test >= today) {
                    //validated = true;
                    unsetErrorBlock(errOverlayId, lblId, fieldId); 
                }
                else {
                    //msg = "Available date must be later than today.";
                    msg = msg2;
                    validated = false;
                    setErrorBlock(errOverlayId, lblId, fieldId, msg);  
                }
            } else {
                //msg = "Invalid or blank available date.";
                msg = msg3;
                validated = false;
                setErrorBlock(errOverlayId, lblId, fieldId, msg);
            }
    }    

    if (validated == false) {
        if (tempDay == "0") {
            aday.focus();
        } else if (tempMonth == "0") {
            amonth.focus();
        } else {
            ayear.focus();
        }
    }
    return validated;
}

function isInt(string) {
    for (var i=0;i < string.length;i++)
        if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9') )
            return false;
    return true;
}

function isReal(string) {
    var decimal_found = false;
    var ws;

    for (var i=0;i < string.length;i++)
      if ((string.substring(i,i+1) < '0' || string.substring(i,i+1) > '9') && string.substring(i,i+1) != '.' && string.substring(i,i+1) != ',') {
            return false;
      }
      else {
        if (string.substring(i,i+1) == '.') {
          if (decimal_found == true) {
            return false;
          }
          else {
            decimal_found = true;
          }
        }   
      }
    return true;      
}

/// EXPERIENCE SECTION ///
function ValidateExperienceCtl(ctl, msg, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    var value;
    for (var i=0; i < ctl.options.length; i++) {        
        if(ctl.options[i].selected ) {
            value = ctl.options[i].value;
        }
    }
    if (value == "") {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;
        return false;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        //validated = true;
        return true;
    }
}

function ValidateDateJoined(amonth, ayear, dob_year, allowedYears, msgMonth, msgYear, msgLegal1, msgLegal2, errOverlayId, monthEleId)
{
    var cont;
    cont = ValidateMonthYear(amonth, ayear, msgMonth, msgYear, 1, errOverlayId, monthEleId);
    if (cont)
    {
        // all required fields present
        cont = ValidateYearsWorked(ayear, dob_year, allowedYears, msgLegal1, msgLegal2, '', errOverlayId, '', '');
    }
    return cont;
}

function ValidateDateLeft(amonth, ayear, join_month, join_year, msg, msgMonth, msgYear, errOverlayId, monthEleId)
{
    var joined = parseInt(GetValueFromCtl(join_year));
    var left = parseInt(GetValueFromCtl(ayear));
    var joinMonth = parseInt(GetValueFromCtl(join_month));
    var leftMonth = parseInt(GetValueFromCtl(amonth));
    // make year compulsory if Present not selected
    yearCompulsory = true;
    if ((elId(monthEleId).style.display != 'none' && leftMonth == 99) || (elId(monthEleId).style.display == 'none' && ayear.options[ayear.selectedIndex].value == '0')) yearCompulsory = false;

    var cont;
    cont = ValidateMonthYear(amonth, ayear, msgMonth, msgYear, yearCompulsory, errOverlayId, monthEleId);
        
    if (cont)
    {
        if (elId(monthEleId).style.display != 'none') {
            // month is visible, validate month as well
            var joinDate = new Date(joined,joinMonth-1,1);
            var leftDate = new Date(left, leftMonth-1, 1);
            if (leftMonth == 99) {
                // present selected
                unsetErrorBlock(errOverlayId, '', '');  
                return true;
            } else {
                if (leftDate<joinDate) {
                    //setErrorBlock(errOverlayId, '', '', 'Join date cannot be greater than left date.');  
                    setErrorBlock(errOverlayId, '', '', msg);
                    focusCtrl(ayear);
                    validated = false;
                    return false;
                } else {
                    unsetErrorBlock(errOverlayId, '', '');  
                    return true;
                }
            }
        } else {
            if (left > 0) {
                if (left<joined) {
                    //setErrorBlock(errOverlayId, '', '', 'Join date cannot be greater than left date.');
                    setErrorBlock(errOverlayId, '', '', msg);  
                    focusCtrl(ayear);
                    validated = false;
                    return false;
                } else {
                    unsetErrorBlock(errOverlayId, '', '');  
                    return true;
                }
            } else {
                unsetErrorBlock(errOverlayId, '', '');  
                return true;
            }
        }
    }
    return cont;
}

function ValidateMonthYear(amonth, ayear, msgMonth, msgYear, yearCompulsory, errOverlayId, monthEleId)
{
    var cont = true;
    if (elId(monthEleId).style.display != 'none') {
        // If month is visible
        cont = ValidateCtl(amonth, msgMonth, 1, '', '', errOverlayId, '', '');
        if (cont) { if (yearCompulsory) cont = ValidateCtl(ayear, msgYear, 1, '', '', errOverlayId, '', ''); }
    } else {
        if (yearCompulsory) cont = ValidateCtl(ayear, msgYear, 1, '', '', errOverlayId, '', '');
    }
    return cont;
}

function ValidateYoeCtl(ctl, dob_year, allowedYears, msg, msgLegal1, msgLegal2, tipOverlayId, errOverlayId, lblId, fieldId) {
    var cont = ValidateCtl(ctl, msg, 1, '', tipOverlayId, errOverlayId, lblId, fieldId);
    if (cont) {
        cont = ValidateYearsWorked(ctl, dob_year, allowedYears, msgLegal1, msgLegal2, tipOverlayId, errOverlayId, lblId, fieldId)
    }
    return cont;
}

function ValidateYoeMonthCtl(ctl, yearStart, msg, msg2, tipOverlayId, errOverlayId, lblId, fieldId) {
    var cont = ValidateCtl(ctl, msg, 1, '', tipOverlayId, errOverlayId, lblId, fieldId);
    if (cont) {
        var yr = parseInt(yearStart);
        cont = ValidateMonthsWorked(ctl, yearStart, msg2, tipOverlayId, errOverlayId, lblId, fieldId)
    }
    return cont;
}

function ValidateMonthsWorked(ctl, yearStart, msg, tipOverlayId, errOverlayId, lblId, fieldId) {
    var today = new Date();
    var month = GetValueFromCtl(ctl) - 1;
    if (month < 0) month = 0;
    var yr = today.getFullYear();
    if ( (yearStart > yr) || (yearStart == yr && month > today.getMonth()) ) {
        setErrorBlock(errOverlayId, lblId, fieldId, msg);  
        focusCtrl(ctl);
        validated = false;
        return false;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function ValidateYearsWorked(ctl, dob_year, allowedYears, msg1, msg2, tipOverlayId, errOverlayId, lblId, fieldId) {
    var value = GetValueFromCtl(ctl);
    var today = new Date();
    var validYear = parseInt(dob_year) + parseInt(allowedYears);
    var yearsWorked = parseInt(value) - parseInt(dob_year);
    //if (isInt(dob_year)) {
        if (yearsWorked < allowedYears) {
            //msg = 'You must be at least ' + allowedYears + ' years old to be legally employed. ';
            if (validYear < today.getFullYear())
            {
                //msg = msg + 'Please select a year not earlier than ' + validYear + '.';
                msg = msg1.replace("#allowed_years#", allowedYears);
                msg = msg.replace("#legal_work_year#", validYear);
            }
            else
            {
                //msg = msg + 'Please check that you have entered your date of birth correctly.';
                msg = msg2.replace("#allowed_years#", allowedYears);
            }
            setErrorBlock(errOverlayId, lblId, fieldId, msg);  
            focusCtrl(ctl);
            validated = false;
            return false;
        } else {
            unsetErrorBlock(errOverlayId, lblId, fieldId);  
            return true;
        }
    //}
}

function ValidateYoeText(ctl, msg1, msg2, msg3, msg4, minYear, tipOverlayId, errOverlayId, lblId, fieldId) {
    var value = ctl.value;
    var validYoe = false;
    if (value == '') {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please fill in the year you started working.');
        setErrorBlock(errOverlayId, lblId, fieldId, msg1);
        validated = false;
    } else {
        //validYoe = ValidateReal(ctl, 'Fill in the years in a numeric format.', '', tipOverlayId, errOverlayId, lblId, fieldId);
        validYoe = ValidateReal(ctl, msg2, '', tipOverlayId, errOverlayId, lblId, fieldId);
        if (validYoe) {
            if (String(value).length != 4) {
                //setErrorBlock(errOverlayId, lblId, fieldId, 'Invalid value detected. Please enter in YYYY format.');  
                setErrorBlock(errOverlayId, lblId, fieldId, msg3);
                validated = false;
            } else if (minYear > value) {
                validYoe = true;
                unsetErrorBlock(errOverlayId, lblId, fieldId);  
            } else {
                //setErrorBlock(errOverlayId, lblId, fieldId, 'Please fill in a year later than ' + minYear + '.');
                msg = msg4.replace("#minYear#", minYear);
                setErrorBlock(errOverlayId, lblId, fieldId, msg);
                validYoe = false;
                validated = false;
            }
        } 
    }
    return validYoe;
}

// Work Locations
function checkWL(strFirst, strScd, strThird) {
    var arrKey = ",10000,20000,30000,40000,50000,60000,70000,80000,110000,";
    var noDup = true;
    if (arrKey.indexOf(strFirst) > 0) {
        noDup = checkWLOverlap(strFirst, strScd + "," + strThird);
    }
    if (noDup && (arrKey.indexOf(strScd) > 0)) {
        noDup = checkWLOverlap(strScd, strFirst + "," + strThird);
    }
    if (noDup && (arrKey.indexOf(strThird) > 0)) {
        noDup = checkWLOverlap(strThird, strFirst + "," + strScd);
    }
    return noDup;
}

function checkWLOverlap(strCtry, strOth) {
    var arrCtry = new Array();
    var i;
    var noDup = true;
    if (strCtry != null) {
        arrCtry = eval("pl" + strCtry);
        var intLen = arrCtry.length;
        for (i=0; i< intLen; i++) {
            strTmp = arrCtry[i].substr(2,6);
            if (strTmp.substr(5,1) == "'") strTmp = strTmp.substr(0,5);
            if(strOth.indexOf(strTmp) > -1) {
                noDup = false; break;
            }
        }
    } return noDup;
}

function ValidateWLCtl(optFirst, optScd, optThird, errOverlayId, lblId, fieldId, msg, msg2, msg3) {
    var state1 = optFirst.options[optFirst.selectedIndex].value;
    var state2 = optScd.options[optScd.selectedIndex].value;
    var state3 = optThird.options[optThird.selectedIndex].value;
    if (state1 == '' && state2 == '' && state3 == '') {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please select at least one Work Location.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msg2);
        validated = false;
        return false;
    } 
    else if ((state1 == state2 && state1 != '' && state2 != '')|| (state1 == state3 && state1 != '' && state3 != '') || (state2 == state3 && state2 != '' && state3 != '')) {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please do not select a Work Location more than once.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msg3);
        validated = false;
        return false;
    }
    else if (! checkWL(state1, state2, state3)) {
        alert(msg);  
        return true;
    } else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

// Training Locations
function checkTL(strFirst, strScd) {
    var arrKey = ",10000,20000,30000,40000,50000,60000,70000,80000,110000,";
    var noDup = true;
    if (arrKey.indexOf(strFirst) > 0) {
        noDup = checkTLOverlap(strFirst, strScd);
    }
    if (noDup && (arrKey.indexOf(strScd) > 0)) {
        noDup = checkTLOverlap(strScd, strFirst);
    }
    return noDup;
}

function checkTLOverlap(strCtry, strOth) {
    var arrCtry = new Array();
    var i;
    var noDup = true;
    if (strCtry != null) {
        arrCtry = eval("pl" + strCtry);
        var intLen = arrCtry.length;
        for (i=0; i< intLen; i++) {
            strTmp = arrCtry[i].substr(2,6);
            if (strTmp.substr(5,1) == "'") strTmp = strTmp.substr(0,5);
            if(strOth.indexOf(strTmp) > -1) {
                noDup = false; break;
            }
        }
    } return noDup;
}

function ValidateTLCtl(optFirst, optScd, errOverlayId, lblId, fieldId, msg, msg2, msg3) {
    var state1 = optFirst.options[optFirst.selectedIndex].value;
    var state2 = optScd.options[optScd.selectedIndex].value;
    if (state1 == '' && state2 == '') {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please select at least one Work Location.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msg2);
        validated = false;
        return false;
    } 
    else if (state1 == state2 && state1 != '' && state2 != '') {
        //setErrorBlock(errOverlayId, lblId, fieldId, 'Please do not select a Training Location more than once.');  
        setErrorBlock(errOverlayId, lblId, fieldId, msg3);
        validated = false;
        return false;
    }
    else if (! checkTL(state1, state2)) {
        alert(msg);  
        return true;    
    }
    else {
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function cfHideSR(ctl, msg)
{
    if (ctl.value == "0") {
        var cf = confirm(msg);
        if (! cf) {
            validated = false;
            focusCtrl(ctl);
        }
        return cf;
    }
    return true;
}

// This scans all the onchanged routines
function onFrmSubmit(frm) {
    // force validation of all fields                   
    var i;
    validated = true;
    firstCtrlWithErr = '';  
    var NS4 = (document.layers) ? true : false; 

    for (i=0;i<frm.elements.length;i++) {
        if (frm.elements[i].onchange!=null) {
            if (!NS4) {         
                if (frm.elements[i].style.visibility != 'hidden' && frm.elements[i].disabled == false) {
                    frm.elements[i].onchange();  // force fire onchange event 
                }
            }
        }
    }

    if (validated==true) {    
      frm.submit();
      return validated;
    } else {
        if (firstCtrlWithErr)  { focusCtrl(firstCtrlWithErr); }
    }
}

function validateOption(ctl,msg) {
    var v = false;
    for (var i=0; i<ctl.length; i++) {            
        if (ctl[i].checked) {
            v = true;
                break;
        }
    }
    if ((!v) && (msg!="")) {alert(msg);}
    return v;
}

// function to focus only if control is visible - to avoid IE errors
function focusCtrl(ctrl)
{
    if (firstCtrlWithErr == '') {
        firstCtrlWithErr = ctrl;
    }
    //ctrl.focus();
    try {
        // focus_form_field() is located at Static/common/core/common.js
        if(ctrl.id) {focus_form_field(ctrl.id);} else {focus_form_field(ctrl.name);}
    } catch (e) {
        //do nothing
    }
}

function warnOnlinePayment(pm, msg, msgAlert) {
    var v = true;
    //v = validateOption(pm,"Please select your payment method.");
    v = validateOption(pm,msg);
    if ((v) && (pm[0].checked)) 
        //return confirm("IMPORTANT: \n\nIn order to provide the best security for your online purchase, details of this payment transaction is logged by JobStreet.com, including your IP address, and the date and time of this transaction. \n\nYou are required to use your own credit card to make the purchase. Fraudulent usage of credit cards is an offence and JobStreet.com is obliged to work with the authorities if fraudulent usage is suspected. \n\nSubscribers are fully advised to make their own informed decision before they subscribe to any of these services. Refunds will be given at the sole discretion of JobStreet.com if a subscribed member decides later to unsubscribe from these services. \n\nClick OK to proceed to make your payment.");
        return confirm(msgAlert);
    else
        return v;
}       

function inputNumericOnly(ctl)
{
    var val = Trim(ctl.value);
    var newVal = val.match(/\d+/g);
    if (newVal == null) {
         ctl.value = '';
    } else {
        newVal = newVal.toString();
        if (newVal == 'null') {  ctl.value = ''; }
        else { ctl.value = newVal; }
    }
    
}

function ValidatePostcode(ctl, msg, msgId, tipOverlayId, errOverlayId, lblId, fieldId) {
    var val = Trim(ctl.value);
    if (val == "")
    {
        ctl.value = "";
        setErrorBlock(errOverlayId, lblId, fieldId, msg);
        focusCtrl(ctl);
        validated = false;
        return false;
    }
    else
    {
        val = val.replace(/[^0-9]+/gi, '');
        ctl.value = val;
        unsetErrorBlock(errOverlayId, lblId, fieldId);  
        return true;
    }
}

function validateReferenceContact(ctl, msgEmail, msgEmailTypo, msgTel, errOverlayId, lblId, fieldId, errOverlayId2, lblId2, fieldId2)
{

}
// -->

