﻿function Logar() {
    if (document.getElementById('txtLogin').value.toString() == 'cia' && document.getElementById('txtSenha').value.toString() == 'cia0101') {
        location.href = 'default.aspx';
    }
    else {
        document.getElementById('txtLogin').value = '';
        document.getElementById('txtSenha').value = '';
        alert('Login e Senha incorretos!');
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundColor(objeto, color1, color2) {
    if (document.getElementById(objeto).style.backgroundColor == color2) {
        document.getElementById(objeto).style.backgroundColor = color1;
    }
    else {
        document.getElementById(objeto).style.backgroundColor = color2;
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundColorMenuHome(objeto1, objeto2, color1, color2) {
    if (document.getElementById(objeto2).style.backgroundColor == color2) {
        document.getElementById(objeto1).style.backgroundColor = color1;
        document.getElementById(objeto2).style.backgroundColor = color1;
    }
    else {
        document.getElementById(objeto1).style.backgroundColor = color2;
        document.getElementById(objeto2).style.backgroundColor = color2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundImage(objeto, image1, image2) {
    if (document.getElementById(objeto).style.backgroundImage == image2) {
        document.getElementById(objeto).style.backgroundImage = image1;

    }
    else {
        document.getElementById(objeto).style.backgroundImage = image2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterColor(objeto, color1, color2) {
    if (document.getElementById(objeto).style.color == color2) {
        document.getElementById(objeto).style.color = color1;
    }
    else {
        document.getElementById(objeto).style.color = color2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Mascaras(e, src, mask) {
    if (window.event)
    { _TXT = e.keyCode; }
    else if (e.which)
    { _TXT = e.which; }

    if (_TXT > 47 && _TXT < 58) {
        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); }
        return true;
    }
    else {
        if (_TXT != 8)
        { return false; }
        else { return true; }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Campos de busca (Limpa no GotFocus() e Reescreve no LostFocus())
function TextOnFocus(txt) {
    txt.value = "";
}
function TextLostFocus(txt, texto) {
    //if (txt.value == "") {
    txt.value = texto;
    //}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Mostra o Loading antes do processamento, o hidden deverá ser passado após na página mesmo.
function ShowObjeto(objeto) {

    document.getElementById(objeto).style.visibility = "visible";
}
//MENU Click /////////////////////////////////////////////////////////////////////////////////////////////
function MenuClick(objeto) {
    if (document.getElementById(objeto).style.display == "none") {
        document.getElementById(objeto).style.display = "block";
    }
    else {
        document.getElementById(objeto).style.display = "none";
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function openWin(URL, titulo, w, h) {
    /*********************************************************************************
    openWin( URL, objeto, width, height );
    Abre jánela nova no centro da tela
    Exemplo de como chamar a função:
    <a href="#" onclick="return openWin('www.site.com.br','nome_da_Janela', 500, 500)">link</a>
    ***********************************************************************************/
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=auto';

    var win = window.open(URL, titulo, winprops);
    return win;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// FUNÇÕES SOLTAS NAS TELAS ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Formata(campo, tammax, teclapres, decimal) {
    var tecla = teclapres.keyCode;
    vr = Limpar(campo.value, "0123456789");
    tam = vr.length;
    dec = decimal

    if (tam < tammax && tecla != 8) { tam = vr.length + 1; }

    if (tecla == 8)
    { tam = tam - 1; }

    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) {

        if (tam <= dec)
        { campo.value = vr; }

        if ((tam > dec) && (tam <= 5)) {
            campo.value = vr.substr(0, tam - 2) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 6) && (tam <= 8)) {
            campo.value = vr.substr(0, tam - 5) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 9) && (tam <= 11)) {
            campo.value = vr.substr(0, tam - 8) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 12) && (tam <= 14)) {
            campo.value = vr.substr(0, tam - 11) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 15) && (tam <= 17)) {
            campo.value = vr.substr(0, tam - 14) + "." + vr.substr(tam - 14, 3) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - 2, tam);
        }
    }
}
function Limpar(valor, validos) {
    // retira caracteres invalidos da string
    var result = "";
    var aux;
    for (var i = 0; i < valor.length; i++) {
        aux = validos.indexOf(valor.substring(i, i + 1));
        if (aux >= 0) {
            result += aux;
        }
    }
    return result;
}
function Validacpf(obj) {

    if (obj.value == "")
        return true;

    if (!valida_cpf(obj.value)) {
        obj.value = "";
        obj.focus();
        alert('CPF Inválido');
    }
}

function Validacnpj(obj) {

    if (obj.value == "")
        return true;

    if (!valida_cnpj(obj.value)) {
        obj.value = "";
        obj.focus();
        alert('CNPJ Inválido');
    }
}

function valida_cpf(cpf) {

    cpf = cpf.replace(".", "");
    cpf = cpf.replace(".", "");
    cpf = cpf.replace("-", "");

    if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
        return false;
    add = 0;
    for (i = 0; i < 9; i++)
        add += parseInt(cpf.charAt(i)) * (10 - i);
    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;
    if (rev != parseInt(cpf.charAt(9)))
        return false;
    add = 0;
    for (i = 0; i < 10; i++)
        add += parseInt(cpf.charAt(i)) * (11 - i);
    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;
    if (rev != parseInt(cpf.charAt(10)))
        return false;
    return true;

}

function valida_cnpj(cnpj) {

    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace("/", "");
    cnpj = cnpj.replace("-", "");

    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))
            return false;
        return true;
    }
    else
        return false;
}
function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//var _gaq = _gaq || [];
//_gaq.push(['_setAccount', 'UA-23337441-1']);
//_gaq.push(['_setDomainName', '.ciadospresentes.com.br']);
//_gaq.push(['_trackPageview']);

//(function () {
//    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
//    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
//    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
//})();
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function ZoomFoto(n_foto) {
    if (n_foto == "1") {
        document.getElementById("ctl00_Conteudo_imgFotoG").src = document.getElementById("ctl00_Conteudo_imgFoto1").src.toString().replace("M.", ".").replace("P.", ".");
        document.getElementById("ctl00_Conteudo_hyFotoG").href = document.getElementById("ctl00_Conteudo_imgFoto1").src.toString().replace("M.", ".").replace("P.", ".");
    }
    if (n_foto == "2") {
        document.getElementById("ctl00_Conteudo_imgFotoG").src = document.getElementById("ctl00_Conteudo_imgFoto2").src.toString().replace("aM.", "a.").replace("aP.", "a.");
        document.getElementById("ctl00_Conteudo_hyFotoG").href = document.getElementById("ctl00_Conteudo_imgFoto2").src.toString().replace("aM.", "a.").replace("aP.", "a.");
    }
    if (n_foto == "3") {
        document.getElementById("ctl00_Conteudo_imgFotoG").src = document.getElementById("ctl00_Conteudo_imgFoto3").src.toString().replace("bM.", "b.").replace("bP.", "b.");
        document.getElementById("ctl00_Conteudo_hyFotoG").href = document.getElementById("ctl00_Conteudo_imgFoto3").src.toString().replace("bM.", "b.").replace("bP.", "b.");
    }
    if (n_foto == "4") {
        document.getElementById("ctl00_Conteudo_imgFotoG").src = document.getElementById("ctl00_Conteudo_imgFoto4").src.toString().replace("cM.", "c.").replace("cP.", "c.");
        document.getElementById("ctl00_Conteudo_hyFotoG").href = document.getElementById("ctl00_Conteudo_imgFoto4").src.toString().replace("cM.", "c.").replace("cP.", "c.");
    }
    MagicZoom.refresh();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function MudaFoto(fotoNome) {
    $('#hyFotoG').attr('href', fotoNome);
    $('#imgFotoG').attr('src', fotoNome);
    MagicZoom.refresh();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetaObjetoCor(obj) {
    re = new RegExp("OpcaoCor*");

    for (i = 0; i < document.forms[0].all.length; i++) {
        elm = document.forms[0].all[i];
        if (re.test(elm.id)) {
            document.getElementById(elm.id).style.border = "1px solid #7d0008";
        }

    }

    if (document.getElementById(obj) != null)
        document.getElementById(obj).style.border = "2px solid #7d0008";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetaObjetoTamanho(obj) {
    re = new RegExp("OpcaoTamanho*");

    for (i = 0; i < document.forms[0].all.length; i++) {
        elm = document.forms[0].all[i];
        if (re.test(elm.id)) {
            document.getElementById(elm.id).style.border = "1px solid #868686";
        }

    }
    if (document.getElementById(obj) != null)
        document.getElementById(obj).style.border = "2px solid #868686";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetaObjetoVoltagem(obj) {
    re = new RegExp("OpcaoVoltagem*");

    for (i = 0; i < document.forms[0].all.length; i++) {
        elm = document.forms[0].all[i];
        if (re.test(elm.id)) {
            document.getElementById(elm.id).style.border = "1px solid #868686";
        }

    }
    if (document.getElementById(obj) != null)
        document.getElementById(obj).style.border = "2px solid #868686";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
