var W3CDOM = (document.getElementsByTagName && document.createElement);

window.onload = function () {
	document.forms[0].onsubmit = function () {
		return validate()
	}
}
/*
function validEmail(email) {
  var emailReg = "[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$";
  var regex = new RegExp(emailReg);
  return regex.test(email);
}
*/
function validate() {
	var chkReq = new Array ("Name","Phone");
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[0].elements;

	for (i=0;i< chkReq.length; i++)
	{
	var chkThis = chkReq[i];
	if (x[chkThis].value == "") {
	writeError(x[chkThis],'This field is required');
	}
	}


/*	if (!validEmail(x['Email'].value))
		writeError(x['Email'],'This is not a valid email address');
	*/
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (!validForm)
	return false;
}

function writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		obj.onchange = removeError;
		var sp = document.createElement('span');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError()
{
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}