(function(_){_.fn.ajaxSubmit=function(E){if(!this.length){$("ajaxSubmit: skipping submit process - no element selected");return this}if(typeof E=="function")E={success:E};E=_.extend({url:this.attr("action")||window.location.toString(),type:this.attr("method")||"GET"},E||{});var I={};this.trigger("form-pre-serialize",[this,E,I]);if(I.veto){$("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this}var H=this.formToArray(E.semantic);if(E.data){E.extraData=E.data;for(var L in E.data)if(E.data[L]instanceof Array){for(var A in E.data[L])H.push({name:L,value:E.data[L][A]})}else H.push({name:L,value:E.data[L]})}if(E.beforeSubmit&&E.beforeSubmit(H,this,E)===false){$("ajaxSubmit: submit aborted via beforeSubmit callback");return this}this.trigger("form-submit-validate",[H,this,E,I]);if(I.veto){$("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this}var C=_.param(H);if(E.type.toUpperCase()=="GET"){E.url+=(E.url.indexOf("?")>=0?"&":"?")+C;E.data=null}else E.data=C;var J=this,B=[];if(E.resetForm)B.push(function(){J.resetForm()});if(E.clearForm)B.push(function(){J.clearForm()});if(!E.dataType&&E.target){var G=E.success||function(){};B.push(function($){_(E.target).html($).each(G,arguments)})}else if(E.success)B.push(E.success);E.success=function(_,A){for(var $=0,C=B.length;$<C;$++)B[$].apply(E,[_,A,J])};var F=_("input:file",this).fieldValue(),D=false;for(var K=0;K<F.length;K++)if(F[K])D=true;if(E.iframe||D){if(_.browser.safari&&E.closeKeepAlive)_.get(E.closeKeepAlive,M);else M()}else _.ajax(E);this.trigger("form-submit-notify",[this,E]);return this;function M(){var C=J[0];if(_(":input[@name=submit]",C).length){alert("Error: Form elements must not be named \"submit\".");return}var A=_.extend({},_.ajaxSettings,E),N=jQuery.extend(true,{},_.extend(true,{},_.ajaxSettings),A),K="jqFormIO"+(new Date().getTime()),I=_("<iframe id=\""+K+"\" name=\""+K+"\" />"),D=I[0];if(_.browser.msie||_.browser.opera)D.src="javascript:false;document.write(\"\");";I.css({position:"absolute",top:"-1000px",left:"-1000px"});var B={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){this.aborted=1;I.attr("src","about:blank")}},H=A.global;if(H&&!_.active++)_.event.trigger("ajaxStart");if(H)_.event.trigger("ajaxSend",[B,A]);if(N.beforeSend&&N.beforeSend(B,N)===false){N.global&&jQuery.active--;return}if(B.aborted)return;var G=0,L=0,F=C.clk;if(F){var M=F.name;if(M&&!F.disabled){E.extraData=E.extraData||{};E.extraData[M]=F.value;if(F.type=="image"){E.extraData[name+".x"]=C.clk_x;E.extraData[name+".y"]=C.clk_y}}}setTimeout(function(){var B=J.attr("target"),$=J.attr("action");J.attr({target:K,method:"POST",action:A.url});if(!E.skipEncodingOverride)J.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});if(A.timeout)setTimeout(function(){L=true;O()},A.timeout);var F=[];try{if(E.extraData)for(var G in E.extraData)F.push(_("<input type=\"hidden\" name=\""+G+"\" value=\""+E.extraData[G]+"\" />").appendTo(C)[0]);I.appendTo("body");D.attachEvent?D.attachEvent("onload",O):D.addEventListener("load",O,false);C.submit()}finally{J.attr("action",$);B?J.attr("target",B):J.removeAttr("target");_(F).remove()}},10);function O(){if(G++)return;D.detachEvent?D.detachEvent("onload",O):D.removeEventListener("load",O,false);var E=0,F=true;try{if(L)throw"timeout";var J,C;C=D.contentWindow?D.contentWindow.document:D.contentDocument?D.contentDocument:D.document;if(C.body==null&&!E&&_.browser.opera){E=1;G--;setTimeout(O,100);return}B.responseText=C.body?C.body.innerHTML:null;B.responseXML=C.XMLDocument?C.XMLDocument:C;B.getResponseHeader=function(_){var $={"content-type":A.dataType};return $[_]};if(A.dataType=="json"||A.dataType=="script"){var K=C.getElementsByTagName("textarea")[0];B.responseText=K?K.value:B.responseText}else if(A.dataType=="xml"&&!B.responseXML&&B.responseText!=null)B.responseXML=$(B.responseText);J=_.httpData(B,A.dataType)}catch(M){F=false;_.handleError(A,B,"error",M)}if(F){A.success(J,"success");if(H)_.event.trigger("ajaxSuccess",[B,A])}if(H)_.event.trigger("ajaxComplete",[B,A]);if(H&&!--_.active)_.event.trigger("ajaxStop");if(A.complete)A.complete(B,F?"success":"error");setTimeout(function(){I.remove();B.responseXML=null},100)}function $(_,$){if(window.ActiveXObject){$=new ActiveXObject("Microsoft.XMLDOM");$.async="false";$.loadXML(_)}else $=(new DOMParser()).parseFromString(_,"text/xml");return($&&$.documentElement&&$.documentElement.tagName!="parsererror")?$:null}}};_.fn.ajaxForm=function($){return this.ajaxFormUnbind().bind("submit.form-plugin",function(){_(this).ajaxSubmit($);return false}).each(function(){_(":submit,input:image",this).bind("click.form-plugin",function(B){var $=this.form;$.clk=this;if(this.type=="image")if(B.offsetX!=undefined){$.clk_x=B.offsetX;$.clk_y=B.offsetY}else if(typeof _.fn.offset=="function"){var A=_(this).offset();$.clk_x=B.pageX-A.left;$.clk_y=B.pageY-A.top}else{$.clk_x=B.pageX-this.offsetLeft;$.clk_y=B.pageY-this.offsetTop}setTimeout(function(){$.clk=$.clk_x=$.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(C){var H=[];if(this.length==0)return H;var A=this[0],K=C?A.getElementsByTagName("*"):A.elements;if(!K)return H;for(var G=0,D=K.length;G<D;G++){var I=K[G],L=I.name;if(!L)continue;if(C&&A.clk&&I.type=="image"){if(!I.disabled&&A.clk==I)H.push({name:L+".x",value:A.clk_x},{name:L+".y",value:A.clk_y});continue}var F=_.fieldValue(I,true);if(F&&F.constructor==Array){for(var J=0,B=F.length;J<B;J++)H.push({name:L,value:F[J]})}else if(F!==null&&typeof F!="undefined")H.push({name:L,value:F})}if(!C&&A.clk){var E=A.getElementsByTagName("input");for(G=0,D=E.length;G<D;G++){var $=E[G],L=$.name;if(L&&!$.disabled&&$.type=="image"&&A.clk==$)H.push({name:L+".x",value:A.clk_x},{name:L+".y",value:A.clk_y})}}return H};_.fn.formSerialize=function($){return _.param(this.formToArray($))};_.fn.fieldSerialize=function(A){var $=[];this.each(function(){var C=this.name;if(!C)return;var E=_.fieldValue(this,A);if(E&&E.constructor==Array){for(var B=0,D=E.length;B<D;B++)$.push({name:C,value:E[B]})}else if(E!==null&&typeof E!="undefined")$.push({name:this.name,value:E})});return _.param($)};_.fn.fieldValue=function(D){for(var A=[],$=0,C=this.length;$<C;$++){var B=this[$],E=_.fieldValue(B,D);if(E===null||typeof E=="undefined"||(E.constructor==Array&&!E.length))continue;E.constructor==Array?_.merge(A,E):A.push(E)}return A};_.fieldValue=function(I,C){var L=I.name,J=I.type,K=I.tagName.toLowerCase();if(typeof C=="undefined")C=true;if(C&&(!L||I.disabled||J=="reset"||J=="button"||(J=="checkbox"||J=="radio")&&!I.checked||(J=="submit"||J=="image")&&I.form&&I.form.clk!=I||K=="select"&&I.selectedIndex==-1))return null;if(K=="select"){var $=I.selectedIndex;if($<0)return null;var H=[],F=I.options,B=(J=="select-one"),D=(B?$+1:F.length);for(var G=(B?$:0);G<D;G++){var A=F[G];if(A.selected){var E=_.browser.msie&&!(A.attributes["value"].specified)?A.text:A.value;if(B)return E;H.push(E)}}return H}return I.value};_.fn.clearForm=function(){return this.each(function(){_("input,select,textarea",this).clearFields()})};_.fn.clearFields=_.fn.clearInputs=function(){return this.each(function(){var _=this.type,$=this.tagName.toLowerCase();if(_=="text"||_=="password"||$=="textarea")this.value="";else if(_=="checkbox"||_=="radio")this.checked=false;else if($=="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($){if($==undefined)$=true;return this.each(function(){this.disabled=!$})};_.fn.selected=function($){if($==undefined)$=true;return this.each(function(){var A=this.type;if(A=="checkbox"||A=="radio")this.checked=$;else if(this.tagName.toLowerCase()=="option"){var B=_(this).parent("select");if($&&B[0]&&B[0].type=="select-one")B.find("option").selected(false);this.selected=$}})};function $(){if(_.fn.ajaxSubmit.debug&&window.console&&window.console.log)window.console.log("[jquery.form] "+Array.prototype.join.call(arguments,""))}})(jQuery)
