//
//-------------------------------------------------------------------
// 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.
//-------------------------------------------------------------------
//

/**********************************************************
* 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 Add2ShopCartAjax(catEntryIdentifier, storeId, catalogId, langId)
{
			var params = [];
			params.storeId		= storeId;
			params.catalogId	= catalogId;
			params.langId			= langId;
			params.orderId		= ".";
			params.catEntryId	= catEntryIdentifier;
			params.quantity		= "1";
			if (globalShipModeId != "") {
				params.shipModeId = globalShipModeId;
			}
			if (globalAddressId != "") {
				params.addressId = globalAddressId;
			}

			var service = wc.service.declare({
				id: "AjaxAddOrderItemOnlyService",
				actionId: "AjaxAddOrderItemOnlyService",
				url: "AjaxOrderChangeServiceItemAdd",
				
				successHandler: function(serviceResponse) {
					params["orderItemId"] = serviceResponse.orderItemId;
					wc.service.invoke("AjaxAddOrderItemWithShipingInfo", params);
				},
				failureHandler: function(serviceResponse) {
					if(serviceResponse !=null && serviceResponse.errorMessage!=null) {
						alertDialog(serviceResponse.errorMessage,storeId,catalogId,langId);
					} else if (serviceResponse !=null && serviceResponse.errorMessageKey!=null) {
						alertDialog(serviceResponse.errorMessageKey,storeId,catalogId,langId);
					} else {
						alert("Error");
					}
				}
			});

			var updateShipInfoService = wc.service.declare({
				id: "AjaxAddOrderItemWithShipingInfo",
				actionId: "AjaxAddOrderItemWithShipingInfo",
				url: "AjaxOrderChangeServiceShipInfoUpdate",
				
				successHandler: function(serviceResponse) {
				},
				failureHandler: function(serviceResponse) {
					if(serviceResponse !=null && serviceResponse.errorMessage!=null) {
						alertDialog(serviceResponse.errorMessage,storeId,catalogId,langId);
					} else if (serviceResponse !=null && serviceResponse.errorMessageKey!=null) {
						alertDialog(serviceResponse.errorMessageKey,storeId,catalogId,langId);
					} else {
						alert("Error");
					}
				}
			});

			wc.service.invoke("AjaxAddOrderItemOnlyService", 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 Add2WishListAjax(catEntryIdentifier, storeId, catalogId, langId)
{

		var params = [];
		params.storeId		= storeId;
		params.catalogId	= catalogId;
		params.langId			= langId;
		params.catEntryId	= catEntryIdentifier;
		params.URL = "SuccessfulAJAXRequest";
		wc.service.invoke("AjaxInterestItemAdd", params);
		cursor_wait();
}

/**********************************************************
* Function to add a catEntry to the compare zone.
*
*	Parameters:
*	catEntryIdentifier - the identifier of the catalog entry element
**********************************************************/
function Add2CompareAjax(catEntryIdentifier, dragImagePath , url) 
{
	if(storeAccordionJS != null)
		storeAccordionJS.Add2CompareAjaxWith(catEntryIdentifier, dragImagePath , url);
}

