function open_window(URL) {
	window.open(URL,'win','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=460');
}

function open_window_sizeable(URL,window_name,w,h) {
	window.open(URL,window_name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h);
}

function open_window_sizeable_resizable(URL,window_name,w,h) {
	window.open(URL,window_name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width='+w+',height='+h);
}

function check_for_keyword(keywords) {
	if (keywords == ""){
		alert("Please enter a Keyword before submitting your search.");
		return false;
	}
	return true;
}

//  Validate Email Address
function validateEmail(oEmail){
	re = /.+@.+\..+/i;
	if (oEmail == ""){
		alert("Please enter an EMAIL ADDRESS before submitting your request.");
		return false;
	}
	else if (oEmail.search(re) != -1)
		return true;
	else
		alert("\"" + oEmail + "\"  is not a valid email address. Please re-enter your email address.");
	return false;
}

function deleteitem(partnumber, manufacturerid)	{
	document.delete_form.partnumber.value = partnumber;
	document.delete_form.manufacturerid.value = manufacturerid;
	document.delete_form.submit();
}

function formatCurrency(num) { 
	var sign, cents; 
	num = num.toString().replace(/\$|\,/g,''); 
	if(isNaN(num)) 
		num = "0"; 
		sign = (num == (num = Math.abs(num))); 
		num = Math.floor(num*100+0.50000000001); 
		cents = num%100; 
		num = Math.floor(num/100).toString(); 
	if(cents<10) 
		cents = "0" + cents; 
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
		num = num.substring(0,num.length-(4*i+3))+','+ 
		num.substring(num.length-(4*i+3)); 
	return (((sign)?'':'-') + '$' + num + '.' + cents); 
}

// DIV Visable/Hidden function for tabs of Product Details Page
function showStep(thisDiv,thisTab){
	if(document.layers){
           thisbrowser="NN4";
		alert("You need Netscape 6 or IE 6 to use this Quoting Tool");
       }
       if(document.all){
        //thisbrowser="ie";
		LongDes.style.display = "none";
		LongDesTab.className = "tab";
		WYSIWYG.style.display = "none";
		WYSIWYGTab.className = "tab";
		document.all[thisDiv].style.display = "inline";
		document.all[thisTab].className = "tabSelected";
       }
       if(!document.all && document.getElementById){
        //thisbrowser="NN6";
		document.getElementById("LongDes").style.display="none";
		document.getElementById("LongDes").className="tab";
		document.getElementById("WYSIWYG").style.display="none";
		document.getElementById("WYSIWYG").className="tab";
		document.getElementById(thisDiv).style.display="inline";
		document.getElementById(thisTab).className="selectedTab";
       }
}

//generic delete confirmation
function verifyDelete(){
	deleteOK=confirm("Are you sure you want to delete this item");
	return deleteOK;
}

//generic form validation based on array of fields passed in
//		fieldarray[1] = fieldlist
//		fieldarray[2] = fieldname
//		fieldarray[3] = fieldrequired
function verifyFormArray(fieldlist,fieldname,fieldrequired,formName){
	var filedlistArray = fieldlist.split(","); //convert list to an array
	var fieldnameArray = fieldname.split(","); //convert list to an array
	var fieldrequiredArray = fieldrequired.split(","); //convert list to an array
	
	
	for (var i=0, len=fieldrequiredArray.length; i<len; ++i){
		if(fieldrequiredArray[i]==1){
			if (document.forms[formName].elements[fieldnameArray[i]]){
				//check for empty required fields
				if (document.forms[formName].elements[fieldnameArray[i]].value == ""){
					alert (filedlistArray[i]+" is a REQUIRED field");
					document.forms[formName].elements[fieldnameArray[i]].focus();
					document.forms[formName].elements[fieldnameArray[i]].select();
					return false;
				}
				//Check password matches confirmation password
				if (fieldnameArray[i]=="PASSWORD"){
					if (document.forms[formName].CONFIRM_PASSWORD.value != document.forms[formName].PASSWORD.value){
						alert("The Confiramtion Password entered does not match the Password.\n\nPlease re-type your Password and Confirmation.");
						document.forms[formName].elements[fieldnameArray[i]].focus();
						document.forms[formName].elements[fieldnameArray[i]].select();
						return false;
					}
				}
				//validate email address
				//Call EMAIL validation subfunction
				if (fieldnameArray[i] == "EMAIL" || fieldnameArray[i] == "EMAIL_ADDRESS"){
					emialVar=fieldnameArray[i]
					if(!Confirm_Email(document.forms[formName].elements[fieldnameArray[i]].value)){
						alert("Please enter a valid EMAIL ADDRESS.");
						document.forms[formName].elements[fieldnameArray[i]].focus();
						document.forms[formName].elements[fieldnameArray[i]].select();
						return false;
					}
				}
				//validate Terms of Use has been Checked
				if (fieldnameArray[i]=="AgreeToTerms"){
					if (!document.forms[formName].AgreeToTerms.checked){
						alert("You must review and agreee to the Terms of Use when creating an account.");
						document.forms[formName].elements[fieldnameArray[i]].focus();
						document.forms[formName].elements[fieldnameArray[i]].select();
						return false;
					}
				}
			}
		}
	}
	
	return true;
}

//Javascript validation of PASSWORD
function validation(formName){
	//Check password matches confirmation password
	if (document.forms[formName].CONFIRM_PASSWORD.value != document.forms[formName].PASSWORD.value){
		alert("The Passwords entered do not match.\n\nPlease re-type your Password and Confirmation.");
		document.forms[formName].PASSWORD.focus();
		document.forms[formName].PASSWORD.select();
		return false;
	}
	else{
		return true;
	}
}

//  Validate Email Address - (Called from other Functions on this page)
function Confirm_Email(EMAIL){
	//Check email address is not blank
	if (EMAIL==""){
		return false
	}
	
	//Invalid email Chars
	invalidChars = " /:,;"
	
	//Check email address for invalid Chars
	for (i=0; i<invalidChars.length;i++){
		badChar=invalidChars.charAt(i)
			if (EMAIL.indexOf(badChar) != -1){
				return false
			}
	}
	//Check for @ Char
	atPos=EMAIL.indexOf("@",1)
	if (atPos == -1){
		return false
	}
	if (EMAIL.indexOf("@",atPos+1) != -1){
		return false
	}
	//Check for dot(.) Char
	dotPos=EMAIL.indexOf(".",atPos)
	if (dotPos <= 0){
		return false
	}
	if (dotPos+3 > EMAIL.lenght){
		return false
	}
	return true
}

//SHOPPINGCART Quantity update
quantityChanged = false;
function checkForQC(){
	if (typeof(quantityChanged) == "object"){
		quantityChanged.checkoutbutton.value = 1;
		quantityChanged.submit();
		return false;
	}
	else  return true;
}


//SHIPPING CALCULATOR FUNCTION
function setShippingServices(shippingServices){
	var filedlistArray = shippingServices.split(","); //convert list to an array
	oField = document.shippingForm.shipping_type;
	oField.options.length = filedlistArray.length - 1;
	for (i=1; i < filedlistArray.length; ++i){
		oField.options[i-1].text = filedlistArray[i];
		oField.options[i-1].value = filedlistArray[i];
	}
}

//SHOPPINGCART -- LETTERING div control
function ShowHideDiv(theID,ShowHide){
	if (ShowHide == 1) visVar = 'visible';
	else visVar = 'hidden';
	document.getElementById(theID).style.visibility=visVar;
}

//SHOPPINGCART -- LETTERING update control
function UpdateLettering(theLetteringID,theListID,theQTY,theProductid){
	if(isNaN(document.getElementById(theQTY).value) || document.getElementById(theQTY).value < 1){
		alert('Please enter a Number Value greater than or equal to 1.');
	}
	else{
		newQTY = document.getElementById(theQTY).value;
		JSListID=theListID-1;
		letteringListItems = document.getElementById(theLetteringID).value.split("|");
		
		//loop throught LETTERING ARRAY to find the emement to edit
		for (i=0; i<letteringListItems.length;i++){
			if (i == JSListID){
				letteringToEdit = letteringListItems[JSListID].split("^^");
				letteringToPreserve = letteringToEdit[0];	//we will need this latter to re-construct the innerHTML of the hyperlink
				letteringToEdit = letteringToEdit[0]+"^^"+newQTY;
				letteringToEdit.replace(",","^^");
				//alert(letteringToEdit);
			}
		}
		
		//Insert the NEW QTY data
		letteringListItems.splice(JSListID,1,letteringToEdit);
		
		//Convert the ARRAY to a string so we can replace the COMMA delimiter with a PIPE
		newLetteringString = letteringListItems.toString();
		newLetteringStringFixed = newLetteringString.replace(/,/g,"|");  //do a global replace of the COMMA with a PIPE
		
		//RETURN THE LETTERING STRING BACK TO THE SHOPPINGCART
		document.getElementById(theLetteringID).value = newLetteringStringFixed;
		
		//Tally the new TOTAL QTY for the PRODUCT
		var newTotalQTY = 0;
		for (i=0; i<letteringListItems.length;i++){
			letteringToEdit = letteringListItems[i].split("^^");
			newTotalQTY = (Number(letteringToEdit[1]) + newTotalQTY);
		}
		//Update Quantity Field
		var theQTYtoEdit = 'quantity_' + theProductid;
		document.getElementById(theQTYtoEdit).focus();
		document.getElementById(theQTYtoEdit).value = newTotalQTY;
		
		//update the inner HTML of the text string (qty)
		var theStringtoEdit = theProductid + '_edit_string_' + theListID; //for string for ID = #productid#_edit_string_#i#
		var newStringValue = letteringToPreserve + ' qty: ' + newQTY;
		document.getElementById(theStringtoEdit).innerHTML = newStringValue;
		
		//close (hide) the div
		var divToHide = theProductid+ '_lettering_'+ theListID;
		ShowHideDiv(divToHide,0);
	}
}

//UPS Address Verification
function useSuggestedAddress(fullAddress){
	addressParts = fullAddress.split(",");
	checkout.st_city.value = addressParts[0];
	checkout.st_state.value = addressParts[1];
	checkout.st_zip.value = addressParts[2];
   	checkout.submit();
}

//Shipping Method page takes a while to load, so upon form submit, lockout submit button and Change it's image to "Working...".
function setInProgress(selectedButton){
	checkout.submit();
	selectedButton.disabled = true;
	selectedButton.src = "images_emart/buttons/baby_blue/please_wait_animated.gif";
	return true;
}

//CHECKOUT3.cfm - TERM PAYMENT SELECTED (Pay by CHECK or PO)
function termPayment(value){
	if (value == "CHECK"){
		verify = confirm('If you are paying by CHECK, your order will not ship until we receive a check for the amount shown in the Grand Total field above.');
		if (verify==true){
			document.getElementById('po_number').value='CHECK';
			document.getElementById('cc_number').disabled=true;
			document.getElementById('cc_number').style.border='solid 1px #d3d3d3';
			document.getElementById('cc_cvv2').disabled=true;
			document.getElementById('cc_cvv2').style.border='solid 1px #d3d3d3';
			document.getElementById('cc_expiration_month').disabled=true;
			document.getElementById('cc_expiration_month').style.border='solid 1px #d3d3d3';
			document.getElementById('cc_expiration_year').disabled=true;
			document.getElementById('cc_expiration_year').style.border='solid 1px #d3d3d3';
			document.getElementById('cc_name').disabled=true;
			document.getElementById('cc_name').style.border='solid 1px #d3d3d3';
			return true;
		}

		else {
			document.getElementById('po_number').value='';
			document.getElementById('cc_type').selectedIndex=0;
			document.getElementById('cc_number').disabled=false;
			document.getElementById('cc_number').style.border='solid 1px #000000';
			document.getElementById('cc_cvv2').disabled=false;
			document.getElementById('cc_cvv2').style.border='solid 1px #000000';
			document.getElementById('cc_expiration_month').disabled=false;
			document.getElementById('cc_expiration_month').style.border='solid 1px #000000';
			document.getElementById('cc_expiration_year').disabled=false;
			document.getElementById('cc_expiration_year').style.border='solid 1px #000000';
			document.getElementById('cc_name').disabled=false;
			document.getElementById('cc_name').style.border='solid 1px #000000';
		return false;
		}
	}
	else {
		document.getElementById('po_number').value='';
		document.getElementById('cc_number').disabled=false;
		document.getElementById('cc_number').style.border='solid 1px #000000';
		document.getElementById('cc_cvv2').disabled=false;
		document.getElementById('cc_cvv2').style.border='solid 1px #000000';
		document.getElementById('cc_expiration_month').disabled=false;
		document.getElementById('cc_expiration_month').style.border='solid 1px #000000';
		document.getElementById('cc_expiration_year').disabled=false;
		document.getElementById('cc_expiration_year').style.border='solid 1px #000000';
		document.getElementById('cc_name').disabled=false;
		document.getElementById('cc_name').style.border='solid 1px #000000';
	return false;
	}
}


//CHECKOUT1.cfm Copies MasterFields value's to CopiedFields if "ShipToBillToSame" box is checked
function ShipToBillToSame(checkedValue,CopiedFields,MasterFields){
	CopiedFieldsNames = CopiedFields.split(",");
	MasterFieldsNames = MasterFields.split(",");
	for (i=0; i < CopiedFieldsNames.length; ++i){
		if (CopiedFieldsNames[i] != " "){
			if (checkedValue) checkout.elements[CopiedFieldsNames[i]].value = checkout.elements[MasterFieldsNames[i]].value; //checkedValue; disabled
			else checkout.elements[CopiedFieldsNames[i]].value = "";
		}
	}
}

//CHECKOUT1.cfm Hide Gift Message Unless IS GIFT is CHECKED
function hideGiftMessage(checkedValue,fieldName){
	if (checkedValue==true) theStyle="block";
	else theStyle="none";
	document.getElementById(fieldName).style.display = theStyle;
}

//CHECKOUT1.cfm Show/Hide Promo error details
function showHideDiv(fieldName,showHide){
	if (showHide==true) theStyle="block";
	else theStyle="none";
	document.getElementById(fieldName).style.display = theStyle;
}

//Get and Set the Price of an option and update the Price Field in the form
function product_selection(thePrice,optionHTML) {
	//get Retail Price of Option
	tempPrice=thePrice.split("_");
	truePrice=tempPrice[1];
	priceDiv.innerHTML=truePrice;
	/* NOT USED by HFTG
		//get List Price of Option
		tempListPrice=thePrice.split("_");
		trueListPrice=tempPrice[2];
		listpriceDiv.innerHTML=trueListPrice;
	 */
	// get productid of selected item
	tempPart=thePrice.split("_");
	truePart=tempPrice[0];
	document.getElementById('productid').value=truePart;
	
	// handle innerHTML of Product Options (Exclusivly for HFTG)
	optVal = optionHTML.toLowerCase();
	if (optVal.indexOf("monogram",1) != -1){
		document.getElementById('LETTERING').disabled=false;
		document.getElementById('letteringDiv').style.display='block';
	}
	else{
		document.getElementById('LETTERING').value='';
		document.getElementById('LETTERING').disabled=true;
		document.getElementById('letteringDiv').style.display='none';
	}
}

//Get and Set the Lettering Image for Monogram
function letter_selection(letter,letter_color) {
	thePath = 'images/' + letter_color + '/' + letter + '.gif';
	document.getElementById('lettering_image').src = thePath;
}

