
// Used and modified (mostly reducing file size and modifiying when not configurable) by permission from 
// Eirik Bjorsnos - http://www.svnsearch.org/resources/js/charts.js
function drawTimeChart() {

    var maxMonth = getMaxMonth(years);
    var time = document.getElementById("timetable");
    time.cellSpacing = 0;
    time.cellPadding = 0;
    time.setAttribute("width", "100%");

    var tbody = document.createElement("tbody");
    time.appendChild(tbody);

    var red = parseInt("4E", 16);
    var green = parseInt("92", 16);
    var blue = parseInt("E1", 16);

    var months = ["J","F","M","A","M","J","J","A","S","O","N","D"];
    var monthstr = document.createElement("tr");
    monthstr.className = "barlabeltd";
    var td = document.createElement("td");
    td.setAttribute("width","20");
    monthstr.appendChild(td);

    for(month in months) {
        td = document.createElement("td");
        td.className = "monthheader";
        td.setAttribute("align", "center");
        td.appendChild(document.createTextNode(months[month]));
        monthstr.appendChild(td);
    }
    td = document.createElement("td");
    td.setAttribute("width", "3%");
    td.style.backgroundColor = "#cccccc";
    monthstr.appendChild(td);
    tbody.appendChild(monthstr);

    for(i = 0; i < years.length; i+=2) {
        var tr = document.createElement("tr");
        tr.className = "yearrow";
        td = document.createElement("td");
        td.setAttribute("width", "16%");
        td.setAttribute("align", "left");
        td.setAttribute("valign", "middle");
        td.setAttribute("height", "16");
        var div = document.createElement("div");
        div.className = "barlabeltd";

        var yearlink = document.createElement("a");
        yearlink.setAttribute("href", "javascript:go('" + years[i] + "', '')");
        yearlink.appendChild(document.createTextNode(years[i]));
        yearlink.className = "barlabellink";
        div.appendChild(yearlink);

        td.appendChild(div);
        tr.appendChild(td);

        for(m = 0; m < years[i+1].length; m++) {
            td = document.createElement("td");
            td.setAttribute("width", "7%");

            var div = document.createElement("div");
            div.className = "monthtd";

            var div2 = document.createElement("div");
            div2.className = "month";

            var r  = Math.round(red +(1-years[i+1][m]/maxMonth)*(255-red));
            var g  = Math.round(green +(1-years[i+1][m]/maxMonth)*(255-green));
            var b  = Math.round(blue +(1-years[i+1][m]/maxMonth)*(255-blue));
            var color = "rgb(" +r +","+g+","+b+")";

            div2.style.backgroundColor = color;
            div2.appendChild(document.createTextNode("\u00a0"));

            div2.onclick = new Function("parent.go('" +years[i] +"', '" + (m+1 <10 ? "0" : "") + (m+1) + "');");  // HEN
//HEN            div2.onclick = new Function("parent.search('from','" +years[i] +(m+1 <10 ? "0" : "") +(m+1) +"01',false);parent.search('to','" +years[i] +(m+1 <10 ? "0" : "") +(m+1) +"31',true)");
//HEN            div.onmouseover = new Function("hoverMonth(" +i +"," +m +")");
//HEN            div.onmouseout = new Function("unHoverMonth(" +i +"," +m +", '" + color +"')");
            div.appendChild(div2);
            //div.title = years[i+1][m] +" commits";

/* HEN comment out
            var moved = new Function("tt('timetooltip', '" +years[i+1][m] +" " +messages["t.commits"] +"')");
            if(td.addEventListener)  {
                td.addEventListener("mousemove", moved, false);
            } else {
                td.attachEvent("onmousemove", moved);
            }
*/


            td.appendChild(div);
            tr.appendChild(td);
        }

        td = document.createElement("td");
        td.setAttribute("width", "3%");
        td.style.backgroundColor = "#cccccc";
        tr.appendChild(td);
        tbody.appendChild(tr);
    }
}

function getMaxMonth(years) {
    var max = 0;
    for(var i = 1; i < years.length; i+=2) {
        for(var m = 0; m < years[i].length; m++) {
            max = Math.max(max,years[i][m]);
        }
    }
    return max;
}

