//*******************************************************************************************
// scandiaModDate.js
//
// Revised: 10/04/2004
//
// This JavaScript calculates the Scandian file last modified date by getting the real file
// last modified date and using Jake Gibson's Scandian date script to convert the real date
// to the Scandian date. The original Scandian date script is courtesy of Jake Gibson and the
// file modified date portion is courtesy of Jerry Hurtgen Jr. The script may be used free
// for non-commercial purposes. Copyright 2003-04.
//
// 10/03/04--Revised copyright notice to 1513-yy where yy is the current Scandian year.
//
// ******************************************************************************************

// Initialize date array

function MakeArray(arrayLength) {this.length = arrayLength;
  for (var i = 1; i <= arrayLength; i++) this[i] = i-1; return this;}
  // fixing Netscape & others' stupidity re: years before & after 1900
  // Netscape thinks 2003 = year 103, unless doctored thisaway
    function getFullYear(d) {var y=d.getYear();
      if (y < 1000) y += 1900; return y;}

// Get date

function writeDate(m,sep){dateNow = new Date(document.lastModified);
  theDay = new MakeArray(7);
  theDay[0] = "Sunday";
  theDay[1] = "Monday";
  theDay[2] = "Tuesday";
  theDay[3] = "Wednesday";
  theDay[4] = "Thursday";
  theDay[5] = "Friday";
  theDay[6] = "Saturday";
  theMonth = new MakeArray(12);
  theMonth[0] = "Jan";
  theMonth[1] = "Feb";
  theMonth[2] = "Mar";
  theMonth[3] = "Apr";
  theMonth[4] = "May";
  theMonth[5] = "Jun";
  theMonth[6] = "Jul";
  theMonth[7] = "Aug";
  theMonth[8] = "Sep";
  theMonth[9] = "Oct";
  theMonth[10] = "Nov";
  theMonth[11] = "Decr";
  whichDay = theDay[dateNow.getDay()];
  //whichMonth = theMonth[dateNow.getMonth()];
  whichMonth = dateNow.getMonth();
  whichDate = dateNow.getDate();
  whichYear = getFullYear(dateNow);
  week = 1;
  //End of Month Calculations
  monarr = new MakeArray(12);
  monarr[0] = 31;
  monarr[1] = 28;
  monarr[2] = 31;
  monarr[3] = 30;
  monarr[4] = 31;
  monarr[5] = 30;
  monarr[6] = 31;
  monarr[7] = 31;
  monarr[8] = 30;
  monarr[9] = 31;
  monarr[10] = 30;
  monarr[11] = 31;
  //Check for leap year
  if (((whichYear % 4 == 0) && (whichYear % 100 != 0)) || (whichYear % 400 == 0)) monarr[1] = 29;
  day = dateNow.getDay();
  date = whichDate;
  month = whichMonth;
  year = whichYear;
  //Counts back to First Day of Year 2001
  // ... gets weeks since 1 Jan 2001
  yearDelta = year - 2001;
  week = 1;
  iDay = day;
  while (year > 2000) {iDay = iDay - 1;
    date = date - 1;
    if (iDay < 0) {iDay = iDay + 7; week = week + 1;}
    if (date < 1) {month = month - 1;
      if (month < 0) {month = 11;year = year - 1;}
    date = monarr[month];}
    }
  // we're going to call sunday the last day of the week
  if (day == 0) week = --week;
  // now earth years into scandian years
  sYear = 1504;
  sMonth = 2;
  iWeek = week;
  // Jan 1 2001 was April 1504
  while (iWeek != 0) {iWeek = iWeek - 1;sMonth = sMonth + 1;
    if (sMonth == 12) {sMonth = 0;sYear = sYear + 1;}
    }
  iHour = dateNow.getHours();
  dateAdd = 0;
  sDate = 1;
  // saturdays and sundays get 5 scandian days
  if (day == 0) {while (iHour > 4) {iHour = iHour - 5;dateAdd = dateAdd + 1;}sDate = 26 + dateAdd;}
  if (day == 6) {while (iHour > 4) {iHour = iHour - 5;dateAdd = dateAdd + 1;}sDate = 21 + dateAdd;}
  // weekdays just get 4 scandian days
  if (day > 0 && day < 6) {while (iHour > 5) {iHour = iHour - 6;dateAdd = dateAdd + 1;}
    sDate = sDate = (((day - 1) * 4) + 1) + dateAdd;}
  // yep - all months = 30 days
  // command decision : Scandian 1 Apr 1504 (1 Jan 2001) was a Scandian Sunday.
  sDaysSince = (((sYear - 1504) * 360) - 90) + (sMonth * 30) + sDate;
         sDay = (sDaysSince - 1) % 7;
  // another command decision : Scandian 1 Apr 1504 (1 Jan 2001) was a new moon
  // or 0 on a scale of 0-28; lunar month is exactly 29 scandian days
  sLunarPhase = (sDaysSince - 1) % 29;
  sDisplayMonth = sMonth + 1;
  sCharYear = sYear + " ";

  sDispDate=sDate;
  if(sDispDate < 10) {sDispDate = "0" + sDispDate}

  if (m==0) document.writeln(" " + theDay[sDay] + " " + theMonth[sMonth] + " " + sDate + ", " + sYear);
  if (m==1) document.writeln(sDisplayMonth + sep + sDate + sep + sCharYear.substring(2,4));
  if (m==2) document.writeln(sDate + sep + sDisplayMonth + sep + sCharYear.substring(2,4));
  if (m==3) document.writeln(sDisplayMonth + sep + sDate + sep + sYear);
  if (m==4) document.writeln(sDate + sep + sDisplayMonth + sep + sYear);
  if (m==5) document.writeln(sDay);
  if (m==6) document.writeln(theDay[sDay]);
  if (m==7) document.writeln(sMonth);
  if (m==8) document.writeln(sDisplayMonth);
  if (m==9) document.writeln(theMonth[sMonth]);
  if (m==10) document.writeln(sDate);
  if (m==11) document.writeln(sYear);
  if (m==12) document.writeln(sDaysSince + " " + sLunarPhase);
  if (m==13) document.writeln(sDaysSince + " " + sLunarPhase + " " + 
    "<img width=13 height=13 src=Moon"+sLunarPhase+".gif>");
  if (m==14) document.writeln("Updated " + sDispDate + " " + theMonth[sMonth - 1] + " " + sCharYear.substring(2,4) + 
     " by<BR><A CLASS=nav HREF='mailto:schwerdt1515@yahoo.com'>Schwerdt News Service</A></P>" + 
     "<P CLASS=up>Copyright &copy; 1513-" + sCharYear.substring(2,4) + "<BR>Social Republic of Schwerdt<BR>&nbsp;</P>" +
     "<TABLE COLs=2 WIDTH='100%' CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD WIDTH='65'>" +
     "<P CLASS=up STYLE='Padding: 5px 0px 0px 5px'>Powered by </P></TD><TD ALIGN='left'>" +
     "<A HREF='http://turn.to/ids' TARGET='new'>" +
     "<IMG SRC='../external/ids/ids-shadow.gif' WIDTH='41' HEIGHT='20' BORDER='0' ALT='IDS logo'></A></TD></TR></TABLE>");
  return iDay;}
  writeDate(14,"/");
