function IsNumericBLN(objField) {

	// INITIALIZE procedure-scope variables.
	var blnNumeric = true
		
	// SCAN string for non-numeric characters.
	for (var i = 0; i < objField.value.length; i++) {
		
		var strDigit = objField.value.charAt(i)
		
		if (strDigit < "0" || strDigit > "9") {	//non-numeric character has been found.
			blnNumeric = false
			break
		}
	}
		
	// ASSIGN return value.
	return blnNumeric
		
}

function TrimSTR(strValue) {

	// REMOVE leading spaces.
	while (true) {
		if (strValue.indexOf(" ") == 0) {								// a leading space has been found so...
			strValue = strValue.substring(1, strValue.length)			// slice it off.
		} else {														// the first character in the string is no longer a space so...
			break														// exit the loop.
		}
	}
		
	// REMOVE trailing spaces.
	if (strValue.length > 0) {	// the string is not null.
		while (true) {
			if (strValue.lastIndexOf(" ") == strValue.length - 1) {			// a trailing space has been found so...
				strValue = strValue.substring(0, strValue.length - 1)	// slice it off.
			} else {													// the last character in the string is no longer a space so...
				break													// exit the loop.
			}
		}
	}

	// ASSIGN return value
	return strValue
}
	
function OpenNewWindow(strPath, option) {
	window.open(strPath, 'test', option)
	return false
}

function CheckStringEmpty(objField, strMessage) {
	
	if (objField.value == "") {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
			
		objField.focus();
		return false
	}
	else {
		if (objField.value.indexOf ('"', 0) > -1) {	// address does not contain the "@" and "." characters.
			OmnCheckFormName('e', objField, "Invalid Character found!");	//Omniture
			alert("Invalid Character found!");
			objField.focus();
			return false;      
		}
		else {	// the address is acceptable.
			return true;      
		}   
	}
}
	
function CheckStringLength(objField, length1, length2, strMessage) {
	
	if (objField.value.length < length1) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}
	if (objField.value.length > length2) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}
	else {
		return true
	}
}
	
function CheckStringEqual(objField, objField2, strMessage) {
	
	if (objField.value != objField2.value) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField2.select()
		objField2.focus();
		return false
	}
	else {
		return true
	}
}
	
function CheckNumericStringEmpty(objField, length, strMessage) {
	
	if (objField.value == "") {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}
	if (!IsNumericBLN(objField)) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus()
		return false
	}
	if (objField.value.length < length) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus()
		return false
	}
	else {
		return true
	}
}
	
function CheckEmailString(objField, strMessage) {
	
	if (objField.value == "") {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select();
		objField.focus();
		return false
	}
	if (!EMailAddressValidBLN(objField)) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select();
		objField.focus();
		return false
	}
	else {
		return true
	}
}
	
function CheckEmailStringFlag(strFlag, objField, strMessage) {
	
	if (strFlag == "Y") {
		if (objField.value == "") {
			OmnCheckFormName('e', objField, strMessage);	//Omniture
			alert(strMessage);
			objField.select();
			objField.focus();
			return false
		}
		if (!EMailAddressValidBLN(objField)) {
			OmnCheckFormName('e', objField, strMessage);	//Omniture
			alert(strMessage);
			objField.select();
			objField.focus();
			return false
		}
		else {
			return true
		}
	}
	else {
		return true
	}
}
	
function EMailAddressValidBLN(objField) {   
		
	if (objField.value.indexOf ('@', 0) == -1 || objField.value.indexOf ('.', 0) == -1) {	// address does not contain the "@" and "." characters.
		
		return false;      
	}
		
	else {	// the address is acceptable.
		return true;      
	}   
}

function chk_CheckAddressString(objField, strMessage) { 
	var addrUpper = objField.value.toUpperCase();
	if( addrUpper.indexOf('PO. BOX') == 0 || 
		addrUpper.indexOf('P0. BOX') == 0 ||
		addrUpper.indexOf('PO. B0X') == 0 ||
		addrUpper.indexOf('P0. B0X') == 0 ||
		addrUpper.indexOf('PO BOX') == 0 || 
		addrUpper.indexOf('P0 BOX') == 0 || 
		addrUpper.indexOf('PO B0X') == 0 || 
		addrUpper.indexOf('P0 B0X') == 0 || 
		addrUpper.indexOf('P.O. BOX') == 0 || 
		addrUpper.indexOf('P.0. BOX') == 0 || 
		addrUpper.indexOf('P.O. B0X') == 0 || 
		addrUpper.indexOf('P.0. B0X') == 0 || 
		addrUpper.indexOf('PO BOX.') == 0 || 
		addrUpper.indexOf('POBOX') == 0 || 
		addrUpper.indexOf('APO') == 0 || 
		addrUpper.indexOf('FPO') == 0) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}
	else {
		return true;      
	}   
}
	
function chk_CheckCityString(objField, strMessage) { 
	var addrUpper = objField.value.toUpperCase();
	if( objField.value.length < 1) {
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}
	if( objField.value.length == 2) {
		if( addrUpper.indexOf('FL') == 0) {
			objField.value = 'FT LAUDERDALE'
			return true
		}
		if( addrUpper.indexOf('NY') == 0) {
			objField.value = 'NEW YORK'
			return true
		}
		if( addrUpper.indexOf('SF') == 0) {
			objField.value = 'SAN FRANCISCO'
			return true
		}
		if( addrUpper.indexOf('LA') == 0) {
			objField.value = 'LOS ANGELES'
			return true
		}
		if( addrUpper.indexOf('SD') == 0) {
			objField.value = 'SAN DIEGO'
			return true
		}
		if( addrUpper.indexOf('KC') == 0) {
			objField.value = 'KANSAS CITY'
			return true
		}
		else {
			return true;      
		}  
	}
	else {
		return true;      
	}
}

function prd_CheckTopSearch(objForm) {
			
	with (objForm) {
				
		// REMOVE trailing and leading spaces from input strings before proceeding with validation.
		SKW.value = TrimSTR(SKW.value)

		if ((SKW.value.length < 1) || (SKW.value == 'Enter Keyword or Item #')) {	
			alert("Please enter a valid Keyword or Item No.");
			SKW.focus()
			return false
		}
		else 
			return true
	}
			
}

function URLEncode(string) {
	string = string.replace(/[ ]/g,"+")
	return escape(string)
}

function fnt_AutoAdvancePhone(objForm, objNext, lngField) {
	if(objForm.value.length >= lngField) {
		objNext.focus();
		objNext.select();
	}
	return true;
}

function OmnCheckFormName(strType, objField, strMessage) {
	var strFormName = objField.form.name;
	var blnCheck = false;
	var strPageName;

	//cart_quantity,order_checkout_form,create_user_form,online_service_form
	switch (strFormName)	
	{
		case ("cart_quantity"):
		  strPageName = "WCGB|HomePage > Product Detail";
		  blnCheck = true;
		  break
		case ("order_checkout_form"):
		  strPageName = "WCGB|HomePage > Order Form";
		  blnCheck = true;
		  break
		case ("create_user_form"):
		  strPageName = "WCGB|HomePage > Create New Account";
		  blnCheck = true;
		  break
		case ("online_service_form"):
		  strPageName = "WCGB|HomePage > Online Service";
		  blnCheck = true;
		  break
		default:
		  strPageName = "";
		  blnCheck = false;
		  break
	}
	if (blnCheck)
	{
		try {
			if (strType == 's')
			{
				s.sendFormEvent(strType,strPageName,strFormName);
			}
			else
			{	
				s.sendFormEvent(strType,strPageName,strFormName,strMessage);
			}
		}
		catch(err){
			//alert(err);
		}
	}		
}