var toggleModal = function (elem) {
	$(elem).fadeToggle(400);
};
var clearPage = function () {
	$("div.page").hide();
};
var validateForm = function (form) {
	return validate($(form).find(":input"));
};
var validate = function (elem) {
	var valid = true;
	var dataTypeRegEx = {
		"zipCode" : /\b[0-9]{5}\b/,
		"phone" : /\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b/,
		"email" : /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/
	}
	$(elem).filter('.validate').each(function () {
		$(this).siblings(".invalid, .valid").hide();
		// Check if value present
		if ($(this).val() === '' || ($(this).is(":checkbox") && !$(this).attr('checked'))) {
			$(this).siblings("span.invalid, .invalid.required").show();
			valid = false;
		}
		// Check if proper data type
		// Email
		else if ($(this).hasClass("email") && !dataTypeRegEx.email.test($(this).val())) {
			$(this).siblings("span.invalid, .invalid.format").show();
			valid = false;
		}
		// Zip Code
		else if ($(this).hasClass("zipCode") && !dataTypeRegEx.zipCode.test($(this).val())) {
			$(this).siblings("span.invalid, .invalid.format").show();
			valid = false;
		}
		// Indicate valid
		else {
			$(this).siblings("span.valid").show();
		}
	});
	return valid;
};
var resetForm = function (form) {
	$(form).find(":input:not(:button, :submit, :hidden)").each(function () {
		if ($(this).is(":checkbox")) {
			$(this).removeAttr('checked');
		} else {
			$(this).val('');
		}
		$(this).siblings(".invalid, .valid").hide();
	});
}
var html = {
	error : {
		required : function () {
			var html = '<label class="error">Required</label>'
		}
	}
};
