// Plugin loading in jquery
jQuery.ajaxsubmit = jQuery.fn.ajaxsubmit = function(form, callback, resultDataType){
	if(arguments.length <=2 && this && this!=jQuery){
		resultDataType = callback;
		callback = form;
		form = this;
	}
	if(form.jquery && (!form.elements || !form.elements["jquery"])){
		for(var i=0;i<form.size();i++)
			jQuery.ajaxsubmit(form[i], callback, resultDataType);
		return ;
	}

	var theCallback = {
		func: callback,
		call: function(){
			if(!this.func)
				return;
			this.func.apply( form, arguments );
			this.func = undefined;
		}
	};

	var formdata = {};
	for(var i=0;i<form.length;i++)
		formdata[form[i].name] = form[i].value;
	jQuery.ajax({
		url: ((!form.action || form.action.length == 0) && form.method.toLowerCase() == "post") ? location.href : form.action,
		type: form.method,
		data: formdata,
		ifModified: false,
		dataType: resultDataType,
		
		complete: function(res, status){
			theCallback.call(res.responseText, status, res);
		},
		success: function(data, status){
			theCallback.call(data, status);
		},
		error: function(xml, status){
			theCallback.call(xml, status);			
		}
	});
};