Memberfuse.Forms = {
	asyncFormSubmit: function(event){
		var form = event.element();
		new Ajax.Request(form.action,{
		    parameters: form.serialize(),
		    onException: function(requestor,e){
		        alert("An error occurred while submitting the request. Error name: " + e.name 
  + ". Error message: " + e.message);
		    },
		    onFailure: function(request,json){
		       alert('There was a problem processing the request');
		    },
		    onSuccess: function(request,json){
		        //the response is expected to be a JSON encoded NFi_Form_Async_Response
		        //object
		        var response = eval('(' + request.responseText + ')');
		        //first hide the old form, don't remove it yet since we need it
		        //as a pointer into the document to insert the new content
		        form.hide();
		        //create a container element to put the returned content in
		        var contentNew = new Element('div');
		        contentNew.innerHTML = response.html;
		        Memberfuse.init(contentNew);
		        //loop through each element in the returned content and add it
		        //to the document where the old form is
		        var currentNode = form;
		        while(contentNew.childNodes.length){
		           currentNode.parentNode.insertBefore(contentNew.childNodes[0],currentNode.nextSibling);
		           currentNode = $(currentNode).nextSibling;
		        }
		        form.remove();
		        
		        eval(response.dhtml);
		    }
		});
		event.stop();
	}
};