//-----------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (C) Copyright IBM Corp. 2008, 2009 All Rights Reserved.
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with
// IBM Corp.
//-----------------------------------------------------------------


/**
* @fileOverview This javascript handles different actions to perform after shopper selects to proceed with checkout.
* In summary, user can have different logon status and user can select different shopping option (if store locator
* feature is enabled). 
* A user can have the following logon status:
* 1. Shopper is a guest user
* 2. Shopper has a commerce account but is not yet logged on (and would like to log on before user proceeds with
*    shopping flow)
* 3. Shopper is already logged on
* In this version of javscript, store locator feature is not enabled, therefore shipping scenario is always buy online
*/

ShipmodeSelectionExtJS = {	
	langId: "-1",
	storeId: "",
	catalogId: "",		

	/**
	* Handles the case when user is already logged on
	* @param {String} billingShippingPageLink Link of the next page to invoke (billing and shipping page)
	*/
	registeredUserContinue: function(billingShippingPageLink) {
		if(CheckoutHelperJS.getFieldDirtyFlag()){
			if(document.getElementById("ShoppingCart_NonAjaxUpdate") != null){
				MessageHelper.formErrorHandleClient(document.getElementById("ShoppingCart_NonAjaxUpdate"), MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}else{
				MessageHelper.displayErrorMessage(MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}
		}
    	
		//For handling multiple clicks
		if(!submitRequest()){
			return;
		}	
    	document.location.href = 'OrderProcessServiceOrderPrepare?storeId='+this.storeId+'&catalogId='+this.catalogId+'&langId='+this.langId+'&errorViewName=AjaxOrderItemDisplayView'+'&orderId=.&URL='+billingShippingPageLink;
	},

	/**
	* 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) {
		if(CheckoutHelperJS.getFieldDirtyFlag()){
			if(document.getElementById("ShoppingCart_NonAjaxUpdate") != null){
				MessageHelper.formErrorHandleClient(document.getElementById("ShoppingCart_NonAjaxUpdate"), MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}else{
				MessageHelper.displayErrorMessage(MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}
		}
		
		//For handling multiple clicks
		if(!submitRequest()){
			return;
		}
		document.location.href = 'OrderProcessServiceOrderPrepare?storeId='+this.storeId+'&catalogId='+this.catalogId+'&langId='+this.langId+'&errorViewName=AjaxOrderItemDisplayView'+'&orderId=.&URL=OrderShippingBillingView';
	},

	/**
	* Handles the case when user is not logged on and would like to log on before completing the shopping flow
	* @param {String} logonURL URL of the logon command
	* @param {String} orderMoveURL URL of orderMove command (to merge the current order item of the guest user ID shopper to the user ID
	* of the user account
	* @param {String} billingShippingPageLink Link of the next page to invoke (billing and shipping page)
	*/
	guestShopperLogon: function(logonURL, orderMoveURL, billingShippingPageURL) {
		document.AjaxLogon.URL.value = orderMoveURL+"&URL=OrderProcessServiceOrderPrepare?URL=OrderShippingBillingView";
		document.location.href = logonURL;
	},
	 	
	/**
	* Handles the case when quick checkout option is selected (user must have already logged on and have a quick checkout
	* profile 
	* @param {String} quickOrderId Order id of this order
	*/
	updateCartWithQuickCheckoutProfile: function(quickOrderId) {
		if(CheckoutHelperJS.getFieldDirtyFlag()){
			if(document.getElementById("ShoppingCart_NonAjaxUpdate") != null){
				MessageHelper.formErrorHandleClient(document.getElementById("ShoppingCart_NonAjaxUpdate"), MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}else{
				MessageHelper.displayErrorMessage(MessageHelper.messages["ERROR_UPDATE_FIRST_SHOPPING_CART"]);
				return;
			}
		}
		CheckoutHelperJS.setCommonParameters(this.langId, this.storeId, this.catalogId);
		CheckoutHelperJS.updateCartWithQuickCheckoutProfile(quickOrderId);
	},

	/** 
	* 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;
	}
		
}	

