/*
 * Copyright(c) 2000 PROCERGS Direto. Todos os direitos reservados.
 * 
 * Este programa é licenciado de acordo com a L.P.G. - P.C. (Licença Pública 
 *   Genérica para Programas de Computador), versão 1.6 ou qualquer versão 
 *   posterior.
 * 
 * A L.P.G. - P.C. deve acompanhar todas PUBLICAÇÕES, DISTRIBUIÇÕES e 
 *   REPRODUÇÕES deste Programa.
 * 
 * A L.P.G. - P.C. também está disponível em: Licença: http://www.lpg.adv.br/lpgpc.rtf
 * Assinatura digital: http://www.lpg.adv.br/lpgpc.rtf.sig
 * Chave pública do advogado responsável pela licença: http://www.lpg.adv.br/pcc.asc
 * 
 * Para poder USAR, PUBLICAR, DISTRIBUIR, REPRODUZIR ou ALTERAR este Programa é 
 *   preciso estar de acordo com os termos da L.P.G. - P.C., adicionada das 
 *   seguintes condições especiais:
 * 
 *   a) Qualquer modificação, mesmo que para simples USO, deve ser notificada à 
 *      PROCERGS, para permitir a evolução do software. A redistribuição do 
 *      código modificado sem notificação anterior não é permitida de nenhuma 
 *      forma.
 * 
 *   b) Produtos derivados e material de divulgação devem conter o seguintes 
 *      texto: "Este produto inclui o software Direto(www.direto.org.br), 
 *      desenvolvido pela PROCERGS (www.procergs.com.br).".
 * 
 *   c) Os nomes "Direto" e "PROCERGS" não devem ser utilizados para endossar ou 
 *      promover produtos derivados deste software sem autorização da PROCERGS.
 */ 
var NS6 = (!document.all && document.getElementById) ? true : false;
var IE = (document.all)? true : false;
//if (NS6)
//   document.all = document.getElementsByTagName("*");


function findObj(n, d)
{
  var p,i,x;
  if (!d)
     d=document;
  if ((p=n.indexOf("?"))>0 && parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if (!(x=d[n]) && d.all)
     x=d.all[n];
  for (i=0; !x && i<d.forms.length; i++)
     x=d.forms[i][n];
  for (i=0; !x && d.layers && i<d.layers.length; i++)
      x=findObj(n,d.layers[i].document);
  if (!x && d.getElementById)
     x=d.getElementById(n);
  return x;
}

 function setCookie(key, value, expire) {
	document.cookie = key + "=" + escape(value) + ((expire == null) ? "" : (";    	expires=" + expire.toGMTString()))
 }

 function getCookie(key) {
    var search = key + "=";
    if (document.cookie.length > 0) {
  	   offset = document.cookie.indexOf(search) ;
          if (offset != -1) {
            offset += search.length ;
            end = document.cookie.indexOf(";", offset);
            if (end == -1)  end = document.cookie.length;
            return unescape(document.cookie.substring(offset, end));
    	    }
	  }
 }
 /** A logica desta funcao esta invertida, retornando false quando o ENTER for pressionado*/
 function keyPress(event) {
    if (!document.layers) {
			tecla = event.which==null? event.keyCode :event.which ;
      if (tecla == 13) return false;
    }
		return true;
}

function waitMessage(doc, message, backgroundColor,fontColor)
{
   if(!IE) return;

   if (doc.body != null)
   {
     doc.body.scroll = "no";
	  if(backgroundColor==null) backgroundColor = "#FFFFFF";
	  if(fontColor==null) fontColor = "#FF0000";
      var altura = doc.body.clientHeight;
      if (doc.body.scrollHeight > altura)
      {
         altura = doc.body.scrollHeight;
         doc.body.scrollTop = 0;
      }
      var largura = doc.body.clientWidth;
      if (doc.body.scrollWidth > largura)
      {
         largura = doc.body.scrollWidth;
         doc.body.scrollLeft = 0;
      }
      if (IE)
         for (i=0; i<doc.forms.length; i++)
            for (j=0; j<doc.forms[i].elements.length; j++)
               if (doc.forms[i].elements[j].tagName == 'SELECT')
               {
                  doc.forms[i].elements[j].style.widthX = doc.forms[i].elements[j].style.width;
                  doc.forms[i].elements[j].style.width = '0px';
               }
      if (IE)
         doc.body.insertAdjacentHTML("afterBegin", "<div id='waitMoment' style='position:absolute; text-align: center; font-size: 12px; color:"+fontColor+"; background-color:"+backgroundColor+"; left:0; top:0; width: " + largura + "; height: " + altura + "; z-index:10000;'><br>" + message + "</div>");
      else
         doc.body.innerHTML += "<div id='waitMoment' style='position:absolute; text-align: center; font-size: 12px; color:"+fontColor+"; background-color:"+backgroundColor+"; left:0; top:0; width: " + largura + "; height: " + altura + "; z-index:10000;'><br>" + message + "</div>";
   }
}

function setCursor(obj, link)
{
   if (link)
   {
      if (NS6)
         obj.style.cursor = 'pointer';
      else
         obj.style.cursor = 'hand';
   }
   else
      obj.style.cursor = '';
}

var viewSelect = true;
function showSelect()
{
   setTimeout('showSelectJan();', 1);
}
function showSelectJan()
{
   if (IE)
   {
      if (!viewSelect)
      {
         for (i=0; i<document.forms.length;i++)
            for (j=0; j<document.forms[i].elements.length; j++)
               if (document.forms[i].elements[j].tagName == 'SELECT')
               {
               document.forms[i].elements[j].style.width = document.forms[i].elements[j].style.widthX;
               viewSelect = true;
            }
      }
   }
}

function hideSelect()
{
   setTimeout('hideSelectJan();', 1);
}
function hideSelectJan()
{
   if (IE)
   {
      if (viewSelect)
      {
         for (i=0; i<document.forms.length; i++)
            for (j=0; j<document.forms[i].elements.length; j++)
               if (document.forms[i].elements[j].tagName == 'SELECT')
               {
               document.forms[i].elements[j].style.widthX = document.forms[i].elements[j].style.width;
               document.forms[i].elements[j].style.width = '0px';
               viewSelect = false;
            }
      }
   }
}

function lineOver(line)
{
   if (line.style.origBackgroundColor == null)
      line.style.origBackgroundColor = line.style.backgroundColor;
   line.style.backgroundColor = '#D1D1D1';
}
function lineOut(line)
{
   if (line.style.origBackgroundColor != null)
      line.style.backgroundColor = line.style.origBackgroundColor;
}
function selectCheck(obj, met)
{
   var sel = obj.checked;
   while (obj.tagName != "TR")
      if (IE)
         obj = obj.parentElement;
      else
         obj = obj.parentNode;
   if (sel)
      obj.style.fontWeight = "bold";
   else
      obj.style.fontWeight = "";

   if (IE && (met != null))
      stopEvent(window.event);
   else if (!IE && (met != null))
      stopEvent(met);
}

function changeValue(obj)
{
   obj.checked = !obj.checked;
   selectCheck(obj);
}

function stopEvent(ev)
{
   if (IE)
      ev.cancelBubble = true;
   else
      ev.stopPropagation();
}

String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

if ((document != null) && (document.onclick == null) && (top.hideMenus != null))
   document.onclick = top.hideMenus;

function ehDoEstado()
{
	var loc = location.hostname;
	return(loc.indexOf(".rs.gov.br") != -1 || loc.indexOf("hanoi") == 0);
}


