oqp = new Array(13);
var i,j;                                                  // counter

for (i=1; i<13 ;i++ )
{
    oqp[i] = new Array(32);
}

for (i=1; i<13 ;i++ )
{
    for (j=1; j<32 ;j++)
    {
        oqp[i][j] = 0;
    }
}
// *************************************************
// Endroit pour mettre les jours OQP dans le format
// oqp[6][27] = 1;        --> Le 27 juin, la journee est oqp...
// oqp[6][27] = 2;        --> Le 27 juin, la journee est non-disponible...


oqp[12][28]  = 1;
oqp[12][29]  = 1;
oqp[12][30]  = 1;
oqp[12][31]  = 1;
oqp[1][1]  = 1;
oqp[1][2]  = 1;
oqp[1][3]  = 1;

oqp[1][24]  = 0;
oqp[1][25]  = 0;

oqp[1][31]  = 0;
oqp[2][1]  = 0;

oqp[2][7]  = 0;
oqp[2][8]  = 0;

oqp[2][13]  = 0;
oqp[2][14]  = 0;
oqp[2][15]  = 0;
oqp[2][16]  = 0;
oqp[2][17]  = 0;
oqp[2][18]  = 0;
oqp[2][21]  = 0;
oqp[2][22]  = 0;

oqp[3][1]  = 0;
oqp[3][2]  = 0;
oqp[3][3]  = 0;
oqp[3][4]  = 0;
oqp[3][5]  = 0;
oqp[3][6]  = 0;
oqp[3][7]  = 0;
oqp[3][8]  = 0;

oqp[3][14]  = 0;

oqp[3][15]  = 0;
oqp[3][16]  = 0;
oqp[3][17]  = 0;
oqp[3][18]  = 0;
oqp[3][19]  = 0;




oqp[8][1]  = 2;
oqp[8][2]  = 2;
oqp[8][3]  = 2;
oqp[8][4]  = 2;
oqp[8][5]  = 2;
oqp[8][6]  = 2;
oqp[8][7]  = 2;
oqp[8][8]  = 2;
oqp[8][9]  = 2;
oqp[8][10]  = 2;
oqp[8][11]  = 2;
oqp[8][12]  = 2;
oqp[8][13]  = 2;
oqp[8][14]  = 2;
oqp[8][15]  = 2;
oqp[8][16]  = 2;
oqp[8][17]  = 2;
oqp[8][18]  = 2;
oqp[8][19]  = 2;
oqp[8][20]  = 2;
oqp[8][21]  = 2;
oqp[8][22]  = 2;
oqp[8][23]  = 2;
oqp[8][24]  = 2;
oqp[8][25]  = 2;
oqp[8][26]  = 2;
oqp[8][27]  = 2;
oqp[8][28]  = 2;
oqp[8][29]  = 2;
oqp[8][30]  = 2;
oqp[8][31]  = 2;

oqp[9][1]  = 2;
oqp[9][2]  = 2;
oqp[9][3]  = 2;
oqp[9][4]  = 2;
oqp[9][5]  = 2;
oqp[9][6]  = 2;
oqp[9][7]  = 2;
oqp[9][8]  = 2;
oqp[9][9]  = 2;
oqp[9][10]  = 2;
oqp[9][11]  = 2;
oqp[9][12]  = 2;
oqp[9][13]  = 2;
oqp[9][14]  = 2;
oqp[9][15]  = 2;
oqp[9][16]  = 2;
oqp[9][17]  = 2;
oqp[9][18]  = 2;
oqp[9][19]  = 2;
oqp[9][20]  = 2;
oqp[9][21]  = 2;
oqp[9][22]  = 2;
oqp[9][23]  = 2;
oqp[9][24]  = 2;
oqp[9][25]  = 2;
oqp[9][26]  = 2;
oqp[9][27]  = 2;
oqp[9][28]  = 2;
oqp[9][29]  = 2;
oqp[9][30]  = 2;

oqp[10][1]  = 2;
oqp[10][2]  = 2;
oqp[10][3]  = 2;
oqp[10][4]  = 2;
oqp[10][5]  = 2;
oqp[10][6]  = 2;
oqp[10][7]  = 2;
oqp[10][8]  = 2;
oqp[10][9]  = 2;
oqp[10][10]  = 2;
oqp[10][11]  = 2;
oqp[10][12]  = 2;
oqp[10][13]  = 2;
oqp[10][14]  = 2;
oqp[10][15]  = 2;
oqp[10][16]  = 2;
oqp[10][17]  = 2;
oqp[10][18]  = 2;
oqp[10][19]  = 2;
oqp[10][20]  = 2;
oqp[10][21]  = 2;
oqp[10][22]  = 2;
oqp[10][23]  = 2;
oqp[10][24]  = 2;
oqp[10][25]  = 2;
oqp[10][26]  = 2;
oqp[10][27]  = 2;
oqp[10][28]  = 2;
oqp[10][29]  = 2;
oqp[10][30]  = 2;

oqp[11][1]  = 2;
oqp[11][2]  = 2;
oqp[11][3]  = 2;
oqp[11][4]  = 2;
oqp[11][5]  = 2;
oqp[11][6]  = 2;
oqp[11][7]  = 2;
oqp[11][8]  = 2;
oqp[11][9]  = 2;
oqp[11][10]  = 2;
oqp[11][11]  = 2;
oqp[11][12]  = 2;
oqp[11][13]  = 2;
oqp[11][14]  = 2;
oqp[11][15]  = 2;
oqp[11][16]  = 2;
oqp[11][17]  = 2;
oqp[11][18]  = 2;
oqp[11][19]  = 2;
oqp[11][20]  = 2;
oqp[11][21]  = 2;
oqp[11][22]  = 2;
oqp[11][23]  = 2;
oqp[11][24]  = 2;
oqp[11][25]  = 2;
oqp[11][26]  = 2;
oqp[11][27]  = 2;
oqp[11][28]  = 2;
oqp[11][29]  = 2;
oqp[11][30]  = 2;


// *************************************************
function DisplayLegend(){
        var txt;
        var p = location.pathname;
        var filename = p.substr(p.lastIndexOf("/",p.length-1)+1,p.length);
        if (filename == "dispo.html")
        {
            txt = "<TABLE style='FONT-SIZE: 8pt; WIDTH: 240px; FONT-FAMILY: Lucida Sans Unicode; HEIGHT: 22px' cellSpacing=1 cellPadding=1 width=240 border=0>\n" + 
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: white; BORDER-BOTTOM: black 1px solid' bgColor=white>.</TD>\n" +
                  "<td>&nbsp;Disponible</td></tr>\n" +
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: silver; BORDER-BOTTOM: black 1px solid' bgColor=silver>.</TD>\n" +
                  "<td>&nbsp;Disponibilité restreinte</td></tr>\n" +
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: black; BORDER-BOTTOM: black 1px solid' bgColor=black>.</TD>\n" +
                  "<td>&nbsp;Non disponible</td></tr>\n" +
                  "</table>\n";
        }
        else
        {
            txt = "<TABLE style='FONT-SIZE: 8pt; WIDTH: 240px; FONT-FAMILY: Lucida Sans Unicode; HEIGHT: 22px' cellSpacing=1 cellPadding=1 width=240 border=0>\n" + 
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: white; BORDER-BOTTOM: black 1px solid' bgColor=white>.</TD>\n" +
                  "<td>&nbsp;Available</td></tr>\n" +
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: silver; BORDER-BOTTOM: black 1px solid' bgColor=silver>.</TD>\n" +
                  "<td>&nbsp;Limited availability</td></tr>\n" +
                  "<tr><td style='BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 19px; COLOR: black; BORDER-BOTTOM: black 1px solid' bgColor=black>.</TD>\n" +
                  "<td>&nbsp;Not available</td></tr>\n" +
                  "</table>\n";
        }
        document.write(txt);

    }





function init() {
DisplayLegend()
	var todayDate       = new Date();
	var currentMonth    = todayDate.getMonth()+1;
	var currentYear     = todayDate.getFullYear();
	
	DisplayCalendar(currentMonth, currentYear);
    ;
}


function DisplayCalendar(inMonth, inYear){
    var currentDate, nbDays, count, dayValue, startWeekDay, currentWeekDay, started, notEnd, libreOQP, calculMonth, calculYear;

    var str             = "";
    var today           = (new Date()).getDate();           // day value of today: 1 to 31
    var displayMonth    = 9;
    var k = 1;

    str = str + "<table cellpadding='5' cellspacing='5' border='0'>\n " +
                "<tr>\n";
    for (j=inMonth; j<inMonth+displayMonth; j++)
    {
        if (j > 12) {
            calculMonth = j - 12;
            calculYear  = inYear + 1;
        }
        else {
            calculMonth = j;
            calculYear  = inYear;
        }

        nbDays          = GetNbOfDays(calculMonth, calculYear);
        currentDate     = new Date(calculYear, calculMonth-1, 01);        // date of first day of input month/year
        currentWeekDay  = 1;                                // index inside for loop to represente current week day: 1, 8, ... for sunday
        startWeekDay    = currentDate.getDay()+1;           // week day of the first day of the specified month: 1 for sunday
        started = false;                                    // true if started to display date, false otherwise
        notEnd = false;                                     // true if last day of the specified month is not saturday, false otherwise

        str = str + "<td valign='top'>\n<table>\n<tr>\n<td class='columntitle' colSpan=7>&nbsp;" + GetMonthName(calculMonth) + " " + calculYear + "</td>\n</tr>\n";
        str = str + "<tr>" + GetMonthDayTitle() + "</tr>\n";

        /*           
            If start day is not sunday, we have to display blanks before starting 
            to display days and at the same time I reset index i to 1. When staring 
            to display days, index i begins with value 2, so we have to add 1 to
            number of days 
        */                                          
        if  (startWeekDay==1){
            count = nbDays;
        }
        else {
            // start day is not sunday
            count = nbDays + 1;
        }
        for (i=1; i<=count; i++) {
            if (startWeekDay==1) {
                dayValue = new Number(i);
            }
            else {
                // loop index i is already incremented
                dayValue = new Number(i-1);
            }
            
            if ((currentWeekDay-1)%7 == 0) {
                // open a new row
                str = str + "<tr>\n";
            }
            
            if ((currentWeekDay!=startWeekDay) && (!started)) {
                // add blanks before first day
                str = str + "<td>&nbsp;</td>\n";
                // reset loop index
                i = 1
            }
            else {
                // no more blanks to be writen
                started = true;
                if (oqp[calculMonth][dayValue] == 1) {
                    libreOQP = "oqp";
                }
                else if (oqp[calculMonth][dayValue] == 2) {
                    libreOQP = "nondispo";
                }
                else {
                    libreOQP = "libre";
                }


                if (dayValue==today & calculMonth == inMonth) {
                    str = str + "<td class='" + libreOQP + "'><b>" + dayValue.toString(10) + "</b></td>\n";
                }
                else {
                    str = str + "<td class='" + libreOQP + "'>" + dayValue.toString(10) + "</td>\n";
                }
            }
            
            currentWeekDay = currentWeekDay + 1;
            
            if ((currentWeekDay-1)%7 == 0) {
                // close the current row
                str = str + "</tr>\n";
            }
        }
    
        while ((currentWeekDay-1)%7 != 0) {
            notEnd = true;
            // add blanks after last day
            str = str + "<td>&nbsp;</td>\n";
            currentWeekDay = currentWeekDay + 1;
        }
    
        if (notEnd) {
            // last row is not closed: close it
            str = str + "</tr>\n";
        }
        str = str + "</table>\n"

        if (k%3 == 0)
        {
            str = str + "</td>\n</tr>\n<tr>\n";
        }
        k++;
    }
    str = str + "</td>\n</tr>\n</table>\n";
    document.write(str);
}

    function GetNbOfDays(inMonth, inYear){
        var returnValue;
        if(inMonth==2) {
            if (isLeap(inYear)) {
                returnValue = 29;
            }
            else {
                returnValue = 28;
            }
        }
        else {
            if (inMonth==4 || inMonth==6 || inMonth==9 || inMonth==11) {
                returnValue = 30;
            }
            else {
                returnValue = 31;
            }
        }
        return returnValue;
    }
    
    /**************************************************************************
    *   There are two situations making a year a leaf year:
    *   1. year is divisible by 100 and divisible by 400
    *   2. year is not divisible by 100 but divisible by 4
    **************************************************************************/
    function isLeap(inYear) {
        var returnValue;
        if (((inYear % 100 == 0) && (inYear % 400 == 0)) || 
            ((inYear % 100 != 0) && (inYear % 4   == 0))) {
            returnValue = true;
        }
        else {
            returnValue = false;
        }
        return returnValue;
    }

    function GetMonthName(inMonth) {
        var returnValue;
        var p = location.pathname;

        var filename = p.substr(p.lastIndexOf("/",p.length-1)+1,p.length);

        if (filename == "dispo.html")
        {
            switch (inMonth) {
                case 1:
                    returnValue = "Janvier";
                    break;
                case 2:
                    returnValue = "F&eacute;vrier";
                    break;
                case 3:
                    returnValue = "Mars";
                    break;
                case 4:
                    returnValue = "Avril";
                    break;
                case 5:
                    returnValue = "Mai";
                    break;
                case 6:
                    returnValue = "Juin";
                    break;
                case 7:
                    returnValue = "Juillet";
                    break;
                case 8:
                    returnValue = "Ao&ucirc;t";
                    break;
                case 9:
                    returnValue = "Septembre";
                    break;
                case 10:
                    returnValue = "Octobre";
                    break;
                case 11:
                    returnValue = "Novembre";
                    break;
                case 12:
                    returnValue = "D&eacute;cembre";
                    break;  
            }
        }
        else 
        {
            switch (inMonth) {
                case 1:
                    returnValue = "January";
                    break;
                case 2:
                    returnValue = "February";
                    break;
                case 3:
                    returnValue = "March";
                    break;
                case 4:
                    returnValue = "April";
                    break;
                case 5:
                    returnValue = "May";
                    break;
                case 6:
                    returnValue = "June";
                    break;
                case 7:
                    returnValue = "July";
                    break;
                case 8:
                    returnValue = "August";
                    break;
                case 9:
                    returnValue = "September";
                    break;
                case 10:
                    returnValue = "October";
                    break;
                case 11:
                    returnValue = "November";
                    break;
                case 12:
                    returnValue = "December";
                    break;  
            }
        }
        return returnValue;
    }

    function GetMonthDayTitle() {
        var returnValue;
        var p = location.pathname;
        var filename = p.substr(p.lastIndexOf("/",p.length-1)+1,p.length);
        if (filename == "dispo.html")
        {
            returnValue = "<td class=jour>Dim</td>\n" + 
                          "<td class=jour>Lun</td>\n" +
                          "<td class=jour>Mar</td>\n" +
                          "<td class=jour>Mer</td>\n" +
                          "<td class=jour>Jeu</td>\n" +
                          "<td class=jour>Ven</td>\n" +
                          "<td class=jour>Sam</td>\n";
        }
        else
        {
            returnValue = "<td class=jour>Sun</td>\n" + 
                          "<td class=jour>Mon</td>\n" +
                          "<td class=jour>Tue</td>\n" +
                          "<td class=jour>Wed</td>\n" +
                          "<td class=jour>Thu</td>\n" +
                          "<td class=jour>Fri</td>\n" +
                          "<td class=jour>Sat</td>\n";
        }
        return returnValue;
    }

    