$(function() {
	function runvalidateform(obj) {
		var form = obj.parents("form");
		var checkmail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var do_submit = true;
		form.find("*:input[rel]").each(function() {
			var input = $(this).attr("rel").split(";");
			if (do_submit === false || !input["1"]) {
			}
			else if (input["0"] == "checkmail" && !checkmail_filter.test($(this).val())) {
				do_submit = false;
				alert(input["1"]);
				if (input["2"] == "true") {
					$(this).focus();
					$(this).select();
				}
				return ;
			}
			else if (input["0"] == "checkinput" && !$(this).val()) {
				do_submit = false;
				alert(input["1"]);
				if (input["2"] == "true") {
					$(this).focus();
				}
				return ;
			}
			else if (input["0"] == "compairinput" && $('#'+input["1"]).val()
				&& (!$(this).val() || $(this).val() != $('#'+input["1"]).val())) {
				do_submit = false;
				alert(input["2"]);
				if (input["3"] == "true") {
					$(this).focus();
				}
				return ;
			}
			else if (input["0"] == "checkcheckboxs") {
				var checkbox = $(this);
				var loop_checkbox = 0;
				var do_checkbox = false;
				form.find("*:input[type='checkbox']").each(function(loop) {
					if (do_checkbox === false) {
						if (($(this).attr("name") == checkbox.attr("name") || loop_checkbox > 0)
							&& loop_checkbox < input["2"] && $(this).attr("checked") === true) {
							do_checkbox = true;
							loop_checkbox++;
						}
					}
				});
				if (do_checkbox === false) {
					do_submit = false;
					alert(input["1"]);
					if (input["3"] == "true") {
						$(this).focus();
					}
					return ;
				}
			}
			else if (input["0"] == "checkcheckbox" && $(this).attr("checked") === false) {
				do_submit = false;
				alert(input["1"]);
				if (input["2"] == "true") {
					$(this).focus();
				}
				return ;
			}
		});
		if (do_submit === true) {
			form.submit();
			return ;
		}
	}
	$("*[rel='validateform']").click(function() {
		runvalidateform($(this));
	});
	$("*:input[rel]").keypress(function(e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
			runvalidateform($(this));
			return false;  
		} else {  
			return true;  
		}  
	});
});