Event.observe(window, 'load', function(){
    var status = $('status');
    if(status){
        status.observe('keyup', function(e){
            var count = 140 - status.value.length;
            $('character_count')
                .update(count)
                .setStyle({ color: (count > 0)? '#28668e' : '#f00' });
        });
    }
    
    var current_page = 1;
    $('more_btn').observe('click', function(e){
        new Ajax.Request('/', {
            method: 'get', 
            parameters: { 
                _output: 'partial', 
                _start: current_page * 12, 
                _row_limit: 12
            }, 
            onSuccess: function(transport){
                current_page++;
                $('reviews').insert(transport.responseText);
                
                // Less than 12 entries returned, must be the end.
                if(transport.responseText.length < 12)
                    Event.element(e).hide();
            }, 
            onFailure: function(){ }
        });
        
        return false;
    });
});

function imposeMaxLength(Object, MaxLen){
    return (Object.value.length <= MaxLen);
}

function popup_mt(page, pgname, w, h){
    var width = w;
    var height = h;
    var left = ((screen.width-width) / 2);
    var top = ((screen.height-height) / 2);
    window.open(page,pgname,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');
}

function show_screenings(id){
    popup_mt('http://rsvp2.foxsearchlight.com/signup/' + id, 'Screenings', '535', '500');
    return false;
}