/*
*	     FoxLib v1.6 - Utilidades para CrossBrowser DHTML
*	Desenvolvido por Rubens Alves de A. Jr. e-mail: firefox@cryogen.com
*	-----------------------------------------------------------------
*		Biblioteca de Funções úteis para DHTML
*           Utilidades para Cookies, Layers, Real/WinMedia videos
*/

var doc=""; 
var sty=""; 
var htm="";

function onerror()
 {
 document.location.href="javascript:";
 }

//************************** Funções de Layers ****************************
//PlayerObj = document.LrPlayer.document.embeds[0];

function setDOM()
 {

 if(navigator.appName.indexOf("Netscape") != -1)
   {
   if(parseInt(navigator.appVersion) >= 5)
     {
     doc = "document.getElementById('";
     sty = "').style";
     htm = "')"
     }
   else
     {
     doc = "document['";
     sty = "']";
     htm = "'].document"        
     }
   }
 else
   {
   doc = "document.all['";
   sty = "'].style";
   htm = "']";
   }
 }

function CriaLayer(Nome)
 {
 this.css = eval(doc + Nome + sty); 
 this.htm = eval(doc + Nome + htm);
 this.Show = ShowLayer;
 this.MoveTo = MoveLrTo;
 this.MoveBy = MoveLrBy;
 this.Load = LoadPage;
 this.LrWrite = TxtWrite;
 this.Roll = Ilumina;
 this.ScVert = ScrollVert;
 this.ScHori = ScrollHoriz;
 this.Clip = ClipTo;
 this.SMenu = SlideMenu;
 this.nome = "";
 this.flag = false;
 this.flagb = false;
 this.flagr = false;
 this.timer1 = null;
 this.timer2 = null;
 }

function MoveLrTo(PosY,PosX)
 {
 this.css.top=parseInt(PosY);
 this.css.left=parseInt(PosX);
 }

function MoveLrBy(QtY,QtX)
 {
 this.css.top= parseInt(this.css.top) + parseInt(QtY);
 this.css.left= parseInt(this.css.left) + parseInt(QtX);
 }

function ShowLayer(St) //exibir - ocultar layer
  {
  (St == "v") ? this.css.visibility = "visible" : this.css.visibility = "hidden";
  }

function LoadPage(site,comp) //comp = width
  {
  if((navigator.appName.indexOf("Netscape") != -1))
    {
    if(parseInt(navigator.appVersion) < 5)
      {
      this.css.load(site,comp);
      }
    else
      {
      var LP = null;
      LP = document.getElementById('FBuffer');
      LP.src = site;
      this.innerHTML = LP.innerHTML;
      }
    }
  else
    {
    parent.FBuffer.document.location = site;
    this.innerHTML = parent.FBuffer.document.body.innerHTML;
    }  
  }

//usar no ie caso use o LoadPage()
//
//<!-- buffer para IE e NS6-->
//<SCRIPT LANGUAGE="JavaScript">
//if (navigator.appName.indexOf("Microsoft") != -1)
//   document.write('<IFRAME STYLE="display:none" NAME="FBuffer"></IFRAME>');
//</SCRIPT>
//<!-- /buffer para IE e NS6-->


function TxtWrite(texto)
 {

 if(navigator.appName.indexOf("Netscape") != -1)
   {
   if(parseInt(navigator.appVersion) >= 5)
     {
     this.htm.innerHTML=(texto);
     }
   else
     {
     this.htm.open("text/html","replace");
     this.htm.write(texto);
     this.htm.close();
     }
   }
 else
   {
   this.htm.innerHTML=(texto);
   }
 }

//*************************Funções para botões e outras frescuras*****************************

//para iluminar o botão, cada figura precisa de dois objetos
//botao_on=new Image;
//botao_on.src="./pics/botao-l.jpg"
//botao_off=new Image;
//botao_off.src="./pics/botao-d.jpg"

function Ilumina(nome,estado)
 {
 if((navigator.appName.indexOf("Netscape") != -1)&&(parseInt(navigator.appVersion) < 5))
    this.htm.images[nome].src = eval(estado + ".src");
 else
    document.images[nome].src = eval(estado + ".src");
 }

function ScrollVert(vel,lim) //vel = velocidade  lim = limite
 {
 if(lim < 0)
   {
   if(parseInt(this.css.top) <= lim) this.flag = false;
   }
 else
   {
   if(parseInt(this.css.top) >= lim) this.flag = false;
   }
  
 if(this.flag==true)
   {
   this.css.top = parseInt(this.css.top) + vel;
   str = this.nome + ".ScVert(" + vel + "," + lim + ")";
   this.timer1=setTimeout(str,15);
   }
 else
   {
   clearTimeout(this.timer1);
   this.flag = false;
   this.Show("h");
   str = this.nome + ".Show('v')";
   setTimeout(str,20);
   }
 }
 
function ScrollHoriz(vel,lim) //vel = velocidade  lim = limite
 {
 if(lim < 0)
   {
   if(parseInt(this.css.left) <= lim) this.flag = false;
   }
 else
   {
   if(parseInt(this.css.left) >= lim) this.flag = false;
   }

 if(this.flag==true)
   {
   this.css.left = parseInt(this.css.left) + vel;
   str = this.nome + ".ScHori(" + vel + "," + lim + ")";
   this.timer1=setTimeout(str,15);
   }
 else
   {
   clearTimeout(this.timer1);
   this.flag = false;
   }  
 } 

function ClipTo(t,r,b,l)
 {
 if((navigator.appName.indexOf("Netscape") != -1)&&(parseInt(navigator.appVersion) < 5)) //para NS 4.x
   {
   this.css.clip.top = t;
   this.css.clip.right = r;
   this.css.clip.bottom = b;
   this.css.clip.left = l;
   }
 else
   {
   this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"; //para IE 4.x+ ou NS6
   }
 }

function SlideMenu(bvel,blim,rvel,rlim) //blim = limite inferior    rlim = limite superior
 {
 if((this.flagr==true)||(this.flagb==true))
   {
   this.Clip(0,rvel,bvel,0);
   
   if(bvel >= blim)
      this.flagb = false;
   else   
      bvel+=10;
   
   if(rvel >= rlim)
      this.flagr = false;
   else
      rvel+=7;   

   str = this.nome + ".SMenu(" + bvel + "," + blim + "," + rvel + "," + rlim + ")";
   this.timer1=setTimeout(str,10);
   }
 else
   {
   clearTimeout(this.timer1);
   this.flag = false;
   }  
 }

//********************************Funções de Cookies**********************************

//para setar data de expiração ponha na página
//<script language="javascript">
//dt_hoje = new Date();
//dt_expira = new Date();
//dt_expira.setTime(dt_hoje.getTime() + 1000*60); aqui vai a data, como exemplo 60*1000 que significa 1 minuto
//</script>

//cria o cookie

function CriaCookie(nome,valor, dtexp)
 {
 nome += "=";
 valor += ".";
 document.cookie = nome + escape(valor) + ((dtexp == null)? "" : (";expires=" + dtexp.toGMTString()));
}

//le um cookie e retorna seu valor, ou null caso não haja o cookie
function LeCookie(nome)
 {
 if (document.cookie.length > 0)
    {
    nome += "=";
    pos = document.cookie.indexOf(nome);
    if (pos != -1)
       {
       pos += nome.length;
       fim = document.cookie.indexOf(".",pos);
       if (fim == -1) fim = document.cookie.lenght;
           return(unescape(document.cookie.substring(pos,fim)));
       }
    else return(null);    
    }
}

//adapte de acordo com o seu formulario, ou item para o cookie guardar
function CriaItem()
 {
 var item = "";
 item += ("nome|" + document.frm_nome.Ftxt.value + ",");
 item += ("dtns|" + document.frm_nome.Fdat.value + ",");
 
 return(item); 
 }

//pega o item guardado no cookie, para caso de haver mais de um item.
//recebe nome do cookie e nome do item como parametros
//o parametro deve ser gravado no cooi no seguinte formato nomeparametro|valorparametro,
//retorna null caso não exista o item
function PegaItem(nome,item)
 {
 MCookie = LeCookie(nome);
 prm="";
 valor="";
 k=0;
 
 if(MCookie == null) return(null);
 
 for(k = 0;k < MCookie.length; k++)
    {
    if(MCookie.charAt(k)!= "|")
       (MCookie.charAt(k) == ",") ? prm = "" : prm += MCookie.charAt(k);
    else if(prm == item)
	   for(k = k + 1; k < MCookie.length; k++)  
	      {
	      if(MCookie.charAt(k)!= ",")
	         valor += MCookie.charAt(k);
	      else
	         return(valor);
	      }
         else
            prm = "";
    }
 
 if(valor == "") return(null);
 }
