/**
 * Future new calendar object.
 * 
 * Dependancies:
 *    - 
 * 
 * @author Michael Mifsud
 * @package DatePicker
 */


/**
 * A Calendar Month Object
 * 
 * @package DatePicker
 * @param integer month - A month value (0 = jan - 11 = dec)
 * @param integer year - a 4 digit year (2005)
 */
function CalendarMonth(month, year) {
    
    //// Properties
    this.month  = parseInt(month); // (0-11)
    this.year   = parseInt(year);
    
    this.dayNames = new Array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
    this.weekDates = new Array();
    this.notes = '';
    
    // __constructor
    this.init();
}
/**
 * Initalise the calendar object
 * 
 */
CalendarMonth.prototype.init = function() {
    
    var i = 0;
    var firstOfMonth = new Date (this.year, this.month, 1);
    var days = firstOfMonth.getDaysInMonth();
    var startingDay = firstOfMonth.getDay();
    
    days += startingDay;
    startingRow = -1;
    
    for (i = 0; i < startingDay; i++) {
        if (i % 7 == 0) { // new row
            this.weekDates[++startingRow] = new Array();
        }
        this.weekDates[startingRow][i % 7] = new CalendarDay(0);
    }
    for (i = startingDay; i < days; i++) {
        if (i%7 == 0) {
            this.weekDates[++startingRow] = new Array();
        }
        this.weekDates[startingRow][i % 7] = new CalendarDay(i-startingDay+1);
    }
    for (i = days; i<42; i++)  {
        if (i % 7 == 0) {
            break;
        }
        this.weekDates[startingRow][i % 7] = new CalendarDay(0);
    }
}


/**
 * Get a date object representing the first of this month.
 * 
 * @return Date
 */
CalendarMonth.prototype.getDate = function() {
    
    return new Date(this.year, this.month, 1, 12, 0, 0);
}

/**
 * Get a date object representing the first of this month.
 * 
 * @return Date
 */
CalendarMonth.prototype.getMonthAbbreviation = function() {
    return this.getDate().getMonthAbbreviation();
}

/**
 * Return a plain text string representation of this calendar
 * @return string
 */
CalendarMonth.prototype.toString = function() {
    
    var html = ' ';
    var weeks = this.weekDates;
    
    for (i = 0; i < this.dayNames.length; i++) {
        html += this.dayNames[i] + ' ';
    }
    html += '\n ';
    for (i = 0; i < weeks.length; i++) {
        week = weeks[i];
        for(j = 0; j < 7; j++) {
            day = week[j];
            if (day.value == 0) {
                html += " ";
            } else if (day.value < 10) {
                html += "0";
            }
            html += day.value;
            html += " ";
        }
        html += "\n ";
    }
    
    html += "\n\n";
    //document.write(html);
    return html;
}

///////////////////// CalendarDay Class //////////////////////

/**
 * A Calendar Day Object
 * 
 * @package DatePicker
 * @param integer value - This days value 1-31 or 0 for a null value
 */
function CalendarDay(value) {
    
    //// Properties
    this.value = value;
    this.notes = '';
    
}
/**
 * Get a date object representing the first of this month.
 * 
 * @return Date
 */
CalendarDay.prototype.getValue = function() {
    if (this.value < 10) {
        return '0'+this.value;
    } else {
        return this.value;
    }
}






