function GnooCalendar(n, min, max, format)
{
	this.target_jour= null;
	this.target_mois= null;
	this.target_an= null;
	this.format = new String("fr");
	this.name = new String(n);
	this.tag = new String();
	this.title =  new String("GnooCalendar");
	this.date=new Date();
	this.moving = new Boolean(false);
	this.vis = new Boolean(false);
	this.free = new Boolean(false);
	this.curYear = new Number(this.date.getFullYear());
	this.maxYear = new Number(this.curYear+max);
	this.minYear = new Number(this.curYear-min);
	this.curMonth= new Number(this.date.getMonth());
//
	this.setFormat=function(f)
	{
		this.format=f;
		return;
	}
//
	this.setFree=function(vis)
	{
		this.free=vis;
		if(this.vis==true)
			this.show();
		return;
	}
//
	this.isDragable=function(drag)
	{
		if(drag==true && !document.layers)
		{
			document.onmousemove=this.getMouse;
			document.getElementById(this.div).root=this;
			document.getElementById(this.div).onmousedown=this.startMove;
			document.getElementById(this.div).onmouseup=this.endMove;
		}
		return;
	}
//
	this.startMove=function(evt)
	{
		var event;
		var tmp;
		if(this.root.vis!=true)
			return;
		if(document.all)
		{
			event = window.event;
			tmp = event.srcElement;
			if(!tmp.form)
			{
				this.root.fixX = tmp.offsetLeft+event.offsetX;
				this.root.fixY = event.offsetY;
				while(tmp.parentElement!=document.getElementById(this.root.div) && tmp.parentElement!=null )
				{
					this.root.fixX += tmp.parentElement.offsetLeft;
					this.root.fixY += tmp.parentElement.offsetTop;
					tmp = tmp.parentElement;
				}
				this.root.moving=true;
				self.movingCalendar = this.root;
				return false;
			}
		}
		else
		{
			event = evt;
			tmp = event.target;
			if( !tmp.form && tmp.tagName!="SELECT" && tmp.tagName!="OPTION" && tmp.tagName!="scrollbar" )
			{			
				this.root.fixX = event.layerX;
				this.root.fixY = event.layerY;
				this.root.moving=true;
				self.movingCalendar = this.root;
				return false;
			}
		}
		return evt;
	}
//
	this.endMove=function()
	{
		if(self.movingCalendar!=null)
		{
			self.movingCalendar.moving=false;
		}
		return false;
	}
//
	this.getMouse=function(evt)
	{
		
		var event;
		if(document.all)
		{
			event = window.event;
			var scrollObj = (document.documentElement) ? document.documentElement : document.body;
			this.posX = self.event.clientX+scrollObj.scrollLeft;
			this.posY = self.event.clientY+scrollObj.scrollTop;
		}
		else
		{
			event = evt;
			this.posX = evt.pageX ;
			this.posY = evt.pageY ;
		}
		if(self.movingCalendar!=null)
		{
			if(self.movingCalendar.moving==true && self.movingCalendar.vis==true )
				self.movingCalendar.move(this.posY-self.movingCalendar.fixY, this.posX-self.movingCalendar.fixX);
		}
		return false;
	}
//
	this.move=function(x, y)
	{
		if(!document.layers)
		{
			document.getElementById(this.div).style.top = x+"px";
			document.getElementById(this.div).style.left = y+"px";
		}
		return false;
	}

//
	this.setFreeDay=function(fd)
	{
		this.freeday.length=0;
		for(var i=0; i<fd.length; i++)
			this.freeday[i] = new String(fd[i]);
		if(this.vis==true)
			this.show();
		return;
	}
//
	this.isFreeDay=function(d,m)
	{
		var tmp = this.checkDate(d)+"/"+this.checkDate(parseInt(m)+1);
		if(this.free==false)
			return false;
		for(var i=0; i<this.freeday.length; i++)
			if( tmp == this.freeday[i])
				return true;
		return false;
	}
//
	this.setTitle=function(t)
	{
		this.title = t;
		if(this.vis==true)
			this.show();
		return;
	}
//
	this.mList=function()
	{
		var tmp = "<table border='0' cellpadding='0' cellspacing='0' class='Gtab'>";
	
		tmp += "<tr><td align='center' colspan='2' class='Gname'>";
		if(document.layers)
		{
			tmp += "<table width='100%'>";
			tmp += "<tr>";
			tmp += "<td class='Gname' align='center'>"+this.title+"</td>";
			tmp += "<td><a href='javascript://' onclick='"+this.name+".hide();' class='Gname'>X</a></td>";
			tmp += "</tr>";
			tmp += "</table>";
		}
		else
		{
			tmp += "<span style='float:left; text-indent:20px;'>"+this.title+"</span>";
			tmp += "<span style='float:right;'>";
			tmp += "<a href='javascript://' onclick='"+this.name+".hide();' class='Gname'>X</a>";
			tmp += "</span>";
		}
		tmp += "</td></tr>";
		tmp += "<tr>";
		tmp += "<td class='Gtxt'><select name='"+this.name+"month' class='Gtxt' ";
		tmp += "onchange='"+this.name+".setMonth(this[this.selectedIndex].value)'>\n";
		for(var i=0; i<this.month.length; i++)
		{			
			tmp += "<option value='"+i+"'";
			if(this.curMonth==i)
				tmp += " selected";
			tmp += ">"+ this.month[i] +"</option>\n";
		}
		tmp += "</select></td><td class='Gtxt'>\n";
		tmp += this.yList();
		tmp += "</td></tr></table>";
		tmp += this.dList();
		return tmp;
	}
//
	this.yList=function()
	{
		var tmp = "<select name='"+this.name+"year' class='Gtxt' ";
		tmp += "onchange='"+this.name+".setYear(this[this.selectedIndex].value);'>\n";
		for(var i=this.minYear; i<=this.maxYear; i+=1)
		{
			tmp += "<option value='"+i+"'";
			if(this.curYear==i)
				tmp += " selected";
			tmp += ">"+ i +"</option>\n";
		}
		tmp += "</select>\n";
		return tmp;
	}

	this.dayCell=function(d,n)
	{
		var tmp = new String("");
		var now = new Date();
		if(this.isFreeDay(d,this.curMonth))
		{
			tmp += "<td class='Gfree'";
		}
		else if (this.checkDate(d)==now.getDate() 
				&& this.curMonth==now.getMonth()
				&& this.curYear==now.getFullYear()) 
		{
			tmp += "<td class='Gc'";
		}
		else
		{
			tmp += "<td class='Gc"+n+"'";
		}
		if(!document.layers)
		{
			tmp += "title='"+this.checkDate(d)+" "+this.month[this.curMonth]+" "+this.curYear+"'";
			tmp += " onmousedown='"+this.name+".getDate(\"";
			tmp += this.formatDate(d);
			tmp += "\");' ";
			tmp += " onmouseover='this.className=this.className+\"on\";' ";
			tmp += " onmouseout='this.className= this.className.substring(0,this.className.indexOf(\"on\"));'";
		}
		else
			tmp += " width='22' height='16' ";
		tmp += ">";
		return tmp;
	}
//
	this.dList=function()
	{
		var cur=new Number(1);
		var tmpDate = new Date();
		var tmp = new String("<table border='0' cellpadding='0' cellspacing='0' class='Gtab'>");
		tmpDate.setDate(cur);
		tmpDate.setMonth(this.curMonth);
		tmpDate.setFullYear(this.curYear);
		tmp += "<tr>\n";
		for(var i=1; i<this.day.length; i++)
			tmp += "<td class='Gh"+i+"'>"+ this.day[i] +"</td>\n";
		tmp += "<td class='Gh0'>"+ this.day[0] +"</td>\n";
		tmp += "</tr>\n";
		for(var j=0; j<6; j++)
		{
			tmp += "<tr>\n";
			for(var i=1; i<this.day.length; i++)
			{
				tmpDate.setDate(cur);			
				if( cur<=31 && i==tmpDate.getDay() && this.curMonth==tmpDate.getMonth())
				{
					tmp += this.dayCell(cur,i);
					tmp += this.getLink(cur);
					cur+=1;
				}
				else
				{
					tmp += "<td class='Gc"+i+"'";
					tmp += ">&nbsp;";
				}
				tmp += "</td>\n";
				tmpDate.setDate(cur);
			}
			if( cur==tmpDate.getDate() && this.curMonth==tmpDate.getMonth())
			{
				tmp += this.dayCell(cur,0);
				tmp += this.getLink(cur);
				cur+=1;
			}
			else
			{
				tmp += "<td class='Gc0'";
				tmp += ">&nbsp;";
			}
			tmp += "</td>\n</tr>\n";
		}
		tmp += "</table>\n";
		return tmp;
	}
//
	this.getLink = function(c)
	{
		var tmp = new String("");
		if(document.layers)
		{
			tmp = "<a href='javascript://' ";
			tmp += "onclick='"+this.name+".getDate(\"";
			tmp += this.formatDate(c);
			tmp += "\");' class='NSday'>"+(c)+"</a>";
		}
		else
		{
			tmp = (c);
		}
		return tmp;
	}
//
	this.setMonth = function(m)
	{
		this.curMonth = m;
		this.show();
		return;
	}
//
	this.getYear = function (y)
	{
		if(document.layers)
		{
			for(var i=0; i<document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"].length; i++)
			{
				if(document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"][i].value==y)
				{
					document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"].selectedIndex=i;
					this.setYear(y);
					return;
				}
			}
		}
		else
		{
			for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"year"].length; i++)
			{
				if(document.forms[this.name+"_form"].elements[this.name+"year"][i].value==y)
				{
					document.forms[this.name+"_form"].elements[this.name+"year"].selectedIndex=i;
					this.setYear(y);
					return;
				}
			}
		}
		return;
	}
//
	this.getMonth = function (d)
	{
		if(document.layers)
		{
			for(var i=0; i<document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"].length; i++)
			{
				if(document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"][i].value==d)
				{
					document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"].selectedIndex=i;
					this.setMonth(d);
					return;
				}
			}
		}
		else
		{
			for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"month"].length; i++)
			{
				if(document.forms[this.name+"_form"].elements[this.name+"month"][i].value==d)
				{
					document.forms[this.name+"_form"].elements[this.name+"month"].selectedIndex=i;
					this.setMonth(d);
					return;
				}
			}
		}
		return;
	}
//
	this.setYear = function (y)
	{
		this.curYear = y;
		this.show();
		return;
	}
//
	this.setTarget = function (obj_jour, obj_mois, obj_an)
	{
		this.target_jour = obj_jour;
		this.target_mois = obj_mois;
		this.target_an = obj_an;		
		return;
	}
//
	this.hide = function()
	{
		if(document.layers)
			document.layers[this.div].visibility='hide';
		else
		{
			document.getElementById(this.div).style.visibility = 'hidden';
			document.getElementById(this.div).style.display = 'none';
		}
		this.vis = false;
		this.endMove();
		return;
	}

//
	this.getDate = function(d)
	{
		if(this.target_jour!=null && this.target_mois!=null && this.target_an!=null)
		{
			jour = this.checkDate(d);
			this.target_jour.value=jour;
			mois = this.checkDate(1+parseInt(this.curMonth));
			this.target_mois.value=mois;
			an = this.curYear;
			this.target_an.value=an;			
			this.hide();
			recalc_onclick('');
		}
		return;
	}

//
	this.show = function()
	{
		this.vis = true;
		this.tag = "<form name='"+this.name+"_form' method='post'>\n";
		this.tag += this.mList();
		this.tag += "</form>\n";
		if(document.layers)
		{
			with(document.layers[this.div])
			{				
				document.open("text/html");
				document.write(this.tag);
				document.close();
				visibility='show';
			}
		}
		else
		{
			document.getElementById(this.div).innerHTML = ""+this.tag;
			document.getElementById(this.div).style.visibility = 'visible';
			document.getElementById(this.div).style.display = 'block';
		}
		return;
	}
//
	this.init = function(d, obj_jour, obj_mois, obj_an)
	{
		this.div=d;
		this.target_jour = obj_jour;
		this.target_mois = obj_mois;
		this.target_an = obj_an;		
		this.date=new Date();
		this.date.setDate(1);		
		this.curMonth = this.date.getMonth();
		this.curYear = this.date.getFullYear();
		if(!self.movingCalendar)
			self.movingCalendar=null;
		return;
	}
//
	this.checkDate = function(d)
	{
	/*
	*if(parseInt(d)<=9)
	*return "0"+parseInt(d);
	*/
		return parseInt(d);
	}
//
	this.formatDate = function(c)
	{
		var tmp = "";
		switch(this.format)
		{
			case "us":	// englais	
				tmp = this.curYear+"-";
				tmp += this.checkDate(1+parseInt(this.curMonth))+"-";
				tmp += this.checkDate(c);
				break;
			default: 	// français
				tmp = this.checkDate(c)+"/"; 
				tmp += this.checkDate(1+parseInt(this.curMonth))+"/";
				tmp += this.curYear;
				break;
		}
		return tmp;
	}
	return this;
}
GnooCalendar.prototype.day = ["D", "L", "M", "M", "J", "V", "S" ];
GnooCalendar.prototype.month = ["Janvier", 
				"F&eacute;vrier", 
				"Mars", 
				"Avril", 
				"Mai", 
				"Juin", 
				"Juillet", 
				"Ao&ucirc;t", 
				"Septembre", 
				"Octobre", 
				"Novembre", 
				"D&eacute;cembre"];
/* jours feriés français */
GnooCalendar.prototype.freeday= ["01/01","10/01","31/01","20/03","21/03","09/04","10/04","01/05","25/07","13/08","15/10","23/10","07/11","31/12"];