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