/*
'===========================================================================
'Name:			Validation.js
'Purpose:		Functions should be included on every form on the site.
'Author:		Unknown
'Creation Date:	Unknown
'
'Change History:
'Date			Author					Comments
'07/28/2004		John Lamberton			Added two Data Validation Functions
'02/15/2005     Mark Sellers			STP WES 561 Added ability to ValidateTextArea
'                                        to have default size limit overriden by
'                                        'global' value set in calling proc.
'06/15/2005		John Lamberton			Modified WriteLayer to allow for dynamic class
'										Added CreditCard Validation
'06/21/2005     Selvakumar Palanisamy	Modified ShowTheErrorMessage function to show new 
'				Srinivas R Bheem Reddy  error message with spacer
'08/10/2006		Jacob Stuart			732 - Added Show/Hide Comment Box, also
'										added object check to ValidateTextArea
'08/17/2006		Jacob Stuart			732 - created generic displayDiv which
'										rendered Show/Hide unnecessary
'09/11/2006		Jacob Stuart			751 - added TextValueClear, TextValueReset & 
'										ValidateNotEqual
'10/27/2006		Mason Peeples			803 - Search by Name - added ValidateSpecialChars function
'05/16/2007		Jacob Stuart			940 - Updated Email validation
'01/08/2008		George Blouin			I31322 - Replaced checkDate function to handle leap years
'11/07/2008		Cathy Hubin				1332/I57457 - Added code to strip dashes & spaces 
'										 in ValidateCreditCard()
'===========================================================================
*/

// Preload images
//var ValidateEmpty = new Image(); ValidateEmpty.src = "/Images/Validation/fieldempty.gif";
//var ValidateEmail = new Image(); ValidateEmail.src = "/Images/Validation/emailerror.gif";
//var ValidateZipcd = new Image(); ValidateZipcd.src = "/Images/Validation/ziperror.gif";
//var ValidatePhone = new Image(); ValidatePhone.src = "/Images/Validation/phoneerror.gif";

var defaultEmptyOK = false;
var bLeftAlign=false;
var bSmall=false;
var ValidateHaveErrors = 0;

var strSpacer = "&nbsp;";
var strSpacerImage = '<img src="/images/spacer.gif" height="21px" width="1px" style="VERTICAL-ALIGN: top;" />';
var blnImageSpacer = new Boolean(false);

// Set up constants for all standard references in the site
var cRewritableError = 1;
var cRewritableTotal = 2;
var cRewritableGiving = 3;
var cRewritableCustom = 4;
var strRewritableClass;

var iRewritableType = cRewritableError; //Use for Netscape 4.x browsers in the function
										//rewriteLayer..

var g_intTextAreaSizeLimit = 0;		// use for default textarea size limit override value. Set in calling procedure.

function checkDate(dteDateToEvaluate) {
    var dteTest = new Date(dteDateToEvaluate);
    if (dteTest.toString() == 'NaN' || dteTest.toString() == 'Invalid Date') {
        return false;
    } else {
        return true;
    }
}

//
// Netscape 4.x
// Note: This function gets called when page validation occurs.
// When writing into layers, Netscape 4.x target elements must have a 
// position: relative or position: abolute defined in the style sheet, otherwise a 
// bug will occur that prompts the user to download a file or the page may not
// even be displed properly.
// Example:
//   Element:
//		<div Width="100%" ID="NameError" CLASS="RewritableError">&nbsp;</div>
//
//   Style Sheet:
//		DIV.RewritableError
//		{
//			BORDER-RIGHT: 1px;
//			BORDER-TOP: 1px;
//			BORDER-LEFT: 1px;
//			WIDTH: 150px;
//			COLOR: red;
//			BORDER-BOTTOM: 1px;
//			POSITION: relative
//		}
// 
// For additional information, see article http://www.xs4all.nl/~ppk/js/layerwrite.html
//
//
function writeLayer (id, html, strClass) {
	if (document.all)
	  document.all[id].innerHTML = html;
	else if (document.getElementById)
	  document.getElementById(id).innerHTML = html;
	else  rewriteLayer (id, html, strClass); 
}


function rewriteLayer (id, html, strClass) {
	var intOldRewritableType = iRewritableType;
	if (strClass != null) {
		iRewritableType = cRewritableCustom;
		strRewritableClass = strClass;
	}
	switch (iRewritableType) {
		case 1 :
			html = '<DIV CLASS="RewritableError">' + html + '</DIV>';
			break;
	
		case 2 :
			html = '<DIV CLASS="RewritableTotal">' + html + '</DIV>';
		    break;
	
		case 3 :
			html = '<DIV CLASS="RewritableGiving">' + html + '</DIV>';
			break;
		case 4:
			html = '<div class="' + strRewritableClass + '">' + html + '</div>';
			break;
	}
	iRewritableType = intOldRewritableType;
 
  if (document.layers) {
    var l = document[id];
    if (!l.ol) {
     var ol = l.ol = new Layer (l.clip.width);
     // comment the following line out if your div is initially empty
     ol.clip.width = l.clip.width; ol.clip.height = l.clip.height;
     ol.left = l.pageX; ol.top = l.pageY;
     ol.bgColor = l.bgColor;
     l.visibility = 'hide';
    }
    var ol = l.ol;
   ol.document.open();
   ol.document.write(html);
   ol.document.close();
   ol.visibility = 'show';
  }
  else if (document.all)
    document.all[id].innerHTML = html;
}   

function ShowTheErrorMessage(TheDivName, ErrorText, bErrors) {
	var html;
	var TempText;
	TempText = ErrorText;
	var sSize="2";
	if (bSmall) sSize="1";
	if(TempText == "") TempText = strSpacer;
	
	//if(!bLeftAlign) html="<p style= \"margin-top: 0; margin-bottom: 0\" align=right>" + TempText + "</b></font></p>";
	//if(bLeftAlign) html="<p style= \"margin-top: 0; margin-bottom: 0\" align=left>" + TempText + "</b></font></p>";
	if(blnImageSpacer == true && TempText != "")
		html = TempText + strSpacerImage;
	else
		html = TempText;
	
	if (!ValidateHaveErrors && bErrors) ValidateHaveErrors = bErrors;
	if (document.all)
	  //Internet Explorer
	  	  
	  document.all[TheDivName].innerHTML = html;
	  
	else if (document.getElementById)
	  document.getElementById(TheDivName).innerHTML = html;
	//Netscape 4 (Yuck!) 
	else  rewriteLayer (TheDivName, html); //alert("Bad Netscape"); 
	}


/*
'===========================================================================
'Function:			objectID
'Purpose:			get an object handle.
'Input:				id			The object id name
'===========================================================================
*/
function objectID(id){
	var oid;
	if (is_all == true) {
		oid = document.all[id]; 
	} else if (is_layers == true) {
		 oid = document[id];
	} else { // if (is_getElementById)
		oid = document.getElementById(id);
	}
	return oid;
}

/*
'===========================================================================
'Function:			hideDiv
'Purpose:			Hide a div layer
'Input:				id			The div id name
'===========================================================================
*/
function hideDiv(id){
	var oid = objectID(id);
	if (is_nav4) {
		oid.visibility = 'hidden';
	} else {
		oid.style.visibility = 'hidden';
	}
}
/*
'===========================================================================
'Function:			showDiv
'Purpose:			Show a div layer.
'Input:				id			The div id name
'===========================================================================
*/
function showDiv(id){
	var oid = objectID(id);
	if (is_nav4) {
		oid.visibility = 'visible';
	} else {
		oid.style.visibility = 'visible';
	}
}
/*
'===========================================================================
'Function:			displayDiv
'Purpose:			Display/Hide a div layer.
'Input:				strDivID	a string with the Div ID
'					blnDisplay	boolean to show or hide layer
'===========================================================================
*/
function displayDiv( strDivID, blnDisplay ){
	var objDivID = objectID(strDivID);
	if (blnDisplay) {
		objDivID.style.display = 'block';
	}
	else {
		objDivID.style.display = 'none';
	}
}

function TextValueClear( strFormField, strCheckValue ) {
	var objFormField = strFormField
	if (typeof(objFormField) != 'object'){ objFormField = objectID(objFormField) };
	if (objFormField.value == strCheckValue) {objFormField.value = '';}
}

function TextValueReset( strFormField, strCheckValue ) {
	var objFormField = strFormField
	if (typeof(objFormField) != 'object'){ objFormField = objectID(objFormField) };
	if (objFormField.value == '') {objFormField.value = strCheckValue;}
}

function ValidateSponsorNumber(txtTemp,DivError,Required) {
	if(!Required && isWhitespace(txtTemp.value)) {
			ShowTheErrorMessage(DivError, "", false)
			return true;
			}
	if(Required && isWhitespace(txtTemp.value)) {
			ShowTheErrorMessage(DivError, "Invalid Sponsor #", true)
			return false;
			}
	(!isNonnegativeInteger(txtTemp.value) | txtTemp.value.length < 6 | txtTemp.value.length > 10 )
	? ShowTheErrorMessage(DivError, "Invalid Sponsor #", true)
	: ShowTheErrorMessage(DivError, "", false);
	}

function ValidateTextArea(txtTemp,DivError,Required) {
	var iLength;
	var iMax;
	//MAS 2/11/05 added for STP 561 which now retrieves the text area size limit for one page
	//from the new local_value table. If this global variable isn't set, then use the 2000
	//default size, otherwise use the global value set by the caller.
	if (g_intTextAreaSizeLimit == 0) {
		iMax=2000;
	} else {
		iMax = g_intTextAreaSizeLimit;
	}
	
	if (typeof(txtTemp) == 'object') {
		iLength=txtTemp.value.length;	
	
		if(iLength > iMax) {
				ShowTheErrorMessage(DivError, "Text Too Long (Max. " + iMax + ")", true)
				return false;
		}

		if ((iLength <= iMax) && (!Required)) {
				ShowTheErrorMessage(DivError, "", false)
				return true;
		}
	
		if (iLength > 0 && (iLength <= iMax)) {
				ShowTheErrorMessage(DivError, "", false)
				return true;
		}

		if(Required && isWhitespace(txtTemp.value)) {
				ShowTheErrorMessage(DivError, "Required Field", true)
				return false;
		}
	
		if(!Required && isWhitespace(txtTemp.value)) {
				ShowTheErrorMessage(DivError, "", false)
				return true;
		}
	}
	else {
		return true;
	}
}


function ValidateCombo(cboTemp,DivError) {
	(cboTemp.selectedIndex<=0)
	? ShowTheErrorMessage(DivError, "Make A Selection", true)
	: ShowTheErrorMessage(DivError, "", false);
	}
	
function ValidateRadio(optTemp,iCount, DivError,sMessage) {
	var i;
	var bSelected=false;
	for (i = 0; i < iCount; i++) {
		if(optTemp[i].checked) bSelected=true;
	}	
	(!bSelected)
	? ShowTheErrorMessage(DivError, sMessage, true)
	: ShowTheErrorMessage(DivError, "", false);
	}
	
function ValidateNonNegativeInteger(txtTemp,DivError) {
	(isNonnegativeInteger(txtTemp.value)==false)
	? ShowTheErrorMessage(DivError, "Integer Required", true)
	: ShowTheErrorMessage(DivError, "", false);
	}

function ValidateAmount(txtTemp,DivError) {
	(isNonnegativeInteger(txtTemp.value)==false)
	? ShowTheErrorMessage(DivError, "Amount Required", true)
	: ShowTheErrorMessage(DivError, "", false);
	}
	
function ValidateNonBlank(txtTemp,DivError) {
	(isWhitespace(txtTemp.value)==true) 
	? ShowTheErrorMessage(DivError, "Required Field", true)
	: ShowTheErrorMessage(DivError, "", false);
	}

function ValidateMustBeBlank(txtTemp,DivError) {
	(isWhitespace(txtTemp.value)==false) 
	? ShowTheErrorMessage(DivError, "Field Not Blank", true)
	: ShowTheErrorMessage(DivError, "", false);
	}
	
function ValidateNotEqual(txtTemp, strCompare, DivError) {
	if(isWhitespace(txtTemp.value)) {
		ShowTheErrorMessage(DivError, "Required Field", true);
		}
	else{
		if(txtTemp.value==strCompare) {
			ShowTheErrorMessage(DivError, 'Required Field - cannot equal ' + strCompare, true);
			}
		else {
			ShowTheErrorMessage(DivError, "", false);
			}
		}
	}
	
function ValidateStateAndZip(txtState, txtZip, DivError) {
	var normalizedZIP = stripCharsInBag(txtZip.value, ZIPCodeDelimiters);
	(!isStateCode(txtState.value.toUpperCase(), false) | !isZIPCode(normalizedZIP, false)) 
	? ShowTheErrorMessage(DivError, "Required Fields", true)
	: ShowTheErrorMessage(DivError, "", false);	
	if (isStateCode(txtState.value.toUpperCase(), false)) txtState.value = txtState.value.toUpperCase();
	if(isZIPCode(normalizedZIP, false)) txtZip.value = reformatZIPCode(normalizedZIP);
	}

function ValidateCityStateAndZip(txtCity, txtState, txtZip, DivError) {
	var normalizedZIP = stripCharsInBag(txtZip.value, ZIPCodeDelimiters);
	(!isStateCode(txtState.value.toUpperCase(), false) | !isZIPCode(normalizedZIP, false) | isWhitespace(txtCity.value)==true) 
	? ShowTheErrorMessage(DivError, "Required Fields", true)
	: ShowTheErrorMessage(DivError, "", false);	
	if (isStateCode(txtState.value.toUpperCase(), false)) txtState.value = txtState.value.toUpperCase();
	if(isZIPCode(normalizedZIP, false)) txtZip.value = reformatZIPCode(normalizedZIP);
	}
	
function ValidateStateAndZipMustBeBlank(txtState, txtZip, DivError) {
	(!isWhitespace(txtState.value) | !isWhitespace(txtZip.value)) 
	? ShowTheErrorMessage(DivError, "Fields Not Blank", true)
	: ShowTheErrorMessage(DivError, "", false);	
	}
	
function ValidateUSPhone(txtTemp,DivError,Required) {
	var normalizedHomePhone = stripCharsInBag(txtTemp.value, phoneNumberDelimiters);
	var sUSPhone = new String(normalizedHomePhone);
	
	if(sUSPhone != "")
	{
		if(sUSPhone.charAt(0) == 0 || sUSPhone.charAt(0) == 1)
		{
			ShowTheErrorMessage(DivError, "Phone number should be (555) 555-5555.", true);
			return;
		}
	}
	
	(isUSPhoneNumber(normalizedHomePhone, !Required)==false) 
	? ShowTheErrorMessage(DivError, "Phone number should be (555) 555-5555.", true)
	: ShowTheErrorMessage(DivError, "", false);	
	if(isUSPhoneNumber(normalizedHomePhone, false)) txtTemp.value = reformatUSPhone(normalizedHomePhone);
	}
	
function ValidateGenericPhone(txtTemp,DivError,Required) {
	var normalizedHomePhone = stripCharsInBag(txtTemp.value, phoneNumberDelimiters);
	if(isUSPhoneNumber(normalizedHomePhone, false)) txtTemp.value = reformatUSPhone(normalizedHomePhone);
	if (Required) {
		(isNonnegativeInteger(normalizedHomePhone)==false) 
		? ShowTheErrorMessage(DivError, "Invalid Phone#", true)
		: ShowTheErrorMessage(DivError, "", false);	
		}
	if (!Required) {
		(isNonnegativeInteger(normalizedHomePhone)==false && !isWhitespace(normalizedHomePhone)) 
		? ShowTheErrorMessage(DivError, "Invalid Phone#", true)
		: ShowTheErrorMessage(DivError, "", false);	
		}
	}

function ValidateAnEmail(txtTemp,DivError) {
	ValidateEmail(txtTemp, DivError, false);
//	(isEmail(txtTemp.value)==false && isWhitespace(txtTemp.value)==false)
//	? ShowTheErrorMessage(DivError, "Invalid E-mail", true)
//	: ShowTheErrorMessage(DivError, "", false);	
	}

function ValidateAnEmailRequired(txtTemp,DivError) {
	ValidateEmail(txtTemp, DivError, true);
/*	if (isWhitespace(txtTemp.value)==false) {
		ValidateEmail(txtTemp,DivError);
//		(isEmail(txtTemp.value)==false)
//		? ShowTheErrorMessage(DivError, "Invalid E-mail", true)
//		: ShowTheErrorMessage(DivError, "", false);	
		}
	else {
		ShowTheErrorMessage(DivError, 'Required Field', true);
		}
*/	}
	
function ValidateAnEmail2(txtTemp,DivError,DivError2) {
	(isEmail(txtTemp.value)==false && isWhitespace(txtTemp.value)==false)
	? ShowTheErrorMessage(DivError, "Invalid Email", true)
	: ShowTheErrorMessage(DivError, "", false);	
	bLeftAlign=true;
	bSmall=true;
	(isEmail(txtTemp.value)==false && isWhitespace(txtTemp.value)==false)
	? ShowTheErrorMessage(DivError2, "Requires An @ And a Period.  Example: Bob@AOL.com", true)
	: ShowTheErrorMessage(DivError2, "", false);	
	bLeftAlign=false;
	bSmall=false;
	}
	
function ValidateInternationalPhone(txtTemp,DivError,Required) {
	(isInternationalPhoneNumber(txtTemp.value,!Required)==false) 
	? ShowTheErrorMessage(DivError, "Invalid Phone#", true)
	: ShowTheErrorMessage(DivError, "", false);	
	}

function ValidateAccountNumber(txtTemp,DivError,Required) {
	var i;
	var sValue;
	sValue=txtTemp.value;
	if (Required && isWhitespace(sValue)) {
		ShowTheErrorMessage(DivError, "Required Account Number", true);
		return false;
		}
	// Characters can only be digits, spaces or dashes
	for (i = 0; i < sValue.length; i++) {
		var c = sValue.charAt(i);
		if ( (!isDigit(c)) && (c != " ") && (c != "-") ) {
			ShowTheErrorMessage(DivError, "Invalid Account Number", true);
			return false;
			}
		}
	ShowTheErrorMessage(DivError, "", false);
	return true;
	}

function ValidateRoutingNumber(txtTemp,DivError,Required) {
	var sValue;
	sValue=txtTemp.value;
	if (Required && isWhitespace(sValue)) {
		ShowTheErrorMessage(DivError, "Required Routing Number", true);
		return false;
		}
	if(!isNonnegativeInteger(sValue) || sValue.length !=9) {
		ShowTheErrorMessage(DivError, "9 Digits (No Spaces)", true);
		return false;
		}
	var intStartValue = Number(sValue.substr(0,2));
	if (intStartValue < 1 || intStartValue > 32	|| (intStartValue >= 13 && intStartValue <= 20)){
		ShowTheErrorMessage(DivError, "Invalid Routing Number", true);
		return false;
	}
	var intSum = 0;
	for (var i = 0; i < sValue.length; i += 3) {
		intSum += parseInt(sValue.charAt(i), 10) * 3
		+  parseInt(sValue.charAt(i + 1), 10) * 7
		+  parseInt(sValue.charAt(i + 2), 10);
	}
	if (intSum%10 == 0) {
		//Good number
	} else {
		ShowTheErrorMessage(DivError, "Invalid Routing Number", true);
		return false;
	}
	
	ShowTheErrorMessage(DivError, "", false);
	return true;
	}

function ValidateSpecialChars(strUserInput) {
	var reg = new RegExp('[\x00-\x08\x0B\x0E-\x1F\x7f-\xbf\xc2-\xc7\xca-\xcb\xce-\xd0\xd4-\xd8\xdb-\xdf\xe2-\xe7\xea\xeb\xee-\xf0\xf4-\xf8\xfb-\xff]+');
	if (strUserInput.match(reg)) {
	  return true;
	}
	else {
	  return false;
	}  
	}

/*
'===========================================================================
'Function:			ValidateCreditCard
'Purpose:			Validate Credit Card is correctly formatted.
'Input:				CardType				Visa, MC, etc
'					CardNumber				Credit Card Number
'					DivError				Div tag name to display error
'					Required				Bool
'===========================================================================
*/
function ValidateCreditCard(CardType, CardNumber, DivError, Required){
	ShowTheErrorMessage(DivError, "", false);
	if (Required && isWhitespace(CardNumber.value)) {
		ShowTheErrorMessage(DivError, "Required Card Number", true);
		return false;
	}
	if (! isCardMatch(CardType.value, CardNumber.value.replace(/-| /g,''))) {
		ShowTheErrorMessage(DivError, "Invalid Card Number", true);
		return false;
	}
	return true;
}

/*
'===========================================================================
'Function:			ValidateCreditCardExp
'Purpose:			Validate Credit Card Expiration.
'Input:				cboMonth				Month Combo Box
'					cboYear					Year Combo Box
'					DivError				Div tag name to display error
'					Required				Bool
'===========================================================================
*/
function ValidateCreditCardExp(cboMonth, cboYear, DivError, Required){
	ShowTheErrorMessage(DivError, "", false);
	if (Required){
		if ((cboMonth.selectedIndex <= 0) || (cboYear.selectedIndex <= 0)) {
			ShowTheErrorMessage(DivError, "Make A Selection", true);
			return false;
		} else {
			var dTemp = new Date();
			var dTempDate = new Date(cboYear.value, cboMonth.value - 1, 1);
			dTempDate.setMonth(dTempDate.getMonth() + 1);
			dTempDate.setDate(dTempDate.getDate() - 1);
			if (dTempDate < dTemp) {
				ShowTheErrorMessage(DivError, "Card Has Expired", true);
				return false;
			}
		}
	}
	return true;
}

/*
'===========================================================================
'Function:			ValidateDate
'Purpose:			Validate date is correctly formatted.
'Input:				txtTemp					string date in form MM/DD/YYYY
'					DivError				Div tag name to display error
'					Required				Bool
'===========================================================================
*/
function ValidateDate(txtTemp,DivError,Required) {
	var sValue;
	sValue = txtTemp.value;
	if (Required && isWhitespace(sValue)) {
		ShowTheErrorMessage(DivError, "Required Date", true);
		return false;
	} else {
		if (checkDate(sValue)==false) {
			ShowTheErrorMessage(DivError, "Invalid Date", true);
			return false;
		}
	}
	ShowTheErrorMessage(DivError, "", false);
	return true;
}

/*
'===========================================================================
'Function:			ValidateDateAfter
'Purpose:			Validate date is after objDateAfter.
'Input:				txtTemp					string date in form MM/DD/YYYY
'					DivError				Div tag name to display error
'					objDateAfter			JavaScript Date Obj with date to compare
'					Required				Bool
'					CustomError				Custom Error String
'===========================================================================
*/
function ValidateDateAfter(txtTemp,DivError,objDateAfter,Required,CustomError) {
	var sValue;
	sValue = txtTemp.value;
	if (Required && isWhitespace(sValue)) {
		ShowTheErrorMessage(DivError, "Required Date", true);
		return false;
		} else if (Required || !isWhitespace(sValue)){
		if (checkDate(sValue)==false) {
			ShowTheErrorMessage(DivError, "Invalid Date", true);
			return false;
			} else {
			iMonth = sValue.substring(0, 2) - 1; //Adjust for starting at 0
			iDay = sValue.substring(3, 5);
			iYear = sValue.substring(6, 10);

			var objDateValue;
			objDateValue = new Date(iYear, iMonth, iDay);
			if (objDateValue.getTime() < objDateAfter.getTime()) {
				(CustomError != '')
				?ShowTheErrorMessage(DivError, CustomError, true)
				:ShowTheErrorMessage(DivError, "Date must be after<br />" + (objDateAfter.getMonth() + 1) + '/' + objDateAfter.getDate() + '/' + objDateAfter.getYear(), true);
				return false;
				}
			}
		}
	ShowTheErrorMessage(DivError, "", false);
	return true;
	}
	
/*
'===========================================================================
'Function:			ValidateDateBefore
'Purpose:			Validate date is after ValidateDateBefore.
'Input:				txtTemp					string date in form MM/DD/YYYY
'					DivError				Div tag name to display error
'					objDateBefore			JavaScript Date Obj with date to compare
'					Required				Bool
'					CustomError				Custom Error String
'===========================================================================
*/
function ValidateDateBefore(txtTemp,DivError,objDateBefore,Required,CustomError) {
	var sValue;
	sValue = txtTemp.value;
	if (Required && isWhitespace(sValue)) {
		ShowTheErrorMessage(DivError, "Required Date", true);
		return false;
		} else if (Required || !isWhitespace(sValue)){
		if (checkDate(sValue)==false) {
			ShowTheErrorMessage(DivError, "Invalid Date", true);
			return false;
			} else {
			iMonth = sValue.substring(0, 2) - 1; //Adjust for starting at 0
			iDay = sValue.substring(3, 5);
			iYear = sValue.substring(6, 10);

			var objDateValue;
			objDateValue = new Date(iYear, iMonth, iDay);
			if (objDateValue.getTime() > objDateBefore.getTime()) {
				(CustomError != '')
				?ShowTheErrorMessage(DivError, CustomError, true)
				:ShowTheErrorMessage(DivError, "Date must be Before<br />" + (objDateBefore.getMonth() + 1) + '/' + objDateBefore.getDate() + '/' + objDateBefore.getYear(), true);
				return false;
				}
			}
		}
	ShowTheErrorMessage(DivError, "", false);
	return true;
	}


/*
'===========================================================================
'Function:			ValidateUSPostalCode
'Purpose:			Validate US Postal Code if the selected Country is US.
'Input:				txtTemp					string 
'					DivError				Div tag name to display error
'===========================================================================
*/

function ValidateUSPostalCode(txtTemp,DivError) {
	var objRegExp  = /^\d{5}(-\d{4})?$/;
	txtTemp.value = txtTemp.value.replace(" ","");
	if(isWhitespace(txtTemp.value)==false)
	{	
		(objRegExp.test(txtTemp.value)==false) 
		? ShowTheErrorMessage(DivError, "Zip Code should be 12345 or 12345-1234.", true)
		: ShowTheErrorMessage(DivError, "", false);
	}
}

/*
'===========================================================================
'Function:			ValidateEmail
'Purpose:			Validate an Email.
'Input:				txtTemp					string 
'					DivError				Div tag name to display error
'===========================================================================
*/

function ValidateEmail(txtTemp, strDivError, blnRequired) {
	// Reset Error
	ShowTheErrorMessage(strDivError, '', false);

	var blnRequireEmail = false;
	if (arguments.length > 2) blnRequireEmail = blnRequired;
	if (blnRequireEmail && isWhitespace(txtTemp.value)) {
		ShowTheErrorMessage(strDivError, 'Required Field', true);
	}
	else {
		var objRegExpSimple = /^^[\w_\+-]+(\.[\w_\+-]+)*@[\w-]+(\.[\w-]+)*\.([a-zA-Z]{2,4})$/;
		var objRegExpComplex  = /^[\w,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[\w,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[\w-]+(\.[\w-]+)*\.([a-zA-Z]{2,})$/;

		if(isWhitespace(txtTemp.value)==false)
		{
			if (objRegExpSimple.test(txtTemp.value)==false)
			{
				if (objRegExpComplex.test(txtTemp.value)==false)
				{
					ShowTheErrorMessage(strDivError, 'Invalid E-mail', true)
				}
				else
				{
					if (!confirm('Please check your e-mail address. Do you wish to continue?')) ShowTheErrorMessage(strDivError, 'Verify E-mail', true);
				}
			}
		}
	}
}

function ValidatePhoneExtn(txtTemp,DivError) {
	var VInt = new Boolean(true);
	var sTemp = txtTemp.value;
	var i;
	
	for(i=0;i<sTemp.length;i++)
	{
		if(isNaN(sTemp.charAt(i)))
			VInt = false;
	}
	
	(!VInt) 
	? ShowTheErrorMessage(DivError, "Extension should be a number.", true)
	: ShowTheErrorMessage(DivError, "", false);
}

function ValidateWorkPhoneandExtn(txtPhone, txtExtn, DivError) {
	if(isWhitespace(txtExtn.value)==false)
	{	
		(isWhitespace(txtPhone.value)==true)
		? ShowTheErrorMessage(DivError, "Enter business phone number.", true)
		: ShowTheErrorMessage(DivError, "", false);
	}
	else
	{
		ShowTheErrorMessage(DivError, "", false);
	}
}

/*
'===========================================================================
'Function:			ValidatePreferredPhone
'Purpose:			Validate an Email.
'Input:				txtHPhone					string
'					txtWPhone					string  
'					txtCPhone					string  
'					txtPrefPhone				string  
'					DivError					Div tag name to display error
'===========================================================================
*/

function ValidatePreferredPhone(txtHPhone,txtWPhone,txtCPhone,txtPrefPhone,DivError) {
	if((isWhitespace(txtHPhone.value)==false) || (isWhitespace(txtWPhone.value)==false) || (isWhitespace(txtCPhone.value)==false))
	{	
		var ValidPrefPhone = new Boolean(true);
		
		if(((isWhitespace(txtHPhone.value)==true) && (txtPrefPhone[0].checked == true)) || ((isWhitespace(txtWPhone.value)==true) && (txtPrefPhone[1].checked == true)) || ((isWhitespace(txtCPhone.value)==true) && (txtPrefPhone[2].checked == true)))
			ValidPrefPhone = false;

		(!ValidPrefPhone)
		? ShowTheErrorMessage(DivError, "Choose a preferred phone number.", true)
		: ShowTheErrorMessage(DivError, "", false);
	}
}

function ValidateCountry(cboTemp,DivError) {
	(cboTemp.selectedIndex==1)
	? ShowTheErrorMessage(DivError, "Make A Selection", true)
	: ShowTheErrorMessage(DivError, "", false);
	}


