function validaForm(){
         d = document.cadastro;
         //validar nome
         if ((d.nome.value == "")&&(d.razaosocial.value == "")){
                   alert("O campo 'Nome' deve ser preenchido!");
                   d.nome.focus();
                   return false;
         }
         //validar CPF
         if (d.cpf.value == ""){
                   alert("O campo 'CPF' deve ser preenchido!");
                   d.cpf.focus();
                   return false;
         }
         
         if (d.cpf.value != ""){
			   var cpf = d.cpf.value;
			   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
			   if(!filtro.test(cpf)){
			     alert("CPF inválido. Tente novamente.");
			     d.cpf.focus();
				 return false;
			   }
			   
			   cpf = remove(cpf, ".");
			   cpf = remove(cpf, "-");
			    
			   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
				  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
				  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
				  cpf == "88888888888" || cpf == "99999999999"){
				  alert("CPF inválido. Tente novamente.");
				  d.cpf.focus();
				  return false;
			   }
			
			   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))){
				 alert("CPF inválido. Tente novamente.");
				 d.cpf.focus();
				 return false;
			   }
			   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))){
			     alert("CPF inválido. Tente novamente.");
			     d.cpf.focus();
				 return false;
			   }
         }
         
         
         
           //validar login
         if (d.login.value == ""){
                   alert("O campo 'Login' deve ser preenchido!");
                   d.login.focus();
                   return false;
         }
         //validar senha
         if (d.senha.value == ""){
                   alert("O campo 'Senha' deve ser preenchido!");
                   d.senha.focus();
                   return false;
         }
         //validar Confirmacao de Senha
         if (d.senha2.value == ""){
                   alert("O campo 'Confirmação de Senha' deve ser preenchido!");
                   d.senha2.focus();
                   return false;
         }
         //validar Senha = Confirmação de Senha
         if (d.senha.value != d.senha2.value){
                   alert("A Confirmação de Senha tem que ser igual a Senha desejada!");
                   d.senha2.focus();
                   return false;
         }
         //validar email
         if (d.email.value == ""){
                   alert("O campo 'Email' deve ser preenchido!");
                   d.email.focus();
                   return false;
         }
         //validar email(verificao de endereco eletrônico)
         parte1 = d.email.value.indexOf("@");
         if (!(parte1 >= 3)) {
                   alert ("O campo 'Email' deve ser conter um endereco eletronico!");
                   d.email.focus();
                   return false;
         }
         //validar Confirmacao de Email
         if (d.confirmaemail.value == ""){
                   alert("O campo 'Confirmar Email' deve ser preenchido!");
                   d.confirmaemail.focus();
                   return false;
         }
          //validar Email = Confirmacao de Email
         if (d.email.value != d.confirmaemail.value){
                   alert("O campo 'Confirmar Email' necessariamente tem que ser igual ao campo 'Email'!");
                   d.confirmaemail.focus();
                   return false;
         }
         //validar telefone
         if (d.telefone.value == ""){
                   alert ("O campo 'Telefone' deve ser preenchido!");
                   d.telefone.focus();
                   return false;
         }
         //validar telefone
         if (d.cidade.value == ""){
                   alert ("O campo 'Cidade' deve ser preenchido!");
                   d.cidade.focus();
                   return false;
         }
	     //validar telefone
	     if (d.UF.value == ""){
                 alert ("O campo 'Estado' deve ser preenchido!");
                 d.UF.focus();
                 return false;
         }
         
        return true;
}

 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }
