jQuery(function() {
    jQuery("form.formval input.formval_title").each(function()
	{
		this.onfocus = function() { if (this.value == this.alt) this.value = ''; }
		this.onblur = function() { if (this.value == '') this.value = this.alt; }
	});
});

function validateForm(formId)
{
	form = jQuery("#" + formId);
	message = "";
    jQuery("input.formval_mandatory", form).each(function() {
		if (this.value == '' || this.value == this.alt)
		{
			message = "Please enter a value for the '" + this.alt + "' field.";
			return false;
		}
	});
	if (message)
	{
		alert(message);
		return false;
	}

	jQuery("input.formval_phone", form).each(function() {
		// Phone number should contain 10 digits, or be empty
		if (this.value == '' || this.value == this.alt)
			return true;

		var m = this.value.match(/[0-9]/g);
		if (!m || m.length != 10)
		{
			message = "Please fill in your phone number in the following format:\r\n\r\n" +
				  "(719) 555-1234";
			return false;
		}
	});
	if (message)
	{
		alert(message);
		return false;
	}

	return true;
}

