// $Id $

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/*
    Author: Bruce Burdick (bruceburdick.com)
    Protects WinIE against crashing bug in Prototype
*/
function safe_toggle(css_id,transition,options) {
    Effect.toggle(css_id,transition,options);
/*  Formerly needed to fix bug in script.aculo.us:    
    if(/MSIE/.test(navigator.userAgent)) {
        Element.toggle(css_id);
    } else {
        Effect.toggle(css_id,transition,options);
    }
*/
}

/*
    Author: Bruce Burdick (bruceburdick.com)
    Performs transition, sets field values, 
    focuses first field (with appropriate delay)
*/
function form_toggle(form_id,target_id,transition,options,params) {
    // Get visibility before transition begins:
    var focusable = !Element.visible(target_id);
    safe_toggle(target_id,transition,options);
    
    if (focusable) {
        // Set any passed params:
        $H(params).each(function(param){
            eval("$('"+form_id+"')."+param.key).value=param.value;
        });
        
        // Focus the first element, accounting for any transition:
        if (isNaN($H(options)['duration'])) {
            Form.focusFirstElement($(form_id));
        } else {
            setTimeout("Form.focusFirstElement($('"+form_id+"'))", ($H(options)['duration']*1000)+20);
        }
    }
}

/* This doesn't work! email_address is always NULL
  $('email_address').onfocus = function() {
    // If already cleared, do nothing:
    if (this._cleared) return

    this.clear()
    this._cleared = true
  }
*/
