/**
 * @author vsa
 */

 $(document).ready(function() {
	// get the contact form
	var form = $('.contactus form');
	// validate the form on the submit event
	form.bind('submit', function(){
		// set error state to default
		var error = 0;
		// get the name input
		var name = $(".contactus form input[name='name']");
		// check if the name input is empty
		if (name.val().length == 0) {
			// show the input error label
			name.parent().children('div').find('span.error').css('visibility', 'visible');
			// set error state to on
			error = 1;
		} else {
			// hide the input error label, if it's showing
			name.parent().children('div').find('span.error').css('visibility', 'hidden');
		}
		// get the e-mail input
		var email = $(".contactus form input[name='email']");
		// check if the email input is empty
		if (email.val().length == 0) {
			// show the input error label
			email.parent().children('div').find('span.error').css('visibility', 'visible');
			// set error state to on
			error = 1;
		} else {
			// hide the input error label, if it's showing
			email.parent().children('div').find('span.error').css('visibility', 'hidden');
		}
		// check if there are any errors
		if (error == 1) {
			// show the form error label
			$('.contactus form .submit span.error').css('visibility', 'visible');
			// prevent form from being submitted
			return false;
		} else {
			// hide the form error label, if it's showing
			$('.contactus form .submit span.error').css('visibility', 'hidden');
		}
	});	
});