function validateValues ( what )
{
  var errors = '';
  var valid = true;

  for (var i=0, j=what.elements.length; i<j; i++)
  {
  	 what.elements[i].value = WholeTrim(what.elements[i].value);
    fieldValue  = what.elements[i].value;
    fieldLength = what.elements[i].value.length;
    fieldName   = what.elements[i].name;

    if ( fieldName == 'name' && fieldValue == '' )
    {
    	 valid = false;
    	 errors = errors + '> Je bent je naam vergeten in te vullen\n';
    }
    if ( fieldName == 'emal' && (fieldLength != 0) )
    {
    	if (fieldLength < 4 || echeck(fieldValue) == false)
    	{
        valid = false;
        errors = errors + '> Je hebt een fout in het emailadres gemaakt\n';
      }
    }
    if ( fieldName == 'mess' && fieldValue == '' )
    {
      valid = false;
      errors = errors + '> Je bent verplicht ook een berichtje achter te laten\n';
    }
  }
  if (!valid)
  {
    alert('U bent enkele velden vergeten in te vullen:\n\n' + errors);
    return false;
  }
  if ( valid )
  {
  	 //alert('return true...');
    return true;
  }
}

function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){return false}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false}
	if (str.indexOf(at,(lat+1))!=-1){return false}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false}
	if (str.indexOf(dot,(lat+2))==-1){return false}
	if (str.indexOf(" ")!=-1){return false}

	return true
}

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;       // Get length of string

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}

function WholeTrim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

/* // BACKUP BACKUP BACKUP
function validateValues( what )
{
    var valid = true;

    var checkBoxes = false;
    var checkboxChecked = false;

    var radioButtons = false;
    var radioChecked = false;

    for (var i=0, j=what.elements.length; i<j; i++) {
        myType = what.elements[i].type;
        if (myType == 'radio') {
           radioButtons = true;
           if (what.elements[i].checked) radioChecked = true;
        }
        if (myType == 'checkbox') {
           checkBoxes = true;
           if (what.elements[i].checked) checkboxChecked = true;
        }
        if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
           if (what.elements[i].value == what.elements[i].defaultValue) valid = false;
        if (myType == 'select-one' || myType == 'select-multiple')
           if (what.elements[i].selectedIndex == 0) valid = false;
    }

    if ((checkBoxes && !checkboxChecked) || (radioButtons && !radioChecked)) valid = false;

    if (!valid)
        alert('Form not completely filled');

    return valid;
} */
