﻿var baseUrl = location.href.substring(0,location.href.lastIndexOf("/")+1);
var aPagVisitadas = new Array();
var lingua = null;
var divAtual = 1;
var s1 = new SWFObject(baseUrl+"img/foto/flash/imagerotator.swf","rotator","570","320","7");
s1.addVariable("file",baseUrl+"img/foto/flash/image.xml&amp;linkfromdisplay=true&amp;shownavigation=false&amp;controlbar=none");
s1.addVariable("width","570");
s1.addVariable("height","320");
s1.addVariable("overstretch","true");
s1.addVariable("shownavigation","true");
s1.addVariable("linkfromdisplay","true");
s1.addVariable("allowfullscreen","true");


var topo = new SWFObject(baseUrl+"img/layout/topo.swf","rotator","1024","388","7");
topo.addVariable("width","1024");
topo.addVariable("height","388");
topo.addVariable("wmode","transparent");


var s2 = new SWFObject(baseUrl+"imagerotator.swf","rotator","170","260","7");
s2.addVariable("file",baseUrl+"topXML.php&amp;linkfromdisplay=true&amp;linktarget=_blank");
s2.addVariable("width","170");
s2.addVariable("height","260");
s2.addVariable("shownavigation","false");
s2.addVariable("overstretch","true");
s2.addVariable("allowfullscreen","false");
s2.addVariable("linkfromdisplay","true");
s2.addVariable("linktarget","_blank");

function mostraDivFoto(divNovo) {
    if (document.getElementById(divAtual) == null)  {
        divAtual = "1";
    }
    document.getElementById(divAtual).style.visibility = "hidden";
    document.getElementById(divNovo).style.visibility = "visible";
    divAtual = divNovo;
}

function documentLoaded() {
    if (document.getElementById("container") != null)  {
        s1.write("container");
    }
    if (document.getElementById("container2") != null)  {
        s2.write("container2");
    }
     if (document.getElementById("topo") != null)  {
        topo.write("topo");
    }
}

function chamaPopup() {
    alert("1");
    var player = document.getElementById("container2");  
    alert(player);
    var playlist = player.getPlaylist();
    alert(playlist);
    var item = player.getConfig().item;
    alert(item);
    window.open(playlist[item].link);
}

function fechaPopup() {
     divPopup = document.getElementById("popup");
     divPopup.style.visibility = "hidden";
}
function doAction(pagName) {
   if (pagName == "NO_LINK")  {
        alert("Aten��o n�o existe pagina para este link! ");
    } else if (pagName.indexOf("http") > -1) { 
        var w=screen.availWidth;
        var h=screen.availHeight;
        window.open(pagName,"nova","width="+w+",height="+h-45+",status=1,toolbar=1,resizable=1,directories=0,location=1,menubar=1","scrollbars=yes","resizable=yes",true);
    } else {
        document.location = baseUrl+"?id="+pagName;
    }
    if (document.getElementById("container") != null)  {
        s1.write("container");
    }
    if (document.getElementById("container2") != null)  {
        s2.write("container2");
    }
     if (document.getElementById("topo") != null)  {
        topo.write("topo");
    }
}
function doFormAction(htmlObj,action) {
    formActions[action](htmlObj);
}
function isEmpty(s) {
    if (s != null) s+="";
    return ((s == null) || (s.length == 0) || (s == replicate(" ",s.length)) || (s == "undefined"));
}
function submitForm(htmlObj) {
    var frm = htmlObj.form;
    var prmts = "";
    if (validaForm(frm)) {
        for (var n = 0; n < frm.elements.length; n++) {
            if (n > 0) {
                prmts += "&";
            }
            prmts += frm.elements[n].name;
            prmts += "=";
            prmts += escape(frm.elements[n].value);
        }
        prmts += "&action=enviar";
        var url = baseUrl+frm.action;
        var xmlResposta = _SpdtAJAX.getXML(url,prmts,"POST");
        var resultadoElm = _SpdtAJAX.getElement(xmlResposta,"resultado","http://www.supridatta.com.br/SITE")
        var msg = resultadoElm.firstChild.nodeValue;
        alert(msg);
        frm.reset();
    }
}
function validaForm(form) {
    var campo = null;
    var rtno  = true;
    for (var n = 0; n < form.elements.length; n++) {
        campo = form.elements[n];
        if (campo.type == "text" || campo.type == "textArea") {
            if (campo.value == "") {
                rtno = false;
            }
        }
    }
    if (!rtno)  {
        alert("Verifique se todos os campos est�o preenchidos");
    }
    return rtno;
}
function clearForm(htmlObj) {
    htmlObj.form.reset();
}
var formActions = new Object();
formActions["submit"] = submitForm;
formActions["clear"] = clearForm;

function voltar() {
    _SpdtSitePlayer.showPage(aPagVisitadas[aPagVisitadas.length - 2]);
    mostraData(lingua);
    aPagVisitadas.pop();
}
function mostraData() {
    var spanData = document.getElementById("data");
    var meses = new Array();
    meses = ["janeiro","fevereiro","marco","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"];
    var hoje = new Date();
    spanData.innerHTML = hoje.getDate()+" de "+meses[hoje.getMonth()]+" de "+hoje.getFullYear();         
    
}

function teste(posicao) {
    posicao = (posicao*1) - 1
    var image = document.getElementById("meio"+posicao);
    if (image != null)  {
        image.src = 'img/layout/invert.gif';
    }
}

function teste2(posicao) {
    var image = document.getElementById("meio"+posicao);
    if (image != null)  {
        image.src = 'img/layout/menuMeio.gif';
        posicao = (posicao*1) - 1  
    }
    var image2 = document.getElementById("meio"+posicao);
    if (image2 != null)  {
        image2.src = 'img/layout/menuMeio.gif';
    }
}
function selectChange() {
    doAction(document.frmCotacao.selCotacao.value);
}
function vz() {
}



var xmlhttp;

function busca() {
    var str = document.frmBusca.busca.value;
    if (str.length==0) {
      document.getElementById("tdConteudo").innerHTML="";
      document.getElementById("tdConteudo").style.border="0px";
      return;
    }
    xmlhttp=GetXmlHttpObject()
    if (xmlhttp==null) {
      alert ("Your browser does not support XML HTTP Request");
      return;
    }
    var url="search.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged ;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged() {
    if (xmlhttp.readyState==4) {
        document.getElementById("tdConteudo").innerHTML=xmlhttp.responseText;
        document.frmBusca.busca.value = "";
    }
}

function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}
function votarEnquete() {
     var data = new Date();
    var resposta = null;
    var itemElm  = null;
    var qtdeVotos = 0;
    var enqXML = _SpdtAJAX.getXML(baseUrl+"xml/enquete.xml?"+data.getTime());
    if (enqXML != null) {
        var inputRadio = document.frmEnquete.radEnquete;
        for(i=0; i < inputRadio.length; i++ ) {
        if (inputRadio[i].checked == true) 
            resposta = inputRadio[i].value;
        }
        if (resposta != null) {
            var enqueteElm = enqXML.getElementsByTagName("enquete")[0];
            itemElm  = _SpdtAJAX.getElement(enqueteElm,"item[@id='"+resposta+"']","http://www.supridatta.com.br/SITE");
            if (itemElm != null) {
                qtdeVotos = itemElm.firstChild.nodeValue*1;
                qtdeVotos++
                itemElm.firstChild.nodeValue = qtdeVotos;
                var url = baseUrl+"filebw/saveXML.php?xmlFile=enquete.xml";
                var xmlResposta = _SpdtAJAX.sendXML(url,enqXML);
                var resultadoElm = _SpdtAJAX.getElement(xmlResposta,"resultado","http://www.supridatta.com.br/SITE");
                alert("Voto Computado com Sucesso!");
                showResult(enqXML);
            }
        }
    }
}
function showResult(enqXML) {
    var qtdeTotal = 0;
    if (enqXML != null) {
        var enqueteElm = enqXML.getElementsByTagName("enquete")[0];
        var itensElm   = enqueteElm.getElementsByTagName("item");
        for (var n=0; n < itensElm.length; n++) {
            qtdeTotal+= itensElm[n].firstChild.nodeValue*1;
        }
        document.getElementById("tdConteudo").innerHTML="";
        document.getElementById("tdConteudo").style.border="0px"; 
        var html = '<table border="0" cellpadding="0" cellspacing="0" width="425">';
        html += '<tr>';
        html += '<td align="center">';
        html += ' <div style="position: relative; overflow: hidden">';
        html += '  <img src="img/foto/separador.png" border="0"/>';
        html += '  <span class="tituloSub" style="position: absolute; top: 2px; left: 30px;">';
        html += '    Resultados Enquete';
        html += '  </span>';
        html += ' </div>';
        html += '</td>';
        html += '</tr>';
        html += '<tr>';
             html += '<td align="center" class="conteudo">';
                html += enqueteElm.getElementsByTagName("pergunta")[0].firstChild.nodeValue;
             html += '</td>';
             html += '</tr>';
        for (var y=0; y < itensElm.length; y++) {
             html += '<tr>';
             html += '<td align="center" class="conteudo">';
                html += itensElm[y].getAttribute("caption")+" - "+fmtPercentual(((itensElm[y].firstChild.nodeValue*1)/qtdeTotal)*100);
             html += '</td>';
             html += '</tr>';
        } 
        html += '</table>';
        document.getElementById("tdConteudo").innerHTML = html;
    }
}
//http://selos.climatempo.com.br/selos/selo.php?CODCIDADE=268

function verTodas() {
    var noticias = _SpdtSitePlayer.siteXML.getElementsByTagName("page");
    var noticiaPage = _SpdtAJAX.getElement(_SpdtSitePlayer.siteXML,"page[@tipo='noticias']","http://www.supridatta.com.br/SITE");
    var contentElm = noticiaPage.getElementsByTagName("content")[0];
    var noticiElm = null
    var aNoticias = new Array();
    var contGrupo = 0;
    var cont = 0;
    var contGr = 1;
    var fechoTag = false;
    var xml = "";
    for (var n=0; n < noticias.length; n++) {
        noticiaElm     = noticias[n];
        if (noticiaElm.getAttribute("tipo") == "noticia") {
            aNoticias[aNoticias.length] = [noticiaElm.getAttribute("data"),noticiaElm.getAttribute("dataString"),noticiaElm.getAttribute("name"),noticiaElm.getAttribute("viewName")];
        }
    }
    aNoticias.sort();
    aNoticias.reverse();
    for (var n=0; n < aNoticias.length; n++) {
        noticiaElm = aNoticias[n];
        if (contGrupo == 0)  {
           xml += '<div id="'+contGr+'" style="align: left; position: absolute; visibility: hidden; width: 425;" align="left">';
           xml += '<table width="425">'
        }
        contGrupo++;
        xml += '<tr>';
        xml += '    <td align="center" width="30"> ';
        xml += '        <img src="img/layout/icoNoticia.png" border="0"/> ';
        xml += '    </td> ';
        xml += '    <td align="center" width="5"> ';
        xml += '        <img src="img/layout/spacer.gif"  width="5" border="0"/> ';
        xml += '    </td> ';
        xml += '    <td class="dataNoticia" align="center" width="70"> ';
        xml += aNoticias[n][1];
        xml += '    </td> ';
        xml += '     <td align="center" width="10"> ';
        xml += '        <img src="img/layout/spacer.gif"  width="10" border="0"/> ';
        xml += '    </td> ';
        xml += "    <td class='conteudoNormal' align='left'  onclick='javascript:doAction(\""+aNoticias[n][2]+"\")' style='cursor: pointer;' height='20'> ";
        xml += aNoticias[n][3];
        xml += '    </td> ';
        xml += '</tr> ';
        if (contGrupo == 20)  {
            xml += '</table>';
            xml += '</div>';
            contGrupo = 0;
            contGr++;
            fechoTag = true;
        }
    }
    if (!fechoTag)  {
       xml += '</table>';
            xml += '</div>';
    }
    var cab = '<table width="425">'
         cab += '<tr>';
         cab += '<td colspan="6">';
    for (var n=0 ; n < contGr; n++) {
         id = n+1
         
         cab += '<ll><a onClick="mostraDivFoto('+id+')" class="conteudo" style="cursor: pointer;">'+id+'</a></ll>|';
         
    }
    cab += '</td>';
        cab += '</tr>';
        cab += '<tr>';
         cab += '<td width="425" align="left">';
         cab +=  xml;
         cab += '</td>';
        cab += '</tr>';
        cab += '</table>'
    document.getElementById("tdConteudo").innerHTML= cab;
      document.getElementById("tdConteudo").style.border="0px";
      mostraDivFoto(1);
    
}
function sortNumber(a,b) {
    return a < b;
}

