//**********************************************************************************************
// Verifica o Navegador que esta sendo utilizado.
//**********************************************************************************************
var isMozilla = navigator.userAgent.indexOf('Mozilla') != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;
var isIE = navigator.userAgent.indexOf('MSIE') != -1;
var select_focus = 1;
var separaDWEB = '@$@';
var jCarregando;


// FUNCOES NECESSARIAS PARA A MONTAGEM DO MENU DO TOPO
// ---------------------------------------------------
                        function selectListItem(id, topic) {
                                var menu = document.getElementById(id);
                                var elements = menu.getElementsByTagName('*');
                                var ancestor;
                                for (var i=0; i<elements.length; i++) {
                                        if (elements[i].nodeType == 1 && elements[i].title == topic) {
                                                if (elements[i].nodeName == 'A') {
                                                        elements[i].className = 'selected';
                                                } else {
                                                        ancestor = elements[i];
                                                        while (ancestor.nodeName != 'LI') { ancestor = ancestor.parentNode }
                                                        ancestor.className = 'selected';
                                                }
                                        }
                                }
                        }

                        sfHover = function() {
                                var sfEls = document.getElementById("menu").getElementsByTagName("LI");
                                for (var i=0; i<sfEls.length; i++) {
                                        sfEls[i].onmouseover=function() {
                                                this.className+=" sfhover";
                                        }
                                        sfEls[i].onmouseout=function() {
                                                this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                                        }
                                }
                        }
                        if (window.attachEvent) window.attachEvent("onload", sfHover);
                        // centerpiece tabs
                        function tab_select(self) {
                                if (self.id == "ria") {
                                        document.getElementById("centerpiece").style.backgroundPosition = "0 0";
                                        document.getElementById("ria-tab").style.display = "block";
                                        document.getElementById("enterprise-tab").style.display = "none";
                                        document.getElementById("consulting-tab").style.display = "none";
                                }
                                if (self.id == "enterprise") {
                                        document.getElementById("centerpiece").style.backgroundPosition = "0 -400px";
                                        document.getElementById("ria-tab").style.display = "none";
                                        document.getElementById("enterprise-tab").style.display = "block";
                                        document.getElementById("consulting-tab").style.display = "none";
                                }
                                if (self.id == "consulting") {
                                        document.getElementById("centerpiece").style.backgroundPosition = "0 -800px";
                                        document.getElementById("ria-tab").style.display = "none";
                                        document.getElementById("enterprise-tab").style.display = "none";
                                        document.getElementById("consulting-tab").style.display = "block";
                                }
                        }
// ---------------------------------------------------



// ---------------------------------------------------
// Funcoes para montar a imagem grande quando clicado sobre o link
// ---------------------------------------------------

     function pesquisar()
       {
         try{
           if (document.getElementById('edit_pesquisar').value != ''){
            document.frm.action = 'pesquisar.php?site=1';
            document.frm.target = '_self';            
            document.frm.submit();
           }
         }
         catch(e){
           alert(e);
         }
       }

     function topoPagina()
       {
         window.document.body.scrollTop = 300;
       }

     var arrNameImage   = new Array();
     var arrTituloImage = new Array();
     var htmlRodape     = '';
     var indiceFoto     = 0;

     function img_grande(obj)
       {
          topoPagina();
          try{
            cria_div_transparente('#3F3F3F', 300,300);
          }
          catch(e){
            alert(e.message)
          }

          for (var str in arrNameImage)
            arrNameImage[str] = '';

          var images = document.getElementsByTagName('td');
          var iTotal = images.length;

          htmlRodape  = "<table cellpading='0' cellspacing='0'>";
          htmlRodape += "  <tr style='background-color:#EEEEEE'><td></td>";

          var x = 0;
          for(var i = 0; i < iTotal; i++)
            {
              if (images[i].getAttribute('tipo') == 'imgdemonstracao')
                {
                  x++;
                  if (images[i].getAttribute('imgname'))
                    arrNameImage[x] = images[i].getAttribute('imgname');
                  if (images[i].getAttribute('imgproduto'))
                    arrTituloImage[x] = images[i].getAttribute('imgproduto');
                }
            }

          for (var str in arrNameImage)
            if (obj.getAttribute('imgname') == arrNameImage[str])
              indiceFoto = str;

          htmlRodape += "  <td bgcolor='#EEEEEE' height='30' align='right' ><img src='admin/images/seta_esquerda.gif' border='0' onClick='nextIndice(0)' style='cursor:pointer'></td>";
          htmlRodape += "  <td bgcolor='#EEEEEE' align='center' width='60' id='tdIndiceImg' class='texto11'>"+indiceFoto+" de "+x+"</td>";
          htmlRodape += "  <td bgcolor='#EEEEEE' >&nbsp;<img src='admin/images/seta_direita.gif' border='0' onClick='nextIndice(1)' style='cursor:pointer'></td>";
          htmlRodape += "  <td></td></tr>";
          htmlRodape += "</table>";

          var html  = "<table width='100%' cellpading='0' cellspacing='0' style='border:1px #999999 solid' bgcolor='#EEEEEE'>";
              html += "  <tr>";
              html += "    <td style='background:#EEEEEE;padding:1px'>";
              html += "      <table width='100%' cellpading='0' cellspacing='0'>";
              html += "        <tr>";
              html += "          <td id='tdDivTitulo' class='texto12' style='height:25;background:#EEEEEE;padding:5px'>...</td>";
              html += "          <td width='1%' align='center'> <img src='admin/images/fechar.gif' border='0' onClick='deleteDivTrans()' title='Fechar' Style='cursor:pointer'> </td>";
              html += "          <td width='1%'></td>";
              html += "        </tr>";
              html += "      </table>";
              html += "  </tr>";
              html += "  <tr>";
              html += "    <td style='cursor:pointer;padding:5px;text-align:center' onClick='deleteDivTrans()'>";
              html += "      <div style='width:100%;height:100%' id='div_img_sequencial'></div>";
              html += "    </td>";
              html += "  </tr>";
              html += "  <tr>";
              html += "    <td valign='top' align='center'>"+htmlRodape+"</td>";
              html += "  </tr>";
              html += "</table>";
          document.getElementById('divTransNewImages').innerHTML = html;

          var td = document.getElementById('tdDivTitulo');
          td.style.cursor = 'move';
          Drag.init(td, document.getElementById('divTransNewImages'));
          nextImage(indiceFoto);
       }

     function nextImage(numero)
       {
         var x = 0;
         for (var str in arrNameImage)
           if (arrNameImage[str] != '')
             x++;

         if (document.getElementById('tdIndiceImg'))
           document.getElementById('tdIndiceImg').innerHTML = numero + ' de ' + x;

         try{
           if (document.getElementById('tdDivTitulo'))
             document.getElementById('tdDivTitulo').innerHTML = '<B>'+arrTituloImage[numero]+'</b>';
         }
         catch(e){
           try{
             if (document.getElementById('tdDivTitulo'))
               document.getElementById('tdDivTitulo').innerHTML = '<B>Imagens</b>';
           }
           catch(err){
             alert(err.message)
           }
         }

        try{
          document.frm.action = "ajax_processa.php?acao=next_image&img="+arrNameImage[numero];
          ajaxForm('div_img_sequencial','frm')
        }
        catch(err){
          alert(err.message)
        }
       }

   function nextIndice(posicao)
     {
       if (posicao == '1'){//frente
         indiceFoto++;
         if ((arrNameImage[indiceFoto] == '') || (arrNameImage[indiceFoto] == undefined) || (arrNameImage[indiceFoto] == 'undefined'))
          indiceFoto = 1;
       }
       else{
         indiceFoto--;
         if ((arrNameImage[indiceFoto] == '') || (arrNameImage[indiceFoto] == undefined) || (arrNameImage[indiceFoto] == 'undefined'))
          indiceFoto = (parseInt(arrNameImage.length) - 1);
       }
       nextImage(indiceFoto);
     }

function cria_div_transparente(cor,top,left)
{
  if ((cor == '')||(cor == 'undefined')||(cor == undefined)||(cor == null))
    cor = '#C0C0C0';

  if(!document.getElementById('bgBody'))
    {
      div = document.createElement('div');
      div.style.position ='absolute';
      div.style.top = '0';
      div.style.left = '0';
      div.style.filter= 'progid:DXImageTransform.Microsoft.Alpha(opacity:70)';
      div.style.opacity='0.70';
      div.style.backgroundColor = cor;
      div.style.width = '100%';
      div.style.height = document.body.scrollHeight;// '100%';
      div.style.zIndex = '99';
      div.setAttribute('id','bgBody');
      div.ondbclick  = function()
        {
          document.body.removeChild(this);
        }
      document.body.appendChild(div);

      var d = document;
      if (isIE)
        {
          iframe = d.createElement('iframe');
          iframe.src = '';
          iframe.frameBorder = '0';
          iframe.style.width = window.document.body.scrollWidth+'px';
          iframe.style.height = window.document.body.scrollHeight+'px';
          iframe.style.filter = 'alpha(opacity:0)';
          iframe.style.position = 'absolute';
          iframe.style.top = '0px';
          iframe.style.left = '0px';
          iframe.id = 'ifrTrans';
          iframe.ondbclick  = function()
            {
              document.removeChild(this);
            }
          d.body.appendChild(iframe);
       }

      div = d.createElement('div');
      div.style.position = 'absolute';
      div.style.zIndex = '100';
      div.style.width= '150';
      div.style.top = top;
      div.style.left= left;
      div.style.backgroundColor = cor;
      div.setAttribute('id','divTransNewImages');
      div.innerHTML = 'Aguarde Carregando ...';
      d.body.appendChild(div);

    }
}

function deleteDivTrans()
  {
     try{
        if (document.getElementById('bgBody'))
          document.body.removeChild(document.getElementById('bgBody'));

        if (document.getElementById('ifrTrans'))
          document.body.removeChild(document.getElementById('ifrTrans'));

        if (document.getElementById('divTransNewImages'))
          document.body.removeChild(document.getElementById('divTransNewImages'));

     }
     catch(err){
       alert(err.message)
     }
  }

// ---------------------------------------------------


// ---------------------------------------------------
// FUNCOES GENERICAS
// ---------------------------------------------------
function noticias(codigo, grupo)
 {
    //cicloturismo noticias ou roteiros
    if ((grupo.toString() == '5') || (grupo.toString() == '6'))
      var link = END_VIRTUAL+'cicloturismo.php?site=1&id='+codigo;
    else
      var link = END_VIRTUAL+'noticias.php?site=1&id='+codigo;
    window.open(link,'_self');
 }
function menu(obj)
 {
   if (typeof(obj) == 'string')
     {
       if (obj == 'home'){
         window.open(END_VIRTUAL,'_self');
       }
       else if (obj == 'noticias'){
         var link = END_VIRTUAL+'noticias.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'alimentacao'){
         var link = END_VIRTUAL+'alimentacao.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'esportes'){
         var link = END_VIRTUAL+'esportes.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'como_chegar'){
         var link = END_VIRTUAL+'como_chegar.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'contatos'){
         var link = END_VIRTUAL+'contatos.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'videos'){
         var link = END_VIRTUAL+'videos.php?site=1';
         window.open(link,'_self');
       }
       else if (obj == 'cicloturismo'){
         var link = END_VIRTUAL+'cicloturismo.php?site=1';
         window.open(link,'_self');
       }

//       document.frm.submit();
     }
   else if (typeof(obj) == 'object')
     {
        alert('objeto')
     }

  // alert(obj);
 }