function OBJDate(chaine){

	this.jour=null;
	this.mois=null; 
	this.annee=null;
	
	this.str = null;
	
	OBJDate.prototype.definition = function(str){
		
		if (!str){
			var dte= new Date();
			var str = dte.getDate()+"/"+(dte.getMonth()+1)+"/"+dte.getFullYear();
		}
		
		str = new String(str);
		if (str.length==6){
			this.jour=str.substr(0,2);
			this.mois=str.substr(2,2);
			this.annee="20"+str.substr(4,2);
		}else{
			tab=str.split("/");
			if (!tab[1] || tab[1].length==0){
				tab=str.split("-");
				if (!tab[1] || tab[1].length==0){
					tab=str.split(".");
					if (!tab[1] || tab[1].length==0){
						tab[0]=str.substr(0,2);
						tab[1]=str.substr(2,2);
						tab[2]=str.substr(4,4);
					}
				}
			}
			if (tab[2].length==2)tab[2]=parseInt(2000+Number(tab[2]));
			
			this.str=new String(str);
			this.jour=tab[0];
			this.mois=tab[1];
			this.annee=tab[2];
		}
	
	}
	if (chaine)this.definition(chaine);
	
	OBJDate.prototype.setDateByInfos = function(j,m,a){
		this.jour=j;
		this.mois=m;
		this.annee=a;
	}
	
	
	OBJDate.prototype.ajoutJour = function(nbj){
		var msPerDay = 24 * 60 * 60 * 1000;
		var quatreheurePourChgtHr= 4 * 60 * 60 * 1000;
		
		var d=Date.UTC(this.annee,(Number(this.mois)-1),this.jour);
		
		var d=Date.parse(Number(this.mois)+"/"+this.jour+"/"+this.annee);
		var d2=parseInt(d+(Number(nbj)*msPerDay) + quatreheurePourChgtHr);
		
		var dte = new Date();
		dte.setTime(d2);
		
		this.jour=dte.getDate();
		this.mois=dte.getMonth()+1;
		this.annee=dte.getFullYear();
	}

    OBJDate.prototype.enleveJour = function(nbj){
		var msPerDay = 24 * 60 * 60 * 1000;
		var quatreheurePourChgtHr= 4 * 60 * 60 * 1000;

		var d=Date.UTC(this.annee,(Number(this.mois)-1),this.jour);

		var d=Date.parse(Number(this.mois)+"/"+this.jour+"/"+this.annee);
		var d2=parseInt(d-(Number(nbj)*msPerDay) + quatreheurePourChgtHr);

		var dte = new Date();
		dte.setTime(d2);

		this.jour=dte.getDate();
		this.mois=dte.getMonth()+1;
		this.annee=dte.getFullYear();
	}
	
	OBJDate.prototype.getMoisSuivant = function(){
		if (this.mois == 12){this.mois=1;this.annee++;}
		else this.mois++;
	}
	
	OBJDate.prototype.getMoisPrecedent = function(){
		if (this.mois == 1){this.mois=12;this.annee--;}
		else this.mois--;
	}

	OBJDate.prototype.estMoisCourant = function(){	
		var dte=new Date();
		return (this.mois==(dte.getMonth()+1));
	}

	OBJDate.prototype.estAnneeCourante = function(){
		var dte=new Date();
		return (this.annee==dte.getFullYear());
	}
	
	OBJDate.prototype.ajoutMois = function(nb){
		if(nb<0)this.retireMois(nb*(-1));
		else {
			for(var i=1;i<=nb;i++){
				this.getMoisSuivant();
			}
		}
	}
	
	OBJDate.prototype.retireMois = function(nb){
		for(var i=1;i<=nb;i++){
			this.getMoisPrecedent();
		}		
	}

	OBJDate.prototype.getJour = function(){
		//if(this.jour.length==1) this.jour = "0"+this.jour;
		return this.jour;
	}
	OBJDate.prototype.getMois = function(){
		//if(this.mois.length==1) this.mois = "0"+this.mois;
		return this.mois;
	}
	OBJDate.prototype.getAnnee = function(){
		return this.annee;
	}

	OBJDate.prototype.getLibelleJour = function(){
		var tabJ= new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
		return tabJ[this.getJourSemaine()];
	}
	
	OBJDate.prototype.getJourSemaine=function(){
		return new Date(this.mois+"/"+this.jour+"/"+this.annee).getDay();
	}
	OBJDate.prototype.getJSONLblJourWeek = function(langue) {	
		var tabJr;
		switch(langue){
			case "ANGLAIS":
				tabJr = [{"libelle":"Sunday","libelle_court":"Su"},
						 {"libelle":"Monday","libelle_court":"Mo"},
						 {"libelle":"Tuesday","libelle_court":"Tu"},
						 {"libelle":"Wednesday","libelle_court":"We"},
						 {"libelle":"Thursday","libelle_court":"Th"},
						 {"libelle":"Friday","libelle_court":"Fr"},
						 {"libelle":"Saturday","libelle_court":"Sa"}];
				break; 
				
			case "ALLEMAND":
				tabJr = [{"libelle":"Sonntag","libelle_court":"So"},
						 {"libelle":"Montag","libelle_court":"Mo"},
						 {"libelle":"Dienstag","libelle_court":"Di"},
						 {"libelle":"Mittwoch","libelle_court":"Mi"},
						 {"libelle":"Donnerstag","libelle_court":"Do"},
						 {"libelle":"Freitag","libelle_court":"Fr"},
						 {"libelle":"Samstag","libelle_court":"Sa"}];
				break; 
				
			case "HOLLANDAIS":
				tabJr = [{"libelle":"Zondag","libelle_court":"Zo"},
						 {"libelle":"Maandag","libelle_court":"Ma"},
						 {"libelle":"Dinsdag","libelle_court":"Di"},
						 {"libelle":"Woensdag","libelle_court":"Wo"},
						 {"libelle":"Donderdag","libelle_court":"Do"},
						 {"libelle":"Vrijdag","libelle_court":"Vr"},
						 {"libelle":"Zaterdag","libelle_court":"Za"}];
				break; 
				
			case "ESPAGNOL":
				tabJr = [{"libelle":"Domingo","libelle_court":"Do"},
						 {"libelle":"Lunes","libelle_court":"Lu"},
						 {"libelle":"Martes","libelle_court":"Ma"},
						 {"libelle":"Mi&eacute;rcoles","libelle_court":"Mi"},
						 {"libelle":"Jueves","libelle_court":"Ju"},
						 {"libelle":"Viernes","libelle_court":"Vi"},
						 {"libelle":"S&aacute;bado","libelle_court":"S&aacute;"}];
				break; 
				
			case "ITALIEN":
				tabJr = [{"libelle":"Domenica","libelle_court":"Do"},
						 {"libelle":"Lunedì","libelle_court":"Lu"},
						 {"libelle":"Martedì","libelle_court":"Ma"},
						 {"libelle":"Mercoledì","libelle_court":"Me"},
						 {"libelle":"Giovedì","libelle_court":"Gi"},
						 {"libelle":"Venerdì","libelle_court":"Ve"},
						 {"libelle":"Sabato","libelle_court":"Sa"}];
				break; 
				
			case "FRANCAIS":
			default:
				tabJr = [{"libelle":"Dimanche","libelle_court":"Di"},
						 {"libelle":"Lundi","libelle_court":"Lu"},
						 {"libelle":"Mardi","libelle_court":"Ma"},
						 {"libelle":"Mercredi","libelle_court":"Me"},
						 {"libelle":"Jeudi","libelle_court":"Je"},
						 {"libelle":"Vendredi","libelle_court":"Ve"},
						 {"libelle":"Samedi","libelle_court":"Sa"}];
				break; 
		}
		
		return tabJr;
	}
	
	OBJDate.prototype.getTabMois = function(langue){
		var tabM= new Array();
		
		switch(langue){
			case "ANGLAIS":
				tabM[1]="January";
				tabM[2]="Februar";
				tabM[3]="March";
				tabM[4]="April";
				tabM[5]="May";
				tabM[6]="June";
				tabM[7]="July";
				tabM[8]="August";
				tabM[9]="September";
				tabM[10]="October";
				tabM[11]="November";
				tabM[12]="December";
				break;
			
			case "ALLEMAND":
				tabM[1]="Januar";
				tabM[2]="Februar";
				tabM[3]="M&auml;rz";
				tabM[4]="April";
				tabM[5]="Mai";
				tabM[6]="Juni";
				tabM[7]="Juli";
				tabM[8]="August";
				tabM[9]="September";
				tabM[10]="Oktober";
				tabM[11]="November";
				tabM[12]="Dezember";
				break;
			
			case "HOLLANDAIS":
				tabM[1]="Januari";
				tabM[2]="Februari";
				tabM[3]="Maart";
				tabM[4]="April";
				tabM[5]="Mei";
				tabM[6]="Juni";
				tabM[7]="Juli";
				tabM[8]="Augustus";
				tabM[9]="September";
				tabM[10]="Oktober";
				tabM[11]="November ";
				tabM[12]="December";
				break;
			
			case "ESPAGNOL":
				tabM[1]="Eenero ";
				tabM[2]="Ebrero";
				tabM[3]="Marzo";
				tabM[4]="Abril";
				tabM[5]="Mayo";
				tabM[6]="Junio";
				tabM[7]="Julio";
				tabM[8]="Agosto";
				tabM[9]="Septiembre";
				tabM[10]="Octubre";
				tabM[11]="Noviembre ";
				tabM[12]="Diciembre";
				break;
			
			case "ITALIEN":
				tabM[1]="Gennaio";
				tabM[2]="Febbraio";
				tabM[3]="Marzo";
				tabM[4]="Aprile";
				tabM[5]="Maggio";
				tabM[6]="Giugno";
				tabM[7]="Luglio";
				tabM[8]="Agosto";
				tabM[9]="Settembre";
				tabM[10]="Ottobre";
				tabM[11]="Novembre ";
				tabM[12]="Dicembre";
				break;
			
			case "FRANCAIS":
			default:
				tabM[1]="Janvier";
				tabM[2]="F&eacute;vrier";
				tabM[3]="Mars";
				tabM[4]="Avril";
				tabM[5]="Mai";
				tabM[6]="Juin";
				tabM[7]="Juillet";
				tabM[8]="Aout";
				tabM[9]="Septembre";
				tabM[10]="Octobre";
				tabM[11]="Novembre";
				tabM[12]="D&eacute;cembre";
				break;
		}
		return tabM;
	}
	OBJDate.prototype.getLibelleMois = function(langue){
		if(!langue) langue = "FRANCAIS";
		var tabM=this.getTabMois(langue);
		return  tabM[this.getMois()];
	}
	

	OBJDate.prototype.toString = function(format){
		if(!format) format="dd/mm/yyyy";
		var strDate;
		
		var jr = parseInt(this.getJour(),10);
		var mois = parseInt(this.getMois(),10);
		var j= new String((jr<10)?"0"+jr:jr);
		var m= new String((mois<10)?"0"+mois:mois);
		var a4 = new String(this.getAnnee());
		var a2 = new String(parseInt((this.getAnnee()-2000),10));
		
		switch (format){
		case "dd/mm/yyyy":
			return (j+"/"+m+"/"+a4);
		case "dd/mm/yy":
			return (j+"/"+m+"/"+a2);
		case "ddmmyyyy":
			return (j+m+a4);
		case "yyyymmdd":
			return (a4+m+j);
		case "ddmmyy":
			return (j+m+a2);
		case "dd":
			return j;
		default:
			return (j+"/"+m+"/"+a4);
		}
	}



	OBJDate.prototype.getNbjMois = function(){
		return this.getNbjMoisAutre(this.mois);
	}


	OBJDate.prototype.getNbjMoisAutre = function(mois){
		if (mois==1 || mois==3 || mois==5 || mois==7 || mois==8 || mois==10 || mois==12)
			return 31;
		if (mois==4 || mois==6 || mois==9 || mois==11)
			return 30;
		if (mois==2 && this.estBissextile(this.annee))return 29;
		else return 28;
	}

	OBJDate.prototype.estBissextile = function(annee){
		return (annee%4==0 && (annee%100!=0 || (annee%100==0 && annee%400==0)));
	}


	OBJDate.prototype.estAvant = function(dte){
		obj=new OBJDate(dte);
		return (this.getTimeStamp()<=obj.getTimeStamp());
	}
	
	OBJDate.prototype.estAvantOBJDate = function(dte){
		return (this.getTimeStamp()<=dte.getTimeStamp());
	}
	
	OBJDate.prototype.estEgale = function(dte){
		obj=new OBJDate();
		obj.definition(dte);
		return (this.getTimeStamp()==obj.getTimeStamp());		
	}
	
	OBJDate.prototype.estApres = function(dte){
		obj=new OBJDate(dte);
		return (this.getTimeStamp()>=obj.getTimeStamp());
	}

	OBJDate.prototype.estApresOBJDate = function(dte){
		return (this.getTimeStamp()>=dte.getTimeStamp());
	}

	OBJDate.prototype.estComprisEntre = function(dteDeb,dteFin){		
		
		return (this.estAvant(dteFin) && this.estApres(dteDeb));
	}

	OBJDate.prototype.getTimeStamp = function() {
		return new Date(this.mois+"/"+this.jour+"/"+this.annee).getTime();
	}

	OBJDate.prototype.getNbJourEcartWithOBJDate = function(dte,positif) {
		var nbj1 = this.getTimeStamp()/ 86400000;
		var nbj2 = dte.getTimeStamp() / 86400000;
		var nbj = Math.round(nbj1 - nbj2);
		if(positif!="N" && nbj<0) nbj = nbj * (-1);
		return nbj;
	}
}
