!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("undefined"!=typeof jQuery?jQuery:window.Zepto)}(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=this;if(i.clk=r,"image"==r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n={};n.fileapi=void 0!==e("<input type='file'/>").get(0).files,n.formdata=void 0!==window.FormData;var i=!!e.fn.prop;e.fn.attr2=function(){if(!i)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t){function r(r){function n(e){var t=null;try{e.contentWindow&&(t=e.contentWindow.document)}catch(e){a("cannot get iframe.contentWindow document: "+e)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){a("cannot get iframe.contentDocument: "+r),t=e.document}return t}function s(){var t=u.attr2("target"),r=u.attr2("action"),i=u.attr("enctype")||u.attr("encoding")||"multipart/form-data";w.setAttribute("target",h),(!o||/post/i.test(o))&&w.setAttribute("method","POST"),r!=m.url&&w.setAttribute("action",m.url),m.skipEncodingOverride||o&&!/post/i.test(o)||u.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(j=setTimeout(function(){T=!0,c(D)},m.timeout));var s=[];try{if(m.extraData)for(var l in m.extraData)m.extraData.hasOwnProperty(l)&&s.push(e.isPlainObject(m.extraData[l])&&m.extraData[l].hasOwnProperty("name")&&m.extraData[l].hasOwnProperty("value")?e('<input type="hidden" name="'+m.extraData[l].name+'">').val(m.extraData[l].value).appendTo(w)[0]:e('<input type="hidden" name="'+l+'">').val(m.extraData[l]).appendTo(w)[0]);m.iframeTarget||v.appendTo("body"),g.attachEvent?g.attachEvent("onload",c):g.addEventListener("load",c,!1),setTimeout(function e(){try{var t=n(g).readyState;a("state = "+t),t&&"uninitialized"==t.toLowerCase()&&setTimeout(e,50)}catch(e){a("Server abort: ",e," (",e.name,")"),c(k),j&&clearTimeout(j),j=void 0}},15);try{w.submit()}catch(e){document.createElement("form").submit.apply(w)}}finally{w.setAttribute("action",r),w.setAttribute("enctype",i),t?w.setAttribute("target",t):u.removeAttr("target"),e(s).remove()}}function c(t){if(!x.aborted&&!F){if((M=n(g))||(a("cannot access response document"),t=k),t===D&&x)return x.abort("timeout"),void S.reject(x,"timeout");if(t==k&&x)return x.abort("server abort"),void S.reject(x,"error","server abort");if(M&&M.location.href!=m.iframeSrc||T){g.detachEvent?g.detachEvent("onload",c):g.removeEventListener("load",c,!1);var r,i="success";try{if(T)throw"timeout";var o="xml"==m.dataType||M.XMLDocument||e.isXMLDoc(M);if(a("isXml="+o),!o&&window.opera&&(null===M.body||!M.body.innerHTML)&&--X)return a("requeing onLoad callback, DOM not available"),void setTimeout(c,250);var s=M.body?M.body:M.documentElement;x.responseText=s?s.innerHTML:null,x.responseXML=M.XMLDocument?M.XMLDocument:M,o&&(m.dataType="xml"),x.getResponseHeader=function(e){return{"content-type":m.dataType}[e.toLowerCase()]},s&&(x.status=Number(s.getAttribute("status"))||x.status,x.statusText=s.getAttribute("statusText")||x.statusText);var u=(m.dataType||"").toLowerCase(),l=/(json|script|text)/.test(u);if(l||m.textarea){var f=M.getElementsByTagName("textarea")[0];if(f)x.responseText=f.value,x.status=Number(f.getAttribute("status"))||x.status,x.statusText=f.getAttribute("statusText")||x.statusText;else if(l){var d=M.getElementsByTagName("pre")[0],h=M.getElementsByTagName("body")[0];d?x.responseText=d.textContent?d.textContent:d.innerText:h&&(x.responseText=h.textContent?h.textContent:h.innerText)}}else"xml"==u&&!x.responseXML&&x.responseText&&(x.responseXML=O(x.responseText));try{E=N(x,u,m)}catch(e){i="parsererror",x.error=r=e||i}}catch(e){a("error caught: ",e),i="error",x.error=r=e||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&x.status<300||304===x.status?"success":"error"),"success"===i?(m.success&&m.success.call(m.context,E,"success",x),S.resolve(x.responseText,"success",x),p&&e.event.trigger("ajaxSuccess",[x,m])):i&&(void 0===r&&(r=x.statusText),m.error&&m.error.call(m.context,x,i,r),S.reject(x,"error",r),p&&e.event.trigger("ajaxError",[x,m,r])),p&&e.event.trigger("ajaxComplete",[x,m]),p&&!--e.active&&e.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,x,i),F=!0,m.timeout&&clearTimeout(j),setTimeout(function(){m.iframeTarget?v.attr("src",m.iframeSrc):v.remove(),x.responseXML=null},100)}}}var l,f,m,p,h,v,g,x,b,y,T,j,w=u[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(f=0;f<d.length;f++)l=e(d[f]),i?l.prop("disabled",!1):l.removeAttr("disabled");if((m=e.extend(!0,{},e.ajaxSettings,t)).context=m.context||m,h="jqFormIO"+(new Date).getTime(),m.iframeTarget?(y=(v=e(m.iframeTarget)).attr2("name"))?h=y:v.attr2("name",h):(v=e('<iframe name="'+h+'" src="'+m.iframeSrc+'" />')).css({position:"absolute",top:"-1000px",left:"-1000px"}),g=v[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{g.contentWindow.document.execCommand&&g.contentWindow.document.execCommand("Stop")}catch(e){}v.attr("src",m.iframeSrc),x.error=r,m.error&&m.error.call(m.context,x,r,t),p&&e.event.trigger("ajaxError",[x,m,r]),m.complete&&m.complete.call(m.context,x,r)}},(p=m.global)&&0==e.active++&&e.event.trigger("ajaxStart"),p&&e.event.trigger("ajaxSend",[x,m]),m.beforeSend&&!1===m.beforeSend.call(m.context,x,m))return m.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;(b=w.clk)&&((y=b.name)&&!b.disabled&&(m.extraData=m.extraData||{},m.extraData[y]=b.value,"image"==b.type&&(m.extraData[y+".x"]=w.clk_x,m.extraData[y+".y"]=w.clk_y)));var D=1,k=2,A=e("meta[name=csrf-token]").attr("content"),L=e("meta[name=csrf-param]").attr("content");L&&A&&(m.extraData=m.extraData||{},m.extraData[L]=A),m.forceSync?s():setTimeout(s,10);var E,M,F,X=50,O=e.parseXML||function(e,t){return window.ActiveXObject?((t=new ActiveXObject("Microsoft.XMLDOM")).async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},C=e.parseJSON||function(e){return window.eval("("+e+")")},N=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i="xml"===r||!r&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&("json"===r||!r&&n.indexOf("json")>=0?o=C(o):("script"===r||!r&&n.indexOf("javascript")>=0)&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var o,s,c,u=this;"function"==typeof t?t={success:t}:void 0===t&&(t={}),o=t.type||this.attr2("method"),(c=(c="string"==typeof(s=t.url||this.attr2("action"))?e.trim(s):"")||window.location.href||"")&&(c=(c.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:c,success:e.ajaxSettings.success,type:o||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var l={};if(this.trigger("form-pre-serialize",[this,t,l]),l.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&!1===t.beforeSerialize(this,t))return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var f=t.traditional;void 0===f&&(f=e.ajaxSettings.traditional);var m,d=[],p=this.formToArray(t.semantic,d);if(t.data&&(t.extraData=t.data,m=e.param(t.data,f)),t.beforeSubmit&&!1===t.beforeSubmit(p,this,t))return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[p,this,t,l]),l.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var h=e.param(p,f);m&&(h=h?h+"&"+m:m),"GET"==t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+h,t.data=null):t.data=h;var v=[];if(t.resetForm&&v.push(function(){u.resetForm()}),t.clearForm&&v.push(function(){u.clearForm(t.includeHidden)}),!t.dataType&&t.target){var g=t.success||function(){};v.push(function(r){var a=t.replaceTarget?"replaceWith":"html";e(t.target)[a](r).each(g,arguments)})}else t.success&&v.push(t.success);if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=v.length;o>i;i++)v[i].apply(n,[e,r,a||u,u])},t.error){var x=t.error;t.error=function(e,r,a){var n=t.context||this;x.apply(n,[e,r,a,u])}}if(t.complete){var b=t.complete;t.complete=function(e,r){var a=t.context||this;b.apply(a,[e,r,u])}}var y=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}).length>0,T="multipart/form-data",j=u.attr("enctype")==T||u.attr("encoding")==T,w=n.fileapi&&n.formdata;a("fileAPI :"+w);var S,D=(y||j)&&!w;!1!==t.iframe&&(t.iframe||D)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){S=r(p)}):S=r(p):S=(y||j)&&w?function(r){for(var a=new FormData,n=0;n<r.length;n++)a.append(r[n].name,r[n].value);if(t.extraData){var i=function(r){var a,n,i=e.param(r,t.traditional).split("&"),o=i.length,s=[];for(a=0;o>a;a++)i[a]=i[a].replace(/\+/g," "),n=i[a].split("="),s.push([decodeURIComponent(n[0]),decodeURIComponent(n[1])]);return s}(t.extraData);for(n=0;n<i.length;n++)i[n]&&a.append(i[n][0],i[n][1])}t.data=null;var s=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:o||"POST"});t.uploadProgress&&(s.xhr=function(){var r=e.ajaxSettings.xhr();return r.upload&&r.upload.addEventListener("progress",function(e){var r=0,a=e.loaded||e.position,n=e.total;e.lengthComputable&&(r=Math.ceil(a/n*100)),t.uploadProgress(e,a,n,r)},!1),r}),s.data=null;var c=s.beforeSend;return s.beforeSend=function(e,r){r.data=t.formData?t.formData:a,c&&c.call(this,e,r)},e.ajax(s)}(p):e.ajax(t),u.removeData("jqxhr").data("jqxhr",S);for(var k=0;k<d.length;k++)d[k]=null;return this.trigger("form-submit-notify",[this,t]),this},e.fn.ajaxForm=function(n){if((n=n||{}).delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!e.isReady&&i.s?(a("DOM not ready, queuing ajaxForm"),e(function(){e(i.s,i.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,r).on("submit.form-plugin",this.selector,n,t).on("click.form-plugin",this.selector,n,r),this):this.ajaxFormUnbind().bind("submit.form-plugin",n,t).bind("click.form-plugin",n,r)},e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r){var a=[];if(0===this.length)return a;var i,o,s,c,u,l,f,m,d=this[0],p=this.attr("id"),h=t?d.getElementsByTagName("*"):d.elements;if(h&&!/MSIE [678]/.test(navigator.userAgent)&&(h=e(h).get()),p&&((i=e(':input[form="'+p+'"]').get()).length&&(h=(h||[]).concat(i))),!h||!h.length)return a;for(o=0,f=h.length;f>o;o++)if(l=h[o],c=l.name,c&&!l.disabled)if(t&&d.clk&&"image"==l.type)d.clk==l&&(a.push({name:c,value:e(l).val(),type:l.type}),a.push({name:c+".x",value:d.clk_x},{name:c+".y",value:d.clk_y}));else if(u=e.fieldValue(l,!0),u&&u.constructor==Array)for(r&&r.push(l),s=0,m=u.length;m>s;s++)a.push({name:c,value:u[s]});else if(n.fileapi&&"file"==l.type){r&&r.push(l);var v=l.files;if(v.length)for(s=0;s<v.length;s++)a.push({name:c,value:v[s],type:l.type});else a.push({name:c,value:"",type:l.type})}else null!==u&&void 0!==u&&(r&&r.push(l),a.push({name:c,value:u,type:l.type,required:l.required}));if(!t&&d.clk){var g=e(d.clk),x=g[0];(c=x.name)&&!x.disabled&&"image"==x.type&&(a.push({name:c,value:g.val()}),a.push({name:c+".x",value:d.clk_x},{name:c+".y",value:d.clk_y}))}return a},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var r=[];return this.each(function(){var a=this.name;if(a){var n=e.fieldValue(this,t);if(n&&n.constructor==Array)for(var i=0,o=n.length;o>i;i++)r.push({name:a,value:n[i]});else null!==n&&void 0!==n&&r.push({name:this.name,value:n})}}),e.param(r)},e.fn.fieldValue=function(t){for(var r=[],a=0,n=this.length;n>a;a++){var i=this[a],o=e.fieldValue(i,t);null===o||void 0===o||o.constructor==Array&&!o.length||(o.constructor==Array?e.merge(r,o):r.push(o))}return r},e.fieldValue=function(t,r){var a=t.name,n=t.type,i=t.tagName.toLowerCase();if(void 0===r&&(r=!0),r&&(!a||t.disabled||"reset"==n||"button"==n||("checkbox"==n||"radio"==n)&&!t.checked||("submit"==n||"image"==n)&&t.form&&t.form.clk!=t||"select"==i&&-1==t.selectedIndex))return null;if("select"==i){var o=t.selectedIndex;if(0>o)return null;for(var s=[],c=t.options,u="select-one"==n,l=u?o+1:c.length,f=u?o:0;l>f;f++){var m=c[f];if(m.selected){var d=m.value;if(d||(d=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),u)return d;s.push(d)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var r=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var a=this.type,n=this.tagName.toLowerCase();r.test(a)||"textarea"==n?this.value="":"checkbox"==a||"radio"==a?this.checked=!1:"select"==n?this.selectedIndex=-1:"file"==a?/MSIE/.test(navigator.userAgent)?e(this).replaceWith(e(this).clone(!0)):e(this).val(""):t&&(!0===t&&/hidden/.test(a)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var r=this.type;if("checkbox"==r||"radio"==r)this.checked=t;else if("option"==this.tagName.toLowerCase()){var a=e(this).parent("select");t&&a[0]&&"select-one"==a[0].type&&a.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1});