﻿/** UTILS ***/
var numbs = '0123456789';
var lowerAlpha = 'abcdefghijklmnopqrstuvwxyz';
var upperAlpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function IsStringEmpty(val) {
    if (null == val)
        return true;

    var trimmed = TrimString(val);
    return 0 == trimmed.length;
}

function StringContains(str, toFind) {
    if (IsStringEmpty(str))
        return false;

    if (IsStringEmpty(toFind))
        return false;

    return -1 != str.indexOf(toFind);
}

function IsPartValid(parm, val) {
    if (null == parm || parm.Length == 0)
        return false;

    for (i = 0; i < parm.length; i++) {
        if (val.indexOf(parm.charAt(i), 0) != -1)
            return true;
    }

    return false;
}

function HasNumber(parm) {
    return IsPartValid(parm, numbs);
}

function HasLower(parm) {
    return IsPartValid(parm, lowerAlpha);
}

function HasUpper(parm) {
    return IsPartValid(parm, upperAlpha);
}

function IsNumberValid(item) {
    var sText = item.value;
    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)
            return false;
    }

    return true;
}

function IsNumericValid(value) {
    var sText = value;
    var ValidChars = ".0123456789";
    var Char;

    if (null == sText)
        return false;

    for (i = 0; i < sText.length; i++) {
        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)
            return false;
    }

    return true;
}

function FormatNumber(number, showThousands) {
    var decimalIndicator = ".";
    var strNum = new String(number);

    if (IsStringEmpty(strNum))
        return "";

    strNum = TrimString(strNum);

    var formatted = "";
    var isFirst = true;
    var decimalPos = -1;
    for (var i = 0; i < strNum.length; ++i) {
        if (isFirst && strNum.charAt(i) == '0')
            continue;
        if (strNum.charAt(i) == decimalIndicator) {
            isFirst = false;
            formatted += strNum.charAt(i);
            decimalPos = i;
        }
        else if (numbs.indexOf(strNum.charAt(i)) != -1) {
            isFirst = false;
            formatted += strNum.charAt(i);
        }
    }

    if (decimalPos == -1)
        formatted += decimalIndicator + "00";
    else if ((formatted.length - decimalPos) == 1)
        formatted += "00";
    else if ((formatted.length - decimalPos) == 2)
        formatted += "0";
    else if ((formatted.length - decimalPos) > 3)
        formatted = formatted.substring(0, decimalPos + 3);

    if (showThousands) {
        decimalPos = formatted.indexOf(decimalIndicator);

        var formattedLeft = formatted.substring(0, decimalPos);
        var formattedRight = formatted.substring(decimalPos + 1);

        if (formattedLeft.length > 3) {
            formatted = "";
            var j = 0;
            for (var i = formattedLeft.length - 1; i >= 0; --i) {
                var f2 = formatted;
                formatted = (j % 3 == 0 && j > 0) ? formattedLeft.charAt(i) + "," + f2 : formattedLeft.charAt(i) + f2;
                ++j;
            }
            formatted += decimalIndicator + formattedRight;
        }
    }

    return formatted;
}

function FormatNumberField(formItemName, showThousands) {
    setElemValue(formItemName, FormatNumber(getElemValue(formItemName), showThousands));
}

function IsFieldEmpty(textObj) {
    if (textObj.value.length == 0)
        return true;
    for (var i = 0; i < textObj.value.length; ++i) {
        var ch = textObj.value.charAt(i);
        if (ch != ' ' && ch != '\t')
            return false;
    }

    return true;
}

function IsEmailValid(em) {
    var aPos = em.value.indexOf("@");
    var dPos = em.value.lastIndexOf(".");
    var adPos = em.value.indexOf("@.");
    var len = em.value.length;

    return (dPos > aPos) && (dPos != (len - 1)) && (aPos > 0) && (adPos == -1);
}

function IsDateValid(date) {
    var ents = date.value.split('-');
    var dd = new Date();
    var curYear = dd.getFullYear();

    if (null == ents || ents.length != 3)
        return false;

    return (((ents[0] > 0) && (ents[0] <= 12)) && ((ents[1] > 0) && (ents[1] <= 31)) && ((ents[2] >= 1900)));
}

// Add usaFormat input parameter as true or false
function IsDateValid(date, usaFormat) {
    var ents = date.value.split('-');
    if (null == ents || ents.length < 3) {
        ents = date.value.split('/');
    }

    if (null == ents || ents.length != 3)
        return false;
        
    var dd = new Date();
    var curYear = dd.getFullYear();

    if (usaFormat == true)
       return (((ents[0] > 0) && (ents[0] <= 12)) && ((ents[1] > 0) && (ents[1] <= 31)) && ((ents[2] >= 1900)));
    return (((ents[1] > 0) && (ents[1] <= 12)) && ((ents[0] > 0) && (ents[0] <= 31)) && ((ents[2] >= 1900)));
}

function IsDateTime(time) {
    var ents = time.value.split(':');

    if (null == ents || ents.length != 3)
        return false;

    return (ents[0] > 0 && ents[0] <= 24) && (ents[1] > 0 && ents[1] <= 60) && (ents[2] > 0 && ents[2] <= 60);
}
function getElem(id, isPopup, isFrame) {
    if (true == isPopup)
        return this.opener.document.getElementById(id);

    if (true == isFrame)
        return this.parent.document.getElementById(id);

    return this.document.getElementById(id);
}


function getElemValue(id, isPopup, isFrame) {
    var e = getElem(id, isPopup, isFrame);

    if (null != e) {
        if (IsMultipleList(e))
            return GetSelectedValues(e);
        if (IsCheckbox(e))
            return e.checked;

        return e.value;
    }
    return null;
}

function setElemValue(id, val, isPopup, isFrame) {
    var e = getElem(id, isPopup, isFrame);

    if (null != e)
        e.value = val;
}

function setElemText(elemID, text, isPopup, isFrame) {
    var e = getElem(elemID, isPopup, isFrame);
    if (null != e) {
        e.style.display = '';
        e.innerHTML = text;
    }
}

function hideElem(elemID, isPopup, isFrame) {
    var e = getElem(elemID, isPopup, isFrame);
    if (null != e) {
        e.style.display = 'none';
    }
}

function hideFormItem(elemID, isPopup, isFrame) {
    hideElem("formItem_" + elemID, isPopup, isFrame);
    hideElem("formItemText_" + elemID, isPopup, isFrame);
}

function showElem(elemID, isPopup, isFrame) {
    var e = getElem(elemID, isPopup, isFrame);
    if (null != e) {
        e.style.display = '';
    }
}

function showFormItem(elemID, isPopup, isFrame) {
    showElem("formItem_" + elemID, isPopup, isFrame);
    showElem("formItemText_" + elemID, isPopup, isFrame);
}

function getFormElem(form, id) {
    return document[form][id];
}

function getMainFormElem(id) {
    return getElem(id); //document.mainForm[id];
}

function TrimString(str) {
    if (str == null)
        return null;

    str = str.replace(/^\s+/g, ""); // strip leading
    return str.replace(/\s+$/g, ""); // strip trailing
}

function nextObject(obj, next, size) {
    if (obj.value.length < size)
        return;

    if (next != null) {
        var toFocus = getMainFormElem(next);
        toFocus.focus();
    }
}
/**
*
* Phone Functions
*
**/

function formatPhoneNumber(phoneNumber, phoneLocale) {
    if (IsStringEmpty(phoneNumber))
        return phoneNumber;

    if (phoneLocale == "US" || phoneLocale == "PR" || phoneLocale == "CA") {
        var formatted = "";
        var numAdded = 0;
        for (var i = 0; i < phoneNumber.length; ++i) {
            if (numbs.indexOf(phoneNumber.charAt(i)) != -1) {
                if (0 == numAdded)
                    formatted += "(";
                if (3 == numAdded)
                    formatted += ") ";
                if (6 == numAdded)
                    formatted += "-";

                formatted += phoneNumber.charAt(i);
                numAdded++;
            }
        }

        return formatted;
    }

    return phoneNumber;
}

function loadPhone(name, val) {
    if (false == isInternationalPhone(name)) {
        if (val.length > 3)
            setElemValue(name + "_phone_first", val.substring(0, 3));
        if (val.length > 6)
            setElemValue(name + "_phone_second", val.substring(3, 6));
        if (val.length == 10)
            setElemValue(name + "_phone_third", val.substring(6, 10));
    }
    else
        setElemValue(name + "_phone_third", val);
}

function setPhone(name) {
    if (null == getElem(name))
        return;

    if (isInternationalPhone(name)) {
        setElemValue(name, getElemValue(name + "_phone_third"));
    }
    else {
        var f = getElemValue(name + "_phone_first");
        var s = getElemValue(name + "_phone_second");
        var t = getElemValue(name + "_phone_third");

        if (IsStringEmpty(f) || IsStringEmpty(s) || IsStringEmpty(t))
            setElemValue(name, '');
        else
            setElemValue(name, f + s + t);
    }
}

function clearPhone(name) {
    setElemValue(name + "_phone_first", '');
    setElemValue(name + "_phone_second", '');
    setElemValue(name + "_phone_third", '');
    setElemValue(name, '');
}

function isInternationalPhone(formName, isPopup, isFrame) {
    var phoneLocale = getElemValue(formName + "_locale", isPopup, isFrame);
    if (IsStringEmpty(phoneLocale))
        return false;

    phoneLocale = phoneLocale.toLowerCase();

    return (phoneLocale != "us" && phoneLocale != "pr" && phoneLocale != "ca");
}

function nextPhoneObject(obj, name, formName) {
    if (null == obj || null == formName)
        return;

    var next = null;
    var doFocus = false;

    if (isInternationalPhone(formName)) {
        setPhone(formName);
        return;
    }

    if ("first" == name) {
        doFocus = obj.value.length >= 3;
        next = getElem(formName + "_phone_second");
    }
    else if ("second" == name) {
        doFocus = obj.value.length >= 3;
        next = getElem(formName + "_phone_third");
    }
    else if ("third" == name) {
        doFocus = obj.value.length >= 4;
        setPhone(formName);
    }

    if (true == doFocus && next != null)
        FocusOnItem(next);
}

function setPhoneLocale(name, locale, isPopup, isFrame) {
    clearPhone(name);
    setElemValue(name + "_locale", locale, isPopup, isFrame);

    if (isInternationalPhone(name)) {
        hideElem(name + "_phone_dash", isPopup, isFrame);
        hideElem(name + "_phone_right_paran", isPopup, isFrame);
        hideElem(name + "_phone_left_paran", isPopup, isFrame);
        hideElem(name + "_phone_first", isPopup, isFrame);
        hideElem(name + "_phone_second", isPopup, isFrame);

        getElem(name + "_phone_third").maxLength = 20;
        getElem(name + "_phone_third").className = "basic";
    }
    else {
        showElem(name + "_phone_dash", isPopup, isFrame);
        showElem(name + "_phone_right_paran", isPopup, isFrame);
        showElem(name + "_phone_left_paran", isPopup, isFrame);
        showElem(name + "_phone_first", isPopup, isFrame);
        showElem(name + "_phone_second", isPopup, isFrame);

        getElem(name + "_phone_third").maxLength = 4;
        getElem(name + "_phone_third").className = "phoneThird";
    }
}

function IsPhoneValid(item) {
    var sText = item.value;
    var ValidChars = "0123456789";

    sText = TrimString(sText);

    /* non-international numbers must be 10 numbers
    */
    if (false == isInternationalPhone(item.name) && sText.length != 10)
        return false;

    for (var i = 0; i < sText.length; i++) {
        if (ValidChars.indexOf(sText.charAt(i)) == -1)
            return false;
    }

    return true;
}

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 ltrim(stringToTrim) {
    return stringToTrim.toString().replace(/^\s+/, "");
    }

function rtrim(stringToTrim) {
    return stringToTrim.toString().replace(/\s+$/, "");
    }

function trim(stringToTrim) {
    return rtrim(ltrim(stringToTrim));
    }

function GetErrorMessage(fTextID) {

    var total = 0;

    if (fTextID == null) {
        return "";
    }
    if (ClientMessages == undefined) {
        return "***";
    }
    if (ClientMessages == null) {
        return "???" + fTextID;
    }
    if (ClientMessages == undefined) {
        return "???"+fTextID;
    }
    if (ClientMessages != 'undefined') {
        for (var i = 0; i < ClientMessages.length; i++) {
            if (fTextID == ClientMessages[i][0]) {
                return ClientMessages[i][1];
            }
        }
    }
    return "???"+fTextID;
}

function GetClientMessageByID(ID) {
    return GetErrorMessage(ID);
}

function MouseOverLabel(lbl) {
    lbl.focus();
    lbl.style.cursor = 'pointer';
    lbl.style.color = '#c2fe80';

}
function MouseOutLabel(lbl) {
    lbl.style.color = '#fff';
    lbl.blur();
}

function IsUKorUSCountrySelected(fCountryID) {
    if (fCountryID == undefined) {
        return false;
    }
    if (fCountryID == "105" /*US*/ || 
        fCountryID == "10912" /*UK*/) {
        return true;
    }
    return false;
}

function LangSupportCalendar() {
    var lang = _LANGUAGE_ABBREV;
    if (lang != null) {
        lang = lang.toLowerCase();
        if (lang == 'en') {
            lang = '';
        }
        if (lang != 'de' && lang != 'es' && lang != 'eu' && lang != 'fr' && lang != 'it' && lang != 'pl') {
            lang = ''; // English
        }
    }
    else {
        lang = '';
    }
    return lang;
} //LangSupportCalendar

function GetFocusControlID(e) {
    var ID = "";
    try {
        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            ID = e.target.id;
        }
        else {
            ID = e.srcElement.id;
        }
    }
    catch (err) {
        ID = "";
    }
    return ID;
} //GetFocusControlID


/**** PASSWORD METER *****/
   /**
    * Calculates the strength of a password
    * @param {Object} p The password that needs to be calculated
    * @return {int} intScore The strength score of the password
    */
function CalcStrength(p)
{
        var intScore = 0;

        // PASSWORD LENGTH
        //intScore += p.length;

        if (p.length > 0 && p.length <= 7) {                    // length 4 or less
            intScore += 5;
        }
        //        else if (p.length >= 5 && p.length <= 7) {	// length between 5 and 7
        //            intScore += 10;
        //        }
        else if (p.length >= 8) {	// length between 8 and 15
            intScore += 25;
            //alert(intScore);
        }
        //        else if (p.length >= 16) {               // length 16 or more
        //            intScore += 18;
        //            //alert(intScore);
        //        }

        // LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
        if (p.match(/[a-z]{1,}/)) {              // [verified] at least one lower case letter
            intScore += 10;
        }
        if (p.match(/[A-Z]{1,}/)) {              // [verified] at least one upper case letter
            intScore += 10;
        }
        // NUMBERS
        if (p.match(/\d{1,}/)) {             	// [verified] at least one number
            intScore += 10;
        }
        if (p.match(/\d{4,}/)) {             	// [verified] at least one number
            intScore += 20;
        }
        //        if (p.match(/.*\d.*\d.*\d/)) {            // [verified] at least three numbers
        //            intScore += 5;
        //        }

        // SPECIAL CHAR
        if (p.match(/[\W]{1}/)) {           // [verified] at least one special character
            intScore += 10;
        }
        // [verified] at least two special characters
        if (p.match(/[\W]{2,}/)) {
            intScore += 25;
        }

        if (p.match(/[a-zA-Z]{1,}/) && p.match(/\d{1,}/)) {
            intScore += 2;
        }

        if (p.match(/[a-zA-Z]{1,}/) && p.match(/\d{1,}/) && p.match(/[\W]{1,}/)) {
            intScore += 3;
        }

        if (p.match(/[a-z]{1,}/) && p.match(/[A-Z]{1,}/) && p.match(/\d{1,}/) && p.match(/[\W]{1,}/)) {
            intScore += 5;
        }
        return intScore;
    }


function CheckPasswordStrength2(element, divScoreBar, divScoreImage, divScore, divComplexity) 
{
        var score = 0
        var password = element.value;
        var oScorebar = this.$get(divScoreBar);
        var imgScoreBar = this.$get(divScoreImage);
        //oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) * 1.75 + "px";
        // start: width: 270px; and margin: 0 0 0 0
        //var maxWidth = 270;
        var maxWidth = imgScoreBar.clientWidth;

        var nScore = this.CalcStrength(password);

        // Set new width
        var nRound = Math.round(nScore);

        if (nRound > 100) {
            nRound = 100;
        }

        var scoreWidth = ((maxWidth / 100) * (100 - nRound)) ? (maxWidth / 100) * (100 - nRound) : 0;
        var scoreLeftMargin = maxWidth - Math.round(scoreWidth);
        //        oScorebar.style.width = Math.round(scoreWidth) + "px";
        //        oScorebar.style.margin = "0 0 0 " + scoreLeftMargin + "px";
        $('#' + divScoreBar).animate({
            width: Math.round(scoreWidth),
            marginLeft: scoreLeftMargin,
            easing: "swing"
            //queue: false
        }, 200);
        //oScorebar.style.margin = "0 0 0 " + scoreLeftMargin + "px";
    }

    /*********************************Password Strength Checker**********************************************/

    /// Function: CheckPasswordStrength(e, element, divScoreBar, divScore, divComplexity); 
    /// Desc:Password Strength Checker for form 'scorebar', 'score', 'complexity' are the divs added in the form.Also image is needed to update the coloring scheme
    /// Usage:fv.CheckPasswordStrength(e, '<%=TxtPassword.ClientID %>', 'scorebar', 'score', 'complexity');
 function CheckPasswordStrength(e, element, divScoreBar, divScore, divComplexity) 
 {
        element = this.$get(element);
        var fv = new eWires.Utility.FormValidator();
        var oPasswordElement = this.$get(element);
        var oScorebar = this.$get(divScoreBar);
        var oScore = this.$get(divScore);
        var oComplexity = this.$get(divComplexity);
        var pwd = oPasswordElement.value;
        var nScore = 0;
        var nLength = 0;
        var nAlphaUC = 0;
        var nAlphaLC = 0;
        var nNumber = 0;
        var nSymbol = 0;
        var nMidChar = 0;
        var nRequirements = 0;
        var nAlphasOnly = 0;
        var nNumbersOnly = 0;
        var nRepChar = 0;
        var nConsecAlphaUC = 0;
        var nConsecAlphaLC = 0;
        var nConsecNumber = 0;
        var nConsecSymbol = 0;
        var nConsecCharType = 0;
        var nSeqAlpha = 0;
        var nSeqNumber = 0;
        var nSeqChar = 0;
        var nReqChar = 0;
        var nReqCharType = 3;
        var nMultLength = 4;
        var nMultAlphaUC = 3;
        var nMultAlphaLC = 3;
        var nMultNumber = 4;
        var nMultSymbol = 6;
        var nMultMidChar = 2;
        var nMultRequirements = 2;
        var nMultRepChar = 1;
        var nMultConsecAlphaUC = 2;
        var nMultConsecAlphaLC = 2;
        var nMultConsecNumber = 2;
        var nMultConsecSymbol = 1;
        var nMultConsecCharType = 0;
        var nMultSeqAlpha = 3;
        var nMultSeqNumber = 3;
        var nTmpAlphaUC = "";
        var nTmpAlphaLC = "";
        var nTmpNumber = "";
        var nTmpSymbol = "";
        var sAlphaUC = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sAlphaLC = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sNumber = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sSymbol = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sMidChar = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sRequirements = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sAlphasOnly = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sNumbersOnly = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sRepChar = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sConsecAlphaUC = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sConsecAlphaLC = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sConsecNumber = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sSeqAlpha = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sSeqNumber = "&nbsp;&nbsp;&nbsp;&nbsp;0";
        var sAlphas = "abcdefghijklmnopqrstuvwxyz";
        var sNumerics = "01234567890";
        var sComplexity = "Too Short";
        var sStandards = "Below";
        var nMinPwdLen = 8;

        if (pwd) {
            nScore = parseInt(pwd.length * nMultLength);
            nLength = pwd.length;
            var arrPwd = pwd.replace(/\s+/g, "").split(/\s*/);
            var arrPwdLen = arrPwd.length;

            /* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */
            for (var a = 0; a < arrPwdLen; a++) {
                if (arrPwd[a].match(new RegExp(/[A-Z]/g))) {
                    if (nTmpAlphaUC !== "") { if ((nTmpAlphaUC + 1) == a) { nConsecAlphaUC++; nConsecCharType++; } }
                    nTmpAlphaUC = a;
                    nAlphaUC++;
                }
                else if (arrPwd[a].match(new RegExp(/[a-z]/g))) {
                    if (nTmpAlphaLC !== "") { if ((nTmpAlphaLC + 1) == a) { nConsecAlphaLC++; nConsecCharType++; } }
                    nTmpAlphaLC = a;
                    nAlphaLC++;
                }
                else if (arrPwd[a].match(new RegExp(/[0-9]/g))) {
                    if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
                    if (nTmpNumber !== "") { if ((nTmpNumber + 1) == a) { nConsecNumber++; nConsecCharType++; } }
                    nTmpNumber = a;
                    nNumber++;
                }
                else if (arrPwd[a].match(new RegExp(/[^a-zA-Z0-9_]/g))) {
                    if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
                    if (nTmpSymbol !== "") { if ((nTmpSymbol + 1) == a) { nConsecSymbol++; nConsecCharType++; } }
                    nTmpSymbol = a;
                    nSymbol++;
                }
                /* Internal loop through password to check for repeated characters */
                for (var b = 0; b < arrPwdLen; b++) {
                    if (arrPwd[a].toLowerCase() == arrPwd[b].toLowerCase() && a != b) { nRepChar++; }
                }
            }

            /* Check for sequential alpha string patterns (forward and reverse) */
            for (var s = 0; s < 23; s++) {
                var sFwd = sAlphas.substring(s, parseInt(s + 3));
                var sRev = sFwd.strReverse();
                if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqAlpha++; nSeqChar++; }
            }

            /* Check for sequential numeric string patterns (forward and reverse) */
            for (var s = 0; s < 8; s++) {
                var sFwd = sNumerics.substring(s, parseInt(s + 3));
                var sRev = sFwd.strReverse();
                if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqNumber++; nSeqChar++; }
            }

            /* Modify overall score value based on Usage: vs requirements */

            /* General point assignment */
            if (nAlphaUC > 0 && nAlphaUC < nLength) {
                nScore = parseInt(nScore + ((nLength - nAlphaUC) * 2));
                sAlphaUC = "+ " + parseInt((nLength - nAlphaUC) * 2);
            }
            if (nAlphaLC > 0 && nAlphaLC < nLength) {
                nScore = parseInt(nScore + ((nLength - nAlphaLC) * 2));
                sAlphaLC = "+ " + parseInt((nLength - nAlphaLC) * 2);
            }
            if (nNumber > 0 && nNumber < nLength) {
                nScore = parseInt(nScore + (nNumber * nMultNumber));
                sNumber = "+ " + parseInt(nNumber * nMultNumber);
            }
            if (nSymbol > 0) {
                nScore = parseInt(nScore + (nSymbol * nMultSymbol));
                sSymbol = "+ " + parseInt(nSymbol * nMultSymbol);
            }
            if (nMidChar > 0) {
                nScore = parseInt(nScore + (nMidChar * nMultMidChar));
                sMidChar = "+ " + parseInt(nMidChar * nMultMidChar);
            }

            /* Point deductions for poor practices */
            if ((nAlphaLC > 0 || nAlphaUC > 0) && nSymbol === 0 && nNumber === 0) {  // Only Letters
                nScore = parseInt(nScore - nLength);
                nAlphasOnly = nLength;
                sAlphasOnly = "- " + nLength;
            }
            if (nAlphaLC === 0 && nAlphaUC === 0 && nSymbol === 0 && nNumber > 0) {  // Only Numbers
                nScore = parseInt(nScore - nLength);
                nNumbersOnly = nLength;
                sNumbersOnly = "- " + nLength;
            }
            if (nRepChar > 0) {  // Same character exists more than once
                nScore = parseInt(nScore - (nRepChar * nRepChar));
                sRepChar = "- " + nRepChar;
            }
            if (nConsecAlphaUC > 0) {  // Consecutive Uppercase Letters exist
                nScore = parseInt(nScore - (nConsecAlphaUC * nMultConsecAlphaUC));
                sConsecAlphaUC = "- " + parseInt(nConsecAlphaUC * nMultConsecAlphaUC);
            }
            if (nConsecAlphaLC > 0) {  // Consecutive Lowercase Letters exist
                nScore = parseInt(nScore - (nConsecAlphaLC * nMultConsecAlphaLC));
                sConsecAlphaLC = "- " + parseInt(nConsecAlphaLC * nMultConsecAlphaLC);
            }
            if (nConsecNumber > 0) {  // Consecutive Numbers exist
                nScore = parseInt(nScore - (nConsecNumber * nMultConsecNumber));
                sConsecNumber = "- " + parseInt(nConsecNumber * nMultConsecNumber);
            }
            if (nSeqAlpha > 0) {  // Sequential alpha strings exist (3 characters or more)
                nScore = parseInt(nScore - (nSeqAlpha * nMultSeqAlpha));
                sSeqAlpha = "- " + parseInt(nSeqAlpha * nMultSeqAlpha);
            }
            if (nSeqNumber > 0) {  // Sequential numeric strings exist (3 characters or more)
                nScore = parseInt(nScore - (nSeqNumber * nMultSeqNumber));
                sSeqNumber = "- " + parseInt(nSeqNumber * nMultSeqNumber);
            }


            /* Determine complexity based on overall score */
            if (nScore > 100) { nScore = 100; } else if (nScore < 0) { nScore = 0; }
            if (nScore >= 0 && nScore < 20) { sComplexity = "Very Weak"; }
            else if (nScore >= 20 && nScore < 40) { sComplexity = "Weak"; }
            else if (nScore >= 40 && nScore < 60) { sComplexity = "Good"; }
            else if (nScore >= 60 && nScore < 80) { sComplexity = "Strong"; }
            else if (nScore >= 80 && nScore <= 100) { sComplexity = "Very Strong"; }

            /* Display updated score criteria to client */
            oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) * 1.75 + "px";
            //oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) + "px";
            if (this.trace)
                Sys.Debug.trace("oScorebar.style.backgroundPosition: " + oScorebar.style.backgroundPosition);
            if (nScore == 100) {
                //oScorebar.style.backgroundPosition="400% 100%";
            }
            oScore.innerHTML = nScore + "%";
            oComplexity.innerHTML = sComplexity;
        }
        else {
            /* Display default score criteria to client */
            this.InitPwdChk(true, oPasswordElement, oScorebar);
            oScore.innerHTML = nScore + "%";
            oComplexity.innerHTML = sComplexity;
        }
    }

 function InitPwdChk(restart, element, scoreBar) 
 {
    /* Reset all form values to their default */
    if (element != null) {
        element.value = "";
        scoreBar.style.backgroundPosition = "0";
        if (restart) {
            //scoreBar.className = "";
        }
    }
}


function GetNextControl(forwardDirection, Fields, ctl) {
    if (forwardDirection == true)
        return GetNextControlForward(Fields, ctl);
    return GetNextControlBackward(Fields, ctl);
}

function GetNextControlBackward(Fields, ctl) {
    if (Fields != undefined) {
        for (i = 0; i < Fields.length; i++) {
            if (ctl == Fields[i]) {
                if (i == 0) {
                    return Fields[Fields.length - 1];
                }
                return Fields[i - 1];
            }
        }
    }
    return Fields[Fields.length - 1];
} //GetNextControlBackward

function GetNextControlForward(Fields, ctl) {
    if (Fields != undefined) {
        for (i = 0; i < Fields.length; i++) {
            if (ctl == Fields[i]) {
                if (i == (Fields.length - 1)) {
                    return Fields[0];
                }
                else {
                    return Fields[i + 1];
                }
            }
        }
    }
    return Fields[0];
} // GetNextControlForward

//SCR#1040411
function PrepaidProducts() {
    document.location = "../Content/PrepaidProducts.aspx";
}

function SetControlFocus(id) {
    var ctl = $get(id);
    if (ctl != null) {
        try
        {
            ctl.focus();
            SetCursorToTextEnd(id);
        }
        catch (err) { return false; }
        return true;
    }
    return false;
}// SetControlFocus

function SetCursorToTextEnd(textControlID) {
    var text = document.getElementById(textControlID);
    if (text != null) {
        if (text.type != 'text') return;
        var endPos = 1;
        if (document.selection) {
            endPos = text.value.length;
            var range = document.selection.createRange();
            range.moveStart('character', endPos);
            range.collapse();
            range.select();
        }
        else if (window.getSelection) {

            var range = window.getSelection().getRangeAt(0);
            if (range.startContainer.nodeName == "#text") {
                endPos = text.value.length;
                range.setStart(range.startContainer, endPos);
                range.setEnd(range.startContainer, endPos);
            }
            else {
                window.getSelection().removeAllRanges();
                var div = document.createRange();
                if (text.childNodes.length > 0 && text.childNodes[0].nodeName == "#text") {
                    endPos = text.value.length;
                    div.setStart(text.childNodes[0], endPos);
                    div.setEnd(text.childNodes[0], endPos);
                    window.getSelection().addRange(div);
                }
            }


        }
    }
}

function openBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}

function openBrModalWindow(theURL, winName, label) {
    var sLabel = label;
    var sBrowser = navigator.appName;


    if (sBrowser == "Microsoft Internet Explorer") {
        if (sLabel == 1) {
            features = 'dialogHeight:340px; dialogWidth:350px; dialogTop=200px; dialogLeft=200px; status=off; scroll=no;'
        }
        else {
            features = 'dialogHeight:390px; dialogWidth:380px; dialogTop=200px; dialogLeft=200px; status=off; scroll=no;'
        }

        window.showModalDialog(theURL, winName, features);
    }
    else {
        if (sLabel == 1) {
            features = 'width=375,height=325,top=20,left=20,status=no,menubar=no'
        }
        else {
            features = 'width=425,height=350,top=20,left=20,status=no,menubar=no'
        }
        window.open(theURL, winName, features);
    }
}

/*Exepecting a control object */
function IsSameAsUSAPhoneFormatC(ctl)
{
  if (ctl.value == null || ctl.value == "") return false;
  if (ctl.value == "105" || //USA
      ctl.value == "605" || // Canada
      ctl.value == "11711" || // Puerto Rico
      ctl.value == "9005") // //Dominican Republic
    {
        return true;
    }
    return false;
} // IsSameAsUSAPhoneFormatC

function IsSameAsUSAPhoneFormatN(num) {
    if ( num == undefined || num == null) return false;
    if (num == 105 || //USA
        num == 605 || // Canada
        num == 11711 || // Puerto Rico
        num == 9005) // //Dominican Republic
    {
        return true;
    }
    return false;
} // IsSameAsUSAPhoneFormatN

function ValidateInputDate(id) {
    if (id.value == "") return;
    // Validate
    var today = new Date();
    var validDate = false;
    if (_COUNTRY_ID == "105")
        validDate = IsDateValid(id, true);
    else
        validDate = IsDateValid(id);
    if (validDate == false) {
        alert(GetErrorMessage(1525)); // Invalid Date Format.
        id.value = "";
        return;
    }
    var xDate = new Date(id.value);
    if (xDate > today) {
        alert(GetErrorMessage(1524));
        id.value = "";
    }
} //ValidateInputDate

function ValidateInputBirthDate(id) {
    if (id.value == "") return;
    // Validate
    var today = new Date();
    var validDate = false;
    if (_COUNTRY_ID == "105")
        validDate = IsDateValid(id, true);
    else
        validDate = IsDateValid(id);
    if (validDate == false) {
        alert(GetErrorMessage(1525)); // Invalid Date Format.
        id.value = "";
        return;
    }
    var xDate = new Date(id.value);
    if (xDate > today) {
        alert(GetErrorMessage(1524)); //The entered date is in the future. Please enter or select a different date.
        //alert(GetErrorMessage(1532)); // Please enter/select a date that is not within 18 years of the current date.
        id.value = "";
        return;
    }
    var todayMinus18 = new Date();
    todayMinus18.setYear(today.getYear() - 18);
    if (xDate >= todayMinus18) {
        //alert(GetErrorMessage(1524));//The entered date is in the future. Please enter or select a different date.
        alert(GetErrorMessage(1532)); // Please enter/select a date that is not within 18 years of the current date.
        id.value = "";
        return;
    }    
} //ValidateInputBirthDate

function ClearReminderInput() {
    var lblError = $get("ctl00_ContentPlaceHolder1_lblReminder");
    if (null != lblError) {
        lblError.innerHTML = "&nbsp;";
    }
}
function CheckReminderInput(txt) {
    if (txt.className == "textfield-reminder" || txt.className == "textfield-long-reminder" || txt.className == "textfield-long-fullreminder") {
        if (txt.id == "ctl00_ContentPlaceHolder1_txtAddress") { // Reset the text control
            txt.className = "textfield-long";
        }
        else {
            txt.className = "textfield";
        }
        txt.value = "";
    }
    if (txt.className == "dropdown-reminder") {
        txt.className = "dropdown";
    }
    ClearReminderInput();
}

function NumbersOnly() {
    if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 8) || (event.keyCode == 9))
        return true;
    else
        return false;
} //NumbersOnly

