Witam, przerobiłem troszeczkę pewien skrypt kalendarza. Jest to skrypt, który generuje kalendarz na aktualny miesiąc

[JAVASCRIPT] pobierz, plaintext
  1. var now = new Date;
  2. var MyMonth = new Array("Styczeń", "Luty", "Marzec", "Kwiecień", "Maj",
  3. "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik",
  4. "Listopad", "Grudzień");
  5. var MyYear = now.getFullYear();
  6. var Days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  7. var DaysinWeek = 7;
  8. var Today = now.getDate();
  9. var ThisMonth = now.getMonth();
  10. var MonthStart = now.setDate(1);
  11. var AddDays = now.getDate();
  12. var DayofWeek = now.getDay();
  13. var DaysinMonth = Days[now.getMonth()];
  14.  
  15. function CreateCurrMonth(TableBG,CellBG){
  16. // Checks Leap Year
  17. if ((((MyYear % 4)==0) && ((MyYear % 100)!=0) || ((MyYear % 400)==0)) && (DaysinMonth == 28)) {
  18. DaysinMonth = 29;
  19. }else{
  20. DaysinMonth = Days[now.getMonth()];
  21. }
  22.  
  23. document.write ("<table><caption>" + MyMonth[now.getMonth()] + " " + now.getFullYear() + "</caption>");
  24.  
  25. document.write ("<tr>");
  26.  
  27. // Build rows in a month
  28. for (i = 0; AddDays < DaysinMonth + 1; i++){
  29. if (i < DayofWeek){
  30. document.write ("<td></td>");
  31. } else {
  32. if ((AddDays == Today) && (now.getMonth() == ThisMonth)){
  33. document.write ("<td><a href=\"index.php\" class=\"current\">" + AddDays + "</a></td>");
  34. AddDays = AddDays + 1
  35. } else {
  36. if ((i % 7) == 0){
  37. document.write ("</tr>");
  38. document.write ("<tr>");
  39. }
  40. if((i % 7) == 0) {
  41. document.write ("<td><a href=\"index.php\" class=\"sunday\">" + AddDays + "</a></td>");
  42. } else {
  43. document.write ("<td><a href=\"index.php\">" + AddDays + "</a></td>");
  44. }
  45. AddDays = AddDays + 1
  46. }
  47. }
  48. }
  49.  
  50. document.write ("</tr></table>");
  51.  
  52. }
  53.  
  54. function AddCalendar(addmonth,TableBG,CellBG){
  55.  
  56. var NewMonth = ThisMonth + addmonth
  57.  
  58. if (NewMonth > 11){
  59. NewMonth=(NewMonth-12);
  60. now.setYear(MyYear + 1);
  61. }
  62.  
  63. now.setMonth(NewMonth);
  64.  
  65. DayofWeek = now.getDay();
  66. AddDays = now.getDate();
  67. DaysinMonth = Days[now.getMonth()];
  68.  
  69. CreateCurrMonth(TableBG,CellBG);
  70.  
  71. }
[JAVASCRIPT] pobierz, plaintext


Skrypt jest generalnie bardzo prosty, ale nie mogę sobie poradzić z przestawieniem go tak, aby to niedziele były na końcu. Próbowałem kombinować, aby pętla for zaczynała się od i=1, ew. zmienną DayofWeek ustawiać na now.getDay()+1;

Czy ktoś ma pomysł w jaki sposób to zrobić?

Z góry dzięki.