
function load_form_behaviors(context) {
  $j.log('loading FORM behaviors from behaviors/application.js')
  
  jQuery('input.initial_focus', context).each(function(){
    jQuery(this).focus();
    jQuery(this).parent().addClass('focus');
  });
  
  jQuery('form input', context).focus(function() {
    jQuery(this).parent().addClass('focus');
  });
  
  jQuery('form select', context).focus(function() {
    jQuery(this).parent().addClass('focus');
  });
  
  jQuery('form input', context).blur(function() {
    jQuery(this).parent().removeClass('focus');
  });
  
  jQuery('form select', context).blur(function() {
    jQuery(this).parent().removeClass('focus');
  });
  
  // Use 'prompt' class to make value disappear on focus / reappear if empty
    
  jQuery('.prompt', context).focus(function(e) {
    if(!this.form.hasClass('editing')){
      if (this.value == this.defaultValue ){ 
        this.value = '';
      };
    };
  });
  
  jQuery('.prompt', context).blur(function(e) {
    if(!this.form.hasClass('editing')){
      if (this.value == '' ){ 
        this.value = this.defaultValue;
      }
    };
  });
  
  
  
  // Ajaxable
  
  jQuery('form.ajaxable_once_without_json', context).submit(function(e) {
    if (!this.ajax_submitted) {    
      this.ajax_submitted = true;
      form = this
      json_request(this.method, this.action, jQuery(this).serialize(), function() { form.ajax_submitted = false; });
    }
    
    return false;
  });
  
  jQuery('form.ajaxable', context).submit(function(e) {
    this.has_form_ajaxable = true;    
    json_request(this.method, append_js_extension(this.action), jQuery(this).serialize())
    return false;
  });
  
  
  jQuery('form.ajaxable_once', context).submit(function(e) {
    if (!this.ajax_submitted) {    
      this.ajax_submitted = true;
      form = this;
      json_request(this.method, append_js_extension(this.action), jQuery(this).serialize(), function() { form.ajax_submitted = false; });
    }
    
    return false;
  });  
  
  // Basically the same function as above except it's not trying to process the jsonh response, but just
  // eval() what comes back.
  jQuery("form.ajax_post", context).submit(function(e){
    jQuery.post(this.action, jQuery(this).serialize(), function(data) { 
      window.eval(data);
    });
    
    return false;
  });
  
  jQuery('form.submit_once', context).submit(function() {
    if (this.submitted) {
      return false;
    } else {
      this.submitted = true;
    }
  });
  
  
}
  
  
  
  
  
function load_misc_behaviors(context) {
  $j.log('loading MISC behaviors from behaviors/application.js')
  
  jQuery('a.ajaxable', context).click(function(e) {
    jQuery.get(this.href, function(data){ eval(data); })
    return false;    
  });

  
  jQuery('span.time_in_words, p.time_in_words', context).each(function(){
    this.innerHTML = get_local_time_for_date(this.title);
  });
}





// ON LOAD

jQuery(function() {
  load_form_behaviors();
  load_misc_behaviors();
});
