
function ampCalendar_setFebDays()
{
  if ( this.month == 1 ) 
  {
    if ( this.year % 4 == 0 )
    {
      if ( this.year % 100 == 0)
      {
        if ( this.year % 400 == 0) 
          this.m_rgDays[1] = 29;
      }
      else
        this.m_rgDays[1] = 29;
    }
  }
}

function ampCalendar_Display()
{
	document.writeln("<font size=3><B>" + this.title + "</font></B>");
	document.writeln("<table width=\"490\" border=\"0\" cellpadding=\"1\" bordercolor=\"#000000\">");
	document.writeln("<tr>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Dimanche</b></font></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Lundi</b></font></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Mardi</b></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Mercredi</b></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Jeudi</b></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Vendredi</b></td>");
	document.writeln("<td align=\"center\" width=\"14%\" bgcolor=\"#00204E\"><font color=\"#FFFFFF\" face=\"" + this.font + "\" size=\"" + this.headSize + "\"><b>Samedi</b></td>");
	document.writeln("</tr>");
	
	// colonnes
	for (j = 0; j < 5; j++)
	{
	x = 0;
	document.writeln("<tr>");
	for( i = 0; i < 7; i++)
	{
	if ( this.m_myDate.getDay() > (i + x) || 
	 this.m_myDate.getMonth() != this.month - 1 )
	document.writeln("<td width=\"14%\" bgcolor=\"#" + this.m_strDead + "\">&nbsp;</td>");
	else
	{
	slongueur = "";
	slongueur = this.getText(this.m_myDate.getDate());
	longueur = slongueur.length;
	if (longueur>14) 
	{
	 ahref = "<A HREF='#" + this.m_myDate.getDate() + "'>";
	 ahrefe = "</A>";
	}
	else
	{
	 ahref = "";
	 ahrefe = "";
	}
	
	// Test sur l'année
	//alert((this.m_myDate.getYear() < this.m_now.getYear() ));
	if (this.m_myDate.getYear() < this.m_now.getYear() )
	{
	 document.writeln("<td valign=\"top\" width=\"14%\" bgcolor=\"#" + this.m_strPast + "\"><b>" + 
	 "<font face=\"" + this.font + "\" size=\"" + this.fontSize + "\">" + ahref + 
	 this.m_myDate.getDate() + ahrefe + "</b><br>" + ahref + 
	 this.getText( this.m_myDate.getDate()) + ahrefe + 
	 "</font></td>");
	}
	else
	{
	 if (this.m_myDate.getMonth() < this.m_now.getMonth())
	 {
	  document.writeln("<td valign=\"top\" width=\"14%\" bgcolor=\"#" + this.m_strPast + "\"><b>" + 
	  "<font face=\"" + this.font + "\" size=\"" + this.fontSize + "\">" + ahref + 
	  this.m_myDate.getDate() + ahrefe + "</b><br>" + ahref + 
	  this.getText( this.m_myDate.getDate()) + ahrefe + 
	  "</font></td>");
	 }
	 else
	 {
	  if (
	      (
		   (this.m_myDate.getDate() < this.m_now.getDate())
		   &&
		   (this.m_myDate.getMonth() == this.m_now.getMonth() )
		  )
		  &&
		  (this.m_myDate.getYear() == this.m_now.getYear())
		 )  // Jour précédent dans le mois
	  {
	   document.writeln("<td valign=\"top\" width=\"14%\" bgcolor=\"#" + this.m_strPast + "\"><b>" + 
	   "<font face=\"" + this.font + "\" size=\"" + this.fontSize + "\">" + ahref + 
	   this.m_myDate.getDate() + ahrefe + "</b><br>" + ahref + 
	   this.getText( this.m_myDate.getDate()) + ahrefe + 
	   "</font></td>");
	  }
	  else
	  {
	   if (
	       (
		    (this.m_myDate.getDate() == this.m_now.getDate())
			&&
			(this.m_myDate.getMonth() == this.m_now.getMonth())
		   )
		   &&
		   (this.m_myDate.getYear() == this.m_now.getYear())
		  )
	   {
	    document.writeln("<td valign=\"top\" width=\"14%\" bgcolor=\"#" + this.m_strNow + "\"><b>" + 
		    "<font face=\"" + this.font + "\" size=\"" + this.fontSize + "\">" + ahref + 
		    this.m_myDate.getDate() + ahrefe + "</b><br>" + ahref + 
		    this.getText( this.m_myDate.getDate()) + ahrefe +
		    "</font></td>");
	   }
	   else
	   {
	    document.writeln("<td valign=\"top\" width=\"14%\" bgcolor=\"#" + this.m_strFutr + "\"><b>" + 
	    "<font face=\"" + this.font + "\" size=\"" + this.fontSize + "\">" + ahref +
	    this.m_myDate.getDate() + ahrefe + "</b><br>" + ahref +
	    this.getText( this.m_myDate.getDate()) + ahrefe +
	    "</font></td>");
	   }
	  }
	 }
	}
	
	
	this.m_myDate.setDate( this.m_myDate.getDate() + 1 );
      }
    }
    document.writeln("</tr>");
    x += 7;
  }
  document.writeln("</table>");

}

function ampCalendar_setItem( nDay, strText )
{
  x = this.m_rgDay.length;
  this.m_rgDay[x + 1] = nDay;
	this.m_rgTxt[x + 1] = strText;
}

function ampCalendar_getText( n )
{
  var strResult = "";
  var x = 0;
  //alert(this.m_rgDay.length);
	while( x < this.m_rgDay.length ) 
	{
		if ( n == this.m_rgDay[x] ) 
			//return this.m_rgTxt[x] ;
		strResult += this.m_rgTxt[x];

		x++;
	}
  return strResult;
}

function ampCalendar( m, y )
{
	// properties
	this.m_rgDay = new Array();
	this.m_rgTxt = new Array();
	
	// Static stuff

	// Colors
	this.m_strDead = "ADBFD2";
  this.m_strFutr = "99CCFF";
  this.m_strPast = "A9C7EC";
  this.m_strNow  = "6699CC";

	this.m_rgDays = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); 
	this.m_rgMths = new Array( "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", 
	 "Septembre", "Octobre", "Novembre", "Decembre" );

	this.font = "Verdana, Arial, Helvetica";
  this.fontSize  = "2";
  this.headSize  = "2";

  this.month = m;
  this.year  = y;
	this.m_now = new Date(); 
	this.m_myDate  = new Date(y, m - 1, 1);

	this.monthName = this.m_rgMths[ this.m_myDate.getMonth() ];
  this.title = this.monthName + " " + this.year;

	// Methods
	this.setFebDays = ampCalendar_setFebDays;
	this.display = ampCalendar_Display;
	this.setItem = ampCalendar_setItem;
	this.getText = ampCalendar_getText;

  this.setFebDays();
}


