/* javascript functions for the music performances page */

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function timeTillDate(whenDay,whenMonth,whenYear) {
    var now = new Date();
    var then = new Date(y2k(whenYear),whenMonth-1,whenDay);
    var difference = Date.UTC(y2k(then.getYear()),then.getMonth(),then.getDate(),0,0,0) - Date.UTC(y2k(now.getYear()),now.getMonth(),now.getDate(),0,0,0);
    return difference/(1000*60*60*24);
}

function highlightRows() {

    // array of tr elements
    tray = document.getElementsByTagName('tr');

    // look for tr elements with an id
    for (i=0; i<tray.length; i++) {
        if (tray[i].id == '') { continue; }

        var sID = tray[i].id;
        var idt = parseInt(sID.substr(8,2), 10);
        var imon = parseInt(sID.substr(6,2), 10);
        var iyr = parseInt(sID.substr(2,4), 10);

        // highlight the row if the date is in the future
        if (timeTillDate(idt,imon,iyr) >= 0) {
            var elem = document.getElementById(sID);
            elem.style.backgroundColor="#ffffcc";
            // the first child node *should* be the first column, so...
            elem.childNodes[1].style.fontWeight="bold";
        }
        else {
        // if dates are in the past, display 'odd-row' shading  
            if (i % 2 == 1)
                tray[i].setAttribute("class", "gray");
        } 
    }
}
