/*
FormValidator class

description
**********************************
Validates a form based on custom attributes in HTML tags.

Constructor
**********************************
new FormValidator(frm)- frm is a reference to an HTML form object

Methods
**********************************
Validate()- boolean- performs internal validation and returns true if validation passed.
IsOneFieldFilled() - boolean- true if one field is filled (not counting fields with the "dontvalidate" attribute set true)

Properties
**********************************
IsError- boolean- returns true if there was an error found in the last Call to Validate()
ErrorMessage- string- contains an error message from the last Call to Validate()
ErrorField- object reference- contains a reference to the field which caused the validation to fail

HTML attribute reference
**********************************
displayname: The name of the field as it should appear in error messages.
required: if true, the field must be filled before the form will validate.
validation: a semicolon seperated list of either validation types or custom function names which adhere to the
	"Validator function interface" described below. Validation types are:
		"integer"
		"number"
		"alphanumeric"
		"date"
		"phone"
		"zip"
		"email"
		"creditcard"
errormessage[num]: The custom error message that will display if the cooresponding validator fails. 
	1 based- i.e. errorMessage2="error message" will be returned if the second validator function fails.
	Error messages should include the strings "#field#" and "#value#" where the cooresponding field or value
	should be displayed.
condition: a javascript expression which must return true for the field to pass validation.
conditionerror: If the "contition" attribute returns false, this message is returned.
dontvalidate: Wont consider the field when Validate() is called
emptyvalue: If the selected value matches this emptyvalue attribute, the field is considered empty for the purposes of validation.

Validator function interface
**********************************
Validation functions must implement the following interface:
function [function name](sValue, bGetMessage)

if bGetMessage is true, the function should return a specific error message. Error messages should use the #field# and #value# convention. If it is false or null, the function should return true or false.

Usage example
**********************************
var oValidator = new FormValidator(document.form1);
	
if (!oValidator.Validate()) {
	alert(oValidator.ErrorMessage);
	oValidator.ErrorField.focus();
	return false;
} else {
	document.form1.submit();
}

*/


var MAX_CHARS_TEXTAREA = 102399;

var ERR_MSG_VALIDATE_INTEGER = "Please enter a valid integer for the field \"#field#\".";
var ERR_MSG_VALIDATE_NUMBER = "Please enter a valid number for the field \"#field#\".";
var ERR_MSG_VALIDATE_ALPHANUMERIC = "The field \"#field#\" must be alphanumeric.";
var ERR_MSG_VALIDATE_DATE = "Please enter a valid date for the field \"#field#\" in the format " + new Date().format('mmm/dd/yyyy') + ".";
var ERR_MSG_VALIDATE_CPP_DATE = "Please enter a date for the field \"#field#\" which is after " + MIN_CPP_DATE.format("month dd, yyyy") + " and before " + MAX_CPP_DATE.format("month dd, yyyy") + ".";
var ERR_MSG_VALIDATE_ZIP = "Please enter a valid zip/postal code for the field \"#field#\".";
var ERR_MSG_VALIDATE_EMAIL = "The email address \"#value#\" is not valid. Please check it before you continue.";
var ERR_MSG_VALIDATE_WWW = "The website address \"#value#\" is not valid. Please check it before you continue.";
var ERR_MSG_VALIDATE_CREDITCARD = "The credit card number \"#value#\" is not valid. Please enter a valid credit card number.";
var ERR_MSG_VALIDATE_TEXTAREA = "The field \"#field#\" contains more than " + MAX_CHARS_TEXTAREA + " characters, which is the limit allowed. Please shorten the entry in this field.";
var ERR_MSG_VALIDATE_PHONE = "The phone number \"#value#\" is not valid. Please enter a valid phone number, e.g. 555-255-4896.";

// Call this function to validate form data on submit
// Parameters: oForm, [sProgressbarText]
// Example: <form onsubmit="return ValidateFormData(this, 'Please Wait...')">
function ValidateFormData(oForm, sProgressbarText)
{
	var oValidator = new FormValidator(oForm);

	if (!oValidator.Validate())
	{
		NewAlert(oValidator.ErrorMessage, null, MSGBOX_ICON_CRITICAL);
		oValidator.ErrorField.focus();
		return false;
	}
	if(sProgressbarText)
	{
		ProgressBar.Show(sProgressbarText);
	}
	return true;
}

function FormValidator(frm) {
	this.IsError = false;
	this.ErrorMessage = "";
	this.ErrorField = null;
	
	var m_bOneFieldFilled = null;
	var ERR_TYPE_REQUIRED = -1;
	var ERR_TYPE_CUSTOM = 0;
	var ERR_TYPE_CONDITIONAL = -2;
	
	this.Validate = function() { //public
		var fValidatorRef;
		var bIsValid, bEmpty, bRequired;
		var i, j;
		var arrCustomValidators;
		var sValue;
		var sCondition;
		var sMessage;
		var bIsEnabled;
		var bDoValidate;
		var sDefaultValue;
		
		m_bOneFieldFilled = false;

		this.IsError = false;
		this.ErrorMessage = '';
		this.ErrorField = null;

		for (i=0; i<frm.elements.length; i++) {
			
			if (frm.elements[i].tagName == 'FIELDSET') {
				continue;
			}
			
			bIsValid = false;
			sValue = GetFieldValue(frm.elements[i]);
			bRequired = GetBoolean(GetAttributeEx(frm.elements[i], "required"));
			bIsEnabled = !frm.elements[i].disabled && frm.elements[i].style.display != 'none';
			bDoValidate = !GetBoolean(GetAttributeEx(frm.elements[i], "dontvalidate")) && (frm.elements[i].type != 'hidden' || GetAttributeEx(frm.elements[i], "dontvalidate") == "false") && frm.elements[i].type != 'button' && frm.elements[i].type != 'submit' && frm.elements[i].type != 'image';
			if (bIsEnabled) {
				if (!IsObjectVisible(frm.elements[i])) {
					bIsEnabled = false;	
				}
			}
			
			sDefaultValue = GetAttributeEx(frm.elements[i], "emptyvalue");
			
			sMessage = "";
			bEmpty = (sValue == sDefaultValue);
			if (!bEmpty && bDoValidate && bIsEnabled) {
				m_bOneFieldFilled = true;
			}

			//if the field is required, validate that it isnt empty
			if (bRequired && bIsEnabled) {
				if (sValue == "") {
					SetError(frm.elements[i], ERR_TYPE_REQUIRED, this);
					return false;
				}
			}
			
			//standard and custom validation
			if (GetAttributeEx(frm.elements[i], "validation") != "" && (!bEmpty || bRequired) && bIsEnabled) {
				//support multiple validation functions
				arrCustomValidators = GetAttributeEx(frm.elements[i], "validation").split(";");
				
				for (j=0; j<arrCustomValidators.length; j++) {
					//the validation attribute can contain either validator keys or function names
					fValidatorRef = eval(GetValidatorFromKey(arrCustomValidators[j]));
					if (!fValidatorRef(sValue)) {
						//check and see if the validator function implements the bGetMessage argument interface
						sMessage = fValidatorRef(sValue, true)
						if (sMessage) {
							SetError(frm.elements[i], j+1, this, sMessage);
						} else {
							SetError(frm.elements[i], j+1, this);
						}
						
						return false;
					} 
				}
			}
			
			//conditional validation
			if (GetAttributeEx(frm.elements[i], "condition") != "" && (!bEmpty || bRequired) && bIsEnabled) {
				//support multiple validation functions
				sCondition = GetAttributeEx(frm.elements[i], "condition").replace(/this/gi, "frm.elements[i]");

				if (!eval(sCondition)) {
					SetError(frm.elements[i], ERR_TYPE_CONDITIONAL, this);
					return false; 
				}
			}
		}
		
		return true;
	}
	
	this.IsOneFieldFilled = function() {
		return m_bOneFieldFilled;
	}
	
	var SetError = function(oObj, nMessageNum, oParent, sOverrideMessage) { //private
		var bCustom = true;

		if (nMessageNum == ERR_TYPE_REQUIRED || nMessageNum == ERR_TYPE_CONDITIONAL) {
			bCustom = false;
		}
		
		oParent.ErrorField = oObj;
		oParent.IsError = true;
		
		//use the error message wich cooresponds to the validation function from the errormessage[num] attribute
		if (GetAttributeEx(oObj, "errorMessage" + nMessageNum) != "" && bCustom) {
			//support dynamic error messages if they are enclosed in parens ()
			if (oObj.getAttribute("errorMessage" + nMessageNum).indexOf("(") == 0) {
				oParent.ErrorMessage = ProcessMessage(oObj, eval(oObj.getAttribute("errorMessage" + nMessageNum)));
			} else {
				oParent.ErrorMessage = ProcessMessage(oObj, oObj.getAttribute("errorMessage" + nMessageNum));
			}
		//use the error message wich cooresponds to the validation function from the errormessage attribute
		} else if (GetAttributeEx(oObj, "errorMessage") != "" && bCustom) {
			oParent.ErrorMessage = ProcessMessage(oObj, GetAttributeEx(oObj, "errorMessage"));
		//use the error message from the functions bGetMessage argument interface
		} else if (sOverrideMessage && bCustom) {
			oParent.ErrorMessage = ProcessMessage(oObj, sOverrideMessage);
		//use the conditionmessage attribute
		} else if (GetAttributeEx(oObj, "conditionMessage") != "" && nMessageNum == ERR_TYPE_CONDITIONAL) {
			oParent.ErrorMessage = ProcessMessage(oObj, GetAttributeEx(oObj, "conditionMessage"));
		//use the "required"/default message
		} else {
			if (oObj.type.toLowerCase().indexOf('select') != -1) {
				oParent.ErrorMessage = "Please select a value for the field \"" + GetAttributeEx(oObj, "displayName") + "\".";
			} else {
				oParent.ErrorMessage = "Please fill in the field \"" + GetAttributeEx(oObj, "displayName") + "\".";
			}
		}
	}
	
	var ProcessMessage = function(oObj, sMessage) { //private
		return sMessage.replace(/\#field\#/gi, GetAttributeEx(oObj, "displayName").trim()).replace(/\#value\#/gi, GetFieldValue(oObj));
	}
	
	var GetFieldValue = function(oObj) { //private
		if (oObj.type.toLowerCase().indexOf('text') != -1 || oObj.type.toLowerCase().indexOf('password') != -1 || oObj.type.toLowerCase().indexOf('hidden') != -1) {
			return Trim(oObj.value);
		} else if (oObj.type.toLowerCase().indexOf('select') != -1) {
			return GetSelectValue(oObj);
		} else if (oObj.type.indexOf('radio') != -1) {
			return GetRadioValue(oObj);
		} else if (oObj.type == 'checkbox') {
			return oObj.checked;
		}
	}
	
	var GetValidatorFromKey = function(sKey) {
		return m_arrValidatorMap[sKey.toLowerCase()] ? m_arrValidatorMap[sKey.toLowerCase()] : sKey;
	}
	
	var m_arrValidatorMap = {
		"integer" : "ValidateInteger",
		"number" : "ValidateNumber",
		"alphanumeric" : "ValidateAlphanumeric",
		"date" : "ValidateDate",
		"cppdate" : "ValidateCppDate",
		"phone" : "ValidatePhone",
		"zip" : "ValidateZip",
		"email" : "ValidateEmail",
		"multiemail" : "ValidateMultiEmail",
		"creditcard" : "ValidateCreditCard",
		"textarea" : "ValidateTextAreaLength",
		"website" : "ValidateWebsite"
	}
}



//a collection of functions used to validate form input
function IsLetter(c) {
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function IsDigit(c) {   
	return ((c >= "0") && (c <= "9"))
}

function IsLetterOrDigit(c) {   
	return (IsLetter(c) || IsDigit(c))
}

function ValidateAlphanumeric(sStr, bGetMessage) {   
	var i;
	var validated = true;
    if (sStr.length < 1){
		return bGetMessage ? "" : true;
	}
    for (i = 0; i<sStr.length; i++){   
        c = sStr.charAt(i);
        if (!(IsLetter(c) || IsDigit(c) || (c == '_'))){  //allows underscores as well
        	return bGetMessage ? ERR_MSG_VALIDATE_ALPHANUMERIC : false;
		}
    }
    return bGetMessage ? "" : true;
}

function ValidateDate(sDate, bGetMessage) {
    //Returns true if value is a date format or is NULL
    //otherwise returns false	

    if (sDate.length == 0) {
        return bGetMessage ? "" : true;
	}

    //Returns true if value is a date in the mm/dd/yyyy format
	var nSplit = sDate.indexOf('/');

	if (nSplit == -1 || nSplit == sDate.length) {
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	}

    var sMonth = sDate.substring(0, nSplit);

	if (sMonth.length == 0) {
        return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	}

	nSplit = sDate.indexOf('/', nSplit + 1);

	if (nSplit == -1 || (nSplit + 1 ) == sDate.length) {
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	}

    var sDay = sDate.substring((sMonth.length + 1), nSplit);

	if (sDay.length == 0) {
        return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	}

	var sYear = sDate.substring(nSplit + 1);

	if (!ValidateInteger(sMonth)) {//check month
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else if (!ValidateRange(sMonth, 1, 12)) {//check month
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else if (!ValidateInteger(sYear)) {//check year
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else if (!ValidateRange(sYear, 0, 9999)) {//check year
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else if (!ValidateInteger(sDay)) {//check day
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else if (!ValidateDay(sYear, sMonth, sDay)) {// check day
		return bGetMessage ? ERR_MSG_VALIDATE_DATE : false;
	} else {
		return bGetMessage ? "" : true;
	}
}

function ValidateDay(nYear, nMonth, nDay) {
	var nMaxDay = 31;

	if (nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11) {
		nMaxDay = 30;
	} else if (nMonth == 2) {
		if (nYear % 4 > 0) {
			nMaxDay =28;
		} else if (nYear % 100 == 0 && nYear % 400 > 0) {
			nMaxDay = 28;
		} else {
			nMaxDay = 29;
		}
	}

	return ValidateRange(nDay, 1, nMaxDay); //check day
}

function ValidateInteger(sInteger, bGetMessage) {
    //Returns true if value is a number or is NULL
    //otherwise returns false	
    if (sInteger.length == 0) {
        return bGetMessage ? "" : true;
	}
	
	if (sInteger.indexOf('.') != -1) {
		return bGetMessage ? ERR_MSG_VALIDATE_INTEGER : false;
	}

    //The first character can be + -  blank or a digit.
	var sChar = sInteger.indexOf('.')
	
    if (sChar < 1) {
		if (!ValidateNumber(sInteger)) {
			return bGetMessage ? ERR_MSG_VALIDATE_INTEGER : false;
		}
		return bGetMessage ? "" : true;
    } else {
		return bGetMessage ? ERR_MSG_VALIDATE_INTEGER : false;
	}
}

function ValidateNumberRange(sNumber, nMinValue, nMaxValue) {
    if (nMinValue != null) {
        if (sNumber < nMinValue) {
			return false;
		}
	}

    if (nMaxValue != null) {
		if (sNumber > nMaxValue) {
			return false;
		}
	}
	
    return true;
}

function ValidateNumber(sNumber, bGetMessage) {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (sNumber.length == 0) {
        return bGetMessage ? "" : true;
	}
    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var sStartFormat = " .+-0123456789";
	var sNumberFormat = " .0123456789";
	var sChar;
	var bIsDecimal = false;
	var bIsTrailingBlank = false;
	var bIsDigits = false;

    //The first character can be + - .  blank or a digit.
	sChar = sStartFormat.indexOf(sNumber.charAt(0))
	
    //Was it a decimal?
	if (sChar == 1) {
	    bIsDecimal = true;
	} else if (sChar < 1) {
		return bGetMessage ? ERR_MSG_VALIDATE_NUMBER : false;
	}
		
	//was it a sole "-"?
	if (sNumber == '-' || sNumber == '+') {
		return bGetMessage ? ERR_MSG_VALIDATE_NUMBER : false;
	}
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i=1; i<sNumber.length; i++) {
		sChar = sNumberFormat.indexOf(sNumber.charAt(i))
		if (sChar < 0) {
			return bGetMessage ? ERR_MSG_VALIDATE_NUMBER : false;
		} else if (sChar == 1) {
			if (bIsDecimal) {		// Second decimal.
				return bGetMessage ? ERR_MSG_VALIDATE_NUMBER : false;
			} else {
				bIsDecimal = true;
			}
		} else if (sChar == 0) {
			if (bIsDecimal || bIsDigits) {	
				bIsTrailingBlank = true;
			}
        // ignore leading blanks
		} else if (bIsTrailingBlank) {
			return bGetMessage ? ERR_MSG_VALIDATE_NUMBER : false;
		} else {
			bIsDigits = true;
		}
	}	

    return bGetMessage ? "" : true;
}

function ValidateRange(sNumber, nMinValue, nMaxValue) {
    //If value is in range Then return true else return false
	if (sNumber.length == 0) {
        return true;
	}

    if (!ValidateNumber(sNumber)) {
		return false;
	} else {
		return (ValidateNumberRange((eval(sNumber)), nMinValue, nMaxValue));
	}
	
	return true;
}

function ValidatePhone(sPhoneNumber, bGetMessage) {
    if (sPhoneNumber.length == 0) {
        return bGetMessage ? "" : true;
	}
		
    if (sPhoneNumber.length != 12) {
        return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	}
	// check if first 3 characters represent a valid area code
    if (!ValidateNumber(sPhoneNumber.substring(0,3))) {
		return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
    } else if (!ValidateNumberRange((eval(sPhoneNumber.substring(0,3))), 100, 1000)) {
		return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	}

	// check if area code/exchange separator is either a'-' or ' '
	if (sPhoneNumber.charAt(3) != "-" && sPhoneNumber.charAt(3) != " ") {
        return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	}

	// check if  characters 5 - 7 represent a valid exchange
    if (!ValidateNumber(sPhoneNumber.substring(4,7))) {
		return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
    } else if (!ValidateNumberRange((eval(sPhoneNumber.substring(4,7))), 100, 1000)) {
		return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	}
	
	// check if exchange/number separator is either a'-' or ' '
	if (sPhoneNumber.charAt(7) != "-" && sPhoneNumber.charAt(7) != " ") {
        return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	}

	// make sure last for digits are a valid integer
	if (sPhoneNumber.charAt(8) == "-" || sPhoneNumber.charAt(8) == "+") {
        return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
	} else {
		if (!ValidateInteger(sPhoneNumber.substring(8,12))) {
			return bGetMessage ? ERR_MSG_VALIDATE_PHONE : false;
		}
		return bGetMessage ? "" : true;
	}
}

function ValidateZip(sZip, bGetMessage) {
    if (sZip.length == 0) {
        return bGetMessage ? "" : true;
	}
		
    if (sZip.length != 5 && sZip.length != 10) {
        return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}

	// make sure first 5 digits are a valid integer
	if (sZip.charAt(0) == "-" || sZip.charAt(0) == "+") {
        return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}
	if (!ValidateInteger(sZip.substring(0,5))) {
		return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}

	if (sZip.length == 5) {
		return bGetMessage ? "" : true;
	}
	
	// check if separator is either a'-' or ' '
	if (sZip.charAt(5) != "-" && sZip.charAt(5) != " ") {
        return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}

	// check if last 4 digits are a valid integer
	if (sZip.charAt(6) == "-" || sZip.charAt(6) == "+") {
        return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}

	if (!ValidateInteger(sZip.substring(6,10))) {
		return bGetMessage ? ERR_MSG_VALIDATE_ZIP : false;
	}
	return bGetMessage ? "" : true;
}

function ValidateCreditCard(sCreditCardNum, bGetMessage) {
	var sWhiteSpace = " -";
	var sCcNumParsed = "";
	var sChar;

    if (sCreditCardNum.length == 0) {
        return bGetMessage ? "" : true;
	}
	
	// remove white space
	for (var i = 0; i < sCreditCardNum.length; i++) {
		sChar = sWhiteSpace.indexOf(sCreditCardNum.charAt(i));
		if (sChar < 0) {
			sCcNumParsed += sCreditCardNum.substring(i, (i + 1));
		}
	}	

	// if all white space return error
    if (sCcNumParsed.length == 0) {
        return bGetMessage ? ERR_MSG_VALIDATE_CREDITCARD : false;
	}
	 	
	// make sure number is a valid integer
	if (sCcNumParsed.charAt(0) == "+") {
        return bGetMessage ? ERR_MSG_VALIDATE_CREDITCARD : false;
	}

	if (!ValidateInteger(sCcNumParsed)) {
		return bGetMessage ? ERR_MSG_VALIDATE_CREDITCARD : false;
	}

	var bIsDoubleDigit = (sCcNumParsed.length % 2 == 1) ? false : true;
	var nCheckDigit = 0;
	var nTempDigit;

	for (var i=0; i<sCcNumParsed.length; i++) {
		nTempDigit = eval(sCcNumParsed.charAt(i));

		if (bIsDoubleDigit) {
			nTempDigit *= 2;
			nCheckDigit += (nTempDigit % 10);

			if ((nTempDigit / 10) >= 1.0) {
				nCheckDigit++;
			}

			bIsDoubleDigit = false;
		} else {
			nCheckDigit += nTempDigit;
			bIsDoubleDigit = true;
		}
	}	
	
	for (i=0; i<sCcNumParsed.length; i++) {
    	if (isNaN(sCcNumParsed.charAt(i))) {
            return bGetMessage ? ERR_MSG_VALIDATE_CREDITCARD : false;
        }
  	}
	
	if ((nCheckDigit % 10) != 0) {
		return bGetMessage ? ERR_MSG_VALIDATE_CREDITCARD : false;
	}
	return bGetMessage ? "" : true;

}
 
function ValidateEmail(sEmail, bGetMessage) {
	var regExpObj = /^([a-zA-Z0-9_\+\-\.\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/  //'
	if (sEmail.search(regExpObj) != 0) {
		return bGetMessage ? ERR_MSG_VALIDATE_EMAIL : false;
	}
	return bGetMessage ? "" : true;
}

function ValidateMultiEmail(sEmailList, bGetMessage) {
	var arrEmails
	if (sEmailList.indexOf(',') != -1) {
		arrEmails = sEmailList.split(',');
	} else if (sEmailList.indexOf(';') != -1) {
		arrEmails = sEmailList.split(';');
	} else {
		arrEmails = sEmailList.split(',');
	}
	
	for (var i=0; i<arrEmails.length; i++) {
		if (!ValidateEmail(arrEmails[i].trim())) {
			return bGetMessage ? ERR_MSG_VALIDATE_EMAIL.replace('#value#', arrEmails[i].trim()) : false;
		}
	}
	
	return bGetMessage ? "" : true;
}

function ValidateWebsite(sWeb, bGetMessage) {
	var regExpObj = /^(http\:\/\/)?(?:[a-zA-Z0-9\-]+\.){0,5}[a-zA-Z0-9\-]{2,}\.[a-zA-Z]{2,4}(\/\S*)?$/;
	if (sWeb.search(regExpObj) != 0) {
		return bGetMessage ? ERR_MSG_VALIDATE_WWW : false;
	}
	return bGetMessage ? "" : true;
}

function ValidateTextAreaLength(sStr, bGetMessage){
 	if (sStr.length > MAX_CHARS_TEXTAREA){
 		return bGetMessage ? ERR_MSG_VALIDATE_TEXTAREA : false;
	} else {
		return true;
	}
}

function ValidateLength(sStr, object_length){
	if (sStr.length == object_length){
    	return true;
	} else {
    	return false;
	}
}

function ValidateBadCharArray(sStr, arrBadChars){
	for (var i=0; i<arrBadChars.length; i++){
		if (sStr.indexOf(arrBadChars[i]) != -1) {
			return false;
		}
	}
	return true;
}

function ValidateCppDate(sStr, bGetMessage){
 	if (ValidateDate(sStr, false)) {
		//Y2K compatibility- assume "03" date is "2003"
		var arrDate = sStr.split("/");
		if (arrDate[2]) {
			if (parseInt(arrDate[2]) < 1900) {
				arrDate[2] = "20" + arrDate[2]
				sStr = arrDate.join("/");
			}
		}
		
		var dDate = new Date(sStr);
		var dMinDate = MIN_CPP_DATE;
		var dMaxDate = MAX_CPP_DATE;
		if (dDate > dMinDate && dDate < dMaxDate) {
			return bGetMessage ? "" : true;
		}
	}
	return bGetMessage ? ERR_MSG_VALIDATE_CPP_DATE : false;
}