Drupal.behaviors.ahah=function(context){for(var base in Drupal.settings.ahah)if(!$('#'+base+'.ahah-processed').size()){var element_settings=Drupal.settings.ahah[base];$(element_settings.selector).each(function(){element_settings.element=this;var ahah=new Drupal.ahah(base,element_settings)});$('#'+base).addClass('ahah-processed')}};Drupal.ahah=function(base,element_settings){this.element=element_settings.element;this.selector=element_settings.selector;this.event=element_settings.event;this.keypress=element_settings.keypress;this.url=element_settings.url;this.wrapper='#'+element_settings.wrapper;this.effect=element_settings.effect;this.method=element_settings.method;this.progress=element_settings.progress;this.button=element_settings.button||{};if(this.effect=='none'){this.showEffect='show';this.hideEffect='hide';this.showSpeed=''}else if(this.effect=='fade'){this.showEffect='fadeIn';this.hideEffect='fadeOut';this.showSpeed='slow'}else{this.showEffect=this.effect+'Toggle';this.hideEffect=this.effect+'Toggle';this.showSpeed='slow'};var form=$(this.element).parents('form');this.form_action=form.attr('action');this.form_target=form.attr('target');this.form_encattr=form.attr('encattr');var ahah=this,options={url:ahah.url,data:ahah.button,beforeSubmit:function(form_values,element_settings,options){return ahah.beforeSubmit(form_values,element_settings,options)},success:function(response,status){if(typeof response=='string')response=Drupal.parseJson(response);return ahah.success(response,status)},complete:function(response,status){if(status=='error'||status=='parsererror')return ahah.error(response,ahah.url)},dataType:'json',type:'POST'};$(element_settings.element).bind(element_settings.event,function(){$(element_settings.element).parents('form').ajaxSubmit(options);return false});if(element_settings.keypress)$(element_settings.element).keypress(function(event){if(event.keyCode==13){$(element_settings.element).trigger(element_settings.event);return false}})};Drupal.ahah.prototype.beforeSubmit=function(form_values,element,options){$(this.element).addClass('progress-disabled').attr('disabled',true);if(this.progress.type=='bar'){var progressBar=new Drupal.progressBar('ahah-progress-'+this.element.id,eval(this.progress.update_callback),this.progress.method,eval(this.progress.error_callback));if(this.progress.message)progressBar.setProgress(-1,this.progress.message);if(this.progress.url)progressBar.startMonitoring(this.progress.url,this.progress.interval||1500);this.progress.element=$(progressBar.element).addClass('ahah-progress ahah-progress-bar');this.progress.object=progressBar;$(this.element).after(this.progress.element)}else if(this.progress.type=='throbber'){this.progress.element=$('<div class="ahah-progress ahah-progress-throbber"><div class="throbber">&nbsp;</div></div>');if(this.progress.message)$('.throbber',this.progress.element).after('<div class="message">'+this.progress.message+'</div>');$(this.element).after(this.progress.element)}};Drupal.ahah.prototype.success=function(response,status){var wrapper=$(this.wrapper),form=$(this.element).parents('form'),new_content=$('<div></div>').html(response.data);form.attr('action',this.form_action);this.form_target?form.attr('target',this.form_target):form.removeAttr('target');this.form_encattr?form.attr('target',this.form_encattr):form.removeAttr('encattr');if(this.progress.element)$(this.progress.element).remove();if(this.progress.object)this.progress.object.stopMonitoring();$(this.element).removeClass('progress-disabled').attr('disabled',false);Drupal.freezeHeight();if(this.method=='replace'){wrapper.empty().append(new_content)}else wrapper[this.method](new_content);if(this.showEffect!='show')new_content.hide();if(($.browser.safari&&$("tr.ahah-new-content",new_content).size()>0)){new_content.show()}else if($('.ahah-new-content',new_content).size()>0){$('.ahah-new-content',new_content).hide();new_content.show();$(".ahah-new-content",new_content)[this.showEffect](this.showSpeed)}else if(this.showEffect!='show')new_content[this.showEffect](this.showSpeed);if(new_content.parents('html').length>0)Drupal.attachBehaviors(new_content);Drupal.unfreezeHeight()};Drupal.ahah.prototype.error=function(response,uri){alert(Drupal.ahahError(response,uri));$(this.element).parent('form').attr({action:this.form_action,target:this.form_target});if(this.progress.element)$(this.progress.element).remove();if(this.progress.object)this.progress.object.stopMonitoring();$(this.wrapper).show();$(this.element).removeClass('progess-disabled').attr('disabled',false)};

