var options = { 
	beforeSubmit:  validate,  // pre-submit callback 
	success:       showResponse,  // post-submit callback 
	resetForm: true        // reset the form after successful submit 
}; 
		
jqnc('#contact_us').ajaxForm(options); 
				
function showResponse(responseText, statusText){
	jqnc('#success').animate({ opacity: "show" }, "fast")
}
				
function validate(formData, jqForm, options) {
	jqnc("p.error").animate({ opacity: "hide" }, "slow");
			 
	var nameValue = jqnc('input[name=Name]').fieldValue(); 
	var emailValue = jqnc('input[name=Email]').fieldValue();
	var messageValue = jqnc('textarea[name=Message]').fieldValue(); 
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var correct = true;
	
	if (!nameValue[0]) {
		jqnc("p.error.wrong_name").animate({ opacity: "show" }, "slow");
		correct = false;
	}
	
	if (!emailValue[0]) {
		jqnc("p.error.wrong_email").animate({ opacity: "show" }, "slow");
		correct = false;
	} else if(!emailReg.test(emailValue[0])) {
		jqnc("p.error.wrong_email").animate({ opacity: "show" }, "slow");
		correct = false;
	}
	
	if (!messageValue[0]) {
		jqnc("p.error.wrong_message").animate({ opacity: "show" }, "slow");
		correct = false;
	}
	
	if (!correct) {return false;}
} 	

				
jqnc("p#success").click( function () { 
	jqnc(this).animate({ opacity: "hide" }, "slow"); 
});								 