function write_year(dt_year) {
    document.write(
//        '<style>table.rplan { border-collapse: separate; }</style>'+
        '<table align="center" cellpadding="0" cellspacing="0" border="0" width="'+ TABLE_WIDTH +'">'+
        '<tr><td height="500">');
    document.write(
        '<table class="rplan" cellspacing="2" border="0" width="100%">'+
        '<tr><td>');
    month = dt_year.getMonth();
    for (var n=0; n<12; n++) {
        dt_year.setDate(1);
        dt_year.setMonth(month)
        write_month(dt_year);
        if (n % 4 == 3) document.write('</td></tr><tr><td>'); 
        else document.write('</td><td>');
        if (month == 11) {
            dt_year.setFullYear(dt_year.getFullYear() + 1);
            dt_year.setMonth(0);
            month = 0;
        } else month += 1;
    }
    document.write( '</td></tr></table>');
// color description
    document.write(
        '<table align="left" cellspacing="0" border="0">'+
        '<tr><td>');
    document.write(
        '<table align="left" cellpadding="0" cellspacing="0" border="0" width="20">'+
        '<tr><td bgcolor="'+ COLOR_8 + '">'+
        '<table class="rplan" align="left" cellpadding="1" cellspacing="1" border="0" width="100%">'+
        '<tr><td  bgcolor="'+ COLOR_1 + '" width="100%"><font size="'+ FONT_SIZE +'">&nbsp;</font>'+
        '</td></tr></table></td></tr></table><font size="'+ FONT_SIZE +'">&nbsp; avaible &nbsp;</font>');
    document.write('</td><td>');
    document.write(
        '<table align="left" cellpadding="0" cellspacing="0" border="0" width="20">'+
        '<tr><td bgcolor="'+ COLOR_8 + '">'+
        '<table class="rplan" align="left" cellpadding="1" cellspacing="1" border="0" width="100%">'+
        '<tr><td  bgcolor="'+ COLOR_2 + '" width="100%"><font size="'+ FONT_SIZE +'">&nbsp;</font>'+
        '</td></tr></table></td></tr></table><font size="'+ FONT_SIZE +'">&nbsp; booked &nbsp;</font>');
    document.write('</td><td>');
    document.write(
        '<table align="left" cellpadding="0" cellspacing="0" border="0" width="20">'+
        '<tr><td bgcolor="'+ COLOR_8 + '">'+
        '<table class="rplan" align="left" cellpadding="1" cellspacing="1" border="0" width="100%">'+
        '<tr><td  bgcolor="'+ COLOR_0 + '" width="100%"><font size="'+ FONT_SIZE +'">&nbsp;</font>'+
        '</td></tr></table></td></tr></table><font size="'+ FONT_SIZE +'">&nbsp; unknown, please ask &nbsp;</font>');
    document.write(
        '</td></tr>'+
        '</table>');
//
    document.write(
        '</td></tr></table>');
} 
 
function write_month(start_date) {
    var dt_current = new Date(start_date);
    //alert(dt_current)
    // get first day to display in the grid for current month
    var dt_firstday = new Date(dt_current);
    dt_firstday.setDate(1);
    dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);
    
    document.write(
    '<table cellspacing="0" border="0" width="100%">'+
    '<tr><td bgcolor="'+ COLOR_8 + '">'+
    '<table class="rplan" cellspacing="1" cellpadding="1" border="0" width="100%">'+
    '<tr><td colspan="7">'+
    '  <table cellspacing="0" cellpadding="0" border="0" width="100%">'+
    '    <tr>'+
    '      <td align="center" width="100%"><font size="'+ FONT_SIZE +'" color="'+ COLOR_6 + '">'+ARR_MONTHS[dt_current.getMonth()]+' '+ dt_current.getFullYear() + '</font></td>'+
    '    </tr>'+
    '  </table>'+
    '</td></tr>'+
    '<tr>');

    // print weekdays titles
    for (var n=0; n<7; n++)
            document.write('<td bgcolor="'+ COLOR_9 + '" align="center"><font size="'+ FONT_SIZE +'"  color="'+ COLOR_7 + '">'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+'</font></td>');
    document.write('</tr>');
    
    // print calendar table
    var lm_date = new Date(dt_firstday);
    var offset = lm_date.getTimezoneOffset() * 60000;
    lm_date.setSeconds(0);
    lm_date.setHours(0,0,0,0);
    for (var n=0; n<6; n++) {
        // print row heder
        document.write('<tr>');
        for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
            if (lm_date.getMonth() == dt_current.getMonth()) {
                // set colors
                bgcolor = COLOR_3;
                for ( var i in item ) {
                  
                    if (lm_date.valueOf() >= item[i][0] + offset) {
                        if (lm_date.valueOf() <= item[i][1] + offset ) {
                            if (item[i][2] == 0) bgcolor = COLOR_0;
                            else if (item[i][2] == 1) bgcolor = COLOR_1;
                            else if (item[i][2] == 2) bgcolor = COLOR_2;
                            else bgcolor = COLOR_3;
                        }
                    }
                } 
                document.write('<td bgcolor="'+ bgcolor + '" align="center" width="14%">');
                // print days of current month
                document.write('<font size="'+ FONT_SIZE +'" color="'+ COLOR_5 + '">');
                document.write(lm_date.getDate()+'</font></td>'); 
            } else {
                // print days of other months
                document.write('<td bgcolor="'+ COLOR_4 + '" align="center" width="14%"><font size="' + FONT_SIZE + '" color="#000000">&nbsp;</font></td>'); 
            }        
            lm_date.setDate(lm_date.getDate()+1);
        }
        // print row footer
        document.write('</tr>');
    }
    document.write(
    '</table></td></tr>'+
    '</table>');
}
