/* * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                   *
 *               Date String Functions               *
 *                                                   *
 *  These JavaScript functions use the client PC's   *
 *  internal date to generate the Gregorian and      *
 *  Amharic (Ethiopian) calendar dates.  They are    *
 *  returned in the format "Month DD YYYY" and       *
 *  "dd Month YYYY" respectively.                    *
 *                                                   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * */

function MakeArray(n)  {
  this.length = n
  return this
}

monthNames = new MakeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"

function customDateString(oneDate)  {
  var theMonth = monthNames[oneDate.getMonth() + 1]
  var theYear = oneDate.getYear() + 1900
  if (theYear > 3000) {
      theYear -= 1900;
  }
  return theMonth + " " + oneDate.getDate() + ", " + theYear + ""
}    


function  AmharicDateString(oneDate)  {
  var aDay
  var aMonth
  var aYear
  var testDate
  var leapDay = 0
  var modYear = 0
  var gMM = oneDate.getMonth() + 1
  var gDD = oneDate.getDate()
  var gYYYY = oneDate.getYear() + 1900
	 
  if (gYYYY > 3000) {
    gYYYY -= 1900;
  }
	
  testDate = (gMM * 100) + gDD;
	
  if (testDate >= 911) {
    modYear = (gYYYY + 1) % 4;
  }
  else {
    modYear = (gYYYY) % 4;
  }
  if (modYear == 0) {
    leapDay = 1;
  }
  if ((testDate == 911) && (leapDay == 1)) {
    leapDay = 0;
  }
	   
  if ((testDate >= (911 + leapDay)) && (testDate < (1011 + leapDay))) {
    aDay = ((gMM - 9)*30) + gDD - 10;
    aMonth = "Meskerem";
    aYear = gYYYY - 7;
  }
  else if ((testDate >= (1011 + leapDay)) && (testDate < (1110 + leapDay))) {
    aDay = ((gMM - 10)*31) + gDD - 10;
    aMonth = "Tikemet";
    aYear = gYYYY -7;
  }
  else if ((testDate >= (1110 + leapDay)) && (testDate < (1210 + leapDay))) {
    aDay = ((gMM - 11)*30) + gDD - 9;
    aMonth = "Hidar";
    aYear = gYYYY -7;
  }
  else if ((testDate >= (1210 + leapDay)) && (testDate <= 1231)) {
    aDay = ((gMM - 12)*21) + gDD - 9;
    aMonth = "Tahesas";
    aYear = gYYYY -7;
  }
  else if ((testDate >= 101) && (testDate < (109 + leapDay))) {
    aDay = gDD + 22;
    aMonth = "Tahesas";
    aYear = gYYYY -8;
  }
  else if ((testDate >= (109 + leapDay)) && (testDate < (208 + leapDay))) {
    aDay = ((gMM - 1)*31) + gDD - 8;
    aMonth = "Tir";
    aYear = gYYYY -8;
  }
  else if ((testDate >= (208 + leapDay)) && (testDate < 310)) {
    aDay = ((gMM - 2)*(28 + leapDay)) + gDD - 7;
    aMonth = "Yekatit";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 310) && (testDate < 409)) {
    aDay = ((gMM - 3)*31) + gDD - 9;
    aMonth = "Megabit";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 409) && (testDate < 509)) {
    aDay = ((gMM - 4)*30) + gDD - 8;
    aMonth = "Miyaza";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 509) && (testDate < 608)) {
    aDay = ((gMM - 5)*31) + gDD - 8;
    aMonth = "Ginbot";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 608) && (testDate < 708)) {
    aDay = ((gMM - 6)*30) + gDD - 7;
    aMonth = "Sene";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 708) && (testDate < 807)) {
    aDay = ((gMM - 7)*31) + gDD - 7;
    aMonth = "Hamle";
    aYear = gYYYY -8;
  }
  else if ((testDate >= 807) && (testDate < 906)) {
    aDay = ((gMM - 8)*31) + gDD - 6;
    aMonth = "Nehase";
    aYear = gYYYY -8;
  }
  else  {
    aDay = ((gMM - 9)*30) + gDD - 5;
    aMonth = "Pagume";
    aYear = gYYYY -8;
  }

  return aDay + " " + aMonth + " " + aYear + ""
}
