	function toggleEdit(form)
	{
		if(form.edit.value==""){
			form.edit.value="Y";
		}else{
			form.edit.value="";
		}
		form.nurl.value = form.rurl.value;
		form.submit();
	}
	
	function linkCat(scLevel, scId){
		
		var form = this.document.forms[0];
		//alert("linkCat, called for " + form.name + ":" +scLevel+":"+scId)
		form.action = "/edealinv/servlet/SearchStoreItems";
		form.nurl.value = "control/StoreDirectory.vm";
		form.eurl.value = "control/SearchStoreItems.vm";
		
		//alert("linkCat, about to set scId "+form.scId)
		form.scId.value = scId;
		//alert("linkCat, scId set "+form.scId.value)
		form.scLevel.value = scLevel;
		
		//form.scName.value = scName;
		//if(scChildren.length==0)
		//	scChildren=-1;
		//form.scChildren.value = scChildren;	
		
		//search criteria
		form.si_sc_id.value = scId;
		form.si_title.value = "";
		form.csku_name.value = "";
		form.st_si_price.value = "";
		form.end_si_price.value = "";
		
		form.sidx.value="0";
		
		form.method = "get";
		form.submit();
	}
	
	function itemPage(siId){
		var form = this.document.forms[0];
		form.action = "/edealinv/servlet/ExecMacro";
		form.nurl.value = "control/StoreItem.vm";
		form.eurl.value = "control/StoreDirectory.vm";
		form.siId.value = siId;
		//form.cskuName.value = cskuName;
		//form.siTitle.value = siTitle;
		//form.siPrice.value = siPrice;
		//form.siQty.value = siQty;
		//form.siThmbUrl.value = siThmbUrl;
		form.method = "get";
		form.submit();
	}
	
	function orderBy(col1){
		var form = this.document.forms[0];
		
		//Test
		form.action = "/edealinv/servlet/SearchStoreItems";
		form.nurl.value = "control/StoreDirectory.vm";
		form.eurl.value = "control/SearchStoreItems.vm";
		
		if(form.orderby.value==col1){
			if(form.sortasc.value=="0"){
				form.sortasc.value="1";
			}else{
				form.sortasc.value="0";
			}
		}
		
		form.orderby.value = col1;
		form.submit();
	}
	
	// TKO: 10/11/2005
	// This function should be used on all the pages except for the home page.
	function buyItem(form, siId, qty)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/AddStoreOrderItem";
		form.nurl.value = "control/AddOrder.vm";

		form.eurl.value = "control/StoreItem.vm";
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "post";
		form.submit();
	}
	
	// TKO: 10/11/2005
	// This function should be used on all cached pages (ie. home page).
	function buyItemCached(form, siId, qty)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/AddStoreOrderItem";
		form.nurl.value = "control/AddOrder.vm";

		form.eurl.value = "control/StoreItem.vm";
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "get";
		form.submit();
	}
	
	// TKO: 08/10/2006
	// This function should be used on all the pages except for the home page, and if the item is coming
	// from a merchandising area.
	function buyItemMA(form, siId, qty, maId)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/AddStoreOrderItem";
		form.nurl.value = "control/AddOrder.vm";

		form.eurl.value = "control/StoreItem.vm";
		form.siId.value = siId;
		form.siQty.value = qty;
		form.maId.value = maId;
		form.method = "post";
		form.submit();
	}
	
	// TKO: 08/10/2006
	// This function should be used on the home page, if it is cached, and if the item is coming
	// from a merchandising area.
	function buyItemMACached(form, siId, qty, maId)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/AddStoreOrderItem";
		form.nurl.value = "control/AddOrder.vm";

		form.eurl.value = "control/StoreItem.vm";
		form.siId.value = siId;
		form.siQty.value = qty;
		form.maId.value = maId;
		form.method = "get";
		form.submit();
	}

	// This function should be used on all the pages except for the home page.
	function addItemToWishlist(form, siId, qty)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your wish list.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/ManageWishlist";
		form.wishlistAction.value = "addStoreItem";
		form.nurl.value = "control/ViewWishlist.vm";
		form.eurl.value = "control/ViewWishlist.vm";
		if (form.ourl) {
		  form.ourl.value = "control/ViewWishlist.vm";
		}
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "post";
		form.submit();
	}
	
	function addItemToGiftregistry(form, siId, qty)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your wish list.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/ManageGiftregistry";
		form.giftregistryAction.value = "addStoreItem";
		form.nurl.value = "control/ViewGiftregistry.vm";
		form.eurl.value = "control/ViewGiftregistry.vm";
		if (form.ourl) {
		  form.ourl.value = "control/ViewGiftregistry.vm";
		}
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "post";
		form.submit();
	}
	
	// This function should be used on all cached pages (ie. home page).
	function addItemToWishlistCached(form, siId, qty)
	{
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN"){
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your wish list.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/ManageWishlist";
		form.wishlistAction.value = "addStoreItem";
		form.nurl.value = "control/ViewWishlist.vm";
		form.eurl.value = "control/ViewWishlist.vm";
		if (form.ourl) {
		  form.ourl.value = "control/ViewWishlist.vm";
		}
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "get";
		form.submit();
	}
	
				function setMasterAttrValues(f, index)
	{
		for(var i=0; i<5; i++){
			eval("var attrval = f.attr_val_"+i+"_"+index);
			if(attrval){
				addUpdInput(f, "attr_val_"+i, attrval.value);
			}//if
		}//for
		addUpdInput(f, "csku_master", "Y");
	} // setMasterAttrValues
	
    		function addUpdInput(f, name, value){
		eval("var input = f."+name+";")
		if(input){
			input.value = value;
		}else{
			input = document.createElement("INPUT");   
			input.setAttribute('type', "hidden");
			input.setAttribute('name', name);
			input.setAttribute('value', value);
			f.appendChild(input);	
		}

	}
	
	// this function should be used mainly for multi-variants with text lists
	function buyMultiVarItem(theForm)
	{
		var si_array = theForm.var_id;
		var qty_array = theForm.var_qty;
		var varSize = theForm.varSize.value;

		var hasQty = false;
		var si_list = "";
		var qty_list = "";
		var delim = "";
		
		//alert("variant size: " + varSize);
		//alert("si_array: " + si_array);
		//alert("qty_array: " + qty_array);
		
		if(varSize == 0)
		{
			alert("There are no items available to add to your shopping cart.");
			return;
		}
		// loop through all the items and check the quantity for each
		else
		{
			if(si_array.length > 1)
			{
				for(var i=0; i<si_array.length; i++)
				{
					// check if there is any qty available first
					if(qty_array[i].value != "")
					{
						// validate the value.
						if(!checkInteger(qty_array[i].value))
						{
							alert(qty_array[i].value +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
							return;
						}
						
						si_list += delim + si_array[i].value;
						qty_list += delim + qty_array[i].value;
						delim = ",";									
					}
				}
			}
			else
			{
				// do the qty check first
				if(qty_array.value != "")
				{
					if(!checkInteger(qty_array.value))
					{
						alert(qty_array.value +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
						return;
					}

					si_list = si_array.value;
					qty_list = qty_array.value;
				}
			}
		}
				
		// check to see if any qty was added for any of the items
		if(si_list == "")
		{
			alert("Please add the quantity you would like to purchase for each item.");
			return;
		}
		
		// all checks are done, perpare the form.
		theForm.action = "/edealinv/servlet/AddStoreOrderItem";
		theForm.nurl.value = "control/AddOrder.vm";

		theForm.eurl.value = "control/StoreItem.vm";
		theForm.siId.value = si_list;
		theForm.siQty.value = qty_list;
		theForm.method = "post";
		theForm.submit();
	}

	// this function should be used mainly for multi-variants with drop-down
	// since it would only be handling one item
	function buySingleVarItem(theForm)
	{
		var si_sel_index=theForm.var_id.selectedIndex;
		var si_id = theForm.var_id.options[si_sel_index].value;
		var qty_id = theForm.var_qty.value;
		var varSize = theForm.varSize.value;
		
		var si_list = si_id;
		var qty_list = qty_id;
		
		//alert("variant size: " + varSize);
		//alert("si_list: " + si_list);
		//alert("qty_list: " + qty_list);
		                        
		// check to see if any qty was added for any of the items
		if(si_list == "")
		{
			alert("Please add the quantity you would like to purchase for each item.");
			return;
		}
		
		// all checks are done, perpare the form.
		theForm.action = "/edealinv/servlet/AddStoreOrderItem";
		theForm.nurl.value = "control/AddOrder.vm";
		
		theForm.eurl.value = "control/StoreItem.vm";
		theForm.siId.value = si_list;
		theForm.siQty.value = qty_list;
		theForm.method = "post";
		theForm.submit();
	}
	
	// this function is the same as buySingleVarItem but for the mini-cart         
	function buyMiniSingleVarItem(theForm)
	{
		// this is on the mini cart page, so we want to refresh back to whatever URL
		// called it
		var oldlocation = document.location.href;
		
		var si_sel_index=theForm.var_id.selectedIndex;
		var si_id = theForm.var_id.options[si_sel_index].value;
		var qty_id = theForm.var_qty.value;
		var varSize = theForm.varSize.value;
		
		var si_list = si_id;
		var qty_list = qty_id;
		
		//alert("variant size: " + varSize);
		//alert("si_list: " + si_list);
		//alert("qty_list: " + qty_list);
		                        
		// check to see if any qty was added for any of the items
		if(si_list == "")
		{
		            alert("Please add the quantity you would like to purchase for each item.");
		            return;
		}
		
		// all checks are done, perpare the form.
		theForm.action = "/edealinv/servlet/AddStoreOrderItem";
		theForm.nurl.value = "control/AddOrder.vm";
		
		theForm.eurl.value = "control/AddOrder.vm";
		theForm.returnPath.value = oldlocation;
		
		theForm.siId.value = si_list;
		theForm.siQty.value = qty_list;
		theForm.method = "post";
		theForm.submit();
	}
	
	// this is a special function for adding items into your minicart directly
					function buyItemMini(form, siId, qty, csku_master, attr_val_0)
	{           
				// this is on the mini cart page, so we want to refresh back to whatever URL
		// called it
		var oldlocation = document.location.href;
		
		//validate quantity
		var num = new Number(parseInt(qty));
		if(num.toString()=="NaN")
		{
			alert(qty +" is not a valid quantity.  Please double-check the quantity to add to your shopping cart.");
			return;
		}//if
		
		form.action = "/edealinv/servlet/AddStoreOrderItem";
		form.nurl.value = "control/AddOrder.vm";
		
		form.eurl.value = "control/AddOrder.vm";
		form.returnPath.value = oldlocation;
		//form.returnPath.value = "";
		
		form.siId.value = siId;
		form.siQty.value = qty;
		form.method = "post";
		
		//AH:  This is for master variant stuff
		if(csku_master && form.csku_master)
		{
			form.csku_master.value = csku_master;
		}
		if(attr_val_0 && form.attr_val_0)
		{
			form.attr_val_0.value = attr_val_0;
		}
		form.submit()                 
	}
	
	// helper function used to validate the quantity values that are being added to cart
	function checkInteger(val)
	{
		var num = new Number(parseInt(val));
		if(num.toString()=="NaN")
			return false;
		else
			return true;
	}