String.prototype.trim = function() { 
 return this.replace(/^\s+|\s+$/g, ""); 
} 
/*Usage at Login and registarion functionality included pages: This function is used to submit form on by press enter key*/  	
function checkEnterAndSubmitSearch(formObj,event) {
	if(checkEnter(formObj,event)) {
		formObj.name.value='submit';
		formObj.submit();
	}
}

/*This function is used to open form in new window when we click on the Signup button in footer section*/  
function openApromoWindow(url) {
	URL = url + document.apromoform.emailAddress.value;
    window.open(URL);
    return false;
}

/*This function is used to submit form on by press enter key*/  	
function checkEnter(formObj,event){
   var characterCode;
	if(formObj && formObj.which){
       formObj = formObj;
       characterCode = formObj.which;
	} else {
       formObj = event;
       characterCode = formObj.keyCode;
	}             
	if(characterCode == 13){
       return true;
	} else {
		return false;
	}
}

/*This function is used to check is pressed is numberkey or not*/  	
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
       return false;
	} else {
		return true;
	}
}

/*This function is used to check is pressed is "c" or "v"*/  
function noCTRL(evt) {
   var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
  if (event.ctrlKey && (pressedKey == "c" || 
                        pressedKey == "v")) {
    event.returnValue = false;
  }
}

/*This function is used to call additem to order function*/  
function addToCart(productId,skuId) {
	var qty = document.getElementById("quantity"+productId).value;	
	if(qty==0||qty.length==0||qty.length==""){
		qty=1;
	}
	omnitureAddTocart(productId);
	document.addToCartForm["/atg/commerce/order/purchase/CartModifierFormHandler.productId"].value=productId;
	document.addToCartForm["/atg/commerce/order/purchase/CartModifierFormHandler.quantity"].value=qty;
    document.addToCartForm["/atg/commerce/order/purchase/CartModifierFormHandler.catalogRefIds"].value=skuId;
    window.document.addToCartForm["/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrder"].value="submit";
    document.addToCartForm.submit();
}
/*This functions is used to send informtion to omniture after adding item to cart*/   
 function omnitureAddTocart(productId){
	var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
	var ssProductsExists = document.getElementById("omnitureSSProductsExists").value;	
	  if(ssProductsExists=='true'){
	 var ssIdstring= document.getElementById("omnitureSSProductsIds").value;
	 var  ssIds =ssIdstring.split("|");
	 for(var i=0;i < ssIds.length;i++){ 
	 	 if(ssIds[i]==productId){
	 return;
	 }	
	 }
	  }
	
    if(isOmnitureRequired =="yes" && typeof(s)==="object"){
	var qty = document.getElementById("quantity"+productId).value;
	var price = document.getElementById("price"+productId).value;
	var marketingName=document.getElementById("markeingname"+productId).value; 
	var categoryName=document.getElementById("categoryName"+productId).value; 	
	categoryName=categoryName.replace(/&/g," ");  	
	if(qty==0||qty.length==0||qty.length==""){
		qty=1;
	}
	var ciPrice = qty * price;	
	marketingName=marketingName.replace(/,/g, " ");
	 var finalString=categoryName+";"+marketingName+";"+qty+";"+ciPrice;
	 var omniturecartEvent = document.getElementById("omnitureCartEvent").value; 
	   s.events=omniturecartEvent;
       s.products=finalString;
	   invokeOmniture();	 
	}
 } 
 

/*This function is used to call additem to order function*/  
function addToSmartCart(productId,skuId) { 
	var qty = document.getElementById("quantity"+productId).value;
	if(qty==0||qty.length==0||qty.length==""){
		qty=1;
	}	
	omnitureAddTocart(productId);
	document.addToCartSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.productId"].value=productId;
	document.addToCartSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.quantity"].value=qty;
    document.addToCartSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.catalogRefIds"].value=skuId;
    window.document.addToCartSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrder"].value="submit";
    document.addToCartSmartForm.submit();
}

/*This function is used to compare selected items by calling the handle method*/  
function compareCatPageItems(tabValue) {
	var checkedProdIds = new Array();
    var cbs=document.getElementsByName("compare");
    var j=0;
    for(var i=0; i<cbs.length; i++){
	  if(cbs[i].checked==true){
		 checkedProdIds[j]=cbs[i].value;
	  	 j=j+1;
	  }
    }
   if(checkedProdIds.length > 0){
     document.compareItemsForm["/lexmark/comparison/PrinterProductHandler.productIds"].value=checkedProdIds;
   }
   window.document.compareItemsForm["/lexmark/comparison/PrinterProductHandler.compare"].value="submit";
   document.compareItemsForm.submit();
}

/*This function is used to compare selected items by calling the handle method*/  
function compareItems() {
	var checkedProdIds = new Array();
    var cbs=document.getElementsByName("compare");
    var j=0;
    var baseProdId = document.getElementById("baseProdId");
    if (baseProdId != null) {
		checkedProdIds[j] = baseProdId.value;
   		j = j+1;
     }
    for(var i=0; i<cbs.length; i++) {
		if(cbs[i].checked==true){
			checkedProdIds[j]=cbs[i].value;
			j=j+1;
		}
    }
    if(checkedProdIds.length > 0) {
      document.compareItemsForm["/lexmark/comparison/PrinterProductHandler.productIds"].value=checkedProdIds;
    }
    window.document.compareItemsForm["/lexmark/comparison/PrinterProductHandler.compare"].value="submit";
    document.compareItemsForm.submit();
}

/*This function is used to remove the the selected product*/  
function removeItem(productId) {
   document.removeProdForm["/lexmark/comparison/PrinterProductHandler.productToBeRemoved"].value=productId;	
   document.removeProdForm.submit();
}

/*This function is used to show the links*/ 
function showMoreLinks(belowId,upperId) {
	if (document.getElementById(belowId).style.display == 'none') {
		document.getElementById(belowId).style.display = 'block';
		document.getElementById(upperId).style.display = 'none';
	} else {
		document.getElementById(belowId).style.display = 'none';
	}
}

/*Usage at Shoppingcart page: This function is used redirect to checkout shippingandbilling page*/ 
function checkOutItems(formName) {
     omnitureCheckoutItems();
    window.document.checkoutForm["/atg/commerce/order/purchase/CartModifierFormHandler.moveToPurchaseInfoByRelId"].value="submit";
    document.checkoutForm.submit();
}

/*Usage at Shoppingcart page: This function is used to invoke the omniture function*/ 
  function omnitureCheckoutItems(){ 
    var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
   if(isOmnitureRequired =="yes" && typeof(s)==="object"){ 
     s.events="scCheckout";
	 invokeOmniture();	
	}
  }

/*This function is used show and Hide the Products*/ 
function showHideProducts(firstSection, secondSection) {	
		document.getElementById(secondSection).style.display = 'block';
		document.getElementById(firstSection).style.display = 'none';
}	

/*Usage at Shoppingcart page: This function is used to remove all items from the cart*/ 
function removeAllItems() {
   var removalItems= document.getElementsByName("removalItems");
   var allids;
   allids=removalItems[0].value;
   for( i=1;i<removalItems.length;i++) {
     allids=allids+"&"+removalItems[i].value;
   }
   var removalMarketingnames=document.getElementsByName("marketingNames"); 
   var removalCategorynames=document.getElementsByName("categoryNames"); 
   
   var removalQtys=document.getElementsByName("quantity"); 
   var removalPrices =document.getElementsByName("price");
   var ciPrice = removalQtys[0].value*removalPrices[0].value;
   var marketingName;
   var categoryName;
   marketingName=removalMarketingnames[0].value.replace(/,/g, " ");   
   categoryName=removalCategorynames[0].value.replace(/&/g," "); 
   var finalString =categoryName+";"+marketingName+";"+removalQtys[0].value+";"+ciPrice;   
    for( i=1;i<removalMarketingnames.length;i++) {
	ciPrice=removalQtys[i].value*removalPrices[i].value;
	 marketingName=removalMarketingnames[i].value.replace(/,/g, " "); 
	 categoryName=removalCategorynames[i].value.replace(/&/g," ");	 
     finalString=finalString+","+categoryName+";"+marketingName+";"+removalQtys[i].value+";"+ciPrice;
    }	
    omnitureRemoveItem(finalString);   
   document.deleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removalCommerceIds"].value=allids;
   window.document.deleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removeItemFromOrder"].value="submit";
   document.deleteForm.submit();
}
 
/*Usage at Shoppingcart page: This function is used to remove selected item from the cart*/
function removeCartItem(removalId) {
        var marketingName = document.getElementById(removalId+"marketinName").value;
	   var categoryName = document.getElementById(removalId+"omncatName").value;
		var quantity = document.getElementById(removalId+"omnquantity").value;		
		var price = document.getElementById(removalId+"price").value;
		var ciPrice=quantity*price;
		 marketingName=marketingName.replace(/,/g, " "); 
		 categoryName=categoryName.replace(/&/g," ");
		var finaString = categoryName+";"+marketingName+";"+quantity+";"+ciPrice;
        omnitureRemoveItem(finaString);
		document.deleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removalCommerceIds"].value=removalId;
		window.document.deleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removeItemFromOrder"].value="submit";
		document.deleteForm.submit();
} 

/*Usaget at shoppingcart page: This functions is used to call the omniture script on removing the item from cart*/
function omnitureRemoveItem(param){     
   var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
   if(isOmnitureRequired =="yes" && typeof(s)==="object"){ 	 
     s.events='scRemove';
     s.products=param;
	 s.prop4=document.getElementById("omnitureLanguage").value;
    var s_code=s.t(); 
	}
	}

/*Usage at Shoppingcart page: This function is used to update the item in the cart*/
function cartUpdateForm(id,sku) {
	ele = document.getElementById(id+"oQty");	
	if(window.document.cartUpdateNDeleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removeItemFromOrder"]!=undefined){ 
		 window.document.cartUpdateNDeleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removeItemFromOrder"].name="";
	   }
	if(window.document.cartUpdateNDeleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removalCommerceIds"]!=undefined){ 
	  window.document.cartUpdateNDeleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.removalCommerceIds"].name="";
	}
	document.getElementById(id).value=ele.value;
	window.document.cartUpdateNDeleteForm["skuId"].value=sku;
	window.document.cartUpdateNDeleteForm["updatedItemQty"].value=ele.value;
	window.document.cartUpdateNDeleteForm["updatedItem"].value=id;
	window.document.cartUpdateNDeleteForm["/atg/commerce/order/purchase/CartModifierFormHandler.setOrderByCommerceId"].value="submit";
	document.cartUpdateNDeleteForm.submit();
}

/*This function is used to remove the product from product list*/
function saveCompChanges() {
   window.document.getElementById("noneSelected").value = "true";	
   var buttons = window.document.getElementsByName("compAttr");
	for(var i=0; i<buttons.length; i++){
		if(buttons[i].checked==true) {
			window.document.getElementById("noneSelected").value = "";
		} 
	}
   document.saveChangesForm.submit();
}

/*This function is used to check at all once a hit*/
function checkAll() {
	var buttons = window.document.getElementsByName("compAttr");
	for(var i=0; i<buttons.length; i++){
		buttons[i].checked=true;
	}
}

/*This function is used to call the handle method*/
function cancelCompChanges() {
	document.cancelForm.submit();
}

/*This function is used to uncheck at all once a hit*/
function deCheckAll() {
	var buttons = window.document.getElementsByName("compAttr");
	for(var i=0; i<buttons.length; i++){
		buttons[i].checked=false;
	}
}

/*Usage at Search: This function is used to insatnceiate the xmlHttp object*/
var printerCategoryId;
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  } catch (e) {
	  // Internet Explorer
		 try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
 }

/*Usage at Search: This function is used to Fetch the PrinterModels withoout page refreshing*/	
function ajaxCallToFetchPrinterModels(countryCode,categoryId) {	
	printerCategoryId = categoryId;
	xmlHttp	 =	GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url;
	if(categoryId != '') {
		url="/" + countryCode+"/search/includes/fetchProducts.jsp?categoryId="+categoryId;;
	} else {
		url="/" + countryCode+"/search/includes/fetchAllPrinterProducts.jsp";
	}
	xmlHttp.onreadystatechange=fetchPrinterModels;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/*Usage at Search: This function is used to Fetch the Smart Solutions PrinterModels withoout page refreshing*/	
function ajaxCallToSmartSolutionsFetchPrinterModels(countryCode,categoryId) {	
	printerCategoryId = categoryId;
	xmlHttp	 =	GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url;
	if(categoryId != '') {
		url="/" + countryCode+"/search/includes/smartSolutionsFetchProducts.jsp?categoryId="+categoryId;;
	} else {
		url="/" + countryCode+"/search/includes/smartSolutionsfetchAllPrinterProducts.jsp";
	}
	xmlHttp.onreadystatechange=fetchPrinterModels;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/*Usage at Search: This function is used to Fetch the PrinterModels withoout page refreshing*/
function fetchPrinterModels() {
   if (xmlHttp.readyState==4) {
		var errorMessage = document.getElementById('errorMessage');
		errorMessage.style.display="none";
		var ele=xmlHttp.responseXML;
		if(ele!=null) {
			ele = xmlHttp.responseXML.documentElement;
		}
		var selectobj=document.getElementById('printerModel');
		if(ele!=null) {
			var xmlDoc=xmlHttp.responseXML.documentElement;
			var x=xmlDoc.getElementsByTagName("printerModel");
			selectobj.options.length=0;
			var j =0;
			if(x.length > 0) {
				for (i=0;i<x.length;i++) {						
					if(x[i].getElementsByTagName("printerName")[0].childNodes[0] != null) {   
						selectobj.options[j]=new Option(x[i].getElementsByTagName("printerName")[0].childNodes[0].nodeValue,x[i].getElementsByTagName("printerId")[0].childNodes[0].nodeValue);
						j++;
					}
				}
			} 
			if(x.length == 1) {
				if(printerCategoryId != '') {
					errorMessage.style.display="block";
				}
			}

		} else {
			selectobj.options.length=0;
			selectobj.options[0]=new Option('Step 2: Select Printer Model','');
			if(printerCategoryId != '') {
				errorMessage.style.display="block";
			}
		}
		var disable = document.getElementById('dropdownDisableButton');
		var enable = document.getElementById('dropdownEnableButton');
		enable.style.display="none";
		disable.style.display="block";
	 }		
 }
 
 /*Usage at Search: This function is used to disable or enable the dropdown*/	
 function disableEnable(Value) {
	var disable = document.getElementById('dropdownDisableButton');
	var enable = document.getElementById('dropdownEnableButton');
	if(Value == '' || Value == 'step2') {
		enable.style.display="none";
		disable.style.display="block";
	} else {
		enable.style.display="block";
		disable.style.display="none";
	}
 }

 /*Usage at Search: This function is used to disable or enable the textbox by passing event*/	
 function disableEnable1(evt) {
		var charCode = (evt.which) ? evt.which : evt.keyCode
		var textBox = document.getElementById('searchTextBox');
		if(charCode == 13) {
			if(textBox.value == '')	{
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}

 /*Usage at Search: This function is used to disable or enable the textbox*/	
 function disableEnable2(e,searchElement) {
	var textBox = document.getElementById('searchTextBox');
	var disable = document.getElementById('textboxDisableButton_id');
	var enable = document.getElementById('textboxEnableButton_id');
	if(textBox.value == '' || textBox.value == ' ' || textBox.value == 'Enter cartridge number') {
		enable.style.display="none";
		disable.style.display="block";
	} else {
		enable.style.display="block";
		disable.style.display="none";
	}
	//populateSearchSuggetions(e,searchElement);
	return true;
  }

 /*Usage at Search: This function is used to disable or enable the textbox*/		
 function disableEnable3() {
	 var disable = document.getElementById('textboxDisableButton_id');
	 var enable = document.getElementById('textboxEnableButton_id');
	 enable.style.display="none";
	 disable.style.display="block";
  }

 /*Usage at Search: This function is used to disable or enable the textbox*/	
 function disableEnable4(textValue) {
	var textBox = textValue;
	var disable = document.getElementById('textboxDisableButton_id');
	var enable = document.getElementById('textboxEnableButton_id');
	if(textValue == '' || textValue == 'Enter cartridge number') {
		enable.style.display="none";
		disable.style.display="block";
	} else {
		enable.style.display="block";
		disable.style.display="none";
	}
  }
	
 /*Usage at Search: This function is used to enable the textbox*/	
 function disableEnable5() {
	  var disable = document.getElementById('textboxDisableButton_id');
	  var enable = document.getElementById('textboxEnableButton_id');
	  enable.style.display="none";
	  disable.style.display="";
 }

 /*Usage at Search: This function is used to enable or disable the textbox*/	
 function disableEnable6(textValue) {
		var textBox = textValue;
		var disable = document.getElementById('textboxDisableButton_id');
		var enable = document.getElementById('textboxEnableButton_id');
		if(textValue == '' || textValue == 'Cartridge or Printer Model') {
			enable.style.display="none";
			disable.style.display="";
		} else {
			enable.style.display="inline-block";
			disable.style.display="none";
		}
 }

 /*Usage at Search: This function is used to enable or disable the textbox*/	
 function disableEnable7(e,searchElement) {
		var textBox = document.getElementById('searchTextBox');
		var disable = document.getElementById('textboxDisableButton_id');
		var enable = document.getElementById('textboxEnableButton_id');
		if(textBox.value == '' || textBox.value == 'Cartridge or Printer Model') {
			enable.style.display="none";
			disable.style.display="";
		} else {
			var dataString =navigator.userAgent;
			var searchString = "Firefox";
			if (dataString.indexOf(searchString) != -1) {
				var index =	dataString.indexOf(searchString);
				if(parseFloat(dataString.charAt(index+searchString.length+1))>=2) {
					enable.style.display="-moz-inline-stack";
					disable.style.display="none";
				} else {
					enable.style.display="inline-block";
					disable.style.display="none";
				}
			} else {
				enable.style.display="inline-block";
				disable.style.display="none";
			}
		}
		//populateSearchSuggetions(e,searchElement);
	  return true;
  }

  /*Usage at Shippingandbilling --> billing section: This function is used to copy the shippingaddress copies to billing section*/  	
  function copyShippingToBilling() {
		if(document.getElementById('checkSameasAhipping').checked){
			document.getElementById('sameasshipping').value = true;
			document.getElementById('billingAddressFirstName').value = document.getElementById('shipingAddressFirstName').value;
			document.getElementById('billingAddressLastName').value = document.getElementById('shippingAddressLastName').value;			
			document.getElementById('billingAddressAddressOne').value = document.getElementById('shippingAddressAddressOne').value;			
			document.getElementById('billingAddressAddressTwo').value = document.getElementById('shippingAddressAddressTwo').value;			
			document.getElementById('billingAddressCity').value = document.getElementById('shippingAddressCity').value;
			if (document.getElementById('shippingAddressState').selectedIndex == undefined) {
			 document.getElementById('billingAddressState').value = document.getElementById('shippingAddressState').value;
			} else {
			 document.getElementById('billingAddressState').selectedIndex = document.getElementById('shippingAddressState').selectedIndex;
			}
			document.getElementById('billingAddressPostalCode').value = document.getElementById('shippingAddressPostalCode').value;			
			document.getElementById('billingAddressPhoneNumber').value = document.getElementById('shippingAddressPhoneNumber').value;
			
			if(document.getElementById('billingAddressNickName') != null){			
				document.getElementById('billingAddressNickName').value = document.getElementById('shippingAddressNickName').value;
			}
		} else {
			document.getElementById('sameasshipping').value = false;
			document.getElementById('billingAddressFirstName').value = "";
			document.getElementById('billingAddressLastName').value = "";			
			document.getElementById('billingAddressAddressOne').value = "";			
			document.getElementById('billingAddressAddressTwo').value = "";			
			document.getElementById('billingAddressCity').value = "";
			document.getElementById('billingAddressState').selectedIndex = 0;			
			document.getElementById('billingAddressPostalCode').value = "";			
			document.getElementById('billingAddressPhoneNumber').value = "";
			if(document.getElementById('billingAddressNickName') != null){			
				document.getElementById('billingAddressNickName').value = "";
			}	
		}
  }

 /*Usage at Shippingandbilling --> billing section: This function is used to copy the readable shippingaddress copies to readable billing section*/  
  function copyShippingContentToBillingContent(){
		if(document.getElementById('checkSameasAhippingFromReadable').checked){
			document.getElementById('sameasshipping').value = true;
			var fname = document.getElementById('shipingAddressFirstName').value;
			var lname = document.getElementById('shippingAddressLastName').value;
			var address1 = document.getElementById('shippingAddressAddressOne').value;			
			var address2 = "";
			if (document.getElementById('shippingAddressAddressTwo').value	 != 'undefined'){ 
			  address2 = document.getElementById('shippingAddressAddressTwo').value;	
			} else {
 			  address2 = "undefined";
			}
			if (address2 == 'undefined' || address2 == ''){
			  var concataddress = address1;
			} else {
               var concataddress = address1 + ", " + address2;	 
			}
			var city = document.getElementById('shippingAddressCity').value;
			var state = document.getElementById('shippingAddressState').value;
			var postalcode = document.getElementById('shippingAddressPostalCode').value;	
			var phonenumber = document.getElementById('shippingAddressPhoneNumber').value;
			var shippingAddressSelectedValue = document.getElementById('shippingaddressOwnerId').value;
			if (shippingAddressSelectedValue == null || shippingAddressSelectedValue == '') {
			  var shippingAddressSelectedValue = document.getElementById('populateAddressid').value;
			}
			if (fname != null && fname != '' && lname != null && lname != '' && address1 != null && address1 != '' && city != null && city != '' &&  postalcode != null &&  postalcode!= '' && state != 'select') {
				document.getElementById("billingaddressOwnerId").value=shippingAddressSelectedValue;
				document.getElementById("populatebillingAddressid").value=shippingAddressSelectedValue;
				if (shippingAddressSelectedValue != null && shippingAddressSelectedValue != '' && shippingAddressSelectedValue != "null") {
					var billingAddressValues = document.usershippingandbillingform.elements['billingaddress'];
					if (billingAddressValues != null) {
						var elem =  billingAddressValues.options;
						for(var j=0; j<=elem.length;j++) {
							if(elem[j]!=null && elem[j] != 'undefined'){
								if(elem[j].value==shippingAddressSelectedValue) {
									elem[j].selected=true;
								}
							}
						}
						for(var j=1; j<=elem.length;j++) {
							if(elem[j]!=null && elem[j] != 'undefined'){
								if(elem[j].value=='select') {
								  billingAddressValues.remove(j);		
								}
							}
						}
					}

				} else {
					var selectaddressesDropdown = document.usershippingandbillingform.billingaddress;
					var shippingAddressNickName = document.getElementById('shippingAddressNickName').value;
					var billingAddressValues = document.usershippingandbillingform.elements['billingaddress'];
					if (billingAddressValues != null && billingAddressValues != 'undefined') {
					var elem =  billingAddressValues.options;
						for(var j=0; j<=elem.length;j++) {
							if(elem[j]!=null && elem[j] != 'undefined'){
								if(elem[j].value=='select') {
								  billingAddressValues.remove(j);		
								}
							}
						}
						var nicknameOption = document.createElement('option');
						var nonicknameOption = document.createElement('option');
						nicknameOption.text = 'Select From Available Addresses';
						nicknameOption.value = 'select';
						try {
							// For standard browsers
							selectaddressesDropdown.options.add(nicknameOption);
							var elem =  selectaddressesDropdown.options;
							for(var j=0; j<=elem.length;j++) {
								if(elem[j]!=null && elem[j] != 'undefined'){
									if(elem[j].value=='select') {
										elem[j].selected=true;
									}
								}
							}
						}
						catch (ex) {
							// For Microsoft Internet Explorer and other non-standard browsers.
							selectaddressesDropdown.options.add(nicknameOption);
							var elem =  selectaddressesDropdown.options;
							for(var j=0; j<=elem.length;j++) {
								if(elem[j]!=null && elem[j] != 'undefined'){
									if(elem[j].value=='select') {
										elem[j].selected=true;
									}
								}
							}
						}
					}
				}
				var concatname = fname + " " +lname;
				document.getElementById("billingFirstname").innerHTML=concatname;
				document.getElementById("billingAddress1").innerHTML=concataddress;
				var concatedinfo =city+", "+state+" "+postalcode;
				document.getElementById("billingCity").innerHTML=concatedinfo;
				
				document.getElementById("billingPhone").innerHTML = document.getElementById('shippingAddressPhoneNumber').value;
				document.getElementById('billingAddressFirstName').value = document.getElementById('shipingAddressFirstName').value;
				document.getElementById('billingAddressLastName').value = document.getElementById('shippingAddressLastName').value;			
				document.getElementById('billingAddressAddressOne').value = document.getElementById('shippingAddressAddressOne').value;			
				document.getElementById('billingAddressAddressTwo').value = document.getElementById('shippingAddressAddressTwo').value;			
				document.getElementById('billingAddressCity').value = document.getElementById('shippingAddressCity').value;
				if (document.getElementById('shippingAddressState').selectedIndex == undefined) {
				 document.getElementById('billingAddressState').value = document.getElementById('shippingAddressState').value;
				} else {
				 document.getElementById('billingAddressState').selectedIndex = document.getElementById('shippingAddressState').selectedIndex;
				}
				document.getElementById('billingAddressPostalCode').value = document.getElementById('shippingAddressPostalCode').value;			
				document.getElementById('billingAddressPhoneNumber').value = document.getElementById('shippingAddressPhoneNumber').value;
				
				if(document.getElementById('billingAddressNickName') != null){
					document.getElementById('billingAddressNickName').value = document.getElementById('shippingAddressNickName').value;
				}
				if(document.getElementById('billingAddressCountry') != null && document.getElementById('shippingAddressCountry') != null) {
					document.getElementById('billingAddressCountry').value = document.getElementById('shippingAddressCountry').value;
				}
			}
		} else {
			document.getElementById('sameasshipping').value = false;
		}
  }
 
  /*Usage at Shippingandbilling --> shipping section: This function is used to show and hide the nickname field by onclick*/  
  function disableenable8(){
		if(document.getElementById("checkShippingAddress").checked == true){
			document.getElementById("saveShippingAddress").value=true;
			if (document.getElementById("shippingAddressNickNameFragment") != null) {
			  document.getElementById("shippingAddressNickNameFragment").style.display = 'block';
			}
		}
		else {
			document.getElementById("saveShippingAddress").value=false;
			if (document.getElementById("shippingAddressNickNameFragment") != null) {
			  document.getElementById("shippingAddressNickNameFragment").style.display = 'none';
			}
		}		
  }

  /*Usage at Shippingandbilling --> billing section: This function is used to show and hide the nickname field by onclick*/
  function disableenable9(){
		if(document.getElementById("checkBillingAddress").checked == true){
			document.getElementById("saveBillingAddress").value=true;
			if (document.getElementById("billingAddressNickNameFragment") != null) {
				document.getElementById("billingAddressNickNameFragment").style.display = 'block';
			}
		}
		else {
			document.getElementById("saveBillingAddress").value=false;
			if (document.getElementById("billingAddressNickNameFragment") != null) {
			  document.getElementById("billingAddressNickNameFragment").style.display = 'none';
			}
			var saveCreditCardCheckBoxObj = document.getElementById("saveCreditCard");
			if(saveCreditCardCheckBoxObj != null) {
				saveCreditCardCheckBoxObj.checked=false
			}

		}		
  }

  /*This function is used to pop-up the overlay*/	
  function openOverLay(){    
		var ct,ca,cg;
		ct = null;
		cg = false;
		var c_h = $(document).scrollTop() + 50;
		ca = contextPath+'/checkout/cvvhelpcontentoverlay.jsp?width=400&height=390&modal=true';
		tb_show(ct,ca,cg,c_h);
  }	
	
  /*This function is used to refresh the page on selecting no of items per page category result page*/
  function itemsperpage(requestURI,catId,addFacet,sort,trail,removeFacet,facetsToShow,collapsedFacets,changedFacetValue,nonPrinterCategory) {
     var selectedOne= document.getElementById("selected");
     window.location = requestURI+"?noofitmes="+selectedOne.value+"&catId="+catId+"&addFacet="+addFacet+"&sort="+sort+"&trail="+trail+"&removeFacet="+removeFacet+"&facetsToShow="+facetsToShow+"&collapsedFacets="+collapsedFacets+"&changedFacetValue="+changedFacetValue+"&nonPrinterCategory="+nonPrinterCategory;   
  }
		
  /*This function is used to refresh the page on selecting the sort option in category result page*/
  function sortbyoption(requestURI,catId,addFacet,noofitems,trail,removeFacet,facetsToShow,collapsedFacets,changedFacetValue,nonPrinterCategory) { 
	 var selectedOne= document.getElementById("sortselected");
	 window.location = requestURI+"?sort="+selectedOne.value+"&catId="+catId+"&addFacet="+addFacet+"&noofitmes="+noofitems+"&trail="+trail+"&removeFacet="+removeFacet+"&facetsToShow="+facetsToShow+"&collapsedFacets="+collapsedFacets+"&changedFacetValue="+changedFacetValue+"&nonPrinterCategory="+nonPrinterCategory;
  }

  /*Usage at Shippingandbilling --> shippingsection: This function is used to show the address by selecting from the dropdown without refreshing the page*/
  function displayShippingSelectedAddress(addressId,path) {
		if (document.getElementById('checkSameasAhippingFromReadable') != null) {
		  document.getElementById('checkSameasAhippingFromReadable').checked=false;
		  document.getElementById('sameasshipping').value=false;
		}
		if (document.getElementById('checkSameasAhipping') != null) {
		  document.getElementById('checkSameasAhipping').checked=false;
		  document.getElementById('sameasshipping').value=false;
		}
		if (addressId == 'select') {
			return false;
		}
		document.getElementById("shippingaddressOwnerId").value=addressId;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		}
		var url="/" + path+"/checkout/includes/populateshippinginfo.jsp";
		url+="?addressId="+addressId;
		xmlHttp.onreadystatechange=populateAddressValue;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
  }

  /*This function is used to print the values from responseobject to page side*/
  function populateAddressValue() {
	if (xmlHttp.readyState == 4) {
		var responseObject = xmlHttp.responseXML;
		if(responseObject != null) {
			responseObject = xmlHttp.responseXML.documentElement;
		}
		if(responseObject != null) {
			var xmlDoc = responseObject;
			    var fname="";
				var lname ="";
				var concatname="";
			if (xmlDoc.getElementsByTagName("firstName")[0] != null && xmlDoc.getElementsByTagName("firstName")[0].childNodes[0]!= null) {					
				 fname = xmlDoc.getElementsByTagName("firstName")[0].childNodes[0].nodeValue;
			}
             if(xmlDoc.getElementsByTagName("lname")[0] !=null &&  xmlDoc.getElementsByTagName("lname")[0].childNodes[0] != null){          
			 lname = xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
			 }			 

			 if(fname == ""){
                  concatname=lname;				 
			 }
			 else if(lname == ""){
				  concatname = fname ;	
			 }else{
			 concatname = fname + " " +lname;
			 }
				document.getElementById("shippingFirstname").innerHTML=concatname;
				document.getElementById("shipingAddressFirstName").value=fname;
				document.getElementById("shippingAddressLastName").value=lname;
			}
           var address1 ="";
		   var address2 = "";
		   var concataddress = ""; 
			if (xmlDoc.getElementsByTagName("address1")[0] != null && xmlDoc.getElementsByTagName("address1")[0].childNodes[0] != null ) { 				
				 address1 = xmlDoc.getElementsByTagName("address1")[0].childNodes[0].nodeValue;
			}			
				if (xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue != 'undefined'){ 
					document.getElementById("shippingAddressAddressTwo").value=xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue;
					address2 = xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue;
				} else {
				 document.getElementById("shippingAddressAddressTwo").value="";
				  address2 = "undefined";
				}
				if (address2 == 'undefined'){
				   concataddress = address1;
				} else if(address1 == "") {
                     concataddress =address2;
				}else {
				    concataddress = address1 + ", " + address2;	 
				}			
				document.getElementById("shippingAddress1").innerHTML=concataddress;
				document.getElementById("shippingAddressAddressOne").value=address1;

				var city = "";
    		 	var state = "";
				var  postalcode = "";
				var concatedinfo = "";

			if (xmlDoc.getElementsByTagName("city")[0] != null && xmlDoc.getElementsByTagName("city")[0].childNodes[0] != null ) {				
				 city = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
				 concatedinfo = city;
				}

           if(xmlDoc.getElementsByTagName("state")[0] != null && xmlDoc.getElementsByTagName("state")[0].childNodes[0] != null){
              state = xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue;			
              if(city == ""){
                  concatedinfo =state;
			  }else{
                      concatedinfo+= ","+state;
			  }
		    }
		   if (xmlDoc.getElementsByTagName("zip")[0] != null && xmlDoc.getElementsByTagName("zip")[0].childNodes[0] != null) { 				
				 postalcode = xmlDoc.getElementsByTagName("zip")[0].childNodes[0].nodeValue;
				 if(concatedinfo == "") {
					 concatedinfo = postalcode;
			   }else{
			concatedinfo+= " "+postalcode;
			   }
			}		  
            document.getElementById("shippingCity").innerHTML=concatedinfo;
			document.getElementById("shippingAddressCity").value=city;
			document.getElementById("shippingAddressState").value=state;
			document.getElementById("shippingAddressPostalCode").value=postalcode;		
			changeshippingmethod(xmlDoc); 		
			
			if (xmlDoc.getElementsByTagName("id")[0] != null) { 
				document.getElementById("populateAddressid").value=xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
			}

			if (xmlDoc.getElementsByTagName("formatphonenumber")[0] != null &&  xmlDoc.getElementsByTagName("formatphonenumber")[0].childNodes[0] !=null ) { 
				document.getElementById("shippingPhone").innerHTML = xmlDoc.getElementsByTagName("formatphonenumber")[0].childNodes[0].nodeValue;
				document.getElementById("shippingAddressPhoneNumber").value=xmlDoc.getElementsByTagName("formatphonenumber")[0].childNodes[0].nodeValue;
			}else{
                   document.getElementById("shippingPhone").innerHTML ="";
				   document.getElementById("shippingAddressPhoneNumber").value="";
			}

			if (xmlDoc.getElementsByTagName("nickname")[0] != null && xmlDoc.getElementsByTagName("nickname")[0].childNodes[0] !=null ) { 
				document.getElementById("shippingAddressNickName").value=xmlDoc.getElementsByTagName("nickname")[0].childNodes[0].nodeValue;
			}else{
				document.getElementById("shippingAddressNickName").value="";
			}

			if (xmlDoc.getElementsByTagName("country")[0] != null && xmlDoc.getElementsByTagName("country")[0].childNodes[0] !=null ) { 
				document.getElementById("shippingAddressCountry").value=xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue;
			}else{
				document.getElementById("shippingAddressCountry").value="";
			}

	}
  }

  /*Usage at Shippingandbilling --> billingsection: This function is used to show the address by selecting from the dropdown without refreshing the page*/
  function displaySelectedBillingAddress(addressId,path){
		if (addressId == 'select') {
		  return false;
		}
		var billingAddressValues = document.usershippingandbillingform.elements['billingaddress'];
		var elem =  billingAddressValues.options;
		for(var j=1; j<=elem.length;j++) {
			if(elem[j]!=null && elem[j] != 'undefined'){
				if(elem[j].value=='No Nickname Available' || elem[j].value==document.getElementById("shippingAddressNickName").value) {
				  billingAddressValues.remove(j);		
				}
			}
		}
		if(document.getElementById("checkSameasAhippingFromReadable") != null) {
		 document.getElementById("checkSameasAhippingFromReadable").checked=false; 
		 document.getElementById('sameasshipping').value = false;  
		}
		document.getElementById("billingaddressOwnerId").value=addressId;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		}
		var url="/" + path+"/checkout/includes/populatebillinginfo.jsp";
		url+="?addressId="+addressId;
		xmlHttp.onreadystatechange=populatebillingAddressValue;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
  }

  /*This function is used to print the values from responseobject to page side*/
  function populatebillingAddressValue() {	 
	if (xmlHttp.readyState == 4) {
		var responseObject = xmlHttp.responseXML;
		if(responseObject != null){
			responseObject = xmlHttp.responseXML.documentElement;
		}
		if(responseObject != null) {
			var xmlDoc = responseObject;
            var fname= "";
			var lname = "";
			var concatname = "";
			if (xmlDoc.getElementsByTagName("firstName")[0] != null && xmlDoc.getElementsByTagName("firstName")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressFirstName").value=xmlDoc.getElementsByTagName("firstName")[0].childNodes[0].nodeValue;
				 fname = xmlDoc.getElementsByTagName("firstName")[0].childNodes[0].nodeValue;
				 concatname= fname;
			}

			if (xmlDoc.getElementsByTagName("lname")[0] != null && xmlDoc.getElementsByTagName("lname")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressLastName").value=xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
				 lname = xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
				 if(concatname == "") {
					 concatname = lname
				 }else{
						 concatname+=" "+lname
					 }
				}
				else {
				document.getElementById("billingAddressLastName").value= "";
			}
			document.getElementById("billingFirstname").innerHTML=concatname;	
			}	
			    var address1 = "";
				var address2 = "";
				var concataddress = ""; 
			if (xmlDoc.getElementsByTagName("address1")[0] != null && xmlDoc.getElementsByTagName("address1")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressAddressOne").value=xmlDoc.getElementsByTagName("address1")[0].childNodes[0].nodeValue;
			    address1 = xmlDoc.getElementsByTagName("address1")[0].childNodes[0].nodeValue;
			}
				
				if (xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue != 'undefined') { 
					address2 = xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue;
					document.getElementById("billingAddressAddressTwo").value=xmlDoc.getElementsByTagName("address2")[0].childNodes[0].nodeValue;
				} else {				 
				  address2 = "undefined";
				  document.getElementById("billingAddressAddressTwo").value="";
				}
				if (address2 == 'undefined') {
				  concataddress = address1; 
				} else if(address1 != "") {
				   concataddress = address1 + ", " + address2;	
				}			
	            document.getElementById("billingAddressAddressOne").value=address1				
				document.getElementById("billingAddress1").innerHTML=concataddress;	

				var city = "";
				var state =  "";
				var postalcode = ""; 
				var concatedinfo = "";				
			if (xmlDoc.getElementsByTagName("city")[0] != null && xmlDoc.getElementsByTagName("city")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressCity").value=xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
				 city = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
				concatedinfo = city;
			}
			  if (xmlDoc.getElementsByTagName("state")[0] != null && xmlDoc.getElementsByTagName("state")[0].childNodes[0]!= null ) { 
				 state = xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue;
				document.getElementById("billingAddressState").value=xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue;
				if(city == ""){
					concatedinfo = state;
				}else{
                        concatedinfo+=","+state;
				}
			}
			
			if (xmlDoc.getElementsByTagName("zip")[0] != null && xmlDoc.getElementsByTagName("zip")[0].childNodes[0] != null){ 
				 postalcode = xmlDoc.getElementsByTagName("zip")[0].childNodes[0].nodeValue;
				document.getElementById("billingAddressPostalCode").value=xmlDoc.getElementsByTagName("zip")[0].childNodes[0].nodeValue;
				if(concatedinfo ==""){
					concatedinfo=postalcode;
				}else{
					concatedinfo+=" "+postalcode;
				}
			}
				document.getElementById("billingCity").innerHTML=concatedinfo;
				document.getElementById("billingAddressCity").value=city;
				document.getElementById("billingAddressState").value=state;
				document.getElementById("billingAddressPostalCode").value=postalcode;

			if (xmlDoc.getElementsByTagName("id")[0] != null) { 
				document.getElementById("populatebillingAddressid").value=xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
			}
			if (xmlDoc.getElementsByTagName("formatphonenumber")[0] != null &&  xmlDoc.getElementsByTagName("formatphonenumber")[0].childNodes[0] != null) { 
				document.getElementById("billingPhone").innerHTML = xmlDoc.getElementsByTagName("formatphonenumber")[0].childNodes[0].nodeValue;
				document.getElementById("billingAddressPhoneNumber").value=xmlDoc.getElementsByTagName("phonenumber")[0].childNodes[0].nodeValue;
			}else{
                  document.getElementById("billingPhone").innerHTML = "";
				  document.getElementById("billingAddressPhoneNumber").value="";

			}
			if (xmlDoc.getElementsByTagName("formatphonenumber")[0] != null &&xmlDoc.getElementsByTagName("phonenumber")[0].childNodes[0] != null ) {
				document.getElementById("billingAddressPhoneNumber").value=xmlDoc.getElementsByTagName("phonenumber")[0].childNodes[0].nodeValue;
			}
			else{
				document.getElementById("billingAddressPhoneNumber").value="";
			}
			if (xmlDoc.getElementsByTagName("nickname")[0] != null && xmlDoc.getElementsByTagName("nickname")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressNickName").value=xmlDoc.getElementsByTagName("nickname")[0].childNodes[0].nodeValue;
			}else{
				document.getElementById("billingAddressNickName").value="";
			}
            
             if (xmlDoc.getElementsByTagName("editlink")[0] != null && xmlDoc.getElementsByTagName("editlink")[0].childNodes[0] != null ) { 
               var isEditLink = xmlDoc.getElementsByTagName("editlink")[0].childNodes[0].nodeValue;
			   var trimlink =  trim(isEditLink)			  
               if( trimlink  == 'true'){
                 document.getElementById("editbillinglinkid").style.display='block';
			   }else{
                 document.getElementById("editbillinglinkid").style.display='none';
			   }

			 }

			if (xmlDoc.getElementsByTagName("country")[0] != null && xmlDoc.getElementsByTagName("country")[0].childNodes[0] != null ) { 
				document.getElementById("billingAddressCountry").value=xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue;
			}else{
				document.getElementById("billingAddressCountry").value="";
			}

			
		}
  }
  
  /*Usage at Shippingandbilling --> shippingsection: This function is used to autochange the shippingmethods by selecting the state from dropdown*/	
  function autochangeshippingmethods(state, path){
		uncheckSameAsShippingCheckBox();
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		}
		var url="/" + path+"/checkout/includes/autochangeshippingmethods.jsp";
		url+="?state="+state;
		xmlHttp.onreadystatechange=populateshippingmethods;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
  }

  /*This function is used to instainate the responseObject*/
  function populateshippingmethods() {
	 if (xmlHttp.readyState==4) {
		var responseObject = xmlHttp.responseXML;
		if(responseObject != null) {
			responseObject = xmlHttp.responseXML.documentElement;
		}
		if(responseObject != null) {
			var xmlDoc = responseObject;
			changeshippingmethod(xmlDoc);
		}
	 }
  }

  /*This function is used to print the values from responseobject to page side*/
    function changeshippingmethod(xmlDoc) {
	 var availableShippingMethods = xmlDoc.getElementsByTagName("shippingMethod");
	 for (i=0;i<availableShippingMethods.length;i++) {
		 var id = availableShippingMethods[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
		 var checked = availableShippingMethods[i].getElementsByTagName("checked")[0].childNodes[0].nodeValue;
		 var disabled = availableShippingMethods[i].getElementsByTagName("disabled")[0].childNodes[0].nodeValue;
		 var shipMethod = document.getElementById(id);
		 if(checked == 'true') {
			shipMethod.checked = true;
			showOrhidePaymentsection(id);
		 } else {
			shipMethod.checked = false;
		 }
		 if(disabled == 'true') {
			shipMethod.disabled = true;
		 } else {
			shipMethod.disabled = false;
		 }
	 }
  }



  /*Usage at Shoppingcart --> estimatesection: This function is used to shows the estimated tax and shippingandhandling charges*/	
  function estimateShipping(action) {      
		var selectedMethods=document.getElementsByName("selecteMethod");
		var j=0; 
		var selectedMethod;	 
		for(var i=0; i<selectedMethods.length; i++) {    
		  if(selectedMethods[i].checked==true) {
			selectedMethod=selectedMethods[i].value;                       
			j=j+1;
		  }
		}
		var isEstimatedTax =false;
		if(action=="estimateTax") { 
		  isEstimatedTax=true;
		}
		var  zipCode = document.shippingInfoForm["zipCode"].value; 
		var state =  document.shippingInfoForm["state"].value; 
		window.document.estimateNShippingMethodsForm["zipCode"].value=zipCode;
		window.document.estimateNShippingMethodsForm["state"].value=state; 
		window.document.estimateNShippingMethodsForm["shippingMethod"].value=selectedMethod;
		window.document.estimateNShippingMethodsForm["estimateTax"].value="true";
		window.document.estimateNShippingMethodsForm["/atg/commerce/order/purchase/CartModifierFormHandler.zipCode"].value=zipCode;    
		window.document.estimateNShippingMethodsForm["/atg/commerce/order/purchase/CartModifierFormHandler.estimateShipping"].value="submit";
		window.document.estimateNShippingMethodsForm.submit();
  }

	function estimateShippinGnTax(action) {
		 
			var selectedMethods=document.getElementsByName("selecteMethod");		
			var selectedMethod;	 
			for(var i=0; i<selectedMethods.length; i++) {    
			  if(selectedMethods[i].checked==true) {
				selectedMethod=selectedMethods[i].value;                       
				
			  }
			}		
			var isEstimatedTax =false;
			if(action=="estimateTax") { 
			  isEstimatedTax=true;
			}
			var  zipCode = document.shippingInfoForm["zipCode"].value; 
			var state =  document.shippingInfoForm["state"].value; 
			window.document.estimateNShippingMethodsForm["zipCode"].value=zipCode;
			window.document.estimateNShippingMethodsForm["state"].value=state;
			/* This if block is required when smartsolution products are added to the cart then shipping methods section is disabled  */
			if(selectedMethod != null && selectedMethod != undefined) {
				window.document.estimateNShippingMethodsForm["shippingMethod"].value=selectedMethod;
			}
			window.document.estimateNShippingMethodsForm["estimateTax"].value="true";
			window.document.estimateNShippingMethodsForm["/atg/commerce/order/purchase/CartModifierFormHandler.zipCode"].value=zipCode;    
			window.document.estimateNShippingMethodsForm["/atg/commerce/order/purchase/CartModifierFormHandler.estimateShipping"].value="submit";
			window.document.estimateNShippingMethodsForm.submit();
	  }
	  /*shipping and tax function for EMEA only - deployed 8/10 at midnight - MJD*/
	  function estimateShippinGnTaxEMEA(action) {
		 
			var selectedMethods=document.getElementsByName("selecteMethod");		
			var selectedMethod;	 
			for(var i=0; i<selectedMethods.length; i++) {    
			  if(selectedMethods[i].checked==true) {
				selectedMethod=selectedMethods[i].value;                       
				
			  }
			}		
			var isEstimatedTax =false;
			if(action=="estimateTax") { 
			  isEstimatedTax=true;
			}			
			/* This if block is required when smartsolution products are added to the cart then shipping methods section is disabled  */
			if(selectedMethod != null && selectedMethod != undefined) {
				window.document.estimateNShippingMethodsForm["shippingMethod"].value=selectedMethod;
			}
			window.document.estimateNShippingMethodsForm["estimateTax"].value="true";
			window.document.estimateNShippingMethodsForm["/atg/commerce/order/purchase/CartModifierFormHandler.estimateShipping"].value="submit";
			window.document.estimateNShippingMethodsForm.submit();
	  }


  /*Usage at Shippingandbilling --> shippingsection: This function is used to show and hide the payment and billing section*/	
  function showOrhidePaymentsection(shippingMethodId) {
	var billingNPaymentSection = document.getElementById('info-container');
	var shipmentIds;
	// shippingFreeOrderInfoIds is a global variable defined in shippingandbilling.jsp holding the info of shipping and free order information
	for(var i=0; i<shippingFreeOrderInfoIds.length; i++) {  
		shipmentIds = shippingFreeOrderInfoIds[i].split(":");
		if(shipmentIds[0] == shippingMethodId) {
			if(shipmentIds[1] == 'true') {
				billingNPaymentSection.style.display='none';
			} else {
				billingNPaymentSection.style.display='block';
			}	
			break;
		}
	 }
  }


  /*Usage at Shippingandbilling --> billingsection: This function is used to uncheck the SameAsShippingCheckBox*/	
  function uncheckSameAsShippingCheckBox() {
	if (document.getElementById('checkSameasAhipping') != null) {
	  document.getElementById('checkSameasAhipping').checked=false;
	}
	if (document.getElementById('checkSameasAhippingFromReadable') != null) {
	  document.getElementById('checkSameasAhippingFromReadable').checked=false;
	}
	document.getElementById('sameasshipping').value=false;
  }

  /*Usage at Shoppingcart --> estimatesection: This function is used to auto select and enable,disable the shipping methods by selecting the state from the drop down*/	
 
    function changeState(path, selectedShippingMethod){
		var state =  document.shippingInfoForm["state"].value; 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		}

		var url=path+"/cart/includes/autoEnableShippingmethod.jsp";
		url+="?state="+state+"&shippingMethod="+selectedShippingMethod;
		
		xmlHttp.onreadystatechange=populateShippingmethods;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
  }



  /*This function is used to instainate the responseObject*/
  function populateShippingmethods(){
	 if (xmlHttp.readyState == 4){
		var responseObject = xmlHttp.responseXML;
		if(responseObject != null){
			responseObject = xmlHttp.responseXML.documentElement;
		}
		if(responseObject != null){
			var xmlDoc = responseObject;
			autoEnableShippingmethod(xmlDoc);
		}
	 }
  }


  /*Usage at Shoppingcart --> estimatesection: This function is used to auto select and enable,disable the shipping methods by selecting the state from the drop down*/	

  function autoEnableShippingmethod(xmlDoc) {
      
       var shipmethods = xmlDoc.getElementsByTagName("shippingmethod");
      
	   for (var i =0;i<shipmethods.length;i=i+1)
       {
          var shipmethod = shipmethods[i];
		  var methodname = shipmethod.getElementsByTagName("methodname")[0].childNodes[0].nodeValue;
		  var count = shipmethod.getElementsByTagName("count")[0].childNodes[0].nodeValue;
		  var disabled = shipmethod.getElementsByTagName("disabled")[0].childNodes[0].nodeValue;
		  var checked = shipmethod.getElementsByTagName("checked")[0].childNodes[0].nodeValue;
		  var elementid = "radio"+count;
		 
		  if(disabled == 'true')
		  document.getElementById(elementid).disabled = true;
		  if(disabled == 'false')
          document.getElementById(elementid).disabled = false;
		  if(checked == 'true')
		  document.getElementById(elementid).checked = true;
		  if(checked == 'false')
          document.getElementById(elementid).checked = false;
       }

  }

  /*Usage at Shippingandbilling --> shippingandbilling section: This function is used to handle edit and addnewaddress funcationalites*/			
  function submit(action, addresstype) {
		
		if (action == 'editaddress' || action == 'newcreditcard' ) {
			
		  document.getElementById("editshippingAddressFirstName").value = document.getElementById("shipingAddressFirstName").value;
		  document.getElementById("editshippingAddressLastName").value = document.getElementById("shippingAddressLastName").value;	
		  document.getElementById("editshippingAddressAddressOne").value = document.getElementById("shippingAddressAddressOne").value;
		  document.getElementById("editshippingAddressAddressTwo").value = document.getElementById("shippingAddressAddressTwo").value;
		  document.getElementById("editshippingAddressCity").value = document.getElementById("shippingAddressCity").value;
		  document.getElementById("editshippingAddressState").value = document.getElementById("shippingAddressState").value;	
		  document.getElementById("editshippingAddressPostalCode").value = document.getElementById("shippingAddressPostalCode").value;
		  document.getElementById("editshippingAddressPhoneNumber").value = document.getElementById("shippingAddressPhoneNumber").value;			
		  document.getElementById("editshippingAddressNickName").value = document.getElementById("shippingAddressNickName").value;
		  
		  document.getElementById("editbillingAddressFirstName").value = document.getElementById("billingAddressFirstName").value;
		  document.getElementById("editbillingAddressLastName").value = document.getElementById("billingAddressLastName").value;	
		  document.getElementById("editbillingAddressAddressOne").value = document.getElementById("billingAddressAddressOne").value;
		  document.getElementById("editbillingAddressAddressTwo").value = document.getElementById("billingAddressAddressTwo").value;
		  document.getElementById("editbillingAddressCity").value = document.getElementById("billingAddressCity").value;
		  document.getElementById("editbillingAddressState").value = document.getElementById("billingAddressState").value;	
		  document.getElementById("editbillingAddressPostalCode").value = document.getElementById("billingAddressPostalCode").value;
		  document.getElementById("editbillingAddressPhoneNumber").value = document.getElementById("billingAddressPhoneNumber").value;			
		  document.getElementById("editbillingAddressNickName").value = document.getElementById("billingAddressNickName").value;
		  if (document.getElementById("populateAddressid") != null && document.getElementById("populateAddressid").value != "null" && document.getElementById("populateAddressid").value != "") {
			document.getElementById("editshippingaddressOwnerId").value = document.getElementById("populateAddressid").value;
		  } else {
			document.getElementById("editshippingaddressOwnerId").value = document.getElementById("shippingaddressOwnerId").value;
		  }
		  if (document.getElementById("populatebillingAddressid") != null && document.getElementById("populatebillingAddressid").value != 'null' && document.getElementById("populatebillingAddressid").value != "") {
			document.getElementById("editbillingaddressOwnerId").value = document.getElementById("populatebillingAddressid").value;
		  } else {
			document.getElementById("editbillingaddressOwnerId").value = document.getElementById("billingaddressOwnerId").value;
		  }

		  if (addresstype == 'newcreditcard') {
			   document.getElementById("creditCardNumber").value = "";
			   document.getElementById("creditCardHolderName").value = "";
			   document.getElementById("creditCardExpirationYear").value = "";
			   document.getElementById("creditCardExpirationMonth").value = "";
		  }
		} else if (addresstype == 'billing') {
		   if (action == 'addnewaddress') {
			  document.getElementById("editshippingAddressFirstName").value = document.getElementById("shipingAddressFirstName").value;
			  document.getElementById("editshippingAddressLastName").value = document.getElementById("shippingAddressLastName").value;	
			  document.getElementById("editshippingAddressAddressOne").value = document.getElementById("shippingAddressAddressOne").value;
			  document.getElementById("editshippingAddressAddressTwo").value = document.getElementById("shippingAddressAddressTwo").value;
			  document.getElementById("editshippingAddressCity").value = document.getElementById("shippingAddressCity").value;
			  document.getElementById("editshippingAddressState").value = document.getElementById("shippingAddressState").value;	
			  document.getElementById("editshippingAddressPostalCode").value = document.getElementById("shippingAddressPostalCode").value;
			  document.getElementById("editshippingAddressPhoneNumber").value = document.getElementById("shippingAddressPhoneNumber").value;			
			  document.getElementById("editshippingAddressNickName").value = document.getElementById("shippingAddressNickName").value;
			  if (document.getElementById("populateAddressid") != null && document.getElementById("populateAddressid").value != "null" && document.getElementById("populateAddressid").value != "") {
				document.getElementById("editshippingaddressOwnerId").value = document.getElementById("populateAddressid").value;
			  } else {
				document.getElementById("editshippingaddressOwnerId").value = document.getElementById("shippingaddressOwnerId").value;
			  }
		   }
		} else if (addresstype == 'shipping') {
			if (action == 'addnewaddress') {
			  document.getElementById("editbillingAddressFirstName").value = document.getElementById("billingAddressFirstName").value;
			  document.getElementById("editbillingAddressLastName").value = document.getElementById("billingAddressLastName").value;	
			  document.getElementById("editbillingAddressAddressOne").value = document.getElementById("billingAddressAddressOne").value;
			  document.getElementById("editbillingAddressAddressTwo").value = document.getElementById("billingAddressAddressTwo").value;
			  document.getElementById("editbillingAddressCity").value = document.getElementById("billingAddressCity").value;
			  document.getElementById("editbillingAddressState").value = document.getElementById("billingAddressState").value;	
			  document.getElementById("editbillingAddressPostalCode").value = document.getElementById("billingAddressPostalCode").value;
			  document.getElementById("editbillingAddressPhoneNumber").value = document.getElementById("billingAddressPhoneNumber").value;			
			  document.getElementById("editbillingAddressNickName").value = document.getElementById("billingAddressNickName").value;
			  if (document.getElementById("populatebillingAddressid") != null && document.getElementById("populatebillingAddressid").value != 'null' && document.getElementById("populatebillingAddressid").value != "") {
				document.getElementById("editbillingaddressOwnerId").value = document.getElementById("populatebillingAddressid").value;
			  } else {
				document.getElementById("editbillingaddressOwnerId").value = document.getElementById("billingaddressOwnerId").value;
			  }
			}
		} 
		 for (i=1; i<=4; i++) {
			var selectedCardType = document.getElementById("clickedRadioButton"+i);
			if(selectedCardType!=null && selectedCardType.checked) {
			  document.getElementById("editcreditCardType").value = selectedCardType.value;	
			}
		}
		
		if (document.getElementById("creditCardId") != null){
		document.getElementById("editcreditCardId").value = document.getElementById("creditCardId").value;	
		}
		document.getElementById("editcreditCardNumber").value = document.getElementById("creditCardNumber").value;	
		document.getElementById("editcreditCardHolderName").value = document.getElementById("creditCardHolderName").value;
		document.getElementById("editcreditCardExpirationMonth").value = document.getElementById("creditCardExpirationMonth").value;
		document.getElementById("editcreditCardExpirationYear").value = document.getElementById("creditCardExpirationYear").value;
		if (document.getElementById("creditCardTransientNumber") != null) {
		  document.getElementById("editcreditCardTransientNumber").value = document.getElementById("creditCardTransientNumber").value;
		}
		if (document.getElementById("checkShippingAddress") != null) {
		 document.getElementById("issaveShippingAddressChecked").value = document.getElementById("checkShippingAddress").checked;
		}
		if (document.getElementById("checkBillingAddress") != null) {
			document.getElementById("issaveBillingAddressChecked").value = document.getElementById("checkBillingAddress").checked;
		}
		if (document.getElementById("checkSameasAhipping") != null) {
		 document.getElementById("issameasshippingChecked").value = document.getElementById("checkSameasAhipping").checked;	
		}
		if (document.getElementById("checkSameasAhippingFromReadable") != null) {
		 document.getElementById("issameasshippingChecked").value = document.getElementById("checkSameasAhippingFromReadable").checked;	
		}
		if (document.getElementById("saveCreditCard") != null) {
			document.getElementById("editSaveCreditCard").value = document.getElementById("saveCreditCard").checked;
		}
		
		document.getElementById("isShippingEditable").value = document.getElementById("isShippingEditableMode").value;	
		document.getElementById("isBillingEditable").value = document.getElementById("isBillingEditableMode").value;
		document.getElementById("addressType").value = addresstype;	
		document.getElementById("editableAddress").value = action;	
		document.editAddressForm.submit();
  }

/*setCVVTextLength Usage at Shippingandbilling --> used in returnuserpaymentinfo.jsp*/
 function setCVVTextLength(){

   if (document.getElementById("creditCardType") != null) {
	   var ccardType = document.getElementById("creditCardType").value;
		if (ccardType == 'americanExpress' || ccardType == 'amex') {
			document.getElementById("cardVerificationNumber").setAttribute('maxLength',4);
		} else {
			document.getElementById("cardVerificationNumber").setAttribute('maxLength',3);
		}
   }

 }

 /*displaySelectedCreditCard Usage at Shippingandbilling --> used in returnusercreditcards.jsp*/
 function displaySelectedCreditCard(creditCardId, path) {
	document.getElementById("creditCardId").value=creditCardId;
	xmlHttp=GetXmlHttpObject();		 
	if (xmlHttp==null){
	alert ("Your browser does not support AJAX!");
	return;
	}
	
	var url=path+"/checkout/includes/populatecreditcardinfo.jsp";
	url+="?creditCardId="+creditCardId;
	xmlHttp.onreadystatechange=populateCreditCardValue;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
 }

 function populateCreditCardValue() {

	if (xmlHttp.readyState == 4) {		
		var responseObject = xmlHttp.responseXML;			
		if(responseObject != null) {
			responseObject = xmlHttp.responseXML.documentElement;
		}
		if(responseObject != null) {
			var xmlDoc = responseObject;
			var creditcards = xmlDoc.getElementsByTagName("creditCard");
			var creditcard = creditcards[0];	  			 						
			var creditcardId = creditcard.getElementsByTagName("creditCardId")[0].childNodes[0].nodeValue;
			var maskCardNumber = creditcard.getElementsByTagName("creditCardNumber")[0].childNodes[0].nodeValue;
			var cardType = creditcard.getElementsByTagName("creditCardType")[0].childNodes[0].nodeValue;	
			var holderName = creditcard.getElementsByTagName("creditCardHolderName")[0].childNodes[0].nodeValue;
			var expMonth = creditcard.getElementsByTagName("creditCardExpirationMonth")[0].childNodes[0].nodeValue;
			var expYear = creditcard.getElementsByTagName("creditCardExpirationYear")[0].childNodes[0].nodeValue;
			document.getElementById("creditCardId").value = creditcardId;
			document.getElementById("creditCardNumber").value = maskCardNumber;
			document.getElementById("creditCardType").value = cardType;
			document.getElementById("creditCardHolderName").value = holderName;
			document.getElementById("creditCardExpirationMonth").value = expMonth;
			document.getElementById("creditCardExpirationYear").value = expYear;
			document.getElementById("cardVerificationNumber").value = "";
			if (cardType == 'americanExpress' || cardType == 'amex') {
				document.getElementById("cardVerificationNumber").setAttribute('maxLength',4);
			} else {
				document.getElementById("cardVerificationNumber").setAttribute('maxLength',3);
			}
		}
	}
 }

	/* this function resets the text field in globsl header to default value "Keyword, SKU, etc".*/	
	 function resetKeyword(SearchCategory,searchCategory){
		  
			var question = document.getElementById('ques')
				
		if(SearchCategory == '')
			{
				if(searchCategory == '')
					question.value="Keyword, SKU, etc."
			}
		
		if(question.value == '')
			{
				question.value="Keyword, SKU, etc."
			}
		}
	/* this function submits the form when user selects any category from global header*/	
	 	  function submitSearchFormHeader(formObj,contextPath)
			   {
				  setTheSearchForHeaderCategory();	
				  var category = document.getElementById('category');
				  setFormAction(category.value,formObj,contextPath);
			   }

  /* this function sets the form default CategoryName in the  global header*/	
 function setTheSearchForHeaderCategory() {
				 var category = document.getElementById('category');
				  var categoryValue = category.value;
  			    if (categoryValue == null || categoryValue.length  < 3 ) {
				  category.value='Products';
				  categoryValue = category.value;
				 } 
				  if (categoryValue == 'Products' || categoryValue =='Solutions' || categoryValue=='Global Services' || categoryValue == 'Software' ||  categoryValue =='Support & Downloads'  || categoryValue == 'About Lexmark' )
				  {
					  category.value=categoryValue;
				  } else {
				  category.value='Products';
				  }
		 }
	  /* this function submits the form when user presses Enter keyword in the text field from global header*/	
	 	  function submitSearchFormHeaderonEnter(formObj,e,contextPath)
			   {
				   if (e.keyCode == 13)
				   {
					   setTheSearchForHeaderCategory();
					   var category = document.getElementById('category');
					   setFormAction(category.value,formObj,contextPath);
					   return false;
				   }
			   }         


	  /* this function invoks while click on close link at No valid address overlay*/
	function saveThisAddressFormNoValidAddress(param) {
	  if (param != null) {
		  if (param == 'addnewaddress') {
			document.addnewaddress.submit();
		  } 
		  if (param == 'notsaveThisAddress') {
			document.notsavethisaddressform.submit();
		  }
		  if (param == 'closeoverlay') {
			document.closeoverlayform.submit();
		  }
	  }
	}

	  /* this function invoks while click on close link at valid address overlay*/
	function saveThisAddressForm(param) {
	  if (param != null) {
		  if (param == 'saveThisAddress') {
		   omnitureAddress('yesuse')
			document.savethisaddressform.submit();
		  } 
		  if (param == 'notsaveThisAddress') {
		   omnitureAddress('nokeep')
		 	document.notsavethisaddressform.submit();
		  }
		  if (param == 'closeoverlay') {
		 	document.closeoverlayform.submit();
		  }
	  }
	}
	/*This function is used to invoke the omnitrue function*/
	function omnitureAddress(param){ 	   
	    var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
   if(isOmnitureRequired =="yes"  && typeof(s)==="object"){ 
	 if(param!= null){
	    if(param  =='yesuse'){	
	     s.prop2='yes,use';		 	   
	    var s_code=s.t();
		if(s_code)document.write(s_code);		
	   }
	 if(param  =='nokeep'){	  
	    s.prop2='no,keep';		 	   	
		var s_code=s.t();
		if(s_code)document.write(s_code);
	   }
	 }
	 }
	}
	/* This function submits the Ink&Toner search form when user clicks on find button*/
	function submitSearchForm(formObj)
	{
		var ques = document.getElementById('question');
		var pModel = document.getElementById('printerModel');
		ques.value = pModel.options[pModel.selectedIndex].value;
		formObj.submit();
	}
	/* This function is invoked when user clicks remove option link for promotion in cart page. */ 
	function removePromotion(promoId) {
		var pomoStatusId = promoId;
		document.removePromoForm["/atg/commerce/promotion/CouponFormHandler.removablepromoStatusId"].value = pomoStatusId;
		document.removePromoForm.submit();
	}
// to set focus...
	function setSelectionRangeCB(el, selectionStart, selectionEnd)
	{
		if (el.setSelectionRange) {
			el.focus();
			el.setSelectionRange(selectionStart, selectionEnd); //Moz/Gecko Proprietary
		} else if (el.createTextRange) {
			var range = el.createTextRange();
			range.collapse(true);
			range.moveEnd('character', selectionEnd);
			range.moveStart('character', selectionStart);
			range.select();
		}
	}
	
//search related form submission functions
	
	function navigationSearch(question,searchcategory,searchcategoryID)
	{
		document.allproductResultsForm.selectedCategory.value=searchcategory;
		document.allproductResultsForm.selectedCategoryId.value=searchcategoryID;
		document.allproductResultsForm.question.value=question;
		document.allproductResultsForm.submit();
	}
	
	function facetSearch(trail,priceFacet)
	{
		if(priceFacet != '') {
		document.facetSearchForm.changedFacetValue.value=priceFacet;
		}
		document.facetSearchForm.addFacetTrail.value=trail;
		document.facetSearchForm.submit();
	}

	function noOfItemsPerPageSearch(noOfItemsPerPage,trail,viewAll)
	{
		if(viewAll == 'View all items') 
		{
			document.facetSearchForm.viewAll.value="true";
		} 
		document.facetSearchForm.pageSize.value=noOfItemsPerPage;
		facetSearch(trail,'');
	}

	function paginationSearch(pageNum)
	{
		document.paginationSearchForm.goToPage.value=pageNum;
		document.paginationSearchForm.submit();
	}

	function sortingSearch(sortOption)
	{
			if(sortOption == 'AtoZ')
			{
				document.facetSearchForm.sortOrder.value='ascending';
				document.facetSearchForm.sort.value='strprop';
				document.facetSearchForm.sortProp.value='marketingName';

			} else if(sortOption == 'ZtoA')
					{
						document.facetSearchForm.sortOrder.value='descending';
						document.facetSearchForm.sort.value='strprop';
						document.facetSearchForm.sortProp.value='marketingName';
					} else if(sortOption == 'HightoLow')
							{
								document.facetSearchForm.sortOrder.value='descending';
								document.facetSearchForm.sort.value='numprop';
								document.facetSearchForm.sortProp.value='price';
							} else if(sortOption == 'LowtoHigh')
								{
									document.facetSearchForm.sortOrder.value='ascending';
									document.facetSearchForm.sort.value='numprop';
									document.facetSearchForm.sortProp.value='price';
									}else if (sortOption == 'Relevance') {
											document.facetSearchForm.sortOrder.value='';
											document.facetSearchForm.sort.value='';
											document.facetSearchForm.sortProp.value='';
											}
		document.facetSearchForm.sortOption.value=sortOption;
		document.facetSearchForm.submit();
	}

	function staticNoOfItemsPerPageSearch(noOfItemsPerPage,viewAll)
	{
		if(viewAll == 'View all items') 
		{
			document.staticSearchForm.viewAll.value="true";
		} 
		document.staticSearchForm.pageSize.value=noOfItemsPerPage;
		document.staticSearchForm.submit();
	}


	function staticPaginationSearch(pageNum)
	{
		document.staticSearchForm.pageNum.value=pageNum;
		document.staticSearchForm.submit();
	}

	function trim(catName) 
	{
		return catName.replace(/^\s*/, '').replace(/\s*$/, '');
    }
	function submitNoResultsFormOnEnter(formObj,e,countryCode)
    {
	   if (e.keyCode == 13)
	   {
		  var category = formObj.elements['searchCategory'];
		  var categoryDispName = trim(category.value);
		  setFormAction(categoryDispName,formObj,countryCode); 
		  return false;
	   }
    }
	function submitSearchFormNoResultsPage(formObj,countryCode)
	{
	    var category = formObj.elements['searchCategory'];
	    var categoryDispName = trim(category.value);
	    setFormAction(categoryDispName,formObj,countryCode); 
	}
	function setFormAction(selectedCategory,formObj,countryCode) 
	{
		if(selectedCategory == 'Products' ||  selectedCategory == 'All Products')
		   {
				formObj.action = "/" + countryCode+'/search/allproductresults.jsp';
		   } else if(selectedCategory == 'Ink &amp; Toner' || selectedCategory == 'Ink & Toner') 
					{
						formObj.action="/" + countryCode+'/search/inktoner_finder.jsp';
					} else if (selectedCategory == 'Solutions' || selectedCategory == 'Global Services' ||  selectedCategory == 'About Lexmark' || selectedCategory == 'Software' ) 
							{
								formObj.action="/" + countryCode+'/search/static/staticcontentresults.jsp';
							} else {
									formObj.action="/" + countryCode+'/search/categoryResultsMain.jsp';
									}
		formObj.submit();
	}
function submitSearchFormHeaderonCLick(catName,formObj,contextPath)
	{
	document.getElementById('category').value=trim(catName);
	setFormAction(catName,formObj,contextPath);
	 return false;
	}			  

function submitFilterResultsForm(obj){					
	document.getElementById('productTypeId').value= obj;		
	document.getElementById('shopbyTypeForm').submit();
}

function submitAllProductsFilterResultsForm(obj){	
	document.getElementById('productTypeId').value= obj;		
	document.getElementById('allProductsShopbyTypeForms').submit();
}

/* This function is for submitting new address content in account management. */ 
function newAddressFormSubmit(formAction){

	document.getElementById("handleAction").value=formAction;   
	document.addnewaddressform.submit();
} 

/* This function is for editing address in account management. */ 
function editAddressFormSubmit(formAction){
    
		document.getElementById("handleAction").value=formAction;   
		document.editaddressform.submit();
   }  

function submitSearchFormHeaderonEnterKey(e,url,countryCode)
{
 if (e.keyCode == 13)
		{
		submitSearchFormHeader(url,countryCode);
		return false;
		}
}

function submitSearchFormHeader(url, countryCode)
		   {			  
			  var catagoryTrimValue ="";
			  var searchTerm = document.getElementById('searchid');
			  if( document.getElementById('category') != null) {
				 var category = document.getElementById('category');
				 var categoryValue =category.value;
				 catagoryTrimValue = categoryValue.trim();
				 if (isEmpty(catagoryTrimValue)) {
					catagoryTrimValue = "Products";
				 }
			  } else {
				  catagoryTrimValue = "Products";
			  }
			window.location = "http://"+url+ "/" + countryCode +"/search/includes/search_intermediate_navigation.jsp?category=" +catagoryTrimValue+ "&searchTerms=" + encodeURIComponent(searchTerm.value);   
		   }


function isEmpty(str) {	
    return (!str || /^\s*$/.test(str));
}

if(document.getElementById("searchid") != null) { 
	document.getElementById("searchid").value= '<dsp:valueof bean="QueryFormHandler.searchRequest.question" />';
}
function removeMiniCart() {
  document.getElementById('mini-cart').style.display = 'none';
}

function focusFirstName() {
  document.getElementById('firstName').focus();
};


/* Ajax call to fetch the billing address */
function ajaxCallToFetchBillingAddress(contextPath, addressId) {

	if(addressId=='') {
		document.getElementById("billingAddressInfo").innerHTML='';
	} else {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		}
		var url=contextPath+"/account/creditcards/include/populateaddress.jsp";
		url+="?addressId="+addressId;
		xmlHttp.onreadystatechange=populateBillingAddress;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

/* function to assign the fetched billing address to display in the page */
function populateBillingAddress() {
	if (xmlHttp.readyState==4 && xmlHttp.status==200) {
		document.getElementById("billingAddressInfo").innerHTML=xmlHttp.responseText;
	}
}

/* Ajax call to fetch the Country Divisons */
function ajaxCallToFetchCountryDivisons(contextPath, countryId) {

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	alert ("Your browser does not support AJAX!");
	return;
	}
	var url=contextPath+"/account/addressbook/include/populateCountrySubDivisions.jsp";
	url+="?countryId="+countryId;
	xmlHttp.onreadystatechange=populateCountrysubDivisions;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/* function to assign the fetched subdivisions to display in the page */
function populateCountrysubDivisions() {
	if (xmlHttp.readyState==4 && xmlHttp.status==200) {
		var responseXML=xmlHttp.responseXML;
		if(responseXML!=null) {
			documentElement = xmlHttp.responseXML.documentElement;
		}
		if(documentElement!=null) {
			
			var xmlDoc=xmlHttp.responseXML.documentElement;
			document.getElementById("stateLabel").innerHTML = xmlDoc.getElementsByTagName("subdivisiontype")[0].childNodes[0].nodeValue;
			var subdivisions=xmlDoc.getElementsByTagName("subdivision");
			var stateDropDownObj = document.getElementById("state");
			var j =1;
			if(subdivisions.length > 0) {
				for (i=0;i<subdivisions.length;i++) {						 
					stateDropDownObj.options[j]=new Option(subdivisions[i].getElementsByTagName("divisionname")[0].childNodes[0].nodeValue,subdivisions[i].getElementsByTagName("divisioncode")[0].childNodes[0].nodeValue);
					j++;
				}
			}
		} 
		
	}
	
}


/*This function is used to call configure smart solution*/  
function configureSmartProduct(partNumber) {
	document.configureSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.partNumber"].value=partNumber;
    window.document.configureSmartForm["/atg/commerce/order/purchase/CartModifierFormHandler.configureSmartSolutions"].value="submit";
    document.configureSmartForm.submit();
}


//function to clear inputs on selecting credit cards 
function resetCreditCardInputtypes(myId){
	
	if (myId.value == 'americanExpress' || myId.value == 'amex') {
		document.getElementById('securitycode').setAttribute('maxLength',4);
			    			
	} else {
		document.getElementById('securitycode').setAttribute('maxLength',3);
				
	}
	resetcreditcardval();

  }
  			
  function resetcreditcardval()
	{
		document.getElementById('cardnumber').value = "";
		document.getElementById('cardholdername').value = "";  
		document.getElementById('month').selectedIndex = "Month"
		document.getElementById('year').selectedIndex = "Year"
		document.getElementById('securitycode').value="";
		document.getElementById('defaultpayment').checked = false;
	}
	
	/*This function is used for watch demo of the product details page*/  
	function omnitureWatchDemo(productname){
	      var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
		if(isOmnitureRequired =="yes" && typeof(s)==="object"){ 
		 s.eVar8=productname+" Demo View";
		 s.events="watch demo";
		 invokeOmniture(); 
		}
	}
	
	/* function is used for home page inkToner finder */
	function omnitureHomePageInkTonerFinder(){
	    var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
		if(isOmnitureRequired =="yes" && typeof(s)==="object"){ 
	      s.eVar3="ink toner finder home page" ;
		 invokeOmniture();
		}
		
	}
	
	/* This Function is used for slots  */
	function omnitureSlots(param){	
	 var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
     if(isOmnitureRequired =="yes" && typeof(s)==="object"){ 
		s.channel="promotions";
		s.events="event4";	
		s.prop1=param;
		var s_code=s.t();
		if(s_code)document.write(s_code);
	 }	
	}	
	/* This Function is used for minibanner  */
	function omniturePencilUnit(){	
	 omnitureSlots("MiniBanner");	
	}
	
	/*This function is used to call additem to order function for  addTo cart overlay*/  
function addToCartItems() {
	omnitureAddTocartOverlay();
    document.addToCartOverlayForm.submit();
}

/*This functions is used to prepare s.product string */  
 function omnitureAddTocartOverlay(){
    var prods=document.getElementsByName("skuAndProductIds");	
	var prodMarketingNames = document.getElementsByName("marketingName");
	var prodCategoryNames = document.getElementsByName("categoryName");	
	var prodPrices= document.getElementsByName("price");
    var finalString; 	
	 var j=0;
	 var qty;
	 var ciPrice=0;
	  var marketingName; 
	  var categoryName;
	 
    for(var i=0; i<prods.length; i++){
	  if(prods[i].checked==true){	
	  qty = document.getElementById(prods[i].value.substr(0,prods[i].value.indexOf("|"))).value;
	  ciPrice=qty*prodPrices[i].value;
	   marketingName=prodMarketingNames[i].value.replace(/,/g, " ");
	   categoryName=prodCategoryNames[i].value.replace(/&/g," ");
	  if(finalString==undefined){
	     finalString=categoryName+";"+marketingName+";"+qty+";"+ciPrice;
		}
		else{
		 finalString= finalString+","+categoryName+";"+marketingName+";"+qty+";"+ciPrice;
		 }		
	  	 j=j+1;
	  }
    }
	callOmniture(finalString);	
 } 
 /*This functions is used to send informtion to omniture after adding item to cart*/  
 function callOmniture(param){
 var isOmnitureRequired = document.getElementById("omnitureRequiredId").value;
  if(isOmnitureRequired =="yes" && typeof(s)==="object"){  
	 var omniturecartEvent = document.getElementById("omnitureCartEvent").value; 
	   s.events=omniturecartEvent;
       s.products=param;
	   invokeOmniture();
	}
	}	
 
 /*This functions is used to send informtion to omniture after adding item to cart in home page*/ 
	function omnitureAddTocartHomePage(productId,skuId){ 	
	  omnitureAddTocart(productId);
	window.document.addToCartFromHomePage["/atg/commerce/order/purchase/CartModifierFormHandler.productId"].value=productId;
	window.document.addToCartFromHomePage["/atg/commerce/order/purchase/CartModifierFormHandler.quantity"].value=1;
   window.document.addToCartFromHomePage["/atg/commerce/order/purchase/CartModifierFormHandler.catalogRefIds"].value=skuId;
	window.document.addToCartFromHomePage["/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrder"].value="submit";
	 document.addToCartFromHomePage.submit();	 	 
 }
 
  /*This functions is used to invoke omniture function*/ 
function invokeOmniture(){
  if (typeof(s)==="object"){
    s.prop4=document.getElementById("omnitureLanguage").value;
    var s_code=s.t(); 
    if(s_code)document.write(s_code);
  }
}
 
   //Validating the AddressLine1 & AddressLine2
	function moveOnMax(field1,field2,errorMsgId) {
					if(field2 != null) {
									if(field1.value.length >= 35) {
													document.getElementById(errorMsgId).style.display = 'block';
													field2.focus();
									}
					} else {
									if(field1.value.length >= 35) {
													document.getElementById(errorMsgId).style.display = 'block';                                                                  
									}                                                              
					}
	}

	function searchSmartsolutionByPrinter(url)
	{	
		var pModel = document.getElementById('printerModel');
		url = url + "&question=" + encodeURIComponent(pModel.options[pModel.selectedIndex].value);
		window.location = url;
	}
	
	function searchInktonerByKeywordOrPrinter(url,searchBy)
	{	
		var question;
		if(searchBy == 'keyword')
		{
			question = document.getElementById('searchTextBox').value;
		} else if(searchBy == 'Printer') 
			{
				var pModel = document.getElementById('printerModel');
				question = pModel.options[pModel.selectedIndex].value;
			}
		
		url = url + "&question=" + encodeURIComponent(question);
		window.location = url;
	}

	function sortSearch(url,sortOption)
	{
		if(sortOption == 'AtoZ')
		{
			url = url + '&sortOrder=ascending&sort=strprop&sortProp=marketingName';

		} else if(sortOption == 'ZtoA')
				{
					url = url + '&sortOrder=descending&sort=strprop&sortProp=marketingName';
				} else if(sortOption == 'HightoLow')
						{
							url = url + '&sortOrder=descending&sort=numprop&sortProp=price';
						} else if(sortOption == 'LowtoHigh')
								{
									url = url + '&sortOrder=ascending&sort=numprop&sortProp=price';
								} else if (sortOption == 'Relevance') 
									{
										url = url + '&sortOrder=&sort=&sortProp=';
									}
		url = url + '&sortOption=' + sortOption;
		refreshPage(url);
	}

	function refreshPage(url)
	{
		window.location = url;
	}

	function itemsPerPageSearch(url,pageSize,seletedText) 
	{
		if(seletedText == 'View all items') 
		{
			url = url + '&viewAll=true';
		} 
		url = url + '&pageSize=' + pageSize;
		refreshPage(url);
	}
	
/**
 * Switch to this page in another language
 *   <link rel="alternate" hreflang="fr" href="url-of-french-page"/>
 **/	
function changeLanguage(lang) {
  var url = $('link[hreflang="'+lang+'"]').attr('href');
  if (!url) {
    var contxt = document.location.pathname.split('/');
    if (contxt.length > 1) {
	if (contxt[1].length == 2) { // /CA/en/
	   url = "/"+ contxt[1] + "/" + lang;
	} else if (contxt[1].length == 5) { // /en_CA/
	   url = document.URL.split(contxt[1]).join(lang+"_"+contxt[1].substr(3,2));	
	}
    } else {
	url="#";
    }
  }
  window.location.href=url;
}

function submitGlobalSearchFromAllProducts(url)
    {  
      var question = document.getElementById('searchTextBox').value;
        url = url + "&question=" + encodeURIComponent(question);
        window.location = url;
}

/*This function is used to display/hide the cvv number text box*/	 
		 function enableCvvNumber(checkBoxObj) {
			var saveBillingCheckBoxObj = document.getElementById("checkBillingAddress");
			if(saveBillingCheckBoxObj != null && saveBillingCheckBoxObj.type == 'checkbox') {
			 	if(checkBoxObj.checked == true) {
			 		saveBillingCheckBoxObj.checked = true;
			 		document.getElementById("saveBillingAddress").value=true;
			 		if (document.getElementById("billingAddressNickNameFragment") != null) {
						document.getElementById("billingAddressNickNameFragment").style.display = 'block';
					}
			 	}		 	
			 }			
		 }

                  /*This function is used to enable the save creadit card checkbox*/          
                  function enableCvvNumberOnDefault(){
                     var saveCCchkboxObj  = document.getElementById("saveCreditCard");
                     if(saveCCchkboxObj != null) {
                        saveCCchkboxObj.checked = true;
                        enableCvvNumber(saveCCchkboxObj)
                        }                                         
                  }

		function paymentsectionCheck(shippingMethodId,shippingPrice) {
			var billingNPaymentSection = document.getElementById('info-container');
			var totalPrice=document.getElementById('totalprice').value;
			var shipmentIds;
			// shippingFreeOrderInfoIds is a global variable defined in shippingandbilling.jsp holding the info of shipping and free order information
			for(var i=0; i<shippingFreeOrderInfoIds.length; i++) {  
				shipmentIds = shippingFreeOrderInfoIds[i].split(":");
				if(shipmentIds[0] == shippingMethodId) {
					if(shipmentIds[1] == 'true') {
						billingNPaymentSection.style.display='none';
					} else {
						billingNPaymentSection.style.display='block';
					}	
					break;
			}
	 }
	 if(shippingPrice > 0.0){
			enableCvvNumberOnDefault()				
	 }
	 if(totalPrice > 0.0) {
			enableCvvNumberOnDefault()
	 }
	 }



