var openBracket = '["';
var closeBracket = '"]';

var clipTop = 0;
var clipWidth = 170;
var clipBottom = 50;
var topper = 300;
var lyrheight = 0;
var time, amount, theTime, theHeight, DHTML;

var qtde = 0;
var aux = 98;
var valor_total = 0;
var valor_arranjo = 0;
var nome_arranjo = '';
var qtde_anterior = 1;

var altura1 = 0;
var altura2 = 0;
var altura3 = 0;
var altura4 = 0;
var altura5 = 0;
var altura6 = 0;
var altura7 = 0;
var altura8 = 0;
var altura9 = 0;
var altura10 = 0;
var altura11 = 0;
var altura12 = 0;
var altura13 = 0;
var altura14 = 0;
var altura15 = 0;
var altura16 = 0;
var altura17 = 0;
var altura18 = 0;
var altura19 = 0;
var altura20 = 0;

var sumidos = 0;
var nacho1 = 0;

if (navigator.appName == 'Netscape') {
    ver = parseInt(navigator.appVersion.charAt(0));
    var stilo = '';
    if (ver > 4) {
        layerRef = 'document.getElementById';
        styleRef = '.style';
        openBracket = '("';
        closeBracket = '")';
    } else {
        layerRef = 'document.layers';
        styleRef = '';
    }
} else {
    var stilo = ' style="font-family: Verdana; font-size: 8pt; font-weight: bold"';
    var stilo2 = ' style="font-family: Verdana; font-size: 8pt; color: #CC0000; font-weight: bold"';
    layerRef = 'document.all';
    styleRef = '.style';
}


function popup(url, x, y) {
    zoom = window.open(url, "win", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,width=' + x + ',height=' + y);
    self.name = "zoom";
}

function Envia_cep(frm) {
    if (frm.cep.value != "") {
        var windowprops = "width=655,height=350,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
        popup_page = "detalhe_cep2.asp?cep=" + frm.cep.value
        window.open(popup_page, "", windowprops);
        return false;
    }
    else {
        return false;
    }
}

function getObj(name) {
    if (document.getElementById) {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all) {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers) {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}

function popUp2(url) {
    sealWin = window.open(url, "win", 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=530,height=395');
    self.name = "mainWin";
}

function comprarxxxx() {
    if (document.cestas_form.flornum.value == "0") {
        alert("Defina o arranjo");
    }
    else if (qtde == 0) {
        alert("Escolha um acessório para a sua cesta!");
    }
    else {
        document.cestas_form.submit();
    }
}

function comprar() {
    valor = (valor_total + valor_arranjo)

    if (valor < 4500) {
        alert("Pedido mínimo de R$ 45,00!");
    }
    else if (qtde == 0) {
        alert("Escolha um acessório para a sua cesta!");
    }
    else {
        document.cestas_form.submit();
    }
}

function focus_select(qual) {
    selecionado = eval('document.cestas_form.qtdexx_' + qual + '.options.selectedIndex')
    qtde_anterior = eval('document.cestas_form.qtdexx_' + qual + '.options[' + selecionado + '].value');
}

function nachoxx_xxx() {
    aSelects = document.getElementsByTagName("SELECT");

    if (sumidos == 1) {
        for (iCounter = 0; iCounter < aSelects.length; iCounter++) {
            aHiddenSelects[iCounter].style.visibility = "visible";
        }
        sumidos = 0;
    }
    else {
        aHiddenSelects = new Array();

        for (iCounter = 0; iCounter < aSelects.length; iCounter++) {
            aHiddenSelects[aHiddenSelects.length] = aSelects[iCounter];
            aSelects[iCounter].style.visibility = "hidden";
        }
        sumidos = 1;
    }
}

function nachoxx() {
    //alert('pop');
}



function troca_select(qual, valor) {
    selecionado = eval('document.cestas_form.qtdexx_' + qual + '.options.selectedIndex')
    qtde_select = eval('document.cestas_form.qtdexx_' + qual + '.options[' + selecionado + '].value');

    if (eval('document.cestas_form.acessorio_cesta_' + qual + '.checked') == true) {
        valor_total = valor_total - (valor * qtde_anterior) + (valor * qtde_select)
        qtde_anterior = qtde_select;

        valor = (valor_total + valor_arranjo) / 100
        if (valor.toFixed) { valor = valor.toFixed(2) }

        document.cestas_form.total_cesta.value = 'R$ ' + valor
    }


}

function define_flor(flornum, valor, nome) {
    document.cestas_form.flornum.value = flornum
    valor_arranjo = valor;
    nome_arranjo = nome;

    valor = (valor_total + valor_arranjo) / 100
    if (valor.toFixed) { valor = valor.toFixed(2) }

    document.cestas_form.arranjo_cesta.value = nome_arranjo
    document.cestas_form.acessorios_cesta.value = qtde
    document.cestas_form.total_cesta.value = 'R$ ' + valor
}



function fecha(camada) {

    layerNutz = "nutz";
    layerName = "camada_" + camada;
    layerName2 = "iggy_" + camada;
    layerName3 = "iggyxx_" + camada;

    var xs = new getObj(layerName2);
    lyrheight1 = xs.obj.offsetHeight + 50;


    var x = new getObj('nutz');
    lyrheight = x.obj.offsetHeight;
    lyrheight = lyrheight - lyrheight1

    eval(layerRef + openBracket + layerName + closeBracket + styleRef + '.height="28"');
    eval(layerRef + openBracket + layerName3 + closeBracket + styleRef + '.visibility="visible"');
    eval(layerRef + openBracket + layerName2 + closeBracket + styleRef + '.visibility="hidden"');
}

function abre(camada) {
    layerNutz = "nutz";
    layerName = "camada_" + camada;
    layerName2 = "iggy_" + camada;
    layerName3 = "iggyxx_" + camada;

    var xs = new getObj(layerName2);
    lyrheight1 = xs.obj.offsetHeight + 50;
    eval(layerRef + openBracket + layerName2 + closeBracket + styleRef + '.visibility="visible"');
    eval(layerRef + openBracket + layerName3 + closeBracket + styleRef + '.visibility="hidden"');

    eval(layerRef + openBracket + layerName + closeBracket + styleRef + '.height="' + lyrheight1 + 'px"');

    var x = new getObj('nutz');
    lyrheight = x.obj.offsetHeight;
    lyrheight = lyrheight + lyrheight1

}

function enviar(qual, valor) {
    selecionado = eval('document.cestas_form.qtdexx_' + qual + '.options.selectedIndex')
    qtde_select = eval('document.cestas_form.qtdexx_' + qual + '.options[' + selecionado + '].value');

    valor = (valor * qtde_select)

    if (eval('document.cestas_form.acessorio_cesta_' + qual)) {
        if (eval('document.cestas_form.acessorio_cesta_' + qual + '.checked') == true) {
            qtde = qtde + 1;
            valor_total = valor_total + valor
        }
        if (eval('document.cestas_form.acessorio_cesta_' + qual + '.checked') == false) {
            qtde = qtde - 1;
            valor_total = valor_total - valor
        }
    }

    if (qtde > aux) {
        alert("Escolha até " + aux + " acessórios!");
        eval('document.cestas_form.acessorio_cesta_' + qual + '.checked = false');
        qtde = qtde - 1;
        valor_total = valor_total - valor
        return "false";
    }


    valor = (valor_total + valor_arranjo) / 100
    if (valor.toFixed) { valor = valor.toFixed(2) }

    document.cestas_form.arranjo_cesta.value = nome_arranjo
    document.cestas_form.acessorios_cesta.value = qtde
    document.cestas_form.total_cesta.value = 'R$ ' + valor

}
