function isMail(mailField){
  strMail = mailField.value;
  var re = new RegExp;
  re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var arr = re.exec(strMail);
  if (arr == null)
    return(false);
  else
    return(true);
}

function minLen(txtField, minVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l < minVal)
    return(true);
  else
    return(false);
}

function maxLen(txtField, maxVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l > maxVal)
    return(true);
  else
    return(false);
}

function isBlank(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}

function isSelectedZero(txtField){
  selected = txtField.selectedIndex;
  if (selected == 0)
    return(true);
  else
    return(false);
}

function isNumber(txtField){
  numExp = txtField.value;
  if (isNaN(numExp) || (numExp.length == 0))
    return (false);
  else
    return(true);
}


function valida(theForm){
					
					if (isBlank(theForm.nome)){
					    alert("Preencha o campo \"Nome\".");
						document.getElementById("nome").focus();
						return false;
					}					
					if (isBlank(theForm.mail)){
              		alert("Preencha o campo \"E-mail\".");
					document.getElementById("mail").focus();
             		return false;
         		   	}	
										
          			else if (!isMail(theForm.mail)) {
            	  	alert("Formato incorreto de E-mail.");
					document.getElementById("mail").focus();
					document.getElementById("mail").value = '';
             	 	return false;
          	 	 	}
					if (isBlank(theForm.fone)){
						alert("Preencha o campo \"Telefone\".");
						document.getElementById("fone").focus();
						return false;
					}
					
					if (!isNumber(theForm.fone)){
              		alert("Preencha o campo \"Telefone\" (apenas com números).");
					document.getElementById("fone").focus();
					document.getElementById("fone").value = '';
             		return false;
            		}	
					
					if (isBlank(theForm.comentarios)){
					  alert("Preencha o campo \"Comentários\".");
					  document.getElementById("comentarios").focus();
					  return false;
					}				
					 		
			 return true;
} 
