<!-- // 
// example of how we would create a multidimentional javascript array using asp array values passed in from STORIS...
/*
arMyKitValues = new Array(8);
arMyKitValues[0] = new Array(<%= """" & join(arrKitID, """, """) & """" %>)
arMyKitValues[1] = new Array(<%= """" & join(arrKitDesc, """, """) & """" %>)
arMyKitValues[2] = new Array(<%= """" & join(arrSellPrice, """, """) & """" %>)
arMyKitValues[3] = new Array(<%= """" & join(arrKitPrice, """, """) & """" %>)
arMyKitValues[4] = new Array(<%= """" & join(arrKitQty, """, """) & """" %>)
arMyKitValues[5] = new Array(<%= """" & join(arRollupKitID, """, """) & """" %>)
arMyKitValues[6] = new Array(<%= """" & join(arRollupKitQty, """, """) & """" %>)
arMyKitValues[7] = new Array(<%= """" & join(arReplacementProductID, """, """) & """" %>)
arMyKitValues[8] = new Array(<%= """" & join(arAddon, """, """) & """" %>)
*/

// format currencey without dollar sign or comas. Not currently used but was left in if needed in the future..
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);
}

// sends back a array containing items. All items have their id attribute set to the value of the RollupKitID
// which indicates to us it is a nested kit. If no RollupKitID is found the KitId (prodNo) is used for the hidden 
// fields id attribute. In either case the id attribute exsist on all hidden fields that relate to kitItems...
function getItemList(myForm){
	var arKitId = new Array;
	var arKitDesc = new Array;
	var arSellPrice = new Array;
	var arKitPrice = new Array;
	var arKitQty = new Array;
	var arRollupKitID = new Array;
	var arRollupKitQty = new Array;
	var arReplacementProductID = new Array;
	var arAddon = new Array;
	var arUniqueId = new Array;
	var myTempID = "";
	var myTempIDs = new Array;
	
	// retrieve all ids that makeup the unmodified kit...
	for (var i = 0;i<myForm.length;i++){
		if ((myForm.elements[i].name.toLowerCase()=="addon")&&(myForm.elements[i].value=="0")){
			if (myTempID != myForm.elements[i].id){
				myTempIDs.push(myForm.elements[i].id);
				myTempID = myForm.elements[i].id;
			}
		}
	}
	
	// loop through unmodified kit ids and store their associated items in a new array...
	for (var i = 0;i<myTempIDs.length;i++){
		for (var k = 0;k<myForm.length;k++){
			if (myTempIDs[i] == myForm.elements[k].id){
				switch(myForm.elements[k].name.toLowerCase()){
					case "kitid":
					  arKitId.push(myForm.elements[k].value + "");
					  break;    
					case "kitdesc":
					  	arKitDesc.push(myForm.elements[k].value + "");
					  	break;
					case "sellprice":
					  arSellPrice.push(myForm.elements[k].value + "");
					  break;
					case "kitprice":
					  arKitPrice.push(myForm.elements[k].value + "");
					  break;
					case "kitqty":
					  arKitQty.push(myForm.elements[k].value + "");
					  break;
					case "rollupkitid":
					  arRollupKitID.push(myForm.elements[k].value + "");
					  break;
					case "rollupkitqty":
					  arRollupKitQty.push(myForm.elements[k].value + "");
					  break;
					case "replacementproductid":
					  arReplacementProductID.push(myForm.elements[k].value + "");
					  break;
					case "addon":
					  arAddon.push(myForm.elements[k].value + "");
					  break;
					case "uniqueid":
					  arUniqueId.push(myForm.elements[k].value + "");
					  break;  
					default:				  
				}
			}
		}
	}
	
	var arMyKitItemValues = new Array(9);
	arMyKitItemValues[0] = arKitId;
	arMyKitItemValues[1] = arKitDesc;
	arMyKitItemValues[2] = arSellPrice;
	arMyKitItemValues[3] = arKitPrice;
	arMyKitItemValues[4] = arKitQty;
	arMyKitItemValues[5] = arRollupKitID;
	arMyKitItemValues[6] = arRollupKitQty;
	arMyKitItemValues[7] = arReplacementProductID;
	arMyKitItemValues[8] = arAddon;
	arMyKitItemValues[9] = arUniqueId;
	return arMyKitItemValues	
}

// sends back a array containing addon and replacement items the user has selected.
function getItemUpdateList(myForm){
	var arKitId = new Array
	var arKitDesc = new Array
	var arSellPrice = new Array
	var arKitPrice = new Array
	var arKitQty = new Array
	var arRollupKitID = new Array
	var arRollupKitQty = new Array
	var arReplacementProductID = new Array
	var arAddon = new Array
	var arUniqueId = new Array;
	for (var i = 0;i<myForm.length;i++){
		if ((myForm.elements[i].name.toLowerCase()=="updateitems")&&(myForm.elements[i].checked)||
		(myForm.elements[i].name.toLowerCase()=="replaceitems")&&(myForm.elements[i].checked)){
			for (var j = 0;j<myForm.length;j++){
				if (myForm.elements[j].id == myForm.elements[i].id){
					switch(myForm.elements[j].name.toLowerCase()){
						case "kitid":
						  arKitId.push(myForm.elements[j].value);
						  break;    
						case "kitdesc":
						  arKitDesc.push(myForm.elements[j].value);
						  break;
						case "sellprice":
						  arSellPrice.push(myForm.elements[j].value);
						  break;
						case "kitprice":
						  arKitPrice.push(myForm.elements[j].value);
						  break;
						case "kitqty":
						  arKitQty.push(myForm.elements[j].value);
						  break;
						case "rollupkitid":
						  arRollupKitID.push(myForm.elements[j].value);
						  break;
						case "rollupkitqty":
						  arRollupKitQty.push(myForm.elements[j].value);
						  break;
						case "replacementproductid":
						  arReplacementProductID.push(myForm.elements[j].value);
						  break;
						case "addon":
						  arAddon.push(myForm.elements[j].value)
						  break;
						case "uniqueid":
						  arUniqueId.push(myForm.elements[j].value + "");
						  break;  
						default:				  
					}
				}
			}
			if ((myForm.elements[i].name.toLowerCase()=="replaceitems")){
				uncheckOthers(myForm.elements[i])
			}
		}
	}
	
	arMyUpdateValues = new Array(9);
	arMyUpdateValues[0] = arKitId;
	arMyUpdateValues[1] = arKitDesc;
	arMyUpdateValues[2] = arSellPrice;
	arMyUpdateValues[3] = arKitPrice;
	arMyUpdateValues[4] = arKitQty;
	arMyUpdateValues[5] = arRollupKitID;
	arMyUpdateValues[6] = arRollupKitQty;
	arMyUpdateValues[7] = arReplacementProductID;
	arMyUpdateValues[8] = arAddon;
	arMyUpdateValues[9] = arUniqueId;	
	return arMyUpdateValues
}

function replaceNullWithZero(myValue){
	if(myValue == ""){
		myValue = "0";
	}
	return myValue;
}

function refreshProductInfo(element){
	var target = element; 
	var KitID, KitDesc, SellPrice, KitPrice, KitQty, RollupKitID, KitIDToUse;
	var RollupKitQty, ReplacementProductID, Addon, UniqueId, myForm, myNewProductPrice;
	var NewId, OldId
	// check if we have the form or one of it's child elements and set the form we're working with based off that check...
	var myForm = (!target.form) ? target : target.form;
	var arMyUpdateValues, arMyItemValues;
	arMyItemValues = getItemList(myForm);
	arMyUpdateValues = getItemUpdateList(myForm);

	//ProdNo~ProductDesc~ProductPrice~Qty~KitID~RollupKitID~RollupKitQty~ReplacementProductID~Addon
	var myNewCartString = "";
	var myCartItem = ""
	var myNewProductPrice = parseFloat(0);
	var breakFlag = false;
	
	var myReplacementProductID;
	// sum up the none addon values if they have not been replaced...
	if (arMyItemValues[0].length > 0){
		for (i=0;i<arMyItemValues[0].length;i++){
			KitID = arMyItemValues[0][i];
			KitDesc = arMyItemValues[1][i];
			SellPrice = parseFloat(arMyItemValues[2][i]);
			KitPrice = parseFloat(arMyItemValues[3][i]);
			KitQty = arMyItemValues[4][i];
			RollupKitID = arMyItemValues[5][i];
			RollupKitQty = arMyItemValues[6][i];
			ReplacementProductID = arMyItemValues[7][i];
			Addon = parseInt(arMyItemValues[8][i]);
			UniqueId = (arMyItemValues[9][i]);
			KitIDFound = false;
			// we need to use the rollupID if it exist otherwise default to the kitID			
			KitIDToUse = KitID
			if(RollupKitID != ""){
				KitIDToUse = RollupKitID
			}
			// loop through our addon items to see if any have been selected to replace our kit.			
			for (j=0;j<arMyUpdateValues[0].length;j++){
				myReplacementProductID = arMyUpdateValues[7][j];
				if (myReplacementProductID == KitIDToUse){
					KitIDFound = true;
				}
			}
			
			// if we have found that the current item has not been replaces by an addon kit item go ahead and 
			// calculate the price for page display and add the item to the cart string.
			if (!KitIDFound){
				if (RollupKitID!=""){
					//myNewProductPrice = (myNewProductPrice + (RollupKitQty * (KitQty * KitPrice)))
					myNewProductPrice = (myNewProductPrice + (KitQty * KitPrice));
				}else{
					myNewProductPrice = (myNewProductPrice + (KitQty * KitPrice))
				}					

				// cart string property positions...
				//ProdNo~ProductDesc~ProductPrice~Qty~KitID~RollupKitID~RollupKitQty~ReplacementProductID~Addon
				// we no longer need to know the addon id but we do need a UniqueId for manipulating cart rows so swap the addon value for the UniqueId value...
				myCartItem = KitID + "~" + KitDesc + "~" + KitPrice + "~" + KitQty + "~" + replaceNullWithZero(sMainKitId) + "~" + replaceNullWithZero(RollupKitID) + "~" + replaceNullWithZero(RollupKitQty) + "~" + replaceNullWithZero(ReplacementProductID) + "~" + UniqueId
				if (myNewCartString == ""){
					myNewCartString = myCartItem;
				}else{
					myNewCartString = myNewCartString + "|" + myCartItem;
				}
			}
		}
	}
	
	// if we have addons in our addonArray we will sum up their values...
	var addonDetected = false;
	if (arMyUpdateValues[0].length > 0){
		addonDetected = true;
		for (j=0;j<arMyUpdateValues[0].length;j++){
			KitID = arMyUpdateValues[0][j];
			KitDesc = arMyUpdateValues[1][j];
			SellPrice = arMyUpdateValues[2][j];
			KitPrice = parseFloat(arMyUpdateValues[3][j]);
			KitQty = parseInt(arMyUpdateValues[4][j]);
			RollupKitID = arMyUpdateValues[5][j];
			RollupKitQty = (arMyUpdateValues[6][j]);
			ReplacementProductID = arMyUpdateValues[7][j];
			Addon = arMyUpdateValues[8][j];
			UniqueId = (arMyUpdateValues[9][j]);
			if(RollupKitID != ""){
				KitIDToUse = RollupKitID
			}else{
				KitIDToUse = KitID
			}
			
			if (RollupKitID!=""){
				//myNewProductPrice = (myNewProductPrice + (RollupKitQty * (KitQty * KitPrice)))
				myNewProductPrice = (myNewProductPrice + (KitQty * KitPrice))
			}else{
				myNewProductPrice = (myNewProductPrice + (KitQty * KitPrice))
			}
			// *********************************************************************************
			// we no longer need to know the addon id but we do need a UniqueId for manipulating cart rows so swap the addon value for the UniqueId value...
			myCartItem = KitID + "~" + KitDesc + "~" + KitPrice + "~" + KitQty + "~" + replaceNullWithZero(sMainKitId) + "~" + replaceNullWithZero(RollupKitID) + "~" + replaceNullWithZero(RollupKitQty) + "~" + replaceNullWithZero(ReplacementProductID) + "~" + UniqueId
			if (myNewCartString == ""){
				myNewCartString = myCartItem;
			}else{
				myNewCartString = myNewCartString + "|" + myCartItem;
			}	
		}
	}	
	myForm.hidSessionCart.value = myNewCartString;
	myForm.hidWishList.value = myNewCartString;
	myForm.hidNextLink.value = "sy599frm.asp"
	myForm.hidTotalKitPrice.value = myNewProductPrice
	
	var myProductPrice = document.getElementById("myProductPrice");
	myProductPrice.innerHTML = formatCurrency(myNewProductPrice);
}

function submitKit(myForm){
	refreshProductInfo(myForm);
	myForm.action = "reCalcCart.asp";
	myForm.method = "post";	
	if (myForm.hidSessionCart.value != ""){
		myForm.submit();
	}
	return false;
}

function submitKitToWishList(myForm){
	refreshProductInfo(myForm);
	myForm.action = "processReformatWishList.asp";
	myForm.method = "post";
	if (myForm.hidWishList.value != ""){
		myForm.submit();
	}
	return false;
}


// loops through our form looking for replacement check boxes that are not the selected one but have the 
// same replacementId so it can uncheck them if checked.
function uncheckOthers(element){
	var objForm = element.form
	if (element.checked){
		//writeHistory(element, element.title)
		for (var i=0;i<objForm.length;i++){
			if ((objForm.elements[i].name == "replaceitems")&&(objForm.elements[i]!=element)){
				//writeHistory(objForm.elements[i], objForm.elements[i].id)
				if(objForm.elements[i].title == element.title){
					objForm.elements[i].checked = false;
				}
			}
		}
	}
}

// -->
