String.prototype.trim = function() 
{
 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}
		
function checkformfield(formfield,name,length) 
{
  // get the string value from input
  var s = formfield.value;
  // trim the string value and put it into the variable
  formfield.value = s.trim();
  // check the length of the string value
  if(formfield.value.length<length)
  {
  	var message="Gelieve het veld: '"+name+"' in te vullen alvorens op VERSTUREN te klikken.";
  	alert(message);
  	return false;
  }
  return true;
}

function validateEmail(email)
{
  var teststr=email;
  var iserr=false;
  if (!teststr=='')
  { 
      // there must be >= 1 character before @, so we
      // start looking at character position 1 
      // (i.e. second character)
      var i = 1;
      var sLength = teststr.length;
      // look for @
      while ((i < sLength) && (teststr.charAt(i) != "@"))
      { 
         i++;
      }
      if ((i >= sLength) || (teststr.charAt(i) != "@")) 
      {
         iserr=true;
      }
      else 
      {
         i += 2;
         // look for .
         while ((i < sLength) && (teststr.charAt(i) != "."))
         { 
            i++;
         }
         // there must be at least one character after the .
         if ((i >= sLength - 1) || (teststr.charAt(i) != ".")) 
         {
            iserr = true;
         }
      }
   }
   if (iserr)
   {
      alert('Het e-mailadres dat u invulde blijkt niet geldig te zijn, gelieve dit even te controleren.');
	  return false;
   }
   else
   {
      return true;
   }
};

function checkvalues() 
{
  if(!checkformfield(document.request_info.contact,"Contact persoon",5))
  	return false;
  if(!checkformfield(document.request_info.adres,"Adres",5))
  	return false;
  if(!checkformfield(document.request_info.postcode,"Postcode",4))
  	return false;
  if(!checkformfield(document.request_info.plaats,"Plaats",2))
  	return false;
  if(!checkformfield(document.request_info.email,"E-mail",6))
  	return false;
  if(!validateEmail(document.request_info.email.value))
  	return false;
  return true;
}
