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