
var $j = jQuery.noConflict();

$j(function() {

	// comment next lines to disable features

	if ($j("form#contact").length > 0) contactForm(); // initialize javascript validators for the contact form

});


// functions


function getMeta($name) {
	return $j("meta[name=" + $name + "]").attr('content');
}

function contactForm() {

	$j(".input", "form#contact").blur(function() { validateInput($j(this)); }); // validate when unfocus

	$j("#submit", "form#contact").click(function() { // validate on submit
		$j(".input", "form#contact").each(function() { validateInput($j(this)); })
		if (!isFormValid())
			return false;
	});

}

function isFormValid() {

	return $j(".input.incorrect", "form#contact").length > 0 ? false : true;

}

function validateInput(obj) {

	var id = obj.attr("id");
	var correct = false;

	if (id == "email") { // email validator
		if (obj.val().match(/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/))
			correct = true;
	}
	else if (id == "message") { // message validator
		if (obj.val().replace(/(^\s+)|(\s+$)/g, "") != "")
			correct = true;
	}

	obj.removeClass("correct incorrect"); // clearing
	if (correct) {
		obj.addClass("correct");
	}
	else {
		obj.addClass("incorrect");
	}

}