function carrinho(tipo,partnumber){
if(tipo==1){
window.location = "?pag=carrinho&part="+partnumber+"&tipo=1";
}

if(tipo==2){
window.location = "?pag=carrinho&part="+partnumber+"&tipo=2";
}

if(tipo==4){
window.location = "?pag=carrinho&part="+partnumber+"&tipo=4";
}
}

function addlista(produto, usuario){
    valor = ajaxInit();
    valor.open("GET",'pages/addlista.asp?produto='+produto+'&usuario='+usuario, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==4) && (valor.status==200)){
        document.getElementById("addlista").innerHTML = valor.responseText;
        }
    }
    valor.send(null);
}

function checalogin(){
var login = document.formulario_login.login
var senha = document.formulario_login.senha
if(login.value==""){
alert("Login está em branco.");
login.focus();
return false;
}else{
if(senha.value==""){
alert("Senha está em branco.");
senha.focus();
return false;
}else{
}
	document.formulario_login.submit();
}

}

function formatar(src, mask, campo){
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i);
if (texto.substring(0,1) != saida){
    src.value += texto.substring(0,1);
  }
}

function Caracteres(objeto,limite){
    var erro = "Você ultrapassou o limite de caracteres.";

    tamanho = objeto.value.length;
    if (tamanho>limite) {
 	objeto.value = objeto.value.substring(0,limite);
    } 
    }

function colorir(campo){
campo.style.background = 'url(images/form/input_back.png) bottom repeat-x';
//campo.style.border = '1px solid #8E8E8E';
}
function descolorir(campo){
campo.style.background = '#ffffff';
campo.style.border = '1px solid #AFAFAF';
}

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 suporta Ajax");
                req = null;
            }
        }
    }
    return req;
}

function ValidarEmail(formulario)
{
  var obj = eval("document."+formulario+".email");
  var txt = obj.value;
  if ((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7)))
  {
    alert('Email incorreto');
	obj.focus();
  }else{
  validaemail(formulario);
  }
}

function validaemail(form){
var form;
var email = eval("document."+form+".email");
if(email.value!=""){
    valor = ajaxInit();
    valor.open("GET",'pages/checar.asp?tipo=1&email='+email.value, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("cemail").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.getElementById("cemail").innerHTML = valor.responseText;
        }
    }
    valor.send(null);
}else{
alert("Digite um email para validá-lo");
email.focus();
}
}

function checarlogin(formulario){
var login = eval("document."+formulario+".login");

if(login.value!=""){
    valor = ajaxInit();
    valor.open("GET",'pages/checar.asp?tipo=2&login='+login.value, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("clogin").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.getElementById("clogin").innerHTML = valor.responseText;
        }
    }
    valor.send(null);
}else{
alert("Digite um Login para validá-lo");
login.focus();
}
}

function calcula_frete(cep,tipo,peso){
if(cep!=""){
    valor = ajaxInit();
    valor.open("GET",'pages/frete.asp?cep='+cep+'&tipo='+tipo+'&peso='+peso, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==4) && (valor.status==200)){
        document.form_carrinho.frete.value = valor.responseText;
        }
    total = parseFloat(document.form_carrinho.subtotal.value)+parseFloat(document.form_carrinho.frete.value);
    document.form_carrinho.total.value = parseFloat(total);
    }
    valor.send(null);
}else{
alert("Digite um CEP para calcular o frete.");
}
}

function pegaCEP(){
var cep = document.formulario_cadastro.cep;
if(cep.value!=""){
    valor = ajaxInit();
    valor.open("GET",'pages/cep.asp?cep='+cep.value+'&tipo=e', true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("pegacep").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.formulario_cadastro.endereco.value = valor.responseText;
        document.getElementById("pegacep").innerHTML = '';
        Bairro();
        }
    }
    valor.send(null);
}else{
alert("Digite um CEP para validar.");
cep.focus();
}
}

function Bairro(){
    valor = ajaxInit();
    valor.open("GET",'pages/cep.asp?cep='+document.formulario_cadastro.cep.value+'&tipo=b', true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("pegacep").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.formulario_cadastro.bairro.value = valor.responseText;
        document.getElementById("pegacep").innerHTML = '';
        Cidade();
        }
    }
    valor.send(null);
}

function Cidade(){
    valor = ajaxInit();
    valor.open("GET",'pages/cep.asp?cep='+document.formulario_cadastro.cep.value+'&tipo=c', true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("pegacep").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.formulario_cadastro.cidade.value = valor.responseText;
        document.getElementById("pegacep").innerHTML = '';
        Estado();
        }
    }
    valor.send(null);
}

function Estado(){
    valor = ajaxInit();
    valor.open("GET",'pages/cep.asp?cep='+document.formulario_cadastro.cep.value+'&tipo=u', true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==1)){
        document.getElementById("pegacep").innerHTML = '<img src=images/loader.gif>';
        }

        if ((valor.readyState==4) && (valor.status==200)){
        document.formulario_cadastro.estado.value = valor.responseText;
        document.getElementById("pegacep").innerHTML = '';
        document.getElementById("numero").focus;
        }
    }
    valor.send(null);
}

function logar(tipo){
if(tipo==1){
	document.getElementById("carrinho-janela1").style.display = "none";
	document.getElementById("carrinho-janela2").style.display = "block";
}
if(tipo==2){
	document.getElementById("carrinho-janela1").style.display = "block";
	document.getElementById("carrinho-janela2").style.display = "none";
}
}

function abre1(){
document.getElementById('tipo1').style.display = 'none';
document.getElementById('pfisica').style.display = 'none';

document.getElementById('tipo2').style.display = 'block';
document.getElementById('pjuridica').style.display = 'block';

document.getElementById('tipop').value = '2';
}
function abre2(){
document.getElementById('tipo1').style.display = 'block';
document.getElementById('pfisica').style.display = 'block';

document.getElementById('tipo2').style.display = 'none';
document.getElementById('pjuridica').style.display = 'none';

document.getElementById('tipop').value = '1';
}
