/*****************************************************************
 * 
 * This script provides the necessary JS helper object for 
 * checkout
 * 
 *****************************************************************/


/* 
 * Checkout helper object
 * 
 * @return 
 */
function CheckoutHelper() {

	//*** event listener - START ***/
	
	// listen to click event of the shipping address checkboxes.
	var _shippAddrEventListener = {
	
		checkoutHelperObj: function() {
		
			return new CheckoutHelper();
		},
		
		initialize: function() {
		
			var dwAddressGroup = this.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
			var dwDifferentShippAddrBoxEl		= dwAddressGroup[0];
			var dwFreightStationShippAddrBoxEl	= dwAddressGroup[1];
			if ((dwDifferentShippAddrBoxEl != null) && (dwFreightStationShippAddrBoxEl != null)) {
			
				dwDifferentShippAddrBoxEl.shippAddrBindObj = this;
				dwDifferentShippAddrBoxEl.onclick = this.clickHandler;
				
				if(dwDifferentShippAddrBoxEl.checked) {
					this.selectPaymentMethod(dwDifferentShippAddrBoxEl);
				}				

				dwFreightStationShippAddrBoxEl.shippAddrBindObj = this;

				var freightStnMethodJSONE1 = $('freightStnMethodJSON');
				if(eval('(' + freightStnMethodJSONE1.value + ')').freightStnMethods.length > 0){
					
					dwFreightStationShippAddrBoxEl.onclick = this.clickHandler;

					if(dwFreightStationShippAddrBoxEl.checked) {
						this.selectPaymentMethod(dwFreightStationShippAddrBoxEl);
						
						// first activate or deactivate shipping methods depending on payment method 
						var shippingOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('paymentOptions');	
						if(shippingOptionsGroup != null){
							for (var i = 0; i < shippingOptionsGroup.length; i++) {	
								if(shippingOptionsGroup[i].checked && (_paymentEventListener != null))
									_paymentEventListener.selectShippingMethod(shippingOptionsGroup[i]);
							}
						}		
						// now deactivate methods based on their freight station support
						this.selectFreightStationSupportingShippingMethod(dwFreightStationShippAddrBoxEl);
					}
				}
				else{
					dwFreightStationShippAddrBoxEl.ancestors()[0].hide();
				}
			}	
			this.initSelects();	
			this.initInputChangeHandlers();
		},
		
		initSelects: function() {
		
			if($('addressPaymentShippingAddressSelect') != null){
				var shippingAddrSelect = $($('addressPaymentShippingAddressSelect').value);
				if(shippingAddrSelect != null){
					shippingAddrSelect.onchange = this.selectHandler;
					shippingAddrSelect.shippAddrBindObj = this;
				}
			}	

			if($('addressPaymentFreightStationAddressSelect') != null){
				var freightStationAddrSelect = $($('addressPaymentFreightStationAddressSelect').value);
				if(freightStationAddrSelect != null){
					freightStationAddrSelect.onchange = this.selectHandler;
					freightStationAddrSelect.shippAddrBindObj = this;
				}
			}
		
		},		
		
		initInputChangeHandlers: function() {
			var inputFieldTable = $('dwShippingInputFields');
			var that = this;
			if(inputFieldTable){
				inputFieldTable.select('input').each(function(node){
					node.shippAddrBindObj = that;
					node.onchange = that.inputChangeHandler;
				});
			}
		},
		
		selectPaymentMethod: function(obj) {
		
			var shippingAddressPaymentMethodJSON1 = $('shippingAddressPaymentMethodJSON');
			var dwAddressGroup = this.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
			var paymentOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('paymentOptions');			
			if ((paymentOptionsGroup != null) && (dwAddressGroup != null) && (shippingAddressPaymentMethodJSON1 != null)) {
			
				var shippingAddressPaymentMethodJSON = eval('(' + shippingAddressPaymentMethodJSON1.value + ')');
				var allowedPaymentMethods;
				if(obj == dwAddressGroup[0]) 	//Different shipping address
				 	allowedPaymentMethods = shippingAddressPaymentMethodJSON.shippingAddressPaymentMethod.differentShippingAddress;
				else 								//Freightstation address
					allowedPaymentMethods = shippingAddressPaymentMethodJSON.shippingAddressPaymentMethod.freightstationAddress;
				
				if(obj.checked){
					var optionSelected = false;
					var optionEnabledCounter = 0;
					var selectNewOption = false;
					for (var i = 0; i < paymentOptionsGroup.length; i++) {
					
						paymentOptionsGroup[i].disabled = true;			

						if(allowedPaymentMethods.indexOf(paymentOptionsGroup[i].value) != -1){
							if(paymentOptionsGroup[i].checked && !optionSelected) {								
								optionSelected = true;
							}
							paymentOptionsGroup[i].disabled = false;
							optionEnabledCounter++;
						}
						
						if(paymentOptionsGroup[i].disabled == true && paymentOptionsGroup[i].checked == true){
							paymentOptionsGroup[i].checked = false;
							selectNewOption=true;
						}
					}
					
					for (var i = 0; i < paymentOptionsGroup.length; i++) {
						if(!paymentOptionsGroup[i].disabled && !optionSelected) {
							if(optionEnabledCounter==1){
								paymentOptionsGroup[i].checked = true;
							}
							obj.shippAddrBindObj.updatePaymentCtn(paymentOptionsGroup[i]);
							break;
						}
					}
					/* select first selectable item, if the selected one is disabled */
					for (var i = 0; i < paymentOptionsGroup.length; i++) {
						if(!paymentOptionsGroup[i].disabled && selectNewOption) {
							paymentOptionsGroup[i].checked = true;
							break;
						}
					}	
				}
				else{
					for (var i = 0; i < paymentOptionsGroup.length; i++) {
					
						paymentOptionsGroup[i].disabled = false;			
						
					}		
				}		
			}
		},		
		
		selectFreightStationSupportingShippingMethod: function(obj) {
		
			var freightStnMethodJSONE1 = $('freightStnMethodJSON');
			var shippingOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('shippingOptions');				
			if ((shippingOptionsGroup != null) && (freightStnMethodJSONE1 != null)) {
			
				var freightStnMethodJSON = eval('(' + freightStnMethodJSONE1.value + ')');
				var freightStnMethods = freightStnMethodJSON.freightStnMethods;			
				
				if((obj.checked)&&(obj == this.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation')[1])){
					var selectNewOption = false;
					for (var i = 0; i < shippingOptionsGroup.length; i++) {	
						if(freightStnMethods.indexOf(shippingOptionsGroup[i].value) == -1){
							if(shippingOptionsGroup[i].checked) {								
								selectNewOption = true;
							}
							shippingOptionsGroup[i].disabled = true;
						}
					}
					for (var i = 0; i < shippingOptionsGroup.length; i++) {
						if(!shippingOptionsGroup[i].disabled && selectNewOption) {
							shippingOptionsGroup[i].checked = true;
							break;
						}
					}					
				}		
			}
		},		
		
		updatePaymentCtn: function(obj) {
		
			var url = $('updatePaymentCtnUrl').value;
			new Ajax.Updater('paymentCtn', url, {
			
					method: 'post', 
					evalScripts: true, 
					parameters: obj.name + "=" + obj.value,
					onComplete: function(transport) {
						initializePopupLinkHandler();
						_redeemPointsEventListener.selectPaymentSubMethod(null);			
					}
				});
		},		
		
		updateShippingAddressCtn: function(obj) {
			
			var ajaxParameters		= '';
			
			//Handle checkbox status
			var differentShipAddr	= false;
			var freightStationAddr	= false;
			
			var dwAddressGroup = this.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
			var dwDifferentShippAddrBoxEl		= dwAddressGroup[0];
			var dwFreightStationShippAddrBoxEl	= dwAddressGroup[1];
			
			if ((dwDifferentShippAddrBoxEl != null) && (dwFreightStationShippAddrBoxEl != null)) {
			
				ajaxParameters = dwDifferentShippAddrBoxEl.name + '=false&' + 
						dwFreightStationShippAddrBoxEl.name + '=false';
				
				switch(obj.id) {
				
					case dwDifferentShippAddrBoxEl.id:
						if(dwFreightStationShippAddrBoxEl.checked) {
						
							dwFreightStationShippAddrBoxEl.checked = false;
						}
						if(obj.checked) {
						
							differentShipAddr		= true;
							ajaxParameters	= dwDifferentShippAddrBoxEl.name + '=true&' + 
									dwFreightStationShippAddrBoxEl.name + '=false';
						}
						break;
					case dwFreightStationShippAddrBoxEl.id:
						if(dwDifferentShippAddrBoxEl.checked) {
						
							dwDifferentShippAddrBoxEl.checked = false;
						}
						if(obj.checked) {
						
							freightStationAddr	= true;
							ajaxParameters		= dwDifferentShippAddrBoxEl.name + '=false&' + 
									dwFreightStationShippAddrBoxEl.name + '=true';
						}
						break;
				}
				
				//Handle select status
				if($('addressPaymentShippingAddressSelect') != null){
					var shippingAddrSelect = $($('addressPaymentShippingAddressSelect').value);
					
					if(obj.id == shippingAddrSelect.id){
						ajaxParameters	= dwDifferentShippAddrBoxEl.name + '=true&' + 
									dwFreightStationShippAddrBoxEl.name + '=false';	
					}		
								
					if((ajaxParameters != null)&&(ajaxParameters != ''))
						ajaxParameters += '&';						
					if(shippingAddrSelect.value != null)
						ajaxParameters += shippingAddrSelect.name + "=" + shippingAddrSelect.value;
				}
					
				if($('addressPaymentFreightStationAddressSelect') != null){
					var freightStationAddrSelect = $($('addressPaymentFreightStationAddressSelect').value);
										
					if(obj.id == freightStationAddrSelect.id){
						ajaxParameters	= dwDifferentShippAddrBoxEl.name + '=false&' + 
									dwFreightStationShippAddrBoxEl.name + '=true';	
					}					
					
					if((ajaxParameters != null)&&(ajaxParameters != ''))
						ajaxParameters += '&';
					if(freightStationAddrSelect.value != null)
						ajaxParameters += freightStationAddrSelect.name + "=" + freightStationAddrSelect.value;
				}
				
				var url = $('updateShippingAddressCtnUrl').value;
				new Ajax.Updater('shippingAddressCtn', url, {
				
						method: 'post', 
						evalScripts: true, 
						parameters: ajaxParameters,			
						onComplete: function(transport) {
							initializePopupLinkHandler();
							_shippAddrEventListener.initSelects();
							_shippAddrEventListener.initInputChangeHandlers();
						}
					});
			}
		},
		
		clickHandler: function() {
			this.shippAddrBindObj.updateShippingAddressCtn(this);
			this.shippAddrBindObj.selectPaymentMethod(this);
			
			// also check for applicable payment methods
			_redeemPointsEventListener.selectPaymentMethod(null);
			
			// first activate or deactivate shipping methods depending on payment method 
			var shippingOptionsGroup = this.shippAddrBindObj.checkoutHelperObj()._getDWOptionGroup('paymentOptions');	
			if(shippingOptionsGroup != null){
				for (var i = 0; i < shippingOptionsGroup.length; i++) {	
					if(shippingOptionsGroup[i].checked && (_paymentEventListener != null))
						_paymentEventListener.selectShippingMethod(shippingOptionsGroup[i]);
				}
			}		
			// now deactivate methods based on their freight station support
			this.shippAddrBindObj.selectFreightStationSupportingShippingMethod(this);
			
			return true;
		},
		
		selectHandler: function() {
			this.shippAddrBindObj.updateShippingAddressCtn(this);
			
			return true;
		},
		
		inputChangeHandler: function() {
			if($('addressPaymentShippingAddressSelect') != null){
				var shippingAddrSelect = $($('addressPaymentShippingAddressSelect').value);
				if(shippingAddrSelect != null){
					shippingAddrSelect.value = "new_address";
					if($('dwNewAddressMarker') != null){
						var newAddressField = $($('dwNewAddressMarker').value);
						if(newAddressField != null)
							newAddressField.value = "true";
					}
				}
			}	

			if($('addressPaymentFreightStationAddressSelect') != null){
				var freightStationAddrSelect = $($('addressPaymentFreightStationAddressSelect').value);
				if(freightStationAddrSelect != null){
					freightStationAddrSelect.value = "new_address";
					if($('dwNewAddressMarker') != null){
						var newAddressField = $($('dwNewAddressMarker').value);
						if(newAddressField != null)
							newAddressField.value = "true";
					}					
				}
			}
			
			return true;
		}		
			
	};
	
	// listen to click event of the payment method radio buttons.
	var _paymentEventListener = {
	
		checkoutHelperObj: function() {
		
			return new CheckoutHelper();
		},
		
		initialize: function() {
		
			var paymentOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('paymentOptions');			
			if (paymentOptionsGroup != null) {
			
				for (var i = 0; i < paymentOptionsGroup.length; i++) {
				
					paymentOptionsGroup[i].paymentBindObj = this;
					paymentOptionsGroup[i].onclick = this.clickHandler;
					
					if(paymentOptionsGroup[i].checked) {					
						// first activate or deactivate shipping methods depending on payment method 
						this.selectShippingMethod(paymentOptionsGroup[i]);
						// now deactivate methods based on their freight station support
						var dwAddressGroup = this.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
						var dwFreightStationShippAddrBoxEl	= dwAddressGroup[1];			
						if(dwFreightStationShippAddrBoxEl != null){
							_shippAddrEventListener.selectFreightStationSupportingShippingMethod(dwFreightStationShippAddrBoxEl);
						}
					}
				}
			}
		},
		
		selectShippingMethod: function(obj) {
			
			var reqShippingMethodJSONEl = $('reqShippingMethodJSON');
			var shippingOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('shippingOptions');			
			
			if ((shippingOptionsGroup != null) && (reqShippingMethodJSONEl != null)) {
			
				var reqShippingMethodJSON = eval('(' + reqShippingMethodJSONEl.value + ')');
				
				var jsonShippingMethod = reqShippingMethodJSON.reqShippingMethods[obj.value];
				
				if(jsonShippingMethod != null) {
					
					var optionSelected = false;
					var initial = true;
					
					for (var i = 0; i < shippingOptionsGroup.length; i++) {
						
						if(shippingOptionsGroup[i].checked) {
							
							initial = false;
						}
					
						shippingOptionsGroup[i].disabled = true;						
						for(var j = 0; j < jsonShippingMethod.length; j++) {
							if(shippingOptionsGroup[i].value == jsonShippingMethod[j].shippingMethodID) {
								
								if(shippingOptionsGroup[i].checked && !optionSelected) {
									
									optionSelected = true;
								}
								shippingOptionsGroup[i].disabled = false;
							}
						}
					}
					for (var i = 0; i < shippingOptionsGroup.length; i++) {
						
						if(!shippingOptionsGroup[i].disabled && !optionSelected && !initial) {
						
							shippingOptionsGroup[i].checked = true;
							break;
						}
					}
				}
				else {
					for (var i = 0; i < shippingOptionsGroup.length; i++) {
					
						shippingOptionsGroup[i].disabled = false;
						
					}
				}
			}
		},
		
		updatePaymentCtn: function(obj) {
			var url = $('updatePaymentCtnUrl').value;
			new Ajax.Updater('paymentCtn', url, {
			
					method: 'post', 
					evalScripts: true, 
					parameters: obj.name + "=" + obj.value,
					onComplete: function(transport) {
						initializePopupLinkHandler();
						_redeemPointsEventListener.selectPaymentSubMethod(null);
						
					}
				});
		},
		
		clickHandler: function() {
		
			this.paymentBindObj.updatePaymentCtn(this);
								
			// first activate or deactivate shipping methods depending on payment method 
			this.paymentBindObj.selectShippingMethod(this);
			// now deactivate methods based on their freight station support
			var dwAddressGroup = this.paymentBindObj.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
			var dwFreightStationShippAddrBoxEl	= dwAddressGroup[1];			
			if(dwFreightStationShippAddrBoxEl != null){
				_shippAddrEventListener.selectFreightStationSupportingShippingMethod(dwFreightStationShippAddrBoxEl);
			}
			
			return true;
		}
	};
	
	var _redeemPointsEventListener = {
	
		storedOptions: new Array(),
	
		checkoutHelperObj: function() {
		
			return new CheckoutHelper();
		},
		
		initialize: function() {

			var dwRedeemPointsEl = $("dwRedeemPoints");
			var applicablePaymentMethodsJSONEl = $('applicablePaymentMethodsJSON');
			var dwRedeemPoints = null;

			if(applicablePaymentMethodsJSONEl != null){
				if(dwRedeemPointsEl != null){
					dwRedeemPoints = $(dwRedeemPointsEl.value);
					if(dwRedeemPoints != null){
						dwRedeemPoints.pointsBindObj = this;
						dwRedeemPoints.onclick = this.clickHandler;
					}				
				}
				this.selectPaymentMethod(dwRedeemPoints);
			}					
		},		
		
		selectPaymentMethod: function(obj) {
			
			if(obj == null){
				// Try to find redeemPoints
				var dwRedeemPointsEl = $("dwRedeemPoints");
				var dwRedeemPoints = null;
				if(dwRedeemPointsEl != null){
					dwRedeemPoints = $(dwRedeemPointsEl.value);
					if(dwRedeemPoints != null){
						obj = dwRedeemPoints;
					}				
				}									
			}
			
			var applicablePaymentMethodsJSONEl = $('applicablePaymentMethodsJSON');
			var paymentOptionsGroup = this.checkoutHelperObj()._getDWOptionGroup('paymentOptions');			
			if ((paymentOptionsGroup != null) && (applicablePaymentMethodsJSONEl != null)) {
			
				var applicablePaymentMethodsJSONE = eval('(' + applicablePaymentMethodsJSONEl.value + ')');
				
				var applicablePaymentMethods;
				
				if(obj == null){
					applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.noPoints;
				}
				else{
					if(obj.checked)
						applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.withPoints;	
					else
						applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.noPoints;
				}
											
				var selectNewOption = false;
				for (var i = 0; i < paymentOptionsGroup.length; i++) {	
					if(applicablePaymentMethods.indexOf(paymentOptionsGroup[i].value) == -1){
						if(paymentOptionsGroup[i].checked) {								
							selectNewOption = true;
						}
						paymentOptionsGroup[i].disabled = true;
					}
				}
				for (var i = 0; i < paymentOptionsGroup.length; i++) {
					if(!paymentOptionsGroup[i].disabled && selectNewOption) {
						paymentOptionsGroup[i].checked = true;
						_shippAddrEventListener.updatePaymentCtn(paymentOptionsGroup[i]);						
						break;
					}
				}		
			}
			this.selectPaymentSubMethod(obj);
		},		
		
		selectPaymentSubMethod: function(obj) {		// for credit card types

			if(obj == null){
				// Try to find redeemPoints
				var dwRedeemPointsEl = $("dwRedeemPoints");
				var dwRedeemPoints = null;
				if(dwRedeemPointsEl != null){
					dwRedeemPoints = $(dwRedeemPointsEl.value);
					if(dwRedeemPoints != null){
						obj = dwRedeemPoints;
					}				
				}									
			}
						
			var applicablePaymentMethodsJSONEl = $('applicablePaymentMethodsJSON');
			var subMethodSelectEl = $('dwCreditCardType');
			var subMethodSelect = null;
			if(subMethodSelectEl != null){
				subMethodSelect = $(subMethodSelectEl.value);
			}						
						
			if ((subMethodSelect != null) && (applicablePaymentMethodsJSONEl != null)) {
			
				var applicablePaymentMethodsJSONE = eval('(' + applicablePaymentMethodsJSONEl.value + ')');
				
				var applicablePaymentMethods;
				
				if(obj == null){
					applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.noPoints;
				}
				else{
					if(obj.checked)
						applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.withPoints;	
					else
						applicablePaymentMethods = applicablePaymentMethodsJSONE.applPaymentMethods.noPoints;
				}
				
				// Refill select with recently removed options
				this.storedOptions.each(function(item){
					item.selected = false;
					var duplicate = false;
					for (var i = 0; i < subMethodSelect.length; i++) {	
						if(subMethodSelect.options[i] == item) {								
							duplicate = true;
						}
					}
					if(!duplicate)										
						subMethodSelect.insert(item);
				});
				this.storedOptions.clear();						
							
				// Remove unapplicable options							
				/*var selectNewOption = false;
				for (var i = 0; i < subMethodSelect.length; i++) {	
					if(applicablePaymentMethods.indexOf(subMethodSelect.options[i].value) == -1){
						if(subMethodSelect.options[i].selected) {								
							selectNewOption = true;
						}
						// Remove option since disabling won't work in everyone's favourite IE6						
						this.storedOptions[this.storedOptions.length] = subMethodSelect.options[i].remove();
					}
				}
				if(selectNewOption && subMethodSelect.length > 0) {
					subMethodSelect.selectedIndex = 0;
				}*/		
			}
		},		
		
		clickHandler: function() {
			// first activate or deactivate payment methods depending on shipping address 
			var dwAddressGroup = this.pointsBindObj.checkoutHelperObj()._getDWAddressGroup('addressTypeDifferent', 'addressTypeFreightStation');
			var dwDifferentShippAddrBoxEl		= dwAddressGroup[0];
			var dwFreightStationShippAddrBoxEl	= dwAddressGroup[1];
			if(dwDifferentShippAddrBoxEl != null && dwFreightStationShippAddrBoxEl != null){
				if(dwDifferentShippAddrBoxEl.checked)
					_shippAddrEventListener.selectPaymentMethod(dwDifferentShippAddrBoxEl);
				else
					_shippAddrEventListener.selectPaymentMethod(dwFreightStationShippAddrBoxEl);
			}	
			// now deactivate methods based on the applicable payment methods
			this.pointsBindObj.selectPaymentMethod(this);
			
			return true;
		}		
	};
		
	
	var _confirmEventListener = {	
	
		active: true,
		deactivateImage: null,
		oldImageSrc: null,
	
		checkoutHelperObj: function() {
		
			return new CheckoutHelper();
		},
		
		initialize: function() {

			var confirmBttnEl = $("confirmButton");
			var dwConfirmBttn = null;

			if(confirmBttnEl != null){
				dwConfirmBttn = $(confirmBttnEl.value);
			}

			if(dwConfirmBttn != null){
				dwConfirmBttn.confirmBindObj = this;
				dwConfirmBttn.onclick = this.clickHandler;
			}
			
			var imageSrcEl = $("confirmButtonDeactivateSrc");
		
			if(imageSrcEl != null){
				this.deactivateImage = new Image();
				this.deactivateImage.src = imageSrcEl.value;
				
				// Register event listener for overlay
				var overlay = $('overlay');
				if(overlay != null){
					overlay.observe('overlay:shown',this.unblock);
				}
			}			
		},
		
		setDeactivateImage: function(obj) {
		
			if(this.deactivateImage != null){
				this.oldImageSrc = obj.src;
				obj.src = this.deactivateImage.src;
			}
		},	
		
		unblock: function() {
			var confirmBttnEl = $("confirmButton");
			var dwConfirmBttn = null;

			if(confirmBttnEl != null){
				dwConfirmBttn = $(confirmBttnEl.value);
			}

			if(dwConfirmBttn != null){
				dwConfirmBttn.disabled = false;
				this.active = true;
				
				if(this.oldImageSrc != null){
					var oldImage = new Image();
					oldImage.src = this.oldImageSrc;
					dwConfirmBttn.src = oldImage.src;
				}						
			}					
		},
		
		clickHandler: function() {
			if(this.confirmBindObj.active){
				this.confirmBindObj.active = false;
				this.confirmBindObj.setDeactivateImage(this);
				return true;
			}
			else{
				// Block all futher submits
				// (To make sure nothing slips through (on order summary page) additionally deactivate button)
				this.disabled = true;
				return false;
			}
		}	
	};
	
	//*** event listener - END ***/
	
	/* 
	 * Initializes the checkout helper
	 * 
	 * @return
	 */
	this.init = function() {
	
		_shippAddrEventListener.initialize();
		_paymentEventListener.initialize();
		_confirmEventListener.initialize();
		_redeemPointsEventListener.initialize();
	};
	
	/* 
	 * Private method to get the Demandware option group elements.
	 * 
	 * @return HTML Elements
	 */
	this._getDWOptionGroup = function(elementId) {
	
		var optionsEl		= $(elementId);
		var optionsGroup	= null;
		
		if(optionsEl != null) {
		
			optionsGroup	= $$('[name="' + optionsEl.value + '"]');
		}
		
		return optionsGroup;
	};
	
	/* 
	 * Private method to get the Demandware address type elements.
	 * 
	 * @return Array
	 */
	this._getDWAddressGroup = function(address1, address2) {	
		var address1El		= $(address1);
		var address2El		= $(address2);
		
		var dwAddress1El	= null;
		var dwAddress2El	= null;
		
		
		if(address1El != null && (address2El != null)) {
		
			dwAddress1El	= $(address1El.value);
			dwAddress2El	= $(address2El.value);
		}
		
		return new Array(dwAddress1El, dwAddress2El);		
	};
}

if ('observe' in document) {

	document.observe('dom:loaded', function() {
	
		// initialize checkout helper
		checkoutHelperObj = new CheckoutHelper();
		// timeout hack for our beloved IE6
		window.setTimeout('checkoutHelperObj.init()', 0);
	});
}

