function getMonthName(monthNo)
{
var months = new Array(13);
months[0] = "Ianuarie";
months[1] = "Februarie";
months[2] = "Martie";
months[3] = "Aprilie";
months[4] = "Mai";
months[5] = "Iunie";
months[6] = "Iulie";
months[7] = "August";
months[8] = "Septembrie";
months[9] = "Octombrie";
months[10] = "Noiembrie";
months[11] = "Decembrie";
return months[monthNo];
}

function DaysInMonth (year, month) {
     return 32 - new Date(year, month, 32).getDate();
}



function ShowCal(ctlName, spnName){
   if (document.getElementById(spnName).style.display==""){
       document.getElementById(spnName).style.display="none";
   }else{

/*       if (document.getElementById(ctlName).value==""){
           var currDate=new Date();
           WriteCalendarMonth(currDate.getMonth(), currDate.getFullYear(), ctlName, spnName);
       }else{
           var currDate= new Date(document.getElementById(ctlName).value);
           WriteCalendarMonth(currDate.getMonth(), currDate.getFullYear(), ctlName, spnName);
       }
*/
       var currDate=new Date();
       WriteCalendarMonth(currDate.getMonth(), currDate.getFullYear(), ctlName, spnName);
       document.getElementById(spnName).style.display="";
   }
}

function WriteCalendarMonth(monthNo, year, ctlName, spnName)
{

        var currMonth = new Date(year, monthNo, 1);
        if (currMonth.getFullYear()<1900)
                currYear = currMonth.getFullYear() + 1900;
        else
                currYear = currMonth.getFullYear();

        output = "";
        output += "<table cellspacing='1' cellpadding='0' class='calTable'>";
        output += "<tr><td class='calCell'><a href='#' onClick='WriteCalendarMonth(" + (currMonth.getMonth()-12) + ", " + currMonth.getFullYear() + ", \"" + ctlName + "\", \"" + spnName + "\");return false;'><<</a></td>";
        output += "<td class='calCell'><a href='#' onClick='WriteCalendarMonth(" + (currMonth.getMonth()-1) + ", " + currMonth.getFullYear() + ", \"" + ctlName + "\", \"" + spnName + "\");return false;'><</a></td>";
        output += "<td colspan='3' style='text-align:center'>";
        output += getMonthName(currMonth.getMonth()) + ' ' + currYear;
        output += "</td>";
        output += "<td class='calCell'><a href='#' onClick='WriteCalendarMonth(" + (currMonth.getMonth()+1) + ", " + currMonth.getFullYear() + ", \"" + ctlName + "\", \"" + spnName + "\");return false;'>></a></td>";
        output += "<td class='calCell'><a href='#' onClick='WriteCalendarMonth(" + (currMonth.getMonth()+12) + ", " + currMonth.getFullYear() + ", \"" + ctlName + "\", \"" + spnName + "\");return false;'>>></a></td></tr>";


        i=1;
        dayFinished=false;
        weekFinished=false;
        var CurrDow=1;

        while (!dayFinished)
        {
                        if (i<=DaysInMonth(currMonth.getFullYear(), currMonth.getMonth()))
                        {
                                if (i==1 && currMonth.getDay()>CurrDow-1)
                                        output += '<td class="calCell"></td>';
                                else
                                {
                                        if(i<10){j='0'+i;}else{j=i;}
                                        if(currMonth.getMonth()<9){m='0'+(currMonth.getMonth()+1);}
                                        else{m=(currMonth.getMonth()+1);}
                                        output += "<td class='calCell'>";
                                        output += "<a href='#' onclick='document.getElementById(\"" + ctlName + "\").value=\"" + j + "." + m + "." + currYear + "\"; document.getElementById(\"" + spnName + "\").style.display=\"none\"; return false;'>" + i + "</a></td>";
                                        i++;
                                }


                        }
                        else
                        {
                                output += '<td class="calCell"></td>';
                                if (CurrDow%7==0)
                                {

                                        dayFinished=true;
                                }
                                else
                                {
                                        i++;
                                }
                        }

                        if (CurrDow%7==0 && !dayFinished && i>1)
                                output += '</tr><tr>';

                        CurrDow++;

        }
        document.getElementById(spnName).innerHTML=output;

}
