var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Courier New";
var gHeaderColor = "green"
var fontsize = 3;

var gNow = new Date();

isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
 
function BuildJustShow( ) {
	gCal = new Calendar(); 
    var vCode = "";

    // Customize your Calendar here..
    gCal.gBGColor="white";
    gCal.gLinkColor="black";
    gCal.gTextColor="black";
    gCal.gHeaderColor="darkgreen";
 //---
 
    
 //---
    // Get the complete calendar code for the month..
    vCode = gCal.getMonthlyCalendarCode();
    document.write(vCode);

}


 
Calendar.prototype.write_weekend_string = function(vday) {
    var i;  
    for (i=0; i<weekend.length; i++) {
        if (vday == weekend[i])
            return (" BGCOLOR=\"" + weekendColor + "\"");
    }
    
    return "";
}

// any error : no output.

function Calendar( ){
    this.gBGColor = "white";
    this.gFGColor = "black";
    this.gTextColor = "black";
    this.gHeaderColor = "black";
    this.gMonth = gNow.getMonth();
    this.gYear  = gNow.getFullYear();

    
}

Calendar.prototype.cal_data = function() {
    var vDate = new Date();
    vDate.setDate(1);
    vDate.setMonth(this.gMonth);
    vDate.setFullYear(this.gYear);

    var vFirstDay=vDate.getDay();
    var vDay=1;
    var vLastDay=this.get_daysofmonth(this.gMonth, this.gYear); //Calendar.get_daysofmonth(this.gMonth, this.gYear);
    var vOnLastDay=0;
    var vCode = "";
  

    vCode = vCode + "<TR>";
    for (i=0; i<vFirstDay; i++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
    }

    // Write rest of the 1st week
    for (j=vFirstDay; j<7; j++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
                            this.format_today(vDay) +        "</FONT></TD>";
        vDay=vDay + 1;
    }
    vCode = vCode + "</TR>";

    // Write the rest of the weeks
    for (k=2; k<7; k++) {
        vCode = vCode + "<TR>";

        for (j=0; j<7; j++) {
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
                  this.format_today(vDay) +      "</FONT></TD>";
            vDay=vDay + 1;

            if (vDay > vLastDay) {
                vOnLastDay = 1;
                break;
            }
        }

        if (j == 6)
            vCode = vCode + "</TR>";
        if (vOnLastDay == 1)
            break;
    }
    
    // Fill up the rest of last week with proper blanks, so that we get proper square blocks
    for (m=1; m<(7-j); m++) {
        if (this.gYearly)
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
        else
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
    }
    
    return vCode;
}



Calendar.prototype.format_today = function(vday) {
    var vNowDay = gNow.getDate();
    var vNowMonth = gNow.getMonth();
    var vNowYear = gNow.getFullYear();

    if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
        return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
    else
    return ("<B>" + vday + "</B>"  ); //        return (vday  + "-"  + vNowDay + "-" + this.gMonth);
}


//Note: use all class member function instead of static class function.
Calendar.prototype.get_daysofmonth = function(monthNo, p_year){    
    if ((p_year % 4) == 0) {
        if ((p_year % 100) == 0 && (p_year % 400) != 0)
            return Calendar.DOMonth[monthNo];
    
        return Calendar.lDOMonth[monthNo]; // Leap year Month days..
    } else
        return Calendar.DOMonth[monthNo]; // Non-Leap year Month days..
}


Calendar.prototype.getMonthlyCalendarCode = function() {
    var vCode = "";
    var vHeader_Code = "";
    var vData_Code = "";
    
    // Begin Table Drawing code here..
    vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + "white" + "\">";
    
    vHeader_Code = this.cal_header();
    vData_Code = this.cal_data();
    vCode = vCode + vHeader_Code   + vData_Code;
    
    vCode = vCode + "</TABLE>";
   
    return vCode;
}



Calendar.prototype.cal_header = function() {
   
	 
	var vCode = "";
     vCode = vCode + "<TR>";
    vCode = vCode + "<TD colspan =7 WIDTH='100%' align='center'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>" +
      Calendar.Months[this.gMonth] + " "+ this.gYear +"</B></FONT></TD>";
       vCode = vCode + "</TR>";
    
    vCode = vCode + "<TR>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Sun</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Mon</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Tue</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Wed</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Thu</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Fri</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + gHeaderColor + "'><B>Sat</B></FONT></TD>";
    vCode = vCode + "</TR>";
  
    return vCode;
}

  
