
var crossSellCountItems=1;var cacheId=0;$(window).load(function(){$('ul.lstAcessorios').jcarousel({vertical:false,scroll:3,animation:'slow',buttonNextHTML:'<div></div>',buttonPrevHTML:'<div></div>'});});Number.prototype.formatMoney=function(c,d,t){var n=this,c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?",":d,t=t==undefined?".":t,s=n<0?"-":"",i=parseInt(n=Math.abs(+n||0).toFixed(c))+"",j=(j=i.length)>3?j%3:0;return s+(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)
+(c?d+Math.abs(n-i).toFixed(c).slice(2):"");}
function AddRemoveProduct(selectedItem){if(selectedItem.parentNode.className.indexOf("excluido")>=0){cacheId+=parseInt(selectedItem.getAttribute('index'));selectedItem.parentNode.className=selectedItem.parentNode.className.replace('excluido','adicionado');crossSellCountItems++;for(var i=0,obj;obj=selectedItem.parentNode.childNodes[i];i++){if(obj.nodeType===1){if(obj.id.indexOf("hdnProductPrice")>=0){crossSellTotalValue+=parseFloat(obj.value);}else if(obj.id.indexOf("hdnProductId")>=0){$('a[id$=HyperLinkComprar]').attr('href',$('a[id$=HyperLinkComprar]').attr('href')+","+obj.value);}else if(obj.id==selectedItem.id){obj.src='/Theme/extra/img/new/DetalheProduto/btExcluirLista.gif'}}}}
else{cacheId-=parseInt(selectedItem.getAttribute('index'));selectedItem.parentNode.className=selectedItem.parentNode.className.replace('adicionado','excluido');crossSellCountItems--;for(var i=0,obj;obj=selectedItem.parentNode.childNodes[i];i++){if(obj.nodeType===1){if(obj.id.indexOf("hdnProductPrice")>=0){crossSellTotalValue-=parseFloat(obj.value);}else if(obj.id.indexOf("hdnProductId")>=0){$('a[id$=HyperLinkComprar]').attr('href',$('a[id$=HyperLinkComprar]').attr('href').replace(","+obj.value,""));}else if(obj.id==selectedItem.id){obj.src='/Theme/extra/img/new/DetalheProduto/btIncluirLista.gif'}}}}
var found=null;var link=$('a[id$=HyperLinkComprar]').attr('href');var ids=link.substring(link.lastIndexOf("=")+1,link.length);for(i=0;i<cacheValuesObject.length;i++){if(cacheValuesObject[i].CacheId==cacheId)
found=cacheValuesObject[i];}
var imgSrc;if(found==null){$.ajax({type:"POST",url:"/WebService/AccessoriesCrossSell.asmx/CalculateInstallment",data:"{'products':'"+ids+"', 'totalValue':"+crossSellTotalValue+"}",contentType:"application/json; charset=utf-8",dataType:"json",beforeSend:function(){imgSrc=selectedItem.src;selectedItem.src='/theme/extra/img/new/loading.gif';},success:function(T){selectedItem.src=imgSrc;if(T.d==null){$('span[id$=LabelInstallmentWithoutInterest]').text('');cacheValuesObject[cacheValuesObject.length]={CacheId:cacheId,InstallmentTotalNumber:0,Value:0};}else{cacheValuesObject[cacheValuesObject.length]={CacheId:cacheId,InstallmentTotalNumber:T.d.InstallmentTotalNumber,Value:T.d.Value};$('span[id$=LabelInstallmentWithoutInterest]').text("Em até: "+T.d.InstallmentTotalNumber+" x R$ "+T.d.Value.formatMoney(2,",",".")+" sem juros no cartão");}}});}else{if(found.Value!=0){$('span[id$=LabelInstallmentWithoutInterest]').text("Em até: "+found.InstallmentTotalNumber+" x R$ "+parseFloat(found.Value).formatMoney(2,",",".")+" sem juros no cartão");}else{$('span[id$=LabelInstallmentWithoutInterest]').text('');}}
document.getElementById("spanQuantity").innerHTML=crossSellCountItems;$('span[id$=LabelTotal]').text("R$ "+crossSellTotalValue.formatMoney(2,",","."));}