<!--

sayCal();

function getMonthName(month) {
   var mah_name = new Array(13);
   mah_name[0]="NULL";
   mah_name[1]="Farwardin";
   mah_name[2]="Ardwahisht";
   mah_name[3]="Hordad";
   mah_name[4]="Tir/Tishtar";
   mah_name[5]="Amurdad";
   mah_name[6]="Shahrewar";
   mah_name[7]="Mihr";
   mah_name[8]="Aban";
   mah_name[9]="Adar";
   mah_name[10]="Day";
   mah_name[11]="Vohuman";
   mah_name[12]="Spandarmad";
   return mah_name[month]
}

function getDayName(day){
  var ruz_name = new Array(31);
   ruz_name[0]="";
   ruz_name[1]="Ohrmazd";
   ruz_name[2]="Vohuman";
   ruz_name[3]="Ardwahisht";
   ruz_name[4]="Shahrewar";
   ruz_name[5]="Spandarmad";
   ruz_name[6]="Hordad";
   ruz_name[7]="Amurdad";
   ruz_name[8]="Day-pa-Adar";
   ruz_name[9]="Adar";
   ruz_name[10]="Aban";
   ruz_name[11]="Khwarshed";
   ruz_name[12]="Mah";
   ruz_name[13]="Tir/Tishtar";
   ruz_name[14]="Gosh";
   ruz_name[15]="Day-pa-Mihr";
   ruz_name[16]="Mihr";
   ruz_name[17]="Srosh";
   ruz_name[18]="Rashnu";
   ruz_name[19]="Farwardin";
   ruz_name[20]="Warharan";
   ruz_name[21]="Ram";
   ruz_name[22]="Gowad";
   ruz_name[23]="Day-pa-Den";
   ruz_name[24]="Den";
   ruz_name[25]="Ard/Ashi";
   ruz_name[26]="Ashtad";
   ruz_name[27]="Asman";
   ruz_name[28]="Zam";
   ruz_name[29]="Mahraspand";
   ruz_name[30]="Anagran";
   return ruz_name[day];
}

function getGathaName(day){
   var gatha_name = new Array(6);
   gatha_name[0]="Ahunawad";
   gatha_name[1]="Ushtawad";
   gatha_name[2]="Spentomad";
   gatha_name[3]="Wohukhshathra";
   gatha_name[4]="Wahishtoisht";
   return gatha_name[day];
}

function getSpecialDayMessage(day_of_year) {
  var message=""
    if (day_of_year==1)
      message+="It is Noruz."; // Noruz, March 21
    else if (day_of_year==3)
      message+="Rapithwin starts today.";
    else if (day_of_year==6)
      message+="It is Khordad sal. Today we celebrate Zarathushtra's birthday.";
    else if (day_of_year==13)
      message+="It is Sezdeh Bedar. It is traditional to go out for a picnic on this day, and throw the Sabzi in a stream.";
    else if (day_of_year==19)
      message+="It is the Jashan of the Fravashis.";
    else if (day_of_year==33)
      message+="It is the Jashan of the Ardwahisht.";
    else if (day_of_year==41)
      message+="It is the Gahambar of Maidhyozarem.";
    else if (day_of_year==66)
      message+="It is the Jashan of Hordad."; // 
    else if (day_of_year==101)
      message+="It is the Gahambar of Maidyoshem."; // Jun 29
    else if (day_of_year==103)
      message+="It is the Jashan of Tiragan."; // July 1
    else if (day_of_year==127)
      message+="It is the Jashan of Amurdad.";
    else if (day_of_year==154)
      message+="It is the Jashan of Shahrewar.";
    else if (day_of_year==176)
      message+="It is the Gahambar of Paitishem."; // 150+26, Sep 12
    else if (day_of_year==196)
      message+="It is the Jashan of Mihragan."; // 6*30 + 16, Oct 2
    else if (day_of_year==206)
      message+="It is the Gahambar of Ayathrima."; // Oct 12
    else if (day_of_year==210)
      message+="It is the last day of Rapithwin.";
    else if (day_of_year==220)
      message+="It is the Jashan of Abanagan."; // Oct 26 = 7*30 + 10
    else if (day_of_year==249)
      message+="It is the Jashan of Adargan."; // Nov 24 = 8*30+9
    else if (day_of_year==266)                // December 11
      message+="It is the Jashan of Sadeh (Kermani tradition).";
    else if (day_of_year==271)
      message+="It is the first Jashan of Dadvah (the Creator)."; // 9*30 +1
    else if (day_of_year==276) // December 21
      message+="It is the winter solstice.";
    else if (day_of_year==278)
      message+="It is the second Jashan of Dadvah (the Creator)."; // 9*30 +8
    else if (day_of_year==280)
      message+="Merry Christmas!";
    else if (day_of_year==281)
      message+="It is the death anniversary of Zarathushtra (Zartosht No Diso)."; // 9*30 +11, Dec 26
    else if (day_of_year==285)
      message+="It is the third Jashan of Dadvah (the Creator)."; // 9*30 +15
    else if (day_of_year==286)
      message+="It is the Gahambar of Maidyairem."; // 9*30 +16
    else if (day_of_year==293)
      message+="It is the fourth Jashan of Dadvah (the Creator)."; // 9*30 +23
    else if (day_of_year==302)
      message+="It is the Jashan of Vohuman."; // 10*30 +2
    else if (day_of_year==310)
      message+="It is the Jashan of Sadeh (Yazdi tradition)."; // 10*30 +10 = Jan 24
    else if (day_of_year==335)
      message+="It is the Jashan of Spandarmad."; // 11*30 +5
   return message;
}

function sayCal() {
   var today = new Date();
   var year  = today.getYear();
   var month = today.getMonth();
   //var noRuz = new Date("March 21, 1999");
   var noRuz = new Date("March 21, 2004");
   var msPerDay = 24*60*60*1000; // milliseconds per day
   var day_of_year = Math.floor((1+((today.getTime() - noRuz.getTime()) / msPerDay)) % 365);
   //var day_of_year = Math.floor((1+((today.getTime() - noRuz.getTime()) / msPerDay)));
   if (day_of_year==0) day_of_year=365
   var message = "and day " + day_of_year + " of the holy year:";
   if (day_of_year==366) {
      message+= " it is the intercalculatory day (Roz-e Wahizag), ";
   } else if (day_of_year>360) {
      message+= " it is the "+getGathaName(day_of_year-361)+" Gatha day, ";
   } else {
      var mah = Math.floor((day_of_year-1) / 30) + 1;
      var ruz = day_of_year + 30 - mah*30;
      message += " month "+getMonthName(mah)+", day "+getDayName(ruz)+", ";
   }

// if the day is more than March, 21.  getmonth() returns 0-11, not 1-12
dia = today.getDate();
    if (year <2000) {
     year = year + 1900;
    }
    if (month < 2) {
    message+= " year AY " + (year-631) + "";
    } else
    if ((month == 2) && (dia < 21)) { //
    message+= " year AY " + (year-631) + "";
    } else {
    message+= " year AY " + (year-630) + "";
    }

   document.writeln("");
   document.writeln(message);
   document.writeln(getSpecialDayMessage(day_of_year));
   document.writeln("(Zoroastrian).");
}
//-->
