// Extend date functions

function padNumber(number, padTo){
	number = "" + number;
	while (number.length<padTo){
		number = "0" + number;
	}
	return number;
}

ddmmyyyy = /(\d{1,2})\/(\d{1,2})\/(\d{4})/;

Date.prototype.getDayNum   = function(){      return this.getDate()    }
Date.prototype.setDayNum   = function(day){   this.setDate(day)        }
Date.prototype.getMonthNum = function(){      return this.getMonth()+1 }
Date.prototype.setMonthNum = function(month){ this.setMonth(month-1)   }
Date.prototype.getYearNum  = function(){      return this.getFullYear()}
Date.prototype.setYearNum  = function(year){  this.setYear(year)       }

Date.prototype.getDayOfWeekNum = function(firstDay){
	var day = this.getDay()-firstDay;
	if (day < 0) return day + 7;
	else return day;
}

Date.prototype.setDayMonthYear = function(day,month,year){
	this.setFullYear(year);
	this.setMonth(month-1);
	this.setDate(day);
	this.setHours(12);
}

Date.prototype.addDay = function(){
	this.setDate(this.getDate()+1);
}

Date.prototype.addMonth = function(){
	this.setMonth(this.getMonth()+1);
}

Date.prototype.addYears = function(numberOfYears){
	this.setYear(this.getFullYear()+numberOfYears);
}

Date.prototype.copyTo = function(date2){
	date2.setTime(this.getTime());
}

Date.prototype.getMonthComparator = function(){//Returns int to allow comparison
	return this.getYearNum()*100 + this.getMonthNum();
}

Date.prototype.getDayComparator = function(){//Returns int to allow comparison
	return this.getYearNum()*10000 + this.getMonthNum()*100 + this.getDayNum();
}

Date.isDate = function(day,month,year){//Checks if a date is valid
	if (year>999 && year<10000){
		var dt = new Date(year,month-1,day);
		return dt.getDate()==day && dt.getMonth()==month-1 && dt.getFullYear()==year;
	}
	return false;
}

