(function($){
$.fn.ajaxSubmit=function(_1){
if(!this.length){
_2("ajaxSubmit: skipping submit process - no element selected");
return this;
}
if(typeof _1=="function"){
_1={success:_1};
}
var _3=$.trim(this.attr("action"));
if(_3){
_3=(_3.match(/^([^#]+)/)||[])[1];
}
_3=_3||window.location.href||"";
_1=$.extend({url:_3,type:this.attr("method")||"GET"},_1||{});
var _4={};
this.trigger("form-pre-serialize",[this,_1,_4]);
if(_4.veto){
_2("ajaxSubmit: submit vetoed via form-pre-serialize trigger");
return this;
}
if(_1.beforeSerialize&&_1.beforeSerialize(this,_1)===false){
_2("ajaxSubmit: submit aborted via beforeSerialize callback");
return this;
}
var a=this.formToArray(_1.semantic);
if(_1.data){
_1.extraData=_1.data;
for(var n in _1.data){
if(_1.data[n] instanceof Array){
for(var k in _1.data[n]){
a.push({name:n,value:_1.data[n][k]});
}
}else{
a.push({name:n,value:_1.data[n]});
}
}
}
if(_1.beforeSubmit&&_1.beforeSubmit(a,this,_1)===false){
_2("ajaxSubmit: submit aborted via beforeSubmit callback");
return this;
}
this.trigger("form-submit-validate",[a,this,_1,_4]);
if(_4.veto){
_2("ajaxSubmit: submit vetoed via form-submit-validate trigger");
return this;
}
var q=$.param(a);
if(_1.type.toUpperCase()=="GET"){
_1.url+=(_1.url.indexOf("?")>=0?"&":"?")+q;
_1.data=null;
}else{
_1.data=q;
}
var _5=this,_6=[];
if(_1.resetForm){
_6.push(function(){
_5.resetForm();
});
}
if(_1.clearForm){
_6.push(function(){
_5.clearForm();
});
}
if(!_1.dataType&&_1.target){
var _7=_1.success||function(){
};
_6.push(function(_8){
$(_1.target).html(_8).each(_7,arguments);
});
}else{
if(_1.success){
_6.push(_1.success);
}
}
_1.success=function(_9,_a){
for(var i=0,_b=_6.length;i<_b;i++){
_6[i].apply(_1,[_9,_a,_5]);
}
};
var _c=$("input:file",this).fieldValue();
var _d=false;
for(var j=0;j<_c.length;j++){
if(_c[j]){
_d=true;
}
}
var _e=false;
if(_1.iframe||_d||_e){
if(_1.closeKeepAlive){
$.get(_1.closeKeepAlive,_f);
}else{
_f();
}
}else{
$.ajax(_1);
}
this.trigger("form-submit-notify",[this,_1]);
return this;
function _f(){
var _10=_5[0];
if($(":input[name=submit]",_10).length){
alert("Error: Form elements must not be named \"submit\".");
return;
}
var _11=$.extend({},$.ajaxSettings,_1);
var s=$.extend(true,{},$.extend(true,{},$.ajaxSettings),_11);
var id="jqFormIO"+(new Date().getTime());
var $io=$("<iframe id=\""+id+"\" name=\""+id+"\" src=\"about:blank\" />");
var io=$io[0];
$io.css({position:"absolute",top:"-1000px",left:"-1000px"});
var xhr={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){
},getResponseHeader:function(){
},setRequestHeader:function(){
},abort:function(){
this.aborted=1;
$io.attr("src","about:blank");
}};
var g=_11.global;
if(g&&!$.active++){
$.event.trigger("ajaxStart");
}
if(g){
$.event.trigger("ajaxSend",[xhr,_11]);
}
if(s.beforeSend&&s.beforeSend(xhr,s)===false){
s.global&&$.active--;
return;
}
if(xhr.aborted){
return;
}
var _12=0;
var _13=0;
var sub=_10.clk;
if(sub){
var n=sub.name;
if(n&&!sub.disabled){
_1.extraData=_1.extraData||{};
_1.extraData[n]=sub.value;
if(sub.type=="image"){
_1.extraData[name+".x"]=_10.clk_x;
_1.extraData[name+".y"]=_10.clk_y;
}
}
}
setTimeout(function(){
var t=_5.attr("target"),a=_5.attr("action");
_10.setAttribute("target",id);
if(_10.getAttribute("method")!="POST"){
_10.setAttribute("method","POST");
}
if(_10.getAttribute("action")!=_11.url){
_10.setAttribute("action",_11.url);
}
if(!_1.skipEncodingOverride){
_5.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});
}
if(_11.timeout){
setTimeout(function(){
_13=true;
cb();
},_11.timeout);
}
var _14=[];
try{
if(_1.extraData){
for(var n in _1.extraData){
_14.push($("<input type=\"hidden\" name=\""+n+"\" value=\""+_1.extraData[n]+"\" />").appendTo(_10)[0]);
}
}
$io.appendTo("body");
io.attachEvent?io.attachEvent("onload",cb):io.addEventListener("load",cb,false);
_10.submit();
}
finally{
_10.setAttribute("action",a);
t?_10.setAttribute("target",t):_5.removeAttr("target");
$(_14).remove();
}
},10);
var _15=0;
function cb(){
if(_12++){
return;
}
io.detachEvent?io.detachEvent("onload",cb):io.removeEventListener("load",cb,false);
var ok=true;
try{
if(_13){
throw "timeout";
}
var _16,doc;
doc=io.contentWindow?io.contentWindow.document:io.contentDocument?io.contentDocument:io.document;
if((doc.body==null||doc.body.innerHTML=="")&&!_15){
_15=1;
_12--;
setTimeout(cb,100);
return;
}
xhr.responseText=doc.body?doc.body.innerHTML:null;
xhr.responseXML=doc.XMLDocument?doc.XMLDocument:doc;
xhr.getResponseHeader=function(_17){
var _18={"content-type":_11.dataType};
return _18[_17];
};
if(_11.dataType=="json"||_11.dataType=="script"){
var ta=doc.getElementsByTagName("textarea")[0];
xhr.responseText=ta?ta.value:xhr.responseText;
}else{
if(_11.dataType=="xml"&&!xhr.responseXML&&xhr.responseText!=null){
xhr.responseXML=_19(xhr.responseText);
}
}
_16=$.httpData(xhr,_11.dataType);
}
catch(e){
ok=false;
$.handleError(_11,xhr,"error",e);
}
if(ok){
_11.success(_16,"success");
if(g){
$.event.trigger("ajaxSuccess",[xhr,_11]);
}
}
if(g){
$.event.trigger("ajaxComplete",[xhr,_11]);
}
if(g&&!--$.active){
$.event.trigger("ajaxStop");
}
if(_11.complete){
_11.complete(xhr,ok?"success":"error");
}
setTimeout(function(){
$io.remove();
xhr.responseXML=null;
},100);
};
function _19(s,doc){
if(window.ActiveXObject){
doc=new ActiveXObject("Microsoft.XMLDOM");
doc.async="false";
doc.loadXML(s);
}else{
doc=(new DOMParser()).parseFromString(s,"text/xml");
}
return (doc&&doc.documentElement&&doc.documentElement.tagName!="parsererror")?doc:null;
};
};
};
$.fn.ajaxForm=function(_1a){
return this.ajaxFormUnbind().bind("submit.form-plugin",function(){
$(this).ajaxSubmit(_1a);
return false;
}).each(function(){
$(":submit,input:image",this).bind("click.form-plugin",function(e){
var _1b=this.form;
_1b.clk=this;
if(this.type=="image"){
if(e.offsetX!=undefined){
_1b.clk_x=e.offsetX;
_1b.clk_y=e.offsetY;
}else{
if(typeof $.fn.offset=="function"){
var _1c=$(this).offset();
_1b.clk_x=e.pageX-_1c.left;
_1b.clk_y=e.pageY-_1c.top;
}else{
_1b.clk_x=e.pageX-this.offsetLeft;
_1b.clk_y=e.pageY-this.offsetTop;
}
}
}
setTimeout(function(){
_1b.clk=_1b.clk_x=_1b.clk_y=null;
},10);
});
});
};
$.fn.ajaxFormUnbind=function(){
this.unbind("submit.form-plugin");
return this.each(function(){
$(":submit,input:image",this).unbind("click.form-plugin");
});
};
$.fn.formToArray=function(_1d){
var a=[];
if(this.length==0){
return a;
}
var _1e=this[0];
var els=_1d?_1e.getElementsByTagName("*"):_1e.elements;
if(!els){
return a;
}
for(var i=0,max=els.length;i<max;i++){
var el=els[i];
var n=el.name;
if(!n){
continue;
}
if(_1d&&_1e.clk&&el.type=="image"){
if(!el.disabled&&_1e.clk==el){
a.push({name:n,value:$(el).val()});
a.push({name:n+".x",value:_1e.clk_x},{name:n+".y",value:_1e.clk_y});
}
continue;
}
var v=$.fieldValue(el,true);
if(v&&v.constructor==Array){
for(var j=0,_1f=v.length;j<_1f;j++){
a.push({name:n,value:v[j]});
}
}else{
if(v!==null&&typeof v!="undefined"){
a.push({name:n,value:v});
}
}
}
if(!_1d&&_1e.clk){
var _20=$(_1e.clk),_21=_20[0],n=_21.name;
if(n&&!_21.disabled&&_21.type=="image"){
a.push({name:n,value:_20.val()});
a.push({name:n+".x",value:_1e.clk_x},{name:n+".y",value:_1e.clk_y});
}
}
return a;
};
$.fn.formSerialize=function(_22){
return $.param(this.formToArray(_22));
};
$.fn.fieldSerialize=function(_23){
var a=[];
this.each(function(){
var n=this.name;
if(!n){
return;
}
var v=$.fieldValue(this,_23);
if(v&&v.constructor==Array){
for(var i=0,max=v.length;i<max;i++){
a.push({name:n,value:v[i]});
}
}else{
if(v!==null&&typeof v!="undefined"){
a.push({name:this.name,value:v});
}
}
});
return $.param(a);
};
$.fn.fieldValue=function(_24){
for(var val=[],i=0,max=this.length;i<max;i++){
var el=this[i];
var v=$.fieldValue(el,_24);
if(v===null||typeof v=="undefined"||(v.constructor==Array&&!v.length)){
continue;
}
v.constructor==Array?$.merge(val,v):val.push(v);
}
return val;
};
$.fieldValue=function(el,_25){
var n=el.name,t=el.type,tag=el.tagName.toLowerCase();
if(typeof _25=="undefined"){
_25=true;
}
if(_25&&(!n||el.disabled||t=="reset"||t=="button"||(t=="checkbox"||t=="radio")&&!el.checked||(t=="submit"||t=="image")&&el.form&&el.form.clk!=el||tag=="select"&&el.selectedIndex==-1)){
return null;
}
if(tag=="select"){
var _26=el.selectedIndex;
if(_26<0){
return null;
}
var a=[],ops=el.options;
var one=(t=="select-one");
var max=(one?_26+1:ops.length);
for(var i=(one?_26:0);i<max;i++){
var op=ops[i];
if(op.selected){
var v=op.value;
if(!v){
v=(op.attributes&&op.attributes["value"]&&!(op.attributes["value"].specified))?op.text:op.value;
}
if(one){
return v;
}
a.push(v);
}
}
return a;
}
return el.value;
};
$.fn.clearForm=function(){
return this.each(function(){
$("input,select,textarea",this).clearFields();
});
};
$.fn.clearFields=$.fn.clearInputs=function(){
return this.each(function(){
var t=this.type,tag=this.tagName.toLowerCase();
if(t=="text"||t=="password"||tag=="textarea"){
this.value="";
}else{
if(t=="checkbox"||t=="radio"){
this.checked=false;
}else{
if(tag=="select"){
this.selectedIndex=-1;
}
}
}
});
};
$.fn.resetForm=function(){
return this.each(function(){
if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){
this.reset();
}
});
};
$.fn.enable=function(b){
if(b==undefined){
b=true;
}
return this.each(function(){
this.disabled=!b;
});
};
$.fn.selected=function(_27){
if(_27==undefined){
_27=true;
}
return this.each(function(){
var t=this.type;
if(t=="checkbox"||t=="radio"){
this.checked=_27;
}else{
if(this.tagName.toLowerCase()=="option"){
var _28=$(this).parent("select");
if(_27&&_28[0]&&_28[0].type=="select-one"){
_28.find("option").selected(false);
}
this.selected=_27;
}
}
});
};
function _2(){
if($.fn.ajaxSubmit.debug&&window.console&&window.console.log){
window.console.log("[jquery.form] "+Array.prototype.join.call(arguments,""));
}
};
})(jQuery);

