// this script is meant to work with formmail.php

// master function that is called on form submit
function validate(myform) {


// required field
if (myform.required) {
 var Req = myform.required.value.split(',') ;
 for(i=0;i<Req.length;i++) {
   if (myform[Req[i]].value.replace(/(^\s*)|(\s*$)/g,"")=='') {
     alert(Req[i] + " is required!");
     myform[Req[i]].focus();
     return false;
   }
 }
}

// email
if (myform.email) {
 if (!checkEmail(myform.email.value)) {
   alert("your email address is invalid!");
   myform.email.focus();
   return false;
 }
}


// if everything passes, continue with submit
return true;
}




// support functions
function checkEmail(email) 
{ 
   var splitted = email.match("^(.+)@(.+)$"); 
   if(splitted == null) return false; 
   if(splitted[1] != null ) 
   { 
     var regexp_user=/^\"?[\w-_\.]*\"?$/; 
     if(splitted[1].match(regexp_user) == null) return false; 
   } 
   if(splitted[2] != null) 
   { 
     var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/; 
     if(splitted[2].match(regexp_domain) == null) 
     { 
       var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/; 
       if(splitted[2].match(regexp_ip) == null) return false; 
     }// if 
     return true; 
   } 
return false; 
} 

