(function(d){function q(){if(d.fn.ajaxSubmit.debug){var a="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(a):window.opera&&window.opera.postError&&window.opera.postError(a)}}d.fn.ajaxSubmit=function(a){function e(){function c(){var a=k.attr("target"),e=k.attr("action");b.setAttribute("target",g);"POST"!=b.getAttribute("method")&&b.setAttribute("method","POST");b.getAttribute("action")!=f.url&&b.setAttribute("action",f.url);f.skipEncodingOverride||
k.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});f.timeout&&setTimeout(function(){w=!0;h()},f.timeout);var l=[];try{if(f.extraData)for(var m in f.extraData)l.push(d('<input type="hidden" name="'+m+'" value="'+f.extraData[m]+'" />').appendTo(b)[0]);n.appendTo("body");n.data("form-plugin-onload",h);b.submit()}finally{b.setAttribute("action",e),a?b.setAttribute("target",a):k.removeAttr("target"),d(l).remove()}}function h(){if(!x){n.removeData("form-plugin-onload");var a=!0;try{if(w)throw"timeout";
p=r.contentWindow?r.contentWindow.document:r.contentDocument?r.contentDocument:r.document;var c="xml"==f.dataType||p.XMLDocument||d.isXMLDoc(p);q("isXml="+c);if(!c&&window.opera&&(null==p.body||""==p.body.innerHTML)&&--v){q("requeing onLoad callback, DOM not available");setTimeout(h,250);return}x=!0;m.responseText=p.documentElement?p.documentElement.innerHTML:null;m.responseXML=p.XMLDocument?p.XMLDocument:p;m.getResponseHeader=function(a){return{"content-type":f.dataType}[a]};var b=/(json|script)/.test(f.dataType);
if(b||f.textarea){var g=p.getElementsByTagName("textarea")[0];if(g)m.responseText=g.value;else if(b){var l=p.getElementsByTagName("pre")[0];l&&(m.responseText=l.innerHTML)}}else"xml"!=f.dataType||m.responseXML||null==m.responseText||(m.responseXML=e(m.responseText));y=d.httpData(m,f.dataType)}catch(k){q("error caught:",k),a=!1,m.error=k,d.handleError(f,m,"error",k)}a&&(f.success.call(f.context,y,"success",m),s&&d.event.trigger("ajaxSuccess",[m,f]));s&&d.event.trigger("ajaxComplete",[m,f]);s&&!--d.active&&
d.event.trigger("ajaxStop");f.complete&&f.complete.call(f.context,m,a?"success":"error");setTimeout(function(){n.removeData("form-plugin-onload");n.remove();m.responseXML=null},100)}}function e(a,c){window.ActiveXObject?(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(a)):c=(new DOMParser).parseFromString(a,"text/xml");return c&&c.documentElement&&"parsererror"!=c.documentElement.tagName?c:null}var b=k[0];if(d(":input[name=submit],:input[id=submit]",b).length)alert('Error: Form elements must not have name or id of "submit".');
else{var f=d.extend(!0,{},d.ajaxSettings,a);f.context=f.context||f;var g="jqFormIO"+(new Date).getTime(),l="_"+g;window[l]=function(){var a=n.data("form-plugin-onload");if(a){a();window[l]=void 0;try{delete window[l]}catch(c){}}};var n=d('<iframe id="'+g+'" name="'+g+'" src="'+f.iframeSrc+'" onload="window[\'_\'+this.id]()" />'),r=n[0];n.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;n.attr("src",f.iframeSrc)}},s=f.global;s&&!d.active++&&d.event.trigger("ajaxStart");s&&d.event.trigger("ajaxSend",[m,f]);if(f.beforeSend&&!1===f.beforeSend.call(f.context,m,f))f.global&&d.active--;else if(!m.aborted){var x=!1,w=0,t=b.clk;if(t){var u=t.name;u&&!t.disabled&&(f.extraData=f.extraData||{},f.extraData[u]=t.value,"image"==t.type&&(f.extraData[u+".x"]=b.clk_x,f.extraData[u+".y"]=b.clk_y))}f.forceSync?
c():setTimeout(c,10);var y,p,v=50}}}if(!this.length)return q("ajaxSubmit: skipping submit process - no element selected"),this;"function"==typeof a&&(a={success:a});var b=d.trim(this.attr("action"));b&&(b=(b.match(/^([^#]+)/)||[])[1]);b=b||window.location.href||"";a=d.extend(!0,{url:b,type:this.attr("method")||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},a);b={};this.trigger("form-pre-serialize",[this,a,b]);if(b.veto)return q("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),
this;if(a.beforeSerialize&&!1===a.beforeSerialize(this,a))return q("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var c,h,g=this.formToArray(a.semantic);if(a.data)for(c in a.extraData=a.data,a.data)if(a.data[c]instanceof Array)for(var l in a.data[c])g.push({name:c,value:a.data[c][l]});else h=a.data[c],h=d.isFunction(h)?h():h,g.push({name:c,value:h});if(a.beforeSubmit&&!1===a.beforeSubmit(g,this,a))return q("ajaxSubmit: submit aborted via beforeSubmit callback"),this;this.trigger("form-submit-validate",
[g,this,a,b]);if(b.veto)return q("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;c=d.param(g);"GET"==a.type.toUpperCase()?(a.url+=(0<=a.url.indexOf("?")?"&":"?")+c,a.data=null):a.data=c;var k=this,n=[];a.resetForm&&n.push(function(){k.resetForm()});a.clearForm&&n.push(function(){k.clearForm()});if(!a.dataType&&a.target){var v=a.success||function(){};n.push(function(c){var b=a.replaceTarget?"replaceWith":"html";d(a.target)[b](c).each(v,arguments)})}else a.success&&n.push(a.success);
a.success=function(c,d,b){for(var h=a.context||a,f=0,g=n.length;f<g;f++)n[f].apply(h,[c,d,b||k,k])};c=0<d("input:file",this).length;l="multipart/form-data"==k.attr("enctype")||"multipart/form-data"==k.attr("encoding");!1!==a.iframe&&(c||a.iframe||l)?a.closeKeepAlive?d.get(a.closeKeepAlive,e):e():d.ajax(a);this.trigger("form-submit-notify",[this,a]);return this};d.fn.ajaxForm=function(a){if(0===this.length){var e=this.selector,b=this.context;if(!d.isReady&&e)return q("DOM not ready, queuing ajaxForm"),
d(function(){d(e,b).ajaxForm(a)}),this;q("terminating; zero elements found by selector"+(d.isReady?"":" (DOM not ready)"));return this}return this.ajaxFormUnbind().bind("submit.form-plugin",function(c){c.isDefaultPrevented()||(c.preventDefault(),d(this).ajaxSubmit(a))}).bind("click.form-plugin",function(a){var b=a.target,g=d(b);if(!g.is(":submit,input:image")){b=g.closest(":submit");if(0==b.length)return;b=b[0]}var e=this;e.clk=b;"image"==b.type&&(void 0!=a.offsetX?(e.clk_x=a.offsetX,e.clk_y=a.offsetY):
"function"==typeof d.fn.offset?(g=g.offset(),e.clk_x=a.pageX-g.left,e.clk_y=a.pageY-g.top):(e.clk_x=a.pageX-b.offsetLeft,e.clk_y=a.pageY-b.offsetTop));setTimeout(function(){e.clk=e.clk_x=e.clk_y=null},100)})};d.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};d.fn.formToArray=function(a){var e=[];if(0===this.length)return e;var b=this[0],c=a?b.getElementsByTagName("*"):b.elements;if(!c)return e;var h,g,l,k;h=0;for(max=c.length;h<max;h++)if(g=c[h],l=g.name)if(a&&
b.clk&&"image"==g.type)g.disabled||b.clk!=g||(e.push({name:l,value:d(g).val()}),e.push({name:l+".x",value:b.clk_x},{name:l+".y",value:b.clk_y}));else if((k=d.fieldValue(g,!0))&&k.constructor==Array)for(g=0,jmax=k.length;g<jmax;g++)e.push({name:l,value:k[g]});else null!==k&&"undefined"!=typeof k&&e.push({name:l,value:k});!a&&b.clk&&(a=d(b.clk),c=a[0],(l=c.name)&&!c.disabled&&"image"==c.type&&(e.push({name:l,value:a.val()}),e.push({name:l+".x",value:b.clk_x},{name:l+".y",value:b.clk_y})));return e};
d.fn.formSerialize=function(a){return d.param(this.formToArray(a))};d.fn.fieldSerialize=function(a){var e=[];this.each(function(){var b=this.name;if(b){var c=d.fieldValue(this,a);if(c&&c.constructor==Array)for(var h=0,g=c.length;h<g;h++)e.push({name:b,value:c[h]});else null!==c&&"undefined"!=typeof c&&e.push({name:this.name,value:c})}});return d.param(e)};d.fn.fieldValue=function(a){for(var e=[],b=0,c=this.length;b<c;b++){var h=d.fieldValue(this[b],a);null===h||"undefined"==typeof h||h.constructor==
Array&&!h.length||(h.constructor==Array?d.merge(e,h):e.push(h))}return e};d.fieldValue=function(a,e){var b=a.name,c=a.type,h=a.tagName.toLowerCase();void 0===e&&(e=!0);if(e&&(!b||a.disabled||"reset"==c||"button"==c||("checkbox"==c||"radio"==c)&&!a.checked||("submit"==c||"image"==c)&&a.form&&a.form.clk!=a||"select"==h&&-1==a.selectedIndex))return null;if("select"==h){var g=a.selectedIndex;if(0>g)return null;for(var b=[],h=a.options,l=(c="select-one"==c)?g+1:h.length,g=c?g:0;g<l;g++){var k=h[g];if(k.selected){var n=
k.value;n||(n=k.attributes&&k.attributes.value&&!k.attributes.value.specified?k.text:k.value);if(c)return n;b.push(n)}}return b}return d(a).val()};d.fn.clearForm=function(){return this.each(function(){d("input,select,textarea",this).clearFields()})};d.fn.clearFields=d.fn.clearInputs=function(){return this.each(function(){var a=this.type,d=this.tagName.toLowerCase();"text"==a||"password"==a||"textarea"==d?this.value="":"checkbox"==a||"radio"==a?this.checked=!1:"select"==d&&(this.selectedIndex=-1)})};
d.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})};d.fn.enable=function(a){void 0===a&&(a=!0);return this.each(function(){this.disabled=!a})};d.fn.selected=function(a){void 0===a&&(a=!0);return this.each(function(){var e=this.type;"checkbox"==e||"radio"==e?this.checked=a:"option"==this.tagName.toLowerCase()&&(e=d(this).parent("select"),a&&e[0]&&"select-one"==e[0].type&&e.find("option").selected(!1),
this.selected=a)})}})(jQuery);
