function centraliza(largura, altura) {
    window.moveTo((window.screen.width - largura) / 2, (window.screen.height - altura) / 2);
}

function abreJanela(arquivo, nome, barra, largura, altura) {
    window.open(arquivo, nome, "resizable=no,toolbar=no,status=no,menubar=no,scrollbars=" + barra + ",width=" + largura + ",height=" + altura);
}

function redimenciona() {
    var i = 0;
    function resize() {
        if (navigator.appName == 'Netscape') i = 40;
        if (document.images[0]) window.resizeTo(document.images[0].width + 50, document.images[0].height + 80 - i);
        if (window.moveTo((window.screen.width - document.images[0].width) / 2, (window.screen.height - document.images[0].height) / 2));
    }
}

function montaSWF(arquivo, largura, altura, action) {

    var now = new Date();
    var dia = now.getDay();
    var mes = now.getMonth();
    var ano = now.getFullYear();
    var hora = now.getHours();
    var mintuto = now.getMinutes();
    var segundo = now.getSeconds();
    var data = ano + "" + mes + "" + dia + "" + hora;

    //alert ("Esta é uma caixa de diálogo ALERT do JavaScript!")

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
    document.write('<param name="movie" value="/swf/' + arquivo + '.swf?ieSux=' + data + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<param name="FlashVars" value="' + action + '&clearCache=' + data + '" />');
    document.write('<embed FlashVars="' + action + '&clearCache=' + data + '" wmode="transparent" menu="false" src="/swf/' + arquivo + '.swf?ieSux=' + data + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
    document.write('</object>');
}

function montaJogo(arquivo, largura, altura, action) {
    var now = new Date();
    var dia = now.getDay();
    var mes = now.getMonth();
    var ano = now.getFullYear();
    var hora = now.getHours();
    var mintuto = now.getMinutes();
    var segundo = now.getSeconds();
    var data = ano + "" + mes + "" + dia + "" + hora;

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
    document.write('<param name="movie" value="/jogo/' + arquivo + '/root.swf?ieSux=' + data + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<param name="FlashVars" value="' + action + '&clearCache=' + data + '" />');
    document.write('<embed FlashVars="' + action + '&clearCache=' + data + '" wmode="transparent" menu="false" src="/jogo/' + arquivo + '/root.swf?ieSux=' + data + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
    document.write('</object>');
}

function montaRanking(arquivo, largura, altura, action) {

    var now = new Date();
    var dia = now.getDay();
    var mes = now.getMonth();
    var ano = now.getFullYear();
    var hora = now.getHours();
    var mintuto = now.getMinutes();
    var segundo = now.getSeconds();
    var data = ano + "" + mes + "" + dia + "" + hora;

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
    document.write('<param name="movie" value="/jogo/' + arquivo + '.swf?ieSux=' + data + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<param name="FlashVars" value="' + action + '&clearCache=' + data + '" />');
    document.write('<embed FlashVars="' + action + '&clearCache=' + data + '" wmode="transparent" menu="false" src="/jogo/' + arquivo + '.swf?ieSux=' + data + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
    document.write('</object>');
}

function videoSWF(arquivo, largura, altura, action) {
    var now = new Date();
    var dia = now.getDay();
    var mes = now.getMonth();
    var ano = now.getFullYear();
    var hora = now.getHours();
    var mintuto = now.getMinutes();
    var segundo = now.getSeconds();
    var data = ano + "" + mes + "" + dia + "" + hora;

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
    document.write('<param name="movie" value="http://www.opee.com.br/video/' + arquivo + '.swf?ieSux=' + data + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name="wmode" value="transparent" />');
    document.write('<param name="FlashVars" value="' + action + '&clearCache=' + data + '" />');
    document.write('<embed FlashVars="' + action + '&clearCache=' + data + '" wmode="transparent" menu="false" src="http://www.opee.com.br/video/' + arquivo + '.swf?ieSux=' + data + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
    document.write('</object>');
}

// PAPP
function papp(img, n, i) {
    for (var x = 1; x <= 4; x++) {
        if (x != i)
            document.getElementById("img_" + n + "_" + x).src = '/img/global/bt/b' + x + '.jpg';
    }

    if (parseInt(img.src.lastIndexOf("b" + i + ".jpg")) > 0) {
        img.src = "/img/global/bt/c" + i + ".jpg";
        document.getElementById("hidPapp" + n).value = i;
    }
    else {
        img.src = "/img/global/bt/b" + i + ".jpg";
        document.getElementById("hidPapp" + n).value = 0;
    }
}

function preenche_papp(i, valor) {
    for (var x = 1; x <= 4; x++) {
        if (x != valor)
            document.getElementById("img_" + i + "_" + x).src = '/img/global/bt/b' + x + '.jpg';
    }

    img = document.getElementById("img_" + i + "_" + valor);
    img.src = "/img/global/bt/c" + valor + ".jpg";
    document.getElementById("hidPapp" + i).value = valor;
}

// JScript File
var ie = (((navigator.userAgent.indexOf("MSIE") > -1) || (navigator.userAgent.indexOf("Mozilla/5.0") > -1)) && navigator.userAgent.indexOf("Opera") == -1 ? true : false);
var ns = (navigator.userAgent.indexOf("Netscape") > -1 && navigator.userAgent.indexOf("Opera") == -1 ? true : false);

// AJUSTAR CEP
function testeBol(input, evento, valor) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }

    var key = false;
    var valores = valor.split(',');

    for (var i = 0; i < valores.length; i++) {
        //if (tecla != 83 && tecla != 82 && tecla != 78 && tecla != 114 && tecla != 110 && tecla != 115) {
        if (tecla == valores[i]) {
            key = true;
            break;
        }
    }

    evento.returnValue = key;
    return key;
}

function ucase(input) {
    input.value = input.value.toUpperCase();
}

function checado(c, valor, view) {
    var input = document.getElementsByName(c);
    var valores = valor.split(',');

    for (var i = 0; i < input.length; i++) {
        if (valores.contains(input[i].value))
            input[i].checked = 'checked';
        if (!view)
            input[i].disabled = 'disabled';
    }
}

Array.prototype.contains = function(element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element)
            return true;
    }
    return false;
}

function lembrarSenha() {
    var d = document.getElementById('dvEsqueci');
    if (d.style.display == 'none')
        d.style.display = '';
    else
        d.style.display = 'none';

    return false;
}

function faleConosco(n) {
    var d = document.getElementById("ctl00_conteudo_txtOutros");
    d.value = '';
    switch (n) {
        case "conteudo":
            d.style.display = 'none';
            break;
        case "senha":
            d.style.display = 'none';
            break;
        case "outro":
            d.style.display = '';
            break;
    }
}

function enviarOficina() {
    var d = document.getElementById("tblEmail");
    if (d.style.display == '')
        d.style.display = 'none';
    else
        d.style.display = '';

    return false;
}

// TESTES
function authentic_test(id, campo, input, grupo) {
    document.getElementById("fixme").style.display = '';
    if (!input.value.match(/^([0-9]|10)$/)) {
        alert(unescape('Valor inv%E1lido.'));
        input.value = "";
        input.focus();
        return;
    }
    doRequest('../server.aspx?query=teste&teste=' + id + '&campo=' + campo + '&valor=' + input.value + '&grupo=' + grupo, response_test);
}

function response_test(f) {
    document.getElementById("fixme").style.display = 'none';
}

function showPopUpWindow(page, obj, winW, winH, modal, windowTitle, winTop, winLeft, maxAble, closeAble, id) {
    windowTitle = windowTitle.replace("&amp;#39", "'");
    if (maxAble == null) {
        maxAble = true;
    }
    if (closeAble == null) {
        closeAble = true;
    }

    win1 = new Window('1', { className: "greylighting", title: windowTitle, width: winW, height: winH, maximizable: maxAble, minimizable: false, closable: closeAble });
    win1.setZIndex(4);
    win1.setURL(page + ".aspx?uid=" + id);
    win1.showCenter(modal);
    win1.setDestroyOnClose();
}

// AJUSTAR CEP
function ajustar_cep(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 5) {
            input.value += "-";
        }
    }
    return true;
}

// AJUSTAR CPF
function ajustar_cpf(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 3 || input.value.length == 7)
            input.value += ".";
        if (input.value.length == 11)
            input.value += "-";
    }
    return true;
}

var key = true;

function papp_amigo(img) {
    if (eval(key)) {
        key = false;
        img.src = '../img/global/bt/papp-ocultar.jpg';
        document.getElementById("papp_amigo").style.display = '';
    }
    else {
        key = true;
        img.src = '../img/global/bt/papp-visualizar.jpg';
        document.getElementById("papp_amigo").style.display = 'none';
    }
}

function excluir_amigo(i) {
    window.location.href = 'papp-amigo-excluir.aspx?IDPappConvite=' + i;
}

function expandir(n) {
    if (n != 1) document.getElementById("ul1").style.display = 'none';
    if (n != 2) document.getElementById("ul2").style.display = 'none';
    if (n != 3) document.getElementById("ul3").style.display = 'none';
    if (n != 4) document.getElementById("ul4").style.display = 'none';
    if (n != 5) document.getElementById("ul5").style.display = 'none';
    if (n != 6) document.getElementById("ul6").style.display = 'none';

    if (document.getElementById("ul" + n).style.display == 'none')
        document.getElementById("ul" + n).style.display = '';
    else
        document.getElementById("ul" + n).style.display = 'none';

    return false;
}

function viewer(n) {
    if (document.getElementById('u' + n).style.display == 'none')
        document.getElementById('u' + n).style.display = '';
    else
        document.getElementById('u' + n).style.display = 'none';
}

function senha() {
    var msg = prompt('Preencha seu e-mail:');
    if (msg != null) {
        doRequest('server.aspx?query=senha&email=' + msg, senha_retorno);
    }
}

function senha_retorno(f) {
    alert(f);
}
