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 IsNumericMSG(objField, strMessage) {

	// 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.
			alert(strMessage);
			objField.select()
			objField.focus();
			return false
			break
		}
	}
		
	// ASSIGN return value.
	return true
		
}

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 (chk_XSSCheckField(objField)) {
	}
	else {
		chk_XSSRemoveField(objField);
		return false;
	}     
	if (objField.value == "") {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
				
		objField.focus();
		return false;
	}
	else {
		return true;
	}
}
	
function CheckNotRequiredField(objField) {
	
	if (chk_XSSCheckField(objField)) {
	}
	else {
		chk_XSSRemoveField(objField);
		return false;
	}     
	if (objField.value == "") {
		return true;
	}
	else {
		return true;
	}
}
	
function CheckStringEmptyDelete(objField, strMessage) {
	
	if (chk_XSSCheckField(objField)) {
	}
	else {
		chk_XSSRemoveField(objField);
		return false;
	}     
	if (objField.value == "") {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.value = "";
		objField.focus();
		return false
	}
	else {
		return true;
	}
}
	
function CheckStringEmptyDeleteMove(objField1, objField2, strMessage) {
	
	if (chk_XSSCheckField(objField1)) {
	}
	else {
		chk_XSSRemoveFieldTwo(objField1);
		return false;
	}     
	if (objField1.value == "") {
		OmnCheckFormName('e', objField1, strMessage);	//Omniture
		alert(strMessage);
		objField2.value = "";
		objField2.focus();
		return false
	}
	else {
		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 CheckStringEqualDelete(objField, objField2, strMessage) {
	
	if (objField.value != objField2.value) {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField2.value = "";
		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.
		if (chk_XSSCheckField(objField)) {
			return true; 
		}
		else {
			chk_XSSRemoveField(objField);
			return false;
		}     
	}   
}

function chk_CheckAddressString(objField, strMessage) { 
	if(chk_CheckAddressStringBLN(objField)) {
		return true;      
	}
	else {
		OmnCheckFormName('e', objField, strMessage);	//Omniture
		alert(strMessage);
		objField.select()
		objField.focus();
		return false
	}   
}
	
function chk_CheckAddressStringBLN(objField) { 
	var addrUpper = objField.value.toUpperCase();
	addrUpper = addrUpper.replace(/[ ]/g,"")
	addrUpper = addrUpper.replace(/[.]/g,"")
	if( addrUpper.indexOf('POBOX') == 0 || 
		addrUpper.indexOf('P0BOX') == 0 || 
		addrUpper.indexOf('POB0X') == 0 || 
		addrUpper.indexOf('P0B0X') == 0 || 
		addrUpper.indexOf('APO') == 0 || 
		addrUpper.indexOf('FPO') == 0) {
		return false
	}
	else {
		return true;      
	}   
}
	
function chk_CheckAddressValueBLN(strValue) { 
	var addrUpper = strValue.toUpperCase();
	addrUpper = addrUpper.replace(/[ ]/g,"")
	addrUpper = addrUpper.replace(/[.]/g,"")
	if( addrUpper.indexOf('POBOX') == 0 || 
		addrUpper.indexOf('P0BOX') == 0 || 
		addrUpper.indexOf('POB0X') == 0 || 
		addrUpper.indexOf('P0B0X') == 0 || 
		addrUpper.indexOf('APO') == 0 || 
		addrUpper.indexOf('FPO') == 0) {
		return false
	}
	else {
		return true;      
	}   
}
	
function chk_CheckCityString(objField, strMessage) { 
	var addrUpper = objField.value.toUpperCase();
	if (chk_XSSCheckField(objField)) {
	}
	else {
		chk_XSSRemoveField(objField);
		return false;
	}     
	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 CheckRadioSelected(objField, strMessage)
 {
   
	radio_select = -1;
	radio_length = objField.length;
	if (radio_length == undefined) {
		if (objField.checked) {
			return true
		}
		else{
			OmnCheckFormName('e', objField, strMessage);	//Omniture
			alert(strMessage);
			return false
		}
	}
	else {
		for (i=radio_length-1;i> -1;i--) {
			if (objField[i].checked) {
				radio_select = i;
				i = -1;
			}
		}
		
		if (radio_select < 0) {
			OmnCheckFormName('e', objField, strMessage);	//Omniture
			alert(strMessage);
			return false
		}
		else {
			return true
		}
	}
}  

function CheckDropSelected(sel, strMessage) {

	if (sel.options[sel.selectedIndex].value != '') {
		return true
	}
	else {
		OmnCheckFormName('e', sel, strMessage);	//Omniture
		alert(strMessage);
		sel.focus();
		return false
	}
}

function prd_CheckTopSearch(objForm) {
			
	var sel = objForm.HKW; 
	value_selected = sel.options[sel.selectedIndex].value

	with (objForm) {
				
		// REMOVE trailing and leading spaces from input strings before proceeding with validation.
		SKW.value = TrimSTR(SKW.value)

		if (chk_XSSCheckField(SKW)) {
		}
		else {
			chk_XSSRemoveField(SKW);
			return false;
		}     
		if ((SKW.value.length < 1) || (SKW.value == 'Enter Keyword or Item #')) {
			if (value_selected == 'all') {
				alert("Please enter a valid Keyword or Item No.");
				SKW.focus()
				return false
			}
			else {
				SKW.value = value_selected;
				return true
			}
		}
		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;

	//item_add,order_checkout_form,create_user_form,online_service_form
	switch (strFormName)	
	{
		case ("item_add"):
		  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);
		}
	}		
}

// Display the H1 tag to the bottom of the homepage
function DisplayH1() {
	if (document.getElementById("wc_h1tag")) {
		var h1Tag=document.getElementById("wc_h1tag").firstChild.innerHTML;
		document.write(h1Tag);
	}
}
// Display Hidden DIV tag to the bottom of the page
function DisplayCategoryDIV() {
	if (document.getElementById("wc_category_div")) {
		var h1Tag=document.getElementById("wc_category_div").innerHTML;
		document.write(h1Tag);
	}
}
function DisplayDivMenu(divId) {
	if (document.getElementById(divId)) {
		document.getElementById(divId).style.visibility = 'visible';
	}
}
function HideDivMenu(divId) {
	if (document.getElementById(divId)) {
		document.getElementById(divId).style.visibility = 'hidden';
	}
}

 function DisplayDivObject(object,widthpostions,heightposition)
 {
 	var width = 0;
 	var height = 0;
 	var winWidth = 0;
 	var winHeight = 0;
 	var winSize = 900;
 	var minWidth = 190;
 	if( typeof( window.innerWidth ) == 'number' ) {
 		winWidth = window.innerWidth;
 		winHeight = window.innerHeight;
 		height = heightposition;
 		if (winWidth < winSize) { width = widthpostions + 20; }
 		else { width = (winWidth - winSize)/2 + widthpostions; }
 	} else {
 		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
 			winWidth = document.documentElement.clientWidth;
 			winHeight = document.documentElement.clientHeight;
 			height = heightposition;
 			if (winWidth < winSize) { width = minWidth; }
 			else { width = (winWidth - winSize)/2 + widthpostions; }
 		} else {
 			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
 				winWidth = document.body.clientWidth;
 				winHeight = document.body.clientHeight;
 				height = heightposition;
 				if (winWidth < winSize) { width = minWidth; }
 				else { width = (winWidth - winSize)/2 + widthpostions; }
 			}
 		}
 	}
 	if (document.getElementById) {
 	  document.getElementById(object).style.left = width;
 	  document.getElementById(object).style.top = height;
 	  document.getElementById(object).style.visibility = 'visible';
 	}
 	else if (document.layers && document.layers[object]) {
 	  document.layers[object].style.left = width;
 	  document.layers[object].style.top = height;
 	  document.layers[object].visibility = 'visible';
 	}
 	else if (document.all) {
 	  document.all[object].style.left = width;
 	  document.all[object].style.top = height;
 	  document.all[object].style.visibility = 'visible';
 	}
}

function HideDivObject(object) {
	if (document.getElementById) {
	  document.getElementById(object).style.visibility = 'hidden';
	}
	else if (document.layers && document.layers[object]) {
	  document.layers[object].visibility = 'hidden';
	}
	else if (document.all) {
	  document.all[object].style.visibility = 'hidden';
	}
}

function chk_ValidateEmailOfferForm(objForm) {

	with (objForm) {
				
		// REMOVE trailing and leading spaces from input strings before proceeding with validation.
		email.value = TrimSTR(email.value)

		if (CheckEmailString(objForm.email, "Please enter a valid Email.")) {
			return true
		}
		else {
			return false
		}
	}
}
		
function tmp_WineStateChecker(objForm) {

	var sel = objForm.wine_state; 

	value_selected = sel.options[sel.selectedIndex].value
	if (value_selected == '') {
		return false
	}
	else {
		if ( value_selected == "Y" ) {
			wine_default.style.display = "none"; 
			wine_no.style.display = "none"; 
			wine_restric.style.display = "none"; 
			wine_yes.style.display = "block"; 
			return false
		}
		if ( value_selected == "R" ) {
			wine_default.style.display = "none"; 
			wine_yes.style.display = "none"; 
			wine_no.style.display = "none"; 
			wine_restric.style.display = "block"; 
			return false
		}
		else {
			wine_default.style.display = "none"; 
			wine_yes.style.display = "none"; 
			wine_restric.style.display = "none"; 
			wine_no.style.display = "block"; 
			return false
		}
	}
}

function chk_XSSCheckField(objField) { 
	var addrUpper = objField.value.toUpperCase();
	if( addrUpper.indexOf('<') >= 0 || 
		addrUpper.indexOf('>') >= 0 || 
		addrUpper.indexOf('X20') >= 0 || 
		addrUpper.indexOf('X00') >= 0 || 
		addrUpper.indexOf('X0a') >= 0 || 
		addrUpper.indexOf('X0b') >= 0 || 
		addrUpper.indexOf('X1b') >= 0 || 
		addrUpper.indexOf('X08') >= 0 || 
		addrUpper.indexOf('$') >= 0 || 
		addrUpper.indexOf('{') >= 0 || 
		addrUpper.indexOf('}') >= 0 || 
		addrUpper.indexOf('[') >= 0 || 
		addrUpper.indexOf(']') >= 0 || 
//		addrUpper.indexOf('"') >= 0 || 
//		addrUpper.indexOf('(') >= 0 || 
//		addrUpper.indexOf(')') >= 0 || 
//		addrUpper.indexOf(':') >= 0 || 
//		addrUpper.indexOf('=') >= 0 || 
//		addrUpper.indexOf('%') >= 0 || 
//		addrUpper.indexOf('/') >= 0 || 
//		addrUpper.indexOf('-') >= 0 || 
//		addrUpper.indexOf('*') >= 0 || 
//		addrUpper.indexOf(';') >= 0 || 
//		addrUpper.indexOf('~') >= 0 || 
//		addrUpper.indexOf('?') >= 0 || 
//		addrUpper.indexOf('!') >= 0 || 
//		addrUpper.indexOf('&') >= 0 || 
		addrUpper.indexOf('/SCRIPT') >= 0 || 
		addrUpper.indexOf('SCRIPT') >= 0) {
		return false
	}
	else {
		return true;      
	}   
}
	
function chk_XSSRemoveField(objField) { 
//	var strUpper = objField.value.toUpperCase();
//	strUpper = strUpper.replace(/[<]/g,"");
//	strUpper = strUpper.replace(/[>]/g,"");
//	strUpper = strUpper.replace(/[%]/g,"");
//	strUpper = strUpper.replace(/["]/g,"");
//	strUpper = strUpper.replace("/SCRIPT","");
//	strUpper = strUpper.replace("SCRIPT","");
//	objField.value = strUpper;

	alert('An invalid character found in the text you entered!\nPlease click OK button to check your input.');
	objField.select()
	objField.focus();
	return false;

}

function chk_XSSRemoveFieldTwo(objField1,objField2) { 
//	var strUpper = objField1.value.toUpperCase();
//	strUpper = strUpper.replace(/[<]/g,"");
//	strUpper = strUpper.replace(/[>]/g,"");
//	strUpper = strUpper.replace(/[%]/g,"");
//	strUpper = strUpper.replace(/["]/g,"");
//	strUpper = strUpper.replace("/SCRIPT","");
//	strUpper = strUpper.replace("SCRIPT","");
//	objField1.value = strUpper;
//	objField2.value = strUpper;

	alert('An invalid character found in the text you entered!\nPlease click OK button to check your input.');
	objField1.select()
	objField1.focus();
	return false;

}

