/*
 jQuery Form Plugin
 version: 4.3.0
 Requires jQuery v1.7.2 or later
 Project repository: https://github.com/jquery-form/form

 Copyright 2017 Kevin Morris
 Copyright 2006 M. Alsup

 Dual licensed under the LGPL-2.1+ or MIT licenses
 https://github.com/jquery-form/form#license

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
*/
(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):"object"===typeof module&&module.exports?module.exports=function(T,M){"undefined"===typeof M&&(M="undefined"!==typeof window?require("jquery"):require("jquery")(T));b(M);return M}:b(jQuery)})(function(b){function T(a){var d=a.data;a.isDefaultPrevented()||(a.preventDefault(),b(a.target).closest("form").ajaxSubmit(d))}function M(a){var d=a.target,g=b(d);if(!g.is("[type=submit],[type=image]")){d=g.closest("[type=submit]");if(0===
d.length)return;d=d[0]}var e=d.form;e.clk=d;"image"===d.type&&("undefined"!==typeof a.offsetX?(e.clk_x=a.offsetX,e.clk_y=a.offsetY):"function"===typeof b.fn.offset?(g=g.offset(),e.clk_x=a.pageX-g.left,e.clk_y=a.pageY-g.top):(e.clk_x=a.pageX-d.offsetLeft,e.clk_y=a.pageY-d.offsetTop));setTimeout(function(){e.clk=e.clk_x=e.clk_y=null},100)}function w(){if(b.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)}}var da=/\r?\n/g;var Z=void 0!==b('<input type="file">').get(0).files;var ea="undefined"!==typeof window.FormData;var aa=!!b.fn.prop;b.fn.attr2=function(){if(!aa)return this.attr.apply(this,arguments);var a=this.prop.apply(this,arguments);return a&&a.jquery||"string"===typeof a?a:this.attr.apply(this,arguments)};b.fn.ajaxSubmit=function(a,d,g,e){function m(n){n=b.param(n,a.traditional).split("&");var A=n.length,r=[],v;for(v=0;v<A;v++){n[v]=n[v].replace(/\+/g,
" ");var p=n[v].split("=");r.push([decodeURIComponent(p[0]),decodeURIComponent(p[1])])}return r}function t(n){for(var A=new FormData,r=0;r<n.length;r++)A.append(n[r].name,n[r].value);if(a.extraData)for(n=m(a.extraData),r=0;r<n.length;r++)n[r]&&A.append(n[r][0],n[r][1]);a.data=null;r=b.extend(!0,{},b.ajaxSettings,a,{contentType:!1,processData:!1,cache:!1,type:J||"POST"});a.uploadProgress&&(r.xhr=function(){var p=b.ajaxSettings.xhr();p.upload&&p.upload.addEventListener("progress",function(u){var F=
0,R=u.loaded||u.position,N=u.total;u.lengthComputable&&(F=Math.ceil(R/N*100));a.uploadProgress(u,R,N,F)},!1);return p});r.data=null;var v=r.beforeSend;r.beforeSend=function(p,u){u.data=a.formData?a.formData:A;v&&v.call(this,p,u)};return b.ajax(r)}function y(n){function A(h){var k=null;try{h.contentWindow&&(k=h.contentWindow.document)}catch(B){w("cannot get iframe.contentWindow document: "+B)}if(k)return k;try{k=h.contentDocument?h.contentDocument:h.document}catch(B){w("cannot get iframe.contentDocument: "+
B),k=h.document}return k}function r(){function h(){try{var K=A(G).readyState;w("state = "+K);K&&"uninitialized"===K.toLowerCase()&&setTimeout(h,50)}catch(O){w("Server abort: ",O," (",O.name,")"),v(2),N&&clearTimeout(N),N=void 0}}var k=q.attr2("target"),B=q.attr2("action"),D=q.attr("enctype")||q.attr("encoding")||"multipart/form-data";p.setAttribute("target",V);J&&!/post/i.test(J)||p.setAttribute("method","POST");B!==c.url&&p.setAttribute("action",c.url);c.skipEncodingOverride||J&&!/post/i.test(J)||
q.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});c.timeout&&(N=setTimeout(function(){R=!0;v(1)},c.timeout));var H=[];try{if(c.extraData)for(var E in c.extraData)c.extraData.hasOwnProperty(E)&&(b.isPlainObject(c.extraData[E])&&c.extraData[E].hasOwnProperty("name")&&c.extraData[E].hasOwnProperty("value")?H.push(b('<input type="hidden" name="'+c.extraData[E].name+'">',W).val(c.extraData[E].value).appendTo(p)[0]):H.push(b('<input type="hidden" name="'+E+'">',W).val(c.extraData[E]).appendTo(p)[0]));
c.iframeTarget||L.appendTo(fa);G.attachEvent?G.attachEvent("onload",v):G.addEventListener("load",v,!1);setTimeout(h,15);try{p.submit()}catch(K){document.createElement("form").submit.apply(p)}}finally{p.setAttribute("action",B),p.setAttribute("enctype",D),k?p.setAttribute("target",k):q.removeAttr("target"),b(H).remove()}}function v(h){if(!f.aborted&&!ba)if(z=A(G),z||(w("cannot access response document"),h=2),1===h&&f)f.abort("timeout"),I.reject(f,"timeout");else if(2===h&&f)f.abort("server abort"),
I.reject(f,"error","server abort");else if(z&&z.location.href!==c.iframeSrc||R){G.detachEvent?G.detachEvent("onload",v):G.removeEventListener("load",v,!1);h="success";var k;try{if(R)throw"timeout";var B="xml"===c.dataType||z.XMLDocument||b.isXMLDoc(z);w("isXml="+B);if(!B&&window.opera&&(null===z.body||!z.body.innerHTML)&&--ha){w("requeing onLoad callback, DOM not available");setTimeout(v,250);return}var D=z.body?z.body:z.documentElement;f.responseText=D?D.innerHTML:null;f.responseXML=z.XMLDocument?
z.XMLDocument:z;B&&(c.dataType="xml");f.getResponseHeader=function(S){return{"content-type":c.dataType}[S.toLowerCase()]};D&&(f.status=Number(D.getAttribute("status"))||f.status,f.statusText=D.getAttribute("statusText")||f.statusText);var H=(c.dataType||"").toLowerCase(),E=/(json|script|text)/.test(H);if(E||c.textarea){var K=z.getElementsByTagName("textarea")[0];if(K)f.responseText=K.value,f.status=Number(K.getAttribute("status"))||f.status,f.statusText=K.getAttribute("statusText")||f.statusText;
else if(E){var O=z.getElementsByTagName("pre")[0],X=z.getElementsByTagName("body")[0];O?f.responseText=O.textContent?O.textContent:O.innerText:X&&(f.responseText=X.textContent?X.textContent:X.innerText)}}else"xml"===H&&!f.responseXML&&f.responseText&&(f.responseXML=ia(f.responseText));try{ca=ja(f,H,c)}catch(S){h="parsererror",f.error=k=S||h}}catch(S){w("error caught: ",S),h="error",f.error=k=S||h}f.aborted&&(w("upload aborted"),h=null);f.status&&(h=200<=f.status&&300>f.status||304===f.status?"success":
"error");"success"===h?(c.success&&c.success.call(c.context,ca,"success",f),I.resolve(f.responseText,"success",f),F&&b.event.trigger("ajaxSuccess",[f,c])):h&&("undefined"===typeof k&&(k=f.statusText),c.error&&c.error.call(c.context,f,h,k),I.reject(f,"error",k),F&&b.event.trigger("ajaxError",[f,c,k]));F&&b.event.trigger("ajaxComplete",[f,c]);F&&!--b.active&&b.event.trigger("ajaxStop");c.complete&&c.complete.call(c.context,f,h);ba=!0;c.timeout&&clearTimeout(N);setTimeout(function(){c.iframeTarget?L.attr("src",
c.iframeSrc):L.remove();f.responseXML=null},100)}}var p=q[0],u,F,R,N,I=b.Deferred();I.abort=function(h){f.abort(h)};if(n)for(u=0;u<U.length;u++)n=b(U[u]),aa?n.prop("disabled",!1):n.removeAttr("disabled");var c=b.extend(!0,{},b.ajaxSettings,a);c.context=c.context||c;var V="jqFormIO"+(new Date).getTime();var W=p.ownerDocument,fa=q.closest("body");if(c.iframeTarget){var L=b(c.iframeTarget,W);(u=L.attr2("name"))?V=u:L.attr2("name",V)}else L=b('<iframe name="'+V+'" src="'+c.iframeSrc+'" />',W),L.css({position:"absolute",
top:"-1000px",left:"-1000px"});var G=L[0];var f={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(h){var k="timeout"===h?"timeout":"aborted";w("aborting upload... "+k);this.aborted=1;try{G.contentWindow.document.execCommand&&G.contentWindow.document.execCommand("Stop")}catch(B){}L.attr("src",c.iframeSrc);f.error=k;c.error&&c.error.call(c.context,f,k,h);F&&b.event.trigger("ajaxError",
[f,c,k]);c.complete&&c.complete.call(c.context,f,k)}};(F=c.global)&&0===b.active++&&b.event.trigger("ajaxStart");F&&b.event.trigger("ajaxSend",[f,c]);if(c.beforeSend&&!1===c.beforeSend.call(c.context,f,c))return c.global&&b.active--,I.reject(),I;if(f.aborted)return I.reject(),I;(n=p.clk)&&(u=n.name)&&!n.disabled&&(c.extraData=c.extraData||{},c.extraData[u]=n.value,"image"===n.type&&(c.extraData[u+".x"]=p.clk_x,c.extraData[u+".y"]=p.clk_y));n=b("meta[name=csrf-token]").attr("content");(u=b("meta[name=csrf-param]").attr("content"))&&
n&&(c.extraData=c.extraData||{},c.extraData[u]=n);c.forceSync?r():setTimeout(r,10);var ca,z,ha=50,ba,ia=b.parseXML||function(h,k){window.ActiveXObject?(k=new ActiveXObject("Microsoft.XMLDOM"),k.async="false",k.loadXML(h)):k=(new DOMParser).parseFromString(h,"text/xml");return k&&k.documentElement&&"parsererror"!==k.documentElement.nodeName?k:null},ka=b.parseJSON||function(h){return window.eval("("+h+")")},ja=function(h,k,B){var D=h.getResponseHeader("content-type")||"",H=("xml"===k||!k)&&0<=D.indexOf("xml");
h=H?h.responseXML:h.responseText;H&&"parsererror"===h.documentElement.nodeName&&b.error&&b.error("parsererror");B&&B.dataFilter&&(h=B.dataFilter(h,k));"string"===typeof h&&(("json"===k||!k)&&0<=D.indexOf("json")?h=ka(h):("script"===k||!k)&&0<=D.indexOf("javascript")&&b.globalEval(h));return h};return I}if(!this.length)return w("ajaxSubmit: skipping submit process - no element selected"),this;var q=this;"function"===typeof a?a={success:a}:"string"===typeof a||!1===a&&0<arguments.length?(a={url:a,data:d,
dataType:g},"function"===typeof e&&(a.success=e)):"undefined"===typeof a&&(a={});var J=a.method||a.type||this.attr2("method");var l=a.url||this.attr2("action");(l=(l="string"===typeof l?l.trim():"")||window.location.href||"")&&(l=(l.match(/^([^#]+)/)||[])[1]);var x=/(MSIE|Trident)/.test(navigator.userAgent||"")&&/^https/i.test(window.location.href||"")?"javascript:false":"about:blank";a=b.extend(!0,{url:l,success:b.ajaxSettings.success,type:J||b.ajaxSettings.type,iframeSrc:x},a);l={};this.trigger("form-pre-serialize",
[this,a,l]);if(l.veto)return w("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(a.beforeSerialize&&!1===a.beforeSerialize(this,a))return w("ajaxSubmit: submit aborted via beforeSerialize callback"),this;x=a.traditional;"undefined"===typeof x&&(x=b.ajaxSettings.traditional);var U=[],P=this.formToArray(a.semantic,U,a.filtering);if(a.data){var C="function"===typeof a.data?a.data(P):a.data;a.extraData=C;C=b.param(C,x)}if(a.beforeSubmit&&!1===a.beforeSubmit(P,this,a))return w("ajaxSubmit: submit aborted via beforeSubmit callback"),
this;this.trigger("form-submit-validate",[P,this,a,l]);if(l.veto)return w("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;l=b.param(P,x);C&&(l=l?l+"&"+C:C);"GET"===a.type.toUpperCase()?(a.url+=(0<=a.url.indexOf("?")?"&":"?")+l,a.data=null):a.data=l;var Q=[];a.resetForm&&Q.push(function(){q.resetForm()});a.clearForm&&Q.push(function(){q.clearForm(a.includeHidden)});if(!a.dataType&&a.target){var la=a.success||function(){};Q.push(function(n,A,r){var v=arguments,p=a.replaceTarget?"replaceWith":
"html";b(a.target)[p](n).each(function(){la.apply(this,v)})})}else a.success&&(Array.isArray(a.success)?b.merge(Q,a.success):Q.push(a.success));a.success=function(n,A,r){for(var v=a.context||this,p=0,u=Q.length;p<u;p++)Q[p].apply(v,[n,A,r||q,q])};if(a.error){var ma=a.error;a.error=function(n,A,r){ma.apply(a.context||this,[n,A,r,q])}}if(a.complete){var na=a.complete;a.complete=function(n,A){na.apply(a.context||this,[n,A,q])}}C=0<b("input[type=file]:enabled",this).filter(function(){return""!==b(this).val()}).length;
l="multipart/form-data"===q.attr("enctype")||"multipart/form-data"===q.attr("encoding");x=Z&&ea;w("fileAPI :"+x);var Y;!1!==a.iframe&&(a.iframe||(C||l)&&!x)?a.closeKeepAlive?b.get(a.closeKeepAlive,function(){Y=y(P)}):Y=y(P):Y=(C||l)&&x?t(P):b.ajax(a);q.removeData("jqxhr").data("jqxhr",Y);for(C=0;C<U.length;C++)U[C]=null;this.trigger("form-submit-notify",[this,a]);return this};b.fn.ajaxForm=function(a,d,g,e){if("string"===typeof a||!1===a&&0<arguments.length)a={url:a,data:d,dataType:g},"function"===
typeof e&&(a.success=e);a=a||{};a.delegation=a.delegation&&"function"===typeof b.fn.on;if(!a.delegation&&0===this.length){var m=this.selector,t=this.context;if(!b.isReady&&m)return w("DOM not ready, queuing ajaxForm"),b(function(){b(m,t).ajaxForm(a)}),this;w("terminating; zero elements found by selector"+(b.isReady?"":" (DOM not ready)"));return this}if(a.delegation)return b(document).off("submit.form-plugin",this.selector,T).off("click.form-plugin",this.selector,M).on("submit.form-plugin",this.selector,
a,T).on("click.form-plugin",this.selector,a,M),this;a.beforeFormUnbind&&a.beforeFormUnbind(this,a);return this.ajaxFormUnbind().on("submit.form-plugin",a,T).on("click.form-plugin",a,M)};b.fn.ajaxFormUnbind=function(){return this.off("submit.form-plugin click.form-plugin")};b.fn.formToArray=function(a,d,g){var e=[];if(0===this.length)return e;var m=this[0],t=this.attr("id"),y=a||"undefined"===typeof m.elements?m.getElementsByTagName("*"):m.elements;y&&=b.makeArray(y);t&&(a||/(Edge|Trident)\//.test(navigator.userAgent))&&
(t=b(':input[form="'+t+'"]').get(),t.length&&(y=(y||[]).concat(t)));if(!y||!y.length)return e;"function"===typeof g&&(y=b.map(y,g));var q,J;t=0;for(J=y.length;t<J;t++){var l=y[t];if((g=l.name)&&!l.disabled)if(a&&m.clk&&"image"===l.type)m.clk===l&&(e.push({name:g,value:b(l).val(),type:l.type}),e.push({name:g+".x",value:m.clk_x},{name:g+".y",value:m.clk_y}));else if((q=b.fieldValue(l,!0))&&q.constructor===Array){d&&d.push(l);var x=0;for(l=q.length;x<l;x++)e.push({name:g,value:q[x]})}else if(Z&&"file"===
l.type)if(d&&d.push(l),q=l.files,q.length)for(x=0;x<q.length;x++)e.push({name:g,value:q[x],type:l.type});else e.push({name:g,value:"",type:l.type});else null!==q&&"undefined"!==typeof q&&(d&&d.push(l),e.push({name:g,value:q,type:l.type,required:l.required}))}!a&&m.clk&&(a=b(m.clk),d=a[0],(g=d.name)&&!d.disabled&&"image"===d.type&&(e.push({name:g,value:a.val()}),e.push({name:g+".x",value:m.clk_x},{name:g+".y",value:m.clk_y})));return e};b.fn.formSerialize=function(a){return b.param(this.formToArray(a))};
b.fn.fieldSerialize=function(a){var d=[];this.each(function(){var g=this.name;if(g){var e=b.fieldValue(this,a);if(e&&e.constructor===Array)for(var m=0,t=e.length;m<t;m++)d.push({name:g,value:e[m]});else null!==e&&"undefined"!==typeof e&&d.push({name:this.name,value:e})}});return b.param(d)};b.fn.fieldValue=function(a){for(var d=[],g=0,e=this.length;g<e;g++){var m=b.fieldValue(this[g],a);null===m||"undefined"===typeof m||m.constructor===Array&&!m.length||(m.constructor===Array?b.merge(d,m):d.push(m))}return d};
b.fieldValue=function(a,d){var g=a.name,e=a.type,m=a.tagName.toLowerCase();"undefined"===typeof d&&(d=!0);if(d&&(!g||a.disabled||"reset"===e||"button"===e||("checkbox"===e||"radio"===e)&&!a.checked||("submit"===e||"image"===e)&&a.form&&a.form.clk!==a||"select"===m&&-1===a.selectedIndex))return null;if("select"===m){m=a.selectedIndex;if(0>m)return null;d=[];a=a.options;g=(e="select-one"===e)?m+1:a.length;for(m=e?m:0;m<g;m++){var t=a[m];if(t.selected&&!t.disabled){var y=t.value;y||=t.attributes&&t.attributes.value&&
!t.attributes.value.specified?t.text:t.value;if(e)return y;d.push(y)}}return d}return b(a).val().replace(da,"\r\n")};b.fn.clearForm=function(a){return this.each(function(){b("input,select,textarea",this).clearFields(a)})};b.fn.clearFields=b.fn.clearInputs=function(a){var d=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var g=this.type,e=this.tagName.toLowerCase();d.test(g)||"textarea"===e?this.value="":"checkbox"===g||"radio"===
g?this.checked=!1:"select"===e?this.selectedIndex=-1:"file"===g?/MSIE/.test(navigator.userAgent)?b(this).replaceWith(b(this).clone(!0)):b(this).val(""):a&&(!0===a&&/hidden/.test(g)||"string"===typeof a&&b(this).is(a))&&(this.value="")})};b.fn.resetForm=function(){return this.each(function(){var a=b(this),d=this.tagName.toLowerCase();switch(d){case "input":this.checked=this.defaultChecked;case "textarea":return this.value=this.defaultValue,!0;case "option":case "optgroup":var g=a.parents("select");
g.length&&g[0].multiple?"option"===d?this.selected=this.defaultSelected:a.find("option").resetForm():g.resetForm();return!0;case "select":return a.find("option").each(function(e){if((this.selected=this.defaultSelected)&&!a[0].multiple)return a[0].selectedIndex=e,!1}),!0;case "label":return d=b(a.attr("for")),g=a.find("input,select,textarea"),d[0]&&g.unshift(d[0]),g.resetForm(),!0;case "form":return("function"===typeof this.reset||"object"===typeof this.reset&&!this.reset.nodeType)&&this.reset(),!0;
default:return a.find("form,input,label,select,textarea").resetForm(),!0}})};b.fn.enable=function(a){"undefined"===typeof a&&(a=!0);return this.each(function(){this.disabled=!a})};b.fn.selected=function(a){"undefined"===typeof a&&(a=!0);return this.each(function(){var d=this.type;"checkbox"===d||"radio"===d?this.checked=a:"option"===this.tagName.toLowerCase()&&(d=b(this).parent("select"),a&&d[0]&&"select-one"===d[0].type&&d.find("option").selected(!1),this.selected=a)})};b.fn.ajaxSubmit.debug=!1});
