//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2006
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//

//
// ***
// * This javascript function is used by the 'Add to Shopcart' button.  Since the HTML form is shared by both 'Add to Shopcart' and 'Add to Wish List' button,
// * appropriate values are set using this javascript before the form is submitted.
// * The variable 'busy' is used to avoid submitting the same forms multiple times when users click the button more than once.
// ***
//
var busy = false;
function Add2ShopCart(form, catEntryId, catEntryQuantity)
{
       if (!busy) {
              busy = true;
              form.action="OrderItemAdd";
//              form.catEntryId.value = catEntryId;
//              form.quantity.value = catEntryQuantity;
              form.URL.value='OrderCalculate?item_quantity*=&URL=OrderItemDisplay';
              form.submit();
       }
}
// This javascript function is used by the "add to shopping bag" button and submits additional product and URL info
function Add2ShopCartWithURL(form, catEntryId, catEntryQuantity, catId)
{
		var formSKU = document.OrderItemAddForm.newSKU.value;
		if(formSKU != null)
		{
			// additional continue shopping info :: start
			//alert('adding shopping cart info from productitemdisplaysetup...');
			if(catId.length < 1){
				catId = getCookie("CategoryPage");
			}
			
			var partnumber = document.createElement('input');
			partnumber.type='hidden';
			partnumber.name='partnumber';
			partnumber.value=document.OrderItemAddForm.newSKU.value;
			form.appendChild(partnumber);
			
			var continueShoppingUrl = document.createElement('input');
			continueShoppingUrl.type='hidden';
			continueShoppingUrl.name='continueShoppingUrl';
			continueShoppingUrl.value=getCookie("previousCategoryUrl");
			form.appendChild(continueShoppingUrl);
			
			var categoryId = document.createElement('input');
			categoryId.type = 'hidden';
			categoryId.name = 'cmCategoryId';
			categoryId.value = catId;
			form.appendChild(categoryId);
			//alert('partnumber: '+ formSKU + ', url: ' + getCookie("previousCategoryUrl"));
			// additional continue shopping info :: end
		}
		Add2ShopCart(form, catEntryId ,catEntryQuantity);
}


// This javascript function is used on shopping bag page for adding window shade item and submits additional product and URL info
function Add2ShopCartWindowShade(form, catEntryId, catEntryQuantity, cmCategoryId, partNumber)
{
		
			// additional continue shopping info :: start
			//alert('adding shopping cart info from productitemdisplaysetup...');
			if(cmCategoryId.length < 1){
				cmCategoryId = getCookie("CategoryPage");
			}
			
			var partnumber = document.createElement('input');
			partnumber.type='hidden';
			partnumber.name='partnumber';
			partnumber.value=partNumber;
			form.appendChild(partnumber);
			
			/*var continueShoppingUrl = document.createElement('input');
			continueShoppingUrl.type='hidden';
			continueShoppingUrl.name='continueShoppingUrl';
			continueShoppingUrl.value=getCookie("previousCategoryUrl");
			form.appendChild(continueShoppingUrl);*/
			
			var categoryId = document.createElement('input');
			categoryId.type = 'hidden';
			categoryId.name = 'cmCategoryId';
			categoryId.value = cmCategoryId;
			form.appendChild(categoryId);
			//alert('partnumber: '+ formSKU + ', url: ' + getCookie("previousCategoryUrl"));
			// additional continue shopping info :: end
		
		Add2ShopCart(form, catEntryId ,catEntryQuantity);
}


// This javascript function is used by the 'Add to Wish List' button to set appropriate values before the form is submitted
function Add2WishList(form, catEntryId)
{
       if (!busy) {
              busy = true;
              form.action="InterestItemAdd";
//              form.catEntryId.value = catEntryId;
              form.URL.value='InterestItemDisplay';
              form.submit();
       }
}
