	
	function validaCadastro( Form ) {
		var error = new Array();

		if( Form.nome.value.trim() == '' ) {
			error.push('Nome');
		}
		
		if( Form.dt_nasc.value.trim() == '' ) {
			error.push('Data de Nascimento');
		}
		
		if( Form.sexo.selectedIndex == 0 ) {
			error.push('Sexo');
		}
		
		var cpf = Form.cpf.value.trim();
		var cpf = cpf.replace(".", "");
		var cpf = cpf.replace(".", "");		
		var cpf = cpf.replace("-", "");		
				
		if( cpf == '' ) {
			error.push('CPF');
		} else if( !isValidCPF( cpf ) ) {
			error.push('CPF Inválido');
		}
		
		if( Form.documento.value.trim() == '' ) {
			error.push('RG');
		}
		
		if( Form.cep.value.trim() == '' || Form.cep.value.length < 8) {
			error.push('CEP');
		}
		
		if( Form.logradouro.value.trim() == '' ) {
			error.push('Endereço');
		}
		
		if( Form.numero.value.trim() == '' ) {
			error.push('Número');
		}				
		
		if( Form.bairro.value.trim() == '' ) {
			error.push('Bairro');
		}
		
		if( Form.localidade.value.trim() == '' ) {
			error.push('Cidade');
		}
		
		if( Form.estado.selectedIndex == 0 ) {
			error.push('Estado');
		}

		if( Form.fone_ddd.value.trim() != '' || Form.fone_p1.value.trim() != '' || Form.fone_p2.value.trim() != '') {
			var notNumeric = !IsNumeric( Form.fone_ddd.value ) || !IsNumeric( Form.fone_p1.value ) || !IsNumeric( Form.fone_p2.value );
			if( Form.fone_ddd.value.trim().length < 2 || Form.fone_p1.value.length < 3 || Form.fone_p2.value.length != 4 ) {
				error.push('Telefone Inválido');
			} else if ( notNumeric ) {
				error.push('Telefone dever conter somente números!');
			}
		}	

		if( Form.email.value.trim() != '' && !isEmail( Form.email.value.trim() ) ) {
			error.push('E-mail Inválido');
		}			
		
		if( Form.codigo.value.trim() == '' ) {
			error.push('Digite o código da imagem no campo código!');
		}
		
		if(error.length > 0) {
			alertErrors( error.join('\n  - ') );
		} else {
			Form.submit();
			Form.disabled = true;
		}
	}
	
	function alertErrors( errors ) {
		alert( 'O campos abaixo são obrigatórios, ou não são válidos\n\n  - ' + errors );
	}
	
	function campoObrigatorio( campo ) {
		return 'O campo ' + campo + ' é Obrigatório!';
	}

	function IsNumeric(sText) {
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
	}

	function FormataCPF(Campo, teclapres) {

		var tecla = teclapres.keyCode;
		
		var vr = new String(Campo.value);
		vr = vr.replace(".", "");
		vr = vr.replace(".", "");
		vr = vr.replace("-", "");
	
		tam = vr.length + 1;
		
		if (tecla != 9 && tecla != 8)
			{
			if (tam > 3 && tam < 7)
				Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
			if (tam >= 7 && tam <10)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
			}
			
	}
	
	
	function FormataCEP(objeto, teclapres) {
		var tecla, tamanho;
		tecla = teclapres.keyCode;
		if (tecla != 8 && tecla != 16 && tecla != 9){
			tamanho = objeto.value.length;
			if(tamanho < 9) {
				if(tamanho == 5) {
					objeto.value = objeto.value + '-';
				}
			}
		}
	}
	
	function isValidCPF( c ) {
		return cpf( c );
	}

	
	//
	function isAlpha(strChar) {
	  var i, blnValid;
	
	  blnValid = false;
	  for (i = 0; i < strChar.length; i++) {
		if ((strChar.charAt(i) >= "a" && strChar.charAt(i) <= "z")
		|| (strChar.charAt(i) >= "A" && strChar.charAt(i) <= "Z") )
		blnValid = true;
	  }
	  return blnValid;
	}
	
	//===========================================================================
	//
	function aSplit(strString, charSep) {
	  var arrAux = new Array(), i, j;
	
	
	 if (charSep.length == 1) {
	   j = 0;
	   arrAux[j] = "";
	   for (i = 0; i < strString.length; i++) {
		 if (strString.charAt(i) != charSep) {
		   arrAux[j] = arrAux[j] + strString.charAt(i);
		 }
		 else {
		   j++;
		   arrAux[j] = "";
		 }
	   }
	
	   return arrAux;
	  }
	  else return NaN;
	}
	
	//===========================================================================
	//
	function isEmail(email) {
	   var Valid, strDomain, strUser, i, intCount;
	   var arrAux;
	
	   if (email == "") {
		   return false;
	   }
	   else {
		   Valid = false;
	
		   if (email.charAt(email.length - 1) == ".") {
			 email = email.substr(0, email.length - 1);
		   }
	
		   if (email.indexOf("@") > 0) {
			   strDomain = email.substr(email.indexOf("@") + 1, email.length - (email.indexOf("@") + 1));
			   strUser = email.substr(0, email.indexOf("@"));
	
			   arrAux = aSplit(strUser, ".");
	
		   intCount = -1;
		   for (i = 0; i <= arrAux.length - 1; i++) {
			 if (arrAux[i] > "" && arrAux[i].indexOf("@") == -1) {
				 intCount++;
			 }
		   }
	
		   if (intCount == arrAux.length - 1) Valid = true;
	
		   if (Valid) {
	
			 Valid = false;
			 arrAux = aSplit(strDomain, ".");
	
			   intCount = -1;
			   for (i = 0; i <= arrAux.length - 1; i++) {
	
				 if (arrAux[i] > "" && isAlpha(arrAux[i].charAt(0)) && arrAux[i].indexOf("@") == -1) {
				 intCount++;
				 }
			   }
	
			 if (intCount == arrAux.length - 1) Valid = true;
	
			 }
	
		   }
		   if (!Valid) {
			   return false;
		   }
		   else {
			   return true;
		   }
	
	   }
	}

