// Metro Audio Dynamics JavaScript Functions

var message = "";
var index = 0;
var flash = 0;

// Preload teletype graphics
letterforms = new Array()  // Letter graphics from 'a' to 'z'
for (i = 0; i < 26; i++) {
    letterforms[i] = new Image();
    letterforms[i].src = String.fromCharCode(i + 97) + ".gif";
}

function teleprompt( m ) {
    if (m) {
        message = m;
    }
    if (flash++ < 12) {
        if (eval ("document._" + index + ".src").indexOf("cursor") > -1) {
            eval ("document._" + index + ".src = 'graphics/blank.gif'");
        } else {
            eval ("document._" + index + ".src = 'graphics/cursor.gif'");
        }
        setTimeout ("teleprompt()", 200);
    } else if (!index) {
        teletype();
    } else {
        eval ("document._" + index + ".src = 'graphics/blank.gif'");
    }
}

function teletype() {
    letter = message.charAt(index).toLowerCase();
    if (letter == " ") { letter = "blank"; }
    eval ("document._" + index + ".src = 'graphics/" + letter + ".gif'");
    eval ("document._" + ++index + ".src = 'graphics/cursor.gif'");
    if (index < message.length) {
        setTimeout ("teletype()", 200);
    } else {
        flash = 0;
        teleprompt();
    }
}


function loadPage( where ) {
    if (where != "") {
        document.location = where;
    }
}

function gotoPage( selectObj ) {
    var where = selectObj.options[selectObj.options.selectedIndex].value;
    loadPage(where);
}

function swap_image( imgName ) {
    imgObj = document.images[imgName];
    if (imgObj.src.lastIndexOf("_over") < 0) {
        imgObj.src = "graphics/" + imgName + "_over.gif";
    } else {
        imgObj.src = "graphics/" + imgName + "_off.gif";
    }
}

function swap_style( cellObj, style ) {
    cellObj.className = style;
}

function highlight_row( row ) {
    var rowObj = document.getElementById(row);
    var cellObjs = rowObj.getElementsByTagName("td");
    // Highlight row title
    if (cellObjs.item(0).className == "rowHead_over") {
        swap_style( cellObjs.item(0), "rowHead_out" );
    } else {
        swap_style( cellObjs.item(0), "rowHead_over" );
    }
    // Highlight row cells
    for (i = 1; i < cellObjs.length; i++) {
        if (cellObjs.item(i).className == "cell_over") {
            swap_style( cellObjs.item(i), "cell_out" );
        } else {
            swap_style( cellObjs.item(i), "cell_over" );
        }
    }
}

function highlight_column( column ) {
    var cellId = 65;  // ASCII character code for "A"
    var character = String.fromCharCode(cellId++);
    var cellObj = document.getElementById(character + column);
    // Highlight column title
    if (cellObj.className == "colHead_over") {
        swap_style( cellObj, "colHead_out" );
    } else {
        swap_style( cellObj, "colHead_over" );
    }
    // Highlight column cells
    character = String.fromCharCode(cellId++);
    while (cellObj = document.getElementById(character + column)) {
        if (cellObj.className == "cell_over") {
            swap_style( cellObj, "cell_out" );
        } else {
            swap_style( cellObj, "cell_over" );
        }
        if (cellId > 90) {
            character = String.fromCharCode(cellId++ - 26);
            character += character;
        } else {
            character = String.fromCharCode(cellId++);
        }
    }
}

function highlight_cell( cellObj ) {
    var row = cellObj.id.match(/^\D\D?/);
    var column = cellObj.id.match(/\d+$/);
    var rowHeadObj = document.getElementById(row + "0");
    var colHeadObj = document.getElementById("A" + column);
    // Highlight column title
    if (colHeadObj.className == "colHead_over") {
        swap_style( colHeadObj, "colHead_out" );
    } else {
        swap_style( colHeadObj, "colHead_over" );
    }
    // Highlight row title
    if (rowHeadObj.className == "rowHead_over") {
        swap_style( rowHeadObj, "rowHead_out" );
    } else {
        swap_style( rowHeadObj, "rowHead_over" );
    }
    // Highlight active table cell
    if (cellObj.className == "cell_over") {
        swap_style( cellObj, "cell_out" );
    } else {
        swap_style( cellObj, "cell_over" );
    }
}
