function toggleAJAXDiv(ajaxUrl, ajaxDiv) {
	dojo.xhrGet( {
	    // The following URL must match that used to test the server.
	    url: ajaxUrl, 
	    handleAs: "text",
	    timeout: 5000, // Time in milliseconds
	
		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs){
			dojo.byId(ajaxDiv).innerHTML = response;
        	//return response;
		},
	
		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
	  		console.error("HTTP status code: ", ioArgs.xhr.status);
	  		//return response;
	  	}
	}); 				    
}

function toggleFormAJAXDiv(ajaxUrl, ajaxDiv, frmName) {
	var kw = {
        form: dojo.byId(frmName),
        url: ajaxUrl,
        handleAs: "text",
        
        // The LOAD function will be called on a successful response.
        load: function(response){
        	dojo.byId(ajaxDiv).innerHTML = response;
        	//return response;
        },
        
        // The ERROR function will be called in an error case.
        error: function(data){
        	console.error("HTTP status code: ", ioArgs.xhr.status);
        	//return response;
        },
        timeout: 2000
	};
	
	dojo.xhrPost(kw);  //Servlet get argement with doPost	  
}

	/**
	* This function toggles between search mode or search results display mode.
	* @param {boolean} advanced boolean used to indicate if the current search mode is advanced search.
	*/
	function toggleDiv(divId){
		var methodName = "toggleDiv";
	  
		divToToggle = dojo.byId(divId);
		if(divToToggle.style.display == "block"){
			dojo.style(divToToggle,"display","none");
		}else{
			dojo.style(divToToggle,"display","block");
		}
	}
	

//declare the namespace if it does not already exist
if (XCheckOutHelperJS == null || typeof(XCheckOutHelperJS) != "object") {
	var XCheckOutHelperJS = new Object();
}

XCheckOutHelperJS = {
	
	/** language ID to be used, default to -1 (English) */
	langId: "-1",
	
	/** store ID to be used */
	storeId: "",
	
	/** catalog ID to be used */
	catalogId: "",
	
	/** 
	* Sets common parameters used by this JavaScript object
	* @param {String} langId language ID to use
	* @param {String} storeId store ID to use
	* @param {String} catalog Catalog ID to use
	*/	
	setCommonParameters:function(langId,storeId,catalogId){
		this.langId = langId;
		this.storeId = storeId;
		this.catalogId = catalogId;
	},

	/**
	 * Updates comments field in Orders table with catalog code and sales man code using <code>OrderCopy</code> service.
	 *
	 * @param {function} the funtion to be called on success
	 * @param {String} optional parameter for function called on success
	 */
	updateCodes:function(successFunction, param1, param2){
		var params = [];
		params["storeId"] = this.storeId;
		params["catalogId"] = this.catalogId;
		params["langId"] = this.langId;
		params.toOrderId = ".";
		params["URL"] = "dummy";
		
		var orderComments = "";
		var catalogCode = dojo.byId("catalogCode");
		var salesmanCode = dojo.byId("salesmanCode");
		
		if(catalogCode && catalogCode.value != ''){
			orderComments = catalogCode.value;
		} else {
			orderComments = "null";
		}
		
		//Append delimiter
		orderComments += "|";
		
		if(salesmanCode && salesmanCode != ''){
			orderComments += salesmanCode.value;
		}  else {
			orderComments += "null";
		}
		
		params["orderComment"] = orderComments;
		
		
		wc.service.declare({
			id: "MyOrderCopy",
			actionId: "MyOrderCopy",
			url: "AjaxOrderCopy",
			successHandler: function(serviceResponse) {
				cursor_clear();
				successFunction(param1, param2);
			},
			failureHandler: function(serviceResponse) {
				cursor_clear();
			}
		});
		
		//For handling multiple clicks
		if(!submitRequest()){
			return;
		}                 
		
		// if they are available
		if (orderComments){
			cursor_wait();
			wc.service.invoke("MyOrderCopy",params);
		}else{
			successFunction(param1, param2);
		}
	},
	
	/**
	* Handles the case when user is not logged on and would like to complete shopping flow as a guest user
	* @param {String} billingShippingPageLink Link of the next page to invoke (billing and shipping page)
	*/
	guestShopperContinue: function(billingShippingPageLink) {
		this.updateCodes(ShipmodeSelectionExtJS.guestShopperContinue, billingShippingPageLink);
	},
	
	addToWishListAndDeleteFromCart:function(catEntryIdentifier,orderItemId){
		this.updateCodes(CheckoutHelperJS.addToWishListAndDeleteFromCart, catEntryIdentifier, orderItemId);
	},
	
	deleteFromCart:function(orderItemId,forWishlist){
		this.updateCodes(CheckoutHelperJS.deleteFromCart, orderItemId, forWishlist);
	}
}	