// prepare the form when the DOM is ready 
function initForm(){
	if ($('#myForm').length) {
	//	$('#myForm').ajaxForm({ beforeSubmit: validate }); 
	   	
		// bind to the form's submit event 
		$('#myForm').submit(function(){
			// inside event callbacks 'this' is the DOM element so we first 
			// wrap it in a jQuery object and then invoke ajaxSubmit 
			$(this).ajaxSubmit({ beforeSubmit: validate,success:showResponse });
			
			// !!! Important !!! 
			// always return false to prevent standard browser submit and page navigation 
			return false;
		});
	} 
} 
// pre-submit callback 
function validate(formData, jqForm, options) { 
    var form = jqForm[0];  
	var valid=true;   
	if (!form.name.value) {
	   $('#pname').addClass('red');
	   valid=false;     
	}else $('#pname').removeClass('red');
	
	if (!form.email.value ) {
	   $('#pemail').addClass('red');
	   valid=false;     
	}else $('#pemail').removeClass('red');
	
	if (!form.comment.value ) {
	   $('#pcomment').addClass('red');
	   valid=false;     
	} else $('#pcomment').removeClass('red');
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    return valid; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
   $('#formbox').hide();
   $('#fname').html($("input[name='name']").val()+',');
   $('#feedback').show();
} 

