(function($){
	$(document).ready(function(){
		
		$('form.validate-js').submit(function(){
			var error = false;
			var error_field = false;
			try{
				$('input, textarea, select', this).each(function(){
					if( !error && (this.type == 'text' || this.nodeName.toLowerCase() == 'textarea' || this.nodeName.toLowerCase() == 'select' ) ){
						if( !this.value ){
							error = 'You must fill in ' + this.title;
							error_field = this;
							}
						}
				});
				
				if(error){
					error_field.focus();
					alert(error);
					return false;
					}
				return true;
			} catch(e){
				return true;
			};
		});
		
		
		$.get('contact_form/last-sent.php', {}, function(text){
			if( text == 'Error!' )
				$('form.validate-js').css('display', 'none').parent().append('<h2>Error!</h2><p>This form was already sent in the last hour. Please try again later.</p>');
				
		});
		
		$('.go-back').click(function(){
			window.history.go(-1);
			return false;
		});
		
	});
})(jQuery);