﻿// JScript File

var POOR_LENGTH = 5;
var FAIR_LENGTH = 6;

function hideStrengthIndicatorDiv() {
    document.getElementById('strengthIndicatorParent').style.display = "none";
    document.getElementById('strengthIndicator').style.display = "none";
    document.getElementById('strengthIndicatorText').style.display = "none";
}
function checkStrength() {
    var regDigits = new RegExp("\\d");
    var regSpecialCharacters = new RegExp("\\W");
    var regAlphabets = new RegExp("[\\a-zA-Z]");

    var val = document.getElementById('txtPassword').value;
    document.getElementById('strengthIndicatorParent').style.display = "";
    document.getElementById('strengthIndicator').style.display = "";
    document.getElementById('strengthIndicatorText').style.display = "";
    document.getElementById('strengthIndicatorParent').className = "divPasswordStrength";

    if (val.length <= POOR_LENGTH) {
        setPoor();
    }
    else if (val.length >= FAIR_LENGTH) {
        setFair();
    }

    if ((val.length >= FAIR_LENGTH && val.match(regDigits)) || (val.length >= FAIR_LENGTH && val.match(regDigits) && val.match(regSpecialCharacters))) {
        setGood();
    }

    if ((val.length >= FAIR_LENGTH && val.match(regDigits)) && (val.match(regSpecialCharacters) && val.match(regAlphabets))) {
        setStrong();
    }

}

function setGood() {
    document.getElementById('strengthIndicator').className = "strengthGood";
    document.getElementById('strengthIndicatorText').className = "strengthIndicatorTextGood";
    document.getElementById('strengthIndicatorText').innerHTML = "Good";
}
function setStrong() {
    document.getElementById('strengthIndicator').className = "strengthStrong";
    document.getElementById('strengthIndicatorText').className = "strengthIndicatorTextStrong";
    document.getElementById('strengthIndicatorText').innerHTML = "Strong";
}
function setFair() {
    document.getElementById('strengthIndicator').className = "strengthAverage";
    document.getElementById('strengthIndicatorText').className = "strengthIndicatorTextAverage";
    document.getElementById('strengthIndicatorText').innerHTML = "Fair";
}
function setPoor() {
    document.getElementById('strengthIndicator').className = "strengthPoor";
    document.getElementById('strengthIndicatorText').className = "strengthIndicatorTextPoor";
    document.getElementById('strengthIndicatorText').innerHTML = "Too short"
}


function Trim(val) {
    val = val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    return val;
}


function emailCheck(emailStr) {

    /*	The following pattern is used to check if the entered e-mail address fits the user@domain format.  
    It also is used to separate the username from the domain. 
    */
    var emailPat = /^(.+)@(.+)$/;

    /*	The following string represents the pattern for matching all special characters.  We don't want to allow 
    special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ]    
    */
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

    /*	The following string represents the range of characters allowed in a username or domainname.  
    It really states which chars aren't allowed. 
    */
    var validChars = "\[^\\s" + specialChars + "\]";

    /*	The following pattern applies if the "user" is a quoted string (in which case, there are no rules about 
    which characters are allowed and which aren't; anything goes).  
    E.g. "jiminy cricket"@disney.com is a legal e-mail address. 
    */
    var quotedUser = "(\"[^\"]*\")";

    /*	The following pattern applies for domains that are IP addresses, rather than symbolic names.  
    E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. 
    */
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /*	The following string represents an atom (basically a series of non-special characters.) 
    */
    var atom = validChars + '+';

    /*	The following string represents one word in the typical username. For example, in john.doe@somewhere.com, 
    john and doe are words. Basically, a word is either an atom or quoted string. 
    */
    var word = "(" + atom + "|" + quotedUser + ")";

    //	The following pattern describes the structure of the user
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");

    /*	The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, 
    shown above. 
    */
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. 
    */
    var matchArray = emailStr.match(emailPat);

    if (matchArray == null) {
        /*	Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid 
        e-mail address. 
        */
        //alert("Email address seems incorrect (check @ and .'s)")
        return false;
    }
    var user = matchArray[1];
    var domain = matchArray[2];

    // See if "user" is valid 
    if (user.match(userPat) == null) {
        // user is not valid
        //alert("The Email address doesn't seem to be valid.")
        return false;
    }

    /*	if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address 
    is valid. 
    */
    var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
        // this is an IP address
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                //alert("Destination IP address is invalid!")
                return false;
            }
        }
        return true;
    }

    // Domain is symbolic name
    var domainArray = domain.match(domainPat);
    if (domainArray == null) {
        //alert("The domain name doesn't seem to be valid.")
        return false;
    }

    /*	domain name seems valid, but now make sure that it ends in a three-letter word (like com, edu, gov) 
    or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain 
    or country. 
    */

    /* Now we need to break up the domain to get a count of how many atoms it consists of. */

    var atomPat = new RegExp(atom, "g");
    var domArr = domain.match(atomPat);
    var len = domArr.length;
    if (domArr[domArr.length - 1].length < 2 ||
		domArr[domArr.length - 1].length > 3) {
        // the address must end in a two letter or three letter word.
        //alert("The address must end in a three-letter domain, or two letter country.")
        return false;
    }

    // Make sure there's a host name preceding the domain.
    if (len < 2) {
        var errStr = "This address is missing a hostname!";
        //alert(errStr)
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;

}
function js_CheckEnterClick(btnId, e) {
    if (window.event) // IE
    {
        if (event.keyCode && event.keyCode == 13) {
            document.getElementById(btnId).focus();
        }
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        if (e.which && e.which == 13) {
            document.getElementById(btnId).focus();
        }
    }
}

function toggleOptionalInfo() {
    var optionalInfo = document.getElementById("divOptional");

    if (optionalInfo.style.display == 'none') {
        optionalInfo.style.display = '';
        document.getElementById("spnOptionalInfoText").innerHTML = "";
    }
    else {
        optionalInfo.style.display = 'none';
        document.getElementById("spnOptionalInfoText").innerHTML = "Expand for Optional Info >>";
    }
    return false;

}

function ValidateControl(ctrl, errorCtrl, errorMsg, ctrlType) {
    var valid = false;
    switch (ctrlType) {
        case "text":
            if (Trim(ctrl.value) != "") {
                valid = true;
            }
            break;
        case "dropdown":
            if (ctrl.selectedIndex != 0) {
                valid = true;
            }
            break;
        case "richtext":
            var val = ctrl.innerHTML;
            if (Trim(val).replace(/&nbsp;/g, '') != "") {
                valid = true;
            }
            val = val.toUpperCase().replace("<P>&NBSP;</P>", "")
            val = val.toUpperCase().replace("<BR>\N", "");
            
            if (Trim(val) == "") {
                valid = false;
            }
            break;
    }
    if (valid) {
        HideErrorMsg(errorCtrl);
    }
    else {
        ShowErrorMsg(errorCtrl, errorMsg)
    }
    return valid;
}
function ShowErrorMsg(errorCtrl, errorMsg) {
    errorCtrl.style.display = "block";
    errorCtrl.innerHTML = errorMsg;
}
function HideErrorMsg(errorCtrl) {
    errorCtrl.style.display = "none";
}


function validateContactUs() {

    if (trimAll(document.getElementById('txtName').value) == '') {
        CreateCordiantAlert("Contact Us", "<div style='color:red'>Please enter your Name.</div>", "txtName");
        return false;
    }
    if (trimAll(document.getElementById('txtEmail').value) == '') {
        CreateCordiantAlert("Contact Us", "<div style='color:red'>Please enter your Email.</div>", "txtEmail");
        return false;
    }
    if (!emailCheck(trimAll(document.getElementById('txtEmail').value))) {
        CreateCordiantAlert("Contact Us", "<div style='color:red'>Please enter a valid Email address.</div>", "txtEmail");

        return false;
    }
    if (trimAll(document.getElementById('txtQueries').value) == '') {
        CreateCordiantAlert("Contact Us", "<div style='color:red'>Please enter your Queries/ Comments.</div>", "txtQueries");
        return false;
    }
    return true;
}
function restrictTo(obj, num) {
    num = num - 1;
    if (obj.value.length > num) {
        obj.value = obj.value.substring(0, num);
        alert("Please enter a short message, field is limited to " + num + " characters.");
        if (obj.value.length == num) {
            return false;
        }
    }
    else
        return true;
}

function ExpandCollapse(clientID) {
    var lblStateComp = document.getElementById('lblExpandCollapse');
    var currentState = lblStateComp.innerHTML;
    if (currentState == "+") {
        lblStateComp.innerHTML = "-";
        document.getElementById('lstOtherLocations').style.display = "";
        
    }
    else {

        lblStateComp.innerHTML = "+";
        document.getElementById('lstOtherLocations').style.display = "none";
        var chkBoxList = document.getElementById(clientID);
        var chkBoxCount = chkBoxList.getElementsByTagName("input");
        for (var i = 0; i < chkBoxCount.length; i++) {
            chkBoxCount[i].checked = false;
        }

    }
    return false;
}
function ToggleEmployerDetails(obj) {
    if (obj[obj.selectedIndex].value == "E" || obj[obj.selectedIndex].value == "B") {
        document.getElementById('divCompanyDetails').style.display = "";
    }
    else {
        document.getElementById('divCompanyDetails').style.display = "none";
    }

}

function RestorePage() {
    history.back();
    return false;
}