
function StrTrim(aString) 
{
  aString = aString.replace( /^\s+/g, "" );  // stanga
  return    aString.replace( /\s+$/g, "" );  // dreapta
}


function ValidateEmail(adres) 
{   	
   adres= StrTrim(adres);
   var at=adres.indexOf("@");   
        
   // 1. verify if input string contins '@' char once   
   if(  at== -1 || (adres.lastIndexOf("@")!== at)  )   {
   	  alert ("The email address is invalid! Please check the '@' character.") 
	  return false }
	  
   // 2. verify if input string contins '.' char 	  
   if(  adres.indexOf(".")== -1  )   {
   	  alert ("The email address is invalid! Plese check the '.' character") 
	  return false }
	  
   // 3) verify substrings against invalid chars
   if ( adres.indexOf(" ")> -1 || adres.indexOf(",")> -1 || adres.indexOf("[")> -1 || adres.indexOf("]")> -1 || adres.indexOf(";")> -1 || adres.indexOf("'")> -1 || adres.indexOf("/")> -1 || adres.indexOf("\\")> -1)   {
   	  alert ("Invalid chars in your email address!") 
	  return false }
	  
	  
   // 4. if yes, split the input string in 3 substring	  
   var part1= adres.substring (0, at);       // find username in email address         (MyEmail)   
   var part2= adres.substring (at+1);        // this is the ramining of the string     (Gmail.com)
   var dot1 = part2.indexOf(".");            // this is the position of the first 'dot' char AFTER the @
   var part3= part2.substring (dot1+1);	     // in the ramining of the string we look tor the domain portion  (com)
       part2= part2.substring (0, dot1);     // finally, we get the email provider  (Gmail)
   
   //debug: 	   
   //document.writeln (part1+ "<br />");
   //document.writeln (part2+ "<br />");   
   //document.writeln (part3+ "<br />");      
      	 
   // 5. check the substrings - all should be at leas 2 or 3 chars long
   if (  part1.length< 3  ||  part2.length< 2  ||  part3.length< 2 )   {
   	  alert ("Length of your email address is not right !") 
	  return false }
 return true
}




function ValidateUserInp() {
    var sEmail= document.form1.sEmail;
	var sComm = document.form1.sMessage;
	
	if (sEmail.value== "")  
	  {
		alert("The email field is empty! Please enter a valid email address to continue.");
		return false
	  }
	
	if (sComm.value== "")  
	  {
		alert("Please enter your comments.");
		return false
	  }
	  	
	if (ValidateEmail (sEmail.value) == false) 
	  {
		return false
	  }

 //alert ("Thank you");
 return true
}
 
 
 
   
