﻿var BuscaMotoModeloIFrameObj;
var BuscaCarroModeloIFrameObj;

function bindModeloMarcaMoto(formName, codigoCliente, comboModelo, valorMarca, valorModelo, tipoAnuncio) {
    var BuscaMotoModeloIFrameDoc;
    form = document.getElementById(formName);
    if (!document.createElement)
        return true;
    limpaComboMoto(comboModelo);
    if (valorMarca != '') {
        URL = "../../Comum/pgBuscaPorModeloMoto/pgBuscaPorModeloMoto.aspx?formName=" + formName + "&codigoCliente=" + codigoCliente + "&comboModelo=" + comboModelo + "&valorMarca=" + valorMarca + "&valorModelo=" + valorModelo + "&tipoAnuncio=" + tipoAnuncio;
        if (!BuscaMotoModeloIFrameObj && document.createElement) {
            try {
                var tempIFrame = document.createElement('iframe');
                tempIFrame.setAttribute('id', 'BuscaMotoModeloIFrame');
                tempIFrame.setAttribute('src', 'blank.htm');
                tempIFrame.style.border = '0px';
                tempIFrame.style.width = '0px';
                tempIFrame.style.height = '0px';
                BuscaMotoModeloIFrameObj = document.body.appendChild(tempIFrame);
                if (document.frames) {
                    BuscaMotoModeloIFrameObj = document.frames['BuscaMotoModeloIFrame'];
                }
            } catch (exception) {
                iframeHTML = '<iframe id="BuscaMotoModeloIFrame" style="';
                iframeHTML += 'border:0px;';
                iframeHTML += 'width:0px;';
                iframeHTML += 'height:0px;';
                iframeHTML += '"><\/iframe>';
                document.body.innerHTML += iframeHTML;
                BuscaMotoModeloIFrameObj = new Object();
                BuscaMotoModeloIFrameObj.document = new Object();
                BuscaMotoModeloIFrameObj.document.location = new Object();
                BuscaMotoModeloIFrameObj.document.location.replace = function(location) {
                    this.iframe.src = location;
                }
            }
        }
        if (navigator.userAgent.indexOf('Gecko') != -1 && !BuscaMotoModeloIFrameObj.contentDocument) {
            setTimeout('bindModeloMarcaAnoMoto("' + formName + '")', 10);
            return false;
        }
        if (BuscaMotoModeloIFrameObj.contentDocument) {
            BuscaMotoModeloIFrameDoc = BuscaMotoModeloIFrameObj.contentDocument;
        } else if (BuscaMotoModeloIFrameObj.contentWindow) {
            BuscaMotoModeloIFrameDoc = BuscaMotoModeloIFrameObj.contentWindow.document;
        } else if (BuscaMotoModeloIFrameObj.document) {
            BuscaMotoModeloIFrameDoc = BuscaMotoModeloIFrameObj.document;
        } else {
            return true;
        }
        BuscaMotoModeloIFrameDoc.location.replace(URL);
        return false;
    }
}

function setModeloMoto(comboModelo, valorModelo) {
    var array = new Array;
    array = document.getElementById('BuscaMotoModeloIFrame').contentWindow.Modelo;
    limpaComboMoto(comboModelo);
    for (i = 0; i < array.length; i++) {
        document.getElementById(comboModelo).options[i] = array[i];
        if (array[i].value == valorModelo)
            document.getElementById(comboModelo).options.selectedIndex = i;
    }
}

function limpaComboMoto(combo) {
    if (document.getElementById(combo) != null)
        document.getElementById(combo).options.length = 0;
}

function bindModeloMarcaCarro(formName, codigoCliente, comboModelo, valorMarca, valorModelo, tipoAnuncio) {
    var BuscaCarroModeloIFrameDoc;
    form = document.getElementById(formName);
    if (!document.createElement)
        return true;
    limpaComboCarro(comboModelo);
    if (valorMarca != '') {
        URL = "../../Comum/pgBuscaPorModeloCarro/pgBuscaPorModeloCarro.aspx?formName=" + formName + "&codigoCliente=" + codigoCliente + "&comboModelo=" + comboModelo + "&valorMarca=" + valorMarca + "&valorModelo=" + valorModelo + "&tipoAnuncio=" + tipoAnuncio;
        if (!BuscaCarroModeloIFrameObj && document.createElement) {
            try {
                var tempIFrame = document.createElement('iframe');
                tempIFrame.setAttribute('id', 'BuscaCarroModeloIFrame');
                tempIFrame.setAttribute('src', 'blank.htm');
                tempIFrame.style.border = '0px';
                tempIFrame.style.width = '0px';
                tempIFrame.style.height = '0px';
                BuscaCarroModeloIFrameObj = document.body.appendChild(tempIFrame);
                if (document.frames) {
                    BuscaCarroModeloIFrameObj = document.frames['BuscaCarroModeloIFrame'];
                }
            } catch (exception) {
                iframeHTML = '<iframe id="BuscaCarroModeloIFrame" style="';
                iframeHTML += 'border:0px;';
                iframeHTML += 'width:0px;';
                iframeHTML += 'height:0px;';
                iframeHTML += '"><\/iframe>';
                document.body.innerHTML += iframeHTML;
                BuscaCarroModeloIFrameObj = new Object();
                BuscaCarroModeloIFrameObj.document = new Object();
                BuscaCarroModeloIFrameObj.document.location = new Object();
                BuscaCarroModeloIFrameObj.document.location.replace = function(location) {
                    this.iframe.src = location;
                }
            }
        }
        if (navigator.userAgent.indexOf('Gecko') != -1 && !BuscaCarroModeloIFrameObj.contentDocument) {
            setTimeout('bindModeloMarcaAnoCarro("' + formName + '")', 10);
            return false;
        }
        if (BuscaCarroModeloIFrameObj.contentDocument) {
            BuscaCarroModeloIFrameDoc = BuscaCarroModeloIFrameObj.contentDocument;
        } else if (BuscaCarroModeloIFrameObj.contentWindow) {
            BuscaCarroModeloIFrameDoc = BuscaCarroModeloIFrameObj.contentWindow.document;
        } else if (BuscaCarroModeloIFrameObj.document) {
            BuscaCarroModeloIFrameDoc = BuscaCarroModeloIFrameObj.document;
        } else {
            return true;
        }
        BuscaCarroModeloIFrameDoc.location.replace(URL);
        return false;
    }
}

function setModeloCarro(comboModelo, valorModelo) {
    var array = new Array;
    array = document.getElementById('BuscaCarroModeloIFrame').contentWindow.Modelo;
    limpaComboCarro(comboModelo);
    for (i = 0; i < array.length; i++) {
        document.getElementById(comboModelo).options[i] = array[i];
        if (array[i].value == valorModelo)
            document.getElementById(comboModelo).options.selectedIndex = i;
    }
}

function limpaComboCarro(combo) {
    if (document.getElementById(combo) != null)
        document.getElementById(combo).options.length = 0;
}

var fotoExibida = 1;
var intervalo = 5000;

function DefineIntervaloFotosLoja() {
    if (quantidadeFotos > 0)
        setInterval("MudaFotoLoja()", intervalo);
}

function MudaFotoLoja() {
    fotoExibida++;

    if (fotoExibida > quantidadeFotos)
        fotoExibida = 1;

    objFoto = document.getElementById("imagemLoja");
    objNomeImagem = document.getElementById(("fotoLoja" + fotoExibida));

    if ((objFoto != null) && (objNomeImagem != null))
        objFoto.src = objNomeImagem.value;
}
function RedirectSiteAutomatico(pag) {
    document.location.href = pag;
}
