var itemCatentryVal;
var partnumber ;
var shipFlag = "";	
var isInStock;
var langId = -1;
var	deliveryChecked = 'false';
var pickUpSelected = 'false';
var shipSelected = 'false';
var ddcRegionalAvlFl = '';
var regionalAvlFl = "";
var zipCode = '';
var storeIdReq='';
var scimCalled ;
var isScimEnabled = '';
var regAvlMainFlag = '';
var variant = '';
var rtiZipcode = 0;
var storeIdFinal = '';
var isSRESEligible = '';
var isSPUEligible = '';
var pickUpVar = '';
var changeStoreFlag = 'N';
var qvVendorStrId='';
var distrCenter;
//Flag to confirm QuickView (Regional Availibility)
var flagQVNew='N';
var flagCartQVNew='false'; 
var regAvailStoreId;
var qvPartnumber='';
var catentryProduct='';
var qvCatalogId='';
var qvMfrNum=''
var pickupStoreIdC = '';
var vcsVertical = '';
var islayAwayEligible = '';
var qvPickupFlag=false;
var pickUpURL='';
var productURL='';
var Load = '';
var qvCmdStrId= '';
var qvATCFlag='';
var cartQuantity='';
var cmdStoreId='';
var catEntryIdScim = '';
var qvOptionTab='';
var attrSelected = [];
var fitmentExists =false;
var revURL='';
var intlShipElg ='';
/** This function is called when delivery radio button is clicked **/
function getDeliveryMsgOnCheck(){
	pickUpSelected = 'false';
	deliveryChecked = 'true';
	shipSelected = 'false';
	scimCalled = false;
	zipCodeAttr = 2;
	storeIdReq = $('input#storeIdReq').attr('value');
	zipCode = getCookie('zipCode'+storeIdReq); 
	    getRadioButtonValue("delivery");
	    if(isScimEnabled == 'true'){
	        if(zipCode != ''){
	        	/*document.getElementById('availZIP').value = zipCode;
				document.getElementById('actionActionType').value ='2';*/
					/* RA CONDITION	*/
					if(regAvlMainFlag != 'true')	{
					/*
					    displayZipDiv.style.display = "block";
					    shipEnterZipDivNew.style.display = "none";
					    shipEnterZipDiv.style.display = "none";
					    zipCookieDisplay("D");*/
				    }
	            if (ddcRegionalAvlFl == 'true') {
	            	/*	RA CONDITION	*/
			 		if(regAvlMainFlag != 'true'){
	                	hardAddTocartBtn(0);
	                }else {
	                	hardAddTocartBtn(1);
	                }
	            }
	        }
	        else{   
	           	if(regAvlMainFlag != 'true')	{           
	      			//showEnterZipMsg(2);
        		}  
	        }
	    }
}

function getRadioButtonValue(type){
	var selRadBtn=type;
	if($("div#actionsForm")){
		var ffmSelected="";
		$("div#actionsForm").find("input[@name=arrivMethd]").each(function(i){
			if(selRadBtn=="onLoad" && i==0){
				$(this).attr("checked","checked");
				ffmSelected=$(this).attr("value");
				$("form#addToCart").find("input[@name=IndicatorA]").attr("value",$(this).attr("value"));
			}
			else{
				if($(this).attr("value")==selRadBtn){
					ffmSelected=$(this).attr("value");
					$(this).attr("checked","checked");
					$("form#addToCart").find("input[@name=IndicatorA]").attr("value",$(this).attr("value"));
				}
			}
		});
		
		if(ffmSelected=="delivery"){
			deliveryChecked=="true";
		}else if(ffmSelected=="pickup"){
			pickUpSelected=="true"
		}else if(ffmSelected=="ship"){
			shipSelected = "true";
		}
	}
}





function initializeVar (){
	getRadioButtonValue("onLoad");
	itemCatentryVal = $('input#qvItemId').attr('value');
	partnumber = $('input#qvPartNumber').attr('value');
	qvPartnumber = $('input#qvPartNumber').attr('value');
	distrCenter = $('input#distributionCenter').attr('value');
	isInStock = $('input#isInStock').attr('value');
	regionalAvlFl = $('input#regionalAvlFl').attr('value');
	zipCode = getCookie('zipCode'+storeIdReq); 
	storeIdReq = $('input#storeIdReq').attr('value');
	isScimEnabled = $('input#scimEnabled').attr('value');
	regAvlMainFlag = $('input#regAvlMainFlag').attr('value');
	variant = $('input#variant').attr('value');
	storeIdFinal = $('input#storeIdFinal').attr('value');
	cmdStoreId = storeIdFinal;
	isSRESEligible = $('input#isSRESEligible').attr('value');
	isSPUEligible = $('input#isSPUEligible').attr('value');
	qvVendorStrId = $('input#qvVendorStrId').attr('value');
	regAvailStoreId=$('input#regAvailStoreId').attr('value');
	catentryProduct = $('input#catentryProduct').attr('value');
	qvCatalogId = $('input#catalogId').attr('value');
	qvMfrNum  = $('input#qvMfrNum').attr('value');
	productURL = $('input#productURL').attr('value');
	Load = document.getElementById('loading_reg');
	var pickupStoreId = getCookie('pickupStoreId'+storeIdReq);
	qvATCFlag = $('input#qvATCFlag').attr('value');
	qvOptionTab = $('input#qvOptionTab').attr('value');
	revURL =$('input#rpn').attr('value');
	flagQV ='Y';
	intlShipElg =  $('input#intlShipElg').attr('value');	
	softStatus = 0;
    qvCmdStrId= $('input#storeIdFinal').attr('value');
	if(pickupStoreId != ""){
		pickupStoreIdC = pickupStoreId;   
	}
	else{
	    pickupStoreIdC = "0";
	}
	
	if((distrCenter != '') && (distrCenter != null)  && (isInStock == '1') && ((distrCenter == 'VD') || (distrCenter == 'KCON') || (distrCenter == 'TW') || (distrCenter == 'GC'))){		
	     shipFlag = 'Y';
	 } else if ((distrCenter != '') && (distrCenter != null)  && (isInStock == '1') && (distrCenter == 'PS')){
	 	shipFlag = 'Y';
	 }
	 if (distrCenter != null && distrCenter == 'DDC' && regionalAvlFl == 'true'){
		ddcRegionalAvlFl = 'true';
	}
	pickUpVar = $('input#ppaPickUpOption').attr('value');
	   	
	if((storeIdReq=='10156' || storeIdReq=='10153' || storeIdReq=='10151') && regionalAvlFl == 'true' && variant =='0'){
	   	displayMessage();
	}
	if(pickUpVar =='1'){
		qvPickupFlag=true;
	}
	if(variant=="0"){selectHardLine();}
	initializeSaveLaterVar();
   	attachOmnitureTagToQV();
}




/** This function is called onClick of ATC button. It decides 
/** which function to be called based on the radio button 
/** checked and calls the corresponding function **/
function addCartAvailability(param)	{

	var pos = $('#addCart').offset();
	
	
	if(deliveryChecked == 'true')	{
		// initializing for Add to cart functionality
		atcDelFlag = true;	
		// set for making ajax call from global.js
		regionalDiv = 'delivery';


		if(!fnChkZipCode())	{
			// open stanard CA pop up
			showCAPopUp(partnumber);
			$('div#availPopup').attr("style","display: block");
			$('div#availPopup div.standardDiv').attr("style","display: block");
			$('div#availPopup').css({top: pos.top - 100, left: pos.left - 300 });
			
			
		}
		else	{
			// make a SCIM call to get availability
			makeRegionalDeliveryCall(pageFlag, dbFlagVal, itemCatentryVal, "");
			showCAPopUp(partnumber);
		}
	}
	else if(pickUpSelected == 'true'){
		// initializing for Add to cart functionality
		atcDelFlag = true;	
		// set for making ajax call from global.js
		regionalDiv = 'pickup';

		var regionalClass = $('span.pick').find('a').attr("class");
		if(regionalClass == 'checkAvail')	{
			// open stanard CA pop up
			showCAPopUp(partnumber);
			$('div#availPopup').attr("style","display: block");
			$('div#availPopup div.standardDiv').attr("style","display: block");
			if(param != null || param != undefined){
				$('div#availPopup').css({top: pos.top - 100, left: pos.left - 300 });
			}else{
				$('div#availPopup').css({top: pos.top - 100, left: pos.left + 300 });
			}
			
		}
		else{
			// make a Regional RTI call to get availability
			makeRegionalRTICall();
			showCAPopUp(partnumber);
		}			
	}
	else if(shipSelected =='true')	{
		submitAddToCart();
	}
}


/** This function is called when pick up radio button is clicked **/
function showPickUpOptions(){ 

	pickUpSelected = 'true';
	deliveryChecked = 'false';
	shipSelected = 'false';
	zipCodeAttr = 3;
	getRadioButtonValue("pickup");
	
}

function callRTI() { 

	 	rtiZipcode = zipCode;
	    var catentryIdValues = getCatEntryIds();
	    url = "RTICall?storeId=" + storeIdReq +"&cmdStoreId=" + storeIdFinal + "&zipCode=" + zipCode + "&pickupStoreId=" + pickupStoreIdC + "&langId=-1&" 
	    		+ catentryIdValues+ "&isSPUEligible=" + isSPUEligible+ "&isSRESEligible=" + isSRESEligible + "&vcsVertical=" + vcsVertical;
	
		if((storeIdReq=='10153') && (pickUpVar == '1') && (variant == "0")){
			ajaxCall(url,'fnRTICallbackCntDwn','','');
		} else {
	    	ajaxCall(url,'fnRTICallback','','');
	    }
}



function getCatEntryIds() {

    var url = "";
    var catId="";
    if(variant=='0'){
     var qty = getQuantity();
		if(qty > 0) {
			url = '&catEntryId_1='+itemCatentryVal+'&quantity_1='+qty;
		}
    } else if(variant=='1'){
        if(document.addToCart.catEntryId_1.value.length > 0) {
            var qty = checkQty();
            if(qty > 0){
                catId = document.addToCart.catEntryId_1.value;
                if(catId == '' || catId == 'undefined' || catId == 0){
                 var strURL = document.location.search;
					if (strURL.search("catEntryIdScim") != -1){
					    
					    var temp=new Array();
					    temp=strURL.split("&");
					    for(var i=0;i<temp.length;i++){
					        if(temp[i].search("catEntryIdScim") != -1){
					        	catId=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
					    	}
					    }
					
					}
                 }
                url = '&catEntryId_1=' + catId + '&quantity_1=' + qty;
            }
        }
        else{
                var strURL = document.location.search;
				if (strURL.search("catEntryIdScim") != -1){
				    
				    var temp=new Array();
				    temp=strURL.split("&");
				    for(var i=0;i<temp.length;i++){
				        if(temp[i].search("catEntryIdScim") != -1){
				        	catId=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
				    	}
				    }
				
				}
				var strURLqty = document.location.search;        
				if (strURLqty.search("qty_GR") != -1){
				    
				    var tempqty=new Array();
				    tempqty=strURLqty.split("&");
				    for(var i=0;i<tempqty.length;i++){
				        if(tempqty[i].search("qty_GR") != -1){
				        	qty=tempqty[i].substring(tempqty[i].indexOf("=")+1,tempqty[i].length);
				   		}
				    }
				
				}
                url = '&catEntryId_1=' + catId + '&quantity_1='+qty;
        }
    }
    return url;
}
	
//Validates the value entered for quantity.
	function getQuantity(){
		var quantity = '';
		if(variant == '0'){
			var qty = document.getElementById('quant').value;
			if(qty != '' && (isNumeric(qty) == 0) && (qty > 0)){
				quantity = qty;
			}
			else{
				quantity = 0;
				var mesg = "Please enter a valid quantity";
	        	var objImage = document.getElementById("avlbtn");
			 	showErrorMsgPopUpBox(objImage,mesg,'Availability');
			}
		} else if (variant == '1'){
		
			var qty = checkQty();
	        if(qty > 0){
	            quantity = qty;
	        }
		}
		return quantity;
}
	
function checkQty() {
	    var qty = rObj('quant').value;
	    if(qty != '' && (isNumeric(qty) == 0) && (qty > 0) ) {
	        return qty;
	    }
	     else {
	        return 0;
	    }
	    return 0;
}


function showEnterZipMsg(actionType){
	   	if(regAvlMainFlag != 'true')	{           
			 if(storeIdReq != 10152){
			 
			    document.getElementById('availZIP').value = zipCode;
			    document.getElementById('actionActionType').value = actionType;
			 
			    getRadioButtonValue();
			    
			    if(actionType == 2 ){	     
			        /* For Delivery*/
			        shipEnterZipMsgDiv.innerHTML = deliveryZipMsg;        
			        if (ddcRegionalAvlFl == 'true') {
			            hardAddTocartBtn(0);
			        }
			    }else if (actionType == 3){ 
		       		/* For Pickup*/	        
			        shipEnterZipMsgDiv.innerHTML = pickUpZipMsg;
		
			        if (ddcRegionalAvlFl == 'true') {
			            hardAddTocartBtn(0);
			        }
		    	} else{   
		        /* For ship*/
					shipEnterZipDiv.innerHTML = shipZipMsg;
		    	}
		 		shipMsgDiv.style.display = "block";
				shipEnterZipDiv.style.display = "block";
				shipEnterZipDivNew.style.display = "none";
				displayZipDiv.style.display = "none";
				shipEnterZipMsgDiv.style.display = "block";
			    if (shipCal == 1){  
			    	$(shipCalDiv).show();
			    }
				
			}
		}
	}
	
	

/** This function is called when ship radio button is clicked **/
function showShipMsg(){

	shipSelected = 'true';
	deliveryChecked = 'false';
	pickUpSelected = 'false';	
	if(storeIdReq == 10153 || storeIdReq == 10156){
		$("span#shipradio").find("p#shipStrMsg").attr("style","display:block");
	}
	getRadioButtonValue("ship");
}

function hardAddTocartBtn(val){
    /*0 add to cart disabled
      1 add to cart enabled*/
    var elemEn = document.getElementById('addCart');
    var elemEnEX = document.getElementById('productXC');
    if(val == 0){
        if(elemEn){    
        	elemEn.style.display = "none";  
        }   
        if(elemEnEX){
        	elemEnEX.style.display = "none";
        }
    }else if(val == 1){
        if(elemEn){
        	elemEn.style.display = "block"; 
       }
       if(elemEnEX){
        	elemEnEX.style.display = "block";
        }    
    }
}

function availabilityButton(val){
	    var availButton = '';

        if(val == 0){  
            availButton=  '<input alt=\"check availability button\" id=\"chkAvailBtn\" type=\"image\" src=\"'+jspStoreImgDir+'img/buttons/btn_check_availability.gif\" width=\"126\" height=\"22\" style=\"display: none;\"/>  ';
        }else{    
          availButton= '<input alt=\"check availability button\" id=\"chkAvailBtn\" type=\"image\" src=\"'+jspStoreImgDir+'img/buttons/btn_check_availability.gif\" width=\"126\" height=\"22\"  align=\"absmiddle\" onclick=\"javascript:submitZipCode(this);\"/> ';	      
        } 
        return  availButton;
}

function storeLocator(){ 
	
		var URL = 'ProductDisplay?';
	    var vName = gup('vName');
	    var cName = gup('cName');
	    var sName = gup('sName');
	    var langId = -1;
	    
	    if(11201 != storeIdReq){
	    var URL = URL+'partNumber='+qvPartnumber+'&cName='+cName+'&sName='+sName+'&vName='+vName+'&storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&langId='+langId;
	    	var presellDate = document.addToCart.presellDate.value;
	    }
	    else{
	    	var URL = $('input#productURL').attr('value');;
	    	URL =URL+'vName='+vName+'&cName='+cName+'&sName='+sName;
	    }
	    var catEntryId = getCatEntId();
		var IndicatorA = document.addToCart.IndicatorA.value;
		if(regAvlMainFlag == 'true')	{
			IndicatorA = 'pickup';
		}
		
		zipCode = getCookie('zipCode'+storeIdReq);
		
	    var grIdentifier = document.addToCart.grIdentifier.value;
	    var atc = document.addToCart.atc.value;
	    var addToCartBtn = document.addToCart.addToCartBtn.value;
	    var grUserType = document.addToCart.grUserType.value;
	    
	    
	    if (catEntryId != '' && catEntryId != "undefined")
	    {
	        var catentryIdValues = getCatEntryIds();
			if(catentryIdValues != '') {
				if(11201 != storeIdReq){
				if(changeStoreFlag == 'Y'){
					var storeLocatorUrl = "StorePickupCommand?storeId="+storeIdReq+"&langId=-1&catalogId="+qvCatalogId+
										  "&grUserType="+grUserType+"&IndicatorA="+IndicatorA+"&zipCode="+zipCode+
										  "&atc="+atc+"&addToCartBtn="+addToCartBtn+"&grIdentifier="+grIdentifier+
										  "&presellDate="+presellDate+"&variant="+variant+
										  "&"+catentryIdValues+"&changeStoreFlag=Y&URL="+URL+pickUpURL;
				} else {
					var storeLocatorUrl = "StorePickupCommand?storeId="+storeIdReq+"&langId=-1&catalogId="+qvCatalogId+
										  "&grUserType="+grUserType+"&IndicatorA="+IndicatorA+"&zipCode="+zipCode+
										  "&atc="+atc+"&addToCartBtn="+addToCartBtn+"&grIdentifier="+grIdentifier+
										  "&presellDate="+presellDate+"&variant="+variant+
										  "&"+catentryIdValues+"&URL="+URL+pickUpURL;
				}
				}
				
				window.location = storeLocatorUrl;
			}
	    }
	    else
	    {
	    	alert(addToCartMsg);
	    	if(regAvlMainFlag != 'true')	{           
		        showEnterZipMsg(3);
	        }
			
	    }
	}

	
/* to check RA on addtocart*/
function submitAddToCartRANew(image){
	if((qvVendorStrId == "10153" || qvVendorStrId == "10156") && variant=="0" && distrCenter=='DDC'&& regionalAvlFl == "true" && deliveryChecked == 'true'){
		var pos = $('#addCart').offset();
		pos.left = (((pos.left - 200) < 0 ) ? (pos.left + 200) : pos.left);
		$('#availPopup').remove();
		pageFlag='CAT';
		showCAPopUp();
		
		$('#availPopup .standardDiv').css({display: "none"});
		$('#availPopup .errorDiv').css({display: "none"});
		$('div#availPopup').css({top: pos.top - 100, left: pos.left - 200});
		flagCartQVNew='true';
	    flagQVNew='Y';
	}
	submitAddToCartNew(image);
}

/* submitaddtocart function  signature changed for smartcart */
function submitAddToCartNew(image) {
   var pos = $('#addCart').offset();
   qvPartnumber=document.addToCart.partNumber.value;
   var itemA=document.addToCart.IndicatorA.value;
   if(document.addToCart.addToCartBtn.value == 'false') {
        //Add to cart button has been clicked once
        	if(itemA=='pickup' && storeIdReq!='10153' && qvVendorStrId != "10153"){
        		zipCode = getCookie('zipCode'+storeIdReq); 
        		if(zipCode!='undefined' && zipCode!='' && checkZipPA(zipCode,'')){
        			storeLocator();
        		}else{
        			dispfnPopUp();
        		}
        	}
        	else if(pickUpSelected == 'true' && storeIdReq =='10153')	{
				
				// initializing for Add to cart functionality
				if(variant=="0"){
					atcDelFlag = true;	
					// set for making ajax call from global.js
					regionalDiv = 'pickup';
			
					var regionalClass = $('span.pick').find('a').attr("class");
					if(regionalClass == 'checkAvail')	{
						// open stanard CA pop up
						showCAPopUp(partnumber);
						$('div#availPopup').attr("style","display: block");
						$('div#availPopup div.standardDiv').attr("style","display: block");
						$('div#availPopup').css({top: pos.top - 100, left: pos.left - 300 });
						
					}
					else	{
						// make a Regional RTI call to get availability
						makeRegionalRTICall();
						showCAPopUp(partnumber);
					}
				}else{
					/*For Sears Softline pickUp to redirect to Store Grid page*/
						zipCode = getCookie('zipCode'+storeIdReq); 
		        		if(zipCode!='undefined' && zipCode!='' && checkZipPA(zipCode,'')){
		        			storeLocator();
		        		}else{
		        			dispfnPopUp();
		        		}
				}			
			}
        	else if((qvVendorStrId == "10153" || qvVendorStrId == "10156") && variant=="0" && distrCenter =='DDC' && regionalAvlFl == "true" && deliveryChecked == 'true'){
         		if(fnChkZipCode()){
					tempZip=getRegDelZip();
					var scimStoreId = "09300";
					var quant = "1";
					var deliveryStore = "09300";
					if(qvVendorStrId == "10156"){
						scimStoreId = "09311";
						deliveryStore = "09311";
					}
					var scimCall = { 
				        success: fnSearsAddToCartNew,
						url:'RegionalAvailCmd?pageInd=CAT&dbFlag=N&ndd=1&zipCode='+tempZip+'&catEntryId='+catentryProduct+'&scimStoreId='+scimStoreId+'&quantity='+quant+'&deliveryStore='+deliveryStore+'&storeId='+regAvailStoreId,
				        type:'POST',
				        data: {DDItemList: qvPartnumber},
				        error: errorFnDeliveryAvailResponse
			     	};
			     	request=$.ajax(scimCall);
				}else{
					fnSetInfoNew('N');
					$('#availPopup').css({display: "block"});
					$('#availPopup .standardDiv').css({display: "block"});
					$('#availPopup .errorDiv').css({display: "none"});
					currentPartNo = qvPartnumber;
					readyOnLoad();
					catentryVal = catentryProduct;
				}
        	}else{
        		//Add to cart button has been clicked once   
        		
				var childCatId =document.addToCart.catEntryId_1.value;
        		
        		var quantity = 0;
				quantity = document.getElementById('quant').value;
				if(quantity != '' && (isNumeric(quantity) == 0) && (quantity > 0)){
					document.addToCart.quantity_1.value = quantity;
					cartQuantity=quantity;
					var atcCheck=false;
					if(variant =='1' && qvATCFlag =='true' ){
						atcCheck= true;
					}
					else if(variant =='0' && (qvATCFlag =='true' && qvOptionTab !='true' )){
						atcCheck= true;					
					}
					if(atcCheck){
					var parameters="&catEntryId_1="+childCatId+"&quantity_1="+quantity+"&parent_catEntryId_1="+catentryProduct;
					var queryString="URL=AJAXResponseView&langId=-1&storeId="+storeIdReq +"&catalogId="+qvCatalogId+parameters+"&IndicatorA="+itemA ;
 					
					  $.ajax({
					  url: "/shc/s/MultipleOrderItemAddCmd",
					  data:queryString,
					  timeout:9999999,
					  success: function(msg){
					   	postCartFlow(msg);
					   }
					 });  
			        }
			        else{
			        	 document.addToCart.submit();
			        }
		        } else {
					var objImage = document.getElementById('cart_enable');
					var mesg = "Please enter a valid quantity";
				 	showErrorMsgPopUpBox(objImage,mesg,'Cart');
				}
        		
    	    }
    }
}
	
function fnSearsAddToCartNew(jsonresponse){
	if(jsonresponse=='OutOfStock'){
		fnSetInfoNew('N');
		atcZipCode = getRegDelZip();
		$('#availPopup').css({display: "block"});
		$('#availPopup .standardDiv').css({display: "none"});
		$('#availPopup .errorDiv').css({display: "block"});
		$('.errorDiv input#checkZip').css({display: "inline"});
  		$('.standardDiv #loadGif').css({display: "none"});
  		$('.errorDiv #loadGif').css({display: "none"});
		readyOnLoad();
		catentryVal = catentryProduct;
	}else if(jsonresponse=='Failure'){
		tempZip=getRegDelZip();
		var dbCall = { 
		        success: fnSearsDBAddToCartNew,
				url:'RegionalAvailCmd?pageInd=CAT&dbFlag=Y&catEntryId='+itemCatentryVal+'&zipCode='+tempZip+'&storeId='+regionalAvlStrId,
		        type:'POST',
		        data: {DDItemList: qvPartnumber},
		        dataType:'json',
		        error: errorFnDeliveryAvailResponse
	     	};
			request=$.ajax(dbCall);
	}else{
		$('#availPopup').remove();
      	document.addToCart.submit ();
    	
	}
}
	
function fnSetInfoNew(callInd){
	if(callInd=='Y' || callInd=='y'){
		pageFlag='CAT';
		dbFlagVal=callInd;
		catentryVal=itemCatentryVal;
	}
	else{
		pageFlag='CAT';
		dbFlagVal=callInd;
		catentryVal=itemCatentryVal;
	}
}
	
function displayMessage(){

/*parameters for SPU Info*/
	pageFlag = 'CAT';
   	var _vert = omVrt.split("'").join("");
    var _cat = omCat.split("'").join("");
    var _sbcat = omSubCat.split("'").join(""); 
	var trimSbcat=stringTrim(_sbcat);
    var pURL='p_'+storeIdReq+'_'+qvCatalogId+'_'+qvPartnumber+'?vName='+_vert+'&cName='+_cat+'&sName='+trimSbcat;
	var sDate='';
	vcsVertical=_vert;
	var spuInfo = qvPartnumber+'^Y^CAT^'+qvMfrNum+'^'+catentryProduct+'^'+pURL+'^/contentserver/StaticContent/Sears/^img/buttons/^'+storeIdReq+'^'+qvCatalogId+'^'+sDate+'^';
    if(fnChkZipCode()){
    
		var availMsg=availValues.Get(qvPartnumber);
		if(typeof availMsg == 'undefined'){			
			$('div#availability span.delivery').html('Temporarily out of stock for delivery <a id="checkAvailDel" class="checkAvail" href="javascript:;" rel="regionalAvailability" info="'+partnumber+'^Y^'+pageFlag+'^'+itemCatentryVal+'">Check Availability</a>');
		}else{
			$('div#availability span.delivery').html(availMsg+' '+getRegDelZip()+'<a id="checkAvailDel" class="checkAvail" href="javascript:;" rel="regionalAvailability" info="'+partnumber+'^Y^'+pageFlag+'^'+itemCatentryVal+'">Change ZIP Code.</a>');
		}
		$('div#availability span.pick a#checkAvailSpu').remove();
		$('div#availability span.pick').append('<a id="checkAvailSpu" class="checkAvail" href="javascript:;" rel="regionalAvailability" info="'+spuInfo+'">Check Availability</a>');
		readyOnLoad();
	}
	if(!fnChkZipCode()){
		if(shipFlag != 'Y')	{
			$('div#availability span.delivery').append('<a id="checkAvailDel" class="checkAvail" href="javascript:;" rel="regionalAvailability" info="'+partnumber+'^Y^'+pageFlag+'^'+itemCatentryVal+'">Check Availability</a>');
		}
			
			$('div#availability span.pick a#checkAvailSpu').remove();
			$('div#availability span.pick').append('<a id="checkAvailSpu" class="checkAvail" href="javascript:;" rel="regionalAvailability" info="'+spuInfo+'">Check Availability</a>');
			readyOnLoad();
	}

}	

function dispfnPopUp(){
 var pos = $('#addCart').offset();
 pos.left = (((pos.left - 200) < 0 ) ? (pos.left + 200) : pos.left);
 $('#availPopup').remove();

var zipcode=getCookie('zipCode'+storeIdReq);
var div ="<div id='availPopup' class='availPopup' style='display: none;'><div style='display: none;' class='standardDiv'><h2>Check Availability</h2><a href='javascript:;\' class='closeAvail'>Close</a>"
	 			+"<p><span>See What\'s in Stock</span>We need a little more info to check this item\'s local availability.<br/>"
				+"Enter your zip.</p><p><label for='zipCode'>Enter ZIP Code: </label><input type='text' id='zipCode' value='"+zipcode+"' maxlength='5' size='5'/>"
				+"<input type='image' value='Check Availability' id='checkZip' src='"+jspStoreImgDir+"img/buttons/btn_check_availability.gif' onClick='submitZipCode(this);'/>"
				+"<img height='16' width='16' alt='loading...' src='"+jspStoreImgDir+"img/loadingSmall.gif' id='loadGif' style='display: none;'/></p>"
				+"</div>"
				+"<div style='display: none;' class='errorDiv'><h2>Check Availability</h2><a href='javascript:;' class='closeAvail' id='closeAvail'>Close</a>"
				+"<p class='error'>This product doesn\'t seem to be available for Delivery in the ZIP Code you\'ve entered.</p><p>Some product availability is based on region, so this product may not be available in your area.</p>"
				+"<p><label for='zipCode'>Check another ZIP Code for Delivery: </label><input type='text' id='zipCode' maxlength='5' size='5'/>"
				+"<input type='image' value='Check Availability' id='checkZip' src='"+jspStoreImgDir+"img/buttons/btn_check_availability.gif' onClick='submitZipCode(this);'/>"
				+"<img height='16' width='16' alt='loading...' src='"+jspStoreImgDir+"img/loadingSmall.gif' id='loadGif' style='display: none;'/>"
				+"</p><p class='or'><span>------------------------------------</span>Or<span>------------------------------------</span></p>"
				+"<p>Save Delivery costs and <a id='popupPickup' style='cursor:pointer'>Pick Up your item at the store</a></p>"
				+"</div>"
				+"</div>";
	  	$('body').append(div);
	  	
	  	$('#availPopup .closeAvail').click(function(){
	  		$('#availPopup').remove();
	  	});
	  	
	  	
 $('#availPopup .standardDiv').css({display: "block"});
 $('#availPopup .errorDiv').css({display: "none"});
 $('div#availPopup').css({top: pos.top - 100, left: pos.left - 200}); 
 $('#availPopup').css({display: "block"});
	  	
}


/*This function is called when the "Check Availability" button is clicked*/
	function submitZipCode(objImg) {	
		var zipCode = $("input#zipCode ").attr("value");
		$.cookie('zipCode'+storeIdReq,zipCode);
	    
	    if(typeof zipCode !='undefined' && zipCode !=''){
	    	zipCode=$.trim(zipCode);
	    }
	    if (checkZipPA(zipCode,objImg)){
	        /*Sets a session cookie for zip code*/	       
	        setCookie('zipCode'+storeIdReq,zipCode);
	        storeLocator();	        
	    }
	}
	
	function checkZipPA(zip,objImg) 
	{
	  var lv_pattern = /^\d{5}$|^\d{5}\-?\d{4}$/;
	  var passed = lv_pattern.test(zip); 
	  if (!passed) 
	  {
	        var mesg = 'Please enter a valid 5-digit ZIP code (example: 60515).';     
	        showErrorMsgPopUpBox(objImg,mesg,'ZipCodeEnter');
	        return false;
	  }
	  else 
	  {
	    return true;
	  }
	}
	
		
/*	function for ajax call for Regional availability Store pick up	*/

function makeRegionalRTICall()	{
    
    var catentryIdValues = getCatEntryIds();
    url = "RTICall?storeId=" + storeIdReq +"&cmdStoreId=" + storeIdFinal + "&zipCode=" + getRegPickZip() + "&pickupStoreId=" + pickupStoreIdC + "&langId=-1&" 
    		+ catentryIdValues+ "&isSPUEligible=" + isSPUEligible+ "&isSRESEligible=" + isSRESEligible + "&vcsVertical=" + vcsVertical+"&islayAwayEligible="+ islayAwayEligible;

	ajaxCall(url,'responseRegionalRTICntCall','','');
}
	
	

/*	call back function for ajax call of Regional availability Store pick up	*/

function responseRegionalRTICntCall(value)	{

	var errorFlag = false;
	datefromScim = "";
	responseFFM = "";
	var layawayMsg = '';
	var layawayCheck="";
	response = value.split('#')[0];
	datefromScim = value.split('#')[1];
	qtyAvail = value.split('#')[2];
	storeName = value.split('#')[3];
    storeAddrDet= value.split('#')[4];
    responseFFM = value.split('#')[5];
    if(value.split('#')[6] != null){
		layawayCheck = value.split('#')[6];
	}
    
	var pickMsg = '<span class="icon"></span>Buy online - Pick up in store eligible. ';

	if(response =="Success" && value!='' && response!='')	{
		/*Lay Away Code changes */
		if(LayAwayFlagConfig != null && LayAwayFlagConfig == 'true'){
		    if(layawayCheck!=null &&  layawayCheck=="layaway=Y"){
			    layawayMsg+='Available for layaway at 	'+storeName+','+storeAddrDet+'  ';
			    layawayMsg+='<a id=\"layCalcLink\" onclick="javascript:layawayClick()" href ="javascript:void(0);" style="cursor:pointer">Layaway Calculator</a>';	
			     
			    }
			    else {
			    		layawayMsg+='Not available for Layaway at '+storeName+', '+storeAddrDet+'  ';
					    layawayMsg+='<a id=\"layCalcLink\" href ="javascript:void(0);"  onclick="javascript:layawayClick()"  style="cursor:pointer">Layaway Calculator</a>'; 
					   	
				}
				$('span#layawaylinks').html(layawayMsg);
				//layawayMsgClick();
		}
		
		/*Lay Away Code changes Ends*/
	     
        /*The product is instock*/
        if(datefromScim=="" || datefromScim == null){
		 if(qtyAvail=="" || qtyAvail == null){
			
			/*	Code for without quantity	*/
			pickMsg += 'In stock at '+storeName+', '+storeAddrDet;
				pickMsg += ' <a id=\"changeZip\" class=\"changeZip\" rel=\"regionalAvailability\" info="'+partnumber+'^Y^PRD^'+catentryVal+'" style="cursor:pointer"> Check another store</a>';
			
		 }else{  
			
			/*	Code for with quantity	*/
				pickMsg += 'Only '+qtyAvail+' left at '+storeName+', '+storeAddrDet;
				pickMsg += ' <a id=\"changeZip\" class=\"changeZip\" rel=\"regionalAvailability\" info="'+partnumber+'^Y^PRD^'+catentryVal+'" style="cursor:pointer"> Check another store</a>';			

		 }
	    }else{
				pickMsg += 'In stock at '+storeName+', '+storeAddrDet+ ' in '+ datefromScim +' days';
				pickMsg += ' <a id=\"changeZip\" class=\"changeZip\" rel=\"regionalAvailability\" info="'+partnumber+'^Y^PRD^'+catentryVal+'" style="cursor:pointer"> Check another store</a>';
			}
	 }else{
		errorFlag = true;
		/*	Code for check availability link	*/
		pickMsg += ' <a href=\"javascript:;\" id=\"check\" class=\"checkAvail\" rel=\"regionalAvailability\" info="'+partnumber+'^Y^'+pageFlag+'^'+catentryVal+'"> Check Availability</a>';
	}
   	$('li.pickup').html("");
	$('li.pickup').html(pickMsg);
	
	/*	for binding the click links	*/
	readyOnLoad();
	
	if(errorFlag){
		// flag for add to cart
		if(atcDelFlag){
			storeLocator();
		}
	}
	else	{
		// remove CA pop up only pop up from pick up option
		if(regionalDiv == 'pickup')	{
			$('div#availPopup').remove();
		}
		if(atcDelFlag)	{
			if(storeIdReq=='10153' && ($.cookie("zipCode")!=null && ($.cookie('zipCode'+getStoreId())==null))){
				$.cookie('zipCode'+getStoreId(),$.cookie('zipCode'));
				storeLocator();
			}
			else if(storeIdReq=='10153' && ($.cookie('zipCode'+getStoreId())!=null)){
				storeLocator();
			}else{
			// Successful call add to cart 
			submitAddToCart();
			}
			
		}
	}
}
	
	
	
function postCartFlow(msg){   
  
  if(msg!=null && msg!=''&& msg!=' '){
    var myJSONObject= "(" + msg + ")";
    if (!_gc) {
	   var _gc = new Object();
     }  
   _gc.prod = eval(myJSONObject);
    
    var  totalFailure=_gc.prod.totalFailure;
    var orderID='';
    var orderItemID='';
    var catentryAdded='';
     if(totalFailure=='false'){
         orderID=_gc.prod.orderID;
         totalQuantity = cartQuantity;
         orderItemID = _gc.prod.addedOrders[0].orderItemID;
         catentryAdded = _gc.prod.addedOrders[0].catentryID;
         $("#chosenAttr span.attrDetail").text("Qty:"+totalQuantity);
         var tabLen = $('#tabs ul:first li').length;
		$('#tabs').tabs('select', tabLen-1);
		
		$('li#addItem').removeClass('qvAddedItem');
		 
		//kill the hover css styles
		$('#tabs li').not('#addItem').find('a').mouseover(function () {
			$(this).css({
				'border' : '0px',
				'margin' : '0px',
				'padding-bottom' : '0px',
				'cursor' : 'default',
				'background' : 'url('+jspStoreImgDir+'img/bg/qv_tab_default_hover_bg.gif) repeat-x 0 -4px'
			});
			
		});
		
		if(_gc.prod.totalQuantity!=null && _gc.prod.totalQuantity!=''  && _gc.prod.totalPrice!=null && _gc.prod.totalPrice!='' && storeIdReq!='11201'){
              updateMiniCartDisplayLink(_gc.prod.totalQuantity,_gc.prod.totalPrice);
         }
         
		var disabled = $('#tabs').tabs('option', 'disabled');
		//setter
		//$('#tabs').tabs('option', 'disabled', [0, 1, 2, 3]);
		
		$("#removeItem").click(function(i){
			var removeParam="/shc/s/OrderItemDelete?langId=-1&updatePrices=1&calculationUsageId=-1&URL=AJAXResponseView&storeId="+storeIdReq+"&catalogId="+qvCatalogId+"&orderId="+orderID+"&orderItemId="+orderItemID+"&productId="+catentryAdded;	
			
			 $.ajax({
					  url: removeParam,
					  success: function(msg){
					  	displayRemoveMsg(msg);
					   }
			 });  
		});
		
		$("#itemResults span#itemChoice a#buyAnother").click(function(){
		 	showNewQuickView(storeIdReq, qvCatalogId, qvPartnumber);		 
		});
		
		displayAttributes();
		
		return false;
     }
      if(totalFailure=='true'){
         displayErrorMessage();
     }

   
  }  
}
 
 function displayRemoveMsg(msg){
	 closePopUpLayerQV();
 }
 
 function displayErrorMessage(){
 /*yet to implement*/
 
 }
 
/*****************Test softline begins********************/
SEARSSOFTLINE = {
    /* STORE PRODUCT INFO */
    Item: {
        "info":function(softlineData){
            var data = softlineData;
                       
			//Softlines
            if(data.Softline){ 
                this.softData   = data.Softline;
                this.variants   = this.softData.prodList.prodVarList;
            
            this.current        = {skuList:'',attList:''};
            this.ssArray        = data.Softline.ssArray;
            this.fakeDDshow     = function(elm){
         
                                    var t;
                                    var global = this;
                                    $('#fakeDDcontent').remove();
                                    var dd = $('<div id="fakeDDcontent"></div>').appendTo('.qvPopUpLayer');
                                    $(elm).children('div').each(function(){
                                        if($(this).is('.disabled')){
                                            $('<div class="notAvail">'+$(this).html()+'</div>').appendTo(dd);   
                                        }else{
                                            $('<div>'+$(this).html()+'</div>').appendTo(dd);
                                        }
                                    });
                                    if($(dd).children().length > 10){
                                        $(dd).css({
                                            height: 175,
                                            overflow:'auto'
                                        }); 
                                    };
                                    $('#fakeDDcontent div').hover(function(){
                                        $(this).addClass('hover');                                 
                                    },function(){
                                        $(this).removeClass('hover');
                                    });
                                    $(dd).css({
                                        top:    $(elm).offset().top - $(elm).parents('.qvPopUpLayer').offset().top,
                                        left:   $(elm).offset().left - $(elm).parents('.qvPopUpLayer').offset().left
                                    }).show().mouseout(function(){
                                        t = setTimeout(function(){
                                            //$(dd).remove();                       
                                        },400); 
                                    }).mouseover(function(){
                                        clearTimeout(t) ;
                                    });
                                    $(dd).find('div').click(function(){
                                        var val = $(this).text();
                                        $(elm).children('div').each(function(){
                                            if($(this).text() == val){
                                                $(this).addClass('opt_sel').removeClass('opt_not_sel');
                                            }else{
                                                $(this).removeClass('opt_sel').addClass('opt_not_sel');
                                            };
                                            
                                        });
                                        $(dd).remove();
                                        global.attrChange(elm,true);
                                        
                                        if($(elm).is('#qvp_var')){
                                            $(SEARSSOFTLINE.Item.softData.prodList.prodVarList).each(function(){
                                                if(this.varName == val){
                                                    SEARSSOFTLINE.Item.current.attList = this.attList;
                                                    SEARSSOFTLINE.Item.current.skuList = this.skuList; 
                                                };                                                         
                                            });
                                            global.changeVariant();
                                            };
                                    });
           }; 
            }
            var tempVal;
            this.changeVariant = function(){
        
                                    softlinePartNum = '';
				                    softlinePrice = '';
                                    $('.qvdropdowns .qvp_att_dd').add('.qvdropdowns div.oos').remove();
                                    $(this.current.attList).each(function(a){
                                    	if(typeof this!='undefined' && this.name != undefined && this.values.length > 0) {
                                        var dd = $('<div class="fakeDD qvp_att_dd" id="qvp_att'+a+'"></div>').appendTo('.qvdropdowns').click(function(){
                                            tempVal = $(this).find('.opt_sel').removeClass('opt_sel').addClass('opt_not_sel');
                                            $(this).find('.default').addClass('opt_sel').removeClass('opt_not_sel');
                                         
                                            SEARSSOFTLINE.Item.attrChange(dd);
                                            SEARSSOFTLINE.Item.fakeDDshow(this);                                                                                               
                                        }); 
                                        $(dd).append('<div class="opt_sel default">'+this.name+'</div>')
                                        if(this.name == 'Color' || this.name == 'Overall Color' || this.name == 'COLOR'){
                                        $(dd).addClass('qvcolor');
                                            $(this.values).each(function(b){
                                                var swURL = 'http://s.sears.com/is/image/Sears/'+this.swId+'?hei=20&wid=20&op_sharpen=1';
                                                $('<div class="opt_not_sel"><img src="'+swURL+'" alt="'+this.cName+'" align="absmiddle" height="20" width="20">'+this.cName+'</div>').appendTo(dd); 
                                            });
                                        }else{
                                            $(this.values).each(function(c){
                                                $('<div class="opt_not_sel">'+this+'</div>').appendTo(dd);                   
                                            }); 
                                        };
                                        }
                                    });
                                    $('<div class="oos">This item is not available in the combination you have selected. Please change your selections.</div>').hide().appendTo('.qvdropdowns');
            };
            this.attrChange = function(changed,msg){
                var condition = '';
                var closedAttrs = [];
                var matches = [];
                var skuList = SEARSSOFTLINE.Item.current.skuList;
                var saveStory = SEARSSOFTLINE.Item.ssArray;
                var qvImgDim=248;
                var allAttrs = $('.qvp_att_dd');
                $(allAttrs).find('div').removeClass('enabled').removeClass('disabled');
                $('.qvp_att_dd').each(function(){
                    if(!$(this).find('div:first').is('.opt_sel')){
                        closedAttrs.push(this); 
                    }                              
                });
                
                if(closedAttrs.length > 0){
                    $(closedAttrs).each(function(a){
                        var spot = this.id.split('qvp_att')[1];
                        if(a==0){
                            condition+= 'this.aVals['+spot+'] == "'+$(this).find('.opt_sel').text()+'"';
                        }else{
                            condition+= ' && this.aVals['+spot+'] == "'+$(this).find('.opt_sel').text()+'"';
                        }
                    });
                    condition+=' && this.stk > 0';
                    $(skuList).each(function(){  
                       //International Shipping
                        if(eval(condition)){
                        if(intShipJspChk == 'true' )
                        {
                        if(this.intShip == 'YES')
                        {
                        
                        if(('.intShip').style == 'display: none;')
                        {
                        $('intShip').show();
                        }
                        $('.unvIntShip').hide();
                        if($('input#quant').val() == '0')
						$('input#quant').attr('value','1');
                        }
                        else if (this.intShip == 'NO') 
                        {
                       
                        $('.intShip').hide();
                        //$('span#pickupradio').hide();
						$('input#quant').attr('disabled','disabled').attr('value','0');
						$('#cart_enable').hide();
                        if(('.unvIntShip').style == 'display: none;'){
                        $('.unvIntShip').show();
                        }
                        $('.gotoBtn').hide();
                        $('.QVqty').attr('disabled','disabled').attr('value','0');
                        //message intShip unavailable
                        }
                        } 
                        else
						{
						$('.unvIntShip').hide();
						$('.intShip').hide();
						if(intlShipElg == 'YES')
						{
						
						$('.intShip').show();
						
						}
						}
                            matches.push(this);
                            $(this.aVals).each(function(b){
                                var m = this;
                                $('#qvp_att'+b).find('div').each(function(){
                                    if($(this).text() == m){$(this).addClass('enabled')}                                          
                                });
                            });
                        }
                    });
                    $(allAttrs).children('div').not('.default').not('.enabled').addClass('disabled');
                    if(closedAttrs.length == 1){
                        $(closedAttrs).children('div').removeClass('disabled').removeClass('enabled');
                    }
                }else{
                    $(allAttrs).children('div').removeClass('disabled').removeClass('enabled');
                };
                
                if($('.qvp_att_dd').find('.opt_sel').hasClass('disabled')){
                
                    $('.qvdropdowns .oos').show();        
                }else{
                    $('.qvdropdowns .oos').hide();
                }
                if(msg){
                    var tot = allAttrs.length
                    var check = [];
                    $(allAttrs).each(function(){
                        if ($(this).children('div.default').hasClass('opt_sel')){
                            check.push(this);   
                        };                    
                    });
                    if(matches.length == 0 && check.length != tot){
                        $('.qvdropdowns .oos').show();
                    };
                };
                if(closedAttrs.length == allAttrs.length && $('.qvdropdowns .oos').is(':hidden')){
                    var QVparent = $('#qv'+SEARSSOFTLINE.Item.pId);
                    var _QV = $('.qvPopUpLayer');
                    var pid = matches[0].pid;
                    attrSelected = matches[0].aVals;
                    softlinePartNum = matches[0].pnum;
                    softlinePrice = matches[0].price;
                    $('form[name="addToCart"] input[name="catEntryId_1"]').val(pid);
                    var ssIndex = matches[0].ssIdx;
                    if(isI18NConvReq()){
		                        $('.qvPopUpLayer .saveStory').html(fnConSSfly(saveStory[ssIndex]));
		                        }else{
		                        $('.qvPopUpLayer .saveStory').html(saveStory[ssIndex]);
                    }
                    if(isI18NConvReq()){ 
		                            	currencySymb = i18nCookieData.currencyCode;
		                            }
		                            else{
		                            	currencySymb = "$"
                        }
                    
                    var _SSqty = $(QVparent).find('.saveStory').eq(0);
                    var _defaultST ="";  
                    if($(_SSqty).find('.regPrice').length){
                         _defaultST = $(_SSqty).find('.regPrice').html().split(currencySymb)[1];
                    }else if($(_SSqty).find('.salePrice').length){
                         _defaultST = $(_SSqty).find('.salePrice').html().split(currencySymb)[1];
                    }
                    else if($(_SSqty).find('.youPay').length){
						_defaultST = $(_SSqty).find('.youPay').eq(0).find('.pricing').eq(0).html().split(currencySymb)[1]
					}
                    
                    var _a2c = $('#cart_disable')
                    var _qty = $(_a2c).find('.QVqty').val();
                    var _sub = $(_a2c).find('.QVsubT');
                    $(_sub).html((_qty*_defaultST).toFixed(2));
                    $('#cart_enable').fadeIn(400,function(){$('.QVborder').height($(_QV).height()+25)});
                    adjustSoftTabHeight();
                     if(isI18NConvReq()){
		            $('.QVqtyWrap strong').remove();
		            var totalP = (_qty*_defaultST).toFixed(2);    
		            $('.QVqtyWrap').append('<strong>Subtotal: '+currencySymb+'<span class="QVsubT">'+' '+totalP+'</span></strong>');
		            $('.softAddtoCart').fadeIn(400,function(){$('.QVborder').height($(_QV).height()+25)});
		            }
                   
                   if(intShipJspChk == 'true')
                   {
                   var elem = $('li.intShip')[0];
                   var elem2 = $('li.unvIntShip')[0];
		                                 if(elem.style.display == 'none'){
		                                 		$('#cart_enable').hide(); 
		                                 }
		                                 else if(elem.style.display != 'none'){
		                      }
		                                 
		                      if(elem.style.display == 'none' && elem2.style.display == 'none'){
				      $('#cart_enable').show(); 
                              }
		   }
                    
                }else{
                   // $('.softAddtoCart').hide(); 
                    $('#cart_enable').hide(); 
                     softlinePartNum = '';
                     softlinePrice = '';
                };
                if($(changed).hasClass('qvcolor')){
                    if(!$(changed).find('.opt_sel').hasClass('default')){
                        var selcolor = $(changed).find('.opt_sel').text();
                        var matchcolor;
                        $(SEARSSOFTLINE.Item.current.attList).each(function(){
                            if(this.name == 'Color' ||  this.name == 'Overall Color'){
                                $(this.values).each(function(){
                                    if(this.cName == selcolor){
                                        matchcolor = this;
                                    };                           
                                }); 
                            };                                          
                        });  
                        if(matchcolor.mImgId != ''){
                            $('.productImage .imgnotavail').remove();
                            $('.qvPopUpLayer .slider .zzz_imgzoom:first').add('.qvPopUpLayer .slider .zzz_zoomed:first').fadeOut(800).remove();
                            $('<img/>').attr({
                                alt:SEARSSOFTLINE.Item.pTitle,
                                src:'http://s.sears.com/is/image/Sears/'+matchcolor.mImgId+'?hei='+qvImgDim+'&wid='+qvImgDim+'&op_sharpen=1&qlt=90,0&op_usm=0.9,0.5,0,0',
                                width:qvImgDim,
                                height:qvImgDim
                            }).hide().prependTo('.qvPopUpLayer .slider').fadeIn(800).imgZoom({container:'.ztBucket', src:"http://s.sears.com/is/image/Sears/"+matchcolor.mImgId+"?hei=1900&wid=1900&op_sharpen=1&resMode=sharp&op_usm=0.9,0.5,0,0", hideIt:true});
                            $('.qvPopUpLayer .slider2 img').removeClass('selected');
                            $('.qvPopUpLayer .slider2 img:first').addClass('selected').animate({opacity:1}).attr('src','http://s.sears.com/is/image/Sears/'+matchcolor.mImgId+'?hei=40&wid=40&op_sharpen=1&qlt=90,0&op_usm=0.9,0.5,0,0')
                            clickIndx = clickIndx2 = 0;
                            $('.qvPopUpLayer .slider').animate({left:"-"+(clickIndx*qvImgDim)},250);
                            $('.qvPopUpLayer .slider2').animate({left:"-"+(clickIndx2*qvThmbDim)},250);
                        }else{
                            $('.qvPopUpLayer .slider .zzz_zoomed:first').remove();
                            var tempimg = $('.qvPopUpLayer .slider .zzz_imgzoom:first').children('img').wrap('<div class="zzz_imgzoom"></div>').parents('.zzz_imgzoom');
                            $('.qvPopUpLayer .slider .zzz_imgzoom:first').replaceWith(tempimg);
                            $('<div class="imgnotavail">Image not available</div>').hide().appendTo('.productImage');
                            $(tempimg).animate({opacity:0.1})
                            $('.productImage .imgnotavail').fadeIn(800);
                            $('.qvPopUpLayer .slider2 img').removeClass('selected');
                            $('.qvPopUpLayer .slider2 img:first').animate({opacity:0.1})
                            clickIndx = clickIndx2 = 0;
                            $('.qvPopUpLayer .slider').animate({left:"-"+(clickIndx*qvImgDim)},250);
                            $('.qvPopUpLayer .slider2').animate({left:"-"+(clickIndx2*qvThmbDim)},250);
                        }
                    };
            };
            }
        }   
    }, /* QUICK VIEW */
    QuickView: {  
    "launch":function() {
     
    
    
                  //$('.drag > ul').prepend('<li><a href="#selections" onclick="s.prop26=\''+_vert+' > '+_cat+' > '+_sbcat+' >'+SEARSSOFTLINE.Item.pId+' > '+'Quick View > Selections\';s.events=\'event27\';s.product=\''+SEARSSOFTLINE.Item.pId+'\';s.tl();">Selections</a></li>');
                    
                  // $(content).prepend('<div class="selectionsTab"/>');
                 var _selects = $('.qvdropdowns');
                   //$(_selects).append(banner);
                   //if(reviewInfo){$(_selects).append(reviewInfo)};
                    //$(_selects).append(ssBase);
                //SOFTLINES CODE//////////////////////////////////////////////////////////////////////////////////////////
          var attData = SEARSSOFTLINE.Item.softData;
          var fitment = attData.prodList.prodVarList;
         
          var currentFit;
          var skuList;
          var attList;
          if(fitment.length > 1){
          fitmentExists=true;
           
          var title = $('<h3>Select:</h3>').appendTo(_selects);
          var varselect = $('<div class="fakeDD" id="qvp_var"></div>').appendTo(_selects).click(function(){
          SEARSSOFTLINE.Item.fakeDDshow(this);
          });
          $(fitment).each(function(a){
          if(a==0){
          $('<div class="opt_sel">'+this.varName+'</div>').appendTo(varselect);
          SEARSSOFTLINE.Item.current.attList = this.attList;
          SEARSSOFTLINE.Item.current.skuList = this.skuList;
           }else{
           $('<div class="opt_not_sel">'+this.varName+'</div>').appendTo(varselect);
           }
           });
           }else if(typeof fitment[0]!='undefined'){
           var varselect = $('<h4 id="qvp_var"> Fit:\t'+fitment[0].varName+'</h4>').appendTo(_selects);
           SEARSSOFTLINE.Item.current.attList = fitment[0].attList;
           SEARSSOFTLINE.Item.current.skuList = fitment[0].skuList;
           };
           SEARSSOFTLINE.Item.changeVariant();
		}
	  	
    }
    
    
    }
   /**********Test softline ends ************/
   
   
   function getCatEntId() {
	    var catEntId = "";
	    var gty_GR='';
	    if( variant == '0' ){
	    	catEntId = itemCatentryVal+'&gty_GR='+gty_GR;
	    } else if(variant=='1') {
	    	
	    	if(document.addToCart.catEntryId_1.value.length > 0 && !(document.addToCart.catEntryId_1.value == 'undefined')) {
				var qty = checkQty();				
				if(qty > 0){
				    catEntId = document.addToCart.catEntryId_1.value+'&gty_GR='+qty ;
				}
	        }
	    }
	    return catEntId;                       
	}
	
	function displayCart(storeId, catId){
		window.location.href='OrderItemDisplay?storeId='+storeId+'&catalogId='+catId+'&orderId=.';
	}
	
	
	function showPrdPage(storeId, catId,partNumber){
		window.location.href='p_'+storeId+'_'+catId+'_'+partNumber;
	}
	
	
	function updateHardlineSwatch(reference){
		var thisImg=reference;
		var relation = $(thisImg).find("img").attr("rel");
		var swatchId=relation.split("~")[0];
		var itemCatId=relation.split("~")[1];
		var swatchPNo=relation.split("~")[2];
		
		getQuickViewContent(storeIdReq, qvCatalogId, swatchPNo);		 
			
	} 	
	
	/*Fake Drop Down Select*/
	
	function selectHardLine(){
		var fakeDDshow = function(elm){
			var t;
			
			$('#fakeDDcontent').remove();
			var dd = $('<div id="fakeDDcontent"></div>').appendTo('.qvPopUpLayer');
			
			$(elm).children('div').each(function(){
				if($(this).is('.disabled')){
					$('<div class="notAvail">'+$(this).html()+'</div>').appendTo(dd);   
				}else{
					$('<div>'+$(this).html()+'</div>').appendTo(dd);
				}
			});
			
			if($(dd).children().length > 10){
				$(dd).css({
					height: 175,
					overflow:'auto'
				}); 
			};
			
			$('#fakeDDcontent div').hover(function(){
				$(this).addClass('hover');                                 
			},function(){
				$(this).removeClass('hover');
			});
			
			$(dd).css({
				top:    (($(elm).offset().top - $(elm).parents('.qvPopUpLayer').offset().top)),
				left:   (($(elm).offset().left - $(elm).parents('.qvPopUpLayer').offset().left))
			}).show().mouseout(function(){
				t = setTimeout(function(){
					$(dd).remove();                       
				},400); 
			}).mouseover(function(){
				clearTimeout(t) ;
			});
	
			$(dd).find('div').each(function(){
				var val = $(this).text();
				var _this2=$(this);
				$(elm).children('div').each(function(){
					if($(this).text() == val ){
						var _this3=$(this);
						$(_this2).click(function(){
							updateHardlineSwatch(this);
							$(_this3).parent().find("div").attr('class','opt_not_sel');
							$(_this3).attr('class','opt_sel');
							var aaqq=1;
						});
						
					}					
				});
					
			});
	    };
	
		$('.fakeDD').click(function(){
			var d = $(this)
			fakeDDshow(d);
		});
	
	}
	
	
	
	
/*CSS and JS functionalites after QV ajax call starts*/
	
	
function attachImgEvents(){
	var qvImgDim = 248;
	var qvThmbDim = 40;
	var qvThmbDim2 = 100;
	var jspStoreImgDir='';
	
	var itmWgts = $('.productImage');	
	var nonZoom = $('.scrollWsmall');
	var slider = $(itmWgts).find('.slider');
	var slider2 = $(itmWgts).find('.slider2');
	var sliderThumbs = $(slider2).children('img');
	
	if(zoomedImg == null){
		zoomedImg = new Image();
	}
	
		
	slider.width((slider.children('img').eq(0).width()+10)*(slider.children('img').size()));
			
	$(slider2).find('img').eq(0).addClass('selected');

	var scrlWgt = $('.scrollWidget');
	var clickIndx=0, clickIndx2=0;
	var curImg = imgArr[clickIndx];
	
	$(slider).children('img').each(function(i){
		var zImgTemp = imgArr[i];
		if(zImgTemp.widthImg>2000){zImgTemp.widthImg=2000};
		if(zImgTemp.heightImg>2000){zImgTemp.heightImg=2000};
		/* ========================================================================
		
			For the imgZoom function to work at its best, the maximum zoomed
			image dimension should vary depending on the maximum size of the
			full-resolution image on the Scene7 system. In this EXAMPLE, we
			are passing a hard-coded dimension, because the images are not
			being served from a JSON string. JSON is the preferred method of
			populating the image gallery interface for QuickView and all
			Product pages.
		
		======================================================================== */

		
				$(this).imgZoom({container:'.ztBucket', src:"http://s.sears.com/is/image/Sears/"+zImgTemp.name+"?hei="+zImgTemp.heightImg+"&wid="+zImgTemp.widthImg+"&op_sharpen=1&resMode=sharp&op_usm=0.9,0.5,0,0", hideIt:true});
		
	});
	
	// the following code contains the controls for the image slide show / viewer

	highlightThumb = function(){
		$(sliderThumbs).each(function(){
			$(this).removeClass('selected');
		});
		$(sliderThumbs[clickIndx]).addClass('selected');
	};
	$(".pImg").click(function(){
		clickIndx--;
		if(clickIndx < 0){clickIndx = 0; return false};
		$(slider).animate({left:"-"+(clickIndx*qvImgDim)},250);
		highlightThumb();
		return false;
	});
	$(".nImg").click(function(){
		clickIndx++;
		if(clickIndx >= imgArr.length){clickIndx--; return false};
		$(slider).animate({left:"-"+(clickIndx*qvImgDim)},250);
		highlightThumb();
		return false;
	});
	$(".c_pImg").click(function(){
		clickIndx2--;
		if(clickIndx2 < 0){clickIndx2 = 0; return false};
		$(slider2).animate({left:"-"+(clickIndx2*qvThmbDim)},250);
		return false;
	});
	$(".c_nImg").click(function(){
		clickIndx2++;
		if(clickIndx2 >= (imgArr.length-3)){clickIndx2--; return false};
		$(slider2).animate({left:"-"+(clickIndx2*qvThmbDim)},250);
		return false;
	});
	$(sliderThumbs).each(function(i){
		$(this).click(function(){
			clickIndx = i;
			$(this).siblings().removeClass('selected');
			$(this).addClass('selected');
			$(slider).animate({left:"-"+(clickIndx*qvImgDim)},250);
			return false;
		})
	});
	/*To show reviews when reviews option is selected*/
		var reviewTag=0;
	/*To go to review section when review link is clicked in title section*/
	
	$(".rating .starrating,  .rating a").click(function(){
		$("div#tabs > ul").find("li").each(function(i){
			  var textVal=$(this).text();
					//$('#tabs').tabs('select', i+1);
				if(textVal=='Reviews'){
				   reviewTag=i;
				}
		});
		$('#tabs #reviews .qvContentHeader .rating a').replaceWith($('#tabs #reviews .qvContentHeader .rating a').text());
		if($("#tabs > ul > li >a[href='#reviews']").parent().attr('class')=='ui-tabs-selected')
		{
			//window.location.href='p_'+storeIdReq+'_'+qvCatalogId+'_'+qvPartnumber;
		}
		else{
			$('#tabs').tabs('select',reviewTag);
			if(storeIdReq == '10154'){
			  	callBazaarVoice();
			}else{
			ViewpointsReviewsWidget(); 
			}
			
		}
		return false;
	});
				
	$("div#tabs > ul").find("li").each(function(i){
				$(this).children().click(function(){
					  var textVal=$(this).text();
					  var reviewTag=0;
						//$('#tabs').tabs('select', i+1);
					if(textVal=='Reviews'){
					  var reviewTag=1;
					  $('#tabs #reviews .qvContentHeader .rating a').replaceWith($('#tabs #reviews .qvContentHeader .rating a').text());
					  if(storeIdReq == '10154'){
					  	callBazaarVoice();
					  }else{
						ViewpointsReviewsWidget(); 						
					}
					}
					if(textVal!='Selections'){
					$('div#fakeDDcontent').css("display","none");
					}
					else
					{
					$('div#fakeDDcontent').css("display","block");
					
					}
					if(textVal=='Description'){
						if($('.comesWith > span').length=='0'){
				      		$('.comesWith > h4').text('');
						}
					}	
			return false;
				});	
	});
	
	
	/* Logic to hide Get this Product label starts */
	
	
	var showFlag = $('input#showFlag').attr('value');
	if(showFlag == '1'){
	$('#getProduct').css('display','block');
	}
	/* Logic to hide Get this Product label ends */
	
	/*To show or hide comes with section for manual depending on the availability of manuals*/
	/*Shows and hides the tabs according to the options selected from Know it all section in overview part*/
	$("div#knowledge").find("span").each(function(i){
		$(this).click(function(){
			
			var textVal=$(this).text();
			$('#tabs').tabs('select', i+1);
			if(textVal=='Reviews'){
				$('#tabs #reviews .qvContentHeader .rating a').replaceWith($('#tabs #reviews .qvContentHeader .rating a').text());
			}
			return false;
		});			
	});
}

function adjustTabHeight(){

	/*Sets height so that tabs stay the same height from content in the overview tab*/
	var side = $('.qvContentSide').height();
	var main = $('.qvContentMain').height();
	var product_image = $('div.productVisual').height();
	var content_header = $('div.qvContentHeader').height();


	if( $.browser.msie ) {
	var qvHeight = $('div.popContent').height()-80;
	}else{
	var qvHeight = $('div.popContent').height()-40;
	}

	$('div.qvContentWrap').css('height', qvHeight+'px');
	$('.ui-tabs-panel').css('height', qvHeight+'px');

	if (side > main) {
	$('div.qvContentMain').css('height', side+'px');
	$('div.qvContentSide').css('height', side+'px');
	}else {
	$('div.qvContentMain').css('height', main+'px');
	$('div.qvContentSide').css('height', main+'px');
	}

	var content_wrap = $('div.qvContentWrap').height();

	if (product_image > content_wrap) {
	$('div.qvContentMain').css('height', (product_image - content_header)+'px');
	$('div.qvContentSide').css('height', (product_image - content_header)+'px')
	}
	
	var contentWrapHt=$('div.qvContentHeader').height();
	var contMnHt=$('.qvContentMain').height();
	var contSdHt=$('div.qvContentSide').height();
	
	if($.browser.msie ){
		if (contSdHt > contMnHt) {
			$('div.qvContentWrap').css('height', contSdHt+contentWrapHt+25+'px');
			$('.ui-tabs-panel').css('height', contSdHt+contentWrapHt+25+'px');
		}else{
			$('div.qvContentWrap').css('height', contMnHt+contentWrapHt+25+'px');
			$('.ui-tabs-panel').css('height', contMnHt+contentWrapHt+25+'px');
		}
	}
	
	$('table.qvProductSpecs tr').find('td:first').addClass('rightAlign');
	/*makes zoom work in ie6*/
	if( $.browser.msie && ($.browser.version == 6) ) {
		var mainHeight = $('.qvContentWrap').height();
		$('.ztBucket').css('height',mainHeight+'px')

	}
	$('li#addItem').addClass('qvAddedItem');
}

var softStatus = 0;
function adjustSoftTabHeight(){
	var softline = $('#selections');
	if (softline.length && softStatus== 0){
		var tempHeight= $('.qvContentMain').height()+55;
		$('.qvContentMain').css('height',tempHeight+'px');
		if( $.browser.msie && ($.browser.version == 6) ){
			tempHeight= $('#wrap').height();
		} else{
			tempHeight= $('#wrap').height()+35;
		}
		$('#wrap').css('height',tempHeight+'px');
		softStatus = 1;
	}	
}


function readyCloseQV(trueModal){
	if (trueModal != 'forced'){
		$('.qvPopUpLayer .closeWin').click(function() {
				 closePopUpLayerQV();
		});
		$('.qvPopUpLayer').click(function(event){
				 event.stopPropagation();
		}); 
	}//end trueModal condition
	else{
		$('body').prepend('<div class="curtainQV"></div>');
		$('.curtainQV').fadeTo(300, .50);
		$('.curtainQV').height( $('body').height() +100 );
		$('.qvPopUpLayer .closeWin').click(function() {
				 closePopUpLayerQV();
		});
	}
	
}

function closePopUpLayerQV(){

	zoomedImg=null;
	$(".qvPopUpLayer").fadeOut('fast', function(){$(this).remove();});
	$(".curtainQV").remove();
	flagQV = 'N';
}

/*Align Quick View Pop up in the broswer window*/
function qvAlignment(){

	if($.browser.msie){
		var qvTop= ( $(window).height() - $('div.qvPopUpLayer').height() ) / 2+$(window).scrollTop();
		qvTop=qvTop+250;
		$('div.qvPopUpLayer').css("top", qvTop+ "px");
		
	}else{
		$('div.qvPopUpLayer').css("top", ( $(window).height() - $('div.qvPopUpLayer').height() ) / 2+$(window).scrollTop() + "px");
	}
	
	$('div.qvPopUpLayer').css("left", ( $(window).width() - $('div.qvPopUpLayer').width() ) / 2+$(window).scrollLeft() + "px");
}
/*CSS and JS functionalites after QV ajax call ends*/	

function displayErrorMessage(){
// yet to do
}

/* Code changes for Lay away */
var fromProductPg = null;
function getLayawayCalDetails2(){
var catentryIdValues = getCatEntryIds();
var regionalZip = $('#layawayPopup div:visible #checkZipText2').val();
globalZipCode = regionalZip;
var layAwayFlag = "true";
	fromProductPg=true;
		var layawayUrl="LayawayCmd?currPrice="+currPriced+"&partNumber="+partNum+"&storeId="+storeId+"&zipCode="+regionalZip+"&layAwayFlag="+layAwayFlag+"&seasonalInd="+seasonalInd+"&cmdStoreId=" + cmdStoreId +"&pickupStoreId=" + pickupStoreIdC + "&langId=-1&"+"&fromProductPage=" + fromProductPg+'&sCriteria=LWS'+'&startFrom=0'+'&isAjax=true'+"&catalogId="+catalogId+
		"&layawayStartDate="+layawayStartDate+"&layawayEndDate="+layawayEndDate; 
	$("#loadImg").css("visibility", "visible");
	request=$.getJSON(layawayUrl,fnLayAwaySuccess);
}

function checkLayAwayZip2()	{
  var regionalZip = $('#layawayPopup div:visible #checkZipText2').val();
  var lv_pattern = /^\d{5}$|^\d{5}\-?\d{4}$/;
  var passed = lv_pattern.test(regionalZip); 
  if (!passed) {
        showLayErrorMsg();
    return false;
	}else {
    return true;
  }
}

function showLayErrorMsg(){
	var validatePopup = "<div id='validatePopup' class='layAwayValidatePopup'>"
							+"<h3>Enter Zip Code</h3>\n"
							+"<h2>Please enter a valid 5-digit ZIP code (example: 60515).</h2>"
							+"\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);' style='margin-bottom:10px'>\n";
		$('#layawayPopup').append(validatePopup);
}

var globalIntArr = null;
var globalPageNo = 1;

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(fromProductPg == 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 fnLayAwaySuccess(response){
	//var response = eval('(' + response + ')');
	$("#loadImg").css("visibility", "hidden");
var initialFee= "";
	var downPayment= "";
	var contractValue= "";
var installmentarray="";
var address = response.storeAddress;
var successResponse = address.split('#')[0];
	if(successResponse =="Success"){
//Code for success

if(response != null && response.initailFee !=null && response.initailFee !=""){
initialFee =  response.initailFee;
}
		if(response != null && response.downPayment !=null && response.downPayment !=""){
			downPayment =  response.downPayment;
		}
		if(response != null && response.contractValue !=null && response.contractValue!=""){
			contractValue =  response.contractValue;
		}
if(response != null && response.installments !=null && response.installments !=""){
	installmentarray = response.installments;
}


//response.installments[1].dueAmount
var installmentMsg ='';
var firstInstallment = '';
			if(typeof(installmentarray) != 'undefined' && installmentarray != null && installmentarray != ""){
			globalIntArr = installmentarray;
			globalPageNo=1;
			var installmentMsg = fnGetInstPageData();
			$('ul.schedule').html(installmentMsg);
}

	var location = address.split('#')[3];
	var location1 = address.split('#')[4];
	var initailFeeMsg = '';
	var address1Msg='';
	var address2Msg='';
	var zipCodeMsg='';
		var downPaymentMsg='';
		var totalContactValue='';
		var fullStoreAddress='';
	if(initialFee != null && initialFee!=""){
		initailFeeMsg+='<label for="layZip1">Initial fee:</label><strong>$'+initialFee+'</strong>';
	$('li#initial').html(initailFeeMsg);
	$('li#initial').css("margin-right","0px");
	}
			if(downPayment != null && downPayment!=""){
				downPaymentMsg+='Down Payment Due Today:<strong>$'+downPayment+'</strong>';				
				$('li#downPayment').html(downPaymentMsg);
			}
			if(contractValue != null && contractValue!=""){
				totalContactValue+='<strong>Total contract amount: <span> $'+contractValue+'</span></strong>';				
				$('span#totalContract').html(totalContactValue);
			}
	if(location !=null && location!=""){
			address1Msg+='<span id="address1">'+location+'</span>';
	$('#PickupStoreMsg').removeClass('hidden')
			fullStoreAddress+=address1Msg;
	}
	if(location1 !=null && location1!=""){
		address2Msg +='<span id="address2">'+location1+'</span>';
		//$('span#storeAddress').html(address2Msg);
		//$('span#errorSpan').remove();
		fullStoreAddress+=address2Msg;
		$('li#error2').remove();
	}
	
		//displaying the full address of the store
		$('span#storeAddress').html(fullStoreAddress);
		
	if(globalZipCode != null && globalZipCode!=""){
	
	zipCodeMsg+=' <span class="selZIP">'+globalZipCode+'</span>   <a id="layAwayChangeZIP" href="#" style="margin-left: 20px;">change</a>';
		$('#checkZipText2, #checkZipHidden, #loadImg').addClass('hidden')
	
	$('span#checkLowerZip').html(zipCodeMsg);
	}
	
	$('#layAwayChangeZIP').click(function(){
				$('#checkZipText2, #checkZipHidden , #loadImg').removeClass('hidden')
			$(this).hide()
			return false
		})
//Code for success ends	
}	

	
	//ECOM-43179
	
	if(successResponse !="Success"){
			//Removing the store address from the jsp
			$('#PickupStoreMsg').addClass('hidden')
			$('span#address1').remove();
			$('span#address2').remove();
		
			//Adding the error message
			var errorMsg='<li id="error2" class="error"> We are sorry, but we cannot find a store with Layaway within 50 miles of that ZIP </li>';
			$('span#errorSpan').addClass('error');			
			$('span#errorSpan').html(errorMsg);
		}
	
	}

function layawayClick(){
	var currPrice= '';
	var partNum = '';
    if(variant == '1'){
    	currPrice = softlinePrice;
    	partNum = softlinePartNum;
    }
    if(variant == '0'){
    	currPrice = hardlinePrice;
    	partNum = partnumber;
    }
	fromProductPg=true;
	var orderId="";
	var address1="";
	var address2="";
	var zipCode="";
	var catentryIdValues = getCatEntryIds();
	var catentry=getCatEntId();
	var catentryZero=getCatEntId().substring(0,1);
	if(currPrice == ''){
		currPrice=0.00;
	}
	
	var layawayStartDate="";
	var layawayEndDate="";
	if(typeof(startDate) != "undefined" && startDate != '' && startDate != null){
		layawayStartDate = startDate;
	}
	
	
	var imageId = $('input#imageId').attr('value');
	var prdTitle = $('input#prdTitle').attr('value');
	
	
	if(typeof(endDate) != "undefined" && endDate != '' && endDate != null){
		layawayEndDate = endDate;
	}
	
	if (catentry != '' && catentryZero != null && catentryZero != "undefined") {
		
		layawayPopup({type:'modal', id:'layawayPopup', Class:'searsPopup', closeTxt:'Close', addContent:		
function (){
	$('<div class="content" style="padding:0px !important;"/>').appendTo('#layawayPopup');
	$.ajax({
		url: 'LayawayJsp?currPrice='+currPrice+'&partNum='+partNum+'&seasonalInd='+seasonalInd+'&storeId='+storeId+'&imageId='+imageId+'&fromProductPage='+ fromProductPg+'&orderId='+ orderId+'&layawayStartDate='+ layawayStartDate+'&layawayEndDate='+ layawayEndDate,
		timeOut:50000,
		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'});
		}
		}
	);
}
		
			});
	} else{
		var addToCartMsg = 'Please select a Color/Size';
            var object = document.getElementById("layCalcLink"); 
		showErrorMsgPopUpBox(object,addToCartMsg,'LayawayCalculator');
            return false;
        }		
}



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(){

//Changing the dzName to W4 from A4 for staging
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(){
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);
}
/**************** Save For later Logic Starts ****************/

//On click of Wishlist link in the in the Save to List dropdown
function productWishlist(objImg){
	//var userType = '<c:out value="${userType}"/>';

        var qty=1;
        var grUserType = getCookie('GiftRegApp'+storeIdReq);
        var catEntryIds = getCatEntryIds();
        var catEntryIdScim = getCatEntId();
        object = document.getElementById("saveToList"); 
   		leftVal = findPos(object)[0];
	 	topVal  = findPos(object)[1];
        /*mainUrl is constructed to be passed as parameter to GiftRegistryDisclaimer page from popupWishlistSubmit function*/
        if(catEntryIdScim == '' || catEntryIdScim == 'undefined' || catEntryIdScim == 0){
			var strURL = document.location.search;
    
			if (strURL.search("catEntryIdScim") != -1){
			    
			    var temp=new Array();
			    temp=strURL.split("&");
			    for(var i=0;i<temp.length;i++){
			        if(temp[i].search("catEntryIdScim") != -1){
			        catEntryIdScim=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
			    	}
			    }			
			}
        }
        
        mainUrl="partNumber="+partnumber;
        if(grUserType != ""){
            mainUrl = mainUrl + '&grUserType='+grUserType;
        }
        if(catEntryIdScim != '' && catEntryIdScim != "undefined"){
            mainUrl = mainUrl + catEntryIds;
        }
        var ProductUrl = 'SHCGiftRegistryProductDetailsCmd?storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&wishListId=1&URL=ProductDisplay&partNumber='+qvPartnumber+'&catEntryIdScim='+catEntryIdScim; 
        if(variant == '1'){
          qty = checkQty();
		}
        if (qty >0){
            if(catEntryIdScim != '' && catEntryIdScim != "undefined" && catEntryIdScim != 0){
			     Load.style.display = "block";
                 ajaxCall(ProductUrl,'getProductStatus');   
            }else{
                var mesg = 'Please make any available size and color selections before adding this item to a Wishlist';
                showErrorMsgPopUpBox(object,mesg,'Wishlist');
            }
         }else{
             var mesg = 'Quantity must be a positive number.  Please enter the quantity again.';
             showErrorMsgPopUpBox(object,mesg,'Wishlist');
        }    
}

//On click of the Save to Registry link in the Save to List dropdown
function productRegistry(objImg){

    //var userType = '<c:out value="${userType}"/>';    
        var url = "";
        var qty=1;
        var grUserType = getCookie('GiftRegApp'+storeIdReq);
        catEntryIds = getCatEntryIds();
        catEntryIdScim = getCatEntId();
        object = document.getElementById("saveToList"); 
   		leftVal = findPos(object)[0];
	 	topVal  = findPos(object)[1];
        if(catEntryIdScim == '' || catEntryIdScim == 'undefined' || catEntryIdScim == 0){
            var strURL = document.location.search;
			if (strURL.search("catEntryIdScim") != -1){
			    var temp=new Array();
			    temp=strURL.split("&");
			    for(var i=0;i<temp.length;i++){
			        if(temp[i].search("catEntryIdScim") != -1){
			        	catEntryIdScim=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
			    	}
			    }			
			}
        }
        
        url = 'AddToGiftRegistry?storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&grUserType=' + grUserType;
        mainUrl="partNumber="+qvPartnumber;
        if(grUserType != ""){
            mainUrl = mainUrl + '&grUserType='+grUserType;
        }
        if(catEntryIdScim != '' && catEntryIdScim != "undefined"){
            mainUrl = mainUrl + catEntryIds;
        }
        var ProductUrl ="";
        if (objImg == "gt" )
        {
        	 ProductUrl = 'SHCGiftRegistryProductDetailsCmd?isGiveTogether=true&storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&URL=ProductDisplay&partNumber='+qvPartnumber+'&catEntryIdScim='+catEntryIdScim; 
        	}
		else {
			ProductUrl = 'SHCGiftRegistryProductDetailsCmd?isGiveTogether=false&storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&URL=ProductDisplay&partNumber='+qvPartnumber+'&catEntryIdScim='+catEntryIdScim; 
		}
        if(variant == '1'){
          qty = checkQty();
        }
        if (qty >0){
            
            if(catEntryIdScim != '' && catEntryIdScim != "undefined" && catEntryIdScim != 0){
                 Load.style.display = "block";
                 ajaxCall(ProductUrl,'getProductStatus');   
                
            }else{
                var mesg = 'Please make any available size and color selections before adding this item to a Gift Registry';
                showErrorMsgPopUpBox(object,mesg,'GiftRegistry');
            }
        }else{
             var mesg = 'Quantity must be a positive number.  Please enter the quantity again.';
             showErrorMsgPopUpBox(object,mesg,'GiftRegistry');
        }
	}

//On click of the Save for Later link in the Save to List dropdown
function productSaveLater(objImg){
	object = document.getElementById("saveToList"); 
	if(variant == '1'){
       if(document.addToCart.catEntryId_1.value == 'undefined' || !(document.addToCart.catEntryId_1.value.length > 0)) {
            var mesg = 'Please make any available size and color selections before adding this item to a list';
            showErrorMsgPopUpBox(object,mesg,'save for later');
            return;
        }
        var qty = checkQty();
        if(!(qty>0)){
            var mesg = 'Quantity must be a positive number.  Please enter the quantity again.';
            showErrorMsgPopUpBox(object,mesg,'save for later');
            return;
        }
    }    
	var catEntryIds = getCatEntryIds();
	var catEntryIdScim = getCatEntId();
    var url="AddToWishlist?langId=-1&storeId="+storeIdReq+"&catalogId="+qvCatalogId+"&partNumber="+qvPartnumber+"&URL=AddToWishListSuccessView&errorViewName=AddToWishListErrorView&redirectView=AddToWishListRedirectView";

    var grUserType = getCookie('GiftRegApp'+storeIdReq);
    
    if(grUserType != ""){
        url = url + '&grUserType='+grUserType;
    }

    if(catEntryIdScim != '' && catEntryIdScim != "undefined"){
        ajaxCall(url + catEntryIds,'returnSaveForLater','','');
    }else
    {
        var mesg = 'Please make any available size and color selections before adding this item to a list';
        showErrorMsgPopUpBox(object,mesg,'save for later');
    }   
}

/*
Function called after the ajaxCall completes execution on clicking
of add to Save for Later link
*/
function returnSaveForLater(value){
    
    if(storeId == 10156){
		object = document.getElementById("saveToListTGI"); 
	}else{
    object = document.getElementById("saveToList");
	}
    flag = '';
    if(value == "Success"){
        if(document.getElementById("remembered")!=null){
           var remem = document.getElementById("remembered").value;
           if(remem=="yes")
               flag = 'error8';
         }
        else        
          flag = 'error6';
          SaveToOpsErrorPopUpBox(object,flag);
    }else if(value == "Redirect"){
        showLogonForm();
    }else{
		//wishlistExceptionMessage is used in getErrorStatus() while displaying the error msg pop-ups
        wishlistExceptionMessage = value;
        SaveToOpsErrorPopUpBox(object,flag);
    }
        
}

/*
Function called after the ajaxCall completes execution on clicking
of Add to Registry link and Add to Wishlist link in the Save to List dropdown
*/
function getProductStatus(value){

    var qty_GR='';
    var actionStatus=value.substring(0,8);
    if((actionStatus == "registry")||(actionStatus == "wishlist")){
	    var RegistryType=value.substring(0,8);
	    var catEntryIdScim=value.substring(8,value.length);
	    if(variant == '1'){
	          qty_GR = checkQty();
	    }
        location.href = "GiftRegistrySignOnView?storeId="+storeIdReq+"&catalogId="+catalogId+"&URL=ProductDisplay&partNumber="+partnumber+"&catEntryIdScim="+catEntryIdScim+"&RegistryType="+RegistryType+"&fromCreate=productPage&qty_GR="+qty_GR;
    }else{

	    flag = value;
	    newDiv=document.createElement('div');
        newDiv.className='errorPop';
        newDiv.id='errorBox';
        newDiv.innerHTML=value;
        document.body.appendChild(newDiv);
        Load.style.display = "none";
        var errBox=document.getElementById('errorBox');
        var oy = topVal;
        var ox = leftVal;
	    if(browser=="Internet Explorer"){
            var docWidth=document.body.scrollWidth;
            var docHeight=(document.body.scrollHeight);
            var boxH=errBox.offsetHeight;
            var boxW=errBox.offsetWidth;
	        if ((ox-100)<0){
	            errBox.style.top=(oy-350)+"px";
	            errBox.style.left=(ox-40)+"px";
	            document.getElementById('errorBox').focus();
	        } 
	        else if ((ox-100)>(docWidth-boxW)){
	            errBox.style.top=(oy-100)+"px";
	            errBox.style.left=(docWidth-boxW-10)+"px";
	            document.getElementById('errorBox').focus();
	        } 
	        else{
	            errBox.style.top=(oy-150)+"px";
	            errBox.style.left=(ox-100)+"px";
	            document.getElementById('errorBox').focus();
	        }
	    }else {
		    var docWidth=document.documentElement.clientWidth;
		    var docHeight=document.documentElement.clientHeight;
		    var boxH=errBox.offsetHeight;
		    var boxW=errBox.offsetWidth;
	        if ((ox-100)<0) {
	            errBox.style.top=(oy-100)+"px";
	            errBox.style.left=(ox)+"px";
	            document.getElementById('errorBox').focus();
	        } 
	        else if ((ox-100)>(docWidth-boxW)){
	            errBox.style.top=(oy-100)+"px";
	            errBox.style.left=(docWidth-boxW-10)+"px";
	            document.getElementById('errorBox').focus();
	        } 
	        else{
	            errBox.style.top=(oy-100)+"px";
	            errBox.style.left=(ox-100)+"px";
	            document.getElementById('errorBox').focus();
	        }
	    }
    }
}

/*
 * Function called when the user is guest and had clicked on add to wishlist. This function is
 * is called after the first ajax call is made. We pass a parameter guest=1 which differentiates a 
 * a user who has already regsitered and is browsing and the guest user who had just clicked on
 * add to wishlist button.
 */
function showLogonForm() {   
    
    var logonUrl = "LogonForm?langId=-1&storeId="+storeIdReq+"&catalogId="+qvCatalogId+"&URL=";
    var addToWishlistUrl = "AddToWishlist?langId=-1&storeId="+storeIdReq+"&catalogId="+qvCatalogId+"&partNumber="+qvPartnumber+"&productURL="+productURL+"&guest=1&";
    var vertical = gup('vName');
    var category = gup('cName');
    var subcategory = gup('sName');
    var grUserType = getCookie('GiftRegApp'+storeIdReq);
    
    if(grUserType != "")
        addToWishlistUrl = addToWishlistUrl + '&grUserType='+grUserType;
    if(vertical !="")
        addToWishlistUrl = addToWishlistUrl + '&vName='+vertical;
    if(category !="")
        addToWishlistUrl = addToWishlistUrl + '&cName='+category;
    if(subcategory !="")
        addToWishlistUrl = addToWishlistUrl + '&sName='+subcategory;
    
    var catEntryIds = getCatEntryIds();
    addToWishlistUrl = addToWishlistUrl+catEntryIds;
    addToWishlistUrl = enCodeUrl(addToWishlistUrl);
    window.location = logonUrl+addToWishlistUrl;
    
}


/**************** Save For later Logic Ends ****************/	

//Code for save for later
	function initializeSaveLaterVar(){
		var qe_popup = $('\n'
	+'<div id="quant_error" style="display:none;">\n'
	+'	<div class="border"></div>\n'
	+'	<div class="content"></div>\n'
	+'</div>\n').hide().appendTo('body');
	
	$('#saveToList').click(function(){
		var _this = $(this);
		var off = $(this).offset();
		var ht = $(this).height()+12;
		var wd = $(this).width()+16;
		var timer1 = 0;
		var dd = $('#saveToOpts');
		_this.addClass('active');
		if(dd.length == 0){
			var code = $('\n'
			+ '<ul id="saveToOpts" style="display: none;">\n'
			+ '	<li><a href="javascript:;">Save to Wishlist</a></li>\n'
			+ '	<li><a href="javascript:;">Save to Registry</a></li>\n'
			+ '	<li class="last"><a href="javascript:;">Save for Later</a></li>\n'
			+ '</ul> \n').appendTo('body').fadeIn(500).css({top:off.top+ht, left:off.left});
			code.hover(function(){
				clearTimeout(timer1)					
			},function(){
				timer1 = setTimeout(function(){
					code.fadeOut(500,function(){
						$(this).remove();
						_this.removeClass('active');
					});							
				},600)
			});
			var actions = code.find('a');
			actions.click(function(){
				code.fadeOut(100,function(){
						$(this).remove();
						_this.removeClass('active');
					});
				var optionSelected = $(this).text();
				if(optionSelected == 'Save to Wishlist'){
					productWishlist();
				}else if(optionSelected == 'Save to Registry'){
					productRegistry();
				}else if(optionSelected == 'Save for Later'){
					productSaveLater();
				}
							
				if($('#quant').val() == 0){
					qe_popup.css({top:off.top, left:off.left}).find('.content').append('<h2>Save to List</h2><p>Please specify the quantity (Qty) before adding to wishlist.</p><img src="http://c.sears.com/1112/img/buttons/okay_btn.gif" alt="OK" class="cancelMod"/>')
					qe_popup.show().find('.cancelMod').click(function(){
						qe_popup.hide().find('.content').empty();										
					})
				}				   
			});
		}else{
			if(dd.is(':visible')){
				dd.fadeOut(500);	
				_this.removeClass('active');
			}else{
				
				dd.fadeIn(500);	
			}	
		}
		return false;
	});
	//Save To List for TGI
	$('#saveToListTGI').click(function(){
	
		var _this = $(this);
		var off = $(this).offset();
		var ht = $(this).height()+12;
		var wd = $(this).width()+16;
		var timer1 = 0;
		var dd = $('#saveToOpts');
		_this.addClass('active');
		if(dd.length == 0){
			var code = $('\n'
			+ '<ul id="saveToOpts" style="display: none;">\n'
			
			+ '	<li><a href="javascript:;">Save for Later</a></li>\n'			
		
			+ '</ul> \n').appendTo('body').fadeIn(500).css({top:off.top+ht, left:off.left});
			code.hover(function(){
				clearTimeout(timer1)					
			},function(){
				timer1 = setTimeout(function(){
					code.fadeOut(500,function(){
						$(this).remove();
						_this.removeClass('active');
					});							
				},600)
			});
			var actions = code.find('a');
			actions.click(function(){
				code.fadeOut(100,function(){
						$(this).remove();
						_this.removeClass('active');
					});
				var optionSelected = $(this).text();
				if(optionSelected == 'Save to Wishlist'){
					productWishlist();
				}else if(optionSelected == 'Save to Registry'){
					productRegistry();
				}else if(optionSelected == 'Save for Later'){
					productSaveLater();
				}else if(optionSelected == 'Add To Give Together List'){
					productRegistry("gt");
	}

				if($('#quant').val() == 0){
					qe_popup.css({top:off.top, left:off.left}).find('.content').append('<h2>Save to List</h2><p>Please specify the quantity (Qty) before adding to wishlist.</p><img src="http://c.sears.com/1112/img/buttons/okay_btn.gif" alt="OK" class="cancelMod"/>')
					qe_popup.show().find('.cancelMod').click(function(){
						qe_popup.hide().find('.content').empty();										
					})
				}				   
			});
		}else{
			if(dd.is(':visible')){
				dd.fadeOut(500);	
				_this.removeClass('active');
			}else{
				
				dd.fadeIn(500);	
			}	
		}
		return false;
	});
	}

function enCodeUrl(url){
    
    var strValue = "";
    var urlLen = url.length;
     for(var i=0;i<urlLen;i++){         
        var ch = url.charAt(i);
        if(ch=="="){
            strValue = strValue + "%3d";
        }
        else if(ch=="&")
        {
            strValue = strValue + "%26";
        }
        else{
            strValue =  strValue + ch;
        }
    }
    return strValue;
}

/* Code changes for Lay away ends*/


function urlforShipCal(objImg){ 
 
    var catEntryId = getCatEntId();
    var flag = '2';
    var qty = getQuantity();
    var  catEntry;    
    if(catEntryId != ''){
        catEntry = catEntryId.split('&'); 
    }
    
    if(qty != '' && (isNumeric(qty) == 0) && (qty > 0) ){
        if (catEntryId != '' && catEntry[0] != null && catEntry[0]!= "undefined") {
            var langId = -1;
            var str = qvCmdStrId;
            url = "SCShippingCostView?storeId="+storeIdReq+"&catalogId="+qvCatalogId+"&langId=" + langId + "&id=" + catEntryId + "&flag=" + flag + "&qty=" + qty + "&cmdStoreId=" + str ;
            window.open(url,null,"width=700,height=350,location=no,scrollbars=yes,toolbar=yes,toolbar=no,status=no,menubar=0");
        }
        else{
            var addToCartMsg = 'Please make a selection.';
              
            showErrorMsgPopUpBox(objImg,addToCartMsg,'ShipCal');
            return;
        }
    }
    else{   
        var addToCartMsg = 'Quantity must be a positive number.  Please enter the quantity again.';
        showErrorMsgPopUpBox(objImg,addToCartMsg,'ShipCal');
        return;
    }
}

function getQuickViewContent(storeIdReq, qvCatalogId, swatchPNo){
	 var quickViewURL='QuickViewCmd?storeId='+storeIdReq+'&catalogId='+qvCatalogId+'&partNumber='+swatchPNo;
         var options = { 
        success: displayQuickViewContent,
        url:quickViewURL,
        type:'GET'
    };                        
    request=$.ajax(options)
    options="";
}

function displayQuickViewContent(data){

	$(".qvPopUpLayer").remove(); //remove any previous instances of this window.
	$('body').append('<div class="qvPopUpLayer"></div>'); //add the div onto the bottom of the page
	$(".qvPopUpLayer").hide();
	$(".qvPopUpLayer").html(data);
	$(".qvPopUpLayer").fadeIn('fast');
	$('div.qvPopUpLayer').css("width", "820px");
	$('#tabs').tabs();
	var count=0;
	$('#actionsForm span').each(function(){
		count += 1;
	});
	if(count == 1){
		$('#actionsForm span').attr('style','display:none');
		if($('#actionsForm span input').val() != 'ship' && ($('#actionsForm small#pd_shippingCal_msg') != null && $('#actionsForm small#pd_shippingCal_msg')!= undefined)){
			$('#actionsForm small#pd_shippingCal_msg').attr('style','display:none');
		}
	}
	$(".qvPopUpLayer").show();
	qvAlignment();	
	readyCloseQV();	
	attachImgEvents();
	initializeVar();
    onload_IntShipping();
	adjustTabHeight();
	return false;

}

/* function to add to cart from QV through db call */
function fnSearsDBAddToCartNew(jsonResponse){
	var regavail = jsonResponse.jsonRegionalAvail; 
	var partNoLen=regavail.pco;
	if(typeof regavail != 'undefined'){
		for(var availCnt=0;availCnt<partNoLen;availCnt++){
			if(regavail.regAvailList[availCnt].pn==SEARS.Item.pId){
				if(regavail.regAvailList[availCnt].msg=="InStock" || regavail.regAvailList[availCnt].msg==""){
					$('div#availPopup').remove();
					
					var childCatId =document.addToCart.catEntryId_1.value;
					var itemA = document.addToCart.IndicatorA.value;
	        		var quantity = 0;
					quantity = document.getElementById('quant').value;
					if(quantity != '' && (isNumeric(quantity) == 0) && (quantity > 0)){
						document.addToCart.quantity_1.value = quantity;
						cartQuantity=quantity;
						var atcCheck=false;
						if(variant =='1' && qvATCFlag =='true' ){
							atcCheck= true;
						}
						else if(variant =='0' && (qvATCFlag =='true' && qvOptionTab !='true' )){
							atcCheck= true;					
						}
						if(atcCheck){
							var parameters="&catEntryId_1="+childCatId+"&quantity_1="+quantity+"&parent_catEntryId_1="+catentryProduct;
							var queryString="URL=AJAXResponseView&langId=-1&storeId="+storeIdReq +"&catalogId="+qvCatalogId+parameters+"&IndicatorA="+itemA ;
		 					
							  $.ajax({
							  url: "/shc/s/MultipleOrderItemAddCmd",
							  data:queryString,
							  timeout:9999999,
							  success: function(msg){
							   	postCartFlow(msg);
							   }
							 });  
				        }
				        else{
				        	 document.addToCart.submit();
				        }
			        } else {
						var objImage = document.getElementById('cart_enable');
						var mesg = "Please enter a valid quantity";
					 	showErrorMsgPopUpBox(objImage,mesg,'Cart');
					}
				}
			}
		}
		fnSetInfo('N');
		$('#availPopup').css({display: "block"});
		$('#availPopup .standardDiv').css({display: "none"});
		$('#availPopup .errorDiv').css({display: "block"});
		readyOnLoad();
	}
}



function SaveToOpsErrorPopUpBox(o,err,isGT)
    {
    if(!document.getElementById('errorBox1')){
       
        var topPosition=0;
        var leftPosition=0;
        newDiv=document.createElement('div');
        newDiv.className='errorPop';
        newDiv.id='errorBox1';
        newDiv.innerHTML=getErrorStatus(err,isGT);
        document.body.appendChild(newDiv);
        var errBox=document.getElementById('errorBox1');
        var oy = findPosY(o);
        var ox = findPosX(o);
         
       
        if(browser=="Internet Explorer"){
            var docWidth=document.body.scrollWidth;
            var docHeight=(document.body.scrollHeight);
            var boxH=errBox.offsetHeight;
            var boxW=errBox.offsetWidth;
          
            if ((ox-100)<0)
            {
                errBox.style.top=(oy-350)+"px";
                errBox.style.left=(ox-15)+"px";
                topPosition=oy-350;
                leftPosition=ox-40;
            } 
            else if ((ox-100)>(docWidth-boxW))
            {
                errBox.style.top=(oy-100)+"px";
                errBox.style.left=(docWidth-boxW-10)+"px";
                topPosition=oy-100;
                leftPosition=docWidth-boxW-10;
            } 
            else 
            {   
                errBox.style.top=(oy-100)+"px";
                errBox.style.left=(ox-100)+"px";
                topPosition= oy-100;
                leftPosition= ox-100;
            }
            
            if(topPosition <=0 || leftPosition<=0)
            {
                errBox.style.top=docWidth/7+"px";
                errBox.style.left=docHeight/1.1+"px";
            }
        } else {
                var topPosition=0;
                var leftPosition=0;
                var docWidth=document.documentElement.clientWidth;
                var docHeight=document.documentElement.clientHeight;
                var boxH=errBox.offsetHeight;
                var boxW=errBox.offsetWidth;
               
                if ((ox-100)<0)
                {
                    errBox.style.top=(oy-100)+"px";
                    errBox.style.left=(ox)+"px";
                    topPosition=oy-100;
                    leftPosition=ox;
                } 
                else if ((ox-100)>(docWidth-boxW))
                {
                    errBox.style.top=(oy-100)+"px";
                    errBox.style.left=(docWidth-boxW-10)+"px";
                    topPosition=oy-100;
                    leftPosition=docWidth-boxW-10;
                } 
                else 
                {
                    errBox.style.top=(oy-100)+"px";
                    errBox.style.left=(ox-100)+"px";
                    topPosition=oy-100;
                    leftPosition=ox-100;
                }
            
                if(topPosition <=0 || leftPosition<=0)
                {
                    errBox.style.top=docWidth/7+"px";
                    errBox.style.left=docHeight/1.1+"px";
                }   
        }
    }
}


function onRegistry(value)
{
	var url = "";
	var grUserType = getCookie('GiftRegApp'+storeId);

	catEntryIdScim = getCatEntId();
	var catEntryIds = '&catEntryId_1=' + catEntryIdScim + '&quantity_1=1';

	var externalId = value;
	url = 'AddToGiftRegistry?storeId='+storeId+'&catalogId='+catalogId+'&grUserType=' + grUserType + '&externalId=' + externalId;
	ajaxCall(url + catEntryIds ,'getAddToRegistryStatus','','');
	
}


function getAddToRegistryStatus(value){
    
    object = document.getElementById("saveToList");
    flag = '';
    
    if(value.substring(7,value.length) == 'ItemsExceeded'){
    
    	flag = value.substring(7,value.length);
    
    }
    else {
    
	    if(value.substring(0,7) == "Success"){
	        if(document.getElementById("remembered")!=null){
	           var remem = document.getElementById("remembered").value;
	           if(remem=="yes")
	                flag = 'error11'+value.substring(7,value.length);
	           else
	                flag = 'error7'+value.substring(7,value.length);
	        } else
	            flag = 'error7'+value.substring(7,value.length);
	   	}
   }
    SaveToOpsErrorPopUpBox(object,flag);
    cursor_Default();
}

function cursor_Default()
{
    Load.style.display = "none";
    
}



			
function popupWishlistSubmit(){    
          Load.style.display = "block";
          var storeId = storeIdReq;
          var langId = '-1';
          var catalogId = qvCatalogId;
          for (i=0;i<document.GRForm.registry.length;i++) 
          {
            if (document.GRForm.registry[i].checked){ 
                var extId = document.GRForm.registry[i].value;
                if (extId == 'create'){
                  var cattId = getCatEntryIds();
                  var rew = "~";
                  cattId = cattId.replace(/&/g,rew);
                  mainUrl = mainUrl.replace(/&/g,rew);
                  if(document.getElementById("remembered")!=null){
                    var remem = document.getElementById("remembered").value;
                    if(remem=="yes")
                        location.href = "LogonForm?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId+'&URL=WeddingWishListCreateView?storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&cattId='+cattId+'&mainUrl='+mainUrl;
                    else
                        location.href = "WeddingWishListCreateView?storeId="+storeId+"&langId="+langId+"&catalogId="+catalogId+"&cattId="+cattId+"&mainUrl="+mainUrl;
                  }
                  else
                      location.href = "WeddingWishListCreateView?storeId="+storeId+"&langId="+langId+"&catalogId="+catalogId+"&cattId="+cattId+"&mainUrl="+mainUrl;
                }
                else{
                  	var url = "";  
				    var grUserType = getCookie('GiftRegApp'+storeId);
				    var catEntryIds = getCatEntryIds();
				    var externalId = extId;
				    url = 'AddToGiftRegistry?storeId='+storeId+'&catalogId='+catalogId+'&grUserType=' + grUserType + '&externalId=' + externalId;
				    ajaxCall(url + catEntryIds ,'getAddToNewWishList','',''); 
                }
            }
          }
          
          if (document.GRForm.registry.checked){
            if (document.getElementById("registry").value == 'create'){
                 var cattId = getCatEntryIds();
                 var rew = "~";
                 cattId = cattId.replace(/&/g,rew);
                 mainUrl = mainUrl.replace(/&/g,rew);
                 if(document.getElementById("remembered")!=null){
                    var remem = document.getElementById("remembered").value;
                    if(remem=="yes")
                        location.href = "LogonForm?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId+'&URL=WeddingWishListCreateView?storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&cattId='+cattId+'&mainUrl='+mainUrl;
                    else
                        location.href = "WeddingWishListCreateView?storeId="+storeId+"&langId="+langId+"&catalogId="+catalogId+"&cattId="+cattId+"&mainUrl="+mainUrl;
                  }
                  else
                      location.href = "WeddingWishListCreateView?storeId="+storeId+"&langId="+langId+"&catalogId="+catalogId+"&cattId="+cattId+"&mainUrl="+mainUrl;
              }
          }
     }
 
 
 
 function getAddToNewWishList(value){
	    Load.style.display = "none";
	    object = document.getElementById("saveToList");
	    flag = '';
	    if(value.substring(7,value.length) == 'ItemsExceeded'){
	    	flag = value.substring(7,value.length);
	    }
     	else {
	    if(value.substring(0,7) == "Success"){
	        if(document.getElementById("remembered")!=null)
	        {
	           var remem = document.getElementById("remembered").value;
	           if(remem=="yes")
	                flag = 'error12'+value.substring(7,value.length);
	           else
	                flag = 'error9'+value.substring(7,value.length);
	        }
	        else
	            flag = 'error9'+value.substring(7,value.length);
	
	    }
   }
    SaveToOpsErrorPopUpBox(object,flag);

}
 
 
 function displayAttributes(){
	var selectionStr='';
	if(typeof softlineJSON != 'undefined' && typeof softlineJSON.Softline != 'undefined'  && typeof softlineJSON.Softline.prodList != 'undefined' && typeof softlineJSON.Softline.prodList.prodVarList != 'undefined' && typeof softlineJSON.Softline.prodList.prodVarList[0] != 'undefined' && typeof softlineJSON.Softline.prodList.prodVarList[0].attList != 'undefined' && softlineJSON.Softline.prodList.prodVarList[0].attList.length >0 && typeof attrSelected != 'undefined' ){
		var attrLen = softlineJSON.Softline.prodList.prodVarList[0].attList.length;
		
		for(i=0 ;i<attrLen;i++){
		
			selectionStr  = selectionStr + softlineJSON.Softline.prodList.prodVarList[0].attList[i].name+" : "+attrSelected[i] +" ; ";

		}
	}
	if(fitmentExists){
		if($("div#qvp_var")){
			var fitSelected = $("div#qvp_var").find("div[@class=opt_sel]").text();
			if(fitSelected!=''){
				selectionStr="Fit :" + fitSelected +" ; "+selectionStr;
			}
		}
	}
	$("span.attrChoice").html(selectionStr);
	

} 

function callBazaarVoice(){

	$("div#reviews .qvContentMain").append('<iframe class="reviewsBucket" frameborder="0" src=""/>');
	$("div#reviews .qvContentMain").append('<br clear="both"/><a href="/shc/s/p_'+storeIdReq+'_'+qvCatalogId+'_'+qvPartnumber+'#reviewsWrap" title="Write a Review for This Product">Click here to write a review for this product</a>');               
	$("div#reviews .qvContentMain").find('.reviewsBucket').attr('src','http://reviews2.sears.com/2328qv/'+revURL+'/reviews.htm?format=noscript&user=__USERID__');            	                
	$("div#reviews .qvContentMain").css("overflow","visible");
}

function attachOmnitureTagToQV(){
            var vert = omVrt.split("'").join("");
            var cat = omCat.split("'").join("");
            var sbcat = omSubCat.split("'").join("");        
            
			$("div#tabs > ul").find("li").each(function(i){
				var textVal=$(this).children().text();
                $(this).find("a").click(function() {
              		s.prop26 = vert+' > '+cat+' > '+sbcat+' > '+'Quick View > '+textVal;
              		s.events ='event27';
              		s.product = qvPartnumber;
              		s.tl();
              	});
            });
        	/* Tagging for Add to Cart removed as the onclick events are getting overwritten*/
        	//$('a#addCart').removeAttr('onclick');
            //$("a#addCart").attr('onclick','javascript:submitAddToCartRANew();s.prop26=\''+vert+' > '+cat+' > '+sbcat+' > Quick View > Add to Cart\';s.product=\''+qvPartnumber+'\';s.tl();');
            //alert($('a#addCart').attr('onclick'));         
}

/** International Shippping implementation**/
function onload_IntShipping(){
	if(intShipJspChk == 'true' && storeId == '10153'){
		fnConvertSaveStory();
		if(intlShipElg == 'YES'){
			$('li#unvIntShipId').hide();
			$('input#quant').removeAttr('disabled');
			if($('input#quant').val() == '0')
			$('input#quant').attr('value','1');
    	}else if(intlShipElg == 'NO'){
    
			$('li#intShipId').hide();
			$('input#quant').attr('disabled','disabled').attr('value','0');
			$('div.buttons div#cart_enable').hide();
			$('.addCart').hide();
			$('div.listOptions').hide();
		}
		if($('#deliveryText').text() == 'Delivery' || $('#pickUpText').attr('style','display:block')){

			if($("#shipText:visible").length === 0){
					$('#actionsForm').append('<strong id="shipText">Ship</strong>');
					$('#actionsForm').append('<span style="display: block;" id="shipradio" class="intShipHide"><input type="radio" select="true" value="ship" onclick="javascript:showShipMsg();" name="arrivMethd" id="ship"/> Ship <br/> </span>');
					$('#shipradio').attr('checked',true);
			}
		}
	}
	else if(intShipJspChk == 'false' && storeId == '10153'){
		$('li#unvIntShipId').hide();
		$('li#intShipId').hide();
		if(intlShipElg == 'YES'){
			$('li#intShipId').show();
		}
	}
	//Showing the saveStory in the quickView only after the saveStory gets converted
	$('#quickViewSaveStory').removeClass('intShipHide');
}

