var le_cal;
var la_date;
var le_champ;
var fin_init = false;
function initCal()
{
 var today = new Date();
 var thisMonth = today.getMonth();
 var thisDay  = today.getDate();
 var thisYear = today.getFullYear();
 YAHOO.widget.Calendar_Core.IMG_ROOT = 'Images/Icone/';
 le_cal = new YAHOO.widget.CalendarGroup("le_cal","calContainer",(thisMonth+1)+"/"+thisYear,(thisMonth+1)+"/"+thisDay+"/"+thisYear);
 le_cal.cfg.setProperty("close",true);
 le_cal.cfg.setProperty("title","Sélectionnez une date :");
 le_cal.cfg.setProperty("DATE_FIELD_DELIMITER","/");
 le_cal.cfg.setProperty("MDY_DAY_POSITION",1);
 le_cal.cfg.setProperty("MDY_MONTH_POSITION",2);
 le_cal.cfg.setProperty("MDY_YEAR_POSITION",3);
 le_cal.cfg.setProperty("MD_DAY_POSITION",1);
 le_cal.cfg.setProperty("MD_MONTH_POSITION",2);
 le_cal.cfg.setProperty("MONTHS_SHORT",   ["Jan", "Fév", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc"]);
 le_cal.cfg.setProperty("MONTHS_LONG",    ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"]);
 le_cal.cfg.setProperty("WEEKDAYS_1CHAR", ["D", "L", "M", "M", "J", "V", "S"]);
 le_cal.cfg.setProperty("WEEKDAYS_SHORT", ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"]);
 le_cal.cfg.setProperty("WEEKDAYS_MEDIUM",["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"]);
 le_cal.cfg.setProperty("WEEKDAYS_LONG",  ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"]);
}
function showCal(formDate,link)
{
 fin_init = false;
 var est_date = false;
 if ( formDate.value != '' && formDate.value.length >= 10 )
 {
  var day   = formDate.value.substr(0,2);
  var month = formDate.value.substr(3,2);
  var year  = formDate.value.substr(6,4);
  est_date  = isDate(year,month,day);
 }
 if ( est_date )
 {
  le_cal.select(day+"/"+month+"/"+year);
  var firstDate = le_cal.getSelectedDates()[0];
  le_cal.cfg.setProperty("pagedate",(firstDate.getMonth()+1) + "/" + firstDate.getFullYear());
 }
 le_cal.selectEvent.subscribe(handleSelect,le_cal,true);
 le_cal.render();
 var viewWidth = YAHOO.util.Dom.getViewportWidth();
 var pos = YAHOO.util.Dom.getXY(link);
 var x = pos[0];
 var y = pos[1] + link.offsetHeight + 1;
 if ( x + 288 > viewWidth )
 {
 	x = pos[0] - 288 + link.offsetWidth;
 }
 document.getElementById("calContainer").style.display = 'block';
 YAHOO.util.Dom.setXY(document.getElementById("calContainer"),[x,y]);
 le_champ = formDate;
 fin_init = true;
}
function handleSelect(type,args,obj)
{
 if ( fin_init )
 {
  var maxlength = 0;
  for (var j=0;j<le_champ.attributes.length;j++)
  {
   attName = le_champ.attributes[j].name.toLowerCase();
   attVal  = le_champ.attributes[j].value;
   switch ( attName )
   {
    case 'maxlength':
     maxlength = parseInt(attVal);
     break;
   }
  }
  heure = '';
  if ( parseInt(maxlength) == 19 )
  {
   heure = le_champ.value.substr(11,8);
   if ( heure.trim() == '' ) heure = '00:00:00';
  }
  var dates = args[0];
  la_date   = dates[0];
  jj = la_date[2];
  mm = la_date[1];
  aa = la_date[0];
  strDate = '';
  if ( jj < 10 ) strDate = strDate + '0';
  strDate = strDate + jj + "-";
  if ( mm < 10 ) strDate = strDate + '0';
  strDate = strDate + mm + "-";
  strDate = strDate + aa;
  if ( parseInt(maxlength) == 19 )
  {
   le_champ.value = strDate + ' ' + heure;
  }
  else
  {
   le_champ.value = strDate;
  }
  document.getElementById("calContainer").style.display = 'none';
 }
}
