var GIORNI_SPECIALI;

  function resetCalendario(campo,etichetta,def) {
      if(campo && $(campo)) {
          $(campo).value='';
      }
      if(etichetta && $(etichetta)) {
          $(etichetta).value='';
          $(etichetta).innerHTML=def;
      }
  }

  function popolaGiorniSpeciali(anno, mese, giorno) {
    if(!GIORNI_SPECIALI[anno]) {
        GIORNI_SPECIALI[anno] = new Array();
    }
    if(!GIORNI_SPECIALI[anno][mese]) {
        GIORNI_SPECIALI[anno][mese] = new Array(0);
    }
    GIORNI_SPECIALI[anno][mese].push(giorno);
  }

  function dataSpeciale(year, month, day) {
    month += 1;
    if(GIORNI_SPECIALI[year] && GIORNI_SPECIALI[year][month]) { 
        var m = GIORNI_SPECIALI[year][month];
        if (!m) return false;
        for (var i in m) {
            if (m[i] == day) {
                return true;
               }
        }
    }
    return false;
  }
  function dateChanged(calendar) {
    // Beware that this function is called even if the end-user only
    // changed the month/year. In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var y = calendar.date.getFullYear();
      var m = calendar.date.getMonth();    // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
      m++;
      if(m<10) {
          m='0'+m;
      }
      if(d<10) {
          d='0'+d;
      }
      // redirect...
      window.location = "/blog/blog.php/data_" + y + m + d;
    }
  }
  function statoData(date, y, m, d) {
    if (dataSpeciale(y, m, d))
      return "special";
    else
      return false; // other dates are enabled
      // return true if you want to disable other dates
  }
  
  function avviaCalendario() {
    Calendar.setup({
        displayArea    :    "calendar-container",       // ID of the span where the date is to be shown
        daFormat       :    "%A, %B %d, %Y",// format of the displayed date
        align          :    "Tl",           // alignment (defaults to "Bl")
        singleClick    :    true,
          onSelect : dateChanged,          // our callback function
          dateStatusFunc : statoData
        });
  }
  function calendarioServizi(area,campo,data) {
        Calendar.setup({
            inputField     :    campo,
            displayArea    :    area,       // ID of the span where the date is to be shown
            daFormat       :    "%A, %B %d, %Y",// format of the displayed date
            align          :    "Tl",           // alignment (defaults to "Bl")
            singleClick    :    true,
            date           :    data,
            ifFormat       :   "%Y-%m-%d"
        });
        //alert("init "+area+" - "+campo+" - "+data);
      }
  function calendarioGenerico(area,campo,data) {
      log("!"+area+"!"+campo+"!"+data);
      Calendar.setup({
          inputField     :    campo,
          displayArea    :    area,       // ID of the span where the date is to be shown
          daFormat       :    "%Y-%m-%d",// format of the displayed date
          align          :    "Tl",           // alignment (defaults to "Bl")
          singleClick    :    true,
          date           :    data,
          ifFormat       :   "%Y-%m-%d"
      });
      //alert("init "+area+" - "+campo+" - "+data);
    }
  function calendarioInput(area,campo,data) {
      log("!"+area+"!"+campo+"!"+data);
      Calendar.setup({
          inputField     :    campo,
          daFormat       :    "%Y-%m-%d",// format of the displayed date
          align          :    "Tl",           // alignment (defaults to "Bl")
          singleClick    :    true,
          date           :    data,
          ifFormat       :   "%Y-%m-%d"
      });
      //alert("init "+area+" - "+campo+" - "+data);
    }
