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

// Add this behavior to a text box for click-to-clear behavior.  The default text is stored in
// the alt attribute.
var ClickToClearDefaults = Behavior.create({
    initialize : function(e) {
        v = this.element.value;
        if (v == '') {
            this.element.value = this.element.alt;
        }
    },
        
    onfocus : function(e) {
        v = this.element.value;
        if (v == this.element.alt) {
            this.element.value = '';
        }
    },
    
    onblur : function(e) {
        v = this.element.value;
        if (v == '') {
            this.element.value = this.element.alt;
        }
    }
});

Event.addBehavior({
    '#flightsshort': ClickToClearDefaults,
    '#flightsmedium': ClickToClearDefaults,
    '#flightslong': ClickToClearDefaults,
    '#flightsextended': ClickToClearDefaults,
    '.hometype': ClickToClearDefaults,
    '#newsletter_email' : ClickToClearDefaults
});

var ShowBills = Behavior.create({
    onchange : function(e) {
        locid = this.element.value;
        new Ajax.Request('/calculator/show_bills', {asynchronous:true, evalScripts:true, parameters:'locid=' + locid + '&authenticity_token=' + encodeURIComponent(window._token)});
    }
});

Event.addBehavior({
    '#homecalc select.homestate' : ShowBills // can't use invalid XHTML id homes[0][locid] in selector.
});

Event.addBehavior.reassignAfterAjax = true;