

//                           SABBAT CLOCK
//
//           Created By Norm Vogel.   nvogel1@tampabay.rr.com

//           This Program may NOT be used without permission!
//    
//                             5/5/00  


sabnum = 3;              //   Set Up Initial Values

hemis = "N"

COMM = " "

specEvnt = 0


sabN = new Array( );

sabN[1] = "Imbolc";
sabN[2] = "Ostara";
sabN[3] = "Beltane";
sabN[4] = "Litha";
sabN[5] = "Lughnasadh";
sabN[6] = "Mabon";
sabN[7] = "Samhain";
sabN[8] = "Yule";


sabDT = new Array( );

sabDT[1] = "February 2, ";
sabDT[2] = "March 21, ";
sabDT[3] = "May 1, ";
sabDT[4] = "June 21, ";
sabDT[5] = "August 1, ";
sabDT[6] = "September 21, ";
sabDT[7] = "October 31, ";
sabDT[8] = "December 21, ";


sabJul = new Array( );   // Jul Dates For Each Sabbat

sabJul[1] = 33;
sabJul[2] = 80;
sabJul[3] = 121;
sabJul[4] = 172;
sabJul[5] = 213;
sabJul[6] = 264;
sabJul[7] = 304;
sabJul[8] = 355;


daysMth = new Array ( );   //  Number of Days in Each Month

daysMth[1] = 31;
daysMth[2] = 28;
daysMth[3] = 31;
daysMth[4] = 30;
daysMth[5] = 31;
daysMth[6] = 30;
daysMth[7] = 31;
daysMth[8] = 31;
daysMth[9] = 30;
daysMth[10] = 31;
daysMth[11] = 30;
daysMth[12] = 31;


// =======================================================================


specJul = new Array( );      //  Special Events

specJul[1] = 1           //   1/1
specJul[2] = 21         //   1/21
specJul[3] = 22         //   1/22
 
specJul[4] = 105       //   4/15
specJul[5] = 165       //   6/14
specJul[6] = 245       //   9/2

specJul[7] = 294       //   10/22
specJul[8] = 358       //   12/24
specJul[9] = 359       //   12/25 
specJul[10] = 365     //   12/31 

numSpec = (specJul.length-1)


julDesc = new Array( );

julDesc[1] = " Happy  New  Year  !!! "
julDesc[2] = "  Tomorrow  is  Norm's  Birthday  ! ! !  "
julDesc[3] = " Today:  Norm's  Birthday !  58  !! "

julDesc[4] = " Set Your Sundial!  Sundial time = Wall Clock Time!"  
julDesc[5] = " Set Your Sundial!  Sundial time = Wall Clock Time!" 
julDesc[6] = " Set Your Sundial!  Sundial time = Wall Clock Time!" 

julDesc[7] = " Today:  Jean  &  Norm's 32nd  Wedding  Anniversary !" 
julDesc[8] = " ~  Christmas Eve  ~ "
julDesc[9] = " Merry  Christmas ! "
julDesc[10] = " ~  New  Year's  Eve  ~ "


// =======================================================================


x = new Date();                  //  Get Current Julian Date

x = new Date();
currMth = (x.getMonth());
currMth++

x = new Date();
currDay = (x.getDate());

x = new Date();
currYR = (x.getFullYear());


daysYr = 365;

LY = 0;
if (currYR%4 == 0) {LY = 1} 



JulDt = 0;

I = 0;

for (I = 1; I < currMth; I++)
    {
    JulDt = JulDt + daysMth[I];   
    }

JulDt = JulDt + currDay;


// =======================================================================


daysYr = 365;
if ((JulDt > 59) && (LY == 1))      //  After Imbolc AND a LY
  {
   daysYr++;
   JulDt++  
  }


// =======================================================================


if (LY == 1)                         // Adjust "Special Events" For Leap Year
{
for (I = 3; I <=numSpec; I++)
     {specJul[I]++ } 
}
          


for (I = 1; I <=numSpec; I++)     // Check to see if it's a "Special Event"
     {if (JulDt == specJul[I]) {specEvnt = I}             // Set Flag  
     }

 

// =======================================================================


Yul = 355;                    
if (LY == 1) {Yul++}

if (JulDt > Yul)                              //   After Yule???
   {


daysLft = (daysYr - JulDt)            //  Days Left in Old Year


daysLft++                                  //    To make it accurate.   12/29/04

currYR++

sabNum = 1;                               //  Force "Imbolc"

count = daysLft + 32                  //  Jan 1 to Imbolc


DY = " days "

SD = (" " + sabDT[sabNum] + currYR)
MSG = (" " + count + DY + "Until " + sabN[sabNum])

// ========================================================================
//
//     11 / 2 / 02   This calculates the number of days since YULE 
//                                            IF it's less than 7.


YuleDt = 355

if (LY == 1) {YuleDt++}            //  Add 1 to Yule Julian Date if LY.     12/22/04


aftSab = JulDt - YuleDt            //  aftSab = Today's Julian date - Sab Date (Yule)

if (aftSab <= 10)                        //  Less than 10 days since Yule?
     {
 COMM = "      " + aftSab + "  day(s) since Yule  /  " + daysLft + 
                                   " day(s) left in " + (currYR-1)

 
     }

fillForm();

    }


// =======================================================================


//   Determine which Sabbat is approaching:

nxtSab = 0;

I = 0;
for (I = 1; I <=8; I++)
     {
 
if  ((LY == 1)  && (I  > 1))  {sabJul[I]++}           //      2/3/04    Don't add 1 to JulDt for Imbolc on a Leap Year.

nxtSab = sabJul[I]

if (nxtSab >= JulDt) break;

     }

sabNum = I
  
if (sabNum == 9) {sabNum = 1}

countdown();


// =======================================================================


//  ***  The Actual Calculation:

 
function countdown()
{
count = sabJul[sabNum] - JulDt   // JulDt of Sabbat - Today's JulDt
}


// =======================================================================


COMM = "  "                      //  Equinoxes & Solstices


//  if (sabNum%2 == 0) {COMM = " Date can vary up to 3 days "}
 if (sabNum%2 == 0) {COMM = " Can vary up to 3 days "}

if (count == 0) {isSabbat()}

           else {daysToGo(count)}


// =======================================================================



function isSabbat()              //  IS Sabbat!
{
SD = (" " + sabDT[sabNum] + currYR)
MSG = ("  Happy " + sabN[sabNum] + " !!!") 
HEM = ("(Southern Hemis: " + SH + ")") 
  
}

// =======================================================================  

function daysToGo(count)            
{


DY = " days ";
if (count == 1) {DY = " day "}

SD = (" " + sabDT[sabNum] + currYR)
MSG = (" " + count + DY + "Until " + sabN[sabNum])



if (sabNum == 7)                               //  10/12/07  Samhain approaching
{
COMM= "              ~~  THE  GRAND  SABBAT  ~~"
}

       
if   ((count > 0) && (count <= 4))             //  Less than  4 days until Sab?
     {
     COMM = "                                " + " It's   almost   here    ! ! ! "
     }


if   ((count > 0) && (count == 1))             //  Is it TOMORROW?
     {
     COMM = "                                " + " It's   TOMORROW    ! ! ! "
     }


}


// ========================================================================
//     11  / 2 / 02   This calc's the number of days since the LAST  Sabbat.   
//       9 / 22 / 04           If only 1 day later.


aftSab = JulDt - sabJul[sabNum-1]                //  aftSab =  Today's date - Sab Date
//                                                                              ( How many days after Sabbat )


if    ((aftSab >1) && (aftSab <= 7))              //  Less than 1 week since Sab?
     {
     COMM = "      " + aftSab + "  days since last Sabbat ( " + sabN[sabNum-1] + " )"
     }


if    (aftSab == 1)                                           //  Sabbat was yesterday?
     {
     COMM = "      " + aftSab + "  day since last Sabbat ( " + sabN[sabNum-1] + " )"
     }


// =======================================================================


function fillForm()      //  Insert Values Into HTML Form
{


if (JulDt < 11)                         //  First 10 days of the New Year?   1/5/05
  {
COMM = "                Happy  New  Year  !!! "
  }



HM = 4;                         //  Southern  Hemisphere
if (sabNum >= 5) { HM = -4 }
SH = (sabN[sabNum + HM])
HEM = ("(Southern Hemis: " + SH + ")")


if (specEvnt > 0) {COMM = julDesc[specEvnt]}  // Change to "Special Event"


cl=document.clock;             
cl.SD.value = SD;
cl.info.value = MSG;
cl.hemis.value = HEM;
cl.misc.value = COMM;
return;  

}

