var comHTTPS = "https://";
var semHTTPS = "http://";
var sitePath = "www.webmotors.com.br/";
var mensagemErroGenericoSite = "Desculpe-nos, ocorreu um problema. Por favor, tente novamente.";
var textoPadrao = "carregando...";

function ValidaBuscaSEO() {

    var vSEO = false;
    var cidadesVizinhas = '';
    var cidade = '';

    if (document.getElementById('chkCidadesVizinhas').checked
    && document.getElementById('cboDistancia').value != "") {
        cidadesVizinhas = "&cidadesvizinhas=S&distancia=" + document.getElementById('cboDistancia').value;
    }

    if (document.getElementById('cboFaixaPrecoInicial').value == "" &&
    document.getElementById('cboFaixaPrecoFinal').value == "" &&
    document.getElementById('cboEstado').value == "" &&
    document.getElementById('cboAnoModeloInicial').value == "" &&
    document.getElementById('cboAnoModeloFinal').value == "") {
        vSEO = false;
       }

    if (document.getElementById('cboCidade').value != textoPadrao)
		cidade = Encoding(document.getElementById('cboCidade').value);

    if (document.getElementById('rdoCarrosUsados').checked) {
        if (document.getElementById('rdoCarrosUsados').checked && vSEO == false) {
        	if (document.getElementById('chkNovos').checked == true && document.getElementById('chkUsados').checked == false) {
        		if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&modelo=" + document.getElementById('cboModelo').value + "&descrModelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anuncionovos=N&revend=S&concessionaria=S&Ordem=OP&orig=S";
                   } else {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anuncionovos=N&revend=S&concessionaria=S&Ordem=OP&orig=S";
                }
            } 
            else if (document.getElementById('chkNovos').checked == false && document.getElementById('chkUsados').checked == true){
            if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                     document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&modelo=" + document.getElementById('cboModelo').value + "&descrModelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anunciousados=U&revend=S&part=S&concessionaria=S&Ordem=OP&orig=S";
                    } else {
                     document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anunciousados=U&revend=S&part=S&concessionaria=S&Ordem=OP&orig=S";
                }
                }
            else {
            	if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&modelo=" + document.getElementById('cboModelo').value + "&descrModelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&revend=S&part=S&concessionaria=S&Ordem=OP&orig=S";
                } else {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&revend=S&part=S&concessionaria=S&Ordem=OP&orig=S";
                }
                }
        } else if (document.getElementById('rdoCarrosUsados').checked && vSEO == true) {
                if (document.getElementById('cboMarca').value != "" && document.getElementById('cboModelo').value == "") {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/comprar/carros/usados/" + formatStringSEO(document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text) + "/veiculo.wm";
                } else if (document.getElementById('cboMarca').value != "" && document.getElementById('cboModelo').value != "") {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/comprar/carros/usados/" + formatStringSEO(document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text) + "/" + formatStringSEO(document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text) + "/modelo.wm";
                   } else {
            document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/carrosResultado/carros-resultado.aspx?marca=" + document.getElementById('cboMarca').value + "&precoinicial=" + document.getElementById('cboFaixaPrecoInicial').value + "&precofinal=" + document.getElementById('cboFaixaPrecoFinal').value + "&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&anoInicial=" + document.getElementById('cboAnoModeloInicial').value + "&anoFinal=" + document.getElementById('cboAnoModeloFinal').value + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&revend=S&part=S&concessionaria=S&Ordem=OP&orig=S"; 
                }
            }
        
            document.FormBusca.submit();

    }
    else if (document.getElementById('rdoMotosUsadas').checked) {
         if (document.getElementById('rdoMotosUsadas').checked && vSEO == false) {
            if (document.getElementById('chkNovos').checked == true && document.getElementById('chkUsados').checked == false) {
            	if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&descrestilo=&descrmodelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&revend=S&modelo=" + document.getElementById('cboModelo').value + cidadesVizinhas + "&anuncionovos=N&concessionaria=S&Ordem=OP&orig=S";
                   } else {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&revend=S&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + cidadesVizinhas + "&anuncionovos=N&concessionaria=S&Ordem=OP&orig=S";
                }
            } else if (document.getElementById('chkNovos').checked == false && document.getElementById('chkUsados').checked == true) {
            if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&descrestilo=&descrmodelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&revend=S&part=S&modelo=" + document.getElementById('cboModelo').value + cidadesVizinhas + "&anunciousados=U&concessionaria=S&Ordem=OP&orig=S";
                   } else {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&revend=S&part=S&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + cidadesVizinhas + "&anunciousados=U&concessionaria=S&Ordem=OP&orig=S";
                }
            } else {
            if (document.getElementById('cboModelo').selectedIndex != -1 && document.getElementById('cboModelo').value != textoPadrao) {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + "&descrestilo=&descrmodelo=" + document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text.replace('&', '%26') + "&revend=S&part=S&modelo=" + document.getElementById('cboModelo').value + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&concessionaria=S&Ordem=OP&orig=S";
                   } else {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&revend=S&part=S&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&concessionaria=S&Ordem=OP&orig=S";
                }
                }
        } else if (document.getElementById('rdoMotosUsadas').checked && vSEO == true) {
                if (document.getElementById('cboMarca').value != "" && document.getElementById('cboModelo').value == "") {
                    document.FormBusca.action = semHTTPS + sitePath + "Webmotors/comprar/motos/usadas/" + formatStringSEO(document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text) + "/veiculo.wm";
                } else if (document.getElementById('cboMarca').value != "" && document.getElementById('cboModelo').value != "") {
                document.FormBusca.action = semHTTPS + sitePath + "Webmotors/comprar/motos/usadas/" + formatStringSEO(document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text) + "/" + formatStringSEO(document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text) + "/modelo.wm";
               } else {
                document.FormBusca.action = semHTTPS + sitePath + "Webmotors/Compra/motosResultado/motos-resultado.aspx?precode=" + document.getElementById('cboFaixaPrecoInicial').value + "&precoate=" + document.getElementById('cboFaixaPrecoFinal').value + "&anoate=" + document.getElementById('cboAnoModeloFinal').value + "&descrmarca=" + document.getElementById('cboMarca').options[document.getElementById('cboMarca').selectedIndex].text + "&marca=" + document.getElementById('cboMarca').value + "&anode=" + document.getElementById('cboAnoModeloInicial').value + "&estilo=&revend=S&part=S&avanc=0&uf=" + document.getElementById('cboEstado').value + "&cidade=" + cidade + cidadesVizinhas + "&anuncionovos=N&anunciousados=U&concessionaria=S&Ordem=OP&orig=S"; ;
                }
            }
        
            document.FormBusca.submit();
        }
    }

function formatStringSEO(texto) {

    text = texto.toLowerCase();
    text = text.replace("ü", "u");
    text = text.replace("ö", "o");
    text = text.replace("ï", "i");
    text = text.replace("ë", "e");
    text = text.replace("ä", "a");
    text = text.replace("û", "u");
    text = text.replace("ô", "o");
    text = text.replace("î", "i");
    text = text.replace("ê", "e");
    text = text.replace("â", "a");
    text = text.replace("ç", "c");
    text = text.replace("õ", "o");
    text = text.replace("ã", "a");
    text = text.replace("ù", "u");
    text = text.replace("ò", "o");
    text = text.replace("ì", "i");
    text = text.replace("è", "e");
    text = text.replace("à", "a");
    text = text.replace("ú", "u");
    text = text.replace("ó", "o");
    text = text.replace("í", "i");
    text = text.replace("é", "e");
    text = text.replace("á", "a");
    text = text.replace(" ", "-");
    text = text.replace("&-", "");
    text = text.replace("&", "");

    if (text.length == (text.lastIndexOf(".") + 1))
        text = text.substring(0, text.length - 1);

    return text;
}

function ValidaBuscaAnuncioExportado() {
    if (document.getElementById('txtAnuncioExportado').value == "") {
        alert("Digite o código de um anúncio no jornal.");
    } else {
        document.FormBuscaAnuncioExportado.action = semHTTPS + sitePath + "/Webmotors/Compra/carrosResultado/carros-resultado.aspx?codExp=" + document.getElementById('txtAnuncioExportado').value;
        document.FormBuscaAnuncioExportado.submit();
    }

}

function selecionaComboModelo() {
    limpaCombo('cboModelo');
    if (document.getElementById('rdoMotosUsadas').checked && document.getElementById('chkUsados').checked == false && document.getElementById('chkNovos').checked == true) 
        bindModeloNovoMarcaMoto('FormBusca', 'cboModelo', document.getElementById('cboMarca').value, document.getElementById('cboModelo').value);
    else if (document.getElementById('rdoMotosUsadas').checked) 
       bindModeloMarcaMoto('FormBusca', 'cboModelo', document.getElementById('cboMarca').value, document.getElementById('cboModelo').value);
   else if (document.getElementById('rdoCarrosUsados').checked && document.getElementById('chkUsados').checked == false && document.getElementById('chkNovos').checked == true)
        bindModeloNovo('FormBusca', 'cboModelo', document.getElementById('cboMarca').value, document.getElementById('cboModelo').value);
    else if (document.getElementById('rdoCarrosUsados').checked) 
        bindModelo('FormBusca', 'cboModelo', document.getElementById('cboMarca').value, document.getElementById('cboModelo').value);
}

function selecionaComboBU() {
    if (document.getElementById('rdoMotosUsadas').checked && document.getElementById('chkUsados').checked == false && document.getElementById('chkNovos').checked == true) {
        limpaCombo('cboModelo');
        limpaCombo('cboMarca');
        bindMarcaMotoNova('FormBusca', 'cboMarca', 'cboModelo', '');
    }
    else if (document.getElementById('rdoMotosUsadas').checked) {
        limpaCombo('cboModelo');
        limpaCombo('cboMarca');
        bindMarcaMoto('FormBusca', 'cboMarca', '');
    }
    else if (document.getElementById('rdoCarrosUsados').checked && document.getElementById('chkUsados').checked == false && document.getElementById('chkNovos').checked == true) {
        limpaCombo('cboModelo');
        limpaCombo('cboMarca');
        bindMarcaNova('FormBusca', 'cboMarca', 'cboModelo', '');
    }
    else if (document.getElementById('rdoCarrosUsados').checked) {
        limpaCombo('cboModelo');        
        limpaCombo('cboMarca');
        bindMarca('FormBusca', 'cboMarca', 'cboModelo', '');
    }
}

function carroMoto() {
    if (document.getElementById('rdoCarro').checked == true) {
        document.getElementById('comprarCarro').style.visibility = 'visible'
        document.getElementById('comprarMoto').style.visibility = 'hidden'
    } else if (document.getElementById('rdoMoto').checked == true) {
        document.getElementById('comprarCarro').style.visibility = 'hidden';
        document.getElementById('comprarMoto').style.visibility = 'visible'
    }
}
function carroMotoAnuncie() {
    if (document.getElementById('carroVender').checked == true) {
        document.getElementById('marcaVender').style.visibility = 'visible';
        document.getElementById('marcaVenderMoto').style.visibility = 'hidden'
    } else if (document.getElementById('motoVender').checked == true) {
        document.getElementById('marcaVender').style.visibility = 'hidden';
        document.getElementById('marcaVenderMoto').style.visibility = 'visible'
    }
}
function carroMotoAvaliacao() {
    if (document.getElementById('carroAvaliar').checked == true) {
        document.getElementById('avaliacaoCarro').style.visibility = 'visible';
        document.getElementById('avaliacaoMoto').style.visibility = 'hidden'
    } else if (document.getElementById('motoAvaliar').checked == true) {
        document.getElementById('avaliacaoCarro').style.visibility = 'hidden';
        document.getElementById('avaliacaoMoto').style.visibility = 'visible'
    }
}
function ValidaAvaliacao() {
    if (document.getElementById('carroAvaliar').checked == true) {
        if (FormAvaliacao.cboMarca.value == "") {
            window.alert("Selecione a marca.");
            return false;
        }
        if (FormAvaliacao.cboModelo.value == "") {
            window.alert("Selecione o modelo.");
            return false;
        }
        document.FormAvaliacao.submit();
    } else if (document.getElementById('motoAvaliar').checked == true) {
        if (document.getElementById('ddlMarca').value == "") {
            window.alert("Selecione a marca.");
            return false;
        }
        document.FormAvaliacaoMoto.submit();
    }
}

function ValidaManutencao() {
    if (!VerificaEmail(document.getElementById('txtEmail').value)) {
        alert("E-mail inválido"); return false;
    }
    if ((document.getElementById('cboDiaNasc').value == "") && (document.getElementById('cboMesNasc').value == "") && (document.getElementById('cboAnoNasc').value == "")) {
        window.alert("Informe sua data de nascimento.");
        return false
    }
    document.FormManutencao.action = "/webmotors/ssManutencao/pgAgendadoCarro/AgendadoCarro.asp?email=" + document.getElementById('txtEmail').value + "&dia=" + document.getElementById('cboDiaNasc').value + "&mes=" + document.getElementById('cboMesNasc').value + "&ano=" + document.getElementById('cboAnoNasc').value;
    return true;
}
function ValidaAnuncie() {
    if (document.getElementById('carroVender').checked == true) {
        if (document.getElementById('cboMarcaAnuncio').value == "") {
            alert("Selecione uma marca.");
            return false;
        } else {
            document.FormAnuncie.action = comHTTPS + sitePath + "webmotors/ssVenda/pgHomeVenda/pgHomeVenda.aspx?CodMarca=" + document.FormAnuncie.cboMarcaAnuncio.value;
        }
    } else if (document.getElementById('motoVender').checked == true) {
        if (document.getElementById('cboMarcaMotoAnuncio').value == "") {
            alert("Selecione uma marca.");
            return false;
        } else {
            document.FormAnuncie.action = comHTTPS + sitePath + "Webmotors/ssVenda/pgHomeVenda/pgHomeVendaMoto.aspx?CodMarca=" + document.FormAnuncie.cboMarcaMotoAnuncio.value;
        }
    }
}

function carregaAno(formName, cboAno, cboAnoFinal, anoInicial, anoFinal, texto) {
    eval("document.getElementById(formName)." + cboAno + ".options[0] = new Option('" + texto + "', '')");
    eval("document.getElementById(formName)." + cboAnoFinal + ".options[0] = new Option('" + texto + "', '')");
    anoFinal = new Date().getFullYear() + 1;
    for (i = 1; i <= anoFinal - anoInicial; i++) {
        eval("document.getElementById(formName)." + cboAno + ".options[i] = new Option(" + (anoFinal - i) + ", " + (anoFinal - i) + ")");
    }
    var AnoFinalComboFinal = new Date().getFullYear() + 2;
    for (i = 1; i <= AnoFinalComboFinal - anoInicial; i++) {
        eval("document.getElementById(formName)." + cboAnoFinal + ".options[i] = new Option(" + (AnoFinalComboFinal - i) + ", " + (AnoFinalComboFinal - i) + ")");
    }
}
function carregaPreco(formName, cboPreco, cboRrecoFinal) {
    eval("document.getElementById(formName)." + cboPreco + ".options[0] = new Option('', '')");
    eval("document.getElementById(formName)." + cboRrecoFinal + ".options[0] = new Option('', '')");
    for (i = 0; i < 16; i++) {
        if (i > 0) {
            eval("document.getElementById(formName)." + cboPreco + ".options[i+1] = new Option('" + (i * 2) + ".000', '" + (i * 2) + "000')");
            eval("document.getElementById(formName)." + cboRrecoFinal + ".options[i+1] = new Option('" + (i * 2) + ".000', '" + (i * 2) + "000')");
        } else {
        eval("document.getElementById(formName)." + cboPreco + ".options[i+1] = new Option('indiferente', '" + (i * 2) + "000')");
        eval("document.getElementById(formName)." + cboRrecoFinal + ".options[i+1] = new Option('indiferente', '" + (i * 2) + "000')");
        }
    }
    for (i = 16; i < 20; i++) {
        eval("document.getElementById(formName)." + cboPreco + ".options[i+1] = new Option('" + ((i - 9) * 5) + ".000', '" + ((i - 9) * 5) + "000')");
        eval("document.getElementById(formName)." + cboRrecoFinal + ".options[i+1] = new Option('" + ((i - 9) * 5) + ".000', '" + ((i - 9) * 5) + "000')");
    }
    for (i = 20; i < 25; i++) {
        eval("document.getElementById(formName)." + cboPreco + ".options[i+1] = new Option('" + ((i - 14) * 10) + ".000', '" + ((i - 14) * 10) + "000')");
        eval("document.getElementById(formName)." + cboRrecoFinal + ".options[i+1] = new Option('" + ((i - 14) * 10) + ".000', '" + ((i - 14) * 10) + "000')");
    }
    eval("document.getElementById(formName)." + cboRrecoFinal + ".options[26] = new Option('999.000', '999000')");
}

function carregaAnoManutencao(formName, cboAno, anoInicial, anoFinal, texto) {
    eval("document.getElementById(formName)." + cboAno + ".options[0] = new Option('" + texto + "', '')");
    for (i = 1; i < anoFinal - anoInicial; i++) {
        eval("document.getElementById(formName)." + cboAno + ".options[i] = new Option(" + (anoFinal - i) + ", " + (anoFinal - i) + ")");
    }
}
function carregaNumeros(formName, cboAno, valorInicial, valorFinal, texto) {
    eval("document.getElementById(formName)." + cboAno + ".options[0] = new Option('" + texto + "', '')");
    for (i = 1; i < valorFinal; i++) {
        if (i < 10)
            eval("document.getElementById(formName)." + cboAno + ".options[i] = new Option('0" + (i) + "', " + (i) + ")");
        else
            eval("document.getElementById(formName)." + cboAno + ".options[i] = new Option('" + (i) + "', " + (i) + ")");
    }
}
function carregaUF(formName, cboUF, texto) {
    
    aUF = new Array(); aUF = new Array(); aUF[0] = texto; aUF[1] = 'AC'; aUF[2] = 'AL'; aUF[3] = 'AP'; aUF[4] = 'AM'; aUF[5] = 'BA'; aUF[6] = 'CE'; aUF[7] = 'DF'; aUF[8] = 'ES';
    aUF[9] = 'GO'; aUF[10] = 'MA'; aUF[11] = 'MG'; aUF[12] = 'MS'; aUF[13] = 'MT'; aUF[14] = 'PA'; aUF[15] = 'PB'; aUF[16] = 'PE'; aUF[17] = 'PI'; aUF[18] = 'PR';
    aUF[19] = 'RJ'; aUF[20] = 'RN'; aUF[21] = 'RO'; aUF[22] = 'RR'; aUF[23] = 'RS'; aUF[24] = 'SC'; aUF[25] = 'SE'; aUF[26] = 'SP'; aUF[27] = 'TO';
    for (i = 0; i < aUF.length; i++)
        if (i == 0)
            eval("document.getElementById(formName)." + cboUF + ".options[i] = new Option(aUF[i], '')");
    else
        eval("document.getElementById(formName)." + cboUF + ".options[i] = new Option(aUF[i], aUF[i])");
}
function soNumero(objeto) {
    var keypress = event.keyCode;
    var campo = eval(objeto);
    var caracteres = '01234567890';
    if ((caracteres.indexOf(String.fromCharCode(keypress)) != -1))
        event.returnValue = true;
    else
        event.returnValue = false;
}
function validaCasasDecimal(objeto, maxlength, casas, valor) {
    if ((objeto.value.indexOf(',') != -1)) {
        if ((objeto.value.length - objeto.value.indexOf(',')) > casas + 1)
            objeto.value = objeto.value.substr(0, objeto.value.length - 1);
    }
    else {
        if ((objeto.value.length) >= maxlength - (casas + valor))
            objeto.value = objeto.value.substr(0, (maxlength - (casas + valor)));
    }
}

function buscaOficinas() {
    document.FormManu.action = semHTTPS + sitePath + "Webmotors/ssManutencao/pgResultadoBuscaOficina/pgResultadoBuscaOficina.aspx?uf=" + document.getElementById('cboEstadoManu').value;
    document.FormManu.submit();
}


function Encoding(string) {
    string = string.replace(/\r\n/g, "\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if ((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return escape(utftext);
}

function VerificarCheckCidadeVizinhaBU(chk, cbo, cboEstado, txtCidade) {
    
    idComboCidadeVizinha = cbo;

    var chkbox = document.getElementById(chk);
    var cboBox = document.getElementById(cbo);
    var comboEstado = document.getElementById(cboEstado);
    var textoCidade = document.getElementById(txtCidade);

    if (chkbox != null && cboBox != null) {
        if (comboEstado.value != null &&
			comboEstado.value != '' &&
			textoCidade.value != null &&
			textoCidade.value.trim() != '') {
            if (chkbox.checked) {
                cboBox.disabled = false;
                WebMotors.ssComum.ssServicos.InformacaoCidades.FindCidadeVizinhas(comboEstado.value, textoCidade.value, FindCidadeVizinhas_OnComplete, FindCidadeVizinhas_OnError, FindCidadeVizinhas_OnTimeOut);
            }
            else {
                limpaCombo(idComboCidadeVizinha);
                cboBox.disabled = true;
            }
        }
        else {
            limpaCombo(idComboCidadeVizinha);
            chkbox.checked = false;
            document.getElementById(cbo).selectedIndex = 0;
            cboBox.disabled = true;
        }
    }
}

function FindCidadeVizinhas_OnComplete(list) {
    if (list) {
        limpaCombo(idComboCidadeVizinha);
        var e = document.getElementById(idComboCidadeVizinha);
        var selectedValueOption = null;
        for (i = 1; i <= list.length; i++) {
            var item = list[i - 1];
            var listItemName = item.name;
            var listItemValue = item.value;
            var listItemIsDefaultValue = item.isDefaultValue;
            var optionElement = new Option(listItemName, listItemValue);
            if (listItemIsDefaultValue)
                selectedValueOption = optionElement;

            e.options[e.options.length] = optionElement;
        }
        if (selectedValueOption)
            selectedValueOption.selected = true;
    }
    else
        alert(msg);
}

function FindCidadeVizinhas_OnTimeOut(arg) {
    alert(mensagemErroGenericoSite);
}

function FindCidadeVizinhas_OnError(arg) {
    alert(mensagemErroGenericoSite);
}

function LimparCidadesVizinhas(chk, cbo) {
    document.getElementById(chk).checked = false;
    limpaCombo(cbo);
    document.getElementById(cbo).disabled = true;
}

function limpaCombo(combo) {
    if (document.getElementById(combo) != null) 
        document.getElementById(combo).options.length = 0;
}

function MarcarCidadesVizinhas(combo, chk) {
    var chkCidadesVizinha = document.getElementById(chk);
    if (combo.value != '') {
        chkCidadesVizinha.checked = true;
        VerificarCheckCidadeVizinhaBU('chkCidadesVizinhas', 'cboDistancia', 'cboEstado', 'cboCidade');
    }   
}
function verificarTexto() {
    if (document.getElementById('q').value == " Pesquisa por matérias") {
        document.getElementById('q').value = "";
    } else if (document.getElementById('q').value == "") {
        document.getElementById('q').value = " Pesquisa por matérias";
    }
}
function randomizarImagem(tipo) {
    if (tipo == 1) {
        nomeImagem = "financiamento-de-veiculos";
    } else {
        nomeImagem = "financiamento-de-veiculos-menor";
    }
    var randomnumber = Math.floor(Math.random() * 4)
    if (randomnumber == 0)
        document.getElementById('imagemFinanciamento').src = semHTTPS + sitePath + "webmotors/_img/" + nomeImagem + "-1.jpg";
    if (randomnumber == 1)
        document.getElementById('imagemFinanciamento').src = semHTTPS + sitePath + "webmotors/_img/" + nomeImagem + "-2.jpg";
    if (randomnumber == 2)
        document.getElementById('imagemFinanciamento').src = semHTTPS + sitePath + "webmotors/_img/" + nomeImagem + "-3.jpg";
    if (randomnumber == 3)
        document.getElementById('imagemFinanciamento').src = semHTTPS + sitePath + "webmotors/_img/" + nomeImagem + "-4.jpg";
    
}
function ValidarAnoBuscaEspecifica(cboAno,cboAnoAte, cboAnoCarc, cboAnoCarcAte)
{

   var Inicial = document.getElementById(cboAno);
   var Final = document.getElementById(cboAnoAte);
   var valorInicial;
   var valorFinal;
   var CboAno = document.getElementById(cboAnoCarc);
   var cboAnoCarc = document.getElementById(cboAnoCarcAte);
	 	 
    for(var i = 0; i < Inicial.options.length; i++)
    {
        if (Inicial.options[i].selected == true) 
        {
            valorInicial = Inicial.options[i].text;
        }
    } 
    for(var i = 0; i < Final.options.length; i++)
    {
        if (Final.options[i].selected == true) 
        {
            valorFinal = Final.options[i].text;
        }
    }

    if (parseInt(valorInicial) > parseInt(valorFinal))
    {
        jQuery('#' + cboAno).val(valorFinal);
        jQuery('#' + cboAnoAte).val(valorInicial);
    }
}
function ValidarPreco(txtPreco,txtPrecoFinal)
{
	// inverte os faixa de preco, se necessário
    var Inicial = document.getElementById(txtPreco);
    var Final = document.getElementById(txtPrecoFinal);

    if (parseFloat(Inicial.value) > parseFloat(Final.value))
    {
        var x = Inicial.value;
        var y = Final.value;

        Inicial.value = ''; 
        Final.value = '';

        Inicial.value = y;
        Final.value = x;
    }
}
