function clearForm(textfield){
	if ( textfield.defaultValue==textfield.value )
		textfield.value = "";
}

function validateEmpty(field) {
	var error = "";
	if (field.value.length == 0 || field.value == field.defaultValue) {
		field.style.background = '#ffff99'; 
		error = "* You didn't fill in your "+field.name+".\n";
	} 
	else {
		field.style.background = '#fff';
	}
	return error;
}

function validateForm(form){
	var reason = "";
	reason += validateEmpty(form.name);
	reason += validateEmail(form.email);
	reason += validateEmpty(form.comments);
	  if (reason != "") {
	    alert("Some fields need correction:\n" + reason);
	    return false;
	  }
	  return true;
}

function validateEmail(field) {
	var error="";
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

	if (field.value == "" || field.value == field.defaultValue) {
		field.style.background = '#ffff99';
		error = "* You didn't enter your email address.\n";
	}
	else if (!emailFilter.test(field.value)) {
		field.style.background = '#ffff99';
		error = "* Please enter a valid email address.\n";
	} 
	else if (field.value.match(illegalChars)) {
		field.style.background = '#ffff99';
		error = "* The email address contains illegal characters.\n";
	} 
	else {
		field.style.background = '#fff';
	}
	return error;
}