function Form_Validator(theForm){

//**********************************
//* Função que chama as validações *
//**********************************

//ADICIONAR AS FUNÇÕES DAS VALIDAÇÕES NESTE ESPAÇO

	//****** CAMPO NOME ******
	// verifica se o campo está vazio
	if (theForm.nome.value == false){

		alert("Preencha o campo Nome.");
		theForm.nome.focus();
		theForm.nome.select();
		return (false);

	  }else{

	// verifica se o campo contêm números
		var contnome = theForm.nome.value;

		for (var i = 0; i < 10; i = i + 1){

			contnome.indexOf(i);
			if (contnome.indexOf(i) != -1){
			alert("O campo Nome não aceita números.");
			theForm.nome.focus();
			theForm.nome.select();
			return (false);

			}
		}
	}

	//****** CAMPO ENDEREÇO ******
	// verifica se o campo está vazio
	if (theForm.endereco.value == false){
    alert("Preencha o campo Endereço.");
    theForm.endereco.focus();
    return (false);
	}

	//****** CAMPO CEP ******

	// Valida o primeiro campo

	// verifica se o campo está vazio
	var cont = theForm.cep.value

	if (theForm.cep.value == "")
	   {
		 alert("Preencha o campo CEP.");
		 theForm.cep.focus();
		 theForm.cep.select();
		 return (false);
	   }

	// verifica se existe espaço em branco no campo
	x = cont.indexOf(" ")
	if (x != -1){

		 alert("O campo CEP não aceita espaços em branco.");
		 theForm.cep.focus();
		 theForm.cep.select();
		 return (false);
	}

  	//verifica se o campo só contêm números
	if (theForm.cep.value != false) {
			// verifica se todos os caracteres digitados são numeros
			var checkOK = "0123456789";
			var checkStr = theForm.cep.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
			for (i = 0;  i < checkStr.length;  i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j)) break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
				allNum += ch;
			}
			if (!allValid)
			{
				alert("O campo CEP só pode conter números, não use o separador (-), nem letras. Ex.: 00000111.");
				theForm.cep.focus();
				theForm.cep.select();
				return (false);
			}
		}

	// verifica se o campo contêm menos de 8 caracteres
	if (theForm.cep.value.length < 8)
		{
		alert("O campo CEP deve ter 8 dígitos.");
		theForm.cep.focus();
		theForm.cep.select();
		return (false);
		}
		
//****** CAMPO CIDADE ******
// verifica se o campo está vazio
if (theForm.cidade.value == false){
   alert("Preencha o campo Cidade.");
   theForm.cidade.focus();
   return (false);
}	

//****** CAMPO ESTADO ******
// verifica se o campo está vazio
if (theForm.estado.value == false){
   alert("Preencha o campo Estado.");
   theForm.estado.focus();
   return (false);
}
 
// verifica se o campo contêm menos de 2 caracteres
if (theForm.estado.value.length < 2){
	alert("O campo Estado deve ter 2 dígitos. Ex.: SP.");
	theForm.estado.focus();
	theForm.estado.select();
	return (false);
}

	//****** CAMPO DDD ******

	// verifica se o campo está vazio
	var cont = theForm.ddd.value

	if (theForm.ddd.value == "")
	   {
		 alert("Preencha o campo DDD.");
		 theForm.ddd.focus();
		 theForm.ddd.select();
		 return (false);
	   }

	// verifica se existe espaço em branco no campo
	x = cont.indexOf(" ")
	if (x != -1){

		 alert("O campo DDD não aceita espaços em branco.");
		 theForm.ddd.focus();
		 theForm.ddd.select();
		 return (false);
	}

	// verifica se o campo contêm menos de 2 caracteres
	if (theForm.ddd.value.length < 2)
		{
		alert("O campo DDD deve conter 2 dígitos.");
		theForm.ddd.focus();
		theForm.ddd.select();
		return (false);
		}

  	//verifica se o campo só contêm números
	if (theForm.ddd.value != false) {
			// verifica se todos os caracteres digitados são numeros
			var checkOK = "0123456789";
			var checkStr = theForm.ddd.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
			for (i = 0;  i < checkStr.length;  i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j)) break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
				allNum += ch;
			}
			if (!allValid)
			{
				alert("O campo DDD só pode conter números. Ex.: 11");
				theForm.ddd.focus();
				theForm.ddd.select();
				return (false);
			}
		}	

//****** CAMPO TELEFONE ******
// verifica se o campo está vazio
var cont = theForm.telefone.value

if (theForm.telefone.value == "")
   {
	 alert("Preencha o campo Telefone.");
	 theForm.telefone.focus();
	 theForm.telefone.select();
	 return (false);
	}

// verifica se existe espaço em branco no campo
x = cont.indexOf(" ")
if (x != -1){
	alert("O campo Telefone não aceita espaços em branco.");
	theForm.telefone.focus();
	theForm.telefone.select();
	return (false);
}

// verifica se o campo contêm menos de 7 caracteres
if (theForm.telefone.value.length < 7)
{
	alert("O campo Telefone deve ter no minimo 7 dígitos.");
	theForm.telefone.focus();
	theForm.telefone.select();
	return (false);
}

//verifica se o campo só contêm números
if (theForm.telefone.value != false) {
	// verifica se todos os caracteres digitados são numeros
	var checkOK = "0123456789";
	var checkStr = theForm.telefone.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j)) break;
				if (j == checkOK.length)
			{
			allValid = false;
			break;
		}
	allNum += ch;
}

if (!allValid)
	{
	alert("O campo Telefone só pode conter números, não use o separador (-), nem letras. Ex.: 2222222");
	theForm.telefone.focus();
	theForm.telefone.select();
	return (false);
	}
}	

//****** CAMPO EMAIL ******
// verifica se o campo está vazio
if (theForm.email.value == false){
	alert("Preencha o campo E-mail.");
	theForm.email.focus();
	return (false);
}

var texto = theForm.email.value
// verifica se o campo não está vazio.
if (texto != false) {

//VERIFICA SE EXISTE "@" NO E-MAIL
pos = texto.indexOf("@")
if (pos == -1 || pos < 2){
	alert("Preencha o campo E-mail corretamente.");
	theForm.email.focus();
	theForm.email.select();
	return(false);
	} else {

		//VERIFICA SE EXISTE "."(PONTO) NO E-MAIL
		pos = texto.indexOf(".")
		if (pos == -1 || pos == 0) {
			alert("Preencha o campo E-mail corretamente.");
			theForm.email.focus();
			theForm.email.select();
			return (false);
		} else {

			ponto = texto.indexOf(".")
			tamanho = texto.length;
			parte = texto.substring(ponto,tamanho);

			//VERIFICA SE EXISTE MAIS DE 2 CARACTERES APÓS O "."(PONTO) NO E-MAIL
			if (parte.length < 3){
				alert("Preencha o campo E-mail corretamente.");
				theForm.email.focus();
				theForm.email.select();
				return (false);
			}

		}
	}
}	

}
