//<script>
function GCalendar(s){
	this.date = (arguments.length==0) ? new Date() : new Date(s);
	this.aMonths = ["January","February","March","April","May","June","July","August","September","October","November","December"];
	this.aWeekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
}
GCalendar.prototype.addDays = function(nDays){
    if (isNaN(nDays)) alert("Parameter supplied is not a number.");
    else{
        var milli = nDays * 24 * 60 * 60 * 1000;
        var now = new Number(this.date);
        this.date = new Date(new Number(now + milli));
    }
}
GCalendar.prototype.isToday = function(){
    var today = new GCalendar();
    if (today.getMonth()==this.date.getMonth() &&
        today.getYear()==this.date.getYear() &&
        today.getDate() == this.date.getDate()) return true;
    return false;
}
GCalendar.prototype.getMonth = function(){return this.date.getMonth();}
GCalendar.prototype.getMonthAsString = function(){return this.aMonths[this.getMonth()];}
GCalendar.prototype.getYear = function(){return this.date.getFullYear();}
GCalendar.prototype.getYearXX = function(){return this.date.getFullYear().toString().substring(2,4);}
GCalendar.prototype.getDate = function(){return this.date.getDate();}
GCalendar.prototype.getDay = function(){return this.date.getDay();}
GCalendar.prototype.getTimeAsInt = function(){
	return ((this.date.getHours()*2) + ((this.date.getMinutes()>=30)?1:0)) * 1800000;
}
GCalendar.prototype.getTimeAsString = function(){
	var h = this.date.getHours();
	var m = new String(this.date.getMinutes());
	return ((h>12)?h-12:(h==0)?12:h) + ":" + ((m.length==1)?("0"+m):m) + ((h>11)?"pm":"am");
}
GCalendar.prototype.getHours = function(){return this.date.getHours();}
GCalendar.prototype.getMinutes = function(){return this.date.getMinutes();}
GCalendar.prototype.getDayAsString = function(){return this.aWeekdays[this.getDay()];}
GCalendar.prototype.getFirst = function(){return new GCalendar((this.getMonth()+1) + "/1/" + this.getYear());}
GCalendar.prototype.getLast = function(){return new GCalendar((this.getMonth()+1) + "/" + this.getDaysInMonth() + "/" + this.getYear());}
GCalendar.prototype.peekMonth = function(dir){
	var s;
	if (!dir){
		if (this.getMonth()==0) s = "12/1/" + (this.getYear()-1);
		else s = this.getMonth() + "/1/" + this.getYear();
	}else{
		if (this.getMonth()==11) s = "1/1/" + (this.getYear()+1);
		else s = (this.getMonth()+2) + "/1/" + this.getYear();
	}			
	return new GCalendar(s);
}
GCalendar.prototype.getDaysInMonth = function(){
	switch (this.getMonth()){
		case 0:case 2:case 4:case 6:case 7:case 9:case 11:
			return 31;
		case 3:case 5:case 8:case 10:
			return 30;
		case 1:
			return this.isLeapYear() ? 29 : 28; 
	}
}
GCalendar.prototype.isLeapYear = function(){
	return (this.getYear()%4==0) ? (this.getYear()%100==0) ? (this.getYear()%400==0) ? true : false : true : false;
}
GCalendar.prototype.toString = function(sFormat){
	switch (sFormat){
		case "mm/dd/yyyy": return (this.getMonth()+1) + "/" + this.getDate() + "/" + this.getYear();
		case "ddd mm/dd/yyyy": 
			return this.aWeekdays[this.getDay()].substring(0, 3) + " " + this.toString("mm/dd/yyyy");
		case "mmm-dd-yyyy": default: 
			return this.aMonths[this.getMonth()] + " " + this.getDate() + ", " + this.getYear();
					
	}
}
GCalendar.prototype.toInt = function(){
	return new Number(new Date((this.getMonth()+1) + "/" + this.getDate() + "/" + this.getYear()));
}
GCalendar.prototype.getOffsetDay = function(i){
	return (i>0) ? new GCalendar(this.toInt() + (86400000*i)) : new GCalendar(this.toInt() - (86400000*Math.abs(i)));
}
GCalendar.prototype.getOffsetDays = function(end){
	var a = [];
	var d2 = new GCalendar(end);
	a.push(this);
	if (this+""==new GCalendar(end)+"") return a;
		
	var x = ((d2.toInt() - this.toInt()) / 86400000);
	for (var i=1; i<=x; i++){
		a.push(this.getOffsetDay(i));
		if (i==40) break;
	}
		
	return a;
}
