
function esse_espaco(valor){
    $('#myspace').val(valor);
    $('#senha').focus();
}
function esconde_pop_myspace(){
    document.getElementById("pop_myspace").style.display="none";
    $('#myspace').val(valor);

}
function abrirJanela(endereco, titulo){
    // window.open(titulo,endereco,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
    window.open(endereco,titulo);
}
function abrirJanelaMaps(endereco, titulo){
     window.open(endereco,titulo,"height=350,width=520,status=no,toolbar=no,menubar=no,location=no");
    //window.open(endereco,titulo);
}
function charUP(campo) {
    campo.value = campo.value.toUpperCase();
}
function VerificaEnter(formulario){
    if (event.keyCode == 13)
        formulario.submit();
}
function FormataLabel(id){
    document.getElementById(id).style.background = "#FE0000";
}

function LimpaFormataLabel(id){
    document.getElementById(id).style.background = "#FFFFFF";
}

function ValidaEmail(objItem){
    var valido = true
    var erEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    if (objItem){
        if (objItem.value=="")
        {
            FormataLabel(objItem.id);
            valido = false;
        }
        else
        {
            LimpaFormataLabel(objItem.id);
            if (!erEmail.test(objItem.value))
            {
                FormataLabel(objItem.id);
                valido = false;
            }
        }
    }
    return valido;
}




function ValidaCEP(objItem)
{
    var erCEP = /^[0-9]{5}-[0-9]{3}$/;

    if (objItem && objItem.value != "")
    {
        if (!erCEP.test(objItem.value))
        {
            FormataLabel(objItem.id);
            return false;
        }
    }
    LimpaFormataLabel(objItem.id);
    return true;
}
function ValidaCPF(campo) {
    var CPF = campo.value; // Recebe o valor digitado no campo
    CPF = CPF.replace(".", "");
    CPF = CPF.replace(".", "");
    CPF = CPF.replace("-", "");

    // Aqui comeï¿½a a checagem do CPF
    var POSICAO, I, SOMA, DV, DV_INFORMADO;
    var DIGITO = new Array(10);
    DV_INFORMADO = CPF.substr(9, 2); // Retira os dois ï¿½ltimos dï¿½gitos do nï¿½mero informado

    // Desemembra o nï¿½mero do CPF na array DIGITO
    for (I=0; I<=8; I++) {
        DIGITO[I] = CPF.substr( I, 1);
    }

    // Calcula o valor do 10ï¿½ dï¿½gito da verificaï¿½ï¿½o
    POSICAO = 10;
    SOMA = 0;
    for (I=0; I<=8; I++) {
        SOMA = SOMA + DIGITO[I] * POSICAO;
        POSICAO = POSICAO - 1;
    }
    DIGITO[9] = SOMA % 11;
    if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
    }
    else{
        DIGITO[9] = 11 - DIGITO[9];
    }

    // Calcula o valor do 11ï¿½ dï¿½gito da verificaï¿½ï¿½o
    POSICAO = 11;
    SOMA = 0;
    for (I=0; I<=9; I++) {
        SOMA = SOMA + DIGITO[I] * POSICAO;
        POSICAO = POSICAO - 1;
    }
    DIGITO[10] = SOMA % 11;
    if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
    }
    else {
        DIGITO[10] = 11 - DIGITO[10];
    }

    // Verifica se os valores dos dï¿½gitos verificadores conferem
    DV = DIGITO[9] * 10 + DIGITO[10];
    if (DV != DV_INFORMADO) {
        //alert('CPF invalido');
        FormataLabel(campo.id);
        campo.focus();
        return false;
    }
    LimpaFormataLabel(campo.id);
    return true;
}
/*
function ValidaCNPJ(cnpj){
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;
    if (cnpj.length < 14 && cnpj.length < 15)
        return false;
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
        {
            digitos_iguais = 0;
            break;
        }
    if (!digitos_iguais)
    {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
            return false;
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1)){
            FormataLabel(cnpj.id);
            return false;
        }
        LimpaFormataLabel(cnpj.id);
        return true;
    }
    else{
        FormataLabel(cnpj.id);
        return false;
    }
}
*/


function vcnpj( c ) {
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais, cnpj = c.value.replace(/\D+/g, '');
    digitos_iguais = 1;
    if (cnpj.length != 14)
    {
        //alert('CNPJ inválido');
        FormataLabel(c.id);
        c.focus();
        return false;
    }
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
        {
            digitos_iguais = 0;
            break;
        }
    if (!digitos_iguais)
    {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
        {
            //alert('CNPJ inválido');
            FormataLabel(c.id);
            c.focus();
            return false;
        }

        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1)){
            //alert('CNPJ inválido');
            FormataLabel(c.id);
            c.focus();
            return false;
        }
        else {
            // alert('CNPJ  OK !');
            LimpaFormataLabel(c.id);
            return true;
        }
    }
    else{
        //alert('CNPJ inválido');
        FormataLabel(c.id);
        c.focus();
        return false;
    }
}






function ValidaSenha( formu ){


    var s1 = formu.senha.value;
    var s2 = formu.senha2.value;

    if(s1 != s2){
        formu.senha.style.color="#FE0000";
        formu.senha2.style.color="#FE0000";
    }
    if(s1 == s2){
        formu.senha.style.color="#000000";
        formu.senha2.style.color="#000000";
    }
}
/*  -----------------------------------   */

$(document).ready(function() {
    $('a[name=modal]').click(function(e) {
        e.preventDefault();

        var id = $(this).attr('href');
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#maskTelasMyspace').css({
            'width':maskWidth,
            'height':maskHeight
        });

        $('#maskTelasMyspace').fadeIn(500);
        $('#maskTelasMyspace').fadeTo("slow",0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);

        $(id).fadeIn(2000);

    });

    $('.windowX .closeX').click(function (e) {
        e.preventDefault();

        $('#maskTelasMyspace').hide();
        $('.windowX').hide();
    });

    $('#maskTelasMyspace').click(function () {
        $(this).hide();
        $('.windowX').hide();
    });
});

/* -------------------------------------- */
function SendSenha( x ) {
    var m = x;
    $('#Rec_senha').html('<img src="http://www.clubcarros.com/images/load/ajax-loader.gif" border="0">');
    $.post("includes/ajax/recuperar_senha.php",
    {
        email: m
    },
    function(data){
        $('#Rec_senha').html(data)
    }
    );
}
/* -------------------------------------- */
function send_a_amigo(n1,m1,n2,m2){
    $('#Indiquea_a_Amigo').html('<img src="http://www.clubcarros.com/images/load/ajax-loader.gif" border="0">');
    $.post("includes/ajax/send_a_amigo.php",
    {
        nome1: n1,
        email1: m1,
        nome2: n2,
        email2:m2
    },
    function(data){
        $('#Indiquea_a_Amigo').html(data)
    }

    );
}
/* -------------------------------------- */
function send_amigo_myspace(n1,m1,n2,m2, id, pf){
    $('#IndiqueAmigo').html('<img src="http://www.clubcarros.com/images/load/ajax-loader.gif" border="0">');
    $.post("includes/ajax/send_amigo_myspace.php",
    {
        nome1: n1,
        email1: m1,
        nome2: n2,
        email2: m2,
        id: id,
        pf: pf
    },
    function(data){
        $('#IndiqueAmigo').html(data)
    }

    );
}
/* -------------------------------------- */
function send_amigo_servico(nome1,mail1,nome2,mail2, idSer){
    $('#RetSendServAmigo').html('<img src="http://www.clubcarros.com/images/load/ajax-loader.gif" border="0">');
    $.post("includes/ajax/send_servico_amigo.php",
    {
        nome1: nome1,
        email1: mail1,
        nome2: nome2,
        email2: mail2,
        id: idSer
    },
    function(data){
        $('#RetSendServAmigo').html(data)
    }

    );
}
/* -------------------------------------- */
function send_proposta(nome,mail,tel,msg, id, pf, destino){
    $('#SendProposta').html('<img src="http://www.clubcarros.com/images/load/ajax-loader.gif" border="0">');
    $.post("includes/ajax/send_proposta.php",
    {
        nome: nome,
        mail: mail,
        tel: tel,
        msg: msg,
        id: id,
        pf: pf,
        destino: destino
    },
    function(data){
        $('#SendProposta').html(data)
    }

    );

}
/* -------------------------------------- */
function numeros(evt)
{
    var key_code = evt.keyCode  ? evt.keyCode  :
    evt.charCode ? evt.charCode :
    evt.which    ? evt.which    : void 0;

    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if (key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27  ||  key_code == 46)
    {
        return true;
    }

    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    else if ((key_code >= 35)  &&  (key_code <= 40))
    {
        return true
    }

    // Habilita números de 0 a 9
    else if ((key_code >= 48)  &&  (key_code <= 57))
    {
        return true
    }

    return false;
}

function letras(evt)
{

    var key_code = evt.keyCode  ? evt.keyCode  :
    evt.charCode ? evt.charCode :
    evt.which    ? evt.which    : void 0;

    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if (key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27  ||  key_code == 46)
    {
        return true;
    }

    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    else if ((key_code >= 35)  &&  (key_code <= 40))
    {
        return true
    }

    // Habilita números de 0 a 9
    else if ((key_code >= 97)  &&  (key_code <= 122))
    {
        return true
    }

    return false;
}
function MaskValor(str)
{
    str = str.replace(/\D/g,"")
    str = str.replace(/(\d)(\d{1})$/, "$1,$2")
    str = str.replace(/(\d)(\d{3},\d{1})$/, "$1.$2")
    str = str.replace(/(\d)(\d{3}\.\d{3},\d{1})$/, "$1.$2")
    str = str.replace(/(\d)(\d{3}\.\d{3}\.\d{3},\d{1})$/, "$1.$2")
    return str;
}


function MaskValorKM(str)
{
    str = str.replace(/\D/g,"")
    str = str.replace(/(\d)(\d{1})$/, "$1,$2")
    str = str.replace(/(\d)(\d{3},\d{1})$/, "$1.$2")
    str = str.replace(/(\d)(\d{3}\.\d{3},\d{1})$/, "$1.$2")
    str = str.replace(/(\d)(\d{3}\.\d{3}\.\d{3},\d{1})$/, "$1.$2")
    return str;
}

