/*  
function escondeElemento()
function esconde()
function mostra()
function limita(campo)
function SetHelp(txt)
function main(campofoco)
function Apaga()
function printPage()
function FormataDado(campo,tammax,pos,teclapres)
function FormataValor(campo,tammax,teclapres)
function SaltaCampo (campo,prox,tammax,teclapres)
function VerificaJava()
function FormataCpf(campo,tammax,teclapres) {
function validaHora(objValue)
function fillOnlyNumbersHora(evt)
function Formata_Hora(campo)
function FormataCgc(campo,tammax,teclapres) 
function valida_CGC(campo)
function valida_CPF(campo)
function Formata_CEP(campo)
function formata_CPF_CGC(campo)
function valida_CPF_CGC(campo)
function Verifica_CGC(campo)
function Verifica_CPF(campo)
function Submit_combo(url, teclapres)
function tiraVirgula(campo)
function openBrWindow(theURL,winName,features) 
function validaCampoNumerico(campo, proximocampo)
function validaVerifica_CPF_CGC(campo)
function checkAll(campo, marcar)
function menuTree(divid)
function openBrWindow(theURL,winName,features)
function showColab(id)
function desenv()
function isValidSearchString(field, minChars)
function isEmail(testString)
function setFocus(form)
function setFocusNextField(form, field)
function isDate(testString)
function checkDate(field)
function filterNumber(field)
function fillOnlyLetters(evt)
function fillOnlyNumbers(evt)
function cleanNotLetters(field)
function cleanNotCharacters(field)
function cleanNotNumbers(field)
function filterTextField(evt, upper, others)
function acentuacao(e, Maiuscula, permissao) 
function checkDateGreater(dtIni,dtFim)
function isDateGreater(dI, dF)
function Limpar(valor, validos)
function FormataReais(campo, tammax, teclapres, decimal) 
function validaNrTelefone(obj)
function loadEtapa(obj)
function validaCampoSemAcentuacao(evt)
function countCharacters(campo, campoContador, max)
function logout()
function logoutEmpresa()
function logoutInstitucional()
function logoutEscola()
function logoutExterno()
function diferencaEmDias(data1, data2)


*/



//Bloco de código para esconder e mostra form
var Ver4 = parseInt(navigator.appVersion) >= 4
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4)
var block = "formulario";
function esconde() {	document.form.style.visibility = "hidden" }
function mostra() { document.form.style.visibility = "visible" }
//Bloco de código para esconder e mostra form

// -- Contador para objeto TextArea.
function limita(campo){
	var tamanho = document.form[campo].value.length;
	var tex=document.form[campo].value;
	if (tamanho>=1199) {
		document.form[campo].value=tex.substring(0,1199);
	}
	return true;
}

/*function contacampo(campo, tamtxt) {
	document.form[tamtxt].value =  1200-document.form[campo].value.length;
}*/

function SetHelp(txt) { help.innerText = txt ; }

function main(campofoco) {
	if ( campofoco == '' || document.form.elements.length == 0 )
		return false;

	var num = parseInt(campofoco);

	if ( num || num == 0 )
	{
		if ( document.form[num] )
			document.form[num].focus();
	}
	else
	{
		if ( document.form[campofoco] )
			document.form[campofoco].focus();
	}
}

function Apaga(){
	if (document.form.elements.length != 0)
		for (i = 0; i < document.form.elements.length; i++)
		{
			if( document.form[i].type != "hidden" )
				document.form[i].value="";
		}
}


var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta fun??o. Por favor utilize a barra de trabalho para imprimir a pÃ¡gina.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }

	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
/* Esta funcao formata um campo MOEDA. Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.form[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}

}

function SaltaCampo (campo,prox,tammax,teclapres){
/* Esta funcao salta para o proximo campo quando tiver completado todas as possiveis posicoes para a ditacao
do campo. Deve ser passado como parametro o nome do campo, nome do proximo campo, tamanho maximo do campo sem os
separadores e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;



	 	if (tecla != 0 && tecla != 9 && tecla != 16 ){
			if ( tam == tammax ){
				if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function VerificaJava()
 	{
	if (navigator.javaEnabled())
		document.form.javas.value="sim"
	}

function FormataCpf(campo,tammax,teclapres) {
/* Esta funcao formata um campo CPF. Mas nao valida, a funcao que formata e valida ? a Verifica_CPF().
Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	/*if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){*/
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.form[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	/*}*/
}

function validaHora(objValue){

	if(objValue == ""){
		return true;
	}

	var valor = objValue;
	var posicao = valor.indexOf(':', valor);
	if (posicao != -1)
		valor = valor.substring(0,posicao) + valor.substring(posicao+1, valor.length);

	if(valor.length==4){
		var hora	 =  parseFloat(valor.substring(0,2));
		var minuto	 =  parseFloat(valor.substring(2,4));
		if(hora >23){
			alert("Hora inválida !");
			return false;
		}
		if(minuto>59){
			alert("Hora inválida !");
			return false;
		}
	}else{
		alert("Hora Inválida !");
		return false;
	}

	return true;
}

function Formata_Hora(campo) {
/* Esta funcao formata o campo hora. Deve ser passado como parametro o nome do campo e 'event'. */

   valor = document.getElementById(campo).value
   posicao = valor.indexOf(':', campo);

   if (posicao != -1) valor = valor.substring(0,posicao) + valor.substring(posicao+1, valor.length);

   if (valor.length > 0 && valor.length < 3){
	  alert ("A data deve ser no mínimo 3 caracteres");
	  document.getElementById(campo).value = '';
	  document.getElementById(campo).focus();
   }
   else if (valor.length == 3){
	  valor = "0"+ valor;
	  document.getElementById(campo).value = valor
   }

   tam = valor.length + 1;

   if (tam == 5) document.getElementById(campo).value = valor.substr( 0, 2 ) + ':' + valor.substr( 2, 4 );
}

function FormataCgc(campo,tammax,teclapres) {
/* Esta funcao formata um campo CNPJ. Mas nao valida, a funcao que formata e valida ? a Verifica_CGC().
Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.getElementById(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		document.form[campo].value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		document.form[campo].value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		document.form[campo].value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}
}

function valida_CGC(campo){
/* Esta funcao valida o CNPJ. Deve ser passado como parametro o nome do campo */

	aux_CGC = document.getElementById(campo).value;
	CGC = "";
	if (aux_CGC != ''){
		for (i = 0; i<=17; i++){
			if (i != 2 && i != 6 && i != 10 && i != 15){
				CGC = CGC + aux_CGC.charAt(i);
			}
		}
		if (CGC.length != 14) {
		// tamanho invalido
  			sim=false;
			//alert ("Tamanho de CNPJ inv?lido!");
			//document.getElementById(campo).value ="";
			//document.getElementById(campo).focus();
			return false;
		}
		else {
			sim=true;
		}
		if (sim)  // verfica se e numero
		{
			for (i=0;((i<=(CGC.length-1))&& sim); i++){
				val = CGC.charAt(i);
				if  ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")){
					sim=false;
					//alert ("CNPJ inv?lido!");
					//document.getElementById(campo).value ="";
			        //document.getElementById(campo).focus();
			        return false;
				}
			}
			if (sim)  // se for numero continua
			{
				m2 = 2;
				soma1 = 0;
				soma2 = 0;
				for (i=11;i>=0;i--){
					val = eval(CGC.charAt(i));
					//file://alert ("Valor do Val: "+val)
					m1 = m2;
					if (m2<9) {
						m2 = m2+1;
					}
					else {
						m2 = 2;
					}
					soma1 = soma1 + (val * m1);
					soma2 = soma2 + (val * m2);
				}  // fim do for de soma
				soma1 = soma1 % 11;
				if (soma1 < 2) {
					d1 = 0;
				}
				else {
					d1 = 11- soma1;
				}
				soma2 = (soma2 + (2 * d1)) % 11;
				if (soma2 < 2) {
					d2 = 0;
				}
				else {
					d2 = 11- soma2;
				}
			}
			if ((d1==CGC.charAt(12)) && (d2==CGC.charAt(13))){
				// alert("Valor Valido de CNPJ")
				return true;
			}
			else{
			    //alert ("CNPJ inv?lido!");
				//document.getElementById(campo).value ="";
			    //document.getElementById(campo).focus();
			    return false;
			}
		}
	}
}

function valida_CPF(campo){
/* Esta funcao valida o CPF. Deve ser passado como parametro o nome do campo */

	aux_CPF = document.getElementById(campo).value;

	CPF = "";
	for (i = 0; i<=13; i++){
		if (i != 3 && i != 7 && i != 11){
			CPF = CPF + aux_CPF.charAt(i);
		}
	}

	if (document.getElementById(campo).value != '' ){
		if (CPF.length != 11 || 
			CPF == "00000000000" || 
			CPF == "11111111111" || 
			CPF == "22222222222" || 
			CPF == "33333333333" || 
			CPF == "44444444444" || 
			CPF == "55555555555" || 
			CPF == "66666666666" || 
			CPF == "77777777777" || 
			CPF == "88888888888" || 
			CPF == "99999999999"){
			return false;
		}
		else {
			soma = 0;
			for (i=0; i < 9; i ++)
				soma += parseInt(CPF.charAt(i)) * (10 - i);
			resto = 11 - (soma % 11);
			if (resto == 10 || resto == 11)
				resto = 0;
			if (resto != parseInt(CPF.charAt(9))){
        			return false;
     			}
			else {
				soma = 0;
				for (i = 0; i < 10; i ++)
					soma += parseInt(CPF.charAt(i)) * (11 - i);
				resto = 11 - (soma % 11);
				if (resto == 10 || resto == 11)
					resto = 0;
				if (resto != parseInt(CPF.charAt(10))){
					return false;
				}
				else{
				   return true;
				}
			}
		}
	}
}

function Formata_CEP(campo) {
/* Esta funcao formata e o CEP. Deve ser passado como parametro o nome do campo */

	vr = campo.value;
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam == 8) {
		campo.value = vr.substr(0, 5) +"-"+ vr.substr(5,3);
	} else if (tam < 8 && tam > 0) {
		alert ("Tamanho inválido de CEP!");
		campo.focus();
	}
}


function formata_CPF_CGC(campo){
/* Esta funcao formata e um campo que pode ser tanto o CPF ou o CNPJ.
Deve ser passado como parametro o nome do campo */

	vr = document.getElementById(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam == 14){
		document.getElementById(campo).value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ;
	}
	else if (tam == 11){
		document.getElementById(campo).value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ) ;
	}
}


function valida_CPF_CGC(campo){
/* Esta funcao valida o campo que pode ser tanto CPF ou CNPJ. Deve ser passado como parametro o nome do campo */

   vr = document.getElementById(campo).value;
   tam = vr.length;

   if (tam == 18){
       return valida_CGC(campo);
   }
   else if (tam == 14){
       return valida_CPF(campo);
   }
}


function Verifica_CGC(campo){
/* Esta funcao formata e o CPF/CNPJ e chama a funcao valida_CPF_CGC para ver se este ? valido.
Deve ser passado como parametro o nome do campo */

   formata_CPF_CGC(campo);
   if ((document.getElementById(campo).value.length > 0) && (!valida_CPF_CGC(campo))){
       alert ("CNPJ/CPF inválido!!!");
       document.getElementById(campo).focus();
   }
}


function Verifica_CPF(campo){
/* Esta funcao formata e o CPF/CNPJ e chama a funcao valida_CPF_CGC para ver se este ? valido.
Deve ser passado como parametro o nome do campo */

   formata_CPF_CGC(campo);
   if ((document.form[campo].value.length > 0) && (!valida_CPF_CGC(campo))){
       alert ("CPF inválido!");
       document.form[campo].focus();
   }
}

function Submit_combo(url, teclapres){
/* Esta funcao da o submit no formulario quando este e feito de um combo box.
Deve ser passado como parametro ex: ('xxx.htm', event) */

   var tecla = teclapres.keyCode;
   if (tecla == 13){
      if (validaSubmit()){
         document.forms[0];
		 document.forms[0].method = "post";
         document.forms[0].action = url;
         document.forms[0].submit();
	  }
   }
}

function tiraVirgula(campo){
/* Esta funcao substritui a 'virgula' de um campo decimal por um 'ponto'.
Deve ser passado como parametro o nome do campo */

    if (campo.value.length > 0){
       conteudo = new String(campo.value);
       rExp = /,/gi;
       campo.value = conteudo.replace(rExp, new String("."));
    }
}

function openBrWindow(theURL,winName,features) {
/* Esta funcao abre uma nova janela do browser.
Ex: javascript:openBrWindow('xxx.htm', '', 'menubar=yes, scrollbar=yes, resize=yes') */

  window.open(theURL,winName,features);
}

function validaCampoNumerico(campo, proximocampo, mensagem){
/*Esta funcao valida se o campo eh numerico ou nao. Deve ser passado como
referencia apenas a referencia do campo (this) */
	if (campo != ''){
		if (campo.name != ''){
			valor = campo.value
			tam = campo.value.length

		   if (tam > 0){
				tiraVirgula(campo)
				valor = campo.value
				if (isNaN(valor)) {
					if( mensagem != undefined && mensagem != ''){
						alert(mensagem);
					} else {
						alert ("Este campo é numérico e não aceita letras.");
					}
					campo.value = "";
					campo.focus();
					return false;
				}
				else{
					if (proximocampo != '') document.form[proximocampo].focus();
					return true;
				}
			}
		}
	}
	else{
		return true;
	}
}

function validaVerifica_CPF_CGC(campo){
// valida e verifica o campo se for CPF ou CNPJ. Chamando tb a funcao que formata esses campos.
   formata_CPF_CGC(campo);
   if ((document.form[campo].value.length > 0) && (!valida_CPF_CGC(campo))){
	   alert ("CNPJ/CPF inválido!");
	   document.form[campo].value = '';
	   document.form[campo].focus();
   }
}

function checkAll(campo, marcar) {
	// marca todas as checkbox da tela
	val = document.forms[0][campo.name].checked;
	len = document.forms[0][marcar].length;
	for( i=0 ; i<len ; i++)
		document.forms[0][marcar][i].checked = val;
}

function menuTree(divid){
	var o = document.all('div' + divid);
	if (o.style.display=="none"){
		o.style.display="block";
	} else{
		o.style.display="none";
	}
}

function openBrWindow(theURL,winName,features) {
/* Esta funcao abre uma nova janela do browser.
Ex: javascript:openBrWindow('xxx.htm', '', 'menubar=yes, scrollbar=yes, resize=yes') */
	window.open(theURL,winName,features);
}
function showColab(id){
	openBrWindow('./colaboradorPesquisa.do?m=doDetail&id='+id,'','status=yes,menubar=no,scrollbars=yes,resizable=no,width=500,height=250')
}

/*
	author: Diego Pires Plentz
	url: http://plentz.org
*/


o = String.prototype;

/*o.$_replace = o.replace;

o.replace = function(a, b) {
	if(a instanceof RegExp) return this.$_replace(a, b);
	else return this.split(a).join(b);
}
*/
o.trim = function() {
	return this.replace(/^\s*|\s*$/g,'');
}
/*
o.ltrim = function() {
	return this.replace(/^\s* /g,''); //asterisco colado no /
}

o.rtrim = function() {
	return this.replace(/\s*$/g,'');
}

o.removeSpaces = function() {
	return this.replace(' ','');
}*/

delete o;

function desenv(){
	alert("Esta funcionalidade ainda não foi desenvolvida.");
}

function isValidSearchString(field, minChars){
	if(minChars == null) minChars = 3;
	var regexp = new RegExp("^.*[a-zA-Z0-9]{" + minChars + ",}.*$");
	var isValid = (field.value == '')? true: (regexp).test(field.value)
	if(!isValid){
		alert("A pesquisa requer no mínimo " + minChars + " caracteres!");
		field.focus();
	}
	return isValid;
}

function isEmail(testString){
	return (/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/).test(testString);
}

function setFocus(form){
// esta funcao nao seta focus se for um select
// Form.focusFirstElement((form == null)? document.forms[0] : form );
  var bFound = false;

  // for each form
  for (f=0; f < document.forms.length; f++){
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++){
      // if it's not a hidden element
      if (document.forms[f][i].type != "hidden"){
        // and it's not disabled
        if (document.forms[f][i].disabled != true){
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}

function setFocusNextField(form, field){
	var elements = form.elements;
    for (var i = 0; i < elements.length; i++) {
		if(field && (elements[i].name == field.name)){
			for (var k = i+1; k < elements.length; k++) {
				if(!elements[k].disabled && elements[k].type != 'hidden'){
					Field.activate(elements[k]);
					break;
				}
			}
		}
    }
}

function isDate(testString){
	return (/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/).test(testString);
}

function checkDate(field){
	date = field.value;

	if(date != ''){
		date = date.replace(/\D/g,'');
		date = date.substr(0,2) + '/' + date.substr(2,2) + '/' + date.substr(4,4);
		if(!isDate(date)){
			alert("A data informada não é válida. O formato correto é dd/mm/aaaa!");
			field.value = '';
			field.focus();
			return false;
		} else {
			field.value = date;
			return true
		}
	} else {
		return true
	}
}

function filterNumber(field){
	field.value = field.value.replace(/\D/g,'');
}

function fillOnlyLetters(evt){
	//distinguish between IE's explicit event object (window.event) and Firefox's implicit.
	var evtobj = window.event ? event : evt; 
			
	if (evtobj.keyCode) unicode = evtobj.keyCode; // I.E.      
	else if (evtobj.charCode) unicode = evtobj.charCode; // Mozilla  
	else if (evtobj.which) unicode = evtobj.which; // Netscape 4.?   
		
	if( (/[^a-zA-Z ]/).test(String.fromCharCode(unicode)) && !isValidUnicode(unicode)){
		return false;
	}
	
	return true;
}

function fillOnlyNumbers(evt){
	//distinguish between IE's explicit event object (window.event) and Firefox's implicit.
	var evtobj = window.event ? event : evt; 
			
	if (evtobj.keyCode) unicode = evtobj.keyCode; // I.E.      
	else if (evtobj.charCode) unicode = evtobj.charCode; // Mozilla  
	else if (evtobj.which) unicode = evtobj.which; // Netscape 4.?   

	if((/\D/).test(String.fromCharCode(unicode)) && !isValidUnicode(unicode)){
		return false;
	}
	
	return true;
}

/**
 * Pertime a digitação das teclas abaixo
 * 
 * 13 - enter 8 - backspace 9 - tab
 * 37 - seta esquerda 39 - seta direita
 * 46 - delete
 */
function isValidUnicode(unicode){
	if(unicode == 8 || unicode == 9 ||
	   unicode == 37 || unicode == 39 ||
	   unicode == 46){
		return true;
	}
	return false;	
}

function cleanNotLetters(field){
	var text = field.value.trim();
	field.value = text.replace(/[^a-zA-Z ]/g,'');
}

function cleanNotCharacters(field){
	var text = field.value.trim();
	field.value = text.replace(/[^\w ]/g,'');
}

function cleanNotNumbers(field){
	field.value = field.value.replace(/\D/g,'');
}

function filterTextField(evt, upper, others){
	var letters = fillOnlyLetters(evt);
	if(!letters){
		alert("Atenção!\n\nLetras acentuadas, cedilha e caracteres especiais não são permitidos neste campo!");
		return false
	}
}

function acentuacao(e, Maiuscula, permissao) {
   var Tecla = event.keyCode;

   if (Tecla > 0){
	   if ((Tecla >= 65 && Tecla <= 90) || Tecla == 16 || Tecla == 20 || (Tecla >= 57 && Tecla <= 59)
			|| (Tecla >= 44 && Tecla <= 48) || Tecla == 32 || (Tecla >= 33 && Tecla <= 40)
			|| Tecla == 188 || Tecla == 190 || Tecla == 191 || Tecla == 13 || (Tecla >= 8 && Tecla <=9))
		   return;

	   if (permissao){
		   // permite barra e hifen
		   if (Tecla == 189 || Tecla == 193)
		   return;
	   }

	   if (Tecla >= 96 && Tecla <= 122){
		  if(Maiuscula == null || Maiuscula == true)
		  event.keyCode -= 32;
		  return;
	   }
	   alert("Atenção!\n\nLetras acentuadas, cedilha e caracteres especiais não são permitidos neste campo!");
	   event.returnValue = false;
   }
}

function checkDateGreater(dtIni,dtFim){
	if (dtIni!=null && dtFim!=null){
    	if(isDateGreater(dtIni,dtFim)){
    		alert("Atenção!\n\nData final deve ser maior que a Data Inicial!");
    		return false;
    	}
    }
  	return true;
}

function isDateGreater(dI, dF){
	d1 = new Date(dI.substr(6,4), dI.substr(3,2)-1, dI.substr(0,2))
	d2 = new Date(dF.substr(6,4), dF.substr(3,2)-1, dF.substr(0,2))
	
	if (d1 > d2) return true;
	
	return false;
}

function Limpar(valor, validos) {

	// retira caracteres invalidos da string	
	var result = "";	
	var aux;
	
	for (var i=0; i < valor.length; i++) {	
		aux = validos.indexOf(valor.substring(i, i+1));
	
		if (aux>=0) {	
			result += aux;	
		}
	}
	return result;
}


function FormataReais(campo, tammax, teclapres, decimal) {
	
	if(fillOnlyNumbers(teclapres)){
	
		var tecla = teclapres.keyCode;
		vr = Limpar(campo.value,"0123456789");
		tam = vr.length;
		dec=decimal
	
		if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }	 
		
		if (tecla == 8 )	
		{ tam = tam - 1 ; } 
	
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )	
		{ 
			if ( tam <= dec )		
			{ campo.value = vr ; } 
	
			if ( (tam > dec) && (tam <= 5) ){
				campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	
			if ( (tam >= 6) && (tam <= 8) ){
				campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
			}
	
			if ( (tam >= 9) && (tam <= 11) ){
				campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	
			if ( (tam >= 12) && (tam <= 14) ){
				campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	
			if ( (tam >= 15) && (tam <= 17) ){
				campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	
		}
	}
}

function validaNrTelefone(obj){
	var nrTelefone = obj.value;
	if (nrTelefone != ''){
		if (nrTelefone.length <= 6 || nrTelefone.length >= 9){
			alert("Número do telefone deve ter entre 7 e 8 digitos.");
			return false;
		}
	}
	
	return true;
}

function loadEtapa(obj){
	var etapa = obj.value;
	
	if (etapa == '2'){
		document.location.href = './cadastroDadosPessoaisEstudante.do?m=doLoad';			
	} else if (etapa == '3'){
		document.location.href = 'cadastroEstudanteDadosAcesso.jsp';
	} else if (etapa == '4'){
		document.location.href = './cadastroDadosEscolaresEstudante.do?m=doLoad';
	} else if (etapa == '5'){
		document.location.href = './cadastroHabilidadesEstudante.do?m=doLoad';
	} else if (etapa == '6'){
		document.location.href = './cadastroAtendimentoEstudante.do?m=doLoad';
	} else if (etapa == '7'){
		document.location.href = './cadastroExperienciasEstudante.do?m=doLoad';
	}
}

function validaCampoSemAcentuacao(evt){ 	
	//distinguish between IE's explicit event 
    //object (window.event) and Firefox's implicit.
	var evtobj = window.event ? event : evt; 
			
	if (evtobj.keyCode) unicode = evtobj.keyCode; // I.E.      
	else if (evtobj.charCode) unicode = evtobj.charCode; // Mozilla  
	else if (evtobj.which) unicode = evtobj.which; // Netscape 4.?   

	myString = String.fromCharCode(unicode);
	
    myRE = new RegExp("[a-zA-Z0-9. ():;,*-/ªº#$%&_=+!?@\\r\\n]*");

	results = myString.match(myRE);

	if (results != null && results.toString() != myString && !isValidUnicode(unicode)) {
	    alert ("Atenção\n\nLetras acentuadas, cedilha e caracteres especiais não são permitidos neste campo !");
	    return false;
	}

	return true;
}

function countCharacters(campo, campoContador, max){
   var aux = document.forms[0];
   CharsLeft = max;
   StrLen = campo.value.length;

   if (StrLen == 1 && campo.value.substring(0,1) == " "){
		campo.value = "";
		StrLen = 0;
   }
   if (StrLen > max){
	   campo.value = campo.value.substring(0,campo.value.length-1);
	   CharsLeft = 0;
   }else{
	  CharsLeft = CharsLeft - StrLen;
   }
   document.getElementById(campoContador).value = CharsLeft;
}

function logout(){	
	document.location = '../estudante/inicial.do?m=doPaginaPrincipalEstudante&logout=s';	
}

function logoutEmpresa(){	
	document.location = '../empresa/inicial.do?m=doPaginaPrincipalEmpresa&logout=s';	
}

function logoutInstitucional(){
	document.location = '../site.do?m=doPaginaPrincipalInstitucional&logout=s';
}

function logoutEscola(){
	document.location = '../escola/inicial.do?m=doPaginaPrincipalEscola&logout=s';
}

function logoutExterno(){
	document.location = '../site.do?m=doPaginaPrincipalInstitucional&logout=s';
}

function diferencaEmDias(data1, data2){
	dia1 = data1.substring(0, 2)
	mes1 = data1.substring(3, 5)
	ano1 = data1.substring(6, 10)
	
	dia2 = data2.substring(0, 2)
	mes2 = data2.substring(3, 5)
	ano2 = data2.substring(6, 10)
	
	d1 = new Date(ano1, mes1, dia1)
	d2 = new Date(ano2, mes2, dia2)

	diff = (d2-d1)/86400000   
	
	return diff
}

function fillOnlyNumbersHora(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode;

	// se digitado for ':'
	if(charCode==58)
		return true;

	return 	fillOnlyNumbers(evt);

}

/**
 * Esconde um elemento se ele estiver aparecendo,
 * mostra o elemento se estiver escondido.
 * Para o elemento já aparecer oculto na página
 * colocar a propriedade abaixo nele:
 * style="display:none" 
 * @param element É o id do elemento. 
 */
function escondeElemento(element){
	if(document.getElementById(element).style.display == 'none'){
		document.getElementById(element).style.display = 'block';
	}else{
		document.getElementById(element).style.display = 'none';
	}
}

