<!-- //
function addFromZipWin(){
	var flag = false;
	var	objForm = document.ConfigurableProducts;
	flag = addToCart(objForm);
	if(flag){
		objForm.submit();
	}
}
// updates the quantity value of the product string that is passed in to the function...
function getNewProductQty(sItem, rejoinItems, collectionQty){
	arrPart = sItem.split("~");
	var newQTY = "";
	var rejoinParts = "";
	for (var b = 0;b < arrPart.length;b++){
		// b3 is the quantity of the items belonging to a kit. If the user enters a quantity greater than one we need to change the quantities of the items in the kit...
		if (b == 3){
			defaultKitQTY = (parseInt(arrPart[b]));
			newQTY = (collectionQty * defaultKitQTY);
			if (rejoinParts == ""){
				rejoinParts = newQTY
			}else{
				rejoinParts = rejoinParts + "~" + newQTY
			}
		}else{
			if (rejoinParts == ""){
				rejoinParts = arrPart[b]
			}else{
				rejoinParts = rejoinParts + "~" + arrPart[b]
			}
		}
	}
	return rejoinItems + rejoinParts;
}

// determinines if a collection selection has a kit or single item product associated with it...
function recalcItem(CartItemField, NetAvailField, collectionQty, hiddenCartValue, hiddenNetAvailValue){
	var sMessage = "";
	var rejoinItems = "";  // contains parts of the product string after the quantity has been updated...
	var newNetAvail = "";
	var kitFlag = CartItemField.value.indexOf("|");	// check if product separater is present which will tell us if we are working with a kit...
	if (kitFlag >= 0){
		// we found a kit so let do some logic to update the individual product quantities based off of the kit quantity entered by the user...
		var arrItems = CartItemField.value.split("|");
		for (var i = 0;i < arrItems.length; i++){
			if (i > 0)rejoinItems = rejoinItems + "|";	// add product delimiter when more than 1 item is encountered...
			rejoinItems = getNewProductQty(arrItems[i], rejoinItems, collectionQty);
		}

		/* update the available onhand property since kits are now broken out into there individual products we need 
		to replace the subvalue mark with chr(253). We also need to check if they are coming from the condensed row display
		or single row so we can correctly grab the relative values. We do not need to loop through our netAvail string
		the way we do for our cart items because we are not recalculating item quanties the way we need to for kits.. */
		if (NetAvailField.type == "select-one"){
			newNetAvail = NetAvailField.options[CartItemField.selectedIndex].value.replace("�", "�")
		}else{
			newNetAvail = NetAvailField.value.replace("�", "�")
		}
	}else{
		// not a kit so just change the item string quantity to match what the user has entered...
		rejoinItems = getNewProductQty(CartItemField.value, rejoinItems, collectionQty);
		newNetAvail = NetAvailField.value
	}

	if (rejoinItems != ""){
		if (hiddenCartValue.value == ""){
			hiddenCartValue.value = rejoinItems;
			hiddenNetAvailValue.value = newNetAvail // for finger only
		}else{
			hiddenCartValue.value = hiddenCartValue.value + "|" + rejoinItems;
			hiddenNetAvailValue.value = newNetAvail;  // for finger only
		}
		//alert(hiddenCartValue.value)
		//return false
	}else{
		sMessage = "No product number found for this item." 
	}
	//alert(hiddenCartValue.value)
	return sMessage;
}

// creates the cart string based off of what was selected by the user then updates hidSessionCart with new string and submits the form...
function addToCart(objForm){
	objForm.hidNextLink.value = "sy599frm.asp"
	var flag = false;
	var hiddenCartValue = objForm.hidSessionCart;
	var hiddenNetAvailValue = objForm.hidNetAvail
	var sMessage = "";
	// lets loop through the elements in this form...
	for (var i = 0;i<objForm.length;i++){
		var excerpt = "";
		var foundOffset, collectionQty, objElement, excerpt, objCartItemField, objNetAvailField, kitFlag;
		objElement = objForm.elements[i];
		foundOffset = objElement.name.indexOf("ProdQty");
		// check if field is our quantity field...
		if (foundOffset >= 0){
			collectionQty = parseInt(objElement.value); // check if our quantity has a value greater than zero 
			if (collectionQty > 0){
				// the user has selected this item so figure out what related form element contains the product information...
				excerpt = objElement.name.substring(7, objElement.name.length)
				objCartItemField = objForm["CartItem" + excerpt]
				objNetAvailField = objForm["NetAvail" + excerpt]
				
				// call function to update the cart string...
				sMessage = recalcItem(objCartItemField, objNetAvailField, collectionQty, hiddenCartValue, hiddenNetAvailValue);
				flag = true;
			}else{
				if(!flag){
					sMessage = "You must have at least one item with a quantity of on before attempting to add this product to your cart.\n";
				}
			}
		}
	}
	
	// if everything went well our flag will be set to true...
	if (sMessage != ""){
		alert(sMessage)
		flag = false;
	}
	return flag;	
}

function hoverBG(obj, flag){
	if(flag=="1"){
		obj.className = "RowAlt";
	}else{
		obj.className = "RowMain";
	}
}

function drillDownLink(objElement, sellPrice, ImageID){
	var prodNo = objElement.options[objElement.selectedIndex].id
	var myProductLink = "ic281frm.asp?prodno=" + prodNo + "&backlink=ic280Collectionfrm.asp?prodno=" + sProdNo + "&SingleItemPrice=" + sellPrice + "&ImageName=" + ImageID;
	location.href = myProductLink
}


function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

// format currencey with dollar sign or comas. Used on main price display after amount has been calculated...
function formatCurrency(num) {
	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);
}


function recalcPrice(objElement){
	var objPriceContainer = document.getElementById("floatingPrice")
	var objQuantityContainer = document.getElementById("totalQuantity");
	var objForm = objElement.form
	var activeTotal = 0
	var activeQuantity = 0
	if(!objPriceContainer){
		objPriceContainer = document.createElement('DIV');
		document.body.appendChild(objPriceContainer);
	}
	
	for(var i=0;i<objForm.length;i++){
		var currentElement = objForm.elements[i]
		if(objForm.elements[i].name.indexOf("ProdQty") > -1){
			var mySuffix = objForm.elements[i].name.replace("ProdQty", "")
			var myValue = parseInt(currentElement.value)
			var myPriceElement = objForm["sellPrice" + mySuffix]
			if (myValue > 0){
				var myPrice = parseFloat(myPriceElement.value.replace("$", ""))
				if(!isNaN(myPrice) && !isNaN(myValue)){
					activeTotal = activeTotal + (myValue*myPrice)
					activeQuantity += myValue;
				}
			}
		}
	}
	objPriceContainer.innerHTML = formatCurrency(activeTotal);
	objQuantityContainer.innerHTML = activeQuantity;
}

function addProductQty(ctr)
{
	var q = document.getElementById('ProdQty'+ctr).value;
	q++;
	document.getElementById('ProdQty'+ctr).value = q;
	document.getElementById('hProdQty'+ctr).innerHTML = q;
	recalcPrice(document.getElementById('ProdQty'+ctr));
}

function subProductQty(ctr)
{
	var q = document.getElementById('ProdQty'+ctr).value;
	if (q > 0) {
		q--;
		document.getElementById('ProdQty' + ctr).value = q;
		document.getElementById('hProdQty' + ctr).innerHTML = q;
		recalcPrice(document.getElementById('ProdQty' + ctr));
	}
}


// -->
