// Activate Cloaking Device
var iPasswordLen;
var iUserNameLen;
var iLoginNameLen;
var strDebug;
var objFocus;
var lVersion;
var bValidEntry;
var TRUE;
var FALSE;

iPasswordLen = 10; 	// password length
iLoginNameLen = 12; 	// user name length
iFirstNameLen = 12; 	// user name length
lVersion = "2k0605"; // Version number
TRUE = 1; 	// boolean TRUE
FALSE = 0; 	// boolean FALSE

// this function takes a string a makes into an array of values
// based on a delimiter!
function explodeArray(item, delimiter) {
    tempArray = new Array(1);
    var Count = 0;
    var tempString = new String(item);

    while (tempString.indexOf(delimiter) > 0) {
        tempArray[Count] = tempString.substr(0, tempString.indexOf(delimiter));
        tempString = tempString.substr(tempString.indexOf(delimiter) + 1, tempString.length - tempString.indexOf(delimiter) + 1);
        Count = Count + 1;
    }

    tempArray[Count] = tempString;
    return tempArray;
}

function parsePara(value) {
    //Breaks apart words longer than 75 characters!
    //Validate paragraph! Make sure no word is over 75 characters long!
    var strPara = new String(value);
    var j = 0;

    for (var i = 0; i < strPara.length; i++) {
        if (strPara.charAt(i) == ' ') {
            j = 0;
            continue;
        }
        j++;

        if (j == 75) {
            strPara = strPara.substring(0, i) + ' ' + strPara.substring(i + 1, strPara.length);
            j = 0;
            i++;
        }
    }
    return strPara;
}

function gjVerifyIsNumber(strValue, strMessage, objFocus) {
    // Function:	Verifies field is number! Uses regular expressions if enabled!
    // Inputs:		strValue (value to check!),
    //					strMessage (message text, if "", will not pop message box),
    //					objFocus (focus on this object if false, if "", will not set focus).
    // Returns:		Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    bReturn = TRUE;

    if (window.RegExp) {
        //Browser supports regular expressions!
        var objRegExp = /^\d+$/

        if (!objRegExp.test(strValue))
            bReturn = FALSE;
    }
    else {
        //Browser doesn't support regular expressions! Use loop method!
        var checkOK = '1234567890';
        var bAllValid = true;

        for (i = 0; i < strValue.length; i++) {
            ch = strValue.charAt(i);
            for (j = 0; j < checkOK.length; j++) {
                if (ch == checkOK.charAt(j))
                    break;
            }
            if (j == checkOK.length) {
                bAllValid = false;
                break;
            }
        }

        if (!bAllValid)
            bReturn = FALSE;
    }

    if (bReturn == FALSE) {
        if (strMessage != "")
            alert(strMessage);
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
    }

    return bReturn;
}

function specialCharacters(strField, specialChars, strMessageTitle, strMessage, objFocus) {
    // Function:	Checks against special numbers and characters! Fields can only have these characters or error is returned!
    // Inputs:		strField (frmName.fldName),
    //				strMessageTitle (in case JavaScript ever allows titles, can be ""),
    //				strMessage (message text, if "", will not pop message box),
    //				objFocus (focus on this object if false, if "", will not set focus).
    // Returns:		Boolean (TRUE/FALSE)
    // Supported in OM2+

    var checkOK = specialChars;
    var checkStr = strField.value;
    var allValid = true;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        allNum += ch;
    }
    if (!allValid) {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
        bReturn = FALSE;
    }
    else {
        bReturn = TRUE;
    }
    return bReturn;
}

function gjOpenWindow(strURL) {
    //	Function	Opens a full browser window.
    //	Supported in OM2+
    openWindow = window.open(strURL);
    return;
}

function gjOpenWindowNoControl(strURL) {
    //	Function	Opens a browser window with controls or toolbars
    //	Supported in OM2+
    openWindow = window.open(strURL, "displayWindow", "height=400,width=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes");
    return;
}

function gjVerifyFieldLength(strField, strMessageTitle, strMessage, objFocus, iLen) {
    // Function	Verifies Field Length,
    //			Reports if passed a non-blank strMessage
    //			Sets Focus if passed a non-blank objFocus
    // Inputs:	strField (frmName.fldName format), 
    //			strMessageTitle (in case JavaScript allows titles, can be ""),
    //			strMessage (message text, if "" will not pop message box),
    //			objFocus (focus on this object if false, if ::, will not set focus),
    //			iLen (Expected Length in chars as integer).
    // Returns: Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    var iLength;
    var strLength;

    bReturn = TRUE;
    strLength = strField.value;
    iLength = strLength.length;

    if (iLength > iLen) {
        if (strMessage != "")
            alert(strMessage);
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
        bReturn = FALSE;
    }
    else
        bReturn = TRUE;

    return bReturn;
}

function gjMinFieldLength(strField, strMessage, objFocus, iLen) {
    // Function: Makes sure field is at least the length of iLen. 
    //				 Sets Focus if passed a non-blank objFocus
    // Inputs:	 strField (frmName.fldName format), 
    //				 strMessage (message text, if "" will not pop message box),
    //				 objFocus (focus on this object if false, if ::, will not set focus),
    //				 iLen (Expected Length in chars as integer).
    // Returns:  Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    var iLength;
    var strLength;

    bReturn = TRUE;
    strLength = strField.value;
    iLength = strLength.length;

    if (iLength < iLen) {
        if (strMessage != "")
            alert(strMessage);
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
        bReturn = FALSE;
    }
    else
        bReturn = TRUE;

    return bReturn;
}

function gjVerifyFieldPop(strField, strMessageTitle, strMessage, objFocus) {
    // Function:	Verifies Field is NOT blank,
    //				Reports if passed a non-blank strMessage 
    //				Sets Focus if passed a non-blank objFocus
    // Inputs:		strField (frmName.fldName format),
    //				strMessageTitle (in case JavaScript ever allows titles, can be ""),
    //				strMessage (message text, if "", will not pop message box),
    //				objFocus (focus on this object if false, if "", will not set focus).
    // Returns:		Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    bReturn = TRUE;

    if (strField.value == "") {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
        }
        bReturn = FALSE;
    }
    else {
        bReturn = TRUE;
    }
    return bReturn;
}

function gjVerifyMatch(strFieldOne, strFieldTwo, strMessageTitle, strMessage, objFocus) {
    // Function:	Verifies Fields match
    //				Reports if passed a non-blank strMessage 
    //				Sets Focus if passed a non-blank objFocus
    // Inputs:		strFieldOne (frmName.fldName format),
    //				strFieldTwo (frmName.fldName format),
    //				strMessageTitle (in case JavaScript ever allows titles, can be ""),
    //				strMessage (message text, if "", will not pop message box),
    //				objFocus (focus on this object if false, if "", will not set focus).
    // Returns:		Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    bReturn = TRUE;

    if (strFieldOne.value != strFieldTwo.value) {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
        }
        bReturn = FALSE;
    }
    else {
        bReturn = TRUE;
    }
    return bReturn;
}

function gjVerifyEMail(strField, strMessageTitle, strMessage, objFocus) {
    // Function:	Verifies string contains '@'
    // Inputs:		strField (frmName.fldName),
    //				strMessageTitle (in case JavaScript ever allows titles, can be ""),
    //				strMessage (message text, if "", will not pop message box),
    //				objFocus (focus on this object if false, if "", will not set focus).
    // Returns:		Boolean (TRUE/FALSE)
    // Supported in OM2+

    var bReturn;
    bReturn = TRUE;

    if (window.RegExp) {
        //RegExp supported!
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.(\w{2,})(\])?/; // valid

        if (!reg1.test(strField.value) && reg2.test(strField.value))
            bReturn = TRUE;
        else
            bReturn = FALSE;
    }
    else {
        //RegExp not supported!
        if (strField.value.indexOf('@', 0) == -1 || strField.value.indexOf('.', 0) == -1)
            bReturn = FALSE;
        else
            bReturn = TRUE;
    }

    if (!bReturn) {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
    }
    return bReturn;
}

function gjIsValidDate(strDate) {
    // standard headers here.
    //
    //
    //	var bDateIsValid;
    //	var ii;
    //	var ch;
    //	var strWork = strDate;

    //	for (ii = 0; ii = 1; ii++)
    // The date string is ten characters long.
    // first two must be numbers.
    //	{
    //		ch = strWork.substring(ii, ii + 1);
    //		if (ch < "0" || "9" < ch)
    //		{
    //			bDateIsValid = FALSE;
    //		}
    //		else
    //		{
    //			bDateIsValid = TRUE;
    //		}
    //	}
    return TRUE;
    //	return FALSE;
}

function gjRepairNumeric(strIn) {
    // function that trims commas!
    var objRegExp = /,/;
    var strOut = strIn.replace(objRegExp, '', ',');
    return strOut;
}


function gjRepairSQL(strInSQL) {
    // Function:	Adds apostrophes where needed for SQL string construction.
    // Inputs:		strInSQL (string) (e.g., o'toole),
    // Returns:		strOutSQL, with double apostrophes where needed (e.g., o''toole).
    // Supported in OM2+

    var strOutSQL;
    var strLen;
    var ii;

    strOutSQL = "";
    iLen = strInSQL.length;

    for (ii = 0; ii < iLen; ii++) {
        if (strInSQL.charAt(ii) == "'") {
            strOutSQL = strOutSQL + strInSQL.charAt(ii) + "'";
        }
        else {
            strOutSQL = strOutSQL + strInSQL.charAt(ii);
        }
    }
    return strOutSQL;
}

function gjApprovedCharsOnly(field, strMessage, objfocus) {
    // Function:	Allows only legitimate characters in field.
    // Inputs:		field = field.value,
    // Returns:  true/false
    // Supported in OM2+
    for (i = 0; i < field.length; i++) {
        ch = field.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        allNum += ch;
    }
    if (!allValid)
    // report on failure
    {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
    }
    return allValid;
}

function validateUSDate(strValue, strMessageTitle, strMessage, objFocus) {
    /************************************************
    DESCRIPTION: Validates that a string contains only 
    valid dates with 2 digit month, 2 digit day, 
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and 
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
    (Year can be yyyy or yy)
    
    PARAMETERS:
    strValue - String to be tested for validity
   
    RETURNS:
    True if valid, otherwise false.
   
    REMARKS:
    Avoids some of the limitations of the Date.parse()
    method such as the date separator character.
    *************************************************/
    var bReturn;

    //if the browser doesnt support RegExp then kick out to a more conventional function!
    if (!window.RegExp) {
        bReturn = specialCharacters(objFocus, '0123456789/', strMessageTitle, strMessage, objFocus)
        return bReturn
    }

    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1(\d{2}|\d{4})$/

    //check to see if in correct format
    if (!objRegExp.test(strValue))
        bReturn = FALSE; //doesn't match pattern, bad date
    else {
        var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
        var intDay = parseInt(arrayDate[1], 10);
        var intYear = parseInt(arrayDate[2], 10);
        var intMonth = parseInt(arrayDate[0], 10);

        var tempString = new String(intMonth);

        if (tempString.length == 1) {
            arrayDate[0] = '0' + tempString;
        }


        //check for valid month
        if (intMonth > 12 || intMonth < 1) {
            bReturn = FALSE;
        }
        else {
            //create a lookup for months not equal to Feb.
            var arrayLookup = { '01': 31, '03': 31, '04': 30, '05': 31, '06': 30, '07': 31,
                '08': 31, '09': 30, '10': 31, '11': 30, '12': 31
            }
            //check if month value and day value agree
            if (arrayLookup[arrayDate[0]] != null) {
                if (intDay <= arrayLookup[arrayDate[0]] && intDay != 0) {

                    bReturn = TRUE; //found in lookup table, good date
                }
                else {
                    bReturn = FALSE;
                }
            }
            else {
                if (intMonth != 2 && intMonth != 02) {
                    bReturn = FALSE;
                }
                else {
                    //check for February
                    var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
                    if ((((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <= 28)) && intDay != 0) || (intMonth != 2 && intMonth != 02)) {
                        bReturn = TRUE; //Feb. had valid number of days
                    }
                    else {
                        bReturn = FALSE; //any other values, bad date
                    }
                }
            }
        }
    }

    if (!bReturn)
    // report on failure
    {
        if (strMessage != "") {
            alert(strMessage);
        }
        if (objFocus != "") {
            objFocus.focus();
            objFocus.select();
        }
    }
    return bReturn;
}
//************************************************************

function gjLinkOver(strMessage) {
    //	Activated when the mouse is OVER the link
    //	corresponding to the MouseOver event.
    //	Update the window.status message.
    //	Supported in OM2+

    window.status = strMessage;
}

function gjLinkOut(strMessage) {
    //	When the mouse has moved OFF the link
    //	corresponds to the MouseOut event.
    //	Update the window.status message.
    //	Supported in OM2+

    window.status = strMessage;
}

// Cloaking Device Off

// Practitioner Article //
function Trim(value) {
    value = value.replace(/^\s+/, "").replace(/\s+$/, "");
    return value;
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/, "");
}
function ValidateTagsArticle(sender, args) {
    if (!CheckMenu('article')) { return true; }
    var blnValid = new Boolean();
    blnValid = true;

    var urlId = document.getElementById(sender.id.replace('cvArticles3', 'txtUrl'));
    var descriptionId = document.getElementById(sender.id.replace('cvArticles3', 'txtDescription'));
    if (urlId.value.indexOf('<') >= 0 ||
            urlId.value.indexOf('>') >= 0 ||
            descriptionId.value.indexOf('<') >= 0 ||
            descriptionId.value.indexOf('>') >= 0) {
        blnValid = false;
        descriptionId.focus();
    }
    args.IsValid = blnValid;
}
function ValidateTagsTestimonial(sender, args) {
    if (!CheckMenu('article')) { return true; }
    var blnValid = new Boolean();
    blnValid = true;

    var testimonial = document.getElementById(sender.id.replace('cvTestimonials1', 'txtTestimonialEdit'));
    var testimonialOf = document.getElementById(sender.id.replace('cvTestimonials1', 'txtTestimonialOfEdit'));

    if (testimonial.value.indexOf('<') >= 0 ||
            testimonial.value.indexOf('>') >= 0 ||
            testimonialOf.value.indexOf('<') >= 0 ||
            testimonialOf.value.indexOf('>') >= 0) {
        blnValid = false;
        testimonial.focus();
    }
    args.IsValid = blnValid;
}
function ValidateTagsQuestion(sender, args) {
    if (!CheckMenu('article')) { return true; }
    var blnValid = new Boolean();
    blnValid = true;
    var txtQuestion = document.getElementById(sender.id.replace("cvCustomQuestion1", "txtQuestion"));
    if (txtQuestion != null) {
        if (Trim(txtQuestion.value).length > 0) {
            if (txtQuestion.value.indexOf('<') >= 0 || txtQuestion.value.indexOf('>') >= 0) {
                blnValid = false;
                txtQuestion.focus();
            }
        }
    }
    args.IsValid = blnValid;
}

function ValidateTagsAnswer(sender, args) {
    if (!CheckMenu('article')) { return true; }
    var blnValid = new Boolean();
    blnValid = true;
    var txtAnswer = document.getElementById(sender.id.replace("cvAnswer1", "txtAnswer"));
    if (Trim(txtAnswer.value).length > 0) {
        if (txtAnswer.value.indexOf('<') >= 0 || txtAnswer.value.indexOf('>') >= 0) {
            blnValid = false;
            txtAnswer.focus();
        }
    }
    args.IsValid = blnValid;
}

function ValidateLink(sender, args) {
    if (!CheckMenu('article')) {return true;}
    var blnValid = new Boolean();
    urlId = sender.id.replace('cvArticles', 'txtUrl');
    descriptionId = sender.id.replace('cvArticles', 'txtDescription');
    if (trim(document.getElementById(urlId).value).length > 0 & trim(document.getElementById(descriptionId).value).length == 0) {
        blnValid = false;
    }
    else if (trim(document.getElementById(urlId).value).length == 0 & trim(document.getElementById(descriptionId).value).length > 0) {
        blnValid = false;
    }
    else {
        blnValid = true;
    }

    args.IsValid = blnValid;
}

function ValidateArticleLink(sender, args) {
    if (!CheckMenu('article')) { return true; }
    var blnValid = new Boolean();
    urlId = sender.id.replace('cvArticles2', 'txtUrl');
    if (trim(document.getElementById(urlId).value).length > 0) {
        if ((trim(document.getElementById(urlId).value).toLowerCase() == 'http://www.emofree.com') ||
            (trim(document.getElementById(urlId).value).toLowerCase() == 'http://www.emofree.com/') ||
            (trim(document.getElementById(urlId).value).toLowerCase() == 'www.emofree.com') ||
            (trim(document.getElementById(urlId).value).toLowerCase() == 'www.emofree.com/')
            ) {
            blnValid = false;
        } else {
            blnValid = true;
        }
    }
    else {
        blnValid = true;
    }

    args.IsValid = blnValid;

}
function ValidateUrls() {
    if (!CheckMenu('article')) {return true; }
    //alert('ValidateUrls');
    var blnValid = false;
    var element = document.getElementsByTagName("input");

    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate()) {
            blnValid = true;
            //for (var i = 0; i < element.length; i++) {
            //    if (element[i].type === "text" && Trim(element[i].value).length > 0) {
            //        blnValid = true;
            //        break;
            //    }
            // }

            //if (!blnValid) {
            //    alert("Please enter at least one link and description!");
            //}
        }
    }

    return blnValid;
}
// Practitioner Article //


// Practitioner Testimonials //
function ValidateTestimonials() {
    if (!CheckMenu('testimonial')) { return true }

    var blnValid = false;
    var element = document.getElementsByTagName("input");

    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate()) {
            blnValid = true;
        }
    }
    return blnValid;
}
function ValidateTestimonial(sender, args) {
    var blnValid = new Boolean();

    testimonial = sender.id.replace('cvTestimonials', 'txtTestimonialEdit');
    testimonialOf = sender.id.replace('cvTestimonials', 'txtTestimonialOfEdit');
    blnValid = false;

    if (Trim(document.getElementById(testimonial).value).length > 0 & Trim(document.getElementById(testimonialOf).value).length == 0) {
        blnValid = false;
    }
    else if (Trim(document.getElementById(testimonial).value).length == 0 & Trim(document.getElementById(testimonialOf).value).length > 0) {
        blnValid = false;
    }
    else {
        blnValid = true;
    }

    args.IsValid = blnValid;
}
// Practitioner Testimonials //

// Practitioner Questionnaires //
function ValidateQuestion() {
    if (!CheckMenu('question')) { return true }
    var blnValid = false;
    var element = document.getElementsByTagName("input");

    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate()) {
            blnValid = true;
        }
    }
    return blnValid;

}

function CheckCustomQuestion(sender, args) {
    if (!CheckMenu('question')) { args.IsValid = true;return;}

    var txtQuestion = document.getElementById(sender.id.replace("cvCustomQuestion", "txtQuestion"));
    var chkSelected = document.getElementById(sender.id.replace("cvCustomQuestion", "chkSelected"));

    if (chkSelected.checked && Trim(txtQuestion.value).length == 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function CheckAnswer(sender, args) {
    if (!CheckMenu('question')) { args.IsValid = true; return; }
    var txtAnswer = document.getElementById(sender.id.replace("cvAnswer", "txtAnswer"));
    var chkSelected = document.getElementById(sender.id.replace("cvAnswer", "chkSelected"));

    if (chkSelected.checked && Trim(txtAnswer.value).length == 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function CheckSelection(id) {
    if (!CheckMenu('question')) { args.IsValid = true; return; }

    var count = 0;
    var elements = document.getElementById(id).getElementsByTagName("INPUT");

    if (typeof (Page_ClientValidate) == 'function') {

        if (Page_ClientValidate()) {
            for (i = 0; i < elements.length; i++) {
                {
                    count = (count + (elements[i].checked ? 1 : 0));
                }
            }

            if (count > 5) {
                alert('Please select at most 5 questions for posting in your profile.');
                return false;
            }

            return true;
        }
        else {
            return false;
        }
    }
}
// Practitioner Questionnaires //

function ShowHidePanel(c) {
    var country = document.getElementById(c);
    var nogroup = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_wzSignup_nogroup');
    var wigroup = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_wzSignup_wigroup');
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/, "");
}


function CheckFilename(sender, args) {
    if (Trim(args.Value).length > 0) {
        var filename = GetNameFromPath(args.Value);
        var extension = filename.substr(filename.lastIndexOf('.'));
        args.IsValid = ((extension.toLowerCase() == ".jpg") || (extension.toLowerCase() == ".gif"));
    }
    else {
        args.IsValid = true;
    }
}

function GetNameFromPath(strFilepath) {
    var oExpr = new RegExp(/([^\/\\]+)$/);
    var strName = oExpr.exec(strFilepath);

    if (strName == null) {
        return '';
    }
    else {
        return strName[0];
    }
}

function CountCharacters(charMax, sourceID, targetID) {
    try {
        var sourceControl = document.getElementById(sourceID);
        var targetControl = document.getElementById(targetID);

        if (sourceControl != null && targetControl != null && charMax > 0) {
            var charRemaining = charMax - sourceControl.value.length;
            targetControl.value = charRemaining;
            if (charRemaining < 0) {
                alert("You have exceeded the maximum allowed number of characters for this field.  Your input will be trimmed to length.");
                sourceControl.value = sourceControl.value.substring(0, charMax);
                targetControl.value = charMax - sourceControl.value.length;
                sourceControl.focus();
            }
        }
    }
    catch (e) {
        alert(e);
    }
}

function CountCheck(oCheckBox) {

    if (oCheckBox.checked == 1) {
        var oValue = document.getElementById("<%=hdnCheckValue.ClientID %>").value
        var maxSpecialties;
        maxSpecialties = 6

        oValue = parseInt(oValue) + 1

        if (parseInt(oValue) > maxSpecialties) {
            alert('Please select a maximum of ' + maxSpecialties + ' Specialties to define your practice.');
            oCheckBox.checked = 0;
            oValue = parseInt(oValue) - 1;
        }
        document.getElementById("<%=hdnCheckValue.ClientID %>").value = oValue;
    }
    else {
        var oValue = document.getElementById("<%=hdnCheckValue.ClientID %>").value

        oValue = parseInt(oValue) - 1
        document.getElementById("<%=hdnCheckValue.ClientID %>").value = oValue;

        if (parseInt(oValue) < 1) {
            document.getElementById("<%=hdnCheckValue.ClientID %>").value = 0;
        }
    }
}
/**
* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strMonth = dtStr.substring(0, pos1)
    var strDay = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("The date format should be : mm/dd/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date")
        return false
    }
    return true
}

function ValidateSteps() {

    if (ValidateStep1()) {
        if (ValidateStep2()) {
            if (ValidateStep3()) {
                return ValidateStep4();
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}

function ValidateStep1() {
    //Validate Represetation Section
    //Start

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (document.getElementById('<%=hdnCertLevel.ClientID %>').value.toLowerCase() == "none") {
        if (document.getElementById('<%=txtSource.ClientID %>').value == '') {
            alert("Please anwser the question 'Where did you get the EFT DVD sets that are contained within the EFT Foundational Library?'");
            document.getElementById('<%=txtSource.ClientID %>').focus();
            return false;
        }
        else {
            if (document.getElementById('<%=txtSource.ClientID %>').value.length > 1000) {
                var lngth = document.getElementById('<%=txtSource.ClientID %>').value.length;
                alert("Please limit your anwser to the question 'Where did you get the EFT DVD sets that are contained within the EFT Foundational Library?' to 1000 characters or less.  Currently you have " + lngth + " characters.");
                document.getElementById('<%=txtSource.ClientID %>').focus();
                return false;
            }
        }
    }

    var percent = document.getElementById('<%=txtPercent.ClientID %>');
    var perValue = percent.value;
    perValue = perValue.replace("%", "");
    percent.value = perValue;

    if (isNaN(document.getElementById('<%=txtPercent.ClientID %>').value) ||
        document.getElementById('<%=txtPercent.ClientID %>').value == '') {
        alert("Please provide an numeric value of the question 'With what percentage of your clients do you use EFT?'")
        document.getElementById('<%=txtPercent.ClientID %>').focus();
        return false;
    }

    if (parseInt(document.getElementById('<%=txtPercent.ClientID %>').value) > 100) {
        alert("Please provide a value between 0 and 100 for the question 'With what percentage of your clients do you use EFT?'");
        document.getElementById('<%=txtPercent.ClientID %>').focus();
        return false;
    }

    if (parseInt(document.getElementById('<%=txtPercent.ClientID %>').value) < 100) {
        if (document.getElementById('<%=txtPercentReason.ClientID  %>').value == '') {
            alert("Please provide an explanation if your usage percentage is less than 100%.");
            document.getElementById('<%=txtPercentReason.ClientID  %>').focus();
            return false;
        }
        else {
            if (document.getElementById('<%=txtPercentReason.ClientID %>').value.length > 400) {
                var lngth = document.getElementById('<%=txtPercentReason.ClientID %>').value.length;
                alert("Please limit your anwser to the question 'Why is your EFT usage percentage less than 100 percent?' to 400 characters or less.  Currently you have " + lngth + " characters.");
                document.getElementById('<%=txtPercentReason.ClientID %>').focus();
                return false;
            }
        }
    }

    if (isNaN(document.getElementById('<%=txtAverageSessions.ClientID %>').value) ||
        document.getElementById('<%=txtAverageSessions.ClientID %>').value == '') {
        alert("Please provide a numeric value of the question 'On average, how many EFT sessions do you conduct per week?'");
        document.getElementById('<%=txtAverageSessions.ClientID %>').focus();
        return false;
    } else {
        if (parseInt(document.getElementById('<%=txtAverageSessions.ClientID %>').value) <= 0) {
            alert("Please provide a value greater than zero on the question 'On average, how many EFT sessions do you conduct per week?'");
            document.getElementById('<%=txtAverageSessions.ClientID  %>').focus();
            return false;
        }

    }

    if (isNaN(document.getElementById('<%=txtOneOnOne.ClientID %>').value) ||
        document.getElementById('<%=txtOneOnOne.ClientID %>').value == '') {
        alert("Please provide an numeric value of the question 'To how many individuals have you delivered EFT in one-on-one sessions (not counting groups)?'");
        document.getElementById('<%=txtOneOnOne.ClientID %>').focus();
        return false;
    }
    else {
        var sessions = document.getElementById('<%=txtOneOnOne.ClientID %>').value;
        if (isNaN(sessions)) {
            alert("Please provide an numeric value of the question 'To how many individuals have you delivered EFT in one-on-one sessions (not counting groups)?'");
            document.getElementById('<%=txtOneOnOne.ClientID %>').focus();
            return false;
        }
        else {
            if (Number(sessions) < 100) {
                alert("To be listed on this site, the minimum number of one-on-one sessions is 100.");
                document.getElementById('<%=txtOneOnOne.ClientID %>').focus();
                return false;
            }
        }
    }

    if (document.getElementById('<%=txtSupportEmail.ClientID %>').value == '') {
        alert("Please enter a value for 'I have subscribed to the EFT email support list under the following email address'");
        document.getElementById('<%=txtSupportEmail.ClientID %>').focus();
        return false;
    }
    else {

        var supportemail = document.getElementById('<%=txtSupportEmail.ClientID %>');
        supportemail.value = trim(supportemail.value);
        if (!filter.test(supportemail.value)) {
            alert("Please enter a standard Email address.");
            supportemail.focus();
            return false;
        }
    }


    if (document.getElementById('<%=txtEFTStarted.ClientID %>').value == '') {
        alert("Please enter a date for 'When did you start practicing EFT?'");
        document.getElementById('<%=txtEFTStarted.ClientID %>').focus();
        return false;
    }
    else {
        if (isDate(document.getElementById('<%=txtEFTStarted.ClientID %>').value)) {
            return true;
        }
        else {
            document.getElementById('<%=txtEFTStarted.ClientID %>').focus();
            return false;
        }
    }
    return true;

}

function ValidateStep2() {

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (document.getElementById('<%=txtFirstName.ClientID %>').value == '') {
        alert("Please enter a value for First Name");
        document.getElementById('<%=txtFirstName.ClientID %>').focus();
        return false;
    }

    if (document.getElementById('<%=txtLastName.ClientID %>').value == '') {
        alert("Please enter a value for Last Name");
        document.getElementById('<%=txtLastName.ClientID %>').focus();
        return false;
    }

    if (document.getElementById('<%=txtAddress.ClientID %>').value == '') {
        alert("Please enter a value for Address");
        document.getElementById('<%=txtAddress.ClientID %>').focus();
        return false;
    }

    if (document.getElementById('<%=txtCity.ClientID %>').value == '') {
        alert("Please enter a value for City");
        document.getElementById('<%=txtCity.ClientID %>').focus();
        return false;
    }

    oCountries = document.getElementById('<%=drpCountries.ClientID %>')

    if (oCountries.options[oCountries.selectedIndex].text == '') {
        alert('You must select a country.')
        oCountries.focus();
        return false;
    }

    if (oCountries.options[oCountries.selectedIndex].text == 'USA') {
        oState = document.getElementById('<%=drpStates.ClientID %>')
        if (oState.options[oState.selectedIndex].text == '') {
            alert('You must select a state if "USA" is selected.')
            oState.focus();
            return false;
        }
    }

    if (document.getElementById('<%=txtPhone.ClientID %>').value == '') {
        alert("Please enter a value for Phone");
        document.getElementById('<%=txtPhone.ClientID %>').focus();
        return false;
    }

    if (document.getElementById('<%=txtEmail.ClientID %>').value == '') {
        alert("Please enter a value for Email address");
        document.getElementById('<%=txtEmail.ClientID %>').focus();
        return false;
    }
    else {
        var email = document.getElementById('<%=txtEmail.ClientID %>');
        email.value = trim(email.value);
        if (!filter.test(email.value)) {
            alert("Please enter a standard Email address.");
            email.focus();
            return false;
        }
    }
    var oWeb = document.getElementById('<%=txtWebsite.ClientID %>');
    if (oWeb.value.length > 0) {
        var v = new RegExp();
        v.compile("[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");

        if (!v.test(oWeb.value)) {
            alert("You must supply a valid URL of the form www.mysite.com.");
            oWeb.focus();
            return false;
        }
    }
    return true;
}
function ValidateStep3() {
    var oValue = document.getElementById("<%=hdnCheckValue.ClientID %>").value
    if (oValue < 1) {
        alert("Please select at least one specialty so visitors can find your listing better.");
        document.getElementById("<%=grvSpecialties.ClientID %>").focus;
        return false;
    }
    return true;
}
function ValidateStep4() {
    if (document.getElementById('<%=txtDescription.ClientID %>').value == '') {
        alert("Please enter a description of yourself and your practice in Step 4.");
        document.getElementById('<%=txtDescription.ClientID %>').focus();
        return false;
    }
    else {
        if (document.getElementById('<%=txtDescription.ClientID %>').value.length > 500) {
            var lngth = document.getElementById('<%=txtDescription.ClientID %>').value.length;
            alert("Please limit your practice description to 500 characters or less.  Currently you have " + lngth + " characters.");
            document.getElementById('<%=txtDescription.ClientID %>').focus();
            return false;
        }
        //prohibit web address
        var desc = document.getElementById('<%=txtDescription.ClientID %>').value;
        var webURL = new RegExp();
        var webURL2 = new RegExp();
        webURL.compile("(https|http)+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]");
        webURL2.compile("www\\.[A-Za-z0-9-_%&\?\/.=]");
        if (desc.match(webURL) != null || desc.match(webURL2) != null) {
            alert("Please do not include website addresses or other contact information in your description.");
            document.getElementById('<%=txtDescription.ClientID %>').focus();
            return false;
        }
        //prohibit email address
        var emailAddress = new RegExp();
        emailAddress.compile("[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}");
        if (desc.match(emailAddress) != null) {
            alert("Please do not include email addresses or other contact information in your description.");
            document.getElementById('<%=txtDescription.ClientID %>').focus();
            return false;
        }
        //prohibit phone number
        var phoneNumber = new RegExp();
        phoneNumber.compile("\(\d{3}\) \d{3}-\d{4}");
        if (desc.match(phoneNumber) != null) {
            alert("Please do not include phone numbers or other contact information in your description.");
            //document.getElementById('<%=txtDescription.ClientID %>').focus();
            return false;
        }
    }
    return true;
}

function ValidatePage() {
    if (!CheckMenu('article')) {
        ValidateSteps;
    } else {
        if (typeof (Page_ClientValidate) == 'function') {
            if (Page_ClientValidate()) {
                ValidateSteps;
            }
        }
    }
}

function CheckMenu(menuText) {
    var blnIsExists = false;
    var nav = document.getElementById('navigation');
    if (nav != null) {
        links = nav.getElementsByTagName('a');
        for (var i = 0; i < links.length; i++) {
            var aText = links[i].innerHTML.toLowerCase();
            if (aText.indexOf(menuText.toLowerCase()) >= 0) {
                blnIsExists = true;
                break;
            }
        }
    }
    return blnIsExists;
}

function maxLength(field, maxChars) {
    if (field.value.length >= maxChars) {
        event.returnValue = false;
        return false;
    }
}

function maxLengthPaste(field, maxChars) {
    event.returnValue = false;
    if ((field.value.length + window.clipboardData.getData("Text").length) > maxChars) {
        return false;
    }
    event.returnValue = true;
}
