// JavaScript Document
function exibe_oculta(id, elemento){
    if (document.all(id).style.display == 'none') {
        document.all(id).style.display = 'block';
    }
    else {
        document.all(id).style.display = 'none';
    }
}

function mostra_pagina(pagina){
    window.open(pagina, "", "width=636,height=700,menubar=no,scrollbars=yes,toolbar=no,resizable=no,top=0,left=0");
}

function mostra_foto(pagina){
    window.open(pagina, "", "width=670,height=510,menubar=no,scrollbars=no,toolbar=no,resizable=no,top=0,left=0");
}

function TestaVal(){
    if (document.form.tipo1.value == "") {
        alert("Selecione um Tipo")
        return false
    }
    else 
        if (document.form.marca.value == "") {
            alert("Selecione uma Marca")
            return false
        }
        else {
            return true
        }
}

/* editar aki quando mudar de pro servidor */
var root = "http://" + window.location.host + "/";

function getDescricaoClassificado(codigo, elemento){
    var _p, _c, d;
    d = $id('descricao_' + codigo);
    if (!d) {
        d = $element('div');
        d.className = 'classificadosmenor';
        d.id = 'descricao_' + codigo;
        d.innerHTML = 'Carregando...';
        elemento.parentNode.appendChild(d, elemento);
        _p = 'cd=' + codigo;
        _c = {
            url: root + 'descricao_classificado.php',
            param: _p,
            type: 'text',
            asc: function(result){
                var r = result;
                d.innerHTML = result;
            }
        }
        new $ajax(_c);
    }
    else {
        if (d.style.display == 'none') {
            d.style.display = '';
        }
        else {
            d.style.display = 'none'
        }
    }
}

function resetSelect(element){
    while (element.length > 0) 
        element.remove(0);
}

/**
 * Consulta por ajax Marca / Modelo
 *
 * @param {String} tipo
 */
function menu_consulta(tipo, codigo){
    var f, t, _p, _c;
    f = $id('menu_consulta');
    _p = 'cd=' + codigo + '&tp=' + tipo;
    _c = {
        url: root + 'consulta_menu.php',
        param: _p,
        type: 'json',
        asc: function(result){
            var r, rS;
            rS = (r = result).ResultSet;
            if (tipo == 'tipo1') {
                resetSelect(f.marca);
                f.marca.options[0] = new Option('Selecione', '0');
                for (var i = 0, c = 1; i < r.rowCount; i++, c++) {
                    f.marca.options[c] = new Option(rS[i].d, rS[i].c);
                }
            }
            else 
                if (tipo == 'marca') {
                    resetSelect(f.modelo);
                    f.modelo.options[0] = new Option('Selecione', '0');
                    for (var i = 0, c = 1; i < r.rowCount; i++, c++) {
                        f.modelo.options[c] = new Option(rS[i].d, rS[i].c);
                    }
                }
                else 
                    if (tipo == 'ano') {
                        resetSelect(f.ate);
                        f.ate.options[0] = new Option('--', '0');
                        for (var i = 0, c = 1; i < r.rowCount; i++, c++) {
                            f.ate.options[c] = new Option(rS[i].d, rS[i].c);
                        }
                    }
        }
    }
    new $ajax(_c);
}

function slide(){
    var e, d, c, a, t, _d, _t, _ul, _li, _img;
    c = 0;
    a = $element('a', 3);
    
    e = $id('destaque');
    d = $name('div', {
        base: e,
        atr: 'class',
        val: 'slide'
    });
    
    var fnInterval = function(){
        t = setInterval(function(){
            $s(d[c], $atr_class, 'slide off');
            $s(a[c], $atr_class, '');
            c < 2 ? c++ : c = 0;
            $s(d[c], $atr_class, 'slide on');
            $s(a[c], $atr_class, 'selected');
        }, 8000, this);
    }
    
    _d = $element('div');
    _d.className = 'slide_link';
    _ul = $element('ul');
    
    d[0].className = 'slide on';
    
    for (var i = 0; i < 3; i++) {
    
        _li = $element('li');
        _img = $element('img');
        _img.src = d[i].getElementsByTagName('img')[0].src.replace('w=250&h=200', 'w=50&h=36');
        
        if (i == 0) 
            a[i].className = 'selected';
        
        a[i].id = "slide_" + i;
        a[i].href = 'javascript:void(0);';
        a[i].onmouseover = function(){
            var _i = this.id.replace('slide_', '');
            clearInterval(t);
            fnInterval();
            this.className = 'selected';
            
            a[c].className = '';
            d[c].className = 'slide off';
            
            c = _i;
            d[_i].className = 'slide on';
        }
        
        $append(a[i], _img);
        $append(_li, a[i])
        $append(_ul, _li);
    }
    $append(_ul, _li);
    $append(_d, _ul);
    
    var firstChild = e.parentNode.getElementsByTagName('div');
    e.parentNode.insertBefore(_d, firstChild[0])
    fnInterval();
    
}