/*<![CDATA[*/
// ################################
// FUNÇÕES - MÓDULO NOTÍCIA
// ################################
function printThis()
{
      var winl = (screen.width - 550)/2;
      var wint = (screen.height - 450)/2;
      if (winl < 0) winl = 0;
      if (wint < 0) wint = 0;

      if (!document.all)
          var attributes = 'width=550, height=450, scrollbars=yes';
      else
          var attributes = 'width=550, height=450, scrollbars=yes';

      attributes += ", top=" + wint + ", left=" + winl;
      window.open(urlPrint, 'noticiaPrint', attributes);
};

function increase_font()
{
    var noticia_corpo = document.getElementById('noticia_corpo');

    switch ( noticia_corpo.style.fontSize )
    {
        case '':
            noticia_corpo.style.fontSize = '12px';
            break;
        case '12px':
            noticia_corpo.style.fontSize = '13px';
            break;
        case '13px':
            noticia_corpo.style.fontSize = '15px';
            break;
        case '15px':
            noticia_corpo.style.fontSize = '17px';
            break;
    };
};

function decrease_font()
{
    var noticia_corpo = document.getElementById('noticia_corpo');

    switch ( noticia_corpo.style.fontSize )
    {
        case '17px':
            noticia_corpo.style.fontSize = '15px';
            break;
        case '15px':
            noticia_corpo.style.fontSize = '13px';
            break;
        case '13px':
            noticia_corpo.style.fontSize = '12px';
            break;
    };
};

function getFriend() {
      var width = 428
      var height = 330
      var url_friend = urlBase + '/alterosa/modulos/envieamigo/portlet_envieamigo?url=' + escape(window.location.href) + '&titulo=' + document.getElementById('noticia_titulo').innerHTML
      var winl = (screen.width - width)/2;
      var wint = (screen.height - height)/2;
      if (winl < 0) winl = 0;
      if (wint < 0) wint = 0;

      var attributes = 'width=' + width + ', height=' + height + ', scrollbars=yes';

      attributes += ", top=" + wint + ", left=" + winl;
      window.open(url_friend, 'envieAmigo', attributes);
}

// ################################
// FUNÇÕES - MÓDULO GALERIA
// ################################
function openGalery(id_galeria) {
    var largura = 700;
    var altura = 590;

    var left=(window.screen.width/2)-(largura/2);
    var top = (window.screen.height/2)-(altura/2);
    var new_window = window.open(urlBase + '/alterosa/modulos/galeriadefotos/portlets/galeria_popup?id_galeria=' + id_galeria, "galeriadefotos",'resizable=no,width='+largura+',height='+altura+', left='+ left +', top='+ top +',toolbars=0,menubar=0,status=0,scrollbars=0');
    new_window.focus(); 
};

// ################################
// FUNÇÕES - MÓDULO ENQUETE
// ################################
function openEnquete() {
    var largura = 200;
    var altura = 280;

    var left=(window.screen.width/2)-(largura/2);
    var top = (window.screen.height/2)-(altura/2);
    var new_window = window.open(urlBase + '/alterosa/modulos/enquete/portlets/enquete_popup?id_enquete=' + id_enquete, "enquete",'resizable=no,width='+largura+',height='+altura+', left='+ left +', top='+ top +',toolbars=0,menubar=0,status=0,scrollbars=0');
    new_window.focus();
}

function showParcial() {
    document.getElementById('voto').style.display = 'none';
    document.getElementById('parcial').style.display = 'block';
};

function votar() {
    var sv = document.getElementById('voto').style.display;
    if (sv == 'none')
    {
        document.getElementById('voto').style.display = 'block';
        document.getElementById('parcial').style.display = 'none';
    } else {
        var frm  = document.forms['enquete'];
        var inp = document.getElementsByTagName('input');
        var check = false;
        var choose = null;
        for (var i=0; i < inp.length; i++) {
            if (inp[i].type == 'radio' && inp[i].checked) {
                check = true;
                choose = inp[i].value;
            }
        }
        if (check == false) {
            alert('É necessário escolher uma resposta.');
        } else {
            var oBtVoltar = document.getElementById('btVotar')
            var handler = new XMLHandler();
            /**  função python **/
            var xmlreq = new XMLClient(urlEstatica + 'webs/modulos/enquete/addVoto');
            /** parâmetros da função python **/
            xmlreq.addParam('id_enquete', frm.id_enquete.value);
            xmlreq.addParam('id_resultado', choose);
            handler.onError = function (e) {
                alert('Ocorreu um erro inesperado, tente novamente.')
            }
            handler.onProgress = function () {};
            handler.onInit = function () { 
                disableForm('enquete', 'disabled')
                oBtVoltar.style.display = 'none'
            }
            handler.onLoad = function (xmlStr) {
                var parser = new XMLParser();
                var xmlobj = parser.parseString(xmlStr);
                var rootnd = xmlobj.documentElement;
                for (var i = 0; i < rootnd.childNodes.length; i++) {
                    // Sucesso
                    if (rootnd.childNodes[i].tagName == 'ok') {
                        result = rootnd.childNodes[i].firstChild.nodeValue
                        if(parseInt(result) == 0) {
                            alert('Voto computado com sucesso!')
                        } else {
                            alert('Você já votou nesta enquete!')
                        }
                        break;
                    }
                    // Erro
                    if (rootnd.childNodes[i].tagName == 'erros') {
                        erros = rootnd.getElementsByTagName('erro')
                        alert(unescape(erros[i].firstChild.nodeValue))
                    }
                }
                document.getElementById('voto').style.display = 'none';
                document.getElementById('parcial').style.display = 'block';
                oBtVoltar.style.display = 'block'    
                disableForm('enquete', '')
            }
            xmlreq.query(handler);
        }
    }
}

function disableForm(sName, sDisabled) {
    oForm = document.forms[sName]
    for(var i=0; i<oForm.elements.length; i++) {
        oForm.elements[i].disabled = sDisabled    
    }
}

// ################################
// FUNÇÕES - MÓDULO FÓRUM
// ################################
function showforum() {
    var largura = 618;
    var altura = 448;
    var left=(window.screen.width/2)-(largura/2);
    var top = (window.screen.height/2)-(altura/2);

    var url_forum = urlBase + '/alterosa/modulos/forum/portlets/forum_show';
    if(id_forum) { url_forum += '?id_tema=' + id_forum }

    if(document.all) {
        var attributes = 'width=618, height=348, scrollbars=yes,left='+ left +',top='+ top;
    } else {
        var attributes = 'width=602, height=342, scrollbars=yes,left='+ left +',top='+ top;
    }

    var new_window = window.open(url_forum, 'forum', attributes);
    new_window.focus(); 
};

/*]]>*/
