/* Plus Productions' shows. */
var shows = [];

/* The prototype dollar function! */
function $() {
    var elements = [];
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i]; 
        if (typeof element == 'string') {
            element = document.getElementById(element);
        }
        if (arguments.length == 1) {
            return element;
        }
        elements.push(element);
    }
    return elements;
}

/* Trims spaces and CRLF's from a given string. */
function trim( field ) {
    while ( field.charAt(0) == " " || field.charAt(0) == "\r" || field.charAt(0) == "\n") {
        field = field.substring(1, field.length);
    }
    
    while ( field.charAt( field.length-1 ) == " " || field.charAt( field.length-1 ) == "\r" || field.charAt( field.length-1 ) == "\n") {
        field = field.substring(0, field.length-1);
    }
    
    return field;
}

/* Checks an email's validity. */
function isValidEmail ( email ) {
    if ( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( email ) ) {
        return true;
    } else {
        return false;
    }
}

/* Makes visible an invisible element. */
function showItem ( item ) {
    item.style.visibility = "visible"
    item.style.display    = "block";
}

/* Makes non visible a visible element. */
function hideItem ( item ) {
    item.style.visibility = "hidden"
    item.style.display    = "none";
}

/* Toggles a menu item's visibility. */
function toggleItem ( item ) {
    if ( item.style.visibility == "visible" || item.style.display == "block" || ( !item.style.visibility && !item.style.display ) ) {
        hideItem( item );
    } else {
        showItem( item );
    }
}

/* Opens a parameterized window. */
function openDialog ( page, width, height, name ) {
    if ( !width || !height) {
        width  = screen.width - 40;
        height = screen.height - 120;
    }
    
    if ( !name) {
        name = "a_new_window_" + new Date().getTime();
    }

    var windowWidth  = screen.width;
    var windowHeight = screen.height;
    
    var X = ( windowWidth  - width )  / 2;
    var Y = ( windowHeight - height ) / 2 - 40;
    
    var win = window.open( page, name, 
        "alwaysraised=yes,dependent=yes,directories=no,hotkeys=no,scrollbars=yes," + 
        "location=no,menubar=no,personalbar=no,resizable=no,status=no,toolbar=no," + 
        "width=" + width + ",height=" + height + "," +
        "left="    + X +   ",top="      + Y    + "," +
        "screenX=" + X +   ",screenY="  + Y 
    );
    
    return;
}