var calendario;
/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}


function file_name_only(str) 
{ 
  return str.substring(str.lastIndexOf('/') + 1, str.lastIndexOf('.')) 
} 

function xajax_BuscaNoticia(){return xajax.call("fnBuscaNoticia", arguments, 1);}

function TrocaNoticia(id)
{
  var ret;
  
  document.getElementById('noticias_fe').className   = 'TabTransparente';
  document.getElementById('noticias_pi').className   = 'TabTransparente';
  document.getElementById('noticias_oc').className   = 'TabTransparente';
  document.getElementById('noticias_cep').className  = 'TabTransparente';
  document.getElementById('noticias_fnh').className  = 'TabTransparente';
  
  
  if ((id == 1) || (id == 4))
  {
     document.getElementById('noticias_fe').className = 'Tab_fe';
     document.getElementById('noticias_tab').className = 'Linha_fe_top';
  }  
  if (id == 2)
  {
     document.getElementById('noticias_pi').className = 'Tab_pi';
     document.getElementById('noticias_tab').className = 'Linha_pi_top';
  }
  
  if (id == 3)
  {
    document.getElementById('noticias_oc').className = 'Tab_oc';
    document.getElementById('noticias_tab').className = 'Linha_oc_top';
  }
  if (id == 5)
  {
    document.getElementById('noticias_cep').className = 'Tab_cep';
    document.getElementById('noticias_tab').className = 'Linha_cep_top';
  }
  if (id == 6)
  {
    document.getElementById('noticias_fnh').className = 'Tab_fnh';
    document.getElementById('noticias_tab').className = 'Linha_fnh_top';
  }
  
  ret = xajax_BuscaNoticia(id);
}

function TrocaNoticiaImg(id,img)
{
  var src  = document.getElementById('noticias_' + id);

  if (src.className == 'TabCinza' || src.className == 'TabTransparente')
  {  
     if (img == 2)
        src.className = 'TabCinza';
     else
        src.className = 'TabTransparente';
        
  }
    
}

function xajax_fnEventosDoDia(){return xajax.call("fnEventosDoDia", arguments, 1);}

function fnEventoDia(dia,mes,ano,unidade,obj)
{
  var ret;
  var i;
  
  for (i=1;i<=31;i++)
  {
    var Id_Dia = document.getElementById('dia_'+i);
    
    if (Id_Dia)
    {
      if (Trim(typeof(Id_Dia)) == 'object')
      {
        if (Trim(Id_Dia.className) == 'Selecionado')
            Id_Dia.className = '';
      }      
    }
  }
  
  if (obj.className != 'Hoje')
    obj.className='Selecionado';
  
  ret = xajax_fnEventosDoDia(dia,mes,ano,unidade);
  
}

function AtualizaImagem(img,descricao)
{
  document.getElementById("img_galeria").src = img;
  document.getElementById("img_descricao").innerText = descricao;
  return false;
}


function EventoDescricao(id)
{
  
  if (id != '')
  {
      var obj = document.getElementById(id);
      document.getElementById('divEvento_Descricao').innerText = obj.innerText;
  }
  else
  {
      document.getElementById('divEvento_Descricao').innerHTML = '';
  }
  
}

function xajax_fnBuscaBiblioteca(){return xajax.call("fnBuscaBiblio", arguments, 1);}

function fnBuscaBiblioteca()
{
 
  var ret;
  var divBiblio;
  var texto       = '';
  var campoParam  = '';
  var biblioParam = '';
  var ini         = '';
  var fim         = '';

  texto       = document.frmBiblioteca.texto.value;
  campoParam  = document.frmBiblioteca.campo.value;
  biblioParam = document.frmBiblioteca.biblio.value;
  ini         = document.frmBiblioteca.ini.value;
  fim         = document.frmBiblioteca.fim.value;

  if ( Trim (texto) == '' )
    alert('Informe o Texto de Busca!');
  else   
  {
    divBiblio = document.getElementById('divBiblio');
    divBiblio.innerHTML = "<b>Aguarde Processando...</b>";      
    ret = xajax_fnBuscaBiblioteca(texto,campoParam,biblioParam,ini,fim);
  }
  
}

function fnIndice(indice)
{
 
  var ret;
  var divBiblio;
  var texto       = '';
  var campoParam  = '';
  var biblioParam = '';
  var ini         = '';
  var fim         = '';

  texto       = document.frmBiblioteca.texto.value;
  campoParam  = document.frmBiblioteca.campo.value;
  biblioParam = document.frmBiblioteca.biblio.value;
  
  if (indice == 1)
  {
    ini         = 0;
    fim         = 4;
  }
  else
  {
    ini         = (indice * 5) - 5;
    fim         = (indice * 5);
  }
    
  if ( Trim (texto) == '' )
    alert('Informe o Texto de Busca!');
  else   
  {
    divBiblio = document.getElementById('divBiblio');
    divBiblio.innerHTML = "<b>Aguarde Processando...</b>";      
    ret = xajax_fnBuscaBiblioteca(texto,campoParam,biblioParam,ini,fim);
  }

}

function fnEnter(e)
{

  if(window.event) // IE
  {
    keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which;
  }
  
  if (keynum == 13)
  {
    fnBuscaBiblioteca();
    return false;
  }  
  else
    return true;

}

var DivStop = Array();

function ScrollDiv(acao,div)
{   


  var c = document.getElementById(div);   

  if (acao == 'D')
  {
      if (c.scrollTop < (c.scrollHeight-c.offsetHeight))
      {
          c.scrollTop = c.scrollTop + 1;
          if (DivStop[div] == 0)
            setTimeout("ScrollDiv('"+acao+"','"+div+"')",50);        
      }    
  }
  else
  {
      if (c.scrollTop > 0)
      {
          c.scrollTop = c.scrollTop - 1;
          if (DivStop[div] == 0)
            setTimeout("ScrollDiv('"+acao+"','"+div+"')",50);  
      }    
  }

}

function ScrollDivStart(acao,div)
{   
  DivStop[div] = 0;
  ScrollDiv(acao,div);
}

function ScrollDivStop(div)
{   
  DivStop[div] = 1;
}
