/* Trap Backspace(8) and Enter(13) - Except bksp on text/textareas, enter on textarea/submit.
 * This should, hopefully, deal with browsers who use that utterly brain-dead 'backspace
 * is a history back operation'
 */
if(typeof window.event != 'undefined') {
    // IE
    document.onkeydown = function() {
        var t = event.srcElement.type;
        var kc = event.keyCode;
        return ((kc != 8 && kc != 13) || ( t == 'text' &&  kc != 13 ) ||
                (t == 'textarea') || ( t == 'submit' &&  kc == 13) ||  (t == 'password'))
    }
} else {
    // FireFox/Others
    document.onkeypress = function(e) {
        var t = e.target.type;
        var kc = e.keyCode;
        if ((kc != 8 && kc != 13) || ( t == 'text' &&  kc != 13 ) ||
            (t == 'textarea') || ( t == 'submit' &&  kc == 13) || (t == 'password')) {
            return true;
        } else {
            return false;
        }
    }
}


/* This is the image precache for rollovers. The page should
 * add the appropriate images to this as needed.
 */
var image_cache = new Array();

/* fn $ preload_images(String base, name, image, name, image, ....)
 * */
function preload_images() 
{
    var base = arguments[0];

    for(var arg = 1; arg < arguments.length; arg += 2) {
        image_cache[arguments[arg]] = new Image();
        image_cache[arguments[arg]].src = base + '/' + arguments[arg + 1];
    }
}


function image_switch(id, imgname)
{
    var img = document.getElementById(id);

    if(img != null && image_cache[imgname] != null) {
        img.src = image_cache[imgname].src;
    }
}


function visit(id, newwin)
{
    if(newwin) {
        window.open('index.cgi?block=2&op=visit&id='+id);
    } else {
        window.location.href = 'index.cgi?block=2&op=visit&id='+id;
    }
}