Memberfuse.Forms = {
	asyncFormSubmit: function(event){
		var form = event.element();
		$(form).down('[type=submit]').replace('<img src="/img/loading.gif" />');
		new Ajax.Request(form.action,{
		    parameters: form.serialize(),
		    onException: function(requestor,exception){
		        alert(exception);
		    },
		    onFailure: function(request,json){
		        alert('There was a problem processing the request');
		    },
		    onSuccess: function(request,json){
		        //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 = request.responseText;
		        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;
		           //if the element is another asyncForm then attach the submit handler to it
		           
		        }
		        form.remove();
		    }
		});
		event.stop();
	}
};


