function open_window(URL) {
	window.open(URL,'win','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=520,height=600');
}

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 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;
					}
				}
			}
		}
	}
	
	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];
	}
}

//UPS Address Verification
function useSuggestedAddress(fullAddress){
	addressParts = fullAddress.split(",");
	if (document.checkout.billto_same.checked) {
		checkout.bt_city.value = addressParts[0];
		checkout.bt_state.value = addressParts[1];
		checkout.bt_zip.value = addressParts[2];
		}
	else {
		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(formName, selectedButton){
	selectedButton.disabled = true;
	//selectedButton.src = "images_emart/buttons/newsmax/please_wait_animated.gif";
	var d = eval('document.' + formName)
	d.submit();
	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("checkout_form").po_number.value = 'check';
			document.getElementById("checkout_form").cc_number.disabled = true;
			document.getElementById("checkout_form").cc_number.style.border='solid 1px #d3d3d3';
			//document.getElementById("checkout_form").cc_cvv2.disabled = true;
			//document.getElementById("checkout_form").cc_cvv2.style.border='solid 1px #d3d3d3';
			document.getElementById("checkout_form").cc_expiration_month.disabled = true;
			document.getElementById("checkout_form").cc_expiration_month.style.border='solid 1px #d3d3d3';
			document.getElementById("checkout_form").cc_expiration_year.disabled = true;
			document.getElementById("checkout_form").cc_expiration_year.style.border='solid 1px #d3d3d3';
			document.getElementById("checkout_form").cc_name.disabled = true;
			document.getElementById("checkout_form").cc_name.style.border='solid 1px #d3d3d3';
			return true;
		}
		else {
			document.getElementById("checkout_form").po_number.value = '';
			document.getElementById("checkout_form").cc_type.selectedIndex = 0;
			document.getElementById("checkout_form").cc_number.disabled = false;
			document.getElementById("checkout_form").cc_number.style.border='solid 1px #000000';
			//document.getElementById("checkout_form").cc_cvv2.disabled = false;
			//document.getElementById("checkout_form").cc_cvv2.style.border='solid 1px #000000';
			document.getElementById("checkout_form").cc_expiration_month.disabled = false;
			document.getElementById("checkout_form").cc_expiration_month.style.border='solid 1px #000000';
			document.getElementById("checkout_form").cc_expiration_year.disabled = false;
			document.getElementById("checkout_form").cc_expiration_year.style.border='solid 1px #000000';
			document.getElementById("checkout_form").cc_name.disabled = false;
			document.getElementById("checkout_form").cc_name.style.border='solid 1px #000000';
			return false;
		}
	}
	else {
		document.getElementById("checkout_form").po_number.value = '';
		document.getElementById("checkout_form").cc_number.disabled = false;
		document.getElementById("checkout_form").cc_number.style.border='solid 1px #000000';
		//document.getElementById("checkout_form").cc_cvv2.disabled = false;
		//document.getElementById("checkout_form").cc_cvv2.style.border='solid 1px #000000';
		document.getElementById("checkout_form").cc_expiration_month.disabled = false;
		document.getElementById("checkout_form").cc_expiration_month.style.border='solid 1px #000000';
		document.getElementById("checkout_form").cc_expiration_year.disabled = false;
		document.getElementById("checkout_form").cc_expiration_year.style.border='solid 1px #000000';
		document.getElementById("checkout_form").cc_name.disabled = false;
		document.getElementById("checkout_form").cc_name.style.border='solid 1px #000000';
		return false;
	}
}


//CHECKOUT1.cfm Disable Bill To Fields if "same as ship to"
function disableBillingFields(checkedValue,fieldNameList){
	fieldNameBT = fieldNameList.split(",");
	for (i=0; i < fieldNameBT.length; ++i){
		if (fieldNameBT[i] != " ")  checkout.elements[fieldNameBT[i]].disabled = checkedValue;
	}
}

//CHECKOUT1.cfm Disable Ship To Fields if "same as bill to"
function disableShippingFields(checkedValue,fieldNameList){
	fieldNameST = fieldNameList.split(",");
	for (i=0; i < fieldNameST.length; ++i){
		if (fieldNameST[i] != " ")  checkout.elements[fieldNameST[i]].disabled = checkedValue;
	}
}

//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 Blank out promo_code field and submit form to skip discounts
function skipDiscounts(){
	document.checkout.promo_code.value="";
	document.checkout.submit();
}

//Get and Set the Price of an option and update the Price Field in the form
function product_selection(thePrice) {
	//get Retail Price of Option
	tempPrice=thePrice.split("_");
	truePrice=tempPrice[1];
	if(document.getElementById("priceDiv2")){
		//priceDiv2.innerHTML=truePrice;
		//change selected index		
		document.getElementById("selectBottom").selectedIndex = document.getElementById("selectTop").selectedIndex;
		//product_selection2(thePrice);
	//	alert(thePrice);
	//	alert(document.getElementById('productid').value);
		
	}
	priceDiv.innerHTML=truePrice;
	//get List Price of Option
	tempListPrice=thePrice.split("_");
	trueListPrice=tempPrice[2];
	listpriceDiv.innerHTML= "List Price: " + trueListPrice;
	if(document.getElementById("listpriceDiv2")){
		//listpriceDiv2.innerHTML= "List Price: " + trueListPrice;
	}	
	// get productid of selected item
	tempPart=thePrice.split("_");
	truePart=tempPrice[0];
	document.getElementById('productid').value=truePart;
}
//Get and Set the Price of an option and update the Price Field in the form
function product_selection2(thePrice) {
	//get Retail Price of Option
	tempPrice=thePrice.split("_");
	truePrice=tempPrice[1];
	if(document.getElementById("priceDiv2")){
		priceDiv2.innerHTML=truePrice;
		//change selected index
		document.getElementById("selectTop").selectedIndex = document.getElementById("selectBottom").selectedIndex;
		//product_selection(thePrice);		
	}
	//priceDiv.innerHTML=truePrice;
	//get List Price of Option
	tempListPrice=thePrice.split("_");
	trueListPrice=tempPrice[2];
	//listpriceDiv.innerHTML= "List Price: " + trueListPrice;
	if(document.getElementById("listpriceDiv2")){
		listpriceDiv2.innerHTML= "List Price: " + trueListPrice;
	}	
	// get productid of selected item
	tempPart=thePrice.split("_");
	truePart=tempPrice[0];
	document.getElementById('productidBottom').value=truePart;
}