/** COMPLETE CHECKOUT CART JS **/
//Paypal2 changes
function findStores(form)
	{
	   var zip = document.getElementById("zipCode1").value;
	   var isAuto="";
	   var finalView='PickUpStoreModalView';
 		var ret = validateZip(zip);   
	    if(ret == false){ 
	    	document.getElementById("errorBox");
			err.style.display= 'block';
			return false;
	    }
	    	if(document.checkout.isAutoItem !=null){
	    		if(document.checkout.isAutoItem.value=='true'){
	    			isAuto="SAC";
	    		}else{
	    			isAuto="N_SAC";
	    		}
	    	}
	    	var findStoresForZip = {
			    method: 'GET',
			    asynchronous: true,
			    postBody: '',
			    onSuccess: function(t) {
			    var response = eval("(" +t.responseText+ ")");
			    if (response.success == 'true') {
			    	if(response.isStoreEmpty=='Y'){
			    		var err = document.getElementById("errorBox");
			    		err.style.display= "";
	       		 		err.innerHTML ="<p>We have no stores within the range of the zip code you have entered offering in-store pickup. You can enter a different ZIP code or return to your cart to select a shipping option, instead.</p>";
					}else{
						document.getElementById("zipCode").value=zip;
						document.getElementById("go").value = "go";	
						document.checkout.action = PATH_SSL;  
						document.getElementById("isFromModalWindow").value="Y";
          				document.checkout.url = "OrderItemDisplayView";
          				//	fnCheckAutoRenewal();
          				document.checkout.submit();
			    	}
			    }
			    },
			    onFailure: function(t) {
			    	err = document.getElementById("errorBox");  
	        		err.style.display= "";
	       		 	err.innerHTML ="<p>Your Request could not be completed, please try again.</p>";
	       		}
			};	
			
			 var url = 'SelectStoresCmd?zipCode='+zip+
			 				'&isAjax=true'+
		    				'&storeId='+storeId+
		    				'&cataLogId='+document.checkout.catalogId.value+
		    				'&langId=-1'+
		    				'&URL='+url+
		    				'&sCriteria='+isAuto+
		    				'&finalView='+finalView+
		    				'&startFrom=0';
		     new searsAjaxBilling(url, findStoresForZip);  	  
	   		
	}
	
	function validateZip(zipStr) {
	    var ret = true;
	    if (zipStr.length != 5) {
	        ret = false;
	    } else {
	        ret = !isNaN(zipStr);
	    }
	    
	    if ( zipStr == null ) {
	        ret = false;
	    }    
	    return ret;
	}
	
	//Paypal2 changes


// this creates the cookie when called
 function fnAutoRenewalFlagUser(paramStoreId){


   		//Function for storing the auto renewal flag
	    if(document.getElementById("renew")){
		  var autoRenewal = document.getElementById("renew").checked;
		 	 setCookie('autoRenewalFlag'+paramStoreId,autoRenewal);

		  }
    }

		// this deletes the cookie when called
	function Delete_Cookie( name, path, domain ) {
			var date = new Date();
            		date.setTime(date.getTime()+(-1*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
			document.cookie = name+"="+""+expires+"; path=/";

	}

	function showArrivalMessage(fulfillmentChannel, parentOrderItemId) {
		if(fulfillmentChannel == "HFM") {
			fulfillmentChannel = "TW";
		}
		if(fulfillmentChannel == "SRES") {
			fulfillmentChannel = "SPU";
		}
		
		var divCheckRadio;
		var pThisRadio;
		if(fulfillmentChannel == "VRES" || fulfillmentChannel == "CRES" || fulfillmentChannel == "KDRES" ||fulfillmentChannel == "DRES"||fulfillmentChannel == "KRES"){
			divCheckRadio = document.getElementById(parentOrderItemId+"_SPU_msg");
			pThisRadio = document.getElementById(parentOrderItemId+"_SPU");
		} else {
			divCheckRadio = document.getElementById(parentOrderItemId+"_"+fulfillmentChannel+"_msg");
			pThisRadio = document.getElementById(parentOrderItemId+"_"+fulfillmentChannel);
		}
		if(pThisRadio!=null)
		{
			var vPd_msg_wrap      = pThisRadio.parentNode.getElementsByTagName('div')[0];

		}
			
		if (typeof divCheckRadio != 'undefined' && divCheckRadio != null) {
			if(TrimString(divCheckRadio.innerHTML).length == 0)
			{
		
				divCheckRadio.style.display = "none";
				if(vPd_msg_wrap!=null)
				{
					vPd_msg_wrap.style.display = "none";
				}
	
			}else{
				
				divCheckRadio.style.display = "block";
				
				if(vPd_msg_wrap!=null)
				{
					vPd_msg_wrap.style.display = "block";
				}
				if(!(document.getElementById('checkLayaway') != null && document.getElementById('checkLayaway').checked == true)){
					$('.layawaybutton').hide();
			}
				
		}
    }
    }


	function getValuesInArray(arrayValue) {
		return arrayValue.split(':');
	}
	function openPopUpForSpecialFinancing(url){
		 window.open(url,"SpecialFinance","location=no,resizable=yes,scrollbars=yes,toolbar=yes,toolbar=no,status=no,menubar=0");
		}
		
		function isAnyArrivalSelected(){
			var totalItem = document.getElementById("totalParentItem").innerHTML;
			for(var i=0; i <totalItem; i++) {   
	   			var current = i+1;
	   			var count=0;
	     	 	var orderItemId = document.getElementById("EachOrderItemId_"+current).innerHTML;
	     	 	orderItemId = TrimString(orderItemId);
	     	 		var arrivalMethodElements = document.getElementsByName(orderItemId+"_arrival_method_1");
						if(typeof(arrivalMethodElements) != "undefined") {
							var arrivalMethodsLength = arrivalMethodElements.length;
								for(var k=0; k < arrivalMethodsLength; k++){
									checkedValue = arrivalMethodElements[k].checked;
									if(checkedValue) {
										count++;
										}
									}
									if(count==0 && arrivalMethodsLength != 0){
										alert("Please select applicable Arrival Method for all the items");
										return false;
									}
						}	
	     	 }
	     	 return true;
		}
		
		
	function checkForInvalidItemsToCheckOut() {
		if(document.errorMessageForm && document.errorMessageForm.fromPage == null){
			if(document.errorMessageForm.errorCatIds != null) {
				var errorCatIds = getValuesInArray(document.errorMessageForm.errorCatIds.value);
				var allCatIds = getValuesInArray(document.errorMessageForm.allCatentryIdsList.value);
				var allOrderItemIds = getValuesInArray(document.errorMessageForm.allOrderItemIdList.value);

				for(var i = 0; i < allCatIds.length; i++) {
					for(var j =0; j < errorCatIds.length; j++) {
						if(allCatIds[i] == errorCatIds[j]) {

							var arrivalMethodElements = document.getElementsByName(allOrderItemIds[i]+"_arrival_method_1");

							if(typeof(arrivalMethodElements) != "undefined") {

								var arrivalMethodsLength = arrivalMethodElements.length;
								for(var k=0; k < arrivalMethodsLength; k++){
									checkedValue = arrivalMethodElements[k].checked;
									if(!checkedValue) {
										var arrivalMethod = arrivalMethodElements[k].value;
											alert("Please select applicable Arrival Method for all the items");
											return false;
									}
								}
							}
						}
					}
				}
			}
			return true;
		}
		else{
			return true;
		}
	}
//changes added for paypal2
	function CheckOutSubmission(payPal){
		var SpuItems ='N';
		var LayawayItems ='N';
		if(payPal=='Y'){
			document.checkout.payPal.value=payPal;
		}
		if(payPal=='N'){
			document.checkout.payPal.value=payPal;
		}
		 if(checkForInvalidItemsToCheckOut()) {
		 	if(isAnyArrivalSelected()) {
			 var StoreId=document.checkout.storeId.value;
			 	var checkedValue = false;
		     	var totalItem = document.getElementById("totalParentItem").innerHTML;
				
		     	for(var i=0; i <totalItem; i++) {   
		   			var current = i+1;
		     	 	var orderItemId = document.getElementById("EachOrderItemId_"+current).innerHTML;
		     	 	orderItemId = TrimString(orderItemId);
		     	  	var arrivalMethod = '';
					var arrivalMethodElements = document.getElementsByName(orderItemId+"_arrival_method_1");
					if(arrivalMethodElements!=null) {
			     		if(typeof(arrivalMethodElements) != "undefined") {
							var arrivalMethodsLength = arrivalMethodElements.length;
							for(var j=0; j < arrivalMethodsLength; j++){
								checkedValue = arrivalMethodElements[j].checked;
								if(checkedValue) {
									arrivalMethod = arrivalMethodElements[j].value;
								}
							}
						}
						else {
							arrivalMethod = document.getElementById(orderItemId+"_arrival_method_1").value;
						}
					}
					if(arrivalMethod!=null && arrivalMethod!='') {
		     			document.getElementById(orderItemId+"_arrival_method").value = arrivalMethod;
			     		
			     		if(arrivalMethod=='SPU'){
			     		 SpuItems ='Y';
			     		 document.getElementById("selectedArrivalMethod").value=arrivalMethod;
			     		}
			     		if(arrivalMethod=='LAYAWAY'){
			     			LayawayItems='Y';
			     		}
			     		if(arrivalMethod == 'VGC'){
			     			var email = document.getElementById(orderItemId+"_email").value;
			     			if(email == ''){
			     				err = document.getElementById("errorMsg");
								err.style.display= "";
								err.innerHTML = "Recipients e-mail address needed. We cannot send an e-Gift Card without this information. Please enter the recipients e-mail address in the space provided below.";
								document.getElementById('product_'+orderItemId).style.display = "block";
			     				return;
			     			}
			     		}
			     	} 
		     	}
		     	fnCheckAutoRenewal();  
		     	var userType = getCookie("pickupStoreId"+storeId);
		     	
		     	var showModalWindow ='N';
		     	if(userType ==""){
			     	if(SpuItems =='Y' || LayawayItems=='Y'){
			     		showModalWindow = 'Y';
			     	}
		     	}
		     	
		     	if(SpuItems =='Y'&& (StoreId=='10151'||StoreId=='10152') && payPal=='Y'){
		     	
		     		showModalWindow = 'N';
			     	err = document.getElementById("errorMsg");
				    err.style.display= "";
					if(StoreId=='10151'){
					err.innerHTML ="We're not able to accept PayPal for KMART store pick up. Please select another payment method for your order";
					}
					if(StoreId=='10152'){
					err.innerHTML ="We're not able to accept PayPal for MYGOFER1 store pick up. Please select another payment method for your order";
					}
					return;
					
		     	}
		     	
		     	if(SpuItems =='Y'&& (StoreId=='10161')){
		     		showModalWindow = 'N';
		     	}
			     	if(document.getElementById("lwzip")!=null && document.getElementById("lwzip")!=""){
			    		document.getElementById("zipCode").value=document.getElementById("lwzip").value;
			    	}
		        document.checkout.action = PATH_SSL;  
	          	document.checkout.url = "OrderItemDisplayView";
	          //	fnCheckAutoRenewal();
	          	document.checkout.submit();
	          	
	          	}
			}
		}


function UpdateProductOption(form,url,count,name,itemType,parOrderItemId){

 		radio = document.getElementsByName(name);
		var i;
 		if(itemType == "Deluxe") {
 			var s="";
	 		for(i=0;i<radio.length;i++) {
	 			if(radio[i].checked)
				{
					var svalue=radio[i].value;
					var s=svalue+","+s;
				}
			}
		}else if(itemType == "Required"){
			var s="";
	 		for(i=0;i<radio.length;i++) {
	 			if(radio[i].checked)
				{
					var svalue=radio[i].value;
					var s=svalue+","+s;
					var poItemType="RA"+","+poItemType;
				}
			}
		}
		else{
			for(i=0;i<count;i++)
			{

				if(radio[i].checked)
				{
					var s=radio[i].value;
					break;
				}
				else
				{  
					var s="";

				}
			}
		}
	     document.ProductOptionForm.action=url;
	    if(itemType == "Deluxe") {
	      	document.ProductOptionForm.questionScimCode.value=s;
     		document.ProductOptionForm.delOrderItemId.value = parOrderItemId;
 	    }
 	    else if(itemType == "Required"){
			document.ProductOptionForm.pcatEntryId.value=s;
			document.ProductOptionForm.delOrderItemId.value = parOrderItemId; 
			document.ProductOptionForm.poItemType.value=poItemType; 
 	    }
	    else {
	     document.ProductOptionForm.pcatEntryId.value=s;
	     if(document.getElementById(parOrderItemId+"_"+itemType+"OrderItemId") != null) {
	     	document.ProductOptionForm.childOrderItemId.value = document.getElementById(parOrderItemId+"_"+itemType+"OrderItemId").innerHTML;

         }
        }
	     document.ProductOptionForm.submit();
	 }

	function RemoveDeluxeProductOption(url,parOrderItemId){
 		document.ProductOptionForm.action=url;
	  	document.ProductOptionForm.questionScimCode.value="";
     	document.ProductOptionForm.delOrderItemId.value = parOrderItemId;
	     document.ProductOptionForm.submit();
	 }

	function UpdateInstallationProductOption(url){

		var	poItemType = '';
		var poCatEntryId = '';
	    
 		/* For adding installation options */           
		$('.install_options input:checked').each(function(){
	     	poCatEntryIdTemp = this.id.split('_')[2];
    
    	 	if(this.id.split('_').length >= 4 && poCatEntryIdTemp != 'COST') {
        	    poCatEntryIdTemp = this.id.split('_')[2];
            	poItemTypeTemp = this.id.split('_')[6];
            
	        //    parentCatentryId = this.id.split('_')[3];
	         //   count = document.getElementById(parentCatentryId).innerHTML;
	         //   orderItemCount = "orderItemId_" + parentCatentryId; //CHANGED
		    //	orderItemId = document.getElementById(orderItemCount).innerHTML;	    
	         //   orderItemquantity = "qty_" + count;
	          //  var quantity = document.getElementById(orderItemquantity).innerHTML;
 
	             if(poCatEntryId == '') {
	                  poCatEntryId = poCatEntryIdTemp;
	               //   parOrderItemId = orderItemId;
	               //   poQuantity = quantity;
	                  poItemType = poItemTypeTemp;
	            }else {
	                  poCatEntryId = poCatEntryId + "," + poCatEntryIdTemp;
	             //     parOrderItemId = parOrderItemId + "," + orderItemId;
	              //    poQuantity = poQuantity + ',' + quantity;
	                  poItemType = poItemType + "," + poItemTypeTemp;
	            }
	       	 }
       	});
       	
		
	    document.ProductOptionForm.action=url;
	    document.ProductOptionForm.pcatEntryId.value=poCatEntryId;
	    document.ProductOptionForm.poItemType.value=poItemType;
	    document.ProductOptionForm.submit();
	 }
	 
	 function UpdateINandHAProductOption(url,count,name,itemType,parOrderItemId){

		var	poItemType = '';
		var poCatEntryId = '';
	    
 		/* For adding installation options */           
		$('.install_options input:checked').each(function(){
	     	poCatEntryIdTemp = this.id.split('_')[2];
    
    	 	if(this.id.split('_').length >= 4 && poCatEntryIdTemp != 'COST') {
        	    poCatEntryIdTemp = this.id.split('_')[2];
            	poItemTypeTemp = this.id.split('_')[6];
            
 
	             if(poCatEntryId == '') {
	                  poCatEntryId = poCatEntryIdTemp;
	              
	                  poItemType = poItemTypeTemp;
	            }else {
	                  poCatEntryId = poCatEntryId + "," + poCatEntryIdTemp;
	             
	                  poItemType = poItemType + "," + poItemTypeTemp;
	            }
	       	 }
       	});
       	radio = document.getElementsByName(name);
 		var i;
 		var s="";
       	for(i=0;i<count;i++)
		{
			if(radio[i].checked)
			{
				var s=radio[i].value;
				poItemType=poItemType+","+"HA";
				poCatEntryId=poCatEntryId+","+s;
				break;
			}
			else
			{  
				var s="";

			}
		}
		
	    if(document.getElementById(parOrderItemId+"_"+itemType+"OrderItemId") != null) {
	     	document.ProductOptionForm.childOrderItemId.value = document.getElementById(parOrderItemId+"_"+itemType+"OrderItemId").innerHTML;
		 }
		
	    document.ProductOptionForm.action=url;
	    document.ProductOptionForm.pcatEntryId.value=poCatEntryId;
	    document.ProductOptionForm.poItemType.value=poItemType;
	    document.ProductOptionForm.submit();
	 }
   function removeItem(url,ffmId,shipVantage) {

	  //delete the cookie for auto renwal
	    if(ffmId == shipVantage){

		    if(document.checkout.storeId.value != null){
	    		var  paramStoreId = document.checkout.storeId.value;
	    		delete_cookie ('autoRenewalFlag'+paramStoreId) ;
	   	 	}
	    }

	 var flag = document.getElementById("removeFlag").value;
	 if(flag == 'true') {
           //Add to cart button has been clicked once
           document.getElementById("removeFlag").value = "false";
           var r_url = unescape(url);
           document.location.href = r_url;

        }
     }

	function removeItemReview(url) {

	 var flag = document.getElementById("removeFlag").value;
	 if(flag == 'true') {
           //Add to cart button has been clicked once
           document.getElementById("removeFlag").value = "false";
	       document.location.href = url;

        }
     }
	function UpdateQuantityOnEnter(form,url,quantityValue,errorId,orderItemId,obj) {
		if(obj.keyCode == 13) {
		  	UpdateQuantity(form,url,quantityValue,errorId,orderItemId);
	 	}
	 	else {
	 		return true;
	 	}
	}
	 function UpdateQuantity(form,url,quantityValue,errorId,orderItemId) {
		var qty = document.getElementById(quantityValue).value;
		qty = qty.replace(/^\s+/g,'').replace(/\s+$/g,'');
	  	var lv_pattern = /^[0-9]+$/;
		var passed = lv_pattern.test(qty);

		if (!passed) {

		//document.getElementById("wrong").value = false;
			err = document.getElementById(errorId+"_"+orderItemId);
          	err.innerHTML = "The value in the Quantity field is not valid.The value must be numeric.  Please enter a numeric value and try again.";
           	err.className="errorBox";
	        quantityValue.focus();
	        quantityValue.select();
	        return false;
		}else{
			var u_url=unescape(url);
		    url = u_url + "&quantity_1=" +  qty;
		    document.location.href = url;
		}
     }


     function clearText(toName,fromName,message)	{
     	toName.value="";
    	fromName.value="";
    	message.value="";

     }

		function validation(toNameGift){
		if(toNameGift.length == 0){
			document.getElementById("errorMessage").innerHTML = '<p>The "To" and "From" fields must be filled in. Please try again.</p>';
			//alert('The "To" and "From" fields must be filled in. Please try again.');
			return false;

		}
		else
		{
			var StrRE1 = /^[a-zA-Z\s]+$/;
			var passed = StrRE1.test(toNameGift);
			if (!passed) {
			document.getElementById("errorMessage").innerHTML = '<p>The "To" and "From" fields cannot contain special characters or numbers. Please try again.</p>';
			//alert('The "To" and "From" fields cannot contain special characters or numbers. Please try again.');

			return false;

			}
			else
			{
				return true;
			}
		}
   }
   function validateMessage(message){

	if(message.length >48){
			alert("The message field can not have more than 48 characters");
			return false;
	}
	else if (message == ' - add your personal message - '){
			message.value = "";
			return true;
	}
	else{

		return true;
	}
   }

  //Special Instruction changes
  function checkIfSPUSelected(thisOrderItemId,thisObj,mOrderItemIdList)
  
  {
        
        var mRadio;
        var hasSPU ="NO";	
        var StoreId=document.checkout.storeId.value;
  	
  	  if(StoreId=='10161')
  	  {
  	 
  	  for (i=1;i<=mOrderItemIdList.length;i++)	
  		{			
  		mRadio=document.getElementsByName(mOrderItemIdList[i]+"_arrival_method_1");
  		radioLength = mRadio.length;
  			for(var j = 0; j < radioLength; j++) 
  			{
  				if(mRadio[j].checked && ("SPU" == mRadio[j].value || "VRES" == mRadio[j].value || "SRES" == mRadio[j].value || "CRES" == mRadio[j].value || "KDRES" == mRadio[j].value || "DRES" == mRadio[j].value|| "KRES" == mRadio[j].value || "LAYAWAY" == mRadio[j].value)) 
  					{
  						document.getElementById("specialInstructionDropdown").style.display = 'block'; 
  						hasSPU="YES";
  					}
  			}						
  
  		} 		
  	
  		if( hasSPU == "NO")
  			{
  			document.getElementById("specialInstructionDropdown").style.display = 'none'; 
  			}
        
        
        }
  
  
}

  function UpdateGiftWrap(url,form,parOrderItemId) {

       document.ProductOptionForm.action=url;
	   document.ProductOptionForm.to.value=form.to.value;
	   document.ProductOptionForm.from.value=form.from.value;

	   if(form.mess.value != ' - add your personal message - ' ) {
	       	document.ProductOptionForm.giftMessage.value=form.mess.value;
       } else {
        	document.ProductOptionForm.giftMessage.value = "";
       }
       document.ProductOptionForm.pcatEntryId.value = document.getElementById(parOrderItemId+"_giftwrap").innerHTML;

       if(document.getElementById(parOrderItemId+"_GWOrderItemId") != null) {
            document.ProductOptionForm.childOrderItemId.value = document.getElementById(parOrderItemId+"_GWOrderItemId").innerHTML;
       }
         document.ProductOptionForm.submit();
  }


    function showHide1(id,num,kind,what,to1,from1,message1,toName,fromName,message){

        toName.value= to1.value;
        fromName.value= from1.value;
        message.value=message1.value;
        var tID  = id + "_" + num + "_" + kind + "_table";

        var comment = to1 + "|" + from1 + "|" + message1;

        if(comment ==null) {
           toName.value="";
      	   fromName.value="";
      	   message.value="";
      	}
        else {
          showBox(tID);
        }
    }

	function setOrderItemId(parOrderItemId,childOrderItemId,itemType) {

		document.getElementById(parOrderItemId+"_"+itemType).innerHTML = childOrderItemId;

	}

	function checkSelectedOption(optionType, parOrderItemId, pOCatEntryId) {
		if(null != document.getElementById(optionType+"_"+parOrderItemId+"_"+pOCatEntryId+"_radio")){
			document.getElementById(optionType+"_"+parOrderItemId+"_"+pOCatEntryId+"_radio").checked = true;
			}
	}

	function checkSelectedOptionDeluxe(optionType, parOrderItemId) {
		var radio = document.getElementsByName("deluxeOptions_" + parOrderItemId);
		var i = 0;
		for(i=0;i<radio.length;i++) {
			var option = radio[i];
	   		option.checked=false;
		}
		var count=questionScimCodeArray.length;
		for(i=0;i<count;i++) {	
			if(null != document.getElementById(optionType+"_"+parOrderItemId+"_"+questionScimCodeArray[i]+"_radio")){
				document.getElementById(optionType+"_"+parOrderItemId+"_"+questionScimCodeArray[i]+"_radio").checked = true;
			}else {
				document.getElementById(optionType+"_"+parOrderItemId+"_"+questionScimCodeArray[i]+"_radio").checked = false;
			}
		}
	}
	function checkSelectedOptionForRequiredAccessories(optionType,parOrderItemId){
		var radio = document.getElementsByName("Required_" + parOrderItemId);
		var i = 0;
		for(i=0;i<radio.length;i++) {
			var option = radio[i];
	   		option.checked=false;
		}
		var count=requiredAccessoriesCatentryIdArray.length;
		for(i=0;i<count;i++) {	
			if(null != document.getElementById(optionType+"_"+parOrderItemId+"_"+requiredAccessoriesCatentryIdArray[i]+"_radio")){
				document.getElementById(optionType+"_"+parOrderItemId+"_"+requiredAccessoriesCatentryIdArray[i]+"_radio").checked = true;
			}else {
				document.getElementById(optionType+"_"+parOrderItemId+"_"+requiredAccessoriesCatentryIdArray[i]+"_radio").checked = false;
			}
		}
	}
	
	function unCheckSelectedOption(optionType, parOrderItemId) {
		radio = document.getElementsByName(optionType+"_"+parOrderItemId);
		var i;
		for(i=0;i<radio.length;i++)
		{
			if(radio[i].checked)
			{
				radio[i].checked = false;
				break;
			}
		}
	}

	function openPopUpForSecurityCode(url){
		 window.open(url,"SecurityCode","location=no,resizable=yes,scrollbars=yes,toolbar=yes,toolbar=no,status=no,menubar=0");
		}

	function prepopulateZipcode(){
		var storeId = document.getElementById("contextStoreId").innerHTML;
		cookieZipCode=getCookie('zipCode'+storeId);
		zipcodeVal(cookieZipCode);
		if(zipcodeVal(cookieZipCode)){
			document.zipForm.txtZipCode.value = cookieZipCode;
		}
	}

	function closeWindow(){
		showBox('shippingCalculatorForm');
		hideBox('shippingCalculatorResults');
		prepopulateZipcode();
	}

	function shippingCalculator(shippingURL) {
		if(typeof(preOrderFlag1) != 'undefined' && preOrderFlag1 != null) {
		shippingURL=shippingURL+"&preOrderFlag1="+preOrderFlag1+"&id="+orderRn;
		}
		window.open(shippingURL,null,"width=700,height=350,location=no,scrollbars=yes,toolbar=yes,toolbar=no,status=no,menubar=0");
	}
function checkForGiftWrap(orderItemId, fulfillmentChannel) {
	if(fulfillmentChannel == 'SPU' || fulfillmentChannel == 'SRES' || fulfillmentChannel == 'VRES'|| fulfillmentChannel == 'CRES'|| fulfillmentChannel == 'KDRES'|| fulfillmentChannel == 'DRES'|| fulfillmentChannel == 'KRES') {
		if(document.getElementById("GiftWrapNotAvailable_"+orderItemId) != null) {
			document.getElementById("GiftWrapNotAvailable_"+orderItemId).style.display = '';
			document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId).style.display = "none";
		}
		if(document.getElementById("GiftWrapAvailable_"+orderItemId) != null) {
			document.getElementById("GiftWrapAvailable_"+orderItemId).style.display = "none";
		}
		if(document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId) != null) {
			document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId).style.display = "none";
		}
	} else if(fulfillmentChannel == 'LW'){
		if(document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId) != null) {
			document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId).style.display = '';
			document.getElementById("GiftWrapNotAvailable_"+orderItemId).style.display = "none";
		}
		if(document.getElementById("GiftWrapAvailable_"+orderItemId) != null) {
			document.getElementById("GiftWrapAvailable_"+orderItemId).style.display = "none";
		}
	} else {
		if(document.getElementById("GiftWrapAvailable_"+orderItemId) != null) {
			document.getElementById("GiftWrapAvailable_"+orderItemId).style.display = '';
		}
		if(document.getElementById("GiftWrapNotAvailable_"+orderItemId) != null) {
			document.getElementById("GiftWrapNotAvailable_"+orderItemId).style.display = "none";
		}
		if(document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId) != null) {
			document.getElementById("GiftWrapNotAvailable_LW_"+orderItemId).style.display = "none";
	}
}
}

function checkForInstallation(orderItemId, fulfillmentChannel){
		if(fulfillmentChannel=='LW'){
		if(document.getElementById("LaywayISNotAvailable_"+orderItemId) != null) {
			document.getElementById("LaywayISNotAvailable_"+orderItemId).style.display = '';
				//document.getElementById(orderItemId+"_lwproductoptions").style.display = "none";
		}
		}else{
			if(document.getElementById("LaywayISNotAvailable_"+orderItemId) != null) {
			//document.getElementById(orderItemId+"_lwproductoptions").style.display = "block";
			document.getElementById("LaywayISNotAvailable_"+orderItemId).style.display = "none";
			
}
		}
		
}
function checkForHaulAway(orderItemId, fulfillmentChannel) {
	if(fulfillmentChannel == 'SPU' || fulfillmentChannel == 'SRES') {
		if(document.getElementById("HaulAwayNotAvailable_"+orderItemId) != null) {
			document.getElementById("HaulAwayNotAvailable_"+orderItemId).style.display = '';
		}
		if(document.getElementById("HaulAwayAvailable_"+orderItemId) != null) {
			document.getElementById("HaulAwayAvailable_"+orderItemId).style.display = "none";
		}  
	} else {
		if(document.getElementById("HaulAwayAvailable_"+orderItemId) != null) {
			document.getElementById("HaulAwayAvailable_"+orderItemId).style.display = '';
		}
		if(document.getElementById("HaulAwayNotAvailable_"+orderItemId) != null) {
			document.getElementById("HaulAwayNotAvailable_"+orderItemId).style.display = "none";
		}
	}
}
		
		
		
		
		
		
			
					function setExternalURL(url) {
						window.location = url;
					}


		function miniCartDisplay(){

			if(document.getElementById("MiniCart")){
				document.getElementById("MiniCart").style.display = 'none';
			}
		}

	function fnCheckAutoRenewal(){
    	//Function for storing the auto renewal flag
	    if(document.getElementById("renew") && document.getElementById("renew")!=null){
			var autoRenewal = document.getElementById("renew").checked;
			if(autoRenewal){
				document.checkout.autoRenewal.value = "true";
			}
			else{
				document.checkout.autoRenewal.value = "false";
			}
	    }
	    if(document.checkout.storeId.value != null){
	    	var  paramStoreId = document.checkout.storeId.value;
			delete_cookie ('autoRenewalFlag'+paramStoreId) ;
	    }
	}

	 function delete_cookie ( cookie_name )
	{

	  var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );
	  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	}
	function hideProductOption (productOptionTable)
	{

		openOptions();
	}

	function applyCouponCart(){
		var coupon = document.getElementById("couponCode");
		if (coupon && coupon.value == '') {
			var couponErrorDiv = document.getElementById("couponErrorDiv");
			couponErrorDiv.innerHTML = "Please enter a coupon code.";
			couponErrorDiv.style.display = "";
			return false;
		}
		document.getElementById("addOrRemoveFlag").value = "add";
		document.couponForm.action="ApplyOrRemovePromotionCodeCmdView";
		document.couponForm.url.value = "OrderItemDisplay";
		document.couponForm.fromCart.value = "true";
		document.couponForm.submit();
    }

    function removeCouponCart(){
		document.getElementById("addOrRemoveFlag").value = "remove";
		document.couponForm.action="ApplyOrRemovePromotionCodeCmdView";
		document.couponForm.url.value = "OrderItemDisplay";
		document.couponForm.fromCart.value = "true";
		document.couponForm.submit();
	 }


	
 //   function submitLoyaltyId(){
   // 	var rewardsCode = document.getElementById("prefered_number");
 //   	var rewardsErrorDiv = document.getElementById("rewardsErrorDiv");
 //   	alert("One");
//	    if (rewardsCode && rewardsCode.value == '') {
//			rewardsErrorDiv.innerHTML = "Please enter a Preferred Member#.";
//			rewardsErrorDiv.style.display = "";
//			return false;
//		}
//		if(!fnIsNumeric(rewardsCode.value)) {
//			rewardsErrorDiv.innerHTML = "Preferred Member# must be numeric.";
//			rewardsErrorDiv.style.display = "";
//			return false;
//		}
//		alert("Two");
   	
    	//if(!isValidLoyaltyId(rewardsCode.value)) {
    	//alert("3");
			//rewardsErrorDiv.innerHTML = "Please enter a valid Preferred Member#.";
			//rewardsErrorDiv.style.display = "";
			//return false;	
	    //}
//	    document.rewardsForm.action="SubmitLoyaltyIdCmdView";
//		document.rewardsForm.url.value = "OrderItemDisplay";
//		document.rewardsForm.LOYALTY_ID.value=rewardsCode.value;
//		document.rewardsForm.submit();	    
//   }

// Automotive Phase 2 - starts
function verifyNoAutoInstall(thisAutoInstall, thisObj, urlInstallDelete, imgPath, fromPage, fulfillName) {
	// Code added for Sears RnP start
	document.getElementById("RnpError").style.display = "none";
	// Code added for Sears RnP start end
	var isAutoInstall = ""+thisAutoInstall+"_isAutoInstallation";
	if (undefined != fulfillName && "" != fulfillName){
		urlInstallDelete = urlInstallDelete + "&fulfillName="+fulfillName;
	}
	if (document.getElementById(isAutoInstall) != undefined) {
		if ("true" == document.getElementById(isAutoInstall).value) {
			var trigger = "autoinstallation";
			var count = 0;
			showAutoErrorMsgPopUpBox (trigger, count, thisObj, urlInstallDelete, imgPath, fromPage, thisAutoInstall);
		}
	}
}

function revertArrival(trigger, thisObj, thisParam1, thisParam2) {
	var arrival = "";
	if ("autoinstallation" == trigger) {
		var myRadioButton = document.getElementsByName(thisObj);
		var myRadioButtonSize = myRadioButton.length;
		for (var i = 0; i < myRadioButtonSize; i++) {
			if ("spu" == thisParam1) {
				if (myRadioButton[i].checked) {
					myRadioButton[i].checked = false;
				}
			} else if ("cart" == thisParam1) {
				if ('SPU' == myRadioButton[i].value || 'VRES' == myRadioButton[i].value || 'CRES' == myRadioButton[i].value || 'KDRES' == myRadioButton[i].value || 'DRES' == myRadioButton[i].value || 'KRES' == myRadioButton[i].value|| 'LAYAWAY' == myRadioButton[i].value) {
					myRadioButton[i].checked = true;
					arrival = myRadioButton[i].value;
				} else {
					myRadioButton[i].checked = false;
				}
				checkForAutoInstallation(thisParam2, arrival);
			}
		}
	} else 	if ("arrSears" == trigger || "arrNonSears" == trigger) {
		var myRadioButton = document.getElementsByName(thisObj);
		var myRadioButtonSize = myRadioButton.length;
		for (var i = 0; i < myRadioButtonSize; i++) {
			if (myRadioButton[i].checked) {
				myRadioButton[i].checked = false;
			} else {
				// For VD or HFM
				if ('SPU' == myRadioButton[i].value || 'VRES' == myRadioButton[i].value || 'CRES' == myRadioButton[i].value || 'KDRES' == myRadioButton[i].value || 'DRES' == myRadioButton[i].value|| 'KRES' == myRadioButton[i].value|| 'LAYAWAY' == myRadioButton[i].value) {
					myRadioButton[i].checked = false;
				} else {
					myRadioButton[i].checked = true;
					arrival = myRadioButton[i].value;
				}
			}
		}
		checkForAutoInstallation(thisParam2, arrival);
		checkForGiftWrap(thisParam2, arrival);
	}
	curtainOverlay({closing:true});
}

function checkSelectedArrival(thisOrderItemId,thisObj,mOrderItemIdList,mURL,imgPath,fromPage)
{
	var mRadio;
	var radioLength;
	var idTobeRemoved="";
	var changeNonSAC = "false";
	var changeSAC = "false";
	var countNonSAC = 0;
	var countSAC = 0;
	for (i=1;i<=mOrderItemIdList.length;i++)
	{
		if (mOrderItemIdList[i] != thisOrderItemId && "true" == document.getElementById(thisOrderItemId+"_isAuto").value) {
			mRadio=document.getElementsByName(mOrderItemIdList[i]+"_arrival_method_1");
			radioLength = mRadio.length;
			for(var j = 0; j < radioLength; j++) {
				if ( "false" == document.getElementById(mOrderItemIdList[i]+"_isAuto").value) {
					if(mRadio[j].checked && ("SPU" == mRadio[j].value || "VRES" == mRadio[j].value || "SRES" == mRadio[j].value || "CRES" == mRadio[j].value || "KDRES" == mRadio[j].value || "DRES" == mRadio[j].value|| "KRES" == mRadio[j].value || "LAYAWAY" == mRadio[j].value)) {
						idTobeRemoved=idTobeRemoved+mOrderItemIdList[i]+"_";
						changeSAC = "true";
						document.checkout.isAutoItem.value="true";
						countSAC++;
					}
				 }
			}

		} else if (mOrderItemIdList[i] != thisOrderItemId && "false" == document.getElementById(thisOrderItemId+"_isAuto").value) {
			mRadio=document.getElementsByName(mOrderItemIdList[i]+"_arrival_method_1");
			radioLength = mRadio.length;
			for(var j = 0; j < radioLength; j++) {
				if ( "true" == document.getElementById(mOrderItemIdList[i]+"_isAuto").value) {
					if(mRadio[j].checked && ("SPU" == mRadio[j].value || "VRES" == mRadio[j].value || "SRES" == mRadio[j].value || "VRES" == mRadio[j].value || "CRES" == mRadio[j].value || "KDRES" == mRadio[j].value || "DRES" == mRadio[j].value|| "KRES" == mRadio[j].value || "LAYAWAY" == mRadio[j].value)) {
						idTobeRemoved=idTobeRemoved+mOrderItemIdList[i]+"_";
						changeNonSAC = "true";
						countNonSAC++;
					}
				 }
			}

		}
	}

	if (idTobeRemoved.length>0){
			idTobeRemoved=idTobeRemoved.substring(0,idTobeRemoved.length-1);
	}
	mURL=mURL+"&orderItemIdList="+idTobeRemoved+"&orderItemIdToSPU="+thisOrderItemId;

	if ("true" == changeNonSAC) {
		showAutoErrorMsgPopUpBox ('arrSears', countNonSAC, thisObj, mURL, imgPath, fromPage, thisOrderItemId);
	} else if ("true" == changeSAC) {
		showAutoErrorMsgPopUpBox ('arrNonSears', countSAC, thisObj, mURL, imgPath, fromPage, thisOrderItemId);
	}
}

function checkForAutoInstallation(orderItemId, fulfillmentChannel) {
	if(fulfillmentChannel != 'SPU' && fulfillmentChannel != 'SRES' && fulfillmentChannel != 'VRES' && fulfillmentChannel != 'CRES' && fulfillmentChannel != 'KDRES' && fulfillmentChannel != 'DRES' && fulfillmentChannel != 'KRES') {
		if(document.getElementById("autoinstallationNotAvailable_"+orderItemId) != null) {
			document.getElementById("autoinstallationNotAvailable_"+orderItemId).style.display = '';
		}
		if(document.getElementById("autoinstallationAvailable_"+orderItemId) != null) {
			document.getElementById("autoinstallationAvailable_"+orderItemId).style.display = "none";
		}
	} else {
		if(document.getElementById("autoinstallationAvailable_"+orderItemId) != null) {
			document.getElementById("autoinstallationAvailable_"+orderItemId).style.display = '';
		}
		if(document.getElementById("autoinstallationNotAvailable_"+orderItemId) != null) {
			document.getElementById("autoinstallationNotAvailable_"+orderItemId).style.display = "none";
		}
	}
}

function setPriceAuto(optionType,poCatEntryId,parCatEntryId,price) {
	var priceElm = "po_price_"+optionType+"_"+poCatEntryId+"_"+parCatEntryId;
	if (price < 0.01) {
		document.getElementById(priceElm).innerHTML = "Free";
	} else if ("roadhazard" == optionType) {
		document.getElementById(priceElm).innerHTML = "$"+formatCurrency(price)+"/tire";
	} else {
		document.getElementById(priceElm).innerHTML = "$"+formatCurrency(price)+" each";
	}
}

/////////////////////////////////////////////////////////////////////////////////
// Automotive Phase 2 - display messaging using curtainOverlay from global.js. //
/////////////////////////////////////////////////////////////////////////////////
function showAutoErrorMsgPopUpBox (trigger, count, thisObj, thisUrl, imgPath, fromPage, thisOrderItemId) {

	if ("autoinstallation" == trigger) {
		var newParam = "'"+trigger+"','"+thisObj+"','"+fromPage+"','"+thisOrderItemId+"'";
		var chDelivery = '<div id="nonSac">'
			chDelivery += '<h2>Change Arrival Method</h2>'
			chDelivery += '<p>Installation is only available with Install/Pick Up. To change the Arrival Method to Delivery, you must first click Delete Service to remove the service from your cart. Delivery costs may vary based on ZIP code.</p>'
			chDelivery += '<div class="actBtns"><a href=\'javascript:;\' onclick="revertArrival('+newParam+')"><img src="'+imgPath+'btn_cancel_blue_H24px.gif" alt="Cancel" class="cancelMod" /></a><a href="'+thisUrl+'"><img src="'+imgPath+'btn_delete_serv.gif" alt="Delete Service" /></a></div>'
			chDelivery += '</div>';

		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(chDelivery);
		$('.nonSac').html(chDelivery).show().centerOnScreen();
	} else if ("_ERR_FORMATCONFLICT_SAC" == trigger) {
		var addSac = '<div id="nonSac">'
			addSac += '<h2>Add to Cart</h2>'
			addSac += '<p>This item can only be picked up at a Sears Auto Center.</p>'
			addSac += '<p>'+count+'</p>'
			addSac += '<p>To keep all items in this order, choose Delivery instead of Pick Up for this item.</p>'
			addSac += '<div class="actBtns"><a href=\'javascript:;\' onclick="curtainOverlay({closing:true});"><img src="'+imgPath+'okay_btn.gif" alt="Okay" class="cancelMod" /></a></div>'
			addSac += '</div>';

		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(addSac);
		$('.nonSac').html(addSac).show().centerOnScreen();
	} else if ("_ERR_FORMATCONFLICT_NSAC" == trigger) {
		var addNonSac = '<div id="nonSac">'
			addNonSac += '<h2>Add to Cart</h2>'
			addNonSac += '<p>This item can only be picked up at a Sears store.</p>'
			addNonSac += '<p>'+count+'</p>'
			addNonSac += '<p>To keep all items in this order, choose Delivery instead of Pick Up for this item.</p>'
			addNonSac += '<div class="actBtns"><a href=\'javascript:;\' onclick="curtainOverlay({closing:true});"><img src="'+imgPath+'okay_btn.gif" alt="Okay" class="cancelMod" /></a></div>'
			addNonSac += '</div>';

		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(addNonSac);
		$('.nonSac').html(addNonSac).show().centerOnScreen();
	} else if ("arrNonSears" == trigger) {
		var newParam = "'"+trigger+"','"+thisObj+"','"+fromPage+"','"+thisOrderItemId+"'";
		var arrNonSears = '<div id="nonSac">'
			arrNonSears += '<h2>Arrival Method</h2>'
			arrNonSears += '<p>Your cart contains ' + count + ' item(s) that cannot be picked up at a Sears Auto Center.</p>'
			arrNonSears += '<p>To continue with your order, you should not change the arrival method. If you would like to pick up these items, you will need to delete them from your cart and place a separate order.</p>'
			arrNonSears += '<div class="actBtns"><a href=\'javascript:;\' onclick="revertArrival('+newParam+')"><img src="'+imgPath+'btn_dont_mk_change.gif" alt="Don\'t Make Change" class="cancelMod" /></a><a href="'+thisUrl+'"><img src="'+imgPath+'btn_remove_from_cart.gif" alt="Remove from Cart" class="cancelMod" /></a></div>'
			arrNonSears += '</div>';

		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(arrNonSears);
		$('.nonSac').html(arrNonSears).show().centerOnScreen();
	} else if ("arrSears" == trigger) {
		var newParam = "'"+trigger+"','"+thisObj+"','"+fromPage+"','"+thisOrderItemId+"'";
		var arrSears = '<div id="nonSac">'
			arrSears += '<h2>Arrival Method</h2>'
			arrSears += '<p>Your cart contains ' + count + ' item(s) that cannot be picked up at a Sears Stores.</p>'
			arrSears += '<p>To continue with your order, you should not change the arrival method. If you would like to pick up these items, you will need to delete them from your cart and place a separate order.</p>'
			arrSears += '<div class="actBtns"><a href=\'javascript:;\' onclick="revertArrival('+newParam+')"><img src="'+imgPath+'btn_dont_mk_change.gif" alt="Don\'t Make Change" class="cancelMod" /></a><a href="'+thisUrl+'"><img src="'+imgPath+'btn_remove_from_cart.gif" alt="Remove from Cart" class="cancelMod" /></a></div>'
			arrSears += '</div>';
		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(arrSears);
		$('.nonSac').html(arrSears).show().centerOnScreen();
	}
}

// This function is used when a mixed cart is left where both Automotive and Non Automotive have Store Pickup.
function correctAutoConflictedArrival(thisOrderItemId,mOrderItemIdList)
{
	var mRadio;
	var radioLength;
	for (i=1;i<mOrderItemIdList.length;i++)
	{
	if(document.getElementById(thisOrderItemId+"_isAuto") != null){
		if (mOrderItemIdList[i] != thisOrderItemId && "true" == document.getElementById(thisOrderItemId+"_isAuto").value) {
			mRadio=document.getElementsByName(mOrderItemIdList[i]+"_arrival_method_1");
			nRadio=document.getElementsByName(thisOrderItemId+"_arrival_method_1");
			radioLength = mRadio.length;
			var nRadioLen = nRadio.length;
			for(var j = 0; j < radioLength; j++) {
				if ((null!= document.getElementById(mOrderItemIdList[i]+"_isAuto")) && (null!= document.getElementById(mOrderItemIdList[i]+"_isAuto").value)&&("false" == document.getElementById(mOrderItemIdList[i]+"_isAuto").value)) {
					if(mRadio[j].checked && ("SPU" == mRadio[j].value ||"VRES" == mRadio[j].value ||"SRES" == mRadio[j].value || "CRES" == mRadio[j].value || "KDRES" == mRadio[j].value || "DRES" == mRadio[j].value || "KRES" == mRadio[j].value || "LAYAWAY" == mRadio[j].value)) {
						for(var k = 0; k < nRadioLen; k++) {
							if(nRadio[k].checked && ("SPU" == nRadio[k].value || "VRES" == nRadio[k].value||"SRES" == nRadio[k].value ||"CRES" == nRadio[k].value ||"KDRES" == nRadio[k].value ||"DRES" == nRadio[k].value||"KRES" == nRadio[k].value ||"LAYAWAY" == nRadio[k].value )) {
								if (j == 0 && radioLength == 2) {
									mRadio[j].checked = false;
									mRadio[1].checked = true;
									var divE1 = document.getElementById(mOrderItemIdList[i]+"_"+mRadio[1].value+"_msg");
									if (divE1 != null) {
										divE1.style.display = "block";
									}
									var divE2 = document.getElementById(mOrderItemIdList[i]+"_"+mRadio[0].value+"_msg");
									if (divE2 != null) {
										divE2.style.display = "none";
									}
								} else if (j == 1) {
									mRadio[j].checked = false;
									mRadio[0].checked = true;
									var divE1 = document.getElementById(mOrderItemIdList[i]+"_"+mRadio[1].value+"_msg");
									if (divE1 != null) {
										divE1.style.display = "none";
									}
									var divE2 = document.getElementById(mOrderItemIdList[i]+"_"+mRadio[0].value+"_msg");
									if (divE2 != null) {
										divE2.style.display = "block";
									}
								}
							}
						}
					}
				 }
			}
		} else if (mOrderItemIdList[i] != thisOrderItemId && "false" == document.getElementById(thisOrderItemId+"_isAuto").value) {
			mRadio=document.getElementsByName(mOrderItemIdList[i]+"_arrival_method_1");
			nRadio=document.getElementsByName(thisOrderItemId+"_arrival_method_1");
			radioLength = mRadio.length;
			var nRadioLen = nRadio.length;
			for(var j = 0; j < radioLength; j++) {
				if ((null!= document.getElementById(mOrderItemIdList[i]+"_isAuto")) && (null!= document.getElementById(mOrderItemIdList[i]+"_isAuto").value) && ("true" == document.getElementById(mOrderItemIdList[i]+"_isAuto").value)) {
					if(mRadio[j].checked && ("SPU" == mRadio[j].value ||"VRES" == mRadio[j].value|| "SRES" == mRadio[j].value || "CRES" == mRadio[j].value || "KDRES" == mRadio[j].value || "DRES" == mRadio[j].value || "KRES" == mRadio[j].value ||  "LAYAWAY" == mRadio[j].value)) {
						for(var k = 0; k < nRadioLen; k++) {
							if(nRadio[k].checked && ("SPU" == nRadio[k].value ||"VRES" == nRadio[k].value || "SRES" == nRadio[k].value ||"CRES" == nRadio[k].value ||"KDRES" == nRadio[k].value ||"DRES" == nRadio[k].value||"KRES" == nRadio[k].value ||"LAYAWAY" == nRadio[k].value)) {
								if (k == 0 && radioLength == 2) {
									nRadio[k].checked = false;
									nRadio[1].checked = true;
									var divE1 = document.getElementById(thisOrderItemId+"_"+nRadio[1].value+"_msg");
									if (divE1 != null) {
										divE1.style.display = "block";
									}
									var divE2 = document.getElementById(thisOrderItemId+"_"+nRadio[0].value+"_msg");
									if (divE2 != null) {
										divE2.style.display = "none";
									}
								} else if (k == 1 && radioLength == 2) {
									nRadio[k].checked = false;
									nRadio[0].checked = true;
									var divE1 = document.getElementById(thisOrderItemId+"_"+nRadio[1].value+"_msg");
									if (divE1 != null) {
										divE1.style.display = "none";
									}
									var divE2 = document.getElementById(thisOrderItemId+"_"+nRadio[0].value+"_msg");
									if (divE2 != null) {
										divE2.style.display = "block";
									}
								}
							}
						}
					}
				 }
			}
		 }
		}
	}

}

function showNotAddVSErrorMsgPopUpBox (imgPath) {
		var addVSSac = '<div id="nonSac">'
			addVSSac += '<h2>Add to Cart</h2>'
			addVSSac += '<p>The maintenance service(s) you\'ve requested could not be added to your Shopping Cart because the store pickup location you\'ve chosen is not a Sears Auto Service Center, which is the only Sears location that offers maintenance services.</p>'
			addVSSac += '<p>To purchase maintenance services, complete this order first, then create a new maintenance services order and select Sear Auto Service Center as the store location.</p>'
			addVSSac += '<div class="actBtns"><a href=\'javascript:;\' onclick="curtainOverlay({closing:true});"><img src="'+imgPath+'okay_btn.gif" alt="Okay" class="cancelMod" /></a></div>'
			addVSSac += '</div>';

		curtainOverlay({ajaxmodal:true, ajaxclass:'nonSac', closeonclick:false});
		$('.nonSac').html(addVSSac);
		$('.nonSac').html(addVSSac).show().centerOnScreen();
}

// Automotive Phase 2 - ends

// CHANGE ARRIVAL MESSAGE WIDGET (Right Side of the Cart)
function chngArrivalMsg(pThisRadio, pPd_msg)
{
	var i;
	var intlShipFlagFrmCookie = document.getElementById("intlShipFlagFrmCookie").value;
	if(intlShipFlagFrmCookie == 'Y'){}
	else{
	if(pThisRadio.parentNode.id!="layawaybutton"){
		var vPd_msg_wrap      = pThisRadio.parentNode.getElementsByTagName('div')[4];
	var vPd_msg_wrap_divs = vPd_msg_wrap.getElementsByTagName('div');
		if(vPd_msg_wrap_divs.length==0)
		{
			vPd_msg_wrap      = pThisRadio.parentNode.getElementsByTagName('div')[3];
			vPd_msg_wrap_divs = vPd_msg_wrap.getElementsByTagName('div');
		}
	for (i=0; i < vPd_msg_wrap_divs.length; i++)
	{
		vPd_msg_wrap_divs[i].style.display="none";
	}
	if(TrimString(vPd_msg_wrap_divs[pPd_msg].innerHTML).length == 0)
	{
	  	vPd_msg_wrap_divs[pPd_msg].style.display="none";
	  	vPd_msg_wrap.style.display="none";
	}else{
	vPd_msg_wrap_divs[pPd_msg].style.display="block";
	    	vPd_msg_wrap.style.display="block";
	}
	}else{
		document.getElementById("pd_msg").style.display="none";
}
}
}

//From ErrorMessages.jsp - START
function showErrorMessage(flag,quantity,count,indicator) {

	if(indicator == '-5' || indicator == '-4'|| indicator == '-11'|| indicator == '-12') {
		document.getElementById("individualMsg_"+count).innerHTML = document.getElementById("MaxQty_"+count).innerHTML;
	}
	else if(quantity > 0 ) {
		document.getElementById("individualMsg_"+count).innerHTML = document.getElementById("partial_"+count).innerHTML;

	}
	else if(quantity <= 0 && flag){
		document.getElementById("individualMsg_"+count).innerHTML = document.getElementById("SPU_"+count).innerHTML;
	}
	else {
		document.getElementById("individualMsg_"+count).innerHTML = document.getElementById("nonSPU_"+count).innerHTML;
	}
	document.getElementById("individualMsg_"+count).style.display = '';
}


function setNextPage(url) {
	window.location = url;
}

//From ErrorMessages.jsp - END
// Moved out of Protection Agreements
	function decideAjaxCall(catalogEntryId, orderItemId, zipCodeItem, pACatEntryId) {

		var paPriceDivElm = 'pa_price_'+pACatEntryId+'_'+orderItemId;
        var paPrice = document.getElementById(paPriceDivElm).innerHTML;
		if(paPrice == "") {
			ajaxCallForShopCart(catalogEntryId, orderItemId, zipCodeItem);
		}
	}

function autoOff(TextBoxId){
	if(document.getElementById(TextBoxId)){
		document.getElementById(TextBoxId).autocomplete = "off";
	}
}
function searsAjaxBilling( url, opt) 
{
    var req = null; 
    var onSuccess = opt.onSuccess;
    var onFailure = opt.onFailure;
    if (window.XMLHttpRequest) 
    {
    	req = new XMLHttpRequest();
        if (req)
        {
        	req.onreadystatechange = processReqChange;
            req.open(opt.method, url, opt.asynchronous);
            req.send(null);
        }      
    }
    else if (window.ActiveXObject) 
    {
    	req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) 
        {
        	req.onreadystatechange = processReqChange;
            req.open(opt.method, url, opt.asynchronous);
            req.send();
		}
    } 
    if (!req)
    	return;
    else
    	ajaxXMLObject = req;

    function processReqChange() {
    	if (req.readyState == 4) {
        	if (req.status == 200) {
            	onSuccess(req);
			} 
            else {
            	onFailure(req);
            }
		}
    };
}

function showLayawayZip(){
	if(document.getElementById("checkLayaway").checked==true){
		document.getElementById("layawayZip").style.display="block";
	}else{
		document.getElementById("layawayZip").style.display="none";
		document.getElementById("errorBox").style.display="none";
		document.getElementById("la_found").style.display="none";
		document.getElementById("la_found_ins").style.display="none";
		document.getElementById("la_not_found_ins").style.display="none";
		document.getElementById("changestore").style.display="none";
		document.getElementById("tryAnother").style.display="none";
		document.getElementById("layawayCalc").style.display="none";
		$('.layawaybutton').children("input:radio").attr("checked","");
		$('.layawaybutton').hide();
		$($(".arrival").children("input:radio")[0]).attr("checked","checked");				    						    		
	}
	
}

function checkLayawayStore(zip){
	 setCookie("lwzipCode",zip);
	 var oldZipCode=getCookie("zipCode");
	 if(oldZipCode == null || oldZipCode == ""){
	 	setCookie("zipCode",zip);
	 }
	 var finalView='PickUpStoreModalView';
 	 var ret = validateZip(zip);   
	    if(ret == false){ 
	    	var err = document.getElementById("errorBox");
			err.style.display= 'block';
			err.innerHTML ="<p>Please enter a valid Zipcode and proceed.</p>";
			return false;
	    }
	    	var findStoresForZip = {
			    method: 'GET',
			    asynchronous: true,
			    postBody: '',
			    onSuccess: function(t) {
				    var response = eval("(" +t.responseText+ ")");
				    if (response.success == 'true') {
				    	if(response.isStoreEmpty=='Y'){
				    		document.getElementById("tryAnother").style.display="block";
				    		document.getElementById("la_found").style.display="none";
				    		document.getElementById("la_found_ins").style.display="none";
				    		document.getElementById("layawayZip").style.display="none";
				    		document.getElementById("layawayCalc").style.display="none";
				    		$('.layawaybutton').hide();
				    		document.getElementById("la_not_found_ins").style.display="block";
							document.getElementById("changestore").style.display="none";
						}else{
							var lwstores=response.layawaystores;
							var lwstoresTemp=lwstores.split("$");
							
							for(var j = 0; j < lwstoresTemp.length; j++) {
								var storeList=lwstoresTemp[j].split("|");
								//alert(storeList[0]);
								if(storeList[3].length==9){
										storeList[3]=storeList[3].substring(0,5);
								}
								document.getElementById("address1_"+j).innerHTML=storeList[0];
								document.getElementById("address2_"+j).innerHTML=storeList[1]+","+storeList[2]+","+storeList[3];
								document.getElementById("lwstoreunitnumber_"+j).innerHTML=storeList[4];
								
							}
							document.getElementById("layawayZip").style.display="none";
							//document.getElementById("layawaybutton").style.display="block";
							$('.layawaybutton').show();
							document.getElementById("errorBox").style.display="none";
							document.getElementById("la_found").style.display="block";
							document.getElementById("la_found_ins").style.display="block";
							document.getElementById("nearest_0").style.display="block";
							document.getElementById("nearest_1").style.display="none";
							document.getElementById("nearest_2").style.display="none";
							document.getElementById("nearest_3").style.display="none";
							document.getElementById("tryAnother").style.display="none";
							document.getElementById("layawayCalc").style.display="block";
							if(lwstoresTemp.length>1 && document.getElementById("changestore") ){
							document.getElementById("changestore").style.display="block";
						}
				    }
				    }
			    },
			    onFailure: function(t) {
			    	var err = document.getElementById("errorBox");  
	        		err.style.display= "";
	       		 	err.innerHTML ="<p>Your Request could not be completed, please try again.</p>";
	       		}
			};	
			
			 var url = 'SelectStoresCmd?zipCode='+zip+
			 				'&isAjax=true'+
		    				'&storeId='+storeId+
		    				'&cataLogId='+document.checkout.catalogId.value+
		    				'&langId=-1'+
		    				'&URL='+url+
		    				'&sCriteria=LWS'+
		    				'&finalView='+finalView+
		    				'&startFrom=0';
		     new searsAjaxBilling(url, findStoresForZip);  	  
}

function ChangeLayawayStore(){

	if(document.getElementById("nearest_0").style.display=="block" && document.getElementById("address1_1").innerHTML!=""){
		document.getElementById("nearest_0").style.display="none";
		document.getElementById("nearest_1").style.display="block";
	}else if(document.getElementById("nearest_1").style.display=="block" && document.getElementById("address1_2").innerHTML!=""){
		document.getElementById("nearest_1").style.display="none";
		document.getElementById("nearest_2").style.display="block";
	}else if(document.getElementById("nearest_2").style.display=="block" && document.getElementById("address1_3").innerHTML!=""){
		document.getElementById("nearest_2").style.display="none";
		document.getElementById("nearest_3").style.display="block";
	}else{
		if(document.getElementById("address1_0").innerHTML!=""){
			document.getElementById("nearest_1").style.display="none";
			document.getElementById("nearest_2").style.display="none";
		document.getElementById("nearest_3").style.display="none";
		document.getElementById("nearest_0").style.display="block";
	}
	}

}

function TryAnotherStore(){
	document.getElementById("layawayZip").style.display="block";
	document.getElementById("la_found").style.display="none";
	document.getElementById("errorBox").style.display="none";
	document.getElementById("la_found_ins").style.display="none";
	document.getElementById("la_not_found_ins").style.display="none";
	document.getElementById("tryAnother").style.display="none";
	document.getElementById("layawayCalc").style.display="none";
}

function removeNonLayawayMsg(orderItem){
	if(document.getElementById(orderItem+"_TW_msg")!=null){
		document.getElementById(orderItem+"_TW_msg").style.display="none";
	}
	if(document.getElementById(orderItem+"_VD_msg")!=null){
		document.getElementById(orderItem+"_VD_msg").style.display="none";
	}

}
//For Layaway Calculator link
var globalIntArr = null;
var globalPageNo = 1;
var fromProductPage=false;

function fnGetInstPageData(){
	var installmentMsg = '<li id="firstInstallment">Amount due on ';
	var fistFlag = true;
	for (var i = (globalPageNo*4)-4; i < (globalPageNo*4); i++){ 
		if(fistFlag){
			if(globalIntArr[i] !=null && globalIntArr[i]!= '' && globalIntArr[i]!="undefined"){
			
				installmentMsg+=globalIntArr[i].installmentDate+':  <span>$'+globalIntArr[i].dueAmount+'</span></li>';
				fistFlag = false;
			}
		}else{
		if(globalIntArr[i] !=null && globalIntArr[i]!= '' && globalIntArr[i]!="undefined" ){
		
				installmentMsg+='<span id="installmentId"><li>'+globalIntArr[i].installmentDate+':  <span>$'+globalIntArr[i].dueAmount+'</span></li></span>';
			}
		}
	}

	if(fromProductPage == true){
	installmentMsg+='<li>'+$('div#intTotalAmount').html()+'</li>';
	}
	
	if(globalPageNo > 1 || globalIntArr.length > globalPageNo*4){
		installmentMsg+='<li id="pagination">';
		
		if(globalIntArr.length > globalPageNo*4){
			installmentMsg+='<div class="adnl" id="next" onclick="fnShowNextPage();"></div>'
		}
		if(globalPageNo > 1){
			installmentMsg+='<div class="lessImage" id="prev" onclick="fnShowPrevPage();"></div>'
			//installmentMsg+='<div id="prev"><img src="/contentserver/StaticContent/Sears/img/layawayLess.gif"  onclick="fnShowPrevPage();" no-repeat 41px -25px; height:20px; width:60px; overflow:hidden; float:right; text-align:left; /></div>'
			
		}
		
		installmentMsg+='</li>';
	}
	return installmentMsg;
}

function fnShowNextPage(){
	globalPageNo +=1;
	var installmentMsg = fnGetInstPageData();
	$('ul.schedule').html(installmentMsg);

}

function fnShowPrevPage(){
	globalPageNo -=1;
	var installmentMsg = fnGetInstPageData();
	$('ul.schedule').html(installmentMsg);
}


//function called from the jsp
function layawayCalcClick(orderId,storeId){
	
	var address1=document.getElementById("address1_0").innerHTML;
	var address2=document.getElementById("address2_0").innerHTML;
	var unitNumber=document.getElementById("lwstoreunitnumber_0").innerHTML;
	var zipCode=document.getElementById("lwzip").value;
	layawayPopup({type:'modal', id:'layawayPopup', Class:'searsPopup', closeTxt:'Close', addContent:		
function (){
	$('<div class="content" style="padding:0px !important;"/>').appendTo('#layawayPopup');
	$.ajax({
		url: 'LayawayJsp?storeId='+storeId+'&fromProductPage='+ fromProductPage+'&address1='+ address1+'&seasonalInd=false&address2='+ address2+'&zipCode='+ zipCode+'&orderId='+ orderId+'&unitNumber='+unitNumber,
		success:function(data){
				$('#layawayPopup .content').append(data);
				//$('#layawayPopup .pTitle').append(prdTitle);
				content.find('input#CloseButton').unbind().click(function(){
					content.remove();
					modal.remove();
					return false;
				});

				if(typeof(instJson) != 'undefined' && instJson != null){
					globalIntArr = instJson;
					globalPageNo=1;
					var installmentMsg = fnGetInstPageData();
	
					$('ul.schedule').html(installmentMsg);
				}
				
				$('#layawayPopup').show();
				
				//$('a.layawayQues').dynamicPopup({filename: dynamicPopup+'&vName=layawayCal',contentname: '.layawayQuestions',windowWidth: '300px',windowHeight: '240px'});
				
			}
		}
	);
}
		
			});
}

var modal =null;
var content =null;
function layawayPopup(settings){
	var dims = layawayDims()
	if(settings.type == 'modal'){
		if($.browser.mozilla){buffer=250}else{buffer=0}
		modal = $('<div id="layawayModal"/>').css({width:dims.h, height:$('body').height()+buffer}).appendTo('body')
		modal.unbind().click(function(){
			content.remove()
			modal.remove()
		})
	}
	content = $('<div id="'+settings.id+'"class="'+settings.Class+'"/>').css({top:dims.vs+30, left:(dims.h/2)-400}).appendTo('body')
	$('<div class="closeBtn"><a href="#">'+settings.closeTxt+'</a></div>').appendTo(content)
	content.find('.closeBtn a').unbind().click(function(){
		content.remove()
		modal.remove()
		return false
	})
	content.hide();
	
	settings.addContent()
}

function layawayDims(){
	return {
			v:window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
			h:window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
			vs:document.documentElement.scrollTop || document.body.scrollTop,
			hs:document.documentElement.scrollLeft || document.body.scrollLeft
	}
}

function layawayQues(){
var storeId=document.checkout.storeId.value;
var catalogId=document.checkout.catalogId.value;
var newWin = window.open('/shc/s/BrowseStaticPageCmd?storeId='+storeId+'&catalogId='+catalogId+'&langId=-1'+'&cmdStoreId='+storeId+'&catalogInd=DZD&dzName=W4&vName=layawayCal','Layaway_Questions','width=750,height=550,location=no,status=no,scrollbars=yes,menubar=no,toolbar=no'); 
newWin.focus();
newWin.moveTo(40,40);
}

function layawayTerms(){

var jspStoreImgDir = document.getElementById("jspStoreImgDir").value;
if(storeId == '10153')
{
      var newWin = window.open(jspStoreImgDir+'pdf/Sears online layaway agreement 8-6-09_Online layaway launch version.pdf'); 
}
if(storeId == '10151')
{
      var newWin = window.open(jspStoreImgDir+'pdf/Kmart Layaway Contract Agreement 08-14-09_Online layaway launch version.pdf'); 
}
newWin.focus();
newWin.moveTo(40,40);
}
