jQuery.fn.editInPlace=function(a){var b={url:"",params:"",field_type:"text",select_options:"",textarea_cols:"25",textarea_rows:"10",bg_over:"#ffc",bg_out:"transparent",saving_text:"Saving...",saving_image:"",default_text:"(Click here to add text)",select_text:"Choose new value",value_required:null,element_id:"element_id",update_value:"update_value",original_html:"original_html",save_button:'<input type="submit" class="inplace_save" value="Save"/>',cancel_button:'<input type="submit" class="inplace_cancel" value="Cancel"/>',callback:null,validation:null,success:null,form_css:"superBigSize",auto_save:true,error:function(d){alert("Failed to save value: "+d.responseText||"Unspecified Error")}};if(a){jQuery.extend(b,a)}if(b.saving_image!=""){var c=new Image();c.src=b.saving_image}String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")};String.prototype.escape_html=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};return this.each(function(){if(jQuery(this).html()==""){jQuery(this).html(b.default_text)}var e=false;var f=jQuery(this);var d;var g=0;jQuery(this).mouseover(function(){if(!e){jQuery(this).css("background",b.bg_over)}else{jQuery(this).css("background",b.bg_out)}}).mouseout(function(){jQuery(this).css("background",b.bg_out)}).click(function(){g++;if(!e){e=true;var l=jQuery(this).html();var q;if(b.auto_save==null){q="<br/>"+b.save_button+" "+b.cancel_button}else{q=""}if(l==b.default_text){jQuery(this).html("")}var r=(b.form_css==null)?"inplace_field":"inplace_field "+b.form_css;if(b.field_type=="textarea"){var p='<textarea  name="inplace_value" class="'+r+'" rows="'+b.textarea_rows+'" cols="'+b.textarea_cols+'">'+jQuery(this).text()+"</textarea>"}else{if(b.field_type=="text"){var p='<input type="text" name="inplace_value" class="'+r+'" value="'+jQuery(this).text().trim().escape_html()+'" />'}else{if(b.field_type=="select"){var m=b.select_options.split(",");var p='<select name="inplace_value" class="'+r+'">';for(var k=0;k<m.length;k++){var h=m[k].split(":");var n=h[1]||h[0];var j=n==l?'selected="selected" ':"";p+="<option "+j+'value="'+n.trim().escape_html()+'">'+h[0].trim().escape_html()+"</option>"}p+="</select>"}}}d='<form class="inplace_form" style="display: inline; margin: 0; padding: 0;">'+p+" "+q+'<div id="errormsg"></div></form>';jQuery(this).html(d);f.children("form").children(".inplace_field").focus().select();$j(document).keyup(function(i){if(i.keyCode==27){e=false;g=0;f.css("background",b.bg_out);f.html(l);return false}});f.children("form").children(".inplace_cancel").click(function(){e=false;g=0;f.css("background",b.bg_out);f.html(l);return false});f.children("form").children(".inplace_save").click(function(){var i=jQuery(this).parent().children(0).val();alert(i);o(i)});f.children("form").children(".inplace_field").change(function(){if(b.auto_save!=null){var i=jQuery(this).parent().children(0).val();o(i)}});if(b.field_type=="select"){f.children("form").children(".inplace_field").blur(function(){if(b.auto_save!=null){var i=jQuery(this).parent().children(0).val();o(i)}})}if(b.field_type=="text"){f.children("form").children(".inplace_field").blur(function(){if(e==true){e=false;g=0;var i=jQuery(this).parent().children(0).val();f.css("background",b.bg_out);f.html(l);return false}})}if(b.field_type=="textarea"){f.children("form").children(".inplace_field").blur(function(){if(e==true){e=false;g=0;var i=jQuery(this).text();f.css("background",b.bg_out);f.html(l);return false}})}function o(s){f.css("background",b.bg_out);if(b.saving_image!=""){var i='<img src="'+b.saving_image+'" alt="Saving..." />'}else{var i=b.saving_text}f.html(i);if(b.params!=""){b.params="&"+b.params}if(b.callback){postreq={result:true,error:""};if(b.validation){postreq=b.validation(f.attr("id"),s,l,b.params)}if(postreq.result==true){html=b.callback(f.attr("id"),s,l,b.params);e=false;g=0;if(html){f.html(html||s)}else{("Failed to save value: "+s);f.html(l)}}else{f.html(d);f.children("form").children(".inplace_save").click(function(){var t=jQuery(this).parent().children(0).val();o(t)});f.children("form").children(".inplace_field").change(function(){var t=jQuery(this).parent().children(0).val();o(t)});if(postreq.error!=""){$j("#"+f.attr("id")+" #errormsg").html(postreq.error)}}}else{if(b.value_required&&s==""){e=false;g=0;f.html(l);alert("Error: You must enter a value to save this field")}else{postreq={result:true,error:""};if(b.validation){postreq=b.validation(f.attr("id"),s,l,b.params)}if(postreq.result==true){jQuery.ajax({url:b.url,type:"POST",data:b.update_value+"="+s+"&"+b.element_id+"="+f.attr("id")+b.params+"&"+b.original_html+"="+l,dataType:"html",complete:function(t){e=false;g=0},success:function(u){var t=u||b.default_text;if(b.field_type=="select"){f.html(jQuery(d).children("select").children("option[value="+u+"]").html())}else{f.html(t)}if(b.success){b.success(u,f)}},error:function(t){f.html(l);if(b.error){b.error(t,f)}}})}else{f.html(d);f.children("form").children(".inplace_save").click(function(){var t=jQuery(this).parent().children(0).val();o(t)});f.children("form").children(".inplace_field").change(function(){var t=jQuery(this).parent().children(0).val();o(t)});if(postreq.error!=""){$j("#errormsg").html(postreq.error)}}}}return false}}})})};