//'-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
//' Loja Exemplo Locaweb 
//' Versão: 6.3
//' Data: 12/09/06
//' Arquivo: funcoes_js.js
//' Versão do arquivo: 0.0
//' Data da ultima atualização: 21/08/07
//'
//'-----------------------------------------------------------------------------
//' Licença Código Livre: http://comercio.locaweb.com.br/gpl/gpl.txt
//'-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

//# FUNCOES CEP

//###################################################################################
function disable_form() {
	document.frm.cep.disabled		= true;
	document.frm.cep.value			= '';

}
//###################################################################################
function mostraiframe(linha) {
var linha = document.getElementById(linha);
  if (linha.style.display=='none') {
   linha.style.display='';
  } else {
   linha.style.display='none';
  }
}
//###################################################################################
function alteraiframe(linha,acao) {
var linha = document.getElementById(linha);
  if (acao=='exibe') {
   linha.style.display='';
  } else {
   linha.style.display='none';
  }
}
//###################################################################################
function enable_form() {
	document.frm.cep.disabled		= false;
}


//###################################################################################
function pesquisar_cep(pais,cep,pesofrete,regiaoenvio) {

    var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_cep');
	tempIFrame.setAttribute('name','iframe_cep');

	tempIFrame.style.border			= '0px';
	tempIFrame.style.width			= '0px';
	tempIFrame.style.height			= '0px';
//    alert("chamando cep_frete");
	tempIFrame.setAttribute('src','cep_frete.asp?pais='+pais+'&cep='+cep+'&pesofrete='+pesofrete+'&regiaoenvio='+regiaoenvio);
	IFrameObj = document.body.appendChild(tempIFrame);
}

//###################################################################################
function valida_pesquisar_cep() {

    // pais
//    var DROPpais = document.frm.paises;
//    var pais = DROPpais.options[DROPpais.selectedIndex].value;
     var pais = "BR"
    // cep
	document.frm.cep.value=""+document.frm.cep1.value+document.frm.cep2.value
   var format_cep = document.frm.cep.value.replace("-", "");
	

        if (format_cep.length == 8){
            executar_pesquisar_cep();
        } else {
            alert(ValPesqCepALERTcepinvalido);
            document.frm.cep1.focus();
        }
 

}

//###################################################################################
function executar_pesquisar_cep() {
	// pais
  // var DROPpais = document.frm.paises;
  // var pais = DROPpais.options[DROPpais.selectedIndex].value;
    var pais = "BR"
    document.frmEditContact.pais_frete.value = pais;

    // cep
//    var cep = document.frm.cep.value.replace("-", "");
    var cep="" + document.frm.cep1.value + "" + document.frm.cep2.value + "";

    //peso
    var peso = document.frm.pesofrete.value;
    
    pesquisar_cep(pais,cep,peso);
}

//###################################################################################
function send_frete(string) {
 var cidade_estado1=document.frmEditContact.cidade_estado.value.split("|");
 var vfrete = string.split('#');
//  beto alterado para permitir moto boy

  SndFrtALERTopcaofreteTMP = SndFrtALERTopcaofrete.replace("varOpcaoFrete", ""+vfrete[0])+"";

  if (vfrete[0] == "MOTO BOY PARA A CIDADE DE SP" )  {
  SndFrtALERTopcaofreteTMP = "A opção de frete escolhida foi MOTO BOY para a cidade de São Paulo.\n O valor da entrega será acertado com o cliente via telefone/email.";
  } else {
//    SndFrtALERTopcaofreteTMP = "- A opção de frete escolhida foi " + vfrete[0] + " no valor de R$ " + vfrete[2] +"\n- Envio para a cidade de " + cidade_estado1[0] + ", estado - " + cidade_estado1[1]
      SndFrtALERTopcaofreteTMP = "- A opção de frete escolhida foi " + vfrete[0] + " no valor de R$ " + vfrete[2];
  }
  var trab_tot2zx =eval(vfrete[2].replace(",",".")) + eval(valor_compra);
  trab_tot2zx=trab_tot2zx.toFixed(2)
  trab_tot2zx=trab_tot2zx.replace(".",",")
//  var conf_frete = confirm(SndFrtALERTopcaofreteTMP+'\n- O total do pedido ficou em R$ '+ trab_tot2zx + ' ( R$ '+ vfrete[2] + ' + R$ ' + valor_compra.toFixed(2).replace(".",",") +' )\n\n- Clique em OK.\n- Escolha a forma de pagamento.\n- Clique em fechar pedido para finalizar sua compra.');
  conf_frete=true
 if (conf_frete==true) {
   document.frmEditContact.opcao_frete.value = vfrete[0];
   document.frmEditContact.frete.value = vfrete[2];
   document.frmEditContact.cep_frete.value = vfrete[3];
   document.frmEditContact.submit();
 }
}

//###################################################################################
function handleResponse(informacoes,cidade) {
	document.frmEditContact.cidade_estado.value=cidade;
	
	//	alert(informacoes);
	
    /////////////////////
    var tbl = document.getElementById('freteTable'); 
    var lastRow = tbl.rows.length; 
    if (lastRow > 0) tbl.deleteRow(lastRow - 1);

    if (informacoes != 0) {
	
        var verify_informacoes = informacoes.indexOf("#");

        if (verify_informacoes>=0) {
		
            var CEP = document.frm.cep.value;
            var textoCEP = document.frm.textocep.value;
        
            var x=document.getElementById('freteTable').insertRow(0);
            var y=x.insertCell(0);
            y.innerHTML="<table id='"+ CEP +"' border='0' width='100%' cellpadding='0' cellspacing='2'></table>";

            /////////////////////

            var array_informacoes = informacoes.split("#");

            var x=document.getElementById(CEP).insertRow(0);
            var y=x.insertCell(0);
            x.height="25"
            x.bgColor="#FEE247"
            y.innerHTML='<b>&nbsp;&nbsp;&nbsp;Escolha abaixo a opção de ENVIO:</b>' ;

            var part_num=0;
            var count = 0;
            var mod = 0;
            var color;

            while (part_num < array_informacoes.length) {
                
                if (mod==0) {
                    mod = 1;
                    color = '#FFFFFF';
                } else {
                    mod = 0;
                    color = '#F5F5F5';
                }
                
                var array_frete = array_informacoes[part_num].split(":");
                
                if (array_frete[2] != "ok") {
                    // Insere o option na tabela
                    var nRows=document.getElementById(CEP).rows.length
                    var x=document.getElementById(CEP).insertRow(nRows)
                    var y=x.insertCell(0)
                    y.innerHTML= array_frete[0] + ": " + array_frete[2] 
                    count+=1;
                } else {
                    
                    if (array_frete[1] != "vazio") {
                        //Trata o valor do frete conforme a moeda utilizada
                        var verify_vlrFRETE = array_frete[1].indexOf("|");
                        if (verify_vlrFRETE>=0) {
                            var vlrFRETE = array_frete[1].split("|");
                            var vlrFRETE_REAL = vlrFRETE[0];
                            var vlrFRETE_VIS = vlrFRETE[1];
                        } else {
                            var vlrFRETE_REAL = array_frete[1];
                            var vlrFRETE_VIS = array_frete[1];
                        }
                        // Insere o option na tabela
		                var x=document.getElementById(CEP).insertRow(1)
		                var y=x.insertCell(0)
                        x.height="10"
                        x.bgColor=color
						
						//   BETO MOTO BOY PARA sp

						y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + ", envio pelos correios ( R$ " + vlrFRETE_VIS + " )";
					    if ( array_frete[0] == "MOTO BOY PARA A CIDADE DE SP"){
					    y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + " - <img onmouseover=\"showhint('&lt;b&gt;Moto Boy&lt;/b&gt;&lt;br&gt;O cliente recebe o pedido por moto boy, o valor do frete é acertado com o cliente por um de nossos atendentes via telefone/e-mail. O pagamento pode ser feito utilizando todos os cartões de crédito pelo site ou em dinheiro ao motoboy. O motoboy não tem conhecimento do conteúdo do pacote e nem da loja que enviou.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Horário de entrega e valor do motoboy a combinar por telefone/e-mail"; 
   		                }	
                        if ( array_frete[0] == "FRETE GRATIS" ){
					    y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + ", envio pelos correios por ENCOMENDA NORMAL" + " - <img onmouseover=\"showhint('&lt;b&gt;Encomenda normal (PAC)&lt;/b&gt;&lt;br&gt;O pedido é enviado pelo Correios diretamente para o endereço informado pelo cliente.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Entrega de 5 a 10 dias úteis, após a postagem."; 
   		                }	
						if ( array_frete[0] == "ENCOMENDA NORMAL" ){
					    y.innerHTML=y.innerHTML + " - <img onmouseover=\"showhint('&lt;b&gt;Encomenda normal (PAC)&lt;/b&gt;&lt;br&gt;O pedido é enviado pelos Correios diretamente para o endereço informado pelo cliente.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Entrega de 5 a 10 dias úteis, após a postagem."; 
   		                }	

						if ( array_frete[0] == "SEDEX"){
					    y.innerHTML=y.innerHTML + " - <img onmouseover=\"showhint('&lt;b&gt;Sedex&lt;/b&gt;&lt;br&gt;O pedido é enviado pelos Correios diretamente para o endereço informado pelo cliente, é uma das formas mais rápida de entrega.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Entrega de 2 a 3 dias úteis, após a postagem.";
						}
						
						if ( array_frete[0] == "E-SEDEX"){
					    y.innerHTML=y.innerHTML + " - <img onmouseover=\"showhint('&lt;b&gt;E-Sedex&lt;/b&gt;&lt;br&gt;O pedido é enviado pelos Correios diretamente para o endereço informado pelo cliente, é uma das formas mais rápida de entrega.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Entrega de 2 a 3 dias úteis, após a postagem.";
						}
						
						if (array_frete[0] == "SEDEX A COBRAR" ){
					    y.innerHTML=y.innerHTML + " - <img onmouseover=\"showhint('&lt;b&gt;Sedex a cobrar&lt;/b&gt;&lt;br&gt;O pedido é enviado para a agência dos Correios mais próxima do endereço informado pelo cliente. O cliente fará a retirada, lembramos que para essa modalidade de envio o pagamento é a vista. Não existe nenhuma referência sobre a loja ou conteúdo no pacote.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Entrega de 2 a 3 dias úteis, após a postagem.";
						}
						
						if ( array_frete[0] == "POSTA RESTANTE" ){
					    y.innerHTML=y.innerHTML + " - <img onmouseover=\"showhint('&lt;b&gt;Posta restante&lt;/b&gt;&lt;br&gt;Seu pedido é enviado para a agência dos Correios de sua preferência, o pedido é retirado na própria agência, não existe nenhuma referência sobre a loja ou conteúdo no pacote.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Disponível de 2 a 3 dias úteis no correio, após a postagem.";
   		                }
						if ( array_frete[0] == "RETIRAR NA LOJA"){
					    y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + " - <img onmouseover=\"showhint('&lt;b&gt;Retirar na LOJA&lt;/b&gt;&lt;br&gt;Será agendado dia e hora para que o cliente retire o pedido na LOJA que fica localizada na zona NORTE de São Paulo, o pagamento poderá ser feito com todos os cartões de crédito antecipadamente pelo site ou no ato da retirada somente em dinheiro.', this, event, '250px')\" src=\"http://www.shopsex.com.br/sexshop/config/imagens_conteudo/padrao/inter.gif\" width=\"15\" height=\"13\" />" + " - Loja na zona NORTE de São Paulo, horário de retirada a combinar por telefone/e-mail"; 
   		                }

						
						count+=1;
                    }
                
                }
                part_num+=1;
            }
            
            if (count == 0) {
                var x=document.getElementById('freteTable').insertRow(0)
                var y=x.insertCell(0)
                y.innerHTML=HndRespALERTsemfrete
            }
            
            enable_form();
        
        } else {
            
            var vfrete = informacoes.split(":");

            if (vfrete[2] != "ok") {
                
                var CEP = document.frm.cep.value;
                var textoCEP = document.frm.textocep.value;
            
                var x=document.getElementById('freteTable').insertRow(0);
                var y=x.insertCell(0);
                y.innerHTML="<table id='"+ CEP +"' border='0' width='100%' cellpadding='0' cellspacing='2'></table>";

                var x=document.getElementById(CEP).insertRow(0);
                var y=x.insertCell(0);
                x.height="25"
                x.bgColor="#FEE247"
                y.innerHTML='<b>&nbsp;&nbsp;&nbsp;' + textoCEP + " " + CEP + ':</b>' ;
                
                // Insere o option na tabela
                var x=document.getElementById(CEP).insertRow(1)
                var y=x.insertCell(0)
                y.innerHTML= vfrete[0] + ": " + vfrete[2] 
                count+=1;
            
            } else {

                //Trata o valor do frete conforme a moeda utilizada
                var verify_vlrFRETE = vfrete[1].indexOf("|");
                
                if (verify_vlrFRETE>=0) {
                    var vlrFRETE = vfrete[1].split("|");
                    var vlrFRETE_REAL = vlrFRETE[0];
                    var vlrFRETE_VIS = vlrFRETE[1];
                } else {
                    var vlrFRETE_REAL = vfrete[1];
                    var vlrFRETE_VIS = vfrete[1];
                }
                
                document.frmEditContact.opcao_frete.value = vfrete[0];
                document.frmEditContact.frete.value = vlrFRETE_REAL;
                document.frmEditContact.cep_frete.value = document.frm.cep.value;
                document.frmEditContact.submit();
	        
            }
        }
    
    } else {
        disable_form();
        document.frm.cep.disabled = false;
        var x=document.getElementById('freteTable').insertRow(0)
		var y=x.insertCell(0)
		y.innerHTML=HndRespALERTsemfrete
    }

}

//###################################################################################
function mostra_cep() {

  Form = document.carrinho;
  if ( (Form.cep1.value.length == 5) && (checatab) ) { 
   Form.cep2.focus();
   checatab=false;
  } 
} 

//###################################################################################
/*VERIFICA*/
function cadastro_cep_verificar(cep){
	if (!alterado_cep)	{
		alterado_cep = true;
		document.all.cep.focus();
		document.all.numero.value = '';
		document.all.complemento.value = '';
	}
}

//###################################################################################
function check_meiopag(opcaopag){
	var fr = document.OpcaoPag;
	for(a=0;a<fr.elements.length;a++){
		if(fr.elements[a].value == opcaopag){
			
			fr.elements[a].checked = true;
		}
	}
}



//# FUNCOES LOJA

//###################################################################################
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
return true;
}

//###################################################################################
function remover_produto(nome) {
	eval("document.carrinho."+nome+".value = 0");  // estamos zerando o carrinho.
	document.carrinho.submit ();
}

//###################################################################################
function atualizar_carrinho() {
	var resposta, Form;
	Form = document.carrinho;
	resposta = true;
	if (Form.tipofrete.value == "SEDEX" && (Form.cep1.value.length != 0 || Form.cep2.value.length != 0)) {
		resposta = valida_cep();
	}
	if (resposta == true)
		document.carrinho.submit ();
}

//###################################################################################
function calcular_frete() {
	var resposta;
	resposta = valida_cep();
	if (resposta == true)
		document.carrinho.submit ();
}

//###################################################################################
function mostra_calculo_frete() {
	var Form;
	Form = document.pagamento;
	janela = window.open('calculo_frete.asp?valor=' + Form.subtotal.value + '&frete=' + Form.taxa_envio.value + '&cepdestino=' + Form.cep.value + '&peso=' + Form.peso.value + '&tipo_sedex=' + Form.tipo_sedex.value,'promocao','width=600,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes')
	if (janela != null) {
		janela.location.href ='calculo_frete.asp?valor=' + Form.subtotal.value + '&frete=' + Form.taxa_envio.value + '&cepdestino=' + Form.cep.value + '&peso=' + Form.peso.value + '&tipo_sedex=' + Form.tipo_sedex.value
	}
}

//###################################################################################
function metodo_pagamento(nome) { 
	var carteira, i, sel, num_pag, temp, metodo_pag, ssl, acao;
	var Form;
	Form = document.carrinho;
	num_pag = document.pagamento.num_pagamentos.value;
	
	if (document.pagamento.tipo.value == false) {
		alert(MtdPagALERTselpag);
		return false;
	} 

	if (document.pagamento.taxa_envio.value == 0 && !document.carrinho.frete_teste) {
		alert(MtdPagALERTcalcfrete);
		return false;
	} else { 
		if (num_pag == "1") {
			temp = document.pagamento.tipo.value;
			acao = document.pagamento.URL_Autentica.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
			eval("document.pagamento.action='" + acao + "'");
			document.pagamento.submit();
		} else {
			for (i=0; i<num_pag; i++) {
				if (document.pagamento.tipo.value == true) {
					sel = i;
				break;
				}
			}
			temp = document.pagamento.tipo.value;
		}
		// VISA1
		// VISA - VisaNet, 1 - com SSL

		metodo_pag = temp.substring(0,temp.length-1);

		if (metodo_pag == "AMEX" || metodo_pag == "AMEXPOS"|| metodo_pag == "REDECARD" || metodo_pag == "RCARDPOS"|| metodo_pag == "VISA" || metodo_pag == "VISAPOS") metodo_pag = "CARTAO"; 
			ssl = temp.substring(temp.length-1,temp.length);
	
		if (ssl == "0") {
			acao = document.pagamento.URL_Autentica.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
		} else {
			acao = document.pagamento.URL_Autentica_seguro.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
		}

		if (metodo_pag == "CARTAO") {
			acao = acao + "&cartao=" + temp.substring(0,temp.length-1);
		}

		eval("document.pagamento.action='" + acao + "'");

		document.pagamento.submit();
	}
}

//###################################################################################
function valida_busca() {

	Form = document.busca;
	
	if (Form.query.value == "") {
		alert("Digite uma frase ou nome do produto");
		Form.query.focus();
		return false;
	}
	
    if (Form.query.value.length == 0) {
	    alert("Digite uma frase ou nome do produto");
		Form.query.focus();
		return false;
	}

    if (Form.query.value.length < 3) {
		alert(VldBuscaALERTminbusca);
		Form.query.focus();
		return false;
	}

//    if (!Form.codigo_categoria) {
 //       alert(VldBuscaALERTexistecatbusca);
   //     return false;
 //   }
	
 //   if (Form.codigo_categoria.value == '') {
	//	alert(VldBuscaALERTcatbusca);
//		Form.codigo_categoria.focus();
	//	return false;
//	}
}


//###################################################################################
function valida_cep() {

	Form = document.carrinho;
	if (Form.cep1.value.length == 0) {
		alert(VldCepALERTcampocep);
		Form.cep1.focus();
		return false;
	}
	if (Form.cep2.value.length == 0) {
		alert(VldCepALERTcampocep);
		Form.cep2.focus();
		return false;
	}
	s = limpa_string(Form.cep1.value);
	if (s.length != 5) {
		alert(VldCepALERTcaractcep);
		Form.cep1.focus();
		return false;
	}
	s = limpa_string(Form.cep2.value);
	if (s.length != 3) {
		alert(VldCepALERTcaractcep);
		Form.cep2.focus();
		return false;
	}
	return true;
}

//###################################################################################
function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){temp=temp+digito}
	}
	return temp
}

//###################################################################################
function mostra_cep() {
	Form = document.carrinho;
	if ( (Form.cep1.value.length == 5) && (checatab) ) { 
		Form.cep2.focus();
		checatab=false;
	} 
}

//###################################################################################
function semtab() { checatab=false; }
function comtab() { checatab=true; } 
checatab=true;
        
//###################################################################################
function mostra_cep() {
	Form = document.carrinho;
	if ( (Form.cep1.value.length == 5) && (checatab) ) { 
		Form.cep2.focus();
		checatab=false;
	} 
} 

//###################################################################################
function menu_goto( menuform ) {
	selecteditem = menuform.local_frete_Exporta.selectedIndex ;
	local_frete_Exporta = menuform.local_frete_Exporta.options[ selecteditem ].value ;
	if (local_frete_Exporta.length != 0) {
		location.href = local_frete_Exporta ;
	}
}

//###################################################################################
function valida_cadastro(formname,tipoverif,cep_frete) {

	var Form;
	Form = formname;

	if (cep_frete == 'SEM FRETE') {
        if (tipoverif == 'CadPedido') {
            if ((valida_endereco(Form,'CadPedido') == false) || (valida_password(Form) == false)) {
                return false;
            }
        } else if (tipoverif == 'CadUsuario') {
            if (valida_endereco(Form,'CadUsuario') == false) {
                return false;
            }
        }
	} else {
        if ((valida_endereco(Form,'CadPedido') == false) || (valida_password(Form) == false) || (verifica_cep(cep_frete) == false)) {
            return false;
        }
    }

}

//###################################################################################
function valida_password(Form) {

	if (Form.tipo_login.value == "user_new") {
		if (Form.senha1.value.length == 0 || Form.senha2.value.length == 0) {
			alert(VldPwdALERTcamposenha);
			Form.senha1.focus();
			return false;
		}
		if (Form.senha1.value != Form.senha2.value) {
			alert(VldPwdALERTsenhadif);
			Form.senha1.focus();
			return false;
		}
	}

}

//###################################################################################
function valida_trocapassword(Form) {

	if (Form.senha_atual.value.length == 0) {
		alert(VldTrocaPwdALERTcamposenhaatual);
		Form.senha_atual.focus();
		return false;
	}
	if (Form.nova_senha.value.length == 0 || Form.confirma_senha.value.length == 0) {
		alert(VldTrocaPwdALERTcamposenha);
		Form.nova_senha.focus();
		return false;
	}
	if (Form.nova_senha.value != Form.confirma_senha.value) {
		alert(VldTrocaPwdALERTsenhadif);
		Form.nova_senha.focus();
		return false;
	}

}

//###################################################################################
function valida_faleconosco(Form) {

	if (Form.nome.value.length == 0) {
		alert(VldFaleConALERTcmpnome);
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldFaleConALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldFaleConALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert(VldFaleConALERTcmpassunto);
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert(VldFaleConALERTcmpcomentario);
		Form.comentarios.focus();
		return false;
	}

    return true;

}

//###################################################################################
function valida_newsletter(Form) {

	if (Form.nome.value.length == 0) {
		alert(VldNewsALERTcmpnome);
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldNewsALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldNewsALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

	Form.email.value = acerta_email(Form.email.value);
	
    return true;

}

//###################################################################################
function valida_endereco(Form,tipoverif) {

	var s;
    
	//if ((Form.tipcliente[0].checked==false) && (Form.tipcliente[1].checked==false)) {
//alert(VldEndALERTcmpfisjur);
  //    return false;
//	}

    //Dados Cobrança
    if (valida_dadosCobranca(Form) == false) {
        return false;
    }

    //Confirma o tipo de verificação
//	if (tipoverif == 'CadPedido') {
        // Dados Entrega
//        if (Form.cobranca_diferente.checked==true) {
  //          if (valida_dadosEntrega(Form) == false) {
    //            return false;
      //      }
 //       }
 //   } else if (tipoverif == 'CadUsuario') {
        // Dados Entrega
  //      if (valida_dadosEntrega(Form) == false) {
    //        return false;
   //     }
//    }

}

//###################################################################################
function valida_dadosCobranca(Form) {
    var s;
	
		if (Form.email_cobranca.value.length == 0) {
		alert("Email é um campo obrigatório !");
		Form.email_cobranca.focus();
		return false;
		}
		
      if (Form.email_cobranca.value.indexOf('@', 0) == -1 || Form.email_cobranca.value.indexOf('.', 0) == -1) {
      alert("Email deve possuir o caracter  '@' (arroba) e o caracter '.' (ponto) ! ")
      Form.email_cobranca.focus();
	  return false;
	  }
	
	   Form.email_cobranca.value = acerta_email(Form.email_cobranca.value);

      if (Form.tipcliente[1].checked==true) {

		if (Form.razaosocial_cobranca.value.length == 0) {
			alert(VldEndALERTcmprazaosocial);
			Form.razaosocial_cobranca.focus();
			return false;
		}

        if (Form.pais_cobranca.value == "BR") {
            
            var cnpj_cob = Form.cnpj_cobranca_b1.value + Form.cnpj_cobranca_b2.value + Form.cnpj_cobranca_b3.value + Form.cnpj_cobranca_b4.value + Form.cnpj_cobranca_b5.value;

            if (cnpj_cob.length == 0) {
                alert(VldEndALERTcmpcnpj);
                Form.cnpj_cobranca_b1.focus();
                return false;
            }
             
            s = limpa_string(cnpj_cob);
            if (s.length == 14) {
                if (valida_CNPJ(cnpj_cob) == false ) {
                    alert(VldEndALERTcmpcnpjinc);
                    Form.cnpj_cobranca_b1.focus();
                    return false;
                }
            }else{
                alert(VldEndALERTcmpcnpjinc);
                Form.cnpj_cobranca_b1.focus();
                return false;
            }

            Form.cnpj_cobranca.value = cnpj_cob;

        }

	}

	if (Form.nome_cobranca.value.length == 0) {
		alert(VldEndALERTcmpnome);
        Form.nome_cobranca.focus();
        return false;
	}
	
	if (Form.tip_frete.value == "POSTA RESTANTE") {
	if (Form.nome1_cobranca.value.length == 0) {
		alert("O nome da agência dos correios é um campo obrigatório");
        Form.nome1_cobranca.focus();
        return false;
	}}

  //  if (Form.pais_cobranca.options[Form.pais_cobranca.selectedIndex].value == "BR") {
    if (Form.tipocpf.value == "sim" ) {
		
        var cpf_cob = Form.cpf_cobranca_b1.value + Form.cpf_cobranca_b2.value + Form.cpf_cobranca_b3.value + Form.cpf_cobranca_b4.value;
     
       if (cpf_cob.length == 0) {
           alert("O número do CPF é obrigatório !");
          Form.cpf_cobranca_b1.focus();
          return false;
          }

         s = limpa_string(cpf_cob);
         if (s.length == 11) {
            if (valida_CPF(cpf_cob) == false ) {
                alert(VldEndALERTcmpcpfinc);
                Form.cpf_cobranca_b1.focus();
                return false;
             }
          }else{
               alert(VldEndALERTcmpcpfinc);
               Form.cpf_cobranca_b1.focus();
               return false;
          }

             Form.cpf_cobranca.value = cpf_cob;

           if (Form.rg_cobranca.value.length == 0) {
              alert("O número da carteira de Identidade é obrigatório !");
              Form.rg_cobranca.focus();
              return false;
             }
    
     }
	
    if (Form.logradouro_cobranca.value.length == 0) {
		alert(VldEndALERTcmpend);
		Form.logradouro_cobranca.focus();
		return false;
	}
     
	if (Form.numero_cobranca.value.length == 0) {
		alert(VldEndALERTcmpnum);
		Form.numero_cobranca.focus();
		return false;
	}
	
		if (Form.bairro_cobranca.value.length == 0) {
		alert("Bairro é um campo obrigatório !");
		Form.bairro_cobranca.focus();
		return false;
	}
     
    if (Form.pais_cobranca.value == "BR") {

        var cep_cob = Form.cep_cobranca_b1.value + Form.cep_cobranca_b2.value;

        if (cep_cob.length == 0) {
            alert(VldEndALERTcmpcep);
            Form.cep_cobranca_b1.focus();
            return false;
        }
         
        s = limpa_string(cep_cob);
        if (s.length != 8) {
            alert(VldEndALERTcmptamcep);
            Form.cep_cobranca_b1.focus();
            return false;
        }

        Form.cep_cobranca.value = cep_cob;
     
	}

    if (Form.cidade_cobranca.value.length == 0) {
		alert(VldEndALERTcmpcidade);
		Form.cidade_cobranca.focus();
		return false;
	}

    if (Form.estado_cobranca.value == "  ") {
		alert("Escolha o estado de sua residência");
		Form.estado_cobranca.focus();
		return false;
	}
  
 	 if (Form.tipo_pagamentos.value == "Pagar ao receber" || Form.tipo_pagamentos.value == "Sedex" || Form.tipo_pagamentos.value == "Visa" || Form.tip_frete.value == "MOTO BOY PARA A CIDADE DE SP" || Form.tip_frete.value == "SEDEX A COBRAR" || Form.tipo_pagamentos.value == "PagSeguro" || Form.tipo_pagamentos.value == "PagDigital" || Form.tipo_pagamentos.value == "VISADIGITAL" || Form.tipo_pagamentos.value == "MASTERCARD" || Form.tipo_pagamentos.value == "DINERS" || Form.tipo_pagamentos.value == "AMERICAN EXPRESS" || Form.tipo_pagamentos.value == "AURA" ) {
        if (Form.ddd_cobranca.value.length !== 2 || Form.ddd_cobranca.value == "00" ) {
            alert("O DDD do telefone fixo é um campo obrigatório nessa modalidade de FRETE/PAGAMENTO e deve ser preenchido com 2 dígitos");
            Form.ddd_cobranca.focus();
            return false;
        }
 
	
	  if (Form.telefone_cobranca.value.length !== 8 || Form.telefone_cobranca.value == "00000000") {
		alert("O telefone fixo é um campo obrigatório nessa modalidade de pagamento e dever ser preenchido com 8 dígitos");
		Form.telefone_cobranca.focus();
		return false;
	}}
	
	  if ((Form.ddd_cobranca.value.length !== 2 || Form.telefone_cobranca.value.length !== 8 ) && (Form.ddd1_cobranca.value.length !== 2 || Form.telefone1_cobranca.value.length !== 8 )) {
        
		alert("Pelo menos um número de telefone deve ser infomado ou telefone fixo ou celular, sendo o DDD com 2 dígitos e o telefone com 8 dígitos.");
		return false;
		}
	  
	  if (Form.tipobanco.value == "sim") {
	  if (Form.banco.value == "000") {
      alert("Selecione um banco para pagamento do pedido !")
		Form.banco.focus();
		return false;
	  }
	 }
	 
//	 if (Form.tipo_pagamentos.value == "Visa") {
//		if (Form.dados_adicionais.value == "") {
//	    alert("Favor escolher a quantidade de parcelas para pagamento no cartão de crédito !");
//		return false;
//		}
//	 }
		
//   desabilita botão
     Form.mandar.value="Favor aguardar.......";
	 Form.mandar.disabled=true;

	
		  
  //  Form.data_nascimento_cobranca.value = Form.data_nascimento_cobranca_b1.value + Form.data_nascimento_cobranca_b2.value + Form.data_nascimento_cobranca_b3.value;

}

//###################################################################################
function valida_dadosParceria(Form) {

    var s;

	if (Form.nome.value.length == 0) {
	alert("Nome deve ser informado");
        Form.nome.focus();
        return false;
	}
        var cpf_cob = Form.cpf_b1.value + Form.cpf_b2.value + Form.cpf_b3.value + Form.cpf_b4.value;
 
       if (cpf_cob.length == 0) {
           alert("O número do CPF é obrigatório");
          Form.cpf_b1.focus();
          return false;
          }

         s = limpa_string(cpf_cob);
         if (s.length == 11) {
            if (valida_CPF(cpf_cob) == false ) {
                alert("CPF digitado errado, favor conferir");
                Form.cpf_b1.focus();
                return false;
             }
          }else{
               alert("CPF deve ter ser digitado com 11 dígitos");
               Form.cpf_b1.focus();
               return false;
          }

           if (Form.rg.value.length == 0) {
              alert("O número da carteira de Identidade é obrigatória");
              Form.rg.focus();
              return false;
             }
  
    if (Form.logradouro.value.length == 0) {
		alert("Logradouro deve ser informado");
		Form.logradouro.focus();
		return false;
	}
     
	if (Form.numero.value.length == 0) {
		alert("Número da residência deve ser informado");
		Form.numero.focus();
		return false;
	}
	
		if (Form.bairro.value.length == 0) {
		alert("Bairro deve ser informado");
		Form.bairro.focus();
		return false;
	}
         var cep_cob = Form.cep_b1.value + Form.cep_b2.value;
        if (cep_cob.length == 0) {
            alert("CEP deve ser informado");
            Form.cep_b1.focus();
            return false;
        }
         
        s = limpa_string(cep_cob);
        if (s.length != 8) {
            alert("CEP deve ter 8 dígitos");
            Form.cep_b1.focus();
            return false;
        }

    if (Form.cidade.value.length == 0) {
		alert("Cidade deve ser informada");
		Form.cidade.focus();
		return false;
	}

    if (Form.estado.value == "  ") {
		alert("Escolha o estado de sua residência");
		Form.estado.focus();
		return false;
	}

        if (Form.ddd.value.length == 0) {
            alert("DDD deve ser informado");
            Form.ddd.focus();
            return false;
        }
  
	if (Form.telefone.value.length == 0) {
		alert("Telefone de contato deve ser informado");
		Form.telefone.focus();
		return false;
	}

	if (Form.favorecido.value.length == 0) {
		alert("Favorecido deve ser informado");
		Form.favorecido.focus();
		return false;
	}

	if (Form.banco.value.length == "") {
		alert("Escolha o banco onde será feito o crédito da comissão");
		Form.banco.focus();
		return false;
	}


	if (Form.agencia.value.length == 0) {
		alert("Agência bancária deve ser informado");
		Form.agencia.focus();
		return false;
	}

	if (Form.conta.value.length == 0) {
		alert("Conta bancária deve ser informado");
		Form.conta.focus();
		return false;
	}

	if (Form.dv.value.length == 0) {
		alert("Dígito verificador da conta bancária deve ser informado");
		Form.dv.focus();
		return false;
	}

		if (Form.email.value.length == 0) {
		alert("Email é um campo obrigatório !");
		Form.email.focus();
		return false;
		}
		
      if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
      alert("Email deve possuir o caracter  '@' (arroba) e o caracter '.' (ponto) ! ")
      Form.email.focus();
	  return false;
	  }

	if (Form.senha.value.length < 5) {
		alert("Senha deve ser informada com no mínimo 5 caracteres e máximo 10 caracteres");
		Form.senha.focus();
		return false;
	}

}



//###################################################################################
function valida_dadosEntrega(Form) {
    
	var s;

    if (Form.tipcliente[1].checked==true) {

        if (Form.razaosocial_entrega.value.length == 0) {
            alert(VldEndALERTcmprazaosocial);
            Form.razaosocial_entrega.focus();
            return false;
        }

        if (Form.pais_entrega.value == "BR") {
            
            var cnpj_ent = Form.cnpj_entrega_b1.value + Form.cnpj_entrega_b2.value + Form.cnpj_entrega_b3.value + Form.cnpj_entrega_b4.value + Form.cnpj_entrega_b5.value;

            if (cnpj_ent.length == 0) {
                alert(VldEndALERTcmpcnpj);
                Form.cnpj_entrega_b1.focus();
                return false;
            }
             
            s = limpa_string(cnpj_ent);
            if (s.length == 14) {
                if (valida_CNPJ(cnpj_ent) == false ) {
                    alert(VldEndALERTcmpcnpjinc);
                    Form.cnpj_entrega_b1.focus();
                    return false;
                }
            }else{
                alert(VldEndALERTcmpcnpjinc);
                Form.cnpj_entrega_b1.focus();
                return false;
            }

            Form.cnpj_entrega.value = cnpj_ent;

        }

    }

    if (Form.nome_entrega.value.length == 0) {
        alert(VldEndALERTcmpnome);
        Form.nome_entrega.focus();
        return false;
    }

    if (Form.pais_entrega.value == "BR") {

        var cpf_ent = Form.cpf_entrega_b1.value + Form.cpf_entrega_b2.value + Form.cpf_entrega_b3.value + Form.cpf_entrega_b4.value;

        if (cpf_ent.length == 0) {
            alert(VldEndALERTcmpcpf);
            Form.cpf_entrega_b1.focus();
            return false;
        }

        s = limpa_string(cpf_ent);
        if (s.length == 11) {
            if (valida_CPF(cpf_ent) == false ) {
                alert(VldEndALERTcmpcpfinc);
                Form.cpf_entrega_b1.focus();
                return false;
            }
        }else{
            alert(VldEndALERTcmpcpfinc);
            Form.cpf_entrega_b1.focus();
            return false;
        }

        Form.cpf_entrega.value = cpf_ent;

        if (Form.rg_entrega.value.length == 0) {
            alert(VldEndALERTcmprg);
            Form.rg_entrega.focus();
            return false;
        }

    }

    if (Form.logradouro_entrega.value.length == 0) {
        alert(VldEndALERTcmpend);
        Form.logradouro_entrega.focus();
        return false;
    }

    if (Form.numero_entrega.value.length == 0) {
        alert(VldEndALERTcmpnum);
        Form.numero_entrega.focus();
        return false;
    }

    if (Form.pais_entrega.value == "BR") {

        var cep_ent = Form.cep_entrega_b1.value + Form.cep_entrega_b2.value;

        if (cep_ent.length == 0) {
            alert(VldEndALERTcmpcep);
            Form.cep_entrega_b1.focus();
            return false;
        }

        s = limpa_string(cep_ent);
        if (s.length != 8) {
            alert(VldEndALERTcmptamcep);
            Form.cep_entrega_b1.focus();
            return false;
        }
        
        Form.cep_entrega.value = cep_ent;

    }

    if (Form.cidade_entrega.value.length == 0) {
        alert(VldEndALERTcmpcidade);
        Form.cidade_entrega.focus();
        return false;
    }

    if (Form.telefone_entrega.value.length == 0) {
        alert(VldEndALERTcmptel);
        Form.telefone_entrega.focus();
        return false;
    }

    if (Form.pais_entrega.value == "BR") {
        if (Form.ddd_entrega.value.length == 0) {
            alert(VldEndALERTcmpddd);
            Form.ddd_entrega.focus();
            return false;
        }
    }

    if (Form.email_entrega.value.length == 0) {
        alert(VldEndALERTcmpemail);
        Form.email_entrega.focus();
        return false;
    }

    if (Form.email_entrega.value.indexOf('@', 0) == -1 || Form.email_entrega.value.indexOf('.', 0) == -1) {
        alert(VldEndALERTcmpemailinc); 
        Form.email_entrega.focus();
        return false;
    }

    Form.data_nascimento_entrega.value = Form.data_nascimento_entrega_b1.value + Form.data_nascimento_entrega_b2.value + Form.data_nascimento_entrega_b3.value;

}

//###################################################################################
function valida_cartao(Form) {

    var s;

    s = limpa_string(Form.ccn.value);
    if (s.length != 16) {
        alert(VldCartaoALERTcmptamnumcartao);
        Form.ccn.focus();
        return false;
    }
    
    if (Form.ccn.value.length == 0) {
        alert(VldCartaoALERTcmpnumcartao);
        Form.ccn.focus();
        return false;

    }

    if (Form.exp.value.length == 0) {
        alert(VldCartaoALERTcmpdataval);
        Form.exp.focus();
        return false;

    }

    if (Form.cvv2.value.length == 0) {
        alert(VldCartaoALERTcmpcodseg);
        Form.cvv2.focus();
        return false;

    }

    return true;

}

//###################################################################################
function valida_visa() {
	if (valida_endereco() == true) {
		document.Endereco.submit();
	}
	else return;
}

//###################################################################################
function limpa_string(S){
    // Deixa so' os digitos no numero
    var Digitos = "0123456789";
    var temp = "";
    var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}

//###################################################################################
function valida_CPF(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

//###################################################################################
function valida_CNPJ(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

//###################################################################################
function valida_numeros(s)
{
	var i; 
	var dif = 0;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!((c >= "0") && (c <= "9")))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		return false;
	}
	return true;
}

//###################################################################################
function copia_entrega(){
	var n='';
	var v='';
	var s='';
	var i=0;
	var form=document.Endereco;
	var x=form.length-1;
	if(form.cobranca_igual.checked){
		for(var y = 0; y <= x; y++){
			n=form.elements[y].name;			
			if(n.substring(0,2)=='b_'){
				s=n.substring(2,n.length);
				if(form.elements[s].type == "select-one"){					
					i=form.elements[s].selectedIndex;
					form.elements[n].selectedIndex=i;
				}
				else{
					
					v=form.elements[s].value;
					form.elements[n].value=v;
				}
			}
		}
	}
}

//###################################################################################
function mostradados(pri) {
  var element = document.getElementById(pri);

  if (element.style.display=='none') {
   element.style.display='';
  } else {
   element.style.display='none'
  }

}

//###################################################################################
function reenvio_pwd() {
   var fr = document.autent;

   if (fr.esquecisenha.checked == true) {
      fr.senha.disabled = true;
      fr.senha.value = '';
      fr.enviar.value = RnvPwdALERTreenvsenha;
   } else {
      fr.senha.disabled = false;
      fr.enviar.value = RnvPwdALERTautentusuario;
   }
}

//###################################################################################
function check_login() {
   var fr = document.autent;

   if (fr.user_id.value.length == 0) {
      alert(CkLoginALERTcmpemail);
      fr.user_id.focus();
      return false;
   }

   if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1) {
      alert(CkLoginALERTcmpemailinc); 
      fr.user_id.focus();
      return false;
   }

   if (fr.esquecisenha.checked == false) {
      if (fr.senha.value.length == 0) {
         alert(CkLoginALERTcmpsenha);
         fr.senha.focus();
         return false;
      }
   }
   return true;
}

//###################################################################################
function check_newlogin() {
   var fr = document.new_user;

   if (fr.user_id.value.length == 0) {
      alert(CkNwLoginALERTcmpemail);
      fr.user_id.focus();
      return false;
   }

   if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1) {
      alert(CkNwLoginALERTcmpemailinc); 
      fr.user_id.focus();
      return false;
   }
   return true;
}

//###################################################################################
function alteraTipCad() {
    
    var tipCadTextCob = document.getElementById('tipCadTextJuridico_cobranca');
    var tipCadInputCob = document.getElementById('tipCadInputJuridico_cobranca');
    var tipCadTextEnt = document.getElementById('tipCadTextJuridico_entrega');
    var tipCadInputEnt = document.getElementById('tipCadInputJuridico_entrega');
    var tipCadTextCob2 = document.getElementById('tipCadTextJuridico2_cobranca');
    var tipCadInputCob2 = document.getElementById('tipCadInputJuridico2_cobranca');
    var tipCadTextEnt2 = document.getElementById('tipCadTextJuridico2_entrega');
    var tipCadInputEnt2 = document.getElementById('tipCadInputJuridico2_entrega');
    
    if (document.Endereco.tipcliente[0].checked == true) {
        tipCadTextCob.style.display='none';
        tipCadInputCob.style.display='none';
        tipCadTextEnt.style.display='none';
        tipCadInputEnt.style.display='none';
        tipCadTextCob2.style.display='none';
        tipCadInputCob2.style.display='none';
        tipCadTextEnt2.style.display='none';
        tipCadInputEnt2.style.display='none';
        document.getElementsByName('razaosocial_cobranca')[0].value ='';
        document.getElementsByName('cnpj_cobranca_b1')[0].value ='';
        document.getElementsByName('cnpj_cobranca_b2')[0].value ='';
        document.getElementsByName('cnpj_cobranca_b3')[0].value ='';
        document.getElementsByName('cnpj_cobranca_b4')[0].value ='';
        document.getElementsByName('cnpj_cobranca_b5')[0].value ='';
        document.getElementsByName('inscricaoestadual_cobranca')[0].value ='';
        document.getElementsByName('razaosocial_entrega')[0].value ='';
        document.getElementsByName('cnpj_entrega_b1')[0].value ='';
        document.getElementsByName('cnpj_entrega_b2')[0].value ='';
        document.getElementsByName('cnpj_entrega_b3')[0].value ='';
        document.getElementsByName('cnpj_entrega_b4')[0].value ='';
        document.getElementsByName('cnpj_entrega_b5')[0].value ='';
        document.getElementsByName('inscricaoestadual_entrega')[0].value ='';
    } else {
        tipCadTextCob.style.display='';
        tipCadInputCob.style.display='';
        tipCadTextEnt.style.display='';
        tipCadInputEnt.style.display='';
        tipCadTextCob2.style.display='';
        tipCadInputCob2.style.display='';
        tipCadTextEnt2.style.display='';
        tipCadInputEnt2.style.display='';
    } 

}

//###################################################################################
function verifica_cep(cep_frete){
//    if (document.Endereco.tipo_acesso.value != "conta"){
  //      if (document.Endereco.cobranca_diferente.checked == true){
    //        if (cep_frete != document.Endereco.cep_entrega.value) {
      //          resposta = confirm(VrfCepALERTcepentdif);
        //        if (resposta == false) {
          //          return false;
            //    } else {
              //      document.Endereco.mode.value='changeItem';
                //    document.Endereco.cep_frete.value=document.Endereco.cep_entrega.value;
                  //  document.Endereco.submit();
       //             return false;
         //       }
   //         }
     //   } else {
       //     if (cep_frete != document.Endereco.cep_cobranca.value) {
         //       resposta = confirm(VrfCepALERTcepentcobdif);
           //     if (resposta == false) {
             //       return false;
       //         } else {
         //           document.Endereco.mode.value='changeItem';
         //           document.Endereco.cep_frete.value=document.Endereco.cep_cobranca.value;
           //         document.Endereco.submit();
         //           return false;
         //       }
       //     }
  //      }
 //   }
}

//###################################################################################
function pagamento() {
	vpos=window.open('','vpos','toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=600,height=400');
	document.pagamento.submit();
}

//###################################################################################
function JanelaNova(URLBoleto) {
	window.open(URLBoleto,'NOME','width=680,height=400,menubar,scrollbars,resizable');
}

//###################################################################################
function Start(VarForm,x,y) {
	vpos = window.open('','vpos','toolbar=no,menubar=no,resizable=yes,status=no,scrollbars=yes,width='+ x +',height='+ y +'');
	document.abnfinanc.submit();
}

//###################################################################################
function submit_bradesco(metodo_pag) {
	Form = document.Confirmacao;

	if (metodo_pag == "cc") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=CC'");
	} else if (metodo_pag == "transfer") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=TRANSFER'");                
	} else if (metodo_pag == "financiamento") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=FINANCIAMENTO'");                
	}
	document.Confirmacao.submit();
}

//###################################################################################
// formata data
function formata_data(formato, keypress, objeto) {
    campo = eval (objeto);

    if (formato=='DATA'){ 
        separador = '/'; 
        conjunto1 = 2; 
        conjunto2 = 5;
    }

    if (campo.value.length == conjunto1){ 
        campo.value = campo.value + separador; 
    }

    if (campo.value.length == conjunto2){ 
        campo.value = campo.value + separador; 
    } 

}

//###################################################################################
function mostraCarrinho(pri) {
	var textview = document.getElementById(pri);
		if (textview.style.display=='none') {
			textview.style.display='';
			} else {
			textview.style.display='none';
	}
}
//###################################################################################
function PopUp(theURL,winName,features) 
{
window.open(theURL,winName,features); 
}

//###################################################################################
function check_opcaopag(limite, fretegratis, opcaofrete,minimo) {	
	var fr = document.OpcaoPag;
	var check = false;
//	alert( fretegratis + "<>" + opcaofrete+"<>"+limite);
	if (opcaofrete == "FRETE GRATIS") {
		if (eval(limite) < eval(fretegratis)) {
	    alert("Informe novamente o CEP e escolha uma nova forma de envio, o frete grátis é só para compras acima de R$ "+fretegratis);
	    return		
		}
	}
	
	if (OpcaoPag.Scobrar.value == "sim") {
		if (eval(limite) < 60.) {
	    alert("Valor mínimo para pedido com opçao de pagamento SEDEX A COBRAR é de R$ 60,00 em produto. Por favor, escolha mais produtos !");
	    return		
		}
	}
	
	if (limite < minimo) {
	alert("O valor do pedido mínimo é de R$ " + minimo.toFixed(2) + " em produtos. Por favor, escolha mais produtos !");
	return
	}
	for(a=0;a<fr.elements.length;a++){
		if(fr.elements[a].name == 'tipo'){
			if (fr.elements[a].checked == true) {
				check = true;
				OpcaoPag.Scobrar.value=fr.elements[a].value;
				break;
			}
		}
	}
	if (OpcaoPag.Scobrar.value == "sim" ) {
	check = true
	}
	if (check == false) {
	alert(CkOpPagALERTselpag);
	} else {
	fr.submit();
	}
}

//###################################################################################
function valida_VisaMoset(Form) {

	if (Form.ccn.value.length == 0) {
		alert(VldMosetALERTcmpnumcartao);
		Form.ccn.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldMosetALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldMosetALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert(VldMosetALERTcmpassunto);
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert(VldMosetALERTcmpcomentario);
		Form.comentarios.focus();
		return false;
	}

    return true;

}

//###################################################################################
function fncLimpaValue(objTexto, sString)

	{

	if (sString == objTexto.value) {

		objTexto.value = '';
	}

}

//###################################################################################
function fncPreencheValue(objTexto, sString)

	{

	if (objTexto.value == '') {

		objTexto.value = sString;

	}

}
//###################################################################################
function atualiza_carrinho(tip) {
    var fr = document.frmEditContact;
    var qte_elements = 0;
    var liberado = true;
    var qte_escolhida, qte_atual, qte_maxima;
    var qte_diferenca;

    for (a=0;a<fr.elements.length;a++) {

        if(fr.elements[a].name == 'quantidade_produto') {
            qte_elements = qte_elements + 1;
        }
        
    }

    qte_elements = (qte_elements - 1);

    if (qte_elements>=1) {

        for (i=0;i<=qte_elements;i++) {
            
            qte_escolhida = fr.quantidade_produto[i].value;
            qte_atual = fr.quantidade_atual[i].value;
            qte_maxima = fr.quantidade_maxima[i].value

            qte_diferenca = qte_escolhida - qte_atual;
            var qte_tratada = String(qte_diferenca);
            
            if (qte_tratada.indexOf('-') == -1) {

                qte_tratada = Number(qte_tratada);

                if ((qte_tratada > qte_maxima) && (qte_maxima != 0)) {
                    alert(AtzCarALERTqtdestoque);
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

                if ((qte_escolhida > qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0)) {
                    alert(AtzCarALERTqtdestoque);
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

            }

        }
    
    } else {
        qte_escolhida = fr.quantidade_produto.value;
        qte_atual = fr.quantidade_atual.value;
        qte_maxima = fr.quantidade_maxima.value

        qte_diferenca = qte_escolhida - qte_atual;
        var qte_tratada = String(qte_diferenca);
        
        if (qte_tratada.indexOf('-') == -1) {

            qte_tratada = Number(qte_tratada);

            if ((qte_tratada > qte_maxima) && (qte_maxima != 0)) {
                alert(AtzCarALERTqtdestoque);
                fr.quantidade_produto.focus();
                liberado = false;
            }

            if ((qte_escolhida > qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0)) {
                alert(AtzCarALERTqtdestoque);
                fr.quantidade_produto.focus();
                liberado = false;
            }

        }
    }

    if (liberado == true) {
        if (tip == 'frete') {
            valida_pesquisar_cep();
        } else {
            fr.submit();
        }
    }
}
function acerta_email(Email) {
	  acerta=Email;
	  if (Email.indexOf('@', 0) !== -1 && Email.indexOf('.', 0) !== -1) {
      var ini=Email.indexOf('@', 0) + 1;
	  var ifi=Email.indexOf('.', 0);
      if (Email.substring(ini,ifi) == "hotmail") {
      acerta=Email.substring(0,ini) + "hotmail.com";
	  };
	  if (Email.substring(ini,ifi) == "yahoo") {
      acerta=Email.substring(0,ini) + "yahoo.com.br";
	  };
	  if (Email.substring(ini,ifi) == "gmail") {
      acerta=Email.substring(0,ini) + "gmail.com";
	  };
	  if (Email.substring(ini,ifi) == "bol") {
      acerta=Email.substring(0,ini) + "bol.com.br";
	  };
	  };
	  return acerta;
}


//###################################################################################
function valida_indique(Form) {


    if (Form.Nome_AmigoIndicador.value.length == 0) {
        alert("O nome do amigo deve ser preenchido ! ");
        Form.Nome_AmigoIndicador.focus();
        return false;
    }

    if (Form.Email_AmigoIndicador.value.length == 0) {
		alert("Seu Email deve ser preenchido !");
		Form.Email_AmigoIndicador.focus();
		return false;
	}

    if (Form.Email_AmigoIndicador.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicador.value.indexOf('.', 0) == -1) {
        alert("Seu Email deve ser preenchido corretamente!"); 
        Form.Email_AmigoIndicador.focus();
        return false;
    }
   
      Form.Email_AmigoIndicador.value = acerta_email(Form.Email_AmigoIndicador.value);
	  
    if (Form.Nome_AmigoIndicado.value.length == 0) {
        alert("O nome do amigo indicado deve ser preenchido !");
        Form.Nome_AmigoIndicado.focus();
        return false;
    }

    if (Form.Email_AmigoIndicado.value.length == 0) {
        alert("O Email do amigo deve ser preenchido !");
		Form.Email_AmigoIndicado.focus();
		return false;
	}
    
    if (Form.Email_AmigoIndicado.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicado.value.indexOf('.', 0) == -1) {
        alert("O Email do amigo deve ser preenchido corretamente!"); 
        Form.Email_AmigoIndicado.focus();
        return false;
    }
     Form.Email_AmigoIndicado.value = acerta_email(Form.Email_AmigoIndicador.value);

    if (Form.comentario.value.length == 0) {
		alert("Preencher com um comentário ! ");
		Form.comentario.focus();
		return false;
	}

    return true;

}

function ajaxInit() {
    var req;
    try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                req = new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser não tem recursos para uso do Ajax");
                req = null;
            }
        }
    }
    return req;
}

function enviarajax(cep) {
    ajax = ajaxInit();
    if(ajax) {
        ajax.open("GET",cep, true);
        
		ajax.send(null);
    }
    return false;
}

//###################################################################################