/* Validate Forms */
function validate_text(objField, this_value, this_name) 
{
	if (this_value == '') 
	{	
		if (objFocus == null || objFocus == '') objFocus = objField;
		return this_name+'\n';
	} 
	else 
	{
		return '';
	}
}

function validate_email(this_value) {
	var re = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if (!re.test(this_value)) {
		return 'Invalid email address \n';
	} else {
		return '';
	}
}

function display_error_msg(strErrorMsg) 
{
	alert('Error on the following field/s: \n' + strErrorMsg);
	if (objFocus != null && objFocus != '') objFocus.focus();
	return true;
}

objFocus = null;
function validate_contact_form(objForm)
{
	strErrorMsg = ''
	strErrorMsg += validate_text(objForm.txtName, objForm.txtName.value, 'Name');
	strErrorMsg += validate_email(objForm.txtEmail.value);
	strErrorMsg += validate_text(objForm.txtPhoneNo, objForm.txtPhoneNo.value, 'Telephone No.');
	strErrorMsg += validate_text(objForm.txtMessage, objForm.txtMessage.value, 'Message');
	if (strErrorMsg != '') 
	{
		display_error_msg(strErrorMsg);
		return false
	}
	else
	{
		return true
	}	
}

