Object.extend(String.prototype, {
	lpad: function(length, character) {
		var source = this;
		if(!length || length <= source.length)
			return this;
		if(!character)
			character = ' ';
		while(source.length < length) {
			source = character+''+source;
		}
		return source;
	},
	rpad: function(length, character) {
		var source = this;
		if(!length || length <= source.length)
			return this;
		if(!character)
			character = ' ';
		while(source.length < length) {
			source += character+'';
		}
		return source;
	}
});

// Champs statiques pour l'objet Date
Date.DAYS_SHORT_FR   = ['Di.', 'Lu.', 'Ma.', 'Me.', 'Je.', 'Ve.', 'Sa.'];
Date.DAYS_LONG_FR    = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
Date.MONTHS_SHORT_FR = ['Jan.', 'Fév.', 'Mar.', 'Avr.', 'Mai', 'Juin', 'Juil.', 'Août', 'Sept.', 'Oct.', 'Nov.', 'Déc.'];
Date.MONTHS_LONG_FR  = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 
						'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
Date.YEAR_OFFSET = document.all ? 0 : 1900;
Date.STR_LONG        = 0;
Date.STR_SHORT       = 1;

Object.extend(Date.prototype, {
	
	getMonthLength: function(date) {
		var src = date ? date : this;
		return src.lastDayOfMonth().getDate();
	},
	
	isBisextile: function(year) {
		var src = year ? year : this.getYear()+Date.YEAR_OFFSET;
		return src%4 == 0 && (src%100 != 0 || src%400 == 0);
	},
	
	firstDayOfMonth: function(date) {
		var src = date ? date : this;
		var date = new Date(Date.YEAR_OFFSET+src.getYear(), src.getMonth(), 1);
		return date;
	},
	
	lastDayOfMonth: function(date) {
		var src = date ? date : this;
		var date = new Date(Date.YEAR_OFFSET+src.getYear(), src.getMonth()+1, 0);
		return date;
	},
	
	toDayString: function(mode) {
		var src = this,
			res;
		if( !mode ) {
			mode = Date.STR_SHORT;
		}
		switch( mode ) {
		case Date.STR_SHORT:
			res = Date.DAYS_SHORT_FR[src.getDay()];
			break;
		case Date.STR_LONG:
			res = Date.DAYS_LONG_FR[src.getDay()];
			break;
		}
		return res;
	},
	
	toMonthString: function(mode) {
		var src = this,
			res;
		if( mode != Date.STR_LONG ) {
			mode = Date.STR_SHORT;
		}
		switch( mode ) {
		case Date.STR_SHORT:
			res = Date.MONTHS_SHORT_FR[src.getMonth()];
			break;
		case Date.STR_LONG:
			res = Date.MONTHS_LONG_FR[src.getMonth()];
			break;
		}
		return res;
	},
	
	setNextDay: function( date ) {
		var src = src ? src : this;
		src.setDate(src.getDate()+1);
		return src;
	},
	
	setPreviousDay: function( date ) {
		var src = src ? src : this;
		src.setTime(src.getTime()-86400000);
		return src;
	},
	
	compareTo: function( oDate ) {
		return this.getTime()-oDate.getTime();
	},
	
	toFrenchString: function() {
		return this.getDate().toString().lpad(2,'0')+'/'+
			   (this.getMonth()+1).toString().lpad(2,'0')+'/'+
			   (Date.YEAR_OFFSET+this.getYear());
	}
});