// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function startWorking() {
    $('#working').show();
}

function stopWorking() {
    $('#working').fadeOut();
}

function openPopup(url, height, width, coordX, coordY){
    if(coordX == null || coordY == null){
        var aw = parseInt(screen.availWidth);
        var ah = parseInt(screen.availHeight);
        if(coordX == null) coordX = (aw - width) / 2;
        if(coordY == null) coordY = (ah - height) / 2;

    }
    window.open(url,'','scrollbars=yes,left=' + coordX + ',top=' + coordY + ',height=' + height + ',width=' + width);
}

function showMessage(message) {
    h = "<div id='flash_notice'>" + message + "</div>";
    $('#message_body').html(h);
    $('#flash_notice').show("slow");
    setTimeout("$('#flash_notice').fadeOut();", 5000);
}

function showError(message) {
    h = "<div id='flash_error'>" + message + "</div>";
    $('#message_body').html(h);
    $('#flash_error').show("slow");
    setTimeout("$('#flash_error').fadeOut();", 5000);
}

function goToTop(){
    document.location.href='#';
    if (document.documentElement && document.documentElement.scrollTop){
        document.documentElement.scrollTop = 0;
    }else if (document.body){
        document.body.scrollTop = 0;
    }
}

var lastObjectClicked;
var lastClickWhen;
BLOCK_TIMEOUT = 2000;
function allowClick(object) {
    // If the user is clicking on a different object, or the blocking timeout has expired, allow the click
    if(lastObjectClicked != object || new Date().getTime() - lastClickWhen > BLOCK_TIMEOUT) {
        lastObjectClicked = object;
        lastClickWhen = new Date().getTime();
        return true;
    } else {
        return false;
    }
}