// Calendar library by ArT-iX  
   function setDateToCtrl(data_str, ctrl_id)
   {
    document.getElementById(ctrl_id).value=data_str;
   }
   
   function checkCalendarHoliday(daypos, iday, imonth)
   {

    if(daypos == 7 || daypos == 14 || daypos == 21 || daypos == 28 || daypos==35)
     return true;
    if(imonth==12 && (iday==25 || iday==26 || iday==8)) 
     return true
    if(imonth==1 && iday==1) 
     return true 
    return false; 
   }
   
   function DrawCalendar(objname, imonth, iyear, ctrl_id, is_popup)
   {
    var c1 = document.getElementById(objname);
    if(is_popup)
     c1.style.visibility='visible';
    var strcal = "";
    
    var months = new Array(12);
    var leapYear=false;
    var hide_str = "";
    var popup_str = 'false';
    if(is_popup)
    {
     hide_str = " onmouseup=\"document.getElementById('" + objname + "').style.visibility='hidden';\" ";
     popup_str = 'true';
    }


    months[0] = new Array('Gennaio', 31);
    months[1] = new Array('Febbraio',28);
    months[2] = new Array('Marzo',31);
    months[3] = new Array('Aprile',30);
    months[4] = new Array('Maggio',31);
    months[5] = new Array('Giugno',30);
    months[6] = new Array('Luglio',31);
    months[7] = new Array('Agosto',31);
    months[8] = new Array('Settembre',30);
    months[9] = new Array('Ottobre',31);
    months[10] = new Array('Novembre',30);
    months[11] = new Array('Dicembre',31); 
    
    if ((iyear % 4) == 0) { leapYear=true; }
    if(leapYear)
     months[1][1] = 29;
     
    strcal += "<table width=100% border=0 cellpadding=1 class=calendar_body>";
    strcal += "<tr><td colspan=7 align=center class=calendar_header>";
    
    strcal += "<a class=calendar_header href=\"Javascript:DrawCalendar('" + objname + "', " + (imonth - 1).toString() + ", " + iyear.toString() + ", '" + ctrl_id + "', " + popup_str + ")\">&laquo&nbsp</a>";
    strcal += "<strong>" + months[imonth-1][0] + "</strong>";
    strcal += "<a class=calendar_header href=\"Javascript:DrawCalendar('" + objname + "', " + (imonth + 1).toString() + ", " + iyear.toString() + ", '" + ctrl_id + "', " + popup_str + ")\">&nbsp&raquo</a>";
    
    strcal += "&nbsp&nbsp";
    
    strcal += "<a class=calendar_header href=\"Javascript:DrawCalendar('" + objname + "', " + (imonth).toString() + ", " + (iyear - 1).toString() + ", '" + ctrl_id + "', " + popup_str + ")\">&laquo&nbsp</a>";
    strcal += "<strong>" + iyear.toString() + "</strong> ";
    strcal += "<a class=calendar_header href=\"Javascript:DrawCalendar('" + objname + "', " + (imonth).toString() + ", " + (iyear + 1).toString() + ", '" + ctrl_id + "', " + popup_str + ")\">&nbsp&raquo</a>";
    
    strcal += "</td></tr>";
    strcal += "<tr><td>Lu</td><td>Ma</td><td>Me</td><td>Gi</td><td>Ve</td><td>Sa</td><td><font color=red>Do</font></td></tr>";
    strcal += "<tr>";
    var i;
    var fd = new Date();
    fd.setYear(iyear);
    fd.setMonth(imonth - 1);
    fd.setDate(1);
    var fdw = fd.getDay();
    //alert(fdw.toString());
    //nulldays = 7 - fdw;
    
    if(fdw == 0)
     fdw=7;
     
    var nd;
    for(nd=0;nd < (fdw - 1); nd++)
      strcal += "<td></td>" ;
     
    
    for(i=1;i<=months[imonth-1][1]; i++)
    {
     //var d = new Date();
   
     var dm = fdw + (i-1);
     if(dm == 8 || dm == 15 || dm == 22 || dm == 29 || dm==36)
      strcal += "</tr><tr>";
     var smonth = (imonth.toString().length == 1)?'0' + imonth.toString():imonth.toString();
     var sday =  (i.toString().length == 1)?'0' + i.toString():i.toString();
     dtstr=iyear.toString() + '-' + smonth + '-' + sday;
     //dtstr = 
     var fred= (checkCalendarHoliday(dm, i, imonth))?"<font color=red>":"";
     var fred2 = (checkCalendarHoliday(dm, i, imonth))?"</font>":"";
     strcal += "<td><a class=calendar_daylink href=\"Javascript:setDateToCtrl('" + dtstr + "', '" + ctrl_id + "')\" " + hide_str + ">" + fred + i.toString() + fred2 +  "</a></td>";
    }
    
    strcal += "</tr></table>";
    c1.innerHTML = strcal;
   }

