		function validaNumero(pObj) {
			if (!/^\d*$/.test(pObj.value)){					
				pObj.value = pObj.value.replace(/[^\d]/g,"");
				pObj.focus();
			}
		} 

		function validaData(pObj){
			if ( isDate(pObj.value) == false ){
				setMsgErro('Data inválida');			
			}
		}
		
		function checkemail(str){
			var testresults ;
			var invalidcheck=0;
			var filter=/^.+@.+\..{2,3}$/;
			if (filter.test(str)){
				var tempstring=str.split("@");
				tempstring=tempstring[1].split(".");
				testresults=true;
			}
			else{				
				testresults=false;
			}
			return (testresults);
		}

		function validaCPF(cpf)
		{
			var numeros, digitos, soma, i, resultado, digitos_iguais;
			digitos_iguais = 1;
				
			if (cpf.length < 11){
				return false;
			}

			for (i = 0; i < cpf.length - 1; i++){				
			    if (cpf.charAt(i) != cpf.charAt(i + 1)){
					digitos_iguais = 0;
					break;
				}
			}
				
			if (!digitos_iguais){
					  
				numeros = cpf.substring(0,9);
				digitos = cpf.substring(9);
				soma = 0;
					  
				for (i = 10; i > 1; i--){
					soma += numeros.charAt(10 - i) * i;
				}
					        
				resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
					  
				if (resultado != digitos.charAt(0)){
					return false;
				}
					        
				numeros = cpf.substring(0,10);
				soma = 0;
					  
				for (i = 11; i > 1; i--){
					soma += numeros.charAt(11 - i) * i;
				}
					  
				resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
					  
				if (resultado != digitos.charAt(1)){
					return false;
				}
	
				return true;
		    }
			else{
		      return false;
		    }
		}

		function validaCEP(strCEP){			
			var reTipo = /^\d+$/;
			return reTipo.test(strCEP);
		}

		/**
		 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
		 */
		// Declaring valid date character, minimum year and maximum year
		var dtCh= "/";
		var minYear=1900;
		var maxYear=2100;

		function isInteger(s){
			var i;
		    for (i = 0; i < s.length; i++){   
		        // Check that current character is number.
		        var c = s.charAt(i);
		        if (((c < "0") || (c > "9"))) return false;
		    }
		    // All characters are numbers.
		    return true;
		}

		function stripCharsInBag(s, bag){
			var i;
		    var returnString = "";
		    // Search through string's characters one by one.
		    // If character is not in bag, append to returnString.
		    for (i = 0; i < s.length; i++){   
		        var c = s.charAt(i);
		        if (bag.indexOf(c) == -1) returnString += c;
		    }
		    return returnString;
		}

		function daysInFebruary (year){
			// February has 29 days in any year evenly divisible by four,
		    // EXCEPT for centurial years which are not also divisible by 400.
		    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
		}
		function DaysArray(n) {
			for (var i = 1; i <= n; i++) {
				this[i] = 31
				if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
				if (i==2) {this[i] = 29}
		   } 
		   return this
		}

		function isDate(dtStr){
			var daysInMonth = DaysArray(12)
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strDay=dtStr.substring(0,pos1)
			var strMonth=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			strYr=strYear
			if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
			if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
			for (var i = 1; i <= 3; i++) {
				if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
			month=parseInt(strMonth)
			day=parseInt(strDay)
			year=parseInt(strYr)
			if (pos1==-1 || pos2==-1){
				alert("O formato da data deve ser : dd/mm/aaaa")
				return false
			}
			if (strMonth.length<1 || month<1 || month>12){
				alert("Por favor, informe um męs válido")
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
				alert("Por favor, informe uma data válida")
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
				alert("Por favor, informe os 4 digitos do ano entre "+minYear+" e "+maxYear)
				return false
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
				alert("Por favor, informe uma data válida")
				return false
			}
		return true
		}
			
		function consisteCampos(consistirCPF){
				
			if( document.getElementById('nome').value == "" ){
				setMsgErro('Preencha o campo "Nome"!!!');
				return false;					
			}
				
			if( document.getElementById('email').value == "" ){
				setMsgErro('Preencha o campo "Email"!!!');
				return false;			
			}
			else{
				if( checkemail(document.getElementById('email').value) == false ){
					setMsgErro('Email inválido!!!');
					return false;			
				}
			}
				
			if( document.getElementById('dtnascimento').value == "" ){
				setMsgErro('Preencha o campo "Dt. Nascimento" !!!');
				return false;
			}
			else{
				if ( isDate(document.getElementById('dtnascimento').value) == false ) 
				{
					setMsgErro('Data de nascimento inválida !!!');
					return false;
				}
			}
			
			if(consistirCPF == "1"){
				if( document.getElementById('cpf').value == "" ){
					setMsgErro('Preencha o campo "CPF" !!!');
					return false;
				}
				else{
					if ( validaCPF(document.getElementById('cpf').value) == false ) 
					{
						setMsgErro('CPF inválido !!!');
						return false;
					}
				}
			}

			if( document.getElementById('cep').value == "" && document.getElementById('cidade').value == ""){
				setMsgErro('Preencha o campo "Cidade / Estado" ou "CEP" !!!');
				return false;
			}
			else{
				if ( validaCEP(document.getElementById('cep').value) == false && document.getElementById('cidade').value == ""){
					setMsgErro('CEP inválido !!!');
					return false;
				}
			}

			return true;
		}

		function setMsgErro(msg){
			document.getElementById ('divMsg').innerHTML = msg;
			//document.getElementById ('divMsg').style.visibility = 'visible';
			document.getElementById ('divMsg').style.display = '';
		}

		function enviar(considerCPF){
			if( consisteCampos(considerCPF) ){
				document.frmCadastro.submit();
			}
		}
		
		function hideDivMessages(){
			document.getElementById ('divMsg').style.display = 'none';
			//document.getElementById ('divExplicacao').style.display = 'none';			
		}

		function consisteDatasPesq(){
			if ( document.getElementById('opcoesDtNascimento').value == '><' ){
				if( isDate(document.getElementById('txtDtInicio').value) == false ){
					setMsgErro('Data Inicial inválida');
					return false;
				}
				if( isDate(document.getElementById('txtDtFim').value) == false ){
					setMsgErro('Data Final inválida');
					return false;
				}
			}
			else if(document.getElementById('opcoesDtNascimento').value != 'qq'){
				if( isDate(document.getElementById('txtDtInicio').value) == false ){
					setMsgErro('Data de nascimento inválida');
					return false;
				}
			}			
			return true;
		}

		function enviarPesquisa(){
			if ( consisteDatasPesq() == true ){
				document.frmPesqCadastro.IsPostBack.value = 1;
				document.frmPesqCadastro.submit();
			}
		}
		
		function excluirRegistro(idReg){
			document.frmPesqCadastro.IsPostBack.value = 1;
			document.frmPesqCadastro.acao.value = "del";
			document.frmPesqCadastro.idReg.value = idReg;
			document.frmPesqCadastro.submit();
		}

		function displayDtAux(optDtSel){
					
			if (optDtSel == 'qq'){
				document.getElementById('dtAux1').style.display = 'none';
				document.getElementById('dtAux2').style.display = 'none';
			}
			else if (optDtSel!='><'){
				document.getElementById('dtAux1').style.display = '';
				document.getElementById('dtAux2').style.display = 'none';					
			}
			else{
				document.getElementById('dtAux1').style.display = '';
				document.getElementById('dtAux2').style.display = '';
			}
		}
				
		function movePageResult(nskip){
			document.frmPesqCadastro.skip.value=nskip;
			enviarPesquisa();				
		}
		
		function changeResearchFields(){
			document.frmPesqCadastro.skip.value=0;			
		}
		