/*
*************************************************
	cart.js
 	JavaScript functions for the cart
*************************************************

*** Note ***
Refresh or reopen browser if these scripts are updated; file is cached by browser!!
*/

var Promo_Length = 8;

function cart_CrossSubmit(strProductID){
	var strURL;
	strURL = "cart_cross_sell.asp?productid=" + strProductID;
	parent.CartCross.location.replace(strURL);
}

function cart_OnBuy(strForm){
	var strURL;
	strURL = "cart_display.asp?ProductID=" + eval("document." + strForm + ".ProductID.value");
	strURL = strURL + "&Qty=" + eval("document." + strForm + ".Qty.value");
	parent.ShopCart.location.replace(strURL);
}

function cart_OnDelete(strProductID, strStore){
	var strURL;
	strURL = "cart_display.asp?ProductID=" + strProductID + "&Action=DELETE&Store=" + strStore;
	parent.ShopCart.location.replace(strURL);
}

function cart_RefreshFrames(iStore, fStoreTotal, fTotal){
	var sErr = "";
	var sHref_Banner;
	var sHref_Total;
	
	if (eval("document.frmErr.ErrorText")) {
		sErr += "ErrorText=" + document.frmErr.ErrorText.value;
	}
	if (eval("document.frmErr.Pending")) {
		if (sErr != "") sErr += "&";
		sErr += "Pending=" + document.frmErr.Pending.value;
	}
	if (eval("document.frmErr.UIExceptions")) {
		if (sErr != "") sErr += "&";
		sErr += "UIExcept=" + document.frmErr.UIExceptions.value;
	}
	if (eval("document.frmErr.Notify")) {
		if (sErr != "") sErr += "&";
		sErr += "Notify=" + document.frmErr.Notify.value;
	}
	
	sHref_Banner = "cart_banner.asp?Store=" + iStore;
	sHref_Total = "cart_total.asp?Store=" + iStore + "&StoreTotal=" + fStoreTotal + "&Total=" + fTotal;
	
	parent.CartBanner.location.replace(sHref_Banner);
	parent.CartTotal.location.replace(sHref_Total);

	if (sErr != "") {
		parent.frames['ProductDisplay'].location.replace("cart_error.asp?" + sErr);
	}
}

function cpn_AcceptPromo(i){
	var oForm;
	var oFormPrd;
	var sConfirm = "This promotion features an item that is already in your cart.\n\nPlease make sure the adjusted quantity for\nthis item is correct before placing your order.";
	var iCount = 0;
	var intQty;
	var intPrd = 0;

	oForm = document.forms["frmPromo" + i];

	if (oForm.PrdID){
		intPrd = oForm.PrdID.value;
	}
	
	if (intPrd != 0){
		intQty = oForm.PrdQty.value;
	
		if (document.frmCOMData.txtListLen){
			iCount = document.frmCOMData.txtListLen.value;
		}

		for (var j = 0; j < iCount; j++){
			if (eval('document.forms["frmProduct' + j + '"]')){
				oFormPrd = document.forms['frmProduct' + j];
				if (oFormPrd.ProductID){
					if (oFormPrd.ProductID.value == intPrd){
						alert(sConfirm);
						if (oFormPrd.Qty.value <= intQty) oFormPrd.Qty.value = intQty;
						if (oForm.PrdQty.value <= oFormPrd.Qty.value) oForm.PrdQty.value = oFormPrd.Qty.value;
					}
				}
			}
		}
	}

	// Set the accept value to process in ApplyAll
	oForm.accept.value = 1;

	// Use apply all so any other edits do not get lost
	cpn_ApplyAll(i);
				
	return false;
}

function cpn_ApplyAll(iItem){
	var oForm;
	var sArrayCpn = "";
	var sArrayPrd = "";
	var sArrayPrm = "";
	var sArrayPck = "";
	var iCount = 0;
	var iPickCount = 0;
	var iArCountCpn = 0;
	var iArCountPrd = 0;
	var iArCountPrm = 0;
	var iArCountPck = 0;
	var sDest = "";
	var sJump = "";

	var re = new RegExp(/[0-9A-Za-z][0-9A-Za-z]RAF[0-9A-Za-z]*/);
	var re3 = /\bWS[0-9A-Za-z]*/i;
	var sPromo;

	if (document.frmPromoData){
		iPickCount = document.frmPromoData.txtListLen.value;
	}
	if (document.frmCOMData.txtListLen){
		iCount = document.frmCOMData.txtListLen.value;
	}
	if ((iCount == 0) && (iPickCount == 0)){
		alert("There are no coupons or promotions to be applied.");
		return false;
	} 
	if (document.frmCOMData.txtAction){
		sDest = document.frmCOMData.txtAction.value;
	}
	if (sDest == ""){
		//sDest = "checkout_coupons.asp";
		sDest = "/checkout_review.asp";
	}
	for (var i = 0; i < iPickCount; i++){
		if (eval('document.forms["frmPromo' + i + '"]')){
			oForm = document.forms['frmPromo' + i];
			if (eval('document.forms["frmPromo' + i + '"].accept')){
				if (oForm.accept.value == 1){
					// Add the promo code to the Pick array
					sArrayPck += '|' + cpn_PromoLength(oForm.PromoID.value);
					iArCountPck++;

					// Add products associated with the promotion to the Product array
					if (eval('document.forms["frmPromo' + i + '"].PrdID')){
						sArrayPrd += '|' + oForm.PrdID.value + '|' + oForm.PrdQty.value;
						iArCountPrd++;
						iArCountPrd++;
					}
				}
			}
		}
	}
	
	for (var i = 0; i < iCount; i++) {
		if (eval('document.forms["frmProduct' + i + '"]')) {
			oForm = document.forms['frmProduct' + i];
			if (eval('document.forms["frmProduct' + i + '"].PromoID')) {
				if (oForm.PromoID.value != oForm.OldPrm.value){
					if (oForm.PromoID.value != ""){
						// Only allow RAF promos in the quick add.
						sPromo = oForm.PromoID.value;
						if (re.test(sPromo.toUpperCase())){
							alert('Refer-A-Friend Promo Codes must be entered in the\nbox above labeled "Enter Promo Codes, separated by commas".');
							return;
						}
						if (re3.test(sPromo.toUpperCase()))	{
							alert('Promo Certificate Codes must be entered in the\nbox above labeled "Enter Promo Codes, separated by commas".');
							return;
						}

						sArrayPrm += "|" + cpn_PromoLength(oForm.PromoID.value);
						iArCountPrm++;
					}
				}
			}
			if (eval('document.forms["frmProduct' + i + '"].Amount')) {
				if (oForm.Amount.value != oForm.OldAmt.value){
					if ((oForm.Amount.value != "") && (validnumber(oForm.Amount.value) == "")){
						alert('An invalid value was entered for this coupon.');
						eval('document.forms["frmProduct' + i + '"].Amount.focus();')
						return;
					}
					if (oForm.Amount.value == "")
						sArrayCpn += '|' + oForm.ProductID.value + '|0';
					else
						sArrayCpn += '|' + oForm.ProductID.value + '|' + oForm.Amount.value;
					iArCountCpn++;
					iArCountCpn++;
				}
			}
			if (eval('document.forms["frmProduct' + i + '"].Qty')){
				if (oForm.Qty.value != oForm.OldQty.value){
					if ((oForm.Qty.value != "") && (validnumber(oForm.Qty.value) == "")){
						alert("An invalid value was entered for this quantity.");
						eval('document.forms["frmProduct' + i + '"].Qty.focus();')
						return;
					}
					if (oForm.Qty.value == "")
						sArrayPrd += '|' + oForm.OldPrd.value + '|0';
					else
						sArrayPrd += '|' + oForm.OldPrd.value + '|' + oForm.Qty.value;
					iArCountPrd++;
					iArCountPrd++;
				}
			}
		}
	}
		
	// Fire the "Verify" alert if customer has applied coupons, but not checked the box
	//if ((iArCountCpn != 0) && (document.accept_terms.chkVerify.checked != true)){
	//	alert("We're sorry, in order to proceed you must check the box to certify the validity of your coupons. If any of your coupons do not have valid expiration dates or are competitors' store coupons, please remove them from your order.");
	//	document.accept_terms.chkVerify.focus();
	//	return;
	//}
	
	// Build the jumplink parameter
	if (iItem > 1){
		if (eval('document.forms["frmProduct' + (iItem - 1) + '"]')){
			oForm = document.forms['frmProduct' + (iItem - 1)];
			sJump = "#" + oForm.OldPrd.value;
		}
	}

	sArrayCpn = iArCountCpn + sArrayCpn;
	sArrayPrm = iArCountPrm + sArrayPrm;
	sArrayPrd = iArCountPrd + sArrayPrd;
	sArrayPck = iArCountPck + sArrayPck;

	document.location.href = sDest + '?Action=Add&CouponArray=' + escape(sArrayCpn) + '&PromoArray=' + escape(sArrayPrm) + '&ProductArray=' + escape(sArrayPrd) + '&PickArray=' + escape(sArrayPck) + sJump;
	return;
}

function cpn_ApplyCoupon(i){
	cpn_ApplyAll(i);
}

function cpn_BuySelected(){
	var oForm;
	var sArrayPrd = "";
	var sArrayPck = "";
	var iCount = 0;
	var iPurchaseCount = 0;
	var iPurchaseReq = 0;
	var iReceiveCount = 0;
	var iReceiveReq = 0;
	var iArCountPrd = 0;
	var iArCountPck = 0;
	var sDest = '';
	
	var iQty = 0;
	var iReq = 0;
	var sProd = ""
	var sPromo;

	// Get the number of PURCHASE items
	if (document.frmPurchase){
		iPurchaseCount = document.frmPurchase.txtPurchaseLen.value;
		iPurchaseReq = document.frmPurchase.txtPurchaseReq.value;
	}else{
		return;
	}

	// Get the number of RECEIVE items
	if (document.frmReceive){
		iReceiveCount = document.frmReceive.txtReceiveLen.value;
		iReceiveReq = document.frmReceive.txtReceiveReq.value;
	}else{
		return;
	}
	
	if (document.frmReceive.Action){
		sDest = document.frmReceive.Action.value;
	}
	if (sDest == ""){
		sDest = 'PromoList.asp';
	}
	
	// Validate the PURCHASE items and build the array
	iCount = 0;
	oForm = document.forms['frmPurchase'];
	for (var i = 1; i <= iPurchaseCount; i++) {
		sProd = eval('oForm.PrdID' + i + '.value');
		iQty = eval('oForm.Qty' + i + '.value');
		iReq = eval('oForm.MinQty' + i + '.value');
		if (iQty == "") iQty = 0;
		if (iReq == "") iReq = 0;

		if ((iQty != 0) && (validnumber(iQty) == "")){
			alert('An invalid value was entered for this quantity.');
			eval('oForm.Qty' + i + '.focus();')
			return;
		}
				
		if (iQty < iReq){
			alert('You must purchase at least ' + iReq + ' of product ' + sProd + ' to be eligible for this promotion.');
			eval('oForm.Qty' + i + '.focus();')
			return;
		}
		
		// Total PURCHASE items
		iCount = iCount + new Number(iQty);

		// Add products associated with the promotion to the Product array
		sArrayPrd += '|' + sProd + '|' + iQty;
		iArCountPrd++;
		iArCountPrd++;
	}
	
	if (iCount < iPurchaseReq){
		alert('You must purchase at least ' + iPurchaseReq + ' of the required products to be eligible for this promotion.');
		return;
	}
		
	// Validate the RECEIVE items and build the array
	iCount = 0;
	oForm = document.forms['frmReceive'];
	sPromo = oForm.PromoID.value;
	for (var i = 1; i <= iReceiveCount; i++){
		sProd = eval('oForm.PrdID' + i + '.value');
		iQty = eval('oForm.Qty' + i + '.value');
		iReq = eval('oForm.MinQty' + i + '.value');
		if (iQty == "") iQty = 0;
		if (iReq == "") iReq = 0;
				
		if ((iQty != 0) && (validnumber(iQty) == "")){
			alert('An invalid value was entered for this quantity.');
			eval('oForm.Qty' + i + '.focus();')
			return;
		}
				
		if (iQty < iReq){
			alert('You must purchase at least ' + iReq + ' of product ' + sProd + ' to be eligible for this promotion.');
			eval('oForm.Qty' + i + '.focus();')
			return;
		}
		
		// Total PURCHASE items
		iCount = iCount + new Number(iQty);
		
		// Add products associated with the promotion to the Product array.
		// This will be used to process all products for the promotion.
		sArrayPrd += '|' + sProd + '|' + iQty;
		iArCountPrd++;
		iArCountPrd++;

		// Add products associated with the promotion to the PromoPick array.
		// This will be used to associate promo codes with the products.
		sArrayPck += '|' + sPromo + '|' + sProd;
		iArCountPck++;
		iArCountPck++;
	}
	
	if (iCount < iReceiveReq){
		alert('You must purchase at least ' + iReceiveReq + ' of the promotion products to be eligible for this promotion.');
		return;
	}
		
	if (iCount > iReceiveReq){
		alert('You can only purchase ' + iReceiveReq + ' of the promotion products at the discounted price.');
		return;
	}

	sArrayPrd = iArCountPrd + sArrayPrd;
	sArrayPck = iArCountPck + sArrayPck;

	document.location.href = sDest + '?promo_id=' + sPromo + '&Action=Add&ProductArray=' + escape(sArrayPrd) + '&PromoProdArray=' + escape(sArrayPck);;
	return;
}

function cpn_DelinePromo(i){
	var oForm;
	var sConfirm = 'Click OK to decline this special offer.';

	if (confirm(sConfirm)){
		// Set the accept value to process in ApplyAll
		oForm = document.forms['frmPromo' + i];
		oForm.accept.value = 0;

		// Use apply all so any other edits do not get lost
		cpn_ApplyAll(i);
	}
	return false;
}

function cpn_Delete(sType, sValue){
	var sURL;
	var sConfirm = 'Click OK to delete this coupon.';

	if (confirm(sConfirm)){
		//sURL = 'checkout_coupons.asp?Action=DELETE&' + sType + '=' + sValue;
		sURL = '/checkout_review.asp?Action=DELETE&' + sType + '=' + sValue + '&coupon=true';
		//alert(sURL);
		document.location.href = sURL;
	}
	//return false;
}

function cpn_DeleteProduct(i){
	var oForm;
	var sConfirm = 'Click OK to delete this item from your cart.';

	if (confirm(sConfirm)){
		// Set the quantity for this product to zero
		oForm = document.forms['frmProduct' + i];
		oForm.Qty.value = 0;

		// Use apply all so any other edits do not get lost
		cpn_ApplyAll(i);
	}
	return false;
}

function cpn_PromoLength(sPromo){
	if (sPromo.length > Promo_Length){
		return sPromo.substring(0, Promo_Length)
	}
	return sPromo
}

function cpn_QuickAdd(){
	var iCount;
	var oForm;
//	var re1 = new RegExp('^[0-9A-Za-z, ]+$');
//	var re2 = new RegExp(/[0-9A-Za-z][0-9A-Za-z]RAF[0-9A-Za-z]*/);
//	var re3 = new RegExp(/\bWS[0-9A-Za-z]*/);

	var re1 = /^[0-9A-Za-z, ]+$/;
	var re2 = /\b[0-9A-Za-z][0-9A-Za-z]RAF[0-9A-Za-z]*/;
	var re3 = /\bWS[0-9A-Za-z]*/i;
	var re4 = /\bDP[0-9A-Za-z]*/i;

	var sPromo;
	var sQuickAdd;
	var sURL;
	
	if (document.frmQuickAdd.txtQuickAdd){
		sQuickAdd = document.frmQuickAdd.txtQuickAdd.value;
	
		if (sQuickAdd.indexOf("GC-") == "0"){
			// this is a gift certificate
			document.location.href = "/checkout_review.asp?Action=REDEEM&gcid=" + sQuickAdd;
			
		}else if (! re1.test(sQuickAdd)){
			alert('Please enter one or more Promo Codes separated by commas.\n\nE.g., PROMO1,PROMO2,PROMO3,...');
			document.frmQuickAdd.txtQuickAdd.focus();
		
		}else{
		    
			sQuickAdd = cpn_QuickAdd_Clean(sQuickAdd);
			
			if (re4.test(sQuickAdd.toUpperCase())){
			// Delivery Pass coupons may not be manually entered
			alert('You have attempted to enter an invalid code beginning with DP.\nPlease re-enter valid codes.');
			document.frmQuickAdd.txtQuickAdd.value = '';
			document.frmQuickAdd.txtQuickAdd.focus();
			return false;
			}
			
			if (re2.test(sQuickAdd.toUpperCase())){
				if (document.frmCOMData.txtListLen){
					iCount = document.frmCOMData.txtListLen.value;
				}

				// Only one REFERAL promo can be used per order
				for (var i = 0; i < iCount; i++){
					if (eval('document.forms["frmProduct' + i + '"]')){
						oForm = document.forms['frmProduct' + i];
						if (eval('document.forms["frmProduct' + i + '"].OldPrm')){
							sPromo = oForm.OldPrm.value;
							if (re2.test(sPromo.toUpperCase())){
								alert("Only one Refer-A-Friend Promo Code can be used per order.");
								return false;
							}
						}
					}
				}
				
				// Collect the referrer's username
				cpn_ShowCouponPopup('REFER')
				return false;
			}else{
				if (re3.test(sQuickAdd.toUpperCase())){
					if (document.frmCOMData.txtListLen){
						iCount = document.frmCOMData.txtListLen.value;
					}

					// Only one CERTIFICATE promo can be used per order
					for (var i = 0; i < iCount; i++){
						if (eval('document.forms["frmProduct' + i + '"]')){
							oForm = document.forms['frmProduct' + i];
							if (eval('document.forms["frmProduct' + i + '"].OldPrm')){
								sPromo = oForm.OldPrm.value;
								if (re3.test(sPromo.toUpperCase())){
									alert('Only one gift card can be used per order.');
									return false;
								}
							}
						}
					}
					
					// Collect the certificate number
					cpn_ShowCouponPopup('GIFT')
					return false;
				}else{
					//sURL = "checkout_coupons.asp?action=ADD&PromoArray=" + escape(sQuickAdd);
					sURL = "/checkout_review.asp?action=ADD&PromoArray=" + escape(sQuickAdd);
					//alert(sURL);
					document.location.href = sURL;
				}
			}
		}
	}
	return false;
}

function cpn_QuickAddProduct(){
	var re = new RegExp('^[0-9, ]+$');
	var sQuickAdd;
	var sURL;
	
	if (document.frmQuickAdd.txtQuickAdd){
		sQuickAdd = document.frmQuickAdd.txtQuickAdd.value;

		if (! re.test(sQuickAdd)){
			alert('Please enter one or more ProductID\'s separated by a space or a comma.');
		}else{
			sQuickAdd = cpn_QuickAddProduct_Clean(sQuickAdd);

			if (parent.Checkout){
				sURL = '/checkout_review.asp?action=ADD&ProductArray=' + escape(sQuickAdd);
				document.location.href = sURL;
			}else{
				sURL = 'cart_display.asp?action=add&ProductArray=' + escape(sQuickAdd);
				parent.ShopCart.location.href = sURL;
			}
		}
	}
	return false;
}

function cpn_QuickAdd_Clean(sQuickAdd){
	// Remove spaces and comma combinations and junk entry, end up with
	// comma delimited numbers.  Goal is to handle any bizarre way of keying entries.
	// Example: ',, ,,,,  111,  222,,,333  ,  ,, 444,,, '
	// Becomes: '111,222,333,444'
	
	sQuickAdd = sQuickAdd.replace(/   /g, ' ');
	sQuickAdd = sQuickAdd.replace(/  /g, ' ');
	sQuickAdd = sQuickAdd.replace(/ /g, ' ');
	sQuickAdd = sQuickAdd.replace(/ , /g, ',');
	sQuickAdd = sQuickAdd.replace(/ ,/g, ',');
	sQuickAdd = sQuickAdd.replace(/, /g, ',');
	sQuickAdd = sQuickAdd.replace(/ /g, ',');
			
	// A few extra replaces to cleanup really bad comma entries. Change later to a do-loop with replaces.		
	sQuickAdd = sQuickAdd.replace(/,,,,/g, ',');	
	sQuickAdd = sQuickAdd.replace(/,,,/g, ',');	
	sQuickAdd = sQuickAdd.replace(/,,/g, ',');	
	sQuickAdd = sQuickAdd.replace(/,,/g, ',');
	sQuickAdd = sQuickAdd.replace(/,,/g, ',');

	// If first char is a delimiter, remove it, or the split function adds a blank element.
	if (sQuickAdd.charAt(0) == ',') {
		sQuickAdd = sQuickAdd.substring(1, sQuickAdd.length);
	}

	// If last char is a delimiter, remove it, or the split function adds a blank element.
	if (sQuickAdd.charAt(sQuickAdd.length - 1) == ',') {
		sQuickAdd = sQuickAdd.substring(0, sQuickAdd.length - 1);
	}

	// Split into array to determine count
	var arQuickAdd = sQuickAdd.split(',');
			
	// Truncate each of the entries to the maximum length
	for (var i = 0; i < arQuickAdd.length; i++){
		arQuickAdd[i] = cpn_PromoLength(arQuickAdd[i]);
	}

	// Join the array back into a string
	sQuickAdd = arQuickAdd.join(",")
	
	// Replace delimiter with pipes and quantity default
	sQuickAdd = sQuickAdd.replace(/,/g, '|');
	sQuickAdd = arQuickAdd.length + '|' + sQuickAdd;
	
	return sQuickAdd;
}

function cpn_QuickAddProduct_Clean(sQuickAdd){
	// Remove spaces and comma combinations and junk entry, end up with
	// comma delimited numbers.  Goal is to handle any bizarre way of keying entries.
	// Example: ',, ,,,,  111,  222,,,333  ,  ,, 444,,, '
	// Becomes: '111,222,333,444'
	
	sQuickAdd = sQuickAdd.replace(/ +/g, '');
			
	// A few extra replaces to cleanup really bad comma entries. Change later to a do-loop with replaces.		
	sQuickAdd = sQuickAdd.replace(/,+/g, ',');	

	// If first char is a delimiter, remove it, or the split function adds a blank element.
	if (sQuickAdd.charAt(0) == ',') {
		sQuickAdd = sQuickAdd.substring(1, sQuickAdd.length);
	}

	// If last char is a delimiter, remove it, or the split function adds a blank element.
	if (sQuickAdd.charAt(sQuickAdd.length - 1) == ',') {
		sQuickAdd = sQuickAdd.substring(0, sQuickAdd.length - 1);
	}

	// Split into array to determine count
	var arQuickAdd = sQuickAdd.split(',');
			
	// Replace delimiter with pipes and quantity default
	sQuickAdd = sQuickAdd.replace(/,/g, '|1|');
	sQuickAdd = arQuickAdd.length*2 + '|' + sQuickAdd + '|1';
			
	return sQuickAdd;
}

function cpn_QuickAdd_Clear(){
	var oQuickAdd;
	
	if (document.frmQuickAdd.txtQuickAdd) {
		oQuickAdd = document.frmQuickAdd.txtQuickAdd;
	
		if (oQuickAdd.value == 'ENTER PROMO CODE(S) OR GIFT CERTIFICATES HERE AND CLICK APPLY BUTTON' || oQuickAdd.value == 'Enter Promo Code(s) or Gift Certificates here and click APPLY button') {
			oQuickAdd.value = '';
		}
	}
	return false;
}

function cpn_ShowCouponPopup(strAction){
	var	sURL;
	var wCoupon;

	sURL = "checkout_coupon_popup.asp?action=" + strAction
	wCoupon = window.open(sURL, "couponpolicy", "height=300,width=500");
	wCoupon.focus();
}

function cpn_ShowHelp(){
	var	sURL;
	var wHelp;
	
	sURL = "checkout_help.html#chtop";
	
	wHelp = window.open(sURL, "helpwindow", "height=350,width=600,resizable,scrollbars");
	wHelp.focus();
}

function psl_Delete(sProductID){
	var sURL;
	var sConfirm = "Click OK to delete this item from your cart.";

	if (confirm(sConfirm)){		
		if (parent.ShopCart) {
			sURL = 'cart_display.asp?Action=DELETE&ProductID=' + sProductID;
			parent.ShopCart.location.href = sURL;
		} else {
			sURL = '/checkout_review.asp?Action=DELETE&ProductID=' + sProductID;
			document.location.href = sURL;
		}
	}
	return false;
}

function psl_DeleteChecked() {
	var oForm;
	var sArray = '';
	var sConfirm;
	var iCount = 0;
	var iCountChecked = 0;

	if (document.frmCOMData.txtListLen) {
		iCount = document.frmCOMData.txtListLen.value;
	}

	for (var i = 0; i < iCount; i++) {
		if (eval('document.forms["frmProduct' + i + '"]')) {
			oForm = document.forms["frmProduct"+i];
		
			if (oForm.chkSelect.checked) {
				iCountChecked++;
				sArray += "||" + oForm.ProductID.value;
			}
		}
	}
	
	if (iCountChecked == 0) {
		alert("No items are selected.");
	} else {
		sArray = iCountChecked + sArray;

		if (iCountChecked == 1) {
			sConfirm = 'Click OK to delete the selected item from your cart.';
		} else {
			sConfirm = 'Click OK to delete the ' + iCountChecked + ' selected items from your cart.';
		}
		
		if (confirm(sConfirm)) {
			parent.ShopCart.location.href = 'cart_display.asp?Action=DELETE&ProductArray=' + escape(sArray);
		}
	}
	return false;	
}

function psl_QuickAdd() {
	var re = new RegExp('^[0-9, ]+$');
	var sQuickAdd;
	var sURL;
	
	if (document.frmQuickAdd.txtQuickAdd) {
		sQuickAdd = document.frmQuickAdd.txtQuickAdd.value;

		if (! re.test(sQuickAdd)) {
			alert('Please enter one or more ProductID\'s separated by a space or a comma.');
		} else {
			sQuickAdd = psl_QuickAdd_Clean(sQuickAdd);

			if (parent.Checkout){
				sURL = '/checkout_review.asp?action=ADD&ProductArray=' + escape(sQuickAdd);
				document.location.href = sURL;
			}else{
				sURL = '/cart_display.asp?action=add&ProductArray=' + escape(sQuickAdd);
				parent.ShopCart.location.href = sURL;
			}
		}
	}
	return false;
}

function psl_UpdateQuantity() {
	var oForm;
	var sArray = "";
	var sURL;
	var iCount = 0;
	var iQty_Curr;
	var iQty_Orig;
	var iUpdateCount = 0;

	if (document.frmCOMData.txtListLen) {
		iCount = document.frmCOMData.txtListLen.value;
	}

	for (var i = 0; i < iCount; i++) {
		if (eval('document.forms["frmProduct' + i + '"]')) {
			oForm = document.forms['frmProduct' + i];
		
			iQty_Curr = oForm.Qty.value;
			iQty_Orig = oForm.Qty.defaultValue;
			
			if (iQty_Curr != iQty_Orig) {
				iUpdateCount++;
				sArray += '||' + oForm.ProductID.value + '|' + iQty_Curr;
			}
		}
	}
		
	if (iUpdateCount != 0) {
		sArray = iUpdateCount + sArray;
		sURL = 'cart_display.asp?action=add&ProductArray=' + escape(sArray);

		parent.ShopCart.location.href = sURL;
	} else {
		alert("No quantities have been updated.");
	}
	return false;
}

function validnumber(strNumber){
	var intTemp;
	
	strNumber = strNumber.replace(' ', '');
	strNumber = strNumber.replace('$', '');

	intTemp = new Number(strNumber);
	if (isNaN(intTemp)) return "";

	return strNumber;
}

function increaseAmt(pdtID,qty){   //used in left column cart summary
	var newURL
	newURL = "cart_display.asp?ProductID=" + pdtID + "&Qty=" + (qty + 1)
	parent.ShopCart.location.replace(newURL);
}

function decreaseAmt(pdtID,qty){  //used in left column cart summary
	if (qty == "1"){
		if (confirm("Do you want to delete\nthis item from your cart?")){
			cart_OnDelete(pdtID,qty);
		}
	}else{
		var newQty
		var newURL
		newQty = (qty - 1)
		newURL = "cart_display.asp?ProductID=" + pdtID + "&Qty=" + newQty
		parent.ShopCart.location.replace(newURL);
	}
}

function increaseQty(pdtID,qty,row){  //used in checkout
	
	var newURL
	var newQty
	var anchorRow

	newQty = (qty + 1)

	newURL = "/checkout_review.asp?Action=Add&ProductArray=2%7C" + pdtID + "%7C" + newQty; // + "#" + pdtID;
	
	document.location.href = newURL;
	
	//alert(newURL);
	//return;
	
}

function decreaseQty(pdtID,qty,row){  //used in checkout
	var newURL
	var newQty
	var anchorRow

	newQty = (qty - 1)

	if (newQty == 0){
		
		/*
		if (confirm("Click OK to delete this item from your cart.")){
			document.location.href = newURL;
		}
		*/

		//always go to top of cart
		newURL = "/checkout_review.asp?Action=Add&ProductArray=2%7C" + pdtID + "%7C" + newQty; // + "#topOfCart";
		
		document.location.href = newURL;
	}else{
		newURL = "/checkout_review.asp?Action=Add&ProductArray=2%7C" + pdtID + "%7C" + newQty; // + "#" + pdtID;
		
		document.location.href = newURL;
	}
}
