//
//-------------------------------------------------------------------
// 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.errorViewName.value = "CatalogItemAddErrorView";
              form.URL.value='SetPendingOrder?item_quantity*=&contractId*=&URL=OrderCalculate?URL=OrderItemDisplay&updatePrices=1&calculationUsageId=-1&orderId=.';
              form.submit();
       }
}

function Add2ShopCartAccessory(form, catEntryId)
{
       if (!busy) {
              busy = true;
              form.action="OrderItemAdd";
              form.catEntryId.value = catEntryId;
              form.errorViewName.value = "CatalogItemAddErrorView";
              form.URL.value='SetPendingOrder?item_quantity*=&contractId*=&URL=OrderCalculate?URL=OrderItemDisplay&updatePrices=1&calculationUsageId=-1&orderId=.';
              form.submit();
       }
}

function Add2RFQ(form) {
	if (form.Type[0].checked) {
		form.action="RFQCreateDisplay?endresult=0";
	} else 	{
		form.action="AddToExistRFQListDisplay?isContract=Y";
	}
	form.submit();		
}
function Add2ShopCartMultiple(form)
{
        
       var form2 = form;
       for(var b=0; b<form2.elements.length; b++)
  			  {
     				if(form2.elements[b].type == "checkbox")
					{
						 
						if(form2.elements[b].checked == false)
							{
								 
								form2.elements[b-1].name = "temp1"+b;
								form2.elements[b-1].value = "";
								form2.elements[b-2].name = "temp2"+b;
								form2.elements[b-2].value = "";
							}
							b = b+1;
					}
	
			}
       if (!busy) {
              busy = true;
              form2.action="OrderItemAdd";
              form2.errorViewName.value = "CatalogItemAddErrorView";
              form2.URL.value='SetPendingOrder?quantity*=&catEntryId*=&item_quantity*=&contractId*=&URL=OrderCalculate?URL=OrderItemDisplay&updatePrices=1&calculationUsageId=-1&orderId=.';
              form2.submit();
       }
}
function Add2WishListMultiple(form)
{
	var form2 = form;
       for(var b=0; b<form2.elements.length; b++)
  			  {
     				if(form2.elements[b].type == "checkbox")
					{
						 
						if(form2.elements[b].checked == false)
							{
								form2.elements[b].disabled=true; 
								form2.elements[b-1].disabled=true;								
								form2.elements[b-2].disabled=true;
							}
							b = b+1;
					}
	
			}
	if (!busy) {
		busy = true;
		form2.action="InterestItemAdd";
		//form2.URL.value='InterestItemDisplay?quantity*=&catEntryId*=&item_quantity*=&contractId*=';
		form2.URL.value='InterestItemDisplay?quantity*=&catEntryId*=&item_quantity*=&contractId*=';
		form2.submit();
	}
}
function Add2RFQMultiple(form) {
	if (form.Type[0].checked) {
		form.action="RFQCreateDisplay?endresult=0";
	} else 	{
		form.action="AddToExistRFQListDisplay?isContract=Y";
	}
	form.submit();		
}

function Add2WishListAccessory(form, catEntryId)
{
	if (!busy) {
		busy = true;
		form.action="InterestItemAdd";
		form.catEntryId.value = catEntryId;
		//form2.URL.value='InterestItemDisplay?quantity*=&catEntryId*=&item_quantity*=&contractId*=';
		form.URL.value='InterestItemDisplay?quantity*=&catEntryId*=&item_quantity*=&contractId*=';
		form.submit();
	}
}
