function GabCalendar(n, min, max, format)
{
	this.target= null;
	this.format = new String("fr");
	this.name = new String(n);
	this.tag = new String();
	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);
	this.curMonth= new Number(this.date.getMonth());
/*
* GabCalendar.setFormat(String format)
* format de date : "fr"=français, "us"=englais
*/
	this.setFormat=function(f)
	{
		this.format=f;
		return;
	}
/*
* GabCalendar.setFree(Boolean vis)
* affiche ou non des jours feries
*/
	this.setFree=function(vis)
	{
		this.free=vis;
		if(this.vis==true)
			this.show();
		return;
	}
/*
* GabCalendar.getMouse(Event evt)
* change la liste des jours feriés
*/
	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;
	}
/*
* GabCalendar.setFreeDay(Array fd)
* change la liste des jours feriés
*/
	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;
	}
/*
* GabCalendar.isFreeDay(d,m)
* true si jour ferié
*/
	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;
	}
/*
* GabCalendar.mList()
* retourne la liste des mois 
*/
	this.mList=function()
	{
		var tmp = "<table border='0' cellpadding='0' cellspacing='0' class='SGtab'>";
		var now = new Date();
	
		tmp += "<tr>";
		tmp += "<td class='SGtxt' nowrap><select name='"+this.name+"month' class='SGtxt' ";
		tmp += "onchange='"+this.name+".setMonth(this[this.selectedIndex].value)' >\n";
		for(var i=0; i<this.month.length; i++)
		{			
			if(this.curYear==now.getFullYear()){
				if(i>=now.getMonth()){
					tmp += "<option value='"+i+"'";
					if(i==this.curMonth)
						tmp += " selected";
					tmp += ">"+ this.month[i] +"</option>\n";
				}
			}else{
					tmp += "<option value='"+i+"'";
					if(this.curMonth==i)
						tmp += " selected";
					tmp += ">"+ this.month[i] +"</option>\n";
			}
		}
		tmp += "</select>\n";
		tmp += this.yList();
		tmp += "&nbsp;&nbsp;&nbsp;<a href='javascript://' onclick='"+this.name+".hide();' class='SGname'>X</a></td></tr></table>";
		tmp += this.dList();
		return tmp;
	}
/*
* GabCalendar.yList()
* retourne la liste des années 
*/
	this.yList=function()
	{
		var tmp = "<select name='"+this.name+"year' class='SGtxt' ";
		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='SGfree'";
		}
		else if (this.checkDate(d)==now.getDate() 
				&& this.curMonth==now.getMonth()
				&& this.curYear==now.getFullYear()) 
		{
			tmp += "<td class='SGc'";
		}
		else
		{
			tmp += "<td class='SGc"+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;
	}
/*
* GabCalendar.dList()
* retourne le tableau des jours
*/
	this.dList=function()
	{
		var now = new Date();
		var cur=new Number(1);
		var tmpDate = new Date();
		var tmp = new String("<table border='0' cellpadding='0' cellspacing='0' class='SGtab'>");
		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='SGh"+i+"'>"+ this.day[i] +"</td>\n";
		tmp += "<td class='SGh0'>"+ 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())
				{
					if(this.curMonth==now.getMonth() && this.curYear==now.getFullYear() && cur<now.getDate()+2){
						if(cur==now.getDate()){ // date du jour en jaune
							tmp += "<td class='SGc' style='color:#fff' width='22' height='16'>";
							tmp += cur;
						}else{
							tmp += "<td class='SGc"+i+"' style='color:#aaaaaa'";
							tmp += ">"+cur;
						}
					}else{
						tmp += this.dayCell(cur,i);
						tmp += this.getLink(cur);
//						tmp += now.getMonth();
					}
					cur+=1;
				}
				else
				{
					tmp += "<td class='SGc"+i+"'";
					tmp += ">&nbsp;";
				}
				tmp += "</td>\n";
				tmpDate.setDate(cur);
			}
			if( cur==tmpDate.getDate() && this.curMonth==tmpDate.getMonth()) // Dimanche
			{
				if(this.curMonth==now.getMonth() && this.curYear==now.getFullYear() && cur<now.getDate()+2){
					if(cur==now.getDate()){
						tmp += "<td class='SGc' style='color:#fff' width='22' height='16'>";
						tmp += cur;
					}else{
						tmp += "<td class='SGc"+i+"' style='background-color:#bbbbbb;border:1px solid #fff;color:#aaaaaa;'";
						tmp += ">"+cur;
					}
				}else{
					tmp += this.dayCell(cur,0);
					tmp += this.getLink(cur);
				}
				cur+=1;
			}
			else
			{
				tmp += "<td class='SGc0'";
				tmp += ">&nbsp;";
			}
			tmp += "</td>\n</tr>\n";
		}
		tmp += "</table>\n";
		return tmp;
	}
/*
* GabCalendar.getLink(c)
* retourne la balise d'un lien
*/
	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;
	}
/*
* GabCalendar.setMonth( Integer m )
* modifie le mois à afficher
*/
	this.setMonth = function(m)
	{
		this.curMonth = m;
		this.show();
		return;
	}
/*
* GabCalendar.getYear( Integer y )
* modifie l'année à afficher
*/
	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;
	}
/*
* GabCalendar.getMonth( Integer m )
* modifie le mois à afficher
*/
	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;
	}
/*
* GabCalendar.setYear( Integer y )
* modifie l'année à afficher
*/
	this.setYear = function (y)
	{
		this.curYear = y;
		this.show();
		return;
	}
/*
* GabCalendar.setTarget( Object obj )
* change le champs cible d'affichage de la date
* BUG OPERA!
*/
	this.setTarget = function (obj)
	{
		this.target = obj;
		return;
	}
/*
* GabCalendar.hide()
* masque le calendrier
*/
	this.hide = function()
	{
		calculprix();
		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;
	}

/*
* GabCalendar.getDate()
* retourne la date selectionnée dans le champs cible
*/
	this.getDate = function(d)
	{
		if(this.target!=null)
		{
			this.target.value=d;	
			this.hide();
		}
		return;
	}

/*
* GabCalendar.show()
* affiche le calendrier
*/
	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;
	}
/*
* GabCalendar.init( String d )
* initialise le Calendrier à la date actuelle
* paramêtres : 
* d : nom du calque d'affichage
* obj : objet dont la propriété value va recevoir le String de la date
*/
	this.init = function(d, obj)
	{
		this.div=d;
		this.target = obj;
		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;
	}
/*
* GabCalendar.checkDate( Integer d )
* paramêtre : le jour d'une date
*/
	this.checkDate = function(d)
	{
		if(parseInt(d)<=9)
			return "0"+parseInt(d);
		return parseInt(d);
	}
/*
* GabCalendar.formatDate( Integer d, Integer m, Integer y )
* paramêtre : le jour d'une date
*/
	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;
}
/******************************/
GabCalendar.prototype.day = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ];
GabCalendar.prototype.month = ["January", 
				"February", 
				"March", 
				"April", 
				"May", 
				"June", 
				"July", 
				"August", 
				"September", 
				"October", 
				"November", 
				"December"];
/* jours feriés français */
GabCalendar.prototype.freeday= ["01/01","25/12"];
/******************************/

function calculprix(){
	if(document.calform.calformfield1.value!="" && document.calform.calformfield2.value!="" && document.calform.calformfield1.value!="dd/mm/yyyy" && document.calform.calformfield2.value!="dd/mm/yyyy"){
 		document.getElementById("priceyes").style.display="block";
 		document.getElementById("priceno").style.display="none";
		var sdate = document.calform.calformfield1.value.split("/");
		var startdate	=	new Date(sdate[1]+"/"+sdate[0]+"/"+sdate[2]+" "+document.calform.pickuptime.value+":00:00");
		var edate = document.calform.calformfield2.value.split("/");
		var enddate	=	new Date(edate[1]+"/"+edate[0]+"/"+edate[2]+" "+document.calform.returntime.value+":00:00");
		var rentalTime = (enddate.getTime()-11400000)  - startdate.getTime();
		if(rentalTime<0){
			alert("Rental start date must be prior to rental end date. Please enter this data again.");
		}else{
			var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;
			var duration = Math.floor((rentalTime / day)+1);
			document.getElementById("rentalduration").value=duration;
			calculleprix();
		}
	}else{
 		document.getElementById("priceyes").style.display="none";
 		document.getElementById("priceno").style.display="block";
	}
}
