﻿try{
    xmlhttp = new XMLHttpRequest();
	xmlhttp1 = new XMLHttpRequest();
	xmlhttp2 = new XMLHttpRequest();
}catch(ee){
    try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	   xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
	   xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
       try{
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
		  xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
       }catch(E){
          xmlhttp = false;
		   xmlhttp1 = false;
		   xmlhttp2 = false;
       }
    }
}

function validaCPF(cpf) {
	valor = true;
	if (cpf.length < 11) {
		alert('CPF: Número de caracteres invalido!'); form.cpf.focus(); return;
		}
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) {
		alert('A verificação de CPF suporta apenas números!'); form.cpf.focus(); return;
		}
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
	{
		alert('CPF: Seqüência de número não permitido!'); form.cpf.focus(); return;
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++)
	{
	  a[i] = cpf.charAt(i);
	  if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		alert('Número de CPF invalido!'); form.cpf.focus(); return;
	}
return;
}
function contar(valor,numero){
	  s1 = valor.substr(0,valor.length - 2);
	  s2 = valor.substr(valor.length - 2,valor.length);
	  v  = s1+','+s2;
	  document.getElementById('sharing'+numero).innerHTML = v;
}

function navegar(o_q){
	ajax('corpo',"../"+o_q,2);
}

function carregar() {
if (xmlhttp.readyState==1){
   document.getElementById('corpo').innerHTML='<center>Carregando<br><img src=../imagens/carregando.gif></center>'
   }
if (xmlhttp.readyState==4){
   document.getElementById('corpo').innerHTML=xmlhttp.responseText
   }
}

function verificarni(o_q,onde){
	ajax('nixx',"../"+onde+"?ni="+o_q,2);
}
function mostrar_rede(onde,qual_div){
	ajax(qual_div,"../"+onde,2);
}
function menu(qual){
	xmlhttp.open("GET","../menu?qual="+qual);
	xmlhttp.onreadystatechange=carregarmenu;
	xmlhttp.send(null);
}
function carregarmenu() {
	if (xmlhttp.readyState==1){
   document.getElementById('menu').innerHTML='&nbsp;'
   }
if (xmlhttp.readyState==4){
   document.getElementById('menu').innerHTML=xmlhttp.responseText
   }
}
function novaaba(qual,site){
	xmlhttp.open("GET","../"+site+"?valor="+qual);
	xmlhttp.onreadystatechange=carregaraba;
	xmlhttp.send(null);
}
function carregaraba() {
	if (xmlhttp.readyState==1){
   document.getElementById('novaaba').innerHTML='&nbsp;'
   }
if (xmlhttp.readyState==4){
   document.getElementById('novaaba').innerHTML=xmlhttp.responseText
   }
}

function kitx(total) {
		v = "32,5";
		if (total=""){ v= ""; }
	document.getElementById("kitss").innerHTML = v;
	v= "";
}
function kits(total) {
		if(total>0&&total<5){v = "75";}
		if(total>4&&total<10){v = "57,50";}
		if(total>9){v = "51,75"*325;}
	document.getElementById("kitsc").innerHTML = v;
	v= "";
}
function validarChave(){
	if ((document.getElementById('seguri').value).toUpperCase() != (document.getElementById('codse').value).toUpperCase()){
		alert('Ocorreu o seguinte erro:\n - Chave de segurança invalida');
		document.getElementById('seguri').focus();
		return;
	}else{
		document.form.submit();
	}	
}


function ValidateOrder(form,local,msg)
{
	if (local=="patrocinador"){
		if ((form.patrocinador.value == "")&&(form.outro.checked ==false)){
			alert(msg); form.patrocinador.focus(); return;
		}
	}
	if (local=="cadtres"){
		msg=""
	
		if (form.email.value == ""){
			msg='- Digite seu e-mail\n'; form.email.focus();
		}else{
			if (form.email.value.lastIndexOf("@") == '-1'){
				msg='- Digite seu e-mail corretamente\n'; form.email.focus();
			}
		}
		if (form.email.value.lastIndexOf(".") == '-1'){ msg='- Digite seu e-mail corretamente\n'; form.email.focus(); }
		
		if (form.senha.value.length < 3){
			msg='- Digite uma senha\n'; form.senha.focus();
		}else{
			if (form.senha.value.length > 15){
				msg='- Sua senha contem mais de 15 digitos!\n'; form.senha.focus();
			}else{
				if (form.senha.value.length < 5){
					msg='- Sua senha contem menos de 5 digitos!\n'; form.senha.focus();
				}else{
					if (form.confsenha.value == ""){
						msg=msg+'- Digite a confirmação da senha\n'; form.confsenha.focus();
					}else{
						if (form.senha.value != form.confsenha.value){
							msg=msg+'- Confirmação de senha incorreta'; form.confsenha.focus();
						}else{
							if (form.email.value != form.email2.value){
								msg=msg+'- Confirmação de SEU E-MAIL está incorreto'; form.email2.focus();
							}
						}
					}
				}
			}
		}
		if ((document.getElementById('seguri').value).toUpperCase() != (document.getElementById('codse').value).toUpperCase()){
			msg='- Chave de segurança invalida\n'; form.senha.focus();
		}
		if (msg != "") {
			msg = "Ocorreram os seguintes erros:\n"+msg; 
			alert(msg);
			return;
		}
	}
	if (local=="caddois"){
		if(form.fibrative.value == ""){
		   alert('Nome Fibrative é obrigatório');
		   form.fibrative.focus();
		   return false;
	    }
		msg=""
		
		if (form.cpf.value == ""){ 
			alert('CPF Invalido');
			form.cpf.focus();
			return false;
		}
		
		
		
		
		if (form.cpf.length < 11) {
		    alert('CPF: Número de caracteres invalido!'); form.cpf.focus();
			return false;
		}
	    var nonNumbers = /\D/;
	    if (nonNumbers.test(form.cpf.value)) {
		    alert('A verificação de CPF suporta apenas números!'); form.cpf.focus();
			return false;
		}
	    if (form.cpf.value == "00000000000" || form.cpf.value == "11111111111" || form.cpf.value == "22222222222" || form.cpf.value == "33333333333" || form.cpf.value == "44444444444" || form.cpf.value == "55555555555" || form.cpf.value == "66666666666" || form.cpf.value == "77777777777" || form.cpf.value == "88888888888" || form.cpf.value == "99999999999"){
		    alert('CPF: Seqüência de número não permitido!'); form.cpf.focus(); 
			return false;
	    }
	    var a = [];
	    var b = new Number;
	    var c = 11;
	    for (i=0; i<11; i++){
	         a[i] = form.cpf.value.charAt(i);
	         if (i < 9)
			     b += (a[i] *  --c);
	    }
	    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	    b = 0;
	    c = 11;
	    for (y=0; y<10; y++) b += (a[y] *  c--); 
	    if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	    if ((form.cpf.value.charAt(9) != a[9]) || (form.cpf.value.charAt(10) != a[10])){
		    alert('Número de CPF invalido!'); form.cpf.focus(); return false;
	    }
		
		
		if (form.cep.length < 8) {
		    alert('CEP Incorreto'); form.cep.focus();
			return false;
		}
		
		
		if (form.cep.value == ""){ 
			msg='- Digite corretamente seu CEP\n'+msg; form.cep.focus();
			return false;
		}else{
			if (form.estado.value == ""){
				msg='- Digite seu estado\n'+msg; form.estado.focus();
				return false;
			}
			if (form.cidade.value == ""){
				msg='- Digite sua cidade\n'+msg; form.cidade.focus();
				return false;
			}
			if (form.rua.value == ""){
				msg='- Digite seu endereço completo\n'+msg; form.rua.focus();
				return false;
			}
			if (form.nome.value.indexOf(" ") < 1){
				msg='- Digite seu nome completo\n'+msg; form.nome.focus();
				return false;
			}else{
				if (form.nome.value == ""){
					msg='- Digite seu nome completo\n'+msg; form.nome.focus();
					return false;
				}
			}
			/*
			if (form.fibrative.value == ""){
				msg='- Digite um nome Fibrative\n'+msg; form.fibrative.focus();
			}
			*/
		}
		if (msg != "") {
			msg = "Ocorreram os seguintes erros:\n"+msg; 
			alert(msg);
			return;
		}
	}
	form.submit();
}

function tiraracento(texto){
	texto=texto.replace(/Á/i, "A")
	texto=texto.replace(/À/i, "A")
	texto=texto.replace(/Ã/i, "A")
	texto=texto.replace(/Â/i, "A")
	texto=texto.replace(/É/i, "E")
	texto=texto.replace(/Ê/i, "E")
	texto=texto.replace(/Ó/i, "O")
	texto=texto.replace(/Õ/i, "O")
	texto=texto.replace(/Ô/i, "O")
	texto=texto.replace(/Í/i, "I")
	document.form.nome.value=texto
	return texto
}
function deci(N){
       texto = N.toString();
       texto2 = ""
       if (texto.indexOf('.') != -1)
       {
          for (var i = 0; i < texto.length; i++)
          {
              if(texto.charAt(i) == ".")
              	texto2 += ",";
              else
				texto2 += texto.charAt(i);
          }
          texto = texto2;
       }   
          
          
          texto[texto.indexOf('.')] = ",";
       ponto = texto.indexOf(',');
if (ponto == -1)
{
 texto += ",00";
 Term = texto
}
else
{
 texto += "0";
 decimal = ponto + 3;
 Term = texto.substring(0,decimal);
}
if (Term == ",0")    { Term = "0,00";}
       if (Term == ".00")   { Term = "0,00";}
//if (Term == "NaN,00"){ Term = "Erro";}
return Term;
}
function mais(produto)
{
	quantidade = parseFloat(document.getElementById(produto+"quant").innerHTML)
	valor =document.getElementById(produto+"valordopote").value
	quantidade= (quantidade+1)
	if (quantidade==1000){quantidade=999}
	valor = valor * quantidade

	document.getElementById(produto+"quant").innerHTML=quantidade
	document.getElementById(produto+"quantidadepote").value=quantidade
	document.getElementById(produto+"total").innerHTML=deci(valor)
}
function menos(produto)
{
	quantidade = parseFloat(document.getElementById(produto+"quant").innerHTML)
	valor =document.getElementById(produto+"valordopote").value
	quantidade= (quantidade-1)
	if (quantidade==0){quantidade=1}
	valor = valor * quantidade

	document.getElementById(produto+"quant").innerHTML=quantidade
	document.getElementById(produto+"quantidadepote").value=quantidade
	document.getElementById(produto+"total").innerHTML=deci(valor)
}

function frete(opcao)
{
	valor = Number (document.getElementById("valorTotal").value)
	if (opcao=='normal'){
		frete = Number (document.getElementById("valorNormal").value)
	}
	if (opcao=='pac'){
		frete = Number (document.getElementById("valorPac").value)
	}
	if (opcao=='sedex'){
		 frete = Number (document.getElementById("valorSedex").value)
	}
	total = (valor + frete)/100
	document.getElementById("valorMostrado").innerHTML=opcao
}
function Mascara_Numero(numero){
	var mnumero = '';
    mnumero = mnumero + numero;
    if(mnumero.length == 3){
        mnumero = mnumero + '.';
        document.tutores.ni.value = mnumero;
    }
    if(mnumero.length == 7){
       mnumero = mnumero + '.';
       document.tutores.ni.value = mnumero;
    }
	if(mnumero.length == 11){
       mnumero = mnumero + '-';
       document.tutores.ni.value = mnumero;
    }
    
}

function NovoCampo(campo,janelinha){
	
	if (campo == 1){
		campinho = document.login.ni1.value;
		if(campinho.length >= 3){
			document.login.ni2.value = "";
		   document.login.ni2.focus();
		}
	}else{
		if (campo == 2){
			campinho = document.login.ni2.value;
			if(campinho.length >= 3){
				document.login.ni3.value = "";
				document.login.ni3.focus();
			}else{
				if ((document.login.ni1.value).length < 3){
					alert('Atenção: Você não digitou corretamente o\nNS (Número SIM) no primeiro campo!');
					document.login.ni2.value = "";
					document.login.ni1.focus();
				}
			}
		}else{
			if (campo == 3){
				campinho = document.login.ni3.value;
				if(campinho.length >= 3){
					document.login.ni4.value = "";
					document.login.ni4.focus();
				}else{
					if ((document.login.ni2.value).length < 3){
						alert('Atenção: Você não digitou corretamente o\nNS (Número SIM) no segundo campo!');
						document.login.ni3.value = "";
						document.login.ni2.focus();
					}
				}
			}else{
				if (campo == 4){
					campinho = document.login.ni4.value;
					if(campinho.length >= 2){
						if (janelinha==1){
							variavel = document.login.ni1.value+'.'+document.login.ni2.value+'.'+document.login.ni3.value+'-'+document.login.ni4.value
						   FuncaoAjax(variavel);
						}else{
							document.login.senha.focus();
						}
					}else{
						if ((document.login.ni3.value).length < 3){
							alert('Atenção: Você não digitou corretamente o\nNS (Número SIM) no terceiro campo!');
							document.login.ni4.value = "";
							document.login.ni3.focus();
						}
					}
				}
			}
		}
	}
}

function SetLayer(mostrar,id){
   if(mostrar == 1)
	  document.getElementById(id).style.visibility='visible';
   else
      document.getElementById(id).style.visibility='hidden';
}
function verifiFinalPedido(ni){
	opCompra = document.getElementById('opCompra').value;
	if (opCompra == "nada"){
		alert('Atenção: Escolha alguma forma de pagamento!!');
		return false;
	}else{
		if (opCompra == "pagseguro"){
			frete = document.getElementById('valorFrete').value;
			opfrete = document.getElementById('opFrete').value;
			window.location= "https://www.fibrative.net/meucarrinho/pagseguro.php?ni="+ni+"&frete="+frete+"&opfrete="+opfrete
			return false;
		}
		if (opCompra == "mastercard"){
			SetLayer('1','escolherParcMasterCard');
			return false;
		}else{
			if (opCompra == "visa"){
				SetLayer('1','escolherParcVisaNet');
				return false;
			}else{
				return true;
			}
		}
	}
}

function promokids(){
	obj = document.all['formKids'];
	opCompra = obj['selecionado'].value;
	if (opCompra < 2){
		alert('Atenção: Escolha 2 produtos!');
	}else{
		if (opCompra > 2){
			alert('Atenção: Escolha apenas 2 produtos em cada pedido!');
		}else{
			document.all['formKids'].submit();
		}
	}
}
function somaProdutoPromo()
{
	quantidade = 0;
	a1 = document.getElementById("cho").value;
	a2 = document.getElementById("mor").value;
	a3 = document.getElementById("tut").value;
	a4 = document.getElementById("gre").value;
	a5 = document.getElementById("blu").value;
	if ((parseInt(a1) != "1")&&(parseInt(a1) != "2")&&(parseInt(a1) != "3")) { if ((parseInt(a1) != "4")&&(parseInt(a1) != "5")&&(parseInt(a1) != "6")&&(parseInt(a1) != "7")&&(parseInt(a1) != "8")&&(parseInt(a1) != "9")) { document.getElementById("cho").value = 0;a1 = parseInt(0);}else{document.getElementById("cho").value = 2;a1 = parseInt(2);}}else{a1 =parseInt(a1);}
	if ((parseInt(a2) != "1")&&(parseInt(a2) != "2")&&(parseInt(a2) != "3")) { if ((parseInt(a2) != "4")&&(parseInt(a2) != "5")&&(parseInt(a2) != "6")&&(parseInt(a2) != "7")&&(parseInt(a2) != "8")&&(parseInt(a2) != "9")) { document.getElementById("mor").value = 0;a2 = parseInt(0);}else{document.getElementById("mor").value = 2;a2 = parseInt(2);}}else{a2 =parseInt(a2);}
	if ((parseInt(a3) != "1")&&(parseInt(a3) != "2")&&(parseInt(a3) != "3")) { if ((parseInt(a3) != "4")&&(parseInt(a3) != "5")&&(parseInt(a3) != "6")&&(parseInt(a3) != "7")&&(parseInt(a3) != "8")&&(parseInt(a3) != "9")) { document.getElementById("tut").value = 0;a3 = parseInt(0);}else{document.getElementById("tut").value = 2;a3 = parseInt(2);}}else{a3 =parseInt(a3);}
	if ((parseInt(a4) != "1")&&(parseInt(a4) != "2")&&(parseInt(a4) != "3")) { if ((parseInt(a4) != "4")&&(parseInt(a4) != "5")&&(parseInt(a4) != "6")&&(parseInt(a4) != "7")&&(parseInt(a4) != "8")&&(parseInt(a4) != "9")) { document.getElementById("gre").value = 0;a4 = parseInt(0);}else{document.getElementById("gre").value = 2;a4 = parseInt(2);}}else{a4 =parseInt(a4);}
	if ((parseInt(a5) != "1")&&(parseInt(a5) != "2")&&(parseInt(a5) != "3")) { if ((parseInt(a5) != "4")&&(parseInt(a5) != "5")&&(parseInt(a5) != "6")&&(parseInt(a5) != "7")&&(parseInt(a5) != "8")&&(parseInt(a5) != "9")) { document.getElementById("blu").value = 0;a5 = parseInt(0);}else{document.getElementById("blu").value = 2;a5 = parseInt(2);}}else{a5 =parseInt(a5);}
	
	
	quantidade = (a1+a2+a3+a4+a5);

	document.getElementById("selecionado").value=quantidade;
}
function enquete(tipo,string){
	switch (tipo) {
		case 1:
			ajax('enquetePorque','../enquete/subitens.asp?string='+string,2);
		break;
		case 2:
			ajax('enqueteProcesso','../enquete/cadastraEnquete.asp?'+ajaxFormPost("enqueteForm"),1,'Carregando...')
		break;
		case 3:
			ajax('enquete','../enquete/pequenaAjax.asp',2)
		break;
		case 4:
			ajax('enqueteResultado','../enquete/resultado.asp?id='+string,2)
		break;
	}
}
function ajax(id,url,mensagem,txt,post){
	if (!mensagem) {
		mensagem = "Carregando...";
	}
	switch (mensagem) {
		case 1: carregando = txt; break;
		case 2: carregando = '<img src="../imagens/carregando.gif" />'; break;
		case 5: carregando = txt+'<img src="../imagens/carregando.gif" />'; break;
		default: carregando = 'Carregando...';
	}
	if (document.getElementById(id)) {
	    document.getElementById(id).innerHTML=carregando;
	}
	url =replaceAll(url, "&amp;", "&");

    fila[fila.length]=[id,url,post];
	ajaxSelect();
}
function ajaxRun1(){
	var pagina = fila[ultimoEx1][1]
	var div = fila[ultimoEx1][0]
	var postar = fila[ultimoEx1][2]
	if (postar) {
		metodo = "POST";
	}else{
		metodo = "GET";
	}
    xmlhttp1.open(metodo,encodeURI(pagina),true);
	xmlhttp1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
    xmlhttp1.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 
    xmlhttp1.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); 
    xmlhttp1.onreadystatechange=function() {
        if (xmlhttp1.readyState==4){
			if (document.getElementById(div)) {
	            document.getElementById(div).innerHTML=xmlhttp1.responseText;
			}
			verificarAjax('scripts',div);
            ifila++;
            ajaxSelect();
        }
    }
    xmlhttp1.send(ajaxFormPost(postar))
	postar=null;
}
function ajaxRun2(){
	var pagina = fila[ultimoEx2][1]
	var div = fila[ultimoEx2][0]
	var postar = fila[ultimoEx2][2]
	if (postar) {
		metodo = "POST";
	}else{
		metodo = "GET";
	}
    xmlhttp2.open(metodo,encodeURI(pagina),true);
	xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
    xmlhttp2.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 
    xmlhttp2.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); 
    xmlhttp2.setRequestHeader("Pragma", "no-cache");
    xmlhttp2.onreadystatechange=function() {
		if (postar) {
			
		}
        if (xmlhttp2.readyState==4){
			if (document.getElementById(div)) {
	            document.getElementById(div).innerHTML=xmlhttp2.responseText;
			}
			verificarAjax('scripts',div);
            ifila++;
            ajaxSelect();
        }
    }
    xmlhttp2.send(ajaxFormPost(postar))
	postar=null;
}

function ajaxFormPost(local){
	if (local) {
		var localValidar = document.getElementById(local);
		var inputs = localValidar.getElementsByTagName("input");
		var textareas = localValidar.getElementsByTagName("textarea");
		var selectinput = localValidar.getElementsByTagName("select");
		var radioinput = localValidar.getElementsByTagName("radio");
		var retorno = "";
		for (var i=0; i < inputs.length; i++){
			switch (inputs[i].type) {
				case "checkbox":
					if (inputs[i].checked) {
						retorno += inputs[i].name + "=" + 
						inputs[i].value + "&";
					} 
				break;
				case "radio":
					if (inputs[i].checked) {
						retorno += inputs[i].name + "=" + 
						inputs[i].value + "&";
					}
				break;
				default:
					retorno += inputs[i].name + "=" + 
					inputs[i].value + "&";
					
				break;
			}
		}
		for (var i=0; i < textareas.length; i++){
			var valor = replaceAll(textareas[i].value,'&','{{}}');
			var valor = replaceAll(valor,'\n','{{espaco}}');
			retorno += textareas[i].name+"="+valor + "&";
		}
		for (var i=0; i < selectinput.length; i++){
			var valor = replaceAll(selectinput[i].value,'&','{{}}');
			var valor = replaceAll(valor,'\n','{{espaco}}');
			retorno += selectinput[i].name+"="+valor + "&";
		}
		return encodeURI(retorno);
	}else{
		return null;	
	}
} 
//Fila de conexões
fila=[]
ifila=0
ultimoObj="xmlhttp2"
ultimoEx1=-1
ultimoEx2=-1


function ajaxSelect(){
	if(ifila<fila.length){
		if (((xmlhttp1.readyState==0)||(xmlhttp1.readyState==4))&&(ultimoEx2!=ifila)&&(ultimoObj!="xmlhttp1")){
			ultimoEx1=ifila;
			ajaxRun1();
			ultimoObj="xmlhttp1"
		}else{
			if (((xmlhttp2.readyState==0)||(xmlhttp2.readyState==4))&&(ultimoEx1!=ifila)&&(ultimoObj!="xmlhttp2")){
				ultimoEx2=ifila;
				ajaxRun2();
				ultimoObj="xmlhttp2"
			}
		}
	}
}
function replaceAll(string, palavra, nova) {
	while (string.indexOf(palavra) != -1) {
 		string = string.replace(palavra, nova);
	}
	return string;
}
function verificarAjax(qualDiv,pai){
	var scripts = document.getElementById(qualDiv);
    if(scripts){
    	var corpo = window.document.getElementsByTagName('body')[0];
        var js = window.document.createElement('script');
        js.text = scripts.innerHTML;
 		js.text=replaceAll(js.text, "&amp;", "&");
		js.text=replaceAll(js.text, "%", " ");
        js.type = 'text/javascript';
        corpo.appendChild(js); 
		corpo.removeChild(js);
		if (document.getElementById(pai)){
			document.getElementById(pai).removeChild(scripts);
		}
    }
}
/* funcoes tratamento de mascara */

function mascara(o,f,vari){
    v_obj=o
    v_fun=f
	v_var=vari
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}
function soNumeros2(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function vcep(v){
    v=v.replace(/\D/g,"")               //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function masc_ni(v){
    v=v.replace(/\D/g,"")               //Remove tudo o que não é dígito
    v=v.replace(/^(\d{8})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function data(v){
    v=v.replace(/\D/g,"")               //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca hífen entre o quarto e o quinto dígitos
	v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function moeda(v){  
    v=v.replace(/\D/g,"")
    v=v.replace(/[0-9]{12}/,"inválido")   //limita pra máximo 999.999.999,99
    v=v.replace(/(\d{1})(\d{8})$/,"$1.$2")  //coloca ponto antes dos últimos 8 digitos
    v=v.replace(/(\d{1})(\d{5})$/,"$1.$2")  //coloca ponto antes dos últimos 5 digitos
    v=v.replace(/(\d{1})(\d{1,2})$/,"$1,$2")    //coloca virgula antes dos últimos 2 digitos
    return v
}
function openModal(pUrl, pWidth, pHeight) {
	if (window.showModalDialog) {
		return window.showModalDialog(pUrl, window,
		  "dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px");
	} else {
		try {
			netscape.security.PrivilegeManager.enablePrivilege(
			  "UniversalBrowserWrite");
			window.open(pUrl, "wndModal", "width=" + pWidth
			  + ",height=" + pHeight + ",resizable=no,modal=yes");
			return true;
		}
		catch (e) {
			alert("Não é possível abrir janela.");
			return false;
		}
	}
}

function calcTotal(id){
	valorUnit = (document.getElementById('valor'+id).innerHTML).replace(',','.');
	desconto = (document.getElementById('desc'+id).innerHTML).replace(',','');
	qntidade = document.getElementById('qnt'+id).value;
	if ((qntidade=="")||(qntidade=="0")){
		document.getElementById('total'+id).innerHTML="0,00";
		calculo = 0;
	}else{
		string = "("+valorUnit+"*"+qntidade+")-(("+valorUnit+"*"+qntidade+")*0."+desconto+")";
		calculo = eval(string);
		document.getElementById('total'+id).innerHTML=format_number(calculo,2);
	}
	var i=0;
	
	var totalProd = 0;
	
	var totalPreco = 0;
	for (i=0;i<parseInt(document.getElementById('contTotal').value);i++)
	{
		p = i + 1
		if(document.getElementById('qnt'+p)){
		if (document.getElementById('qnt'+p).value==""){
			document.getElementById('qnt'+p).value = "0"
		}
		totalProd += parseInt(document.getElementById('qnt'+p).value);
		totalPreco += parseFloat((document.getElementById('total'+p).innerHTML).replace(',','.'));
		}
	}
	document.getElementById('totalProd').innerHTML=totalProd;
	document.getElementById('totalPreco').innerHTML=format_number(totalPreco,2);
}

function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return "0,00"};
	if (pnumber=='') { return "0,00"};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}
	if (result==0){
		return "0,00";
	}else{
		return result.replace(".",",");
	}
}
function checar(valor){
	
	var barrar = document.getElementById('barrar').value;
	var valorTotal = parseFloat(document.getElementById('totalPreco').innerHTML.replace(',','.'));
	var valorMinimo = parseFloat(valor.replace(',','.'));
	var qntKit = document.getElementById('qnt1').value;
	var valorKit = parseFloat(document.getElementById('valor1').innerHTML.replace(',','.')) * qntKit;
	
	if(barrar != 1) {
		//Subtrair valor do Kit
		if(qntKit > 0) {		
			valorTotal = (valorTotal - valorKit);
		}
	}
	
	if(valorTotal < valorMinimo) {
		if(barrar == 1) {
			alert("Sua primeira compra precisa ser igual ou superior a R$ "+valor+". \n*Incluído o Kit de Negócios.");
			return false;	
		} else {
			alert("Sua compra em produtos precisa ser igual ou superior a R$ "+valor+".\n*Obs: Kits de Negócios não somam-se a esse valor.");
			return false;
		}
	} else {
		ajax('divPedido','../g6FazerCompra/passo1_part2.asp',1,'Registrando...','formPedido');
		return false;
	}
}
var idJanelaCarrinhoVar = 0;
var idJanelaCarrinhoCat = 0;
function idJanelaCarrinho(valor, cat){
	if ((idJanelaCarrinhoVar != 0) && (idJanelaCarrinhoVar != valor) && (idJanelaCarrinhoCat == cat)){
		document.getElementById(idJanelaCarrinhoVar+'addProd').style.visibility='hidden';
	}
	if (idJanelaCarrinhoCat != cat){
		idJanelaCarrinhoCat = cat;
	}
	idJanelaCarrinhoVar = valor;
}