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