TAB_CONTROLS = new Array();

var DateJour = new Date();
DATE_DU_JOUR = new Array();
DATE_DU_JOUR[0] = DateJour.getDate();
DATE_DU_JOUR[1] = DateJour.getMonth();
DATE_DU_JOUR[2] = DateJour.getFullYear();
//var JOUR_SEMAINE = new Array('D','L','M','M','J','V','S');
//var MOIS_ANNEE = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');

//**************************************************************
//* Contrôle Calendrier
//**************************************************************

function CtrlCalendrier(largeur) {
  this.index = TAB_CONTROLS.length;
  TAB_CONTROLS[this.index] = this;
  var datedefaut = new Date();
  datedefaut.setDate(DATE_DU_JOUR[0]);
  datedefaut.setMonth(DATE_DU_JOUR[1]);
  datedefaut.setFullYear(DATE_DU_JOUR[2]);
  this.value = datedefaut;
  this.evenements = Array();
  this.premier = 0;
  this.largeur = largeur;
}

CtrlCalendrier.prototype.Add = function(control) {
  var tmp = new Date(Number(control.dateevn));
  this.evenements[ChaineComplete("0000",tmp.getFullYear(),4)+ChaineComplete("00",tmp.getMonth()+1,2)+ChaineComplete("00",tmp.getDate(),2)]=control.value;
}

CtrlCalendrier.prototype.Construct = function() {
  var output = "";
  output += "<DIV id='TableauCalendrier_"+this.index+"'>";
  output += this.ConstructContenu();
  output += "</DIV>";
  return output;
}

CtrlCalendrier.prototype.ConstructContenu = function() {
  var output = "";
  var tmpmois = new Date(this.value.getFullYear(),this.value.getMonth(),this.value.getDate());
  output += "<TABLE CLASS='CalendrierAdv_Tableau' border=0 cellpadding=1 cellspacing=0 width='"+this.largeur+"'>";
  output += "<TR>";
  output += "<TD align='left' width='14%' id='Prec_Calendrier_ctrl_"+this.index+"' Class='CalendrierAdv_EntetePrec' ";
  output += "accessoryGroups='cavtitre'  onclick='javascript:TAB_CONTROLS["+this.index+"].Navigation(this.id);'><</TD>";
  output += "<TD accessoryGroups='cavtitre' align='center' Class='CalendrierAdv_Entete' colspan=5 ";
  output += " >" + MoisEnClair(tmpmois) + " " + tmpmois.getFullYear() + "</TD>";
  output += "<TD accessoryGroups='cavtitre' align='right' width='14%' id='Suiv_Calendrier_ctrl_"+this.index+"' Class='CalendrierAdv_EnteteSuiv' ";
  output += " onclick='javascript:TAB_CONTROLS["+this.index+"].Navigation(this.id);'>></TD></TR>";
  output += "<TR>";
  for(var i=0 ; i < 7 ; i++)
  {
    output += "<TD width='14%' accessoryGroups='cavjour' Class='CalendrierAdv_EnteteJours' align='center'";
    output += " >" + JourEnClair(i) + "</TD>";
  }
  output +="<TR>";
  var tmp = new Date(this.value.getFullYear(),this.value.getMonth(),this.value.getDate());
  var col = 0 ;
  var lig = 0;
  tmp.setMonth(tmp.getMonth())
  tmp.setDate(1);
  while(tmp.getMonth()==tmpmois.getMonth())
  {
    if (col==7)
    {
      output += "</TR><TR>";
      col = 0 ;
      lig++;
    }
    if (tmp.getDay()==col)
    {
      if(tmp.getDate()==1)
        this.premier = col;
      if(this.evenements[ChaineComplete("0000",tmp.getFullYear(),4)+ChaineComplete("00",tmp.getMonth()+1,2)+ChaineComplete("00",tmp.getDate(),2)]!=null)
      {
        output += "<TD align='center' accessoryGroups='cavevenement' width='14%' id='Cell_Calendrier_ctrl_"+this.index+"_"+ChaineComplete("000",col,3)+"_"+ChaineComplete("000",lig,3)+"' Class='CalendrierAdv_Existe'";
          output += "><A Class='CalendrierAdv_Lien' href='"+this.evenements[ChaineComplete("0000",tmp.getFullYear(),4)+ChaineComplete("00",tmp.getMonth()+1,2)+ChaineComplete("00",tmp.getDate(),2)]+"'>"+tmp.getDate()+"</a></TD>";
      }
      else
      {
        output += "<TD align='center' accessoryGroups='cavfond' width='14%' id='Cell_Calendrier_ctrl_"+this.index+"_"+ChaineComplete("000",col,3)+"_"+ChaineComplete("000",lig,3)+"' Class='CalendrierAdv_NExiste'";
        output += ">"+tmp.getDate()+"</TD>";
      }
      tmp.setDate(tmp.getDate()+1);
    }
    else
    {
      output += "<TD align='center' width='14%' id='Cell_Calendrier_ctrl_"+this.index+"_"+ChaineComplete("000",col,3)+"_"+ChaineComplete("000",lig,3)+"' Class='CalendrierAdv_Blanc'";
      output += ">&nbsp;</TD>";
    }
    col++;
  }
  while (col!=7)
  {
    output += "<TD align='center' width='14%' id='Cell_Calendrier_ctrl_"+this.index+"_"+ChaineComplete("000",col,3)+"_"+ChaineComplete("000",lig,3)+"' Class='CalendrierAdv_Blanc'";
    output += ">&nbsp;</TD>";
    col++;
  }
  output += "</TR>";
  tmp.setDate(tmp.getDate()-1);
/*
  while (lig!=5)
  {
    output += "<TR>";
    col=0;
    lig++;
    while (col!=7)
    {
      output += "<TD align='center' id='Cell_Calendrier_ctrl_"+this.index+"_"+ChaineComplete("000",col,3)+"_"+ChaineComplete("000",lig,3)+"' Class='CalendrierAdv_Blanc'";
      output += ">&nbsp;</TD>";
      col++;
    }
    output += "</TR>";
  }
*/
  output += "</TABLE>";

  return output;
}


CtrlCalendrier.prototype.Navigation = function(id)
{
  if (id.substr(0,4)=="Prec")
  {
    this.value.setMonth(this.value.getMonth()-1);
    this.Refresh();
  }
  else
  {
    this.value.setMonth(this.value.getMonth()+1);
    this.Refresh();
  }
}

CtrlCalendrier.prototype.Refresh = function ()
{
  document.all("TableauCalendrier_"+this.index).innerHTML=this.ConstructContenu();
}


//**************************************************************
//* Contrôle Evénement
//**************************************************************

function CtrlEvenement(date,lien) {
  this.dateevn = date
  this.value=lien;
}

CtrlEvenement.prototype.GetValue = function ()
{
 return this.value;
}


function MoisEnClair(valdate)
{
  return MOIS_ANNEE[valdate.getMonth()];
}

function JourEnClair(valdate)
{
  return JOUR_SEMAINE[valdate];
}

function ChaineComplete(char,string,longueur)
{
 var tmp = char + String(string);
 return tmp.substr((tmp.length-longueur),longueur);
}