//
//-------------------------------------------------------------------
// 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 Wish List' button to set appropriate values before the form is submitted
function Add2WishList(form, catEntryId)
{
       if (!busy) {
              busy = true;
              form.action="TCFInterestItemAdd";
              form.catEntryId.value = catEntryId;
              form.URL.value='InterestItemDisplay';
              form.submit();
       }
}

/**********************************************************
* Function to add a catEntry to the shopping cart. Used in conjunction
* with CatalogEntryThumbnailDisplay.jspf. 
*
*	Parameters:
*	catEntryIdentifier - the identifier of the catalog entry element
* storeId - the store identifier
* catalogId - the catalog identifier
* langId - the language identifier
**********************************************************/
function Add2ShopCartAjaxWithQty(catEntryIdentifier, qty, gcAmount, storeId, catalogId, langId)
{			
			var params = [];
			params.storeId		= storeId;
			params.catalogId	= catalogId;
			params.langId			= langId;
			params.orderId		= ".";
			params.catEntryId	= catEntryIdentifier;						
			params.quantity		= qty;	
//			params.gcAmount		= gcAmount;	
			params.UOM		= gcAmount;	 //TODO: This is temporary.  Create a client library to pass this parameter in its unique paramter. Requires lot of time to do this 			
	//		params.comments		= "testsing";	
	//		params.orderItemAmount = "10.45";	

			wc.service.invoke("AjaxAddOrderItem", params);
			cursor_wait();
}

/**********************************************************
* Function to add a catEntry to the wish list. Used in conjunction
* with CatalogEntryThumbnailDisplay.jspf. 
*
*	Parameters:
*	catEntryIdentifier - the identifier of the catalog entry element
* storeId - the store identifier
* catalogId - the catalog identifier
* langId - the language identifier
**********************************************************/
function Add2WishListAjaxWithField2(catEntryIdentifier, field2, storeId, catalogId, langId)
{
		var params = [];
		params.storeId		= storeId;
		params.catalogId	= catalogId;
		params.langId			= langId;
		params.catEntryId	= catEntryIdentifier;
		params.gcAmount = field2;
		params.URL = "SuccessfulAJAXRequest";
		wc.service.invoke("AjaxInterestItemAdd", params);
		cursor_wait();
}
