//
function radio_tristate(event) {
    var i, list, radio = Event.element(event);
    if( radio.checked ) {
        radio.checked = !radio.checked_previous;
    }
    radio.checked_previous = radio.checked;
    list = radio.form[radio.name];
    for( i=0; !!list && i<list.length; i++ ) {
        if( list[i] != radio ) {
            list[i].previous = false;
        }
    }
}
Event.observe(window, 'load', function() {
    var uuid = 0;
    $A(document.getElementsByTagName('input')).each(function(input, idx){
        if( Element.hasClassName(input, 'epoch-calendar') ) {
            $A(input.parentNode.getElementsByTagName('img')).each(function(img, i) {
                var calendar;
                if( Element.hasClassName(img, 'epoch-calendar') ) {
                    uuid++;
                    calendar = new Epoch('epoch_popup' + uuid, 'popup', input);
                    Event.observe(img, 'click', function(event) {
                        calendar.toggle();
                    });
                }
            });
        }
    });
    $A(document.getElementsByTagName('input')).each(function(input, idx) {
        if( 'radio' === input.type && Element.hasClassName(input, 'tristate') ) {
            Event.observe(input, 'click', radio_tristate);
        }
    });
});
// EOF
