function ProcessForm(fForm, sListId, sData)
{
   var bReturn = false;
   fForm.list.value = sListId;                 // the number of the list to be added to
   fForm.user1.value = window.location.href;   // custom field 1 is the calling page
   fForm.user2.value = sData;               // this is the version of the page, discount code etm
   bReturn = ValidateForm( fForm.email.value, fForm.fname.value );
   return bReturn;
}

function ValidateForm(psEmail, psName)
{
   var bReturn = true;
   var sEmail, sName;

   sName = trimAll( psName );
   if (sName.length <= 0)
   {
      bReturn = false;
      alert ("Please enter your first name" );
   }
   else
   {
      sEmail = trimAll( psEmail )
      bReturn = validateEmail( sEmail );
      if ( bReturn == false )
      {
         alert( "Please enter a valid email address" );
      }
   }
   return bReturn;
}

function trimAll(sString) 
{
   while (sString.substring(0,1) == ' ')
   {
      sString = sString.substring(1, sString.length);
   }
   while (sString.substring(sString.length-1, sString.length) == ' ')
   {
      sString = sString.substring(0,sString.length-1);
   }
   return sString;
}

function validateEmail(email)
{
    if(email.length <= 0)
   {
     return false;
   }
    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;
}