$(document).ready(function(){
	
	
	$('.go').click(function(){	
		$("#form_contact_us").submit();
		return false;
	});
	
	
	$('#form_contact_us').ajaxForm({ 
			beforeSubmit: validate_contact_us, 
			success: show_response_contact_us
	});
	
	function validate_contact_us () {

		var msg = "";
		
		// reset error state for inputs
		$("input").each(function(){
			$(this).removeClass('error');
		});
		
		$('#notice').addClass('error').html(msg).show();
		$('#confirmation').hide();
		

		if (!$('#email').val()){
			$('#email').addClass('error');
			msg += messages["email_missing"];			
		} else {
			var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!regex.test($('#email').val())){ 
				$('#email').addClass('error');
				msg += messages["email_invalid"];			
			}
		}
	
		if (!$('#subject').val()){
			$('#subject').addClass('error');
			msg += messages["subject_missing"];
		} 
	
		if (!$('#message_txt').val()){
			$('#message_txt').addClass('error');
			msg += messages["message_missing"];
		} 
		
		if(msg == ""){
			return true;
		} else {
			$('#notice').addClass('error').html(msg).show();
			return false;
		}
		// validate_contact_us
	}
	
	
	function show_response_contact_us (response) {
		if(response == 1){
			response = messages["contact_success"];
			
			$('#form_contact_us').hide();
			$('#confirmation').show();
			$('#message').addClass('error').html(response).show();
		
		} else {
			
			response = messages["contact_fail"];
			$('#notice').addClass('error').html(response).show();
			$('html, body').animate({scrollTop:0}, 'slow'); 
		}
	} // show_response_contact_us
	
	
	// end doc ready
});