function CreateCalendarMini(elementid, month,year)
{
    if (month != 0)
    {
        if (month > 12)
        {
            month = 0;
            year++;
        }
        else if (month < 0)
        {
            month = 11;
            year--;
        }
    }

    // 

    
    // 
    var g_date = new Date();
    var cur_date = new Date();
	
    // today possible only in current month
	if((g_date.getMonth() == month && g_date.getFullYear() == year) || month==null)
    var today = g_date.getDate();

    if (month != null)
    {
        g_date = new Date(year, month, 1);
    }
    
    //       
    var febdays = 28;
    if (g_date.getFullYear() % 4 == 0 && g_date.getFullYear() % 100 != 0 && g_date.getFullYear() % 400 == 0)
    {
        febdays = 29;
    }
    
    //     
    var max_days_of_month = Array("31",febdays ,"31","30","31","30","31","31","30","31","30","31");
    
    //     
    var max_days_current = max_days_of_month[g_date.getMonth()];
    
   
    //  
    var curmonth = g_date.getMonth()+1;
    var curyear = g_date.getFullYear();
    if (curmonth.toString().length != 2 ) { curmonth = "0" + curmonth; }; 

    //  
    var first_day_of_month = new Date(g_date.getFullYear(),g_date.getMonth(), 1).getDay();
    first_day_of_month += 6; if (first_day_of_month > 6) first_day_of_month %= 7;
    
    /*   */

    var element = document.getElementById(elementid);
    
    //  
    var calendar = "<div id=\"calendar_mini-outer\">";
    
    // 
    calendar += "<table id=\"calendar_mini-inner\">";
    
    // 
    calendar += "<tr class=\"hat\">";
    
    calendar += "<td class=\"hat-cell\" colspan=\"7\"><table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>";
    
    calendar += "<td><span onclick=\"CreateCalendarMini('" + elementid + "'," + (g_date.getMonth() - 1) + "," + g_date.getFullYear() + ");\" class=\"arrow\">&lt;</span></td>";
    
    calendar += "<td width=\"100%\"><span class=\"cur-month\">" + months_of_year[g_date.getMonth()] + "</span>";
    
    calendar += "&nbsp;&nbsp;<span class=\"cur-year\">" + g_date.getFullYear() + "</span></td>";
    
    calendar += "<td><span onclick=\"CreateCalendarMini('" + elementid + "'," + (g_date.getMonth() + 1) + "," + g_date.getFullYear() + ");\" class=\"arrow\">&gt;</span></td>";
    
    calendar += "</tr></table></td>";
    
    calendar += "</tr>";
    
    // 
    calendar += "<tr>";
    
    for (var i = 0; i < days_of_week.length; i++)
    {
        calendar += "<th>" + days_of_week[i] + "</th>";
    }
    
    calendar += "</tr><tr class=\"dayslist\">";
    
    // 
    var day = 1;
    
    var number_of_cells = parseInt(max_days_current) + parseInt(first_day_of_month) + 7 - (((parseInt(max_days_current) + parseInt(first_day_of_month))%7)?((parseInt(max_days_current) + parseInt(first_day_of_month))%7):(7));
    for (var i = 1; i <= number_of_cells; i++)
    {
    
        //draw a week line ,   
        if (i % 7 == 1 && i != 1)
        calendar += "</tr><tr class=\"dayslist\">";
        
        //     
        var currentclass = "day";
        var currentaction = "";
        
        //   - 
        if (i % 7 == 6 || i % 7 == 0)
        currentclass = "day weekday";
        
        //   - 
        if (day == today)
        currentclass += " today";
        
        //   -  
        if (events_in_day[day + "." + curmonth + "." + curyear] != null)
        {            
            if(cur_date.getDate()>day)
            when = "past";
            else if(cur_date.getDate()<day)
            when = "future";
            else
            when = "today";
            currentclass += " event";
        }

        if (events_in_day["0" + day + "." + curmonth + "." + curyear] != null)
        {            
            if(cur_date.getDate()>day)
            when = "past";
            else if(cur_date.getDate()<day)
            when = "future";
            else
            when = "today";
            currentclass += " event";
        }


        
        if (i > first_day_of_month && day <= max_days_current)
        {
           if(events_in_day[day + "." + curmonth + "." + curyear])
            {
            calendar += "<td " + currentaction + " class=\"" + currentclass + "\"><a href=\"" + path_to_calendar + "?day=" + day + "&month=" + curmonth + "&year=" + curyear + "\"><b>" + day + "</b><br /><small>(" + events_in_day[day + "." + curmonth + "." + curyear] + ")</small></a></td>";
            }
           else
            if(events_in_day["0" + day + "." + curmonth + "." + curyear])
            {
            calendar += "<td " + currentaction + " class=\"" + currentclass + "\"><a href=\"" + path_to_calendar + "?day=" + day + "&month=" + curmonth + "&year=" + curyear + "\"><b>" + day + "</b><br /><small>(" + events_in_day["0" + day + "." + curmonth + "." + curyear] + ")</small></a></td>";
            }
           else
            calendar += "<td " + currentaction + " class=\"" + currentclass + "\">" + day +"</td>";
           day++;
        }
        else
        {
            calendar += "<td class=\"" + currentclass + "\">&nbsp;</td>";
        }

    }
    
    calendar += "</table>";
    // 
    
    //  
    calendar += "</div>";
    element.innerHTML = calendar;
}


