﻿/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 14/10/2011
Atualizado: 14/10/2011
Nota: Adicionar efeitas biblioteca .js
Pagina: Vendas.aspx
*/

function MM_effectBlind(targetElement, duration, from, to, toggle) {
    Spry.Effect.DoBlind(targetElement, { duration: duration, from: from, to: to, toggle: toggle });
}


/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 29/08/2011
Atualizado: 30/08/2011
Nota: Alterar a visiblidade da exibição dos veículos 0-KM
Pagina: versoes-modelos.aspx
*/
function MudarImagemModeloCor(urlImgCor) {
    if (document.getElementById('imgCentralVersaoModelo') != null) {
        document.getElementById('imgCentralVersaoModelo').src = urlImgCor;  
    }
}
 
/* 
Proprietário: Big Solutions 
Autor: Joabe
Data: 29/08/2011
Atualizado: 30/08/2011
Nota: Alterar a visiblidade da exibição dos veículos 0-KM
Pagina: versoes-modelos.aspx
*/
function ExibirDivVersaoVeiculoOnLoad(divId) {
    if (document.getElementById('divVersaoModelo_' + divId) != null) {
        document.getElementById('divVersaoModelo_' + divId).style.display = "block";
    }
}
 
/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 29/08/2011
Atualizado: 25/08/2011
Nota: Alterar a visiblidade da exibição dos veículos 0-KM ao clicar na versão
Pagina: versoes-modelos.aspx
*/
function ExibirDivVersaoVeiculo(divId) {
    if (divId != null) {
        for (var iJs = 0; iJs < 100000; iJs++) {
            if (document.getElementById('divVersaoModelo_' + iJs) != null) { document.getElementById('divVersaoModelo_' + iJs).style.display = "none"; }
        }
        if (document.getElementById(divId)) { document.getElementById(divId).style.display = "block"; }
    }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 15/08/2011
Atualizado: 15/08/2011
Nota: Mantem a marca selecionada em destaque
*/
function PosicionarItemSelecionado() {
    if (document.getElementById('listMarcas') != null) {
        var opcaoMarca = document.getElementById('listMarcas').options;
        for (var oItem = opcaoMarca.length - 1; oItem > 0; oItem--) {
            
                if (opcaoMarca[oItem].selected == true) {
                    opcaoMarca[oItem].focus();
                    opcaoMarca[oItem].selected = true;
                    return;
            }
        }
    }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 09/08/2011
Atualizado: 09/08/2011
Nota: 
*/
function OcultarBotaoError() {
    if (document.getElementById('divAdicionarMinhaLista')) {
        document.getElementById('divAdicionarMinhaLista').style.display = "none";
    }

    if (document.getElementById('divCompanhiaAdicionarMinhaLista')) {
        document.getElementById('divCompanhiaAdicionarMinhaLista').style.display = "none";
    }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 05/08/2011
Atualizado: 03/11/2011
Nota: Alterna a Exibição dos Mapas das concessionarias
*/
function ExibirMapaConcessionaria(mapaId) {
    var divMapa = "divConcessionaria_Mapa_";
    for (var iMapa = 0; iMapa < 1000; iMapa++) {
        if (mapaId != iMapa) {
            if (document.getElementById(divMapa + iMapa)) { document.getElementById(divMapa + iMapa).style.height = "0"; }
        }
    }
    if (document.getElementById(divMapa + mapaId)) {
        if (document.getElementById(divMapa + mapaId).style.height != "0px") {
            document.getElementById(divMapa + mapaId).style.height = "0px"
        }
        else {
            document.getElementById(divMapa + mapaId).style.height = "auto"
        }    
      }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 03/08/2011
Atualizado: 03/08/2011
Nota: Alterna o fone conforme a Loja Selecionada
*/
function TelefoneCompanhiaTopoAlterar(nFone) { if (document.getElementById('spnTelefoneCompanhiaTopo') && nFone != null) {document.getElementById('spnTelefoneCompanhiaTopo').innerHTML = nFone; }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 12/07/2011
Atualizado: 12/07/2011
Nota: Exibir o botão comparar quando mais de 2 itens for selecinado e bloquear os checks 
*/
function ExibirChecksCompare() {
    if (document.getElementsByTagName('span') != null) {
        var pgInput = document.getElementsByTagName('span');
        var nRgchkCompare = "baseComparar";
        var contarChkCompare = 0;
        var qtdInput = pgInput.length;
//CONTAR span baseComparar
        for (inp = 0; inp < qtdInput; inp++) {idInptString = pgInput[inp].id.toString();
            if (idInptString.match(nRgchkCompare)) {
                document.getElementById(idInptString).style.visibility = "hidden";
                ++contarChkCompare; 
            }
        }
// MUDAR VISIBILIDADE
        if (contarChkCompare > 1) {
            for (inp = 0; inp < pgInput.length; inp++) {
                idInptString = pgInput[inp].id.toString();
                if (idInptString.match(nRgchkCompare)) {                    
                 document.getElementById(idInptString).style.visibility = "visible"; }
            }
        }
    }
}


/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 15/06/2011
Atualizado: 28/06/2011
Nota: Exibir o botão comparar quando mais de 2 itens for selecinado e bloquear os checks 
*/
function VerificarChecksCompare() {
    //alert('001');
    var nRgChkCmp = "chkCompare";
    var IDS_CHK = [];
    if (document.getElementsByTagName('input') != null) {
        var pgInput = document.getElementsByTagName('input');        
        var chcCount = 0;
        for (inp = 0; inp < pgInput.length; inp++) {
            idPgInput = pgInput[inp].id.toString();
            if (idPgInput.match(nRgChkCmp) && document.getElementById(idPgInput).checked == true) {++chcCount;}
        }

        for (inp = 0; inp < pgInput.length; inp++) {
            idPgInput = pgInput[inp].id.toString();
            if (chcCount>2) {
                if (idPgInput.match(nRgChkCmp) && document.getElementById(idPgInput).checked == false) {
                    document.getElementById(idPgInput).disabled = true;
                }
            }
            else {
                if (idPgInput.match(nRgChkCmp)) {
                    document.getElementById(idPgInput).disabled = false;
                }
            }
        }
        var ID_btCmp = [];        
            for (inp = 0; inp < document.getElementsByTagName('input').length; inp++) {               
               idbtCmp = document.getElementsByTagName('input')[inp].id;
               if (idbtCmp.match('imgBtComparar') || idbtCmp.match('btnComparar')) {
                        ID_btCmp.push(idbtCmp);
                    }
                }

                for (inp = 0; inp < document.getElementsByTagName('div').length; inp++) {
                    idbtCmp = document.getElementsByTagName('div')[inp].id;
                    if (idbtCmp.match('divImBtComparar01')) {                        
                        ID_btCmp.push(idbtCmp);
                    }
                }

                for (var iId = 0; iId < ID_btCmp.length; iId++) {
                    nId = ID_btCmp[iId];
                    if (chcCount > 1) {
                        document.getElementById(nId).style.visibility = "visible";                        
                    }
                    else {
                        document.getElementById(nId).style.visibility = "hidden";
                    }
                }        
     }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 16/05/2011
Nota:
    Controla o tooTip da Big
*/
function BigTooTip(idCtrl, msgm) {}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 06/05/2011
Nota:
javaScript desenvolvido para o produto BSDealer.
Oculta os campos indesejados*/
function SeekDestroy() {
    if (document.getElementById('cboxNext')) { document.getElementById('cboxNext').style.display = "none"; }
    if (document.getElementById('cboxPrevious')) { document.getElementById('cboxPrevious').style.display = "none"; }
    if (document.getElementById('cboxCurrent')) { document.getElementById('cboxCurrent').style.display = "none"; }
}

/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 25/04/2011
Nota:
javaScript desenvolvido para o produto BSDealer.
Ocultar e exibir conteúdo institucional*/
function AlterarInstitucional(iDiv) {
    if (iDiv != 'undefined') {     
        if (document.getElementById(iDiv) != null) {
            OcultarTudo();
            
            // Exibe a DIV requisitada
            relDiv = document.getElementById(iDiv).rel;
            
            if(relDiv!=null)
            {
                if (document.getElementById(relDiv).style.display == "block")
                    { document.getElementById(relDiv).style.display = "none"; }
                else
                    { document.getElementById(relDiv).style.display = "block"; }
            }
            
            //Altera o titulo da página
            if (window.document.getElementById('ctl00_divTituloPagina')) {
                window.document.getElementById('ctl00_divTituloPagina').innerHTML = document.getElementById(iDiv).innerHTML;
            } 
             
            //Altera o estilo do Link selecionado
            document.getElementById(iDiv).setAttribute('class', 'link_Institucional_Ativo'); 
            }        
        }
    }
     
/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 16/04/2011
Nota:
javaScript desenvolvido para o produto BSDealer.
Altera o titulo da página conforme passado no parametro
*/

/* Exibir e ocultar conteúdo institucional*/
function AlterarTituloTopo(novoTitulo) {
    if (novoTitulo != 'undefined') {
        if (window.document.getElementById('ctl00_divTituloPagina')) {
            window.document.getElementById('ctl00_divTituloPagina').innerHTML = novoTitulo;
        }        
    }
}


/* 
Proprietário: Big Solutions
Autor: Joabe
Data: 29/03/2011
Nota:
javaScript desenvolvido para o produto BSDealer.
Ocultar e exibir DIVS
*/

/* Exibir e ocultar conteúdo institucional*/
function AlterarVisaoDiv(exibirDiv) {
    if (exibirDiv != 'undefined') {
        if (document.getElementById(exibirDiv) != null) {
            OcultarTudo();
            if(document.getElementById(exibirDiv).style.display == "block")
                {document.getElementById(exibirDiv).style.display = "none";}
            else
                {document.getElementById(exibirDiv).style.display = "block";}
            }
    }
}

/*
Proprietário: Big Solutions
Autor: Joabe
Data: 29/03/2011
Nota:
javaScript desenvolvido para o produto BSDealer.
Ocultar e exibir DIVS
*/

/* Exibir e ocultar conteúdo institucional*/
var dv = 0;
function AlterarVisao(exibir) {
    if (exibir != 'undefined') {
        OcultarTudo();
        if (document.getElementById('idDiv' + exibir) != null) {
            document.getElementById('idDiv' + exibir).style.display = "block";
        }
    }
}
function OcultarTudo() {
    if (window.document.getElementById('divDireitaJs') != null) {
        var divs = window.document.getElementById('divDireitaJs');
        for (it = 0; it < divs.getElementsByTagName('div').length; it++) {
            if (divs.getElementsByTagName('div')[it] != null) {
                divs.getElementsByTagName('div')[it].style.display = "none"
            }
        }
    }
}
function AtribuirFuncao() {
    ColorBoxFunc();
    PosicionarItemSelecionado();
    if (window.document.getElementById('divEsquerdaJs') != null) {
        ExpandirConteudoJs();
        var divEsq = window.document.getElementById('divEsquerdaJs');
        for (it = 0; it < divEsq.getElementsByTagName('a').length; it++) {
            if (divEsq.getElementsByTagName('a')[it] != null) {
                divEsq.getElementsByTagName('a')[it].setAttribute('onclick', 'AlterarVisao(' + [it] + ')');
            }
        }        
    }

/*Alterar exibição do item conforme URL string */
    if (window.document.getElementById('divDireitaJs') != null) {
        var urlAtual = window.document.URL;
        var urlTmh = urlAtual.indexOf('?').toString();
        if (urlTmh.length > 0) {
            var exDiv = urlAtual.substring((urlAtual.indexOf('?') + 1), urlAtual.indexOf('&ccv'));
            if (exDiv.length > 0) {
                //AlterarVisaoDiv(exDiv);
                //AlterarTituloTopo(exDiv);
                AlterarInstitucional(exDiv);
            }
        }
    }
}
/* FIM - Exibir e ocultar conteúdo institucional*/


/*
Proprietário: Big Solutions
Autor: Joabe
Data: 15/03/2011
Nota:
javaScript desenvolvido para o produto BSDealer, projeto CCV
style="visibility:hidden;"
*/
var num = 4;
function zera(num) {
    OcultarDivOfert();
    for (i = 1; i < num; i++) {
        if (window.document.getElementById("div" + i) != null) {
            window.document.getElementById("div" + i).style.visibility = "hidden";
        }
    }
    for (i = 1; i < num; i++) {
        if (window.document.getElementById("link" + i) != null) {
            window.document.getElementById("link" + i).className = "bt" + i;
        }
    }
}

/**/
function ExibirDivOferta(lnk, num) {
    zera(num);
    if (window.document.getElementById("div" + lnk) != null) {
        window.document.getElementById("div" + lnk).style.visibility = "visible";
    }
    if (window.document.getElementById("link" + lnk) != null) {
        window.document.getElementById("div" + lnk).style.visibility = "hidden";
        window.document.getElementById("link" + lnk).className = "bt" + lnk + "_active";
    }
}

/*
Proprietário: Big Solutions
Autor: Joabe
Data: 04/04/2011
Nota: Controlar a exibição dos itens novos e seminovos dinamicamente
*/

function SelecionarSeminovoJs(exibir) {
    if (window.document.getElementById('divCategoriaNovo') != null && window.document.getElementById('divCategoriaSemiNovo') != null) {
        if (exibir == 0) {
            window.document.getElementById('divCategoriaNovo').style.visibility = "visible"; //visibility:visible;
            window.document.getElementById('divCategoriaSemiNovo').style.visibility = "hidden"; //visibility:hidden;
        }
        else {
            window.document.getElementById('divCategoriaSemiNovo').style.visibility = "visible";
            window.document.getElementById('divCategoriaNovo').style.visibility = "hidden";
        }
    }
}

/*
Proprietário: Big Solutions
Autor: Joabe
Data: 01/04/2011
Nota: Anima a exibição das ofertas
Exibe as fotos com efeito fade
*/
var pA = 0;
var tm = 0;
var tp = 0;
var lf = 0;
var timAnime;
function divPopFade(ts) {
    if (typeof (ts) != 'undefined') {
        OcultarDivOfert();        
        if (document.getElementById('popDetalheOferta' + ts) != null) {
            pA = ts;            
            document.getElementById('popDetalheOferta' + ts).style.filter = "alpha(opacity=0)";
            document.getElementById('popDetalheOferta' + ts).style.opacity = 0;
            document.getElementById('popDetalheOferta' + ts).style.visibility = "visible";
            var nObj = document.getElementById('popDetalheOferta' + ts);            
                if (document.getElementById('btFecharD')) {
                    document.getElementById('btFecharD').style.visibility = "visible";
                    //document.getElementById('btFecharD').style.display = "block";
                    document.getElementById('popDetalheOferta' + ts).appendChild(document.getElementById('btFecharD'));
                }                
            document.getElementById('dGaleri').appendChild(nObj);
            tm = 0;
            tp = 0;
            lf = 0;
            animOfert(ts);
        }
    }
}
function animOfert(ts) {
    timAnime = setInterval("moviOf(" + ts + ")", 20);
}
function moviOf(ts) {
    if (tm < 101) {
        document.getElementById('popDetalheOferta' + ts).style.filter = "alpha(opacity=" + tm + ")";
        document.getElementById('popDetalheOferta' + ts).style.opacity = tm / 100;
        tm = tm + 5;
    }
}
/*************/
function OcultarDivOfert() {
    window.clearInterval(timAnime);
    if (document.getElementById('popDetalheOferta' + pA) != null) {
        document.getElementById('popDetalheOferta' + pA).style.visibility = "hidden";
        if (document.getElementById('btFecharD')!=null) {
            document.getElementById('btFecharD').style.visibility = "hidden";
        }
    }
}
/*
Proprietário: Big Solutions
Autor: Joabe
Data: 11/04/2011
Nota: Adiciona o Script para Expandir o conteudo do texto
*/
function ExpandirSpanJs(spanId) {
    if (document.getElementById(spanId) != null) {
        idSpan = document.getElementById(spanId);
        if (idSpan.style.display == "none") {
            idSpan.style.display = "block";
        }
        else {
            idSpan.style.display = "none";
        }
    }
}
function ExpandirConteudoJs() {
    if (window.document.getElementById('divDireitaJs') != null) {
        var elementos = window.document.getElementById('divDireitaJs').getElementsByTagName('span');
        for (it = 0; it < elementos.length; it++) {
            var elem = elementos[it];
            if (elem.className == 'dinamicoJs') {
                for (iE = 0; iE < elem.getElementsByTagName('a').length; iE++) {
                    if (elem.getElementsByTagName('a')[iE].style.display == 'block') {
                        var classe = elem.getElementsByTagName('a')[iE].className.toString();
                        elem.getElementsByTagName('a')[iE].setAttribute('onclick', 'ExpandirSpanJs("' + classe + '")');
                    }
                }
            }
        }
    }
}

/*******************************************************************/
                //[OBSERVAÇÃO]:[ABAIXO JS BSDEALER - ANTIGO]
/*******************************************************************/
function formataValor(campo, evt) {
    //1.000.000,00
    var xPos = PosicaoCursor(campo);
    evt = getEvent(evt);
    var tecla = getKeyCode(evt);
    if (!teclaValida(tecla))
        return;

    vr = campo.value = filtraNumeros(filtraCampo(campo));
    if (vr.length > 0) {
        vr = parseFloat(vr.toString()).toString();
        tam = vr.length;

        if (tam == 1)
            campo.value = "0,0" + vr;
        if (tam == 2)
            campo.value = "0," + vr;
        if ((tam > 2) && (tam <= 5)) {
            campo.value = vr.substr(0, tam - 2) + ',' + vr.substr(tam - 2, tam);
        }
        if ((tam >= 6) && (tam <= 8)) {
            campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, 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 - 2, 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 - 2, tam);
        }
        if ((tam >= 15) && (tam <= 18)) {
            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);
        }
    }
    MovimentaCursor(campo, xPos);
}

function PosicaoCursor(textarea) {
    var pos = 0;
    if (typeof (document.selection) != 'undefined') {
        //IE
        var range = document.selection.createRange();
        var i = 0;
        for (i = textarea.value.length; i > 0; i--) {
            if (range.moveStart('character', 1) == 0)
                break;
        }
        pos = i;
    }
    if (typeof (textarea.selectionStart) != 'undefined') {
        //FireFox
        pos = textarea.selectionStart;
    }

    if (pos == textarea.value.length)
        return 0; //retorna 0 quando não precisa posicionar o elemento
    else
        return pos; //posição do cursor
}

function MovimentaCursor(textarea, pos) {
    if (pos <= 0)
        return; //se a posição for 0 não reposiciona

    if (typeof (document.selection) != 'undefined') {
        //IE
        var oRange = textarea.createTextRange();
        var LENGTH = 1;
        var STARTINDEX = pos;

        oRange.moveStart("character", -textarea.value.length);
        oRange.moveEnd("character", -textarea.value.length);
        oRange.moveStart("character", pos);
        oRange.select();
        textarea.focus();
    }
    if (typeof (textarea.selectionStart) != 'undefined') {
        //FireFox
        textarea.selectionStart = pos;
        textarea.selectionEnd = pos;
    }
}

function filtraNumeros(campo) {
    var s = "";
    var cp = "";
    vr = campo;
    tam = vr.length;
    for (i = 0; i < tam; i++) {
        if (vr.substring(i, i + 1) == "0" ||
            vr.substring(i, i + 1) == "1" ||
            vr.substring(i, i + 1) == "2" ||
            vr.substring(i, i + 1) == "3" ||
            vr.substring(i, i + 1) == "4" ||
            vr.substring(i, i + 1) == "5" ||
            vr.substring(i, i + 1) == "6" ||
            vr.substring(i, i + 1) == "7" ||
            vr.substring(i, i + 1) == "8" ||
            vr.substring(i, i + 1) == "9") {
            s = s + vr.substring(i, i + 1);
        }
    }
    return s;
}

function getEvent(evt) {
    if (!evt) evt = window.event; //IE
    return evt;
}
    
function getKeyCode(evt) {
    var code;
    if (typeof (evt.keyCode) == 'number')
        code = evt.keyCode;
    else if (typeof (evt.which) == 'number')
        code = evt.which;
    else if (typeof (evt.charCode) == 'number')
        code = evt.charCode;
    else
        return 0;

    return code;
}

function teclaValida(tecla) {
    if (tecla == 8 //backspace
    //Esta evitando o post, quando são pressionadas estas teclas.
    //Foi comentado pois, se for utilizado o evento texchange, é necessario o post.
        || tecla == 9 //TAB
        || tecla == 27 //ESC
        || tecla == 16 //Shif TAB 
        || tecla == 45 //insert
        || tecla == 46 //delete
        || tecla == 35 //home
        || tecla == 36 //end
        || tecla == 37 //esquerda
        || tecla == 38 //cima
        || tecla == 39 //direita
        || tecla == 40)//baixo
        return false;
    else
        return true;
}

function filtraCampo(campo) {
    var s = "";
    var cp = "";
    vr = campo.value;
    tam = vr.length;
    for (i = 0; i < tam; i++) {
        if (vr.substring(i, i + 1) != "/"
            && vr.substring(i, i + 1) != "-"
            && vr.substring(i, i + 1) != "."
            && vr.substring(i, i + 1) != "("
            && vr.substring(i, i + 1) != ")"
            && vr.substring(i, i + 1) != ":"
            && vr.substring(i, i + 1) != ",") {
            s = s + vr.substring(i, i + 1);
        }
    }
    return s;
}

function formataTel(campo, evt) {
    //1234 - 5678
    // OBS.: Para que esta função funcione corretamente é necessario mudar a propriedade "MaxLength" do TextBox para ""9"
    var xPos = PosicaoCursor(campo);
    evt = getEvent(evt);
    var tecla = getKeyCode(evt);
    if (!teclaValida(tecla))
        return;

    vr = campo.value = filtraNumeros(filtraCampo(campo));
    tam = vr.length;

    if (tam < 4)
        campo.value = vr;
    else if (tam == 4)
        campo.value = vr + '-';
    else if (tam > 4)
        campo.value = vr.substr(0, 4) + '-' + vr.substr(4, 9);
    MovimentaCursor(campo, xPos);
}

function formataDDD(campo, evt) {
    //(11)
    var xPos = PosicaoCursor(campo);
    evt = getEvent(evt);
    var tecla = getKeyCode(evt);
    if (!teclaValida(tecla))
        return;

    vr = campo.value = filtraNumeros(filtraCampo(campo));
    tam = vr.length;

    if (tam < 1)
        campo.value = vr;        
    else if (tam > 1)
        campo.value = '(' +  vr.substr(0, 2) + ')';
    MovimentaCursor(campo, xPos);
}

function SomenteNumero(e) {
    var tecla = (window.event) ? event.keyCode : e.which;
    if ((tecla > 47 && tecla < 58)) return true;
    else {
        if (tecla != 8) return false;
        else return true;
    }
}

function formataDataeHora(campo, evt) {
    xPos = PosicaoCursor(campo);
    //dd/MM/yyyy
    evt = getEvent(evt);
    var tecla = getKeyCode(evt);
    if (!teclaValida(tecla))
        return;
    vr = campo.value = filtraNumeros(filtraCampo(campo));
    tam = vr.length;

    if (tam >= 2 && tam < 4)
        campo.value = vr.substr(0, 2) + '/' + vr.substr(2);
    if (tam == 4)
        campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/';
    if (tam > 4)
        campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4);
    if (tam > 8 && tam < 11)
        campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 4) + ' ' + vr.substr(8, 2);
    if (tam >= 11)
        campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 4) + ' ' + vr.substr(8, 2) + ':' + vr.substr(10);

    campo.value = campo.value.substr(0, 16);
    MovimentaCursor(campo, xPos);
}

function formataTelefone(campo, evt) {
    //(00) 0000-0000
    var xPos = PosicaoCursor(campo);
    evt = getEvent(evt);
    var tecla = getKeyCode(evt);
    if (!teclaValida(tecla))
        return;

    vr = campo.value = filtraNumeros(filtraCampo(campo));
    tam = vr.length;

    if (tam == 1)
        campo.value = '(' + vr;
    else if (tam >= 2 && tam < 6)
        campo.value = '(' + vr.substr(0, 2) + ') ' + vr.substr(2);
    else if (tam >= 6)
        campo.value = '(' + vr.substr(0, 2) + ') ' + vr.substr(2, 4) + '-' + vr.substr(6);

    MovimentaCursor(campo, xPos);
}



function mascara(o, f) {
    v_obj = o
    v_fun = f
    setTimeout("execmascara()", 1)
}

function execmascara() {
    v_obj.value = v_fun(v_obj.value)
}


function telefone(v) {
    v = v.replace(/\D/g, "")                 //Remove tudo o que não é dígito
    v = v.replace(/^(\d\d)(\d)/g, "($1)$2") //Coloca parênteses em volta dos dois primeiros dígitos
    v = v.replace(/(\d{4})(\d)/, "$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}


function cpf(v) {
    v = v.replace(/\D/g, "")                    //Remove tudo o que não é dígito
    v = v.replace(/(\d{3})(\d)/, "$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v = v.replace(/(\d{3})(\d)/, "$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    //de novo (para o segundo bloco de números)
    v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

// NÃO ACEITA DIGITAR TEXTO
function semTexto() {
    if (!(event.keyCode <= 57 && event.keyCode >= 48))
        event.keyCode = 0;
}

function mudarEstado(nomeEstado) {
    var estado = window.document.getElementById('baseMudarEstado');

    if (nomeEstado != null && nomeEstado.length > 0) {
        estado.style.visibility = "visible";
        estado.innerHTML = "Mudar para: " + nomeEstado;
    }
    else {
        estado.style.visibility = "hidden";
    }
}

function exibirLojasPorEstado(estadoId) {
    var estadoSelecionado = window.document.getElementById("estado_" + estadoId);
    var estadoAtualId = window.document.getElementById("ctl00_ContentPlaceHolder1_wucPainelLocalidadesCompanhias_hddEstadoAtual");
    var estadoAtual = window.document.getElementById("estado_" + estadoAtualId.value);

    estadoAtual.style.visibility = "hidden";
    estadoSelecionado.style.visibility = "visible";
    estadoAtualId.value = estadoId;
}

function popUp(exibir, tamanho) {
    var container = window.document.getElementById("ctl00_divPopUp");
    var largura = (900 - tamanho) / 2;

    if (exibir) {
        container.style.height = "auto";
        container.style.width = "auto";
        container.style.left = largura + "px";
        container.style.position = "absolute";
        container.style.top = "10%";
        container.style.zIndex = "999";
    }
    else {
        container.style.display = "none";
    }
}
