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