/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function $(id) {
    return document.getElementById(id);
}

function copiaTextoInput (id1,id2) {
    document.getElementById(id2).value = document.getElementById(id1).value;
}

function exibirBgBody() {
    initLytebox();
    // Seleciona a tag body. item(0) por que só existe uma tag body
    var tagBody = document.body;
    // Pega os tamanhos atuais da página, como largura, altura, ...
    var sizesPage = myLytebox.getPageSize();
    // Vamos criar uma tag div
    var bgBody = document.createElement('div');
    // Setar o atributo ID a div criada
    bgBody.setAttribute('id','bgBody');
    bgBody.style.position = 'absolute';
    bgBody.style.top = '0px';
    bgBody.style.left = '0px';
    bgBody.style.backgroundColor = 'black';

    bgBody.style.opacity = (25 / 100);
    bgBody.style.MozOpacity = (25 / 100);
    bgBody.style.KhtmlOpacity = (25 / 100);
    bgBody.style.filter = "alpha(opacity=" + 25 + ")";

    // Essa div terá o tamanho exato da página
    bgBody.style.height = sizesPage[1] + 'px';
    // Essa div terá a largura exata da página
    bgBody.style.width = sizesPage[2] + 'px';

    //alert (sizesPage[2]);

    // Evita criar a div novamente

    // - Gambiarra para corrigir problemas com o IE6
    var selects = document.getElementsByTagName('select');
    for(i = 0,iarr = 0; i < selects.length; i++) {
        selects[i].style.display = 'none';
    }
    // - End Gambiarra

    if (!$('bgBody')) {
        tagBody.insertBefore(bgBody, $('capa1'));
    // myLytebox.fade('bgBody',50);
    }
}

function fechar_promocao() {
    var tagBody = document.body;
    // - Gambiarra para corrigir problemas com o IE6
    var selects = document.getElementsByTagName('select');
    for(i = 0,iarr = 0; i < selects.length; i++) {
        selects[i].style.display = 'inline';
    }
    // - End Gambiarra
    tagBody.removeChild($('bgBody'));
    tagBody.removeChild($('promocaoarea'));
}

function div_promocao(duracao,lingua,id) {
    var sizesPage = myLytebox.getPageSize();

    var promocaoarea = document.createElement('div');
    promocaoarea.style.zindex = 2;
    promocaoarea.setAttribute('id', 'promocaoarea')
    promocaoarea.style.width = '615px';
    promocaoarea.style.height = '397px';
    promocaoarea.style.position = 'absolute';
    //promocaoarea.style.top = (sizesPage[1]/2 - 183) + 'px';
    //promocaoarea.style.left = (sizesPage[2]/2 - 213) + 'px';
    promocaoarea.style.top = '100px';
    promocaoarea.style.left = (sizesPage[2]/2 - 327) + 'px';

    var promocaoborda = document.createElement('div');
    promocaoborda.style.width = '615px';
    promocaoborda.style.height = '387px';
    promocaoborda.style.backgroundColor = 'white';
    promocaoborda.style.position = 'relative';
    promocaoborda.style.marginTop = '15px';
    promocaoborda.style.border = 'solid 4px #aaa';

    var promocao = document.createElement('div');
    promocao.style.width = '599px';
    promocao.style.height = '371px';
    promocao.style.backgroundColor = 'white';
    promocao.style.position = 'relative';
    promocao.style.marginTop = '8px';
    promocao.style.marginLeft = '8px';
    promocao.style.marginBottom = '8px';
    promocao.style.marginRight = '8px';
    promocao.className = 'texto_normal';
    
    if (lingua == 'PtBr') {
        promocaoarea.innerHTML = "<input style='width:150px;height:25px;margin-bottom:-15px;.margin-bottom:-9px;border:solid 2px red;' onclick=\"fechar_promocao();\" style=\"float:right;\" id=\"botao_fecharpromocao\" class=\"botao_menorvermelho\" onmouseover=\"this.className ='botao_menorvermelhofocus'\" onmouseout=\"this.className ='botao_menorvermelho'\" type=\"button\" value=\" FECHAR PROMOÇÃO (X) \">";
    }
    if (lingua == 'En') {
        promocaoarea.innerHTML = "<input style='width:150px;height:25px;margin-bottom:-15px;.margin-bottom:-9px;border:solid 2px red;' onclick=\"fechar_promocao();\" style=\"float:right;\" id=\"botao_fecharpromocao\" class=\"botao_menorvermelho\" onmouseover=\"this.className ='botao_menorvermelhofocus'\" onmouseout=\"this.className ='botao_menorvermelho'\" type=\"button\" value=\" CLOSE PROMOTION (X) \">";
    }
    if (lingua == 'Es') {
        promocaoarea.innerHTML = "<input style='width:150px;height:25px;margin-bottom:-15px;.margin-bottom:-9px;border:solid 2px red;' onclick=\"fechar_promocao();\" style=\"float:right;\" id=\"botao_fecharpromocao\" class=\"botao_menorvermelho\" onmouseover=\"this.className ='botao_menorvermelhofocus'\" onmouseout=\"this.className ='botao_menorvermelho'\" type=\"button\" value=\" CERRAR PROMOCIÓN (X) \">";
    }    

    var tagBody = document.body;
    tagBody.insertBefore(promocaoarea, $('capa1'));
    promocaoarea.appendChild(promocaoborda);

    promocaoarea.insertBefore($('botao_fecharpromocao'), promocaoborda);
    promocaoborda.appendChild(promocao);
    
    ajax('promocao.php','l='+lingua+'&id='+id,promocao);

    $('botao_fecharpromocao').onclick = function() {fechar_promocao();};
    if (duracao > 0) {
        setTimeout("fechar_promocao()",duracao);
    }
    promocao.ondblclick = function() {fechar_promocao()};
}

function ajax(url,parametros,alvo) {
    alvo.innerHTML = '<center><table><tr><td align="right" valign="middle"><img src="imagens/ajaxloader.gif"></td><td align="left" valign="middle" style="font:bold 8pt Arial;">Carregando...</td></tr></table></center>';
    var xmlHttpReq_ajax = false;
    var self_ajax = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self_ajax.xmlHttpReq_ajax = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self_ajax.xmlHttpReq_ajax = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self_ajax.xmlHttpReq_ajax.open('POST', url, true);
    self_ajax.xmlHttpReq_ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //self_ajax.xmlHttpReq_ajax.setRequestHeader("Content-Type", "text/html; charset=iso-8859-9");
    self_ajax.xmlHttpReq_ajax.onreadystatechange = function() {
        if (self_ajax.xmlHttpReq_ajax.readyState == 4) {
            alvo.innerHTML = self_ajax.xmlHttpReq_ajax.responseText;
        }
    }
    self_ajax.xmlHttpReq_ajax.send(parametros);
    
}

function hover_elemento(elemento) {
    elemento.style.backgroundColor = '#efefef';
}
function unhover_elemento(elemento) {
    elemento.style.backgroundColor = '#ffffff';
}
