﻿function IsEmailValid(email) {
	var re = "^([0-9a-zA-Z-._+&])+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
	return email.match(re);
}

function ValidateSalesForceForm() {
	var isValid = true;
	var allInputs = $(":input");

	allInputs.each(function(i) {
		var element = $(this);
		var theValue = $(element).val();

		if (element.attr("type") != "hidden") {
			element.removeClass("validation-error");

			var isNullOrEmpty = !theValue || theValue == "--None--";
			var selectTitle = element.attr("title");
			var theName = selectTitle.length > 0 ? selectTitle : element.attr("name");
			var isSystemField = theName.indexOf('$') >= 0;

			if (!isSystemField) {
				if (isNullOrEmpty || (theName == "email" && !IsEmailValid(theValue))) {
					//alert(theName + ' is invalid');

					element.addClass("validation-error");
					isValid = false;
				}
			}
		}
	});

	return isValid;
}
