// JavaScript Document

// Funções de apoio MM
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Funções Menu
	mostrar = false;
	function mostraMenu(){
		MM_showHideLayers('novidades','','show');
	}
	function escondeMenu(){
		MM_showHideLayers('novidades','','hide');
	}
	
	/*function scrollup(id){
		//obj = document.getElementById(id);
		//alert(obj);
	}
	
	function scrollDown(id){
		obj = document.getElementById(id);
		alert(obj);
	}*/
	
	
	
	
//Funções Geral

function parseelement(tempnum) {    

   wd="w";
   saida = '';
   pos = 0;   

   tempnum = new String(tempnum);
   tempnum = tempnum.replace(',','');
   tempnum = tempnum.replace('.',',');
   
   //
   pos = tempnum.indexOf(',');
   if (pos > -1) {
	   decimal = Math.round(tempnum.substr(pos+1,pos+3));
	   tempnum = tempnum.substr(0,pos+3);
   }
   
   //var tempnum=thisone.value
   for (i=0; i<tempnum.length; i++) {
       if (tempnum.charAt(i)==",") {
         wd="d";
         
		 if (tempnum.charAt(tempnum.length-2)==",") {
		     saida=tempnum+"0";
  	     } else if (tempnum.charAt(tempnum.length-1)==",") {
		     saida=tempnum+"00";
		 } else {
  	         saida=tempnum;	 
		 }
		 
		 return saida;
       }
   }
   
   if (wd=="w") {
       saida=tempnum+",00";
   } else {
       if (tempnum.charAt(tempnum.length-2)==",") {
           saida=tempnum+"0";
       } else if (tempnum.charAt(tempnum.length-1)==",") {
           saida=tempnum+"00";
       }
   }
return saida;
}



function parseelement2(tempnum) {    


   wd="w";
   saida = '';
   pos = 0;   
   
  
   tempnum = new String(tempnum);
   tempnum = tempnum.replace('.','');
   tempnum = tempnum.replace(',','.');
   
   //
   pos = tempnum.indexOf('.');
   if (pos > -1) {
	   tempnum = tempnum.substr(0,pos+3);
   }
   
   //var tempnum=thisone.value
   for (i=0; i<tempnum.length; i++) {
       if (tempnum.charAt(i)==".") {
         wd="d";
         
		 if (tempnum.charAt(tempnum.length-2)==".") {
		     saida=tempnum+"0";
  	     } else if (tempnum.charAt(tempnum.length-1)==".") {
		     saida=tempnum+"00";
		 } else {
  	         saida=tempnum;	 
		 }
		 
		 return saida;
       }
   }
   
   if (wd=="w") {
       saida=tempnum+".00";
   } else {
       if (tempnum.charAt(tempnum.length-2)==".") {
           saida=tempnum+"0";
       } else if (tempnum.charAt(tempnum.length-1)==".") {
           saida=tempnum+"00";
       }
   }
return saida;
}






	function cOn(td,classe){
		if(document.getElementById||(document.all && !(document.getElementById)))
			td.className=classe;
	}
	
	function MovLayer()	{
		
		obj = null;
		if (obj = document.getElementById("totalCompra"))
			//alert(obj.style.top);
			if(document.body.scrollTop > 224 )	
				obj.style.top = document.body.scrollTop;
			else
				obj.style.top = 224;
	}
	
//Funções Carrinho

	function addQtd(qtd,preco){
		obj = MM_findObj('qtd[0]');
		obj2 = MM_findObj('totalParc');
		if(isNaN(obj.value)){
			obj.value = 0;
		}
		if((Math.floor(obj.value) + qtd) < 1){
			obj.value = 1;
		}else{
			obj.value = Math.floor(obj.value) + qtd ;
		}
		obj2.innerHTML = parseelement(obj.value * preco);
	}
	
	function addQtd2(qtd,frm){
		obj = MM_findObj(frm).qtd;
		
		if(isNaN(obj.value)){
			obj.value = 0;
		}
		if((Math.floor(obj.value) + qtd) < 1){
			obj.value = 1;
		}else{
			obj.value = Math.floor(obj.value) + qtd ;
		}
	}
	
	function addQtd3(tipo,qtd,frm,soma,somaPeso){
		if (tipo == 1) {
			obj = MM_findObj('qtd[' + frm + ']');
			obj2 = MM_findObj('total'+frm);
			obj3 = MM_findObj('valor'+frm);
			obj4 = MM_findObj('vlrTotal');
		} else if (tipo == 2) {
			obj = MM_findObj('qtdB[' + frm + ']');
			obj2 = MM_findObj('totalB'+frm);
			obj3 = MM_findObj('valorB'+frm);
			obj4 = MM_findObj('vlrTotal');	
		}
		//alert(obj)
		if(isNaN(obj.value)){
			obj.value = 0;
			obj2.innerHTML = '0,00';
		}
		if((Math.floor(obj.value) + qtd) < 0){
			obj.value = 0;
			obj2.innerHTML = '0,00';
		}else{
			obj.value = Math.floor(obj.value) + qtd ;
			obj2.innerHTML = parseelement(obj.value * obj3.value);
		}

		total3(soma,somaPeso);
		
		//total = ;
		/*if(qtd > 0){
			obj4.innerHTML = parseelement(( Math.floor(obj3.value)) + Math.floor(obj4.innerHTML.replace(",",".")));
		}else{
			if(Math.floor(obj.value) >= 0){
			obj4.innerHTML = parseelement(Math.floor(obj4.innerHTML.replace(",",".")) - ( Math.floor(obj3.value)));	
			}
		}*/
	}

	function total3(soma,somaPeso){
		
		/*
		qtd
		id
		valor
		peso
		
		*/
		obj = MM_findObj('frm');
		//alert(obj.qtd.length);
		precoTotal = 0;
		pesoTotal = 0;
		for (var i = 0; i < obj.qtd.length; i++) {
			if(obj.qtd[i].value > 0){
				precoTotal += obj.valor[i].value * obj.qtd[i].value;
				pesoTotal += obj.peso[i].value * obj.qtd[i].value;
			}
		}
			
			
		/* COMENTADO POIS NÃO TEM MAIS A PARTE DE OUTROS HARDWARE
		 for (var i = 0; i < obj.qtdB.length; i++) {
			if(obj.qtdB[i].value > 0){
				precoTotal += (obj.valorB[i].value * obj.qtdB[i].value);
				pesoTotal += obj.pesoB[i].value * obj.qtdB[i].value;
			}
		}
		*/
		
		
		obj4 = MM_findObj('vlrTotal');
		obj4.innerHTML = parseelement(precoTotal);
		obj5 = MM_findObj('psoTotal');
		obj5.innerHTML = pesoTotal;
	}

	function addQtd4(tipo,qtd,frm){
		if (tipo == 1) {
			obj = MM_findObj('valor[' + frm + ']');
			obj2 = MM_findObj('qtd[' + frm + ']');
			obj3 = MM_findObj('spanParcial' + frm);
		} else if (tipo == 2) {
			obj = MM_findObj('valorB[' + frm + ']');
			obj2 = MM_findObj('qtdB[' + frm + ']');
			obj3 = MM_findObj('spanParcialB' + frm);	
		}
		
		if(isNaN(obj2.value)){
			obj2.value = 0;
		}
		if((Math.floor(obj2.value) + qtd) < 0){
			obj2.value = 0;
		}else{
			obj2.value = Math.floor(obj2.value) + qtd ;
		}

		obj3.innerHTML = parseelement(obj.value * obj2.value);
		
		total4();
	}
	
	function total4(){
		obj = MM_findObj('frmPedido');
		//alert(obj.qtd.length);
		precoTotal = 0;
		pesoTotal = 0;
		
		//PRODUTOS THERMALTAKE
		if(obj.qtd.length != undefined ){
			for (var i = 0; i < obj.qtd.length; i++) {
				if(obj.qtd[i].value > 0){
					precoTotal += obj.valor[i].value * obj.qtd[i].value;
					pesoTotal += obj.peso[i].value * obj.qtd[i].value;
				}
			}
		}else{
			if(obj.qtd.value > 0){
				precoTotal += obj.valor.value * obj.qtd.value;
				pesoTotal += obj.peso.value * obj.qtd.value;
			}
		}
		
		//OUTROS PRODUTOS
		/*
		if(obj.qtdB.length != undefined ){
			for (var i = 0; i < obj.qtdB.length; i++) {
				if(obj.qtdB[i].value > 0){
					precoTotal += obj.valorB[i].value * obj.qtdB[i].value;
					pesoTotal += obj.pesoB[i].value * obj.qtdB[i].value;
				}
			}
		}else{
			if(obj.qtdB.value > 0){
				precoTotal += obj.valorB.value * obj.qtdB.value;
				pesoTotal += obj.pesoB.value * obj.qtdB.value;
			}
		}
		
		obj8 = MM_findObj('spanTotalFrete');
		
		obj6 = MM_findObj('spanTotal');
		obj6.innerHTML = parseelement(precoTotal + (!isNaN(obj8.value)?parseelement2(Math.floor(obj8.value)):"0.00"));
		
		obj7 = MM_findObj('hSubT');
		obj7.innerHTML = parseelement(precoTotal + (!isNaN(obj8.value)?parseelement2(Math.floor(obj8.value)):"0.00"));
		
		*/
	
		obj6 = MM_findObj('spanTotal');
		obj6.innerHTML = parseelement(precoTotal);
		
		objSub = MM_findObj('hSubT');
		objSub.value = parseelement2(precoTotal);
		
		objFrete = MM_findObj('Frete');
		varFrete = Math.abs(objFrete.value);
		
		
		obj7 = MM_findObj('spanTotalFinal');
		obj7.innerHTML = parseelement((precoTotal + varFrete));
	
	}
		
		//alert(obj.qtdB.length);
	
	function mudaValor(obj){
		alert(obj);
	}
	