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


function total_price_for_selected_packages()
{
    elements = $$('fieldset#packages input.checkbox');
    elements = elements.select(function(e) { return e.checked });
    return elements.inject(0, function(s, e) { return(s + parseInt(e.getAttribute('price'))) } );
}



Element.resizeTo = function(container, extra) {
    container = $(container)
    var width = container.clientWidth || container.scrollWidth
    width += extra // a hack to account for margins, padding, etc.
    if(width > 0) {
        for(var i = 2; i < arguments.length; i++)
        $(arguments[i]).style.width = width + "px"
    }
}

window.installResizerFor = function() {
    var container_and_elements = arguments

    var current_onload = window.onload
    window.onload = function() {
        if(current_onload) current_onload()
        Element.resizeTo.apply(Element, container_and_elements)
    }

    var current_onresize = window.onresize
    window.onresize = function() {
        var size = {}
        size.width = window.innerWidth || 
        document.documentElement && document.documentElement.clientWidth ||
        document.body.clientWidth
        size.height = window.innerHeight ||
        document.documentElement && document.documentElement.clientHeight ||
        document.body.clientHeight

        /* keep track of the size from the last resize, because IE likes to call
        * resize over and over even if the window hasn't really resized. */

        if(window.last_size && window.last_size.width == size.width && window.last_size.height == size.height)
        return
        window.last_size = size

        if(current_onresize) current_onresize()
        Element.resizeTo.apply(Element, container_and_elements)
    }
}
