﻿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 tem recursos para uso do Ajax");
                req = null;
            }
        }
    }
    return req;
}
function CarregaBairro(Cidade) {
    if (Cidade.length == 0) {
        document.getElementById("Bairro").options.length = 0;
        document.getElementById("Bairro").options[0] = new Option("Bairro", "")
        document.getElementById("Bairro").options[1] = new Option("Selecione a cidade", "")
        return;
    }
    document.getElementById("Bairro").selectedIndex = 0;
    document.getElementById("Bairro").disabled = true;
    ajax2 = ajaxInit();
    resultado = "";
    if (ajax2) {
        ajax2.open("GET", "ajax_bairros.asp?Cidade=" + Cidade + "&Rand=" + Math.ceil(Math.random() * 100000), true);
        ajax2.setRequestHeader("Content-Type", "charset=iso-8859-1");
        ajax2.onreadystatechange = function() {
            if (ajax2.readyState == 4) {
                if (ajax2.status == 200) {
                    resultado = ajax2.responseText;
                    timerID = setTimeout("ExibeBairros('" + resultado + "')", 1500);
                }
            }
        }
        ajax2.send(null);
    }
}
function ExibeBairros(Bairros) {
    var splitBairros, x;
    document.getElementById("Bairro").disabled = false;
    splitBairros = Bairros.split("|");
    document.getElementById("Bairro").options[0] = new Option("Bairro", "");
    for (x = 0; x < splitBairros.length-1; x++) {
        document.getElementById("Bairro").options[x + 1] = new Option(splitBairros[x], splitBairros[x]);
    }
    if (Bairros.length == 0) {
        document.getElementById("Bairro").options.length = 0;
        document.getElementById("Bairro").options[0] = new Option("Bairro", "")
        document.getElementById("Bairro").options[1] = new Option("Não há bairros cadastrados!", "")
        return;
    }
}
function ProximoBannerHome2(Valor) {
    
    splitBanners = ListaBanners.split("|");
    splitNomeBanners = ListaNomeBanners.split("|");
    splitListaIDBanners = ListaIDBanners.split("|");
    BannerAtual = Valor;
    IndiceAtual = Valor-1;

    document.getElementById("BannerHome").innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"716\" height=\"264\"><param name=\"movie\" value=\"" + ArrayBanner[BannerAtual - 1] + "\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"><embed src=\"" + ArrayBanner[BannerAtual - 1] + "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" menu=\"false\" width=\"716\" height=\"264\"></embed></object>";
    for (x = 1; x <= splitBanners.length - 1; x++) {
        document.getElementById("botao_home_" + x).style.backgroundImage = "url(imgs/off.png)";
        document.getElementById("nome_home_" + x).style.display = "none";
    }
    document.getElementById("botao_home_" + BannerAtual).style.backgroundImage = "url(imgs/on.png)";
    document.getElementById("botao_home_" + BannerAtual).style.color = "#FFFFFF";
    document.getElementById("nome_home_" + BannerAtual).style.display = "block";
    //document.getElementById("legenda_atual").innerHTML = splitNomeBanners[BannerAtual - 1];
}

function ExibeNomeHome(Nome) {
    document.getElementById("Legenda_" + Nome).style.marginTop = -255 + ((27 * Nome) - 27) + "px";
    document.getElementById("Legenda_" + Nome).style.display = "block";
}

function OcultaNomeHome(Nome) {
    document.getElementById("Legenda_" + Nome).style.display = "none";
}

function FichaProdutoBanner() {
    location.href = ArrayBannerLink[IndiceAtual];
}
