// 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: true,        // clear all form fields after successful submit 
       	resetForm: true,        // 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('About to submit: \n\n' + queryString); 
 	$("#myForm_Email").css("display", "none");
	$("#myForm_ErrorRow_Email").css("display", "none");
	$("#myForm_Success_Email").css("display", "none");
	$("#myForm_Thinking_Email").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) { 
    // 'responseXML' is the XML document returned by the server; we use 
    // jQuery to extract the content of the message node from the XML doc 
    //var message = $('message', responseXML).text(); 
	//var errorMessage = $('errorMessage', responseXML).text();

   	//alert($('input[@name=Redirect]').fieldValue());
	if(responseHTML == "Success") {
		$("#myForm_Email").css("display", "none");	
		$("#myForm_Success_Email").css("display", "block");
		$("#myForm_Thinking_Email").css("display", "none");
		$("#myForm_ErrorRow_Email").css("display", "none");
	} else {
		$("#myForm_Email").css("display", "none");	
		$("#myForm_Success_Email").css("display", "none");
		$("#myForm_Thinking_Email").css("display", "none");
		$("#myForm_ErrorRow_Email").css("display", "block");
		$("#myForm_ErrorMessage").html(responseHTML);
	}
}