var outOfStockPrdNameTemp='';
var emailDivClick=false;
var i = 0;
var fitCountLoad=0;
// this variable is for email me eligible

var emailPIndex = 0;
var hardlinesoftlinediff =0 ; 
//Checking whether string contains only numbers
//Even spaces are not allowed 
function isNumeric(strVal)
{
  for(var i=0; i<strVal.length; i++)
  {
	var key = strVal.charCodeAt(i);
			
	if((key < '48') || (key >'57'))
	{
		return 1;
	}
  }
  	return 0;
}

function changeFitCount(tempFitNum){

fitCountLoad=tempFitNum;
}
function rImg(imgSource) {
 var objImg = new Image();
 objImg.src = imgSource;
 return objImg;
}



function setImgSrc(targetID, strSrc) {
 if (typeof targetID == "string") var objImg = rObj(targetID);
 else if (typeof targetID == "object") var objImg = targetID;
 objImg.setAttribute("src",strSrc);
}

function setObjInHTML(objLayer,strHTML) {
 objLayer.innerHTML = strHTML;
}

function formatNumber(num) {
	num = num.toString();
	if(isNaN(num))
		num = "0";
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (num + '.' + cents);
}


if (!_Pd) {
 var _Pd = new Object();
}


_Pd.bldId=function (type,prodNum,varNum,attNum,valNum){
	var elemId="p"+prodNum;
	var typeStr="";
	if(varNum>-1){elemId+="_v"+varNum;}
	if(attNum>-1){elemId+="_a"+attNum;}
	if(valNum>-1){elemId+="_av"+valNum;}
	switch (type){
		case 0: typeStr="_lbl";	break;
		case 1: typeStr="_bd";	break;
		case 2: typeStr="_price"; break;
		case 3: typeStr="_btn";	break;
		case 4: typeStr="_lst";	break;
		case 5: typeStr="_slct"; break;
		case 6: typeStr="_img"; break;
		case 7: typeStr="_price"; break;
		case 8: typeStr="_msg"; break;
		case 9: typeStr="_qtlbl"; break;
		case 10: typeStr="_qty"; break;
	}
	return elemId+typeStr;
}

_Pd.ProdMain = function (pId,
 isPreSelectQty,isSPU) {
	this.pId = pId;
	this.isPreSelectQty=isPreSelectQty;
	this.isSPU=isSPU;
	this.prodList=[];
	this.isCol;
	this.numItems;
}

_Pd.ProdBase=function(
 pId,
 numOfAtts,
 attNames,
 isDEME,
 hasVariant,
 name,
 price,
 qty,
 stk){
	this.pId=pId;
	this.numOfAtts=numOfAtts;
	this.attNames=attNames;
	this.isDEME=isDEME;
	this.hasVariant=hasVariant;
	this.prodVarList=[];
	this.dVarIndex;
	this.sProd;
	this.vIndex;
	this.isProd;
	this.isReg;
	this.qty;
	this.name;
	this.price;
	this.itemTotalStr;
	this.stk;
	this.mModel;
}

_Pd.ProdVar=function(varName){
	this.varName=varName;
	this.attList=[];
	this.skuList=[];
	this.sAttVal;
	this.sAttValIndex;
	this.sSKU;
	this.isSKU;
	this.sIndex;
	this.vStory;
}

_Pd.ProdAtt=function(){
	this.aVals=[];
	this.sAttValList=[];
	this.attGIndex=[];
	this.aStory=[];
	this.sStory=[];
}

_Pd.ProdSKU=function (pId,stk,price){
	this.pId=pId;
	this.stk=stk;
	this.aVals=[];
	this.pI;
}
var itmTemp='';
var addToCartMsg='';
var scene7Tmp="";
var slct="";
var inStk='';
var outStk='';
var spuDis='';
var cartImg="";
var cartImgGr="";
var spuImgGr = "";
var spuImg = "";
var tempemailMsg ='';
var inStkC = '';
var spuDisC = ''
var outStkC =	'';
var jsonText ='';
var s7Obj = null;
var availHTML='';
_Pd.initPage = function(isCol){
 
	var inQt=1;
	_Pd.prod.numItems=0;
	var l = _Pd.prod.prodList.length;
     availHTML=$("div.specs .availability").html();
	if(isCol){
		_Pd.prod.isCol=true;
		inStk=inStkC;
		spuDis=spuDisC;
		outStk=outStkC;
	}
	for(var i=0; i<l; i++){
		_Pd.prod.prodList[i].isProd=false;
		if(_Pd.prod.prodList[i].isReg && !_Pd.prod.isPreSelectQty){
		 _Pd.prod.prodList[i].sProd=_Pd.prod.prodList[i].pId;
		 inQt=0;
		}
		else{
			inQt=1;
			if (_Pd.prod.isPreSelectQty)
				_Pd.prod.prodList[i].sProd=_Pd.prod.prodList[i].pId;
			else
				_Pd.prod.prodList[i].sProd=0;
			
		}
		_Pd.prod.prodList[i].qty=inQt;
		if(rObj(_Pd.bldId(10,i))){
			rObj(_Pd.bldId(10,i)).value=inQt;
			 	
			setObjInHTML(rObj(_Pd.bldId(5,i)),slct);
			disObjBlk(rObj(_Pd.bldId(5,i)),true);
			if(_Pd.prod.prodList[i].prodVarList){
				_Pd.sVarDis(i,fitCountLoad);
				if(_Pd.prod.prodList[i].prodVarList[0].vStory.length > 0) {
					setObjInHTML(rObj(_Pd.bldId(7,i)), _Pd.prod.prodList[i].prodVarList[0].vStory);
				}
				var numVar=_Pd.prod.prodList[i].prodVarList.length;
				for(var k=0; k<numVar;k++){
				 
					_Pd.prod.prodList[i].prodVarList[k].isSKU=false;
					_Pd.prod.prodList[i].prodVarList[k].sIndex=-1;
				}
			}else{
				_Pd.prod.prodList[i].prodVarList=new Array();
			}
			_Pd.setQty(i);
		}	
	}
				if(isI18NConvReq()){

					$('div.saveStory').hide();
					fnConvertSaveStory()
}
}

_Pd.sVarDis = function(pIndex,vIndex){
	var prd=_Pd.prod.prodList[pIndex];
	prd.vIndex=vIndex;
	if(prd.hasVariant){
		rObj(_Pd.bldId(3,pIndex,vIndex)).className="active";
		setObjInHTML(rObj(_Pd.bldId(0,pIndex)),prd.prodVarList[vIndex].varName);
	}
	disObjBlk(rObj(_Pd.bldId(1,pIndex,vIndex)), true);
	prd.sVarIndex=vIndex;
	prd=null;
				if(isI18NConvReq()){
					
					$('div.saveStory').hide();
					fnConvertSaveStory()
}
}

_Pd.sVarHd = function(pIndex,vIndex){
	rObj(_Pd.bldId(3,pIndex,vIndex)).className="";
	disObjBlk(rObj(_Pd.bldId(1,pIndex,vIndex)), false);
}


_Pd.selectVar= function(pIndex,vIndex){
	var prd = _Pd.prod.prodList[pIndex];
	if(prd.sVarIndex==vIndex){return;}
	for(var i=0; i<prd.prodVarList.length; i++){
		if(vIndex!=i){
			 _Pd.sVarHd(pIndex,i);
		}
	}
	_Pd.sVarDis(pIndex,vIndex);
	//check for msg && Cart
	if(prd.prodVarList[vIndex].isSKU){
		var sIndex = prd.prodVarList[vIndex].sIndex;
		prd.sProd=prd.prodVarList[vIndex].sSKU;
		_Pd.prodIsSel(pIndex,vIndex,sIndex);
				
		//If the sIndex is already set then the add to cart forms can be populated accordingly.
		//Using this sIndex we can get the selected item's catentryId and stock
		if(sIndex > -1){
			var form4 = rObj('fakeAddToCart_' + pIndex);
			if(form4) {
				form4.currentCatEntryId.value = _Pd.prod.prodList[pIndex].sProd;
				form4.isInStock.value = prd.prodVarList[vIndex].skuList[sIndex].stk || _Pd.prod.isSPU;;
			}
			
		 
		}
		
	}else{
	 
		_Pd.prodIsNotSel(pIndex);
	}
	setObjInHTML(rObj(_Pd.bldId(7,pIndex)),prd.prodVarList[vIndex].vStory);
	if(isI18NConvReq()){
					
					$('div.saveStory').hide();
					fnConvertSaveStory()
	}
	prd=null;
}

_Pd.sAttDis = function(pIndex,vIndex,attNum,aIndex){
	var prd = _Pd.prod.prodList[pIndex];
	if(!prd.prodVarList[vIndex].sAttVal){
		prd.prodVarList[vIndex].sAttVal=new Array();
	}
	if(typeof prd.prodVarList[vIndex].attList[attNum].sAttValList=="undefined")
			prd.prodVarList[vIndex].attList[attNum].sAttValList=new Array();
	if(prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]!=2){
		 
		prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=1;
	}else{
		 
		prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=3;
	}	
	prd.prodVarList[vIndex].sAttVal[attNum]=prd.prodVarList[vIndex].attList[attNum].aVals[aIndex];
	prd.prodVarList[vIndex].sAttValIndex[attNum]=aIndex;
	setObjInHTML(rObj(_Pd.bldId(0,pIndex,vIndex,attNum)),prd.prodVarList[vIndex].sAttVal[attNum]);
	prd=null;
			if(isI18NConvReq()){
				
				$('div.saveStory').hide();
				fnConvertSaveStory()
}
}




_Pd.selectAtt= function(pIndex,vIndex,attNum,aIndex,gIndex){
	//alert('pIndex'+pIndex);
	emailPIndex = pIndex ; 
	//alert('emailPIndex:'+emailPIndex);
	var prd = _Pd.prod.prodList[pIndex];
	if(typeof prd.prodVarList[vIndex].sAttValIndex=="undefined"){
		prd.prodVarList[vIndex].sAttValIndex=new Array();
	}
	else if(prd.prodVarList[vIndex].sAttValIndex[attNum]==aIndex){
		return false;
	}
	if(typeof prd.prodVarList[vIndex].attList[attNum].sAttValList=="undefined"){
			prd.prodVarList[vIndex].attList[attNum].sAttValList=new Array();
	}
	for(var i=0; i<prd.prodVarList[vIndex].attList[attNum].aVals.length; i++){
		if(aIndex!=i){
			 if(prd.prodVarList[vIndex].attList[attNum].sAttValList[i]==3)
			 	prd.prodVarList[vIndex].attList[attNum].sAttValList[i]=2;
			 else if(prd.prodVarList[vIndex].attList[attNum].sAttValList[i]==1)
				prd.prodVarList[vIndex].attList[attNum].sAttValList[i]=0;
			rObj(_Pd.bldId(3,pIndex,vIndex,attNum,i)).className=""
		} else {
			rObj(_Pd.bldId(3,pIndex,vIndex,attNum,i)).className="selected";
		}
	}
 
	prd.prodVarList[vIndex].sAttValIndex[attNum]=aIndex;
	 
	_Pd.sAttDis(pIndex,vIndex,attNum,aIndex);
	 
	_Pd.updateAtt(pIndex,vIndex,attNum,aIndex);
	 
	_Pd.checkSku(pIndex,vIndex);
	 
	if(prd.prodVarList[vIndex].sAttValIndex[0]>-1 && (!prd.isProd || prd.numOfAtts==1) ){
		//setObjInHTML(rObj(_Pd.bldId(7,pIndex)),"<div class='salePrice'>"+prd.prodVarList[vIndex].attList[0].aVals[prd.prodVarList[vIndex].sAttValIndex[0]]+"</div>"+ prd.prodVarList[vIndex].attList[0].aStory[prd.prodVarList[vIndex].attList[0].attGIndex[prd.prodVarList[vIndex].sAttValIndex[0]]]);
		 setObjInHTML(rObj(_Pd.bldId(7,pIndex))," "+ prd.prodVarList[vIndex].attList[0].aStory[prd.prodVarList[vIndex].attList[0].attGIndex[prd.prodVarList[vIndex].sAttValIndex[0]]]);
		//prd.prodVarList[vIndex].vStory="<div class='salePrice'>"+prd.prodVarList[vIndex].attList[0].aVals[prd.prodVarList[vIndex].sAttValIndex[0]]+"</div>"+ prd.prodVarList[vIndex].attList[0].aStory[prd.prodVarList[vIndex].attList[0].attGIndex[prd.prodVarList[vIndex].sAttValIndex[0]]];
	}
 
	 
	var itemIndex = _Pd.prod.prodList[pIndex].prodVarList[vIndex].sIndex;
	//alert("sIndex = "+itemIndex);

	if(itemIndex >= 0){
		var stock = _Pd.prod.prodList[pIndex].prodVarList[vIndex].skuList[itemIndex].stk || _Pd.prod.isSPU;
	}
 var itemCount = _Pd.prod.prodList.length;
	 
	if(_Pd.prod.prodList[pIndex].isProd)
	{
	var catentryId=_Pd.prod.prodList[pIndex].sProd;
	//alert('in the if condition:'+catentryId);
	}
	
	if(!stock) {
		var form1  = document.emailNotify;
		if(form1) {
			form1.catEntryId.value = catentryId;
		}
	}
  	var form4 = rObj('fakeAddToCart_' + pIndex);
		if(form4) {
			form4.currentCatEntryId.value = catentryId;
			form4.isInStock.value = stock;
		}
	 
		
	//alert('prd.prodVarList[vIndex].attList[attNum].aVals = ' + prd.prodVarList[vIndex].attList[attNum].aVals);
	if(prd.prodVarList[vIndex].attList[attNum].aVals)
		if(prd.prodVarList[vIndex].attList[attNum].aVals.length<1)
			return false;
	prd=null;		
	//i18n shipping 
		if(isI18NConvReq()){
			
			$('div.saveStory').hide();
			fnConvertSaveStory()
	}
	return true;
}

_Pd.updateAtt= function(pIndex,vIndex,attNum,aIndex){
	var prd = _Pd.prod.prodList[pIndex];
	var stk=false;
	var checkVal;
	var attCount = prd.prodVarList[vIndex].attList.length;
	var sVal = prd.prodVarList[vIndex].sAttVal[attNum];
	var setIndex=-1;
	//all attributes
	for(var j=0; j<attCount; j++){
		if(j!=attNum){
			for(var i=0; i<prd.prodVarList[vIndex].attList[j].aVals.length; i++){
				checkVal = prd.prodVarList[vIndex].attList[j].aVals[i];
				//check from skuList
				stk=false;
				for(var k=0; k<prd.prodVarList[vIndex].skuList.length; k++){
					if(sVal== prd.prodVarList[vIndex].skuList[k].aVals[attNum] && checkVal == prd.prodVarList[vIndex].skuList[k].aVals[j]){
						//need to check the rest of the selected values
						var l=0;
						for(l=0; l<attCount; l++){
							if(l!=attNum && l!=j){
								if(typeof prd.prodVarList[vIndex].sAttVal[l]!= "undefined")
									if(prd.prodVarList[vIndex].sAttVal[l]!=prd.prodVarList[vIndex].skuList[k].aVals[l]){
										break;
									}	
							}
						}
						if(l==attCount){
							stk=true;
							break;
						}	
					}
				}//skus
				if(typeof prd.prodVarList[vIndex].attList[j].sAttValList=="undefined")
						prd.prodVarList[vIndex].attList[j].sAttValList=new Array();
				if(stk){
					_Pd.setInStk(pIndex,vIndex,j,i);}
				else{
		 
				_Pd.setOutStk(pIndex,vIndex,j,i);}
			}//attValue
		}//don't check in current level
	}//for all levels of att
	prd=null;
}

_Pd.setOutStk= function(pIndex,vIndex,attNum,aIndex){
	if(_Pd.prod.prodList[pIndex].prodVarList[vIndex].attList[attNum].sAttValList[aIndex]==1) {
		_Pd.prod.prodList[pIndex].prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=3;
	} else if(_Pd.prod.prodList[pIndex].prodVarList[vIndex].attList[attNum].sAttValList[aIndex]!=3){
		_Pd.prod.prodList[pIndex].prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=2;
		rObj(_Pd.bldId(3,pIndex,vIndex,attNum,aIndex)).className="unavail";
	}
	rObj(_Pd.bldId(11,pIndex,vIndex,attNum,aIndex)).className="unavail";
	disObjBlk(rObj(_Pd.bldId(6,pIndex,vIndex,attNum,aIndex)),true);
}

_Pd.setInStk= function(pIndex,vIndex,attNum,aIndex){
	var prd = _Pd.prod.prodList[pIndex];
	if(prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]==3 ){
		rObj(_Pd.bldId(3,pIndex,vIndex,attNum,aIndex)).className="selected"
		prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=1;
	}else if(prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]!=1){
		rObj(_Pd.bldId(3,pIndex,vIndex,attNum,aIndex)).className=""
		prd.prodVarList[vIndex].attList[attNum].sAttValList[aIndex]=0;
	}
	rObj(_Pd.bldId(11,pIndex,vIndex,attNum,aIndex)).className="";
	disObjBlk(rObj(_Pd.bldId(6,pIndex,vIndex,attNum,aIndex)),false);
}

_Pd.checkSku= function(pIndex,vIndex){
	var prd = _Pd.prod.prodList[pIndex];
	 
	var attCount = prd.prodVarList[vIndex].attList.length;
	 
	//var notAvail='Please use the selection boxes to pick available items before adding them to your cart.';
	var notAvail='This item is not available in the '+_Pd.buildDispAttr(pIndex,vIndex)+' you have selected.';
	addToCartMsg = notAvail;
	var i;
	var hasOut=false;
	for(i=0; i<attCount; i++){
		if(typeof prd.prodVarList[vIndex].sAttValIndex[i]=="undefined" )
			break;
		if(prd.prodVarList[vIndex].attList[i].sAttValList[prd.prodVarList[vIndex].sAttValIndex[i]]>1)
			hasOut=true;
	}
	 
	if(attCount==i){
		if(hasOut) {
	 
			_Pd.prodIsNotSel(pIndex,vIndex);
		  	 
			setObjInHTML(rObj(_Pd.bldId(5,pIndex)),'<ul class=\"availability\"><li class=\"notinStock\">'+notAvail+'<br>'+_Pd.buildDispNameOut(pIndex,vIndex)+'</li></ul>');
				 
		}	
		else
		 
		_Pd.setSku(pIndex,vIndex);
			 
	}	
}

_Pd.buildDispNameOut=function(pIndex,vIndex,isStory){
	var prd=_Pd.prod.prodList[pIndex];
	var rem=2;
	if(isStory){
		var temp="<div class='prodName'>";
		var space="<br>";
		var end="</div>"
		rem+=4;
	}
	else{
		var temp="<span class='fivepx smallTxt'>";
		var space="";
		var end="</span>"
	}

	if(prd.hasVariant){
		temp+="Fit:"+prd.prodVarList[vIndex].varName+", "+space;
	}
	
	var numAtts=_Pd.prod.prodList[pIndex].numOfAtts;
	for(var i=0; i<numAtts; i++){
		temp+=_Pd.prod.prodList[pIndex].attNames[i]+": "+prd.prodVarList[vIndex].attList[i].aVals[prd.prodVarList[vIndex].sAttValIndex[i]]+", "+space;
	}
	 
	return temp.substring(0,temp.length-rem)+end;
}



_Pd.setSku= function(pIndex,vIndex){
	var prd = _Pd.prod.prodList[pIndex];
	var attCount = prd.prodVarList[vIndex].attList.length;
	var skuCount;
	var isSku=true;
	var i=0;
	for(var k=0; k<prd.prodVarList[vIndex].skuList.length; k++){
		for(i=0; i<attCount; i++){
			if(prd.prodVarList[vIndex].sAttVal[i] != prd.prodVarList[vIndex].skuList[k].aVals[i]){
				break;
			}
		}
		if(i==attCount){
			prd.prodVarList[vIndex].isSKU=true;
			prd.prodVarList[vIndex].sSKU=prd.prodVarList[vIndex].skuList[k].pId;
			prd.prodVarList[vIndex].sIndex=k;
			//New code : Start
			_Pd.prod.prodList[pIndex].prodVarList[vIndex].sIndex=k;
			//New code : End
			prd.sProd=prd.prodVarList[vIndex].sSKU;
			prd.price=prd.prodVarList[vIndex].skuList[k].price;
			_Pd.prodIsSel(pIndex,vIndex,k);
			if(prd.numOfAtts!=1){
				if(prd.prodVarList[vIndex].attList[0].sStory[prd.prodVarList[vIndex].skuList[k].pI]){
				//	var sStory=_Pd.buildDispNameOut(pIndex,vIndex,true)+ prd.prodVarList[vIndex].attList[0].sStory[prd.prodVarList[vIndex].skuList[k].pI];
					var sStory=  prd.prodVarList[vIndex].attList[0].sStory[prd.prodVarList[vIndex].skuList[k].pI];
			  
					setObjInHTML(rObj(_Pd.bldId(7,pIndex)),sStory);
					prd.prodVarList[vIndex].vStory=sStory;
				}	
			}	
			break;
		}
	}//skus
	//i18n shipping 
					if(isI18NConvReq()){
					
					$('div.saveStory').hide();
					fnConvertSaveStory()
	}
				}	

_Pd.prodIsSel=function(pIndex,vIndex,sIndex){
	var prd = _Pd.prod.prodList[pIndex];
	var stk=false;
	var msg="";
	var attrArr = toattr.split('|');
	var intlShpilglnktotArr = intlShpilglnktot.split('|');
	var qtybxidArr = totbox2.split('|');
	var unvIntShiplnktotArr = unvIntShiplnktot.split('|');
	var parId =	prd.pId;
		var jqf ="$('input#";
		var jqc ="')";
        var intShipf = "$('#intlShpilg";
        var unvIntShipf = "$('#unvIntShip";
        var hidep = "').hide();"
        var showp = "').show();"
      	 var bxattrdis = ".attr('disabled','disabled').attr('value','0');"
        var bxattrena = ".removeAttr('disabled','disabled').attr('value','0');"
	var ter = '';
	if(prd.qty<1)return;
	if(prd.isReg) stk = prd.stk;
	else{
	 if(typeof vIndex=="undefined"){
	 	vIndex=prd.vIndex;
	 	sIndex=prd.prodVarList[vIndex].sIndex;
	 }
	 if(sIndex>=0)
	 {
	 	stk=prd.prodVarList[vIndex].skuList[sIndex].stk;
                 //International Shipping
         if(intShipJspChk == 'true')
         {
         $('.inStock').hide();
         }
        if(prd.prodVarList[vIndex] !=null && intShipJspChk == 'true') {	    
	    //TODO:Hiding css
		if(prd.prodVarList[vIndex].skuList[sIndex].intShip =='YES' && prd.prodVarList[vIndex].skuList[sIndex].intShipChild == 'YES')
		{
		/*if(intlShpilglnktotArr[i].indexOf(parId)!= -1)
		{
		eval(intShipf + parId + showp );
		eval(unvIntShipf + parId + hidep );	
		}*/
		$('.gWrap').hide();
		$('#srshlp').hide();
		$('#cart_enable').hide();
		$('#cntr_open_ak_hi').hide();
		$('.sendPrint').hide();
		$('div#pd_shippingCal_msg').hide();
		for (i = 0; i < intlShpilglnktotArr.length - 1; i++)
		{
		 
		 		 if(intlShpilglnktotArr[i].indexOf(parId)!= -1)
				 {
				       eval(intShipf + parId + showp );
				       eval(unvIntShipf + parId + hidep );	
		}
		
		}
		
		 		for (i = 0; i < qtybxidArr.length - 1; i++)
		 		{
		 		if(qtybxidArr[i] != '' || qtybxidArr[i] != 'undefined')
		 		{
		 		 var qtybxid = qtybxidArr[i].split('@');
		 		 
		 		 if(qtybxid != '' || qtybxid != 'undefined')
		 		 {
		 		 if(qtybxid[1] == parId)
		 		 {
		 		  eval(jqf + qtybxid[0] + jqc + bxattrena );
		}
		 		 
		 		 }
		 		
		 		}	
		 	    }
		
		}
	    else if (prd.prodVarList[vIndex].skuList[sIndex].intShip == 'NO' ||  prd.prodVarList[vIndex].skuList[sIndex].intShipChild == 'NO')
	    {
	    $('.gWrap').hide();
		$('#srshlp').hide();
		$('#cart_enable').hide();
    		$('#cntr_open_ak_hi').hide();
		$('.sendPrint').hide();
		$('div#pd_shippingCal_msg').hide();
		for (i = 0; i < unvIntShiplnktotArr.length - 1; i++)
		{
		 if(unvIntShiplnktotArr[i].indexOf(parId)!= -1)
			{
		eval(intShipf + parId +  hidep );
		eval(unvIntShipf + parId + showp );	
			}
		}
		for (i = 0; i < qtybxidArr.length - 1; i++)
		{
		if(qtybxidArr[i] != '' || qtybxidArr[i] != 'undefined')
		{
		 var qtybxid = qtybxidArr[i].split('@');
		 if(qtybxid != '' || qtybxid != 'undefined')
		 {
		 if(qtybxid[1] == parId)
		 {
		 eval(jqf + qtybxid[0] + jqc + bxattrdis );
		 }
	    
	    }
		
}	    
	    }
		}
}	    
	    
	    
	 }
	 else
	 	return;
	}
	 var parentCID='';
	 var storePickUpEligible='false';
	 var form = rObj('fakeAddToCart_' + pIndex);
					if(form) {
					     parentCID=form.parentCatentryVal.value;
					     storePickUpEligible=form.storePickUpEligible.value+'';
	                  }
				 
	if(stk){
	         
	         
	         if(SPU_TURNED_ON){
                       msg+='<ul class="availability" id="'+parentCID+'">';
				        if(stk &&  storePickUpEligible=='true'){
				           msg+=AVAIL_MESSAGE.IN_STOCK;
				           }
				         if(stk &&  storePickUpEligible=='false'){
				             msg+=AVAIL_MESSAGE.IN_STOCK_ONLY;
				           }

				}
	         if(!SPU_TURNED_ON){ 
	           msg+='<ul class="availability">';
	           if(prd.prodVarList[vIndex].skuList[sIndex].intShip =='YES' && intShipJspChk == 'true' || intShipJspChk == 'false')
	           {
	           msg+='<li class="inStock">In stock </li>';
	           }
	           }
	           
	           
	           
	       	prd.isProd=true;
			if(_Pd.prod.isSPU && storePickUpEligible=='true'){
			   
			   if(SPU_TURNED_ON){ msg+= AVAIL_MESSAGE.SPUELG_SOFT; }
			  if(!SPU_TURNED_ON){  msg+=' <li class="storepu">Eligible For Store Pick Up   </li> ';}
			   
			   }
		    msg+='</ul>';
	}else{ 
		 
		if(_Pd.prod.isCol) {
	 
			 
			var temp=_Pd.getOutOfStkMsg(pIndex,vIndex);
			 
		  if(!SPU_TURNED_ON){
			msg=  '<ul class="availability">';
			if(intShipJspChk == 'false')
			msg+='<li class="notinStock">Temporarily out of stock for delivery.</li>'+temp;
			 if(_Pd.prod.isSPU){   msg+=' <li class="storepu">Eligible For Store Pick Up   </li> ';}
		    msg+='</ul>';
		    }
		  if(SPU_TURNED_ON){ 
		    msg=  '<ul class="availability" id="'+parentCID+'">';
			msg+=AVAIL_MESSAGE.OOS +temp;
			 if(_Pd.prod.isSPU && storePickUpEligible=='true'){   msg+= AVAIL_MESSAGE.SPUELG_SOFT;}
		    msg+='</ul>';
		}
		}	
	   
	   //New If coondition : Start
	   if(!prd.isProd && sIndex >= 0){
			//This condition is executed only the first time when a complete selection has been made.
			//After that any other selection made will not bring it here as prd.isProd is set to true here
			prd.isProd = true;
			//New Code : Start
			//_Pd.prod.numItems--;
			if(!_Pd.prod.isCol) {
				_Pd.prod.numItems = 0;
			}
			//New Code : End
		}

	   	else if(prd.isProd && !(_Pd.prod.isSPU)){
			//The product is out of stock and not spu.
			//New Code : Start
			//_Pd.prod.numItems--;
			if(!_Pd.prod.isCol) {
				_Pd.prod.numItems = 0;
			}
			prd.isProd=true;
			//prd.isProd=false;
			//prd.isProd = true;
			//New Code : End
		}
		else if(!prd.isProd && _Pd.prod.isSPU){
			//The product is out of stock but it is spu. Hence we need to increment
			//New Code : Start
			//_Pd.prod.numItems++;
			if(!_Pd.prod.isCol) {
				_Pd.prod.numItems = 1;
			}
			//New Code : End
			prd.isProd=true;
		}else{
			prd.isProd=false;
		}
	}
	if(_Pd.prod.isSPU && storePickUpEligible=='true'){ msg=spuDis+msg; prd.isProd=true;}
	 
	rObj(_Pd.bldId(5,pIndex)).className="inStockBox";
	
	setObjInHTML(rObj(_Pd.bldId(5,pIndex)),msg);
 

	 if(intShipJspChk == 'true')
	 {    
     $('.availability').hide();
     }
 
   }

_Pd.getOutOfStkMsg=function(pIndex,vIndex) {

	var prd=_Pd.prod.prodList[pIndex];
	var temp ="";
 
 
	if(!emailDivClick){
	outOfStockPrdNameTemp=outOfStockPrdName;
	emailDivClick=true;
	}
	outOfStockPrdName= outOfStockPrdNameTemp;
	if (! prd.isDEME) {
	        outOfStockPrdName= outOfStockPrdName.replace('tempCatEntryId', _Pd.prod.prodList[pIndex].prodVarList[0].skuList[0].pId);
	
            outOfStockPrdName= outOfStockPrdName.replace('tempProductId',''+_Pd.prod.prodList[pIndex].pId);
		
		var tempDispName=_Pd.buildDispName(pIndex);

		//This replace function is used to replace the bad character like ' or " which appears as brand name
		// These bad char will cause js error when passing to other functions so these chars are masked.
		
		tempDispName=replaceCharacters(tempDispName,'\'','##12');
		
		tempDispName=replaceCharacters(tempDispName,'\"','##13');
		
	 
		outOfStockPrdName= outOfStockPrdName.replace('tempDispName',tempDispName);
		 
		outOfStockPrdName= outOfStockPrdName.replace('tempManufacturerModel', prd.mModel);
		
		 
		temp  =emailmeText(outOfStockPrdName);
	
		}
  return temp;
  
  
	 
}


_Pd.prodIsNotSel=function(pIndex,vIndex){
	var prd = _Pd.prod.prodList[pIndex];

	setObjInHTML(rObj(_Pd.bldId(5,pIndex)),slct);

	 
	prd.isProd=false;
	
	//If the product is not selected we set the catentry ids in the hidden forms as undefined ans
	//the stock as false. Depending on the product type we update the corresponding forms
	
		var form4 = rObj('fakeAddToCart_' + pIndex);
		if(form4) {
			form4.currentCatEntryId.value = "undefined";
			form4.isInStock.value = false;
		}
	
	 
	
	 

}

 



_Pd.buildDispName=function(pIndex){
	var prd=_Pd.prod.prodList[pIndex];
	var temp = prd.name;
	  
	return temp;
}

			if(isI18NConvReq()){
 
				$('div.saveStory').hide();
				fnConvertSaveStory()
		}
 



var idTimeout;

_Pd.setScene7=function(img,height,width,objName,pIndex){
	if(typeof img=="undefined" || img==null || img.length==0){
	window.clearTimeout(idTimeout);		
	  if(!_Pd.prod.isCol){
			if(rObj("noPhotoBox")){
				disObjBlk(rObj("noPhotoBox"), true);		
				var empty_str="";				
				idTimeout=window.setTimeout("_Pd.disNoImgGeneric();",6000);
			}		
	  } else {
	  	if(rObj("noPhotoBox"+pIndex)){
				disObjBlk(rObj("noPhotoBox"+pIndex), true);			
				idTimeout=window.setTimeout("_Pd.disNoImg("+pIndex+");",6000);
			}		
	  }
		return;
	}else{
		if(!_Pd.prod.isCol){		
			if(rObj("noPhotoBox")){
				disObjBlk(rObj("noPhotoBox"), false);
			}		
		} else {
			if(rObj("noPhotoBox"+pIndex)){
				disObjBlk(rObj("noPhotoBox"+pIndex), false);
			}		
		}		
	}
	if(objName==null) return;
	var tempObj;
	if(typeof objName =="undefined"){
		if(typeof s7_Obj =="undefined" || s7_Obj==null) return;
		tempObj = s7_Obj;
	}else{tempObj = objName;}
	var url=scene7Tmp.replace("**",img+"?qlt=90,0&op_usm=0.9,0.5,0,0");  
	tempObj.setImage(eval(url),eval(true),eval(width),eval(height));
	tempObj.setBorder(1,'ffffff');
	tempObj.setMaxZoom(5,2,1);
	tempObj.setBackground("ffffff");
	tempObj.setFadeTime(500);
	tempObj.addToPage();
}

_Pd.disNoImg=function(pIndex){
	disObjBlk(rObj("noPhotoBox"+pIndex), false);
}

_Pd.disNoImgGeneric=function(){
	disObjBlk(rObj("noPhotoBox"), false);
}


_Pd.setColor= function(pIndex,vIndex,attNum,
	aIndex,gIndex,img,height,width,objName){
	var flag = _Pd.selectAtt(pIndex,vIndex,attNum,aIndex,gIndex);
	if(flag)
		_Pd.setScene7(img,height,width,objName,pIndex);
}
/* _Pd.addToCart function signature changed for smartcart */
_Pd.addToCart=function (objImg,isSmartCartFlag) 
{

	if(!_Pd.prod.isCol)
	{
		if(_Pd.prod.numItems<1) 
		{
			 
			var releaseDate = document.addToCart.presellDate.value;
			if(releaseDate != '') {
				showErrorMsgPopUpBox(objImg,addToCartMsg,'preOrderItem');
			} else {
				showErrorMsgPopUpBox(objImg,addToCartMsg,'Cart');
			}
			return;
		}
	}
	else
	{
		var numItemAdded = addedLength();
		if(numItemAdded < 1)
		{
		 
			showErrorMsgPopUpBox(objImg,addToCartMsg,'Cart');
			return;
		}
	}
	if(!_Pd.prod.isCol)
	{
		if(rObj(_Pd.bldId(10,0))) 
		{
			var qty = rObj(_Pd.bldId(10,0)).value;
			if(qty != '' && (isNumeric(qty) == 0) && (qty > 0) ) 
			{
				document.forms['addToCart'].quantity_1.value=rObj(_Pd.bldId(10,0)).value;
				document.forms['addToCart'].IndicatorA.value= itemA;
			}
			else
			{
				//alert('Quantity must be a positive number.  Please enter the quantity again.');
				var mesg="Quantity must be a positive number.  Please enter the quantity again.";
				showErrorMsgPopUpBox(objImg,mesg,'Cart');
				return;
			}
		
		} 
	}
	else 
	{
		var num = document.forms['addToCart'].numOfAddedItem.value;
		document.forms['addToCart'].IndicatorA.value= itemA;
		if(num < 1) 
		{
			//alert('Please click on Add item before adding to the cart');
			var mesg="Please click on Add item before adding to the cart";
			showErrorMsgPopUpBox(objImg,mesg,'Cart');
			return;
		}
	}
	 /* Added for Smart Cart --Start */
	 		 
		document.forms['addToCart'].submit();
	 
     
}
/* functions for smartcart start*/
var referanceToButton;
function updateSoftLineItem(referance,parentCatalogId,storeId){
referanceToButton=referance;
var showcartUrl="SmartCartView?parentCatalogId="+parentCatalogId+"&storeId="+storeId;
	if(document.addToCart.addToCartBtn.value=='false'){
		ajaxCall(showcartUrl,'showFullCart');		
		document.addToCart.addToCartBtn.value='true';
		
	}
}
 function showFullCart(value){
 document.addToCart.addToCartBtn.value='false';
 	document.getElementById("items").innerHTML = value;
 	/* just to check the flow is from smartcart*/
 	var isSmartCartFlag="smartcart";
 	_Pd.addToCart(referanceToButton,isSmartCartFlag);
 }

function updateItemAjaxFromProduct(){

		var softlineUrl = document.location.search;
		var temp=new Array();
		temp=softlineUrl.split("&");
		 for(var i=0;i<temp.length;i++)
				    {				    	
				    	if(temp[i].search("rowCount") != -1)
				    	{
				    	var rowCount=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
				    	}
					}
		var referanceRow="#row_"+rowCount+" a";
		jQuery("#cartLink").click();
  		jQuery("#show").click();		
  		//alert(referanceRow);
  		var JQobject = jQuery(referanceRow);
  		//alert(referanceRow.html());
  		updateItemsAttributeEffect(JQobject);
		//alert("updateItemAjaxFromProduct");

}
function showSmartCartfullview(value){
	document.getElementById("items").innerHTML = value;
	 
}

/* smartcart changes end*/
_Pd.buildCartItems=function(){
	var itemCount = _Pd.prod.prodList.length;
	var selectedValue='';
	for(var l=0;l<itemCount;l++) {
		if(_Pd.prod.prodList[l].isProd)
			selectedValue+="baseId="+_Pd.prod.prodList[l].pId+"+itemId="+_Pd.prod.prodList[l].sProd+"+Qty="+_Pd.prod.prodList[l].qty+",";
	}
	return selectedValue;
}

_Pd.goSPU = function(form,isStore) {
	if(_Pd.prod.numItems<1)
			return;
	var frm = document.forms[form];
	var itemCount = _Pd.prod.prodList.length;
	var pids="";
	var str = "";
	if(!isStore){
		str=frm.zip.value;
		if (!checkZip(str)) return;
	}else{
		str=frm.store.value;
	}
	for(var l=0;l<itemCount;l++) {
		if(_Pd.prod.prodList[l].isProd)
			pids+=_Pd.prod.prodList[l].sProd+"_" +_Pd.prod.prodList[l].qty+",";
	}
	if(pids!=""){
		pids = pids.substring(0,pids.length-1);
		if(!isStore) frm.pid_zip.value = pids+"|" + str;
		else frm.pid_strid.value = pids+"|" + str;
		frm.selectedProducts.value=_Pd.buildCartItems();
		frm.collectionId.value=_Pd.prod.pId;
		frm.submit();
	}
}

var emailMeSuccessDiv;
var emailMeSection;

function submitEmail() {
	
	submitEmailAJAX();
	fillProductData();
	emailMeSuccessDiv.style.display = 'block';
	emailMeSection.style.display = 'none';
}

function showEmailMeForm() {
	
	//emailMeSection.style.display = 'block';
	//emailMeSuccessDiv.style.display = 'none';
}

function hideEmailMeForm() {
	emailMeSection.style.display = 'none';
}
function setEmailMeDataCollection(info) {
 
 
	mePop(info,'emailMe');
}
 

function hideSucessDiv() {
	emailMeSuccessDiv.style.display = 'none';
}

function where(a,what,wrapper){
    if (wrapper == null || typeof wrapper == "undefined") {
		wrapper = "rightContentWrapper";
    }
    var f = findPosY(document.getElementById(wrapper));
    var e = findPosX(document.getElementById(wrapper));
    document.getElementById(what).style.top = (findPosY(a)- f + 100) + "px";
    document.getElementById(what).style.left = (findPosX(a)- e + 150) + "px";
    document.getElementById(what).style.display = "";
}

function submitEmailAJAX()
{	
	var emailVal = document.emailNotify.userEmail.value;
	var catEntryId = document.emailNotify.catEntryId.value;
	var searsItemNumber = document.emailNotify.searsItemNumber.value;
	var manufacturerPartNumber = document.emailNotify.manufacturerPartNumber.value;
	
	var ajaxcallUrl = "EmailMeWhenInStockCmd?userEmail="+emailVal+"&catEntryId="+catEntryId+
	"&searsItemNumber="+searsItemNumber+"&manufacturerPartNumber="+manufacturerPartNumber;
	
	ajaxCall(ajaxcallUrl,'showEmailMe');
	
	return true;
}

_Pd.buildDispAttr=function(pIndex,vIndex){
	var prd=_Pd.prod.prodList[pIndex];
	var rem=2;
	
		var temp="";
		
	//}

	if(prd.hasVariant){
		temp+="Fit/";
	}
	
	var numAtts=_Pd.prod.prodList[pIndex].numOfAtts;
	for(var i=0; i<numAtts; i++){
		temp+=_Pd.prod.prodList[pIndex].attNames[i]+"/";
	}
	
	temp = temp.substring(0,temp.length-1);
	//return temp.substring(0,temp.length-rem);
	return temp;
}
function emailmeText(outOfStockPrdName){
var tempemailMsg ='<li class=\"emailMe\"><a href="javascript:;"  onclick="setEmailMeDataCollection(\''+outOfStockPrdName+'\');">E-mail me </a> when in stock. </li>';
return tempemailMsg;
}