(function(a){a.fn.extend({abform:function(b){var e={attributes:'id="my-form" action="#" method="post"',sequential_disable:true,pluggable:false,serialized:true,multipart:false,clickonce:true,filtertext:true,textfilters:"url=,link=,http:,www.,href,<a",convert:false,obj:a(this)};var b=a.extend(e,b);var d=a(this);return this.each(function(){var y=b,s=y.attributes,f=y.sequential_disable,z=y.pluggable,l=y.serialized,w=y.multipart,p=y.clickonce,q=y.filtertext,g=y.textfilters,r=y.convert,t=[];var x=d.attr("id");if(r){var u=r.split("{");for(var B in u){if(B>0){var h=u[B].split("}");h=h[0];var C=h.split("|");var n=(!C[0])?alert("Error! Code misconfiguration. Disable A Better Form convert option or check the documentation to learn how to properly code the convert option. You are missing the element id option."):C[0];var k=(!C[1])?alert("Error! Code misconfiguration. Disable A Better Form convert option or check the documentation to learn how to properly code the convert option. You are missing the element type option."):C[1];var j=(C[2])?" "+C[2]:"";var A=a("#"+n).html();var m="";switch(k){case"text":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"textarea":m='<textarea id="'+n+'" name="'+n+'"'+j+">"+A+"</textarea>";break;case"password":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"file":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"button":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"submit":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"reset":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"image":m='<input id="'+n+'" name="'+n+'" type="'+k+'" src="'+A+'"'+j+" />";break;case"radio":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"checkbox":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break;case"select":m='<select id="'+n+'" name="'+n+'"'+j+">";a("#"+n+" ul").each(function(){if(a(this).attr("title")){m+='<optgroup label="'+a(this).attr("title")+'">'}a("li").each(function(){m+='<option value="'+a(this).attr("id")+'">'+a(this).html()+"</option>"});if(a(this).attr("title")){m+="</optgroup>"}});m+="</select>";break;case"hidden":m='<input id="'+n+'" name="'+n+'" type="'+k+'" value="'+A+'"'+j+" />";break}a("#"+n).replaceWith(m)}}}var v=a("#"+x+" input, #"+x+" textarea, #"+x+" select");a("#"+x+" input, #"+x+" textarea, #"+x+" select").each(function(){t.push(a(this).attr("id"));if(a(this).is("input")&&(a(this).attr("type")=="radio"||a(this).attr("type")=="checkbox")){a(this).attr("name",a(this).attr("id"))}});if(f){v.attr("disabled","disabled");v.first().attr("disabled","");c(x,t)}a("#"+x+" input, #"+x+" textarea, #"+x+" select").each(function(i){var D=i+1;var o=a("#"+t[D]).attr("id");if(a(this).is("select")||(a(this).is("input")&&(a(this).attr("type")=="file"||a(this).attr("type")=="radio"||a(this).attr("type")=="checkbox"))){a(this).bind("change",function(){if(a(this).val()!=""){a(this).attr("name",a(this).attr("id"));a("#"+t[D]).attr("disabled","")}else{if(a(this).attr("type")!="radio"||a(this).attr("type")!="checkbox"){a(this).attr("name","")}}if(f){c(x,t)}})}if(a(this).is("input, textarea")&&a(this).attr("type")!="file"&&a(this).attr("type")!="radio"&&a(this).attr("type")!="checkbox"){a(this).bind("keyup change",function(){if(a(this).val()!=""){if(q){var E=g.split(",");for(var F in E){var G=a(this).val().split(E[F]);if(G.length>1){a(this).val(G[0])}}}a("#"+t[D]).attr("disabled","");a(this).attr("name",a(this).attr("id"))}else{a(this).attr("name","")}if(f){c(x,t)}})}});a("#"+x+" optgroup").each(function(D){if(a(this).hasClass("aboptgroup")){var o=a(this).html();a(this).replaceWith('\n<optgroup label="'+a(this).attr("id")+'">\n'+o+"\n</optgroup>\n");a(this).attr("label",a(this).attr("id"))}else{a(this).attr("name",a(this).attr("id"))}});a(".absubmit").bind("click",function(){if(a(this).attr("disabled")!="disabled"){a("#"+x+" input").each(function(){if(a(this).attr("type")=="hidden"){a(this).attr({disabled:"",name:a(this).attr("id")})}});var i=(w)?"<form "+s+' enctype="multipart/form-data"></form>':"<form "+s+"></form>";d.wrapInner(i);if(z&&a.isFunction(z)){if(l){z(a(":parent").serialize())}else{z()}}else{a(":parent").submit()}}if(p){a(this).attr("disabled","disabled")}})});function c(g,f){a("#"+g+" input, #"+g+" textarea, #"+g+" select").each(function(h){var i=false;for(var j in f){if(j<h){if(a("#"+f[j]).val()==""){i=true}}}if(i){a("#"+f[h]).attr("disabled","disabled")}else{if(a(this).is("input")&&(a(this).attr("type")=="radio"||a(this).attr("type")=="checkbox")){a("[id="+a(this).attr("id")+"]").each(function(){a(this).attr("disabled","")})}else{a("#"+f[h]).attr("disabled","")}}})}}})})(jQuery);
