YAHOO.util.Event.addListener(window, "load", 
  function()
  {
	if(!YAHOO.util.Dom.get("calendar"))
	  return;
    YAHOO.namespace("example.calendar");

    sReturn = '';
    iFirstKey = 0;
    sDate = '';
    
    if(typeof(property) != "undefined")
    {
      for (property in aSelectedDate)
      {
        if (iFirstKey == 0)
        {
          sDate = aSelectedDate[property];
          sProperty = property;
        }
        iFirstKey++;
      }
      var iYear = sProperty.substr(0, 4);
      var iMonth = sProperty.substr(5, 2);
      iKey = 0;
      for(sKey in sDate)
      {
        if (iKey == 0)
        {
          var iDay = aSelectedDate[sProperty][sKey];
          aMaxDate = new Array(iYear,iMonth, iDay);
        }
        iKey++;
      }

      YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","calendar-content", 
        {
          mindate: STARTDATE, 
          maxdate: new Date(aMaxDate)
        } 
      ); 
    }
    else
    {
        YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","calendar-content");
    }
    
    aMonth = new Array();
    aMonth['LONG'] = new Array();
    aMonth['SHORT'] = new Array();
    for(i=1; i<=12; i++)
    {
      aMonth['LONG'].push(oGB.GG('long-' + i, 'date_month'));
      aMonth['SHORT'].push(oGB.GG('short-' + i, 'date_month'));
    }
    YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_SHORT", aMonth['SHORT']); 
    YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG", aMonth['LONG']); 

    aDay = new Array();
    aDay['LONG'] = new Array();
    aDay['SHORT'] = new Array();

    aDay['LONG'].push(oGB.GG('long-6', 'date_day'));
    aDay['SHORT'].push(oGB.GG('short-6', 'date_day'));

    for(i=0; i<=5; i++)
    {
      aDay['LONG'].push(oGB.GG('long-' + i, 'date_day'));
      aDay['SHORT'].push(oGB.GG('short-' + i, 'date_day'));
    }

    YAHOO.example.calendar.cal1.cfg.setProperty("START_WEEKDAY", 1); 
    YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT", aDay['SHORT']); 
    YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",  aDay['LONG']); 

    YAHOO.example.calendar.cal1.addRenderer(GenerateSelectedString(), YAHOO.example.calendar.cal1.renderCellStyleHighlight1);
    YAHOO.example.calendar.cal1.selectEvent.subscribe(ChooseDate, YAHOO.example.calendar.cal1, true); 

    YAHOO.example.calendar.cal1.render();
  }
);

var GenerateSelectedString = function()
{
  var sReturn = "";
  for(sDate in aSelectedDate)
  {
    var iYear = sDate.substr(0, 4);
    var iMonth = sDate.substr(5, 2);

    for(sKey in aSelectedDate[sDate])
    {
      var iDay = aSelectedDate[sDate][sKey];
      sReturn += iMonth + "/"+ iDay  + "/" + iYear + ",";
    }
  }

  return sReturn.substr(0, sReturn.length-1);
}

var ChooseDate = function(type, aArgs, oObject)
{ 
  aDate = new Date(this._toDate(aArgs[0][0]));
  sDate = aDate.getFullYear() + '-' + (aDate.getMonth() + 1 < 10 ? "0" : "") + Number(aDate.getMonth() + 1);
  if (typeof(aSelectedDate[sDate]) != "undefined")
  {
    for(i in aSelectedDate[sDate])
    {
      if (aDate.getDate() == aSelectedDate[sDate][i])
      {
        window.location.href = "/" + sLang + "/date/" + sDate + "-" + (aDate.getDate() < 10 ? "0" : "") + aDate.getDate() + ".html";
      }
    }
  }
}; 

function trim(myString) 
{ 
  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'') 
}

function CheckUserForm()
{
  if (typeof(document.forms["loginf"]) != "undefined")
  {
    //Vérification du formulaire
    oForm = document.forms["loginf"];
    if (trim(oForm.login.value) == "")
    {
      alert(sErrorText['no_login']);
      oForm.login.focus();
      return false;
    }
    if (trim(oForm.password.value) == "")
    {
      alert(sErrorText['no_password']);
      oForm.password.focus();
      return false;
    }
    return true;
  }
}

var ShowComment = function()
{
  oForm = YAHOO.util.Dom.get("formaddcomment");
  oForm.style.display = oForm.style.display == "block" ? "none" : "block";
}
