$.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {
	var vars = this.serialize();
 	 
	if (pre_cb && pre_cb.constructor == Function && pre_cb(vars) === false) return;
 	
 	var f = this.get(0);
	var url = url || f.action || '';
	var mth = mth || f.method || 'POST';
 	
	if (target && target.constructor == Function)
		$.ajax(mth, url, $.param(vars), target);
	else if (target && target.constructor == String)
		$(target).load(url, vars, post_cb);
	else {
		vars.push({name: 'evaljs', value: 1});
		$.ajax(mth, url, $.param(vars), function(r) {
			eval(r.responseText);
		});
	}
 	
	return this;
};
$.fn.ajaxForm = function(target, post_cb, pre_cb) {
 	return this.each(function(){
		$("input[@type=submit],input[@type=image]", this).click(function(ev){
			this.form.clicked = this;
			if (ev.offsetX != undefined) {
				this.form.clicked_x = ev.offsetX;
				this.form.clicked_y = ev.offsetY;
			} else {
				this.form.clicked_x = ev.pageX - this.offsetLeft;
				this.form.clicked_y = ev.pageY - this.offsetTop;
			}
		});
	}).submit(function(e){
		$(this).ajaxSubmit(target, post_cb, pre_cb);
		return false;
	});
};
$.fn.serialize = function() {
	var a = [];
	var ok = {INPUT:true, TEXTAREA:true, OPTION:true};
 	
	$('*', this).each(function() {
		var par = this.parentNode;
		var p = par.nodeName.toUpperCase();
		var n = this.name || p == 'OPTGROUP' && par.parentNode.name || p == 'SELECT' && par.name || this.id;
 	
		if ( !n || this.disabled || this.type == 'reset' ||
			(this.type == 'checkbox' || this.type == 'radio') && !this.checked ||
			!ok[this.nodeName.toUpperCase()] ||
			(this.type == 'submit' || this.type == 'image') && this.form.clicked != this ||
			(p == 'SELECT' || p == 'OPTGROUP') && !this.selected ) return;
 	
		if (this.type == 'image' && this.form.clicked_x)
			return a.push(
				{name: this.name+'_x', value: this.form.clicked_x},
				{name: this.name+'_y', value: this.form.clicked_y}
 	      );
 	
		a.push({name: n, value: this.value});
	});
 	
	return a;
};