i = 0;
var crcinvalidos = new Array('~','`','!','#','$','%','%','^','&','*','(',')',',');

/*
Carlos Eduardo - Dg2 Internet Solutions
4what? 	
	Checkar todos os campos que contem o mesmo nome - objeto checkbox
recebe:	
	string fieldName  (Nome do Campo)
	string fatherName (Nome do Campo Pai)
retorna:
	Seta a propriedade checked de todos os campos de fieldName
	iguais a propriedade checked do pai. Se pai estiver checkado 
	todos os campos serão setados, caso contrário setá false a propriedade checked de 
	todos os campos 
*/
function CheckAll(fieldName, fatherName){
	var FieldsLen 	= eval('document.forms[0].' + fieldName + '.length');
	var Obj = eval('document.forms[i].' + fieldName + ';');
	var blnChecked 	= eval('document.forms[i].' + fatherName + '.checked');
	var j;
	if (FieldsLen > 0)
		for (j=0; j<FieldsLen; j++)
			Obj[j].checked=blnChecked;
	return true;
}

function MudaAction(action){
	document.forms[i].action= action;
	document.forms[i].submit();
}

function visivel(id,v) {
	document.getElementById(id).style.display = v ? 'block' : 'none';
}

function visivel2(obj,v) {
	if (v) {
		eval(obj + '.style.visibility="visible";');
		eval(obj + '.style.position="relative";');
	} else {
		eval(obj + '.style.visibility="hidden";');
		eval(obj + '.style.position="absolute";');
	}
	return true;
}
function validarcentro() {
	  if (document.frm.nome_instituicao.value=="")
	     {
	      alert('Por favor, digite o nome da Instituição');
	      document,frm.nome_instituicao.focus();
	      return false;
	     } 
	  if (document.frm.selOrgao.selectedIndex==0)
	     {
	      alert('Por favor, selecione o orgão transplantado');
	      document.frm.selOrgao.focus();
	      return false;
	     } 
	  
	  if (document.frm.senha.value=='') 
	     {
	      alert('Por favor, digite a senha do centro.');
	      document.frm.senha.focus();
          return false;
         }
          
      if (document.frm.responsavel.value=='')
         {
          alert('Por favor, digite o(s) nome(s) do(s) responsável(is).');
          document.frm.responsavel.focus();
          return false;
         } 
             
      if (document.frm.endereco.value=='')
         {
          alert('Por favor, digite o endereço da instituição.');
          document.frm.endereco.focus();
          return false;
         }
             
      if (document.frm.cep.value=='')
         {
          alert('Por favor, digitar o cep da instituição.');
          document.frm.cep.focus();
          return false;
         }
             
      if (document.frm.cidade.value=='')
         {
          alert('Por favor, digitar a cidade onde a instituição se situa.');
          document.frm.cidade.focus();
          return false;
         }
               
      document.frm.submit();    
}
    
function tab(controle,n) {
	if (controle.value.length >= n) {
		var j = 0;
		while (document.forms[i].elements[j]!=null && document.forms[i].elements[j].name!=controle.name) j++;
		while (document.forms[i].elements[j].name==controle.name) j++;
		if (document.forms[i].elements[j]!=null) document.forms[i].elements[j].focus();
	}
}

/*function TabControl(controle, n, i) {
	if (controle.value.length >= n) {
		var j = 0;
		while (document.forms[i].elements[j]!=null && document.forms[i].elements[j].name!=controle.name) j++;
		while (document.forms[i].elements[j].name==controle.name) j++;
		if (document.forms[i].elements[j]!=null) document.forms[i].elements[j].focus();
	}
}*/

function verificar_atualizacao() {
	if(document.frm_transpl.DataTransplante.value== '')
	  {
	  	alert('Favor digitar a data do transplante');
	  	document.frm_transpl.DataTransplante.focus();
	  	return false;
	  }
	else
	  {
	    if (!isDateValid(document.frm_transpl.DataTransplante.value))
	  	   {
	   	 	alert('Data do transplante inválida.');
	   	 	document.frm_transpl.DataTransplante.focus();
	   	 	return false;
	   	   }
	   }	 	
	
		   
	if (document.frm_transpl.DataPerdaEn.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataPerdaEn.value)) 
	        {
		 	 alert('Data da perda do enxerto inválida.');
		 	 document.frm_transpl.DataPerdaEn.focus();
		     return false;	  
			}
	   }	    	 
        
    if (document.frm_transpl.DataPerdaAc.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataPerdaAc.value)) 
	        {
			 alert('Data da perda do acompanhamento inválida.');
			 document.frm_transpl.DataPerdaAc.focus();
		 	 return false;	  
			}
	   }	 
        
    if (document.frm_transpl.DataTransferencia.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataTransferencia.value)) 
	        {
		 	 alert('Data de transferencia inválida.');
		 	 document.frm_transpl.DataTransferencia.focus();
		 	 return false;	  
			}
	   }	 
        
        
    var dataobito = document.frm_transpl.DataObito.value;

 	if (document.frm_transpl.Situacao.value == 4) 
	    {
	      if (dataobito == '') 
	         {
	          alert('Favor digitar a data do óbito.');
		      document.frm_transpl.DataObito.focus();
		      return false;
		      }
	          if (!isDateValid(dataobito)) 
	             {
		          alert('Data do óbito inválida.');
		          document.frm_transpl.DataObito.focus();
		          return false;
		          }
		  if (document.frm_transpl.MotivoObito.value=='')
		      {
		       alert('Favor digitar o motivo do óbito');
		       document.frm_transpl.MotivoObito.focus();
		       return false;
		      }         
	     }
	      if (document.frm_transpl.DataObito.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataObito.value)) 
	        {
		 	 alert('Data de Obito inválida.');
		 	 document.frm_transpl.DataObito.focus();
		 	 return false;	  
			}
	   }	 
	  
	 var acompanhamento = document.frm_transpl.DataPerdaAc.value; 
	 if (document.frm_transpl.Situacao.value == 3)
	    {
	      if(acompanhamento=='')
	         {
	          alert('Favor digitar a data de perda de acompanhamento.');
	          document.frm_transpl.DataPerdaAc.focus();
	          return false;
	         }
	         if (!isDateValid(acompanhamento))
	            {
	             alert('Data de perda de acompanhamento inválida.');
	             document.frm_transpl.DataPerdaAc.focus();
	             return false;
	            }
	       if (document.frm_transpl.MotivoPerdaAc.value=='')
	          {
	          	alert('Favor digitar o motivo da perda de acompanhamento.');
	          	document.frm_transpl.MotivoPerdaAc.focus();
	          	return false;
	          }	      
	     }
	     
 document.frm_transpl.submit();
}


function verificar_insercao() {
	if(document.frm_transpl.DataTransplante.value== '')
	  {
	  	alert('Favor digitar a data do transplante');
	  	document.frm_transpl.DataTransplante.focus();
	  	return false;
	  }
	else
	  {
	    if (!isDateValid(document.frm_transpl.DataTransplante.value))
	  	   {
	   	 	alert('Data do transplante inválida.');
	   	 	document.frm_transpl.DataTransplante.focus();
	   	 	return false;
	   	   }
	   }	 	
	
		   
	if (document.frm_transpl.DataPerdaEn.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataPerdaEn.value)) 
	        {
		 	 alert('Data da perda do enxerto inválida.');
		 	 document.frm_transpl.DataPerdaEn.focus();
		     return false;	  
			}
	   }	    	 
        
    if (document.frm_transpl.DataPerdaAc.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataPerdaAc.value)) 
	        {
			 alert('Data da perda do acompanhamento inválida.');
			 document.frm_transpl.DataPerdaAc.focus();
		 	 return false;	  
			}
	   }	 
        
    if (document.frm_transpl.DataTransferencia.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataTransferencia.value)) 
	        {
		 	 alert('Data de transferencia inválida.');
		 	 document.frm_transpl.DataTransferencia.focus();
		 	 return false;	  
			}
	   }	 
        
        
    var dataobito = document.frm_transpl.DataObito.value;
 	if (document.frm_transpl.Situacao.value == 4) 
	    {
	      if (dataobito == '')
 
	         {
	          alert('Favor digitar a data do óbito.');
		     document.frm_transpl.DataObito.focus();
		      return false;
		      }
	          if (!isDateValid(document.frm_transp1.dataobito.value)) 
	             {
		          alert('Data do óbito inválida.');
		          document.frm_transpl.DataObito.focus();
		          return false;
		          }

    
    if (document.frm_transpl.DataObito.value!= '') 
	   {
	     if (!isDateValid(document.frm_transpl.DataObito.value== '')) 
	        {
		 	 alert('Data do óbito inválida.');
		 	 document.frm_transpl.dataobito.focus();
		 	 return false;	  
			}
	   }
   
		  if (document.frm_transpl.MotivoObito.value=='')
		      {
		       alert('Favor digitar o motivo do óbito');
		       document.frm_transpl.MotivoObito.focus();
		       return false;
		      }         
	     }
	  
	 var acompanhamento = document.frm_transpl.DataPerdaAc.value; 
	 if (document.frm_transpl.Situacao.value == 3)
	    {
	      if(acompanhamento=='')
	         {
	          alert('Favor digitar a data de perda de acompanhamento.');
	          document.frm_transpl.DataPerdaAc.focus();
	          return false;
	         }
	         if (!isDateValid(acompanhamento))
	            {
	             alert('Data de perda de acompanhamento inválida.');
	             document.frm_transpl.DataPerdaAc.focus();
	             return false;
	            }
	       if (document.frm_transpl.MotivoPerdaAc.value=='')
	          {
	          	alert('Favor digitar o motivo da perda de acompanhamento.');
	          	document.frm_transpl.MotivoPerdaAc.focus();
	          	return false;
	          }	      
	     }
	     
	  if(document.frm_transpl.DoadorVivo[0].checked)
	    {
	     if (document.frm_transpl.parente.selectedIndex==0)
	     	{  
     		  alert('Favor indicar se o Doador é Aparentado ou não.');
	   		  document.frm_transpl.parente.focus();
	   		  return false;
	   	    }
	     else
	        {
	          if(document.frm_transpl.parente.value==1 && document.frm_transpl.fkParentesco.value=='')
	            {
	             alert('Favor indicar o tipo de relação do doador.');
	             document.frm_transpl.fkParentesco.focus();
	             return false;
	            }
         
   	          if(document.frm_transpl.parente.value==0 && document.frm_transpl.fkParentesco1.value=='')
	            {
	             alert('Favor indicar o tipo de relação do doador.');
	             document.frm_transpl.fkParentesco1.focus();
	             return false;
	            }
	        } 
	    }     	      		
 document.frm_transpl.submit();
}
	

function verificar1() {
		var nome1 = document.form.selCentros1.value;
		if (nome1 == '')
		    {
		     alert('Favor selecionar o centro.');
		     document.form.selCentros1.focus();
		     return false;
		    }
		document.form.submit();
	      }
	   
	   
function barra(campo)
	  {
		if ((event.keyCode != 37)&&(event.keyCode != 39)) 
		   if (event.keyCode != 46 && event.keyCode != 8 && campo.value.charAt(campo.value.length +1) != "/")
	  		  if((campo.value.length==2) || (campo.value.length==5))
	    		 {
	      		  campo.value = campo.value + "/";
	     		 }
	  }
	
	
// Licio corrigiu em 07/fev/2003
function isDateValid(datein) {
		var indate=datein;

        if (indate.indexOf('-')!=-1) {
                var sdate = indate.split('-')
        } else {
                var sdate = indate.split('/')
        }
		//alert(sdate[2]);
		/*
		if(Math.abs(sdate[2])<20)
			sdate[2] = Math.abs(sdate[2]) + 2000;
		if(Math.abs(sdate[2])>20 && Math.abs(sdate[2])<100 )
			sdate[2] = Math.abs(sdate[2]) + 1900;
		*/
		
        var chkDate=new Date(Math.abs(sdate[2]), Math.abs(sdate[1])-1, Math.abs(sdate[0]));
		
		var checkedYear = chkDate.getFullYear();
		if (chkDate.getFullYear() < 200)
			checkedYear = chkDate.getFullYear() + 1900;
		
        var cmpDate=(chkDate.getMonth()+1)+'/'+(chkDate.getDate())+'/'+(checkedYear)
        var indate2=(Math.abs(sdate[1]))+'/'+(Math.abs(sdate[0]))+'/'+(Math.abs(sdate[2]))
		if ((indate2!=cmpDate) || (cmpDate=='NaN/NaN/NaN')) return false;
		return true;
}

function MudaAction(acao,frm){
	frm.action= acao;
	frm.submit();
}

//==================================================================================================================
//									scripts - Validacao de campos
//==================================================================================================================

i=0
function cpfValido(controle) {

	eval('var strcpf=document.forms[i].'+controle+'.value;');
	strcpf = strcpf.replace(/\./gi,'');
	strcpf = strcpf.replace(/\-/gi,'');
	//alert(strcpf);
	
	var wSomaDosProdutos=0;
	var wResto=0;
	var wDigitChk=0;
	var wDigitChk2=0;
	var wStatus=0;
	var wI=0;


	for (wI = 0;wI<9;wI++)
		wSomaDosProdutos += parseInt( strcpf.substring(wI, wI+1) ) * (11 - (wI+1) );

	var wResto = wSomaDosProdutos - parseInt( wSomaDosProdutos / 11 ) * 11;

	if ( wResto == 0 || wResto == 1 )
		wDigitChk1 = 0;
	else
		wDigitChk1 = 11 - wResto;


	wSomaDosProdutos = 0;
	for (wI = 0;wI<9;wI++)
 		wSomaDosProdutos += parseInt( strcpf.substring(wI,wI+ 1) ) * (12 - (wI+1) );


	wSomaDosProdutos += 2 * wDigitChk1;
	wResto = wSomaDosProdutos - parseInt(wSomaDosProdutos / 11) * 11;
	if ( wResto == 0 || wResto == 1 )
		wDigitChk2 = 0;
	else
		wDigitChk2 = 11-wResto ; 

	var ch1 = strcpf.charAt(9);
	var ch2 = strcpf.charAt(10);

	if ( parseInt( ch1 ) == wDigitChk1 && parseInt( ch2 ) == wDigitChk2 ) return true;

	alert("Numero de CPF invalido!");
	eval('document.forms[i].'+controle+'.select();');
	return false;
}

function dataValida(controle) {
	var j;
	eval('var dia = parseInt(document.forms[i].'+controle+'[0].value);');
	eval('var mes = parseInt(document.forms[i].'+controle+'[1].value);');
	eval('var ano = parseInt(document.forms[i].'+controle+'[2].value);');
	//alert(dia+'/'+mes+'/'+ano);
	if (isNaN(dia) || isNaN(mes) || isNaN(ano)) {
		if (isNaN(dia)) j = '0';
		else if (isNaN(mes)) j = '1';
		else j = '2';

		alert('Data inválida');
		eval('document.forms[i].'+controle+'['+j+'].focus();');
		return false;
	}
	if (mes > 12) {
		alert('Data inválida');
		eval('document.forms[i].'+controle+'[1].focus();');
		return false;
	}
	if (ano < 1900) {
		alert('Data inválida');
		eval('document.forms[i].'+controle+'[2].focus();');
		return false;
	}
	//alert(DaysInMonth(mes,ano));
	if (dia > DaysInMonth(mes,ano)) {
		alert('Data inválida.');
		eval('document.forms[i].'+controle+'[0].focus();');
		return false;
	}
	
	return true;
}
function DaysInMonth(WhichMonth, WhichYear) {
  var DaysInMonth = 31;
  if (WhichMonth == 4 || WhichMonth == 6 || WhichMonth == 9 || WhichMonth == 11) DaysInMonth = 30;
  if (WhichMonth == 2 && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
  if (WhichMonth == 2 && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
  return DaysInMonth;
}

function campoDigitado(controle,campo) {
	eval('var texto = document.forms[i].'+controle+'.value;');
	//alert(texto);
	if (texto == '') {
		
		//#############################################################################################################################################		

		if(campo ==undefined)
		{
			alert('Por favor, insira um valor no campo');
		}
		else
		{
			alert('Por favor, digite '+campo);
		}
		
		//alert('Por favor, digite '+campo);

//#############################################################################################################################################		
		//alert('Por favor, digite '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function numeroValido(controle,campo) {
	eval('var texto = document.forms[i].'+controle+'.value;');

	var certo = true;
	for (var j = 0; j < texto.length; j++) {
		certo = certo && !isNaN(texto.charAt(j));
		//if (certo) alert('Continua certo. Atual: '+texto.charAt(j)); else alert('Já está errado. Atual: '+texto.charAt(j)); 
	}
	
	if (!certo) {
		alert('Por favor, digite um número para o '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function numerObr(controle,campo) {
	eval('var texto = document.forms[i].'+controle+'.value;');
	var certo = true;
	for (var j = 0; j < texto.length; j++) {
		certo = certo && !isNaN(texto.charAt(j));
		//if (certo) alert('Continua certo. Atual: '+texto.charAt(j)); else alert('Já está errado. Atual: '+texto.charAt(j)); 
	}
		if (texto == '') certo = false;	
	if (!certo) {
		alert('Por favor, digite um número para '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function numeroDDDValido(controle,campo) {
	eval('var tamanho = document.forms[i].'+controle+'.value.length');
	eval('var numero = parseInt(document.forms[i].'+controle+'.value);');
	if (isNaN(numero)) {
		alert('Por favor, digite um número para o '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	else if (tamanho < 2){
			alert('Por favor, O '+campo+' deve ter 2 digitos');
			eval('document.forms[i].'+controle+'.focus();');
			return false;
	}
	return true;
}

function caixaSelecionada(controle,campo) {
	eval('var valor = document.forms[i].'+controle+'.selectedIndex;');
	if (valor == 0) {
		alert('Por favor, escolha '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function caixaSelecionadaPlus(controle,campo,n) {
	
	eval('var valor = document.forms[i].'+controle+'.selectedIndex;');
	//alert(valor);
	if (valor < n) {
		alert('Por favor, escolha '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function valorSelecionado(controle,campo,v) {
	//eval('var valor = document.forms[i].'+controle+'[document.forms[i].'+controle+'.selectedIndex];');
	eval('var valor = document.forms[i].'+controle+'.value;');
	if (valor == 0) {
		alert('Por favor, escolha '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function senhaValida(caixa1,caixa2) {
	eval('var valor = document.forms[i].'+caixa1+'.value;');
	eval('var valor2 = document.forms[i].'+caixa2+'.value;');
	if (valor == '' || isNaN(valor) || valor.length < 4) {
		if (valor.value == '')
			alert('Por favor, digite uma senha.')
		else
			alert('A senha precisa ser um número com 4 algarismos.')
		eval('document.forms[i].'+caixa1+'.focus();');
		return false;
	}
	if (valor != valor2) {
		alert('A(s) senha(s) digitadas são diferentes.');
		caixa2.value = '';
		eval('document.forms[i].'+caixa2+'.focus();');
		return false;
	}
	return true;
}

function emailValido(controle,emailobrigatorio){
	eval('var email = document.forms[i].'+controle+'.value;');
	if ((vrfemailvld(email)) || (email == "" && !emailobrigatorio))
		return true;
	else {
		alert("E-mail Inválido!");
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
}


function vldcampos(){
	var i, k;
	var FieldObj,FieldName, FieldDesc, FieldVld;
	i=0;
	var CountItens = document.forms[i].length;
	
	resultado = true;
	
	for (k=0;k<CountItens-1 && resultado == true;k++){
		FieldObj  = document.forms[i].elements[k];
		FieldName = FieldObj.name;
		FieldDesc = FieldObj.descricao;
		FieldVld  = FieldObj.tipovalidacao;
		if (FieldDesc!=undefined)FieldDesc = FieldDesc.replace('<br>','');
		switch (FieldVld){   
			case "obrigatorio" :{
				resultado = campoDigitado(FieldName,FieldDesc);
				break;
			}   
			case "selecionado" :{
				resultado = caixaSelecionadaPlus(FieldName,FieldDesc,1);
				break;
			}
			case "selecionadovazio" :{
				resultado = caixaSelecionadaPlus(FieldName,FieldDesc,0);
				break;
			}
			case "cpf"  : {
				resultado = cpfValido(FieldName, FieldDesc);
				break;
			}
			case "data"  : {
				resultado = dataValida(FieldName);
				break;
			}
			case "horario"  : {
				resultado = campoDigitado(FieldName,FieldDesc) 
				break;
			}
			case "numero"  : {
				resultado = numeroValido(FieldName,FieldDesc);
				break;
			}
			case "numeroobrigatorio"  : {
				resultado = campoDigitado(FieldName,FieldDesc) && numeroValido(FieldName,FieldDesc);
				break;
			}
			case "ddd"  : {
				resultado = numeroDDDValido(FieldName,FieldDesc);
				break;
			}
			case "senha" : {
				resultado = senhaValida(FieldName,document.forms[i].elements[k+1].name);
				break;
			}
			case "email" : {
				resultado = emailValido(FieldName,false);
				break;
			}
			case "emailobrigatorio" : {
				resultado = emailValido(FieldName,true);
				break;
			}
			case "float" : {
				resultado = numeroFlutuante(FieldName,FieldDesc);
				break;
			}
			case "floatobr" : {
				resultado = campoDigitado(FieldName,FieldDesc) && numeroFlutuante(FieldName,FieldDesc);
				break;
			}
		}		
	}
	return resultado;
}

function validarcampos(iform){
	var k;
	var FieldObj,FieldName, FieldDesc, FieldVld;
	i=iform;
	var CountItens = document.forms[i].length;
	
	resultado = true;
	for (k=0;k<CountItens-1 && resultado == true;k++){
		FieldObj  = document.forms[i].elements[k];
		FieldName = FieldObj.name;
		FieldDesc = FieldObj.descricao;
		FieldVld  = FieldObj.tipovalidacao;
		if (FieldDesc!=undefined)FieldDesc = FieldDesc.replace('<br>','');
		switch (FieldVld){   
			case "obrigatorio" :{
				resultado = campoDigitado(FieldName,FieldDesc);
				break;
			}   
			case "selecionado" :{
				resultado = caixaSelecionadaPlus(FieldName,FieldDesc,1);
				break;
			}
			case "selecionadovazio" :{
				resultado = caixaSelecionadaPlus(FieldName,FieldDesc,0);
				break;
			}
			case "cpf"  : {
				resultado = cpfValido(FieldName, FieldDesc);
				break;
			}
			case "data"  : {
				resultado = dataValida(FieldName);
				break;
			}
			case "horario"  : {
				resultado = campoDigitado(FieldName,FieldDesc) 
				break;
			}
			case "numero"  : {
				resultado = numeroValido(FieldName,FieldDesc);
				break;
			}
			case "numeroobrigatorio"  : {
				resultado = campoDigitado(FieldName,FieldDesc) && numeroValido(FieldName,FieldDesc);
				break;
			}
			case "ddd"  : {
				resultado = numeroDDDValido(FieldName,FieldDesc);
				break;
			}
			case "senha" : {
				resultado = senhaValida(FieldName,document.forms[i].elements[k+1].name);
				break;
			}
			case "email" : {
				resultado = emailValido(FieldName,false);
				break;
			}
			case "emailobrigatorio" : {
				resultado = emailValido(FieldName,true);
				break;
			}
			case "float" : {
				resultado = numeroFlutuante(FieldName,FieldDesc);
				break;
			}
			case "floatobr" : {
				resultado = campoDigitado(FieldName,FieldDesc) && numeroFlutuante(FieldName,FieldDesc);
				break;
			}
		}		
	}
	return resultado;
}

function numeroFlutuante(controle,campo) {
	eval('var texto = document.forms[i].'+controle+'.value;');
	texto = texto.replace(".","")
	texto = texto.replace(",",".")
	var certo = true;
	for (var j = 0; j < texto.length; j++) {
		certo = certo && (!isNaN(texto.charAt(j)) || texto.charAt(j) == ".");
		//if (certo) alert('Continua certo. Atual: '+texto.charAt(j)); else alert('Já está errado. Atual: '+texto.charAt(j)); 
	}
	
	if (!certo) {
		alert('Por favor, digite um número para o '+campo);
		eval('document.forms[i].'+controle+'.focus();');
		return false;
	}
	return true;
}

function verificaHora(controle){
	var blnHoraOk = true;
	eval('var Hora = document.forms[i].'+controle+'[3].value;');
	var hm = -1;
	var hora = Array(2);
	var ch = Hora.charAt(0); 
	for(i=0; i < Hora.length && (( ch >= '0' && ch <= '9' ) || ( ch == ':' && i != 0 ) ); ){
		hora[++hm] = '';
		if(ch!=':' && i != 0) blnHoraOk = false;
		if(i != 0 ) ch = Hora.charAt(++i);
		if(ch=='0') ch = Hora.charAt(++i);
		while( ch >= '0' && ch <= '9' ){
			hora[hm] += ch;
			ch = Hora.charAt(++i);
		} 
	}
	if(ch!='') blnHoraOk =  false;
	if(hora[0] == '' || isNaN(hora[0]) || parseInt(hora[0]) < 0 || parseInt(hora[0]) > 23) blnHoraOk = false;
	if(hora[1] == '' || isNaN(hora[1]) || parseInt(hora[1]) < 0 || parseInt(hora[1]) > 59) blnHoraOk = false;
	if (!blnHoraOk){
		alert('Horário Inválido');
		//eval('document.forms[i].'+controle+'[3].focus();');
		return false;
	}
	return true;
}

function vrfcrcemail(email){
	var tudocerto = true;
	for (j=0;j<crcinvalidos.length && tudocerto;j++){
		if(email.indexOf(crcinvalidos[j])!= -1)
			tudocerto = false;
	}
	return tudocerto;
}

//######################################################CUSTOMIZAÇÃO###########################################################################

/*
function vrfemailvld(email){
	var tudocerto = true;
	if (!vrfcrcemail(email))
		tudocerto = false;
	if (email.charAt(0) == '.' || email.charAt(0) == '@')
		tudocerto = false;
	if (email.charAt(email.indexOf(".")+ 1) == ".")
		tudocerto = false;
	if (email.indexOf("@") > -1){
		var emailsemarroba =  email.slice(email.indexOf("@")+1,email.length);
		if(
			(emailsemarroba.indexOf("@") > -1) ||
			(email.charAt(email.indexOf("@")+ 1) == ".") ||
			(email.charAt(email.indexOf("@")- 1) == ".") ||
			(emailsemarroba.indexOf("@") == "") ||
			(emailsemarroba.indexOf(".") == -1) ||
			(email.charAt(email.length-1) == ".") ||
			(emailsemarroba.charAt(email.indexOf(".")+ 1) == ".")
		) tudocerto = false;
	}
	else tudocerto = false;
	return tudocerto;
}
*/

	function vrfemailvld(email){
    
	re = /^[^@]+@[^@]+.[a-z]{2,}$/i;

		if(email.search(" ")<1)
		{
			if(email.search(re) == -1)
			{	
				return false;
			}
			else
			{
				return true;
			}
		
		}
		else
		{
			return false;
		}
		
	}


//######################################################CUSTOMIZAÇÃO###########################################################################

//PREENCHIMENTO DINAMICO DE CAMPOS ==========================================================================================
function PegarSelecionado(SelPrincipal,SubObjs){
	i=IndiceForm;
	var Objs = new Array(5);
	var d =0;
	var valores,valoresaux;
	Objs[d] = "";
	for (c=0;c<SubObjs.length;c++){
		if (SubObjs.charAt(c)!=",")
			Objs[d] = Objs[d] + SubObjs.charAt(c);
		else{
			
			d = d+1;
			Objs[d] = "";
		}
	}
	valores = eval('document.forms[i].'+SelPrincipal+'[document.forms[i].'+SelPrincipal+'.selectedIndex].value;');
	d =0;
	valoresaux="";
	for (c=0;c<=valores.length;c++){
		if (valores.charAt(c)!=" " && c<valores.length)
			valoresaux = valoresaux + valores.charAt(c);
		else{
			if (valoresaux == "NULL") valoresaux = "";
			valoresaux = "'" + valoresaux + "'";
			eval('document.forms[i].'+Objs[d]+'.value='+valoresaux+';') 
			d = d+1;
			valoresaux="";
		}
	}
	return true;
}

function ColocarnaSel(SelPrincipal, SubObjs, Separadores, IndiceForm){
	i=IndiceForm;
	var Objs = new Array(5);
	var d =0;
	var valores,valoresaux;
	var str="";
	var valstr="";
	var valorcampo;
	Objs[d] = "";
	for (c=0;c<=SubObjs.length;c++){
		if (SubObjs.charAt(c)!="," && c<SubObjs.length)
			Objs[d] = Objs[d] + SubObjs.charAt(c);
		else{
			d = d+1;
			Objs[d] = "";
			if (Objs[d-1].substring(1,3) == 'fk'){
				str = str + ' ' + Separadores.charAt(d-1) + '  ' + eval('document.forms[i].'+Objs[d-1]+'[document.forms[i].'+Objs[d-1]+'.selectedIndex].text;');
				valstr = valstr + ' ' + eval('document.forms[i].'+Objs[d-1]+'[document.forms[i].'+Objs[d-1]+'.selectedIndex].value;');
			}else{
				valorcampo  = eval('document.forms[i].'+Objs[d-1]+'.value;');
				if (valorcampo == ''){
					valorcampo = "NULL";
				} else {
					str = str + ' ' + Separadores.charAt(d-1) + ' ' + eval('document.forms[i].'+Objs[d-1]+'.value;');
				}
				valstr = valstr + ' ' + valorcampo;
			}
		}
	}
	valstr = valstr.substring(1,valstr.length);
	AdcSelVals (SelPrincipal,valstr,str.substring(1,str.length), IndiceForm);
	//LmpCmpSelecionado(SelPrincipal,SubObjs,IndiceForm)
	return true;
}
function AdcSelVals(SelPrincipal,Indice,Texto,IndiceForm){
	i=0;
	if (FVrfAddRep(SelPrincipal,Indice,IndiceForm)) {
		var NovaOpcao = new Option (Texto,Indice,false,false);
		eval('document.forms[' + IndiceForm + '].'+SelPrincipal+'.options[document.forms[' + IndiceForm + '].'+SelPrincipal+'.length]=NovaOpcao;');
		return true;
	}
	return false;
}
function FVrfAddRep(SelNome,Indice,IndiceForm){
	eval('var CountTodos = document.forms[' + IndiceForm + '].'+SelNome+'.length;');
	for (m=0;m<CountTodos;m++){	
		if (eval('document.forms[' + IndiceForm + '].'+SelNome+'.options[m].value') == Indice){
			alert('Esse item já foi adicionado');
			return false;
		}
	}
	
	return true;
}
function ExcluiOpcao(ObjSel,IndiceForm){
	i=0;
	if (eval('document.forms[' + IndiceForm + '].'+ObjSel+'.selectedIndex')>= 0)
		eval('document.forms[' + IndiceForm + '].'+ObjSel+'.options[document.forms[' + IndiceForm + '].'+ObjSel+'.selectedIndex] = null;');
}

function LmpCmpSelecionado(SelPrincipal,SubObjs,IndiceForm){
	i=0;
	var strcmp="";
	for (c=0;c<=SubObjs.length;c++){
		if (SubObjs.charAt(c)!="," && c<SubObjs.length)
			strcmp = strcmp + SubObjs.charAt(c);
		else{
			eval('document.forms[' + IndiceForm + '].'+strcmp+'.value="";');
			strcmp = "";
		}
	}
	return true;
}

function FSelTodos(SelNome){
	eval('var CountTodos = document.forms[i].'+SelNome+'.length;');
	for (m=0;m<CountTodos;m++)
		eval('document.forms[i].'+SelNome+'[m].selected = true;');
}

function FSelTodosP(SelNome,iForm){
	eval('var CountTodos = document.forms[' + iForm + '].'+SelNome+'.length;');
	for (m=0;m<CountTodos;m++)
		eval('document.forms[' + iForm + '].'+SelNome+'[m].selected = true;');
}

//==================================================================================================================	
// Carlos Eduardo - dg2 internet solutions - 12/09/2003
// recebe: uma string controle(nome do objeto que contem o valor 'outro'), iForm inteiro(indice do form) 
// retorno: seta propiedade tipovalidacao do objeto para "obrigatorio" se 'outro' selecionado
// senão seta propiedade tipovalidacao o valor ""
function vldOutros(controle,iForm){
	var objOutro = controle.replace('fk','Outros');
	if (eval('document.forms[' + iForm + '].' + controle + '[document.forms['+ iForm +'].' + controle + '.selectedIndex].value==' + GbintOutros))
		MudaPropertyValidacao(objOutro,iForm,"obrigatorio");
	else
		ResetValidacao(objOutro,iForm);
}
// recebe: uma string controle(nome do objeto),inteiro indiceform(indice do form),string tipovalidacao
//(qual tipo validacao ira setar para a propriedade) 
// retorno: seta propriedade tipovalidacao do objeto com o valor de tipovalidacao
function MudaPropertyValidacao(controle,indiceform,tipovalidacao){
	var Obj = eval("document.forms[" + indiceform + "]." + controle + ";");
	var Tipo = controle.substring(0,3);
	if (Tipo == 'dat')
		MudaPropertyObj(Obj[0],'dat','tipovalidacao',tipovalidacao);
	else
		MudaPropertyObj(Obj,Obj.type,'tipovalidacao',tipovalidacao);
}
// recebe: um Obj(objeto do form),string ObjType(tipo do Objeto),
//string Ppr(Propriedade do Objeto), variant SetValor(valor para a propriedade)
// retorno: seta para a propriedade do objeto o valor de SetValor
function MudaPropertyObj(Obj,ObjType,Ppr,SetValor){
	var PprAtual;
	Obj.tipovalidacao = SetValor;
}
// recebe: uma string FieldName(nome do objeto),inteiro indiceform(indice do form)
// retorno: seta valor vazio para o campo
function ResetCampos(FieldName,iForm){  
	var Aux = FieldName.toLowerCase();
	var Tipo = Aux.substring(0,3);
	if (Tipo.substring(0,2) != 'fk')
		switch (Tipo){
			case "dat" :{
				eval('document.forms[' + iForm + '].' + FieldName + '[0].selectedIndex=0;');
				eval('document.forms[' + iForm + '].' + FieldName + '[1].selectedIndex=0;');
				eval('document.forms[' + iForm + '].' + FieldName + '[2].selectedIndex=0;');
				break;
			}
			default :{
				eval('document.forms[' + iForm + '].' + FieldName + '.value=""');
				break;
			}
		}
	else
		eval('document.forms[' + iForm + '].' + FieldName + '.selectedIndex=0;');
}
// recebe: uma string FieldName(nome do objeto),inteiro indiceform(indice do form)
// retorno: Chama MudaPropertyValidacao setando vazio para tipovalidacao e 
//			Chama ResetCampos setando vazio para o valor do objeto 
function ResetValidacao(FieldName,indiceform){  
	MudaPropertyValidacao(FieldName,indiceform,"");
	ResetCampos(FieldName,indiceform);
}
// recebe: uma string controle(nome do objeto),inteiro indiceform(indice do form)
// retorno: exibe o valor do objeto em uma window de alerta...
function AlertValor(controle,indiceform){
	alert(eval('document.forms[' + indiceform + '].' + controle + '.tipovalidacao'));
} 


//Quem: Cleytão
//Entrada: 16/6/2004
function getObj(id){
	if (document.all) {
		//IE5+
		return document.all(id);	
	}else{
		if(document.getElementById){	
			//NE	
			return document.getElementById(id);
		}else{
			//IE5-
			return document(id);	
		}
	}
}                                                                                                                                                                                                                                             i

