Date.prototype.getRealYear = function () {
    return this.getFullYear();
};

Date.prototype.getRealMonth = function () {
   	return this.getMonth() + 1;
};

Date.prototype.getRealDay = function () {
    return this.getDate();
};

Date.prototype.getRealWDay = function () {
    return this.getDay() == 0 ? 7 : this.getDay();
};

Date.prototype.getMonthDays = function () {
	year = this.getRealYear(); // 2009 2009
	month = this.getRealMonth(); // 12 5
	
	year += parseInt(month / 12); // 2010 2009
	month = month % 12; // 0 5
	
    return new Date(year, month, 0).getDate();
};

Date.prototype.getYearDays = function () {
    var days = 0;
    for (var i = 0; i < 12; i++) {
        days += new Date(this.getFullYear(), i, 0).getDate();
    }
    return days;
};

Date.prototype.addYear = function(years) {
    this.setYear(this.getFullYear() + years);
};

Date.prototype.addMonth = function(months) {
    this.setMonth(this.getMonth() + months);
};

Date.prototype.addOneDay = function() {
	this.setDate(this.getDate() + 1);
};

Date.prototype.format = function(fstr) {
	year = this.getRealYear();
	month = this.getRealMonth();
	if (month >= 0 && month <= 9) {
		month = '0' + month;
	}
	day = this.getRealDay();
	if (day >= 0 && day <= 9) {
		day = '0' + day;
	}
	
    return year + '-' + month + '-' + day;
};

Date.NewDate = function(year, month, day) {
    return new Date(year, month - 1, day);
};

Date.DiffMonth = function (date1, date2) {
	year1 = date1.getRealYear();
	month1 = date1.getRealMonth();

	year2 = date2.getRealYear();
	month2 = date2.getRealMonth();

	months = (year1 - year2) * 12;

	months = months + month1 - month2;

	return months;
};

Date.Parse = function (sdate, format) {
	// yyyy-mm-dd
	year = sdate.substring(0, 4);
	month = sdate.substring(5, 7);
	day = sdate.substring(8, 10);
	
    return new Date(year, month - 1, day);
};
