function textCounter(field, countfield, maxlimit) {
	if (document.getElementById(field).value.length > maxlimit) {
		document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
	} else {
		document.getElementById(countfield).value = maxlimit - document.getElementById(field).value.length;
	}
}



function textCounterOLD(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
    }
}
				
function pesquisar(){
  if(validaForm()){
    document.ConsultaForm.act.value='pesquisar';
    if(document.ConsultaForm.idPalavra!=null){
      for(i=0;i<document.ConsultaForm.idPalavra.length;i++){
        document.ConsultaForm.idPalavra[i].selected = true;
      }
      if(!document.ConsultaForm.idPalavra.length){
        document.ConsultaForm.idPalavra.selected = true;
      }
    }
    document.ConsultaForm.submit();
  }
}

  function fly(element,action) 
{
	if(action=='on')
	{ 
		document.getElementById(element).style.display='block'; 
	}
	else
	{ 
		document.getElementById(element).style.display='none'; 
	} 
}


function changeToField(chars,thisfld,newfld)
{
	if(thisfld.value.length==chars) 
	{
		newfld.focus();
	}
}


function checkAcomp()
{
	if ((document.acompform.acomp_id.selectedIndex==0 || document.acompform.acomp_id.selectedIndex==undefined) && (document.acompform.gua_nome.value=="" 
			|| document.acompform.gua_tipo.selectedIndex==0  || document.acompform.gua_doc_nr.value=="" 
			|| document.acompform.gua_dia.value=="" || document.acompform.gua_mes.value=="" 
			|| document.acompform.gua_ano.value==""))
	{
		alert("Você deve preencher todos os campos \r\n referentes aos dados do acompanhante!");
		return false;
	}
	return true;
}


function showDiv(area,init) {
	if (init==1) {
		document.getElementById(area).style.display='block';
	} else if (init==0) {
		document.getElementById(area).style.display='none';
	} else {
		if(document.getElementById(area).style.display=='block'){
			document.getElementById(area).style.display='none';
		}else{
			document.getElementById(area).style.display='block';
		}
	}
}

//***************************************
//Mostra / Oculta os selects da página
//***************************************
function selectsVisibility(varVisible){
	for (j=0 ; j<document.forms.length ; j++){
		for (i=0; i<document.forms[j].elements.length ; i++){
			if (document.forms[j].elements[i].type == 'select-one'){
				if(document.forms[j].elements[i].name!='pgid') {
					if(varVisible==0){
						document.forms[j].elements[i].style.visibility = 'hidden';
					} else if (varVisible==1) {
						document.forms[j].elements[i].style.visibility = 'visible'
					}
				}
			}
		}
	}
}




function calcDiarias() {
	var vlr_diarias;
	var vlr_evento;
	var vlr_total;
	var vlr_acomps;
	


	if	(document.getElementById('usi_unid_associado_vlr').value=="") { 
		vlr_diarias=0; 
	} else { 
		vlr_diarias=document.getElementById('usi_unid_associado_vlr').value; 
		//document.unidade.usi_unid_diarias_vlr.value=vlr_diarias.toFixed(2); 
	}
	if	(document.getElementById('usi_unid_evento_vlr').value=="") { 
		vlr_evento=0; 
	} else { 
		vlr_evento=document.getElementById('usi_unid_evento_vlr').value; 
		//document.unidade.usi_unid_evento_vlr.value=vlr_evento.toFixed(2); 
	}
	if	(document.getElementById('usi_acomp_vlr').value=="") { 
		vlr_acomps=0; 
	} else { 
		vlr_acomps=document.getElementById('usi_acomp_vlr').value; 
		//document.unidade.usi_unid_evento_vlr.value=vlr_evento.toFixed(2); 
	}
	vlr_total=parseFloat(vlr_diarias)+parseFloat(vlr_evento)+parseFloat(vlr_acomps);
	document.getElementById('usi_unid_diarias_ttl').value=vlr_total.toFixed(2);
	document.getElementById('usi_unid_diarias_ttl2').value=vlr_total.toFixed(2);
}


//***************************************
//Mostrar e Ocultar itens de uma listagem
//***************************************
function mostraItem(area,valor,tot) {
	//alert(area + valor + tot);
	for (var i=0;i<tot;i++)
		fechaItem(eval(area + (i + 1)));
		abreItem(eval(area + valor));
}
function fechaItem(obj) {
	obj.style.display='none';
}
function abreItem(obj) {
	obj.style.display='';
}


function changeFont(area,valor,tot) {
	for (var i=0;i<tot;i++) {
		var obj=area+(i+1);
		document.getElementById(obj).style.color='transparent';
	}
	var obj=area+valor;
	document.getElementById(obj).style.color='red';
}



//***************************************
//Mostra / Oculta os divs da página
//***************************************


function showDivs(area) {
	if(document.getElementById(area).style.display=='none'){
		document.getElementById(area).style.display='block';
	}else{
		document.getElementById(area).style.display='none';
	}
}

  

function Abrir(end,w,h,dir,ext) {
  loc='/'+dir+'/'+end+'.'+ext; 
  prop='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + w + ',height=' + h;
  janela=window.open(loc,"new",prop)
}

function open2(end) {
  loc=end; 
prop='toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=0,width=585,height=430';      
  janela=window.open(loc,"print",prop)
}

function openWin(end,w,h) {
  loc=end; 
  prop='toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=' + w + ',height=' + h;      
  janela=window.open(loc,"print",prop);
}
//Funcoes para selecionar e pegar Valores do checkbox
function Seleciona(val) {
	dml=document.lista;
	len = dml.elements.length;
	var i=0;
	for ( i=0 ; i<len ; i++) {
		if (dml.elements[i].name=='sel') {
			dml.elements[i].checked=val;
		}
	}
}

function Verifica() {
	var str;
	formlista=document.lista;
	len = formlista.elements.length;
	var i=0;
	for ( i=0 ; i<len ; i++) { 
		if (formlista.elements[i].name=='sel') {
			if (formlista.elements[i].checked) {
				str = str + formlista.elements[i].value + '$';
	       }
	    }
	}
	return str;
}



function hideLayer(lid1,lid2) {
		document.all[lid1].style.display = 'none';
		document.all[lid2].style.display = 'block';
}
function showLayer(lid2,lid1) {
		document.all[lid1].style.display = 'none';
		document.all[lid2].style.display = 'block';
}

function setCookie(name, value, minutes, path, domain, secure) {
        var curCookie = name + "=" + escape(value) + ((minutes)?(";expires=" + ((new Date((new Date()).getTime() + parseInt(minutes)*60000)).toGMTString())):"") + ((path)?";path=" + path:"") + ((domain)?";domain=" + domain:"") + ((secure)?";secure":"");
        document.cookie = curCookie;
	}
function getCookie(name) {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
        begin = dc.indexOf(prefix);
                if (begin != 0) return null;
        } else { begin += 2 }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) { end = dc.length; }
        return unescape(dc.substring(begin + prefix.length, end));
}

function sc_openLayer() {
	var name="layerOpen";
  	setCookie(name,"1",null,"/","","");	
  	return true;
}

function sc_closeLayer() {
	var name="layerOpen";
	setCookie(name,"0",null,"/","","");
	return true;
}


///////////////////////////////////////////////
//  COOKIES //////////////////////////////////

function setCookie2(name, value, minutes, path, domain, secure) // Asettaa cookien
	{
        var curCookie = name + "=" + escape(value) + ((minutes)?(";expires=" + ((new Date((new Date()).getTime() + parseInt(minutes)*60000)).toGMTString())):"") + ((path)?";path=" + path:"") + ((domain)?";domain=" + domain:"") + ((secure)?";secure":"");
        document.cookie = curCookie;
	}



function getCookie2(name) // Palauttaa cookien arvon
{
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
        begin = dc.indexOf(prefix);
                if (begin != 0) return null;
        } else { begin += 2 }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) { end = dc.length; }
        return unescape(dc.substring(begin + prefix.length, end));
}


function openImg(img,legenda,titulo) {

	var newImg = new Image();
	newImg.src = img;
	var width = newImg.width+50;
	var height = newImg.height+80;
	var ww;
	var hh;
	
	if(width>screen.availWidth) {
		ww = screen.availWidth-30;
	} else {
		ww = width;
	}
	if(height>screen.availHeight) {
		hh = screen.availHeight-30;
	} else {
		hh = height;
	}
	
    var leftPos = (screen.width - ww) / 2;
    var topPos = (screen.height - hh) / 2;
	
  photoWin = window.open( "", "fotos","width="+ww+",height="+hh+",status=0,scrollbars=1,resizable=1,screenX="+leftPos+",screenY="+topPos+",left="+leftPos+",top="+topPos);
  photoWin.document.write('<html><head><title>'+titulo+'</title></head>');
  photoWin.document.write('<link href="/lib/site.css" rel="stylesheet">');
  photoWin.document.write('<BODY BGCOLOR=#ffffff>');
  photoWin.document.write('<div align=center><img src="' + img + '" border=0></div>');
  photoWin.document.write('<div align=center>' + legenda + '</div>');
  photoWin.document.write('<div align=right><br><a href="JavaScript:window.close();">» fechar «</a></div>');
  photoWin.document.write('</body></html>');
  photoWin.document.focus();
  photoWin.document.close();
}

 ////////////////////////////////////////////////////////////////////////////
  // NOME : valida_numeros()
  // Descrição : Valida Apenas Números *****Deve ser usado do evento KeyPress
  // Parametros
  ///////////////////////////////////////////////////////////////////////////
  
  function valida_numero() {
    if (event.keyCode < 45 || event.keyCode > 57) 
     event.returnValue = false;
  }
  
  function valida_data(obj) {
    if (event.keyCode < 48 || event.keyCode > 57) 
     event.returnValue = false;
    else {
     if ((len(obj.value) == 3 && obj.value.substring(3,1) == '/') ||  (len(obj.value) == 6 && obj.value.substring == '/'))
       event.returnValue = false;
    } 
  }

  
  ////////////////////////////////////////////////////////////////////
//Valida numeracao com caracteres
////////////////////////////////////////////////////////////////////

function ValidaConteudoCampo(intervalo,caracter){ 
	//Autor: João Carlos B. Morgado (Advice Netbisiness) 
	//Data: 23/10/2001 
	//Descrição: Função para barra que seja digitado um conteúdo inválido no campo 
	//intervalo = 'A..Z' ou se tiver mais de um, faz-se: 'A..Z;a..z' 
	//caracter = '-/@!$' 
	//ex.: <input type="text" name="questao1[]" size="1" onkeypress="JavaScript:ValidaConteudoCampo('1..5','NULL');"> 
	var bvalido = false; 
	if(((caracter.toUpperCase) != 'NULL') || (caracter != '')){ 
		if(caracter == "PONTUACAO"){caracter = 'ãáâéêíîõóôúûçÃÁÂÉÊÍÎÕÓÔÚÛÇ ';} 
		for(i=0;i<=(caracter.length);i++){ 
			if((event.keyCode) == (caracter.charCodeAt(i))){ 
				bvalido = true; 
			} 
		} 
	} 
	if(!bvalido){ 
		var Inicio    = ""; 
		var Fim    = ""; 
		var bRetornaFalso  = false; 
		var bEncontrou  = false; 
		var location   = -1; 
		location = intervalo.indexOf(";"); 
		if((location) > -1){ 
			var restricoes = intervalo.split(";"); 
			for(i=0;i<=(restricoes.length-1);i++){ 
				Inicio  = restricoes[i].substring(0,1); 
				Fim  = restricoes[i].substring(3,4); 
				if((event.keyCode >= Inicio.charCodeAt()) && (event.keyCode <= Fim.charCodeAt())){ //48 57 
					bEncontrou = true; 
					i = restricoes.length; 
				} 
			} 
			if(!bEncontrou){ 
				bRetornaFalso = true; 
			} 
		} else if(intervalo.length == 4) { 
			Inicio  = intervalo.substring(0,1); 
			Fim  = intervalo.substring(3,4); 
			if((event.keyCode >= Inicio.charCodeAt()) && (event.keyCode <= Fim.charCodeAt())) { //48 57 
				bEncontrou = true; 
			} 
			if(!bEncontrou){ 
				bRetornaFalso = true; 
			} 
		} 
		if(bRetornaFalso){ 
			event.returnValue = false; 
		} 
	} 
} 
































ns4 = (document.layers)?true:false;
ie4 = (document.all)?true:false;

function FtrataBackSpace(dado)
{
   NumDig = dado.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;

   if ((TamDig >= 0) && (event.keyCode == 8))
    { numer = "";
      for (i = TamDig; (i >= 0); i--){
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
            {
             Contador++;
			 /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 4) && ((TamDig -i) < 5))
              {numer = ","+numer;
               Contador = 0;
               }
             else if ((Contador == 3) && ((numer.length) > 4))
              {numer = "."+numer;
               Contador = 0;
              }

             numer = NumDig.substr(i, 1)+numer;

            }
			}
			if (numer == "001" || numer == "000" || numer == "002" || numer == "003" || numer == "004" || numer == "005" || numer == "006" || numer == "007" || numer == "008" || numer == "009")
			    numer="";
			if ((numer.length) == 3 )
			    numer= "0," + numer;

		dado.value = numer;
      };

}





/*
   File: funcoesRT.js

   Funções de validação de campos durante a digitação.
*/
ns4 = (document.layers)?true:false;
ie4 = (document.all)?true:false;


/*
   Function: verificaNumericoRT

   Verifica se a tecla pressionada é numérica ou Backspace.
   Utilizar diretamente no campo do formulário no evento "onkeypressed".

   Parâmetros:

      campo - compo do formulário.
      event - tipo de evento.

   Retorno:

      *true* a tecla seja numérica.
*/
function verificaNumericoRT(campo, event)
{
    var TAB = 9;
    var RET = 13;
    var BS =  8;
    var key;
    var tecla;  
    
    if (navigator.appName.indexOf("Netscape") != -1){
        tecla = event.which;
  } else {
        tecla = event.keyCode;
  }

    key = String.fromCharCode( tecla);

    if ( tecla == RET ){
        return false;
  }
    if ( tecla == BS ){
        return true;
  }
    var Digits = "0123456789";
    if ( Digits.indexOf(key) == -1 )
        return false;
    return true;
}

/*
   Function: mascaraValorRT

   Aplica a máscara de valor em tempo real.
   Utilizar diretamente no campo do formulário no evento "onkeypressed".

   Parâmetros:

      campo - compo do formulário.
      e - evento.

   Retorno:

      *true* a tecla seja numérica.
*/
function mascaraValorRT(fld, milSep, decSep, e) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;


    trataBackSpaceMascaraValorRT(fld, e);

    if (whichCode == 13) return true;  // Enter
    key = String.fromCharCode(whichCode);  // Get key value from key code
    if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
    len = fld.value.length;
alert (len);
    for(i = 0; i < len; i++)
        if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    aux = '';
    for(; i < len; i++)
    if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
alert (len);
    if (len == 0) fld.value = '';
    if (len == 1) fld.value = '0'+ decSep + '0' + aux;
    if (len == 2) fld.value = '0'+ decSep + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += milSep;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        fld.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)    fld.value += aux2.charAt(i);
        fld.value += decSep + aux.substr(len - 2, len);
    }
    return false;
}



/*
   Function: trataBackSpaceMascaraValorRT

   Trata adequadamente o backspace em campo de valor.
   Utilizar diretamente no campo do formulário no evento "onkeydown".

   Parâmetros:

      campo - compo do formulário.
      event - evento.

   Retorno:

      nada.
*/
function trataBackSpaceMascaraValorRT(campo, event)
{
   NumDig = campo.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;
   if ((TamDig >= 0) && (event.keyCode == 8))
    {
      numer = "";
      for (i = TamDig; (i >= 0); i--){
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
            {
             Contador++;
             /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 4) && ((TamDig -i) < 5))
              {numer = "."+numer;
               Contador = 0;
               }
             else if ((Contador == 3) && ((numer.length) > 4))  
              {numer = "."+numer;
               Contador = 0;
              }
              
             numer = NumDig.substr(i, 1)+numer;
            
            }
        }
            if (numer == "001" || numer == "000" || numer == "002" || numer == "003" || numer == "004" || numer == "005" || numer == "006" || numer == "007" || numer == "008" || numer == "009") 
                numer="";       
            if ((numer.length) == 3 )
                numer= "0." + numer;

        campo.value = numer;
      };

}

