
function validateEmail(emailAddress)
{
  var emailRegexp = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
  return emailRegexp.test(emailAddress);
}

function check_form()
{
  var fields = new Array('start_date','end_date','persons','company','name','address','address_more','zip','city','email','email_confirm','message');
  var i = new Number();
  var tmp = new String();

  for(i = 0; i < fields.length; i++)
  {
	// Trim the form fields
	if(document.getElementById(fields[i]))
	{
		var tmp = new String(document.getElementById(fields[i]).value);
		tmp = tmp.replace('/^\s+|\s+$/g', '');
		document.getElementById(fields[i]).value = tmp;
	}
  }

  tmp = document.getElementById('start_date').value;
  if(!tmp.match(/^\d\d\/\d\d\/\d\d\d\d$/))
  {
	document.getElementById('start_date').focus();
	alert('The date is malformed, Please use the date selector (click on the calendar icon).');
	return false;	  
  }
  
  if(document.getElementById('end_date'))
  {
  	tmp = document.getElementById('end_date').value;
  	if(!tmp.match(/^\d\d\/\d\d\/\d\d\d\d$/))
  	{
		document.getElementById('end_date').focus();
		alert('The date is malformed, Please use the date selector (click on the calendar icon).');
		return false;	  
  	}  
  }
  
  // Check the req fields
  if(!document.getElementById('start_date').value)
  {
	document.getElementById('start_date').style.backgroundColor = "#FF0000";
	document.getElementById('start_date').focus();
	alert('Please select the Date.');
	return false;
  }

  if(!document.getElementById('name').value)
  {
	document.getElementById('name').style.backgroundColor = "#FF0000";
	document.getElementById('name').focus();
	alert('Please enter your name and press the Send button again.');
	return false;
  }

  if(!document.getElementById('email').value)
  {
	document.getElementById('email').style.backgroundColor = "#FF0000";
	document.getElementById('email').focus();
	alert('Please enter your email address and press the Send button again.');
	return false;
  }

  if(!document.getElementById('email_confirm').value)
  {
	document.getElementById('email_confirm').style.backgroundColor = "#FF0000";
	document.getElementById('email_confirm').focus();
	alert('Please confirm your email address and press the Send button again.');
	return false;
  }

  if(document.getElementById('email').value != document.getElementById('email_confirm').value)
  {
	document.getElementById('email').style.backgroundColor = "#FF0000";
	document.getElementById('email_confirm').style.backgroundColor = "#FF0000";
	document.getElementById('email_confirm').focus();
	alert("Please verify the email addresses you entered!\nThey are not the same!");
	return false;
  }

  if(!validateEmail(document.getElementById('email').value))
  {
	document.getElementById('email').style.backgroundColor = "#FF0000";
	document.getElementById('email').focus();
	alert('Please check your email address, it is malformed and press the Send button again.');
	return false;	  
  }
  
  return true;
}

