function Enviar(fm) {
	e_mail=trim(fm.email.value);
	erro=0;

    if (e_mail=="") {
	   erro=1;
	   alert("Favor informar e-mail.");
	   
       fm.email.focus();
    }

	if (erro==0) {
		if (e_mail!="") {
	       if (val_email(e_mail)==1) {
		      erro=1;
		      alert("E-mail contém caracteres inválidos.");
	          fm.email.focus();
			  }
	       else	{
			  if (val_email(e_mail)==2) {
			     erro=1;
			     alert("E-mail não contém '@'");
		         fm.email.focus();
				 }
		      else {
			     if (val_email(e_mail)==3) {
			        erro=1;
					alert("E-mail contém @ em lugar inválido.");
		            fm.email.focus();
					}
		         else {
				    if (val_email(e_mail)==4) {
				       erro=1;
					   alert("E-mail não contém '.'");
		               fm.email.focus();
					   }
		            else {
					   if (val_email(e_mail)==5) {
					      erro=1;
					      alert("E-mail incompleto.");
		                  fm.email.focus();
						  }
		               else {
					      if (val_email(e_mail)==6) {
					         erro=1;
							 alert("E-mail incorreto.");
		                     fm.email.focus();
	                      }
					   }
					}
				 }
			  }         
		   }
		  }
		 }


 	if (erro==0) {	
		assunto=trim(fm.assunto.value);
   	 	if (assunto=="") {
		  erro=1;
	 	  alert("Favor informar o assunto do e-mail.");
     	  fm.assunto.focus();
    	}
	}	

	
	if (erro==0) {	
		msg=trim(fm.msg.value);
   	 	if (msg=="") {
		  erro=1;
	 	  alert("Favor informar o texto do e-mail.");
     	  fm.msg.focus();
    	}
	}	

   
	if (erro==0) {

       fm.action="/cgi-bin/envia_email.py";

	   fm.submit();
	}
	   
}


function val_email(email) 
{
 invalidChars = "/:,;"
 for   (i=0; i<invalidChars.length; i++) 
       {
       badChar = invalidChars.charAt(i)
       if (email.indexOf(badChar,0) > -1)
	      {
	      return 1;
	      }
	   }

	   atPos = email.indexOf("@",1)
       if (atPos == -1)
          {
		  return 2;
	      }

	   if (email.indexOf("@",atPos+1) > -1)
          {
		  return 3;
		  }

	   periodPos = email.indexOf(".",atPos)
       if (periodPos == -1)
          {
		  return 4;
		  }

	   if (periodPos+3 > email.length)
          {
		  return 5;
		  }

	   if
(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
       {}
       else
       {	
		 return 6;
	   }
}	

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

