;
(function ($) {
	$.fn.ajaxSubmit = function (u) {
		if (!this.length) {
			log('ajaxSubmit: skipping submit process - no element selected');
			return this
		}
		if (typeof u == 'function') u = {
			success: u
		};
		u = $.extend({
			url: this.attr('action') || window.location.toString(),
			type: this.attr('method') || 'GET'
		},
		u || {});
		var v = {};
		this.trigger('form-pre-serialize', [this, u, v]);
		if (v.veto) {
			log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
			return this
		}
		if (u.beforeSerialize && u.beforeSerialize(this, u) === false) {
			log('ajaxSubmit: submit aborted via beforeSerialize callback');
			return this
		}
		var a = this.formToArray(u.semantic);
		if (u.data) {
			u.extraData = u.data;
			for (var n in u.data) {
				if (u.data[n] instanceof Array) {
					for (var k in u.data[n]) a.push({
						name: n,
						value: u.data[n][k]
					})
				} else a.push({
					name: n,
					value: u.data[n]
				})
			}
		}
		if (u.beforeSubmit && u.beforeSubmit(a, this, u) === false) {
			log('ajaxSubmit: submit aborted via beforeSubmit callback');
			return this
		}
		this.trigger('form-submit-validate', [a, this, u, v]);
		if (v.veto) {
			log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
			return this
		}
		var q = $.param(a);
		if (u.type.toUpperCase() == 'GET') {
			u.url += (u.url.indexOf('?') >= 0 ? '&': '?') + q;
			u.data = null
		} else u.data = q;
		var w = this,
		callbacks = [];
		if (u.resetForm) callbacks.push(function () {
			w.resetForm()
		});
		if (u.clearForm) callbacks.push(function () {
			w.clearForm()
		});
		if (!u.dataType && u.target) {
			var x = u.success ||
			function () {};
			callbacks.push(function (a) {
				$(u.target).html(a).each(x, arguments)
			})
		} else if (u.success) callbacks.push(u.success);
		u.success = function (a, b) {
			for (var i = 0, max = callbacks.length; i < max; i++) callbacks[i].apply(u, [a, b, w])
		};
		var y = $('input:file', this).fieldValue();
		var z = false;
		for (var j = 0; j < y.length; j++) if (y[j]) z = true;
		if (u.iframe || z) {
			if (u.closeKeepAlive) $.get(u.closeKeepAlive, fileUpload);
			else fileUpload()
		} else $.ajax(u);
		this.trigger('form-submit-notify', [this, u]);
		return this;
		function fileUpload() {
			var h = w[0];
			if ($(':input[name=submit]', h).length) {
				alert('Error: Form elements must not be named "submit".');
				return
			}
			var i = $.extend({},
			$.ajaxSettings, u);
			var s = jQuery.extend(true, {},
			$.extend(true, {},
			$.ajaxSettings), i);
			var j = 'jqFormIO' + (new Date().getTime());
			var k = $('<iframe id="' + j + '" name="' + j + '" src="about:blank" />');
			var l = k[0];
			k.css({
				position: 'absolute',
				top: '-1000px',
				left: '-1000px'
			});
			var m = {
				aborted: 0,
				responseText: null,
				responseXML: null,
				status: 0,
				statusText: 'n/a',
				getAllResponseHeaders: function () {},
				getResponseHeader: function () {},
				setRequestHeader: function () {},
				abort: function () {
					this.aborted = 1;
					k.attr('src', 'about:blank')
				}
			};
			var g = i.global;
			if (g && !$.active++) $.event.trigger("ajaxStart");
			if (g) $.event.trigger("ajaxSend", [m, i]);
			if (s.beforeSend && s.beforeSend(m, s) === false) {
				s.global && jQuery.active--;
				return
			}
			if (m.aborted) return;
			var o = 0;
			var p = 0;
			var q = h.clk;
			if (q) {
				var n = q.name;
				if (n && !q.disabled) {
					u.extraData = u.extraData || {};
					u.extraData[n] = q.value;
					if (q.type == "image") {
						u.extraData[name + '.x'] = h.clk_x;
						u.extraData[name + '.y'] = h.clk_y
					}
				}
			}
			setTimeout(function () {
				var t = w.attr('target'),
				a = w.attr('action');
				h.setAttribute('target', j);
				if (h.getAttribute('method') != 'POST') h.setAttribute('method', 'POST');
				if (h.getAttribute('action') != i.url) h.setAttribute('action', i.url);
				if (!u.skipEncodingOverride) {
					w.attr({
						encoding: 'multipart/form-data',
						enctype: 'multipart/form-data'
					})
				}
				if (i.timeout) setTimeout(function () {
					p = true;
					cb()
				},
				i.timeout);
				var b = [];
				try {
					if (u.extraData) for (var n in u.extraData) b.push($('<input type="hidden" name="' + n + '" value="' + u.extraData[n] + '" />').appendTo(h)[0]);
					k.appendTo('body');
					l.attachEvent ? l.attachEvent('onload', cb) : l.addEventListener('load', cb, false);
					h.submit()
				} finally {
					h.setAttribute('action', a);
					t ? h.setAttribute('target', t) : w.removeAttr('target');
					$(b).remove()
				}
			},
			10);
			var r = 0;
			function cb() {
				if (o++) return;
				l.detachEvent ? l.detachEvent('onload', cb) : l.removeEventListener('load', cb, false);
				var c = true;
				try {
					if (p) throw 'timeout';
					var d, doc;
					doc = l.contentWindow ? l.contentWindow.document: l.contentDocument ? l.contentDocument: l.document;
					if ((doc.body == null || doc.body.innerHTML == '') && !r) {
						r = 1;
						o--;
						setTimeout(cb, 100);
						return
					}
					m.responseText = doc.body ? doc.body.innerHTML: null;
					m.responseXML = doc.XMLDocument ? doc.XMLDocument: doc;
					m.getResponseHeader = function (a) {
						var b = {
							'content-type': i.dataType
						};
						return b[a]
					};
					if (i.dataType == 'json' || i.dataType == 'script') {
						var f = doc.getElementsByTagName('textarea')[0];
						m.responseText = f ? f.value: m.responseText
					} else if (i.dataType == 'xml' && !m.responseXML && m.responseText != null) {
						m.responseXML = toXml(m.responseText)
					}
					d = $.httpData(m, i.dataType)
				} catch(e) {
					c = false;
					$.handleError(i, m, 'error', e)
				}
				if (c) {
					i.success(d, 'success');
					if (g) $.event.trigger("ajaxSuccess", [m, i])
				}
				if (g) $.event.trigger("ajaxComplete", [m, i]);
				if (g && !--$.active) $.event.trigger("ajaxStop");
				if (i.complete) i.complete(m, c ? 'success': 'error');
				setTimeout(function () {
					k.remove();
					m.responseXML = null
				},
				100)
			};
			function toXml(s, a) {
				if (window.ActiveXObject) {
					a = new ActiveXObject('Microsoft.XMLDOM');
					a.async = 'false';
					a.loadXML(s)
				} else a = (new DOMParser()).parseFromString(s, 'text/xml');
				return (a && a.documentElement && a.documentElement.tagName != 'parsererror') ? a: null
			}
		}
	};
	$.fn.ajaxForm = function (c) {
		return this.ajaxFormUnbind().bind('submit.form-plugin', function () {
			$(this).ajaxSubmit(c);
			return false
		}).each(function () {
			$(":submit,input:image", this).bind('click.form-plugin', function (e) {
				var a = this.form;
				a.clk = this;
				if (this.type == 'image') {
					if (e.offsetX != undefined) {
						a.clk_x = e.offsetX;
						a.clk_y = e.offsetY
					} else if (typeof $.fn.offset == 'function') {
						var b = $(this).offset();
						a.clk_x = e.pageX - b.left;
						a.clk_y = e.pageY - b.top
					} else {
						a.clk_x = e.pageX - this.offsetLeft;
						a.clk_y = e.pageY - this.offsetTop
					}
				}
				setTimeout(function () {
					a.clk = a.clk_x = a.clk_y = null
				},
				10)
			})
		})
	};
	$.fn.ajaxFormUnbind = function () {
		this.unbind('submit.form-plugin');
		return this.each(function () {
			$(":submit,input:image", this).unbind('click.form-plugin')
		})
	};
	$.fn.formToArray = function (b) {
		var a = [];
		if (this.length == 0) return a;
		var c = this[0];
		var d = b ? c.getElementsByTagName('*') : c.elements;
		if (!d) return a;
		for (var i = 0, max = d.length; i < max; i++) {
			var e = d[i];
			var n = e.name;
			if (!n) continue;
			if (b && c.clk && e.type == "image") {
				if (!e.disabled && c.clk == e) a.push({
					name: n + '.x',
					value: c.clk_x
				},
				{
					name: n + '.y',
					value: c.clk_y
				});
				continue
			}
			var v = $.fieldValue(e, true);
			if (v && v.constructor == Array) {
				for (var j = 0, jmax = v.length; j < jmax; j++) a.push({
					name: n,
					value: v[j]
				})
			} else if (v !== null && typeof v != 'undefined') a.push({
				name: n,
				value: v
			})
		}
		if (!b && c.clk) {
			var f = c.getElementsByTagName("input");
			for (var i = 0, max = f.length; i < max; i++) {
				var g = f[i];
				var n = g.name;
				if (n && !g.disabled && g.type == "image" && c.clk == g) a.push({
					name: n + '.x',
					value: c.clk_x
				},
				{
					name: n + '.y',
					value: c.clk_y
				})
			}
		}
		return a
	};
	$.fn.formSerialize = function (a) {
		return $.param(this.formToArray(a))
	};
	$.fn.fieldSerialize = function (b) {
		var a = [];
		this.each(function () {
			var n = this.name;
			if (!n) return;
			var v = $.fieldValue(this, b);
			if (v && v.constructor == Array) {
				for (var i = 0, max = v.length; i < max; i++) a.push({
					name: n,
					value: v[i]
				})
			} else if (v !== null && typeof v != 'undefined') a.push({
				name: this.name,
				value: v
			})
		});
		return $.param(a)
	};
	$.fn.fieldValue = function (a) {
		for (var b = [], i = 0, max = this.length; i < max; i++) {
			var c = this[i];
			var v = $.fieldValue(c, a);
			if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) continue;
			v.constructor == Array ? $.merge(b, v) : b.push(v)
		}
		return b
	};
	$.fieldValue = function (b, c) {
		var n = b.name,
		t = b.type,
		tag = b.tagName.toLowerCase();
		if (typeof c == 'undefined') c = true;
		if (c && (!n || b.disabled || t == 'reset' || t == 'button' || (t == 'checkbox' || t == 'radio') && !b.checked || (t == 'submit' || t == 'image') && b.form && b.form.clk != b || tag == 'select' && b.selectedIndex == -1)) return null;
		if (tag == 'select') {
			var d = b.selectedIndex;
			if (d < 0) return null;
			var a = [],
			ops = b.options;
			var e = (t == 'select-one');
			var f = (e ? d + 1 : ops.length);
			for (var i = (e ? d: 0); i < f; i++) {
				var g = ops[i];
				if (g.selected) {
					var v = g.value;
					if (!v) v = (g.attributes && g.attributes['value'] && !(g.attributes['value'].specified)) ? g.text: g.value;
					if (e) return v;
					a.push(v)
				}
			}
			return a
		}
		return b.value
	};
	$.fn.clearForm = function () {
		return this.each(function () {
			$('input,select,textarea', this).clearFields()
		})
	};
	$.fn.clearFields = $.fn.clearInputs = function () {
		return this.each(function () {
			var t = this.type,
			tag = this.tagName.toLowerCase();
			if (t == 'text' || t == 'password' || tag == 'textarea') this.value = '';
			else if (t == 'checkbox' || t == 'radio') this.checked = false;
			else if (tag == 'select') this.selectedIndex = -1
		})
	};
	$.fn.resetForm = function () {
		return this.each(function () {
			if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) this.reset()
		})
	};
	$.fn.enable = function (b) {
		if (b == undefined) b = true;
		return this.each(function () {
			this.disabled = !b
		})
	};
	$.fn.selected = function (b) {
		if (b == undefined) b = true;
		return this.each(function () {
			var t = this.type;
			if (t == 'checkbox' || t == 'radio') this.checked = b;
			else if (this.tagName.toLowerCase() == 'option') {
				var a = $(this).parent('select');
				if (b && a[0] && a[0].type == 'select-one') {
					a.find('option').selected(false)
				}
				this.selected = b
			}
		})
	};
	function log() {
		if ($.fn.ajaxSubmit.debug && window.console && window.console.log) window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments, ''))
	}
})(jQuery);
