// prepare the form when the DOM is ready 
$(document).ready(function() { 
    var options = { 
        //target:        '#EmailForm',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        dataType:  'html',         // 'xml', 'script', or 'json' (expected server response type) 
        clearForm: false,        // clear all form fields after successful submit 
       	resetForm: false,        // reset the form after successful submit 
 		success:   processHTML
		//error: processXml_Error
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
	};
    // bind form using 'ajaxForm' 
    $('#htmlForm').ajaxForm(options); 
});
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 	//alert('REDIRECT: \n\n' + $('[name=Redirect]').val());
	//alert('About to submit: \n\n' + queryString); 
 	$("#myForm").css("display", "none");
	$("#myForm_Thinking").css("display", "block");
    // here we could return false to prevent the form from being submitted; returning anything other than false will allow the form submit to continue 
    return true; 
}

function processHTML(responseHTML) { 
   	//alert('HELP: \n\n' + $('input[@name=Redirect]').fieldValue());
	if(responseHTML == "Success") {
		$("#myForm").css("display", "none");	
		$("#myForm_Success").css("display", "block");
		$("#myForm_Thinking").css("display", "none");
		$("#myForm_ErrorRow").css("display", "none");
	} else if(responseHTML == "Redirect") {
		window.location = $('[name=Redirect]').val();
	} else {
		$("#myForm").css("display", "block");	
		$("#myForm_Success").css("display", "none");
		$("#myForm_Thinking").css("display", "none");
		$("#myForm_ErrorRow").css("display", "block");
		$("#myForm_ErrorMessage").html(responseHTML);
	}
}
