<!--

// Define Constants:

//		var 	SUN = 0, MON = 1, TUES = 2, WED = 3, THUR = 4, FRI = 5, SAT = 6; 
// 		already defined by HebrewCalendarFunctions.js

//		var JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=12;  
		// already defined in HebrewCalendarFunctions.js

// 		gregorianMonthArray() is already defined in the Standard Template for web pages. 
 

		var 	ONEDAY = 86400000 ;  // 1000 * 60 * 60 * 24  = one day, in milliseconds; used in this file and elsewhere
		
		// var     ONEHOUR = 3600000 ;  // 1000 * 60 * 60 = one hour, in milliseconds; not used in this file, nor elsewhere
		

//=====================================================================================================		
// Candlelighting times for Brookline Massachusetts.  All times are without DST. 
// Format is:  hour*100+minutes.  That is, 623 stands for 6:23 pm.   	
// Non-existent dates take 999.

// This data may also be used to calculate other z'manim.   
 		  
var janTimes = new thirtyoneArray(405,406,407,408,409,410,411,412,413,414,415,417,418,419,420,421,422,424,425,426,427,428,429,431,432,433,435,436,437,438,440) ;

var febTimes = new thirtyoneArray(441,442,444,445,446,448,449,450,451,453,454,455,456,458,459,500,502,503,504,505,507,508,509,511,512,513,514,515,517,999,999) ;

var marTimes = new thirtyoneArray(517,518,519,520,521,522,524,525,526,528,529,530,531,532,534,535,536,537,538,539,540,542,543,544,545,546,547,548,550,551,552) ;

var aprTimes = new thirtyoneArray(553,554,555,556,558,559,600,601,602,603,604,605,606,607,608,609,610,611,612,614,615,616,617,618,619,621,622,623,624,625,999) ;

var mayTimes = new thirtyoneArray(626,627,628,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,655,656) ;

var junTimes = new thirtyoneArray(657,657,658,659,659,700,701,702,702,703,703,704,704,705,705,706,706,706,706,706,706,707,707,707,707,707,707,707,707,707,999) ;

var julTimes = new thirtyoneArray(707,707,706,706,706,706,705,705,705,704,704,703,703,702,701,701,700,659,658,658,657,656,655,654,653,652,651,650,649,648,647) ;

var augTimes = new thirtyoneArray(646,645,643,642,641,639,638,637,636,634,633,632,531,629,628,626,624,622,621,620,618,617,615,614,612,610,609,607,606,604,603) ;

var sepTimes = new thirtyoneArray(601,559,557,556,554,552,551,549,547,546,544,542,540,538,536,534,532,530,528,527,526,524,522,521,519,517,515,513,511,510,999) ;

var octTimes = new thirtyoneArray(507,505,504,502,501,459,458,456,454,453,451,449,448,446,444,442,441,439,438,436,435,433,431,430,428,427,425,424,423,422,421) ;

var novTimes = new thirtyoneArray(419,418,417,416,415,414,413,411,410,409,408,407,406,405,404,403,403,402,401,400,359,359,358,358,357,357,357,356,356,356,999) ;

var decTimes = new thirtyoneArray(355,355,355,355,355,355,354,354,354,354,354,354,355,355,355,356,356,356,357,357,358,358,359,359,400,400,401,402,402,403,404) ;

var timesArray = new gregorianMonthArray(janTimes,febTimes,marTimes,aprTimes,mayTimes,junTimes,julTimes,augTimes,sepTimes,octTimes,novTimes,decTimes) ;


// DST in Massachusetts is from the first Sunday in April to the last Sunday in October.
// getDST() returns 100 if DST applies, otherwise 0.  
function getDST(MMM,DDD,WKDY) 
	{
	// MMM:  Jan=0 to Dec=11;  DDD: 1 to 31;  WKDY: Sun=0 to Sat=6
		var DST = 100 ;
		if ( (MMM < APR)  || (MMM > OCT) )         {DST = 0} ;
		if ( (MMM == APR) && ((DDD - WKDY) <= 0) ) {DST = 0} ;
		if ( (MMM == OCT) && ((DDD - WKDY) > 24) ) {DST = 0} ;
		return DST ;
		// returns 100 if DST, otherwise 0. 
	}
/* 
On August 8, 2005, President George W. Bush signed the Energy Policy Act of 2005. 
This Act changed the time change dates for Daylight Saving Time in the U.S. 
Beginning in 2007, DST will begin on the second Sunday in March 
and end the first Sunday in November. 
The Secretary of Energy will report the impact of this change to Congress. 
Congress retains the right to resume the 2005 Daylight Saving Time schedule 
once the Department of Energy study is complete.
*/
function getDST_EPA2005(MMM,DDD,WKDY) 
	{
	// MMM:  Jan=0 to Dec=11;  DDD: 1 to 31;  WKDY: Sun=0 to Sat=6
		var DST = 100 ;
		if ( (MMM < MAR)  || (MMM > NOV) )         {DST = 0} ;
		if ( (MMM == MAR) && ((DDD - WKDY) <= 7) ) {DST = 0} ;
		if ( (MMM == NOV) && ((DDD - WKDY) > 0) )  {DST = 0} ;
		return DST ;
		// returns 100 if DST, otherwise 0. 
	}
	
function getCandlelighting(MMM,DDD,WKDY,YEAR)    
	{	
	// MMM: 0 to 11.   DDD: 1 to 31.  WKDY: 0 to 6.
		if (YEAR<2007){ candlelighting = timesArray[MMM][DDD-1] + getDST(MMM,DDD,WKDY) ; }
		else { candlelighting = timesArray[MMM][DDD-1] + getDST_EPA2005(MMM,DDD,WKDY) ; }
		return candlelighting ;
	}	

//=====================================================================================================
  
		//Friday services are on the nearest quarter hour to candlelighting
		//or 7:00 pm; whichever is earlier.  
function roundToQuarterHour(TTT)
	{		
		var rounded = (TTT%100)%15 ;
		if (rounded<=7.5) 	{
			rounded = TTT - rounded ;
		} else if (rounded>=7.5)  {
			rounded = TTT + 15 - rounded ; 
			if (rounded%100 == 60) rounded=rounded+40;
		}	
		return rounded ;
	}
		
function sevenOrEarlier(TTT) 
	{		  
		var tested = TTT ;
		if (tested>700) tested=700 ; 
		return tested ;
	}		  
 
function getTimeString(TTT) 
	{
		var minutes = TTT % 100;
		var hours = (TTT - minutes) /100 ;
		if (minutes<10) minutes="0"+minutes ; 
		timeString = hours + ":" + minutes ;
		return timeString; 
	}

var nextFriday = null ;
function getNextFriday() 			// returns today if Friday, yesterday if Saturday, and otherwise the next Friday.  
	{
		// getToday() is defined in Standard Page Template
	 	if(nextFriday == null) { 
	 		nextFriday = new Date(); 
			getToday(); nextFriday.setTime ( today.getTime() ) ; nextFriday.setHours(1) ; 
			nextFriday.setTime( nextFriday.getTime() + ( ( FRI - nextFriday.getDay() )  * ONEDAY ) ); 
		}
		return ; 
	}
var nextSaturday = null ;
function getNextSaturday() 			// returns today if Saturday, otherwise the coming Saturday. 
	{
		// getToday() is defined in Standard Page Template
	 	if(nextSaturday == null) { 
	 		nextSaturday = new Date(); 
			getToday(); nextSaturday.setTime( today.getTime() ) ;  nextSaturday.setHours(1) ; 
			nextSaturday.setTime( nextSaturday.getTime() + ( ( SAT - nextSaturday.getDay() )  * ONEDAY ) ); 
		}
		return ; 
	}	
var nextWednesday = null ;
var firstShabbatAfterNextWed = null ;
function getNextWednesday() 			// returns today if Wednesday, otherwise the coming Wednesday. 
	{
		// getToday() is defined in Standard Page Template
	 	if(nextWednesday == null) { 
	 		nextWednesday = new Date(); 			
			getToday(); nextWednesday.setTime( today.getTime() ) ;  nextWednesday.setHours(1) ; 
			nextWednesday.setTime( nextWednesday.getTime() + ( ( ( (7+WED) - nextWednesday.getDay() )%7 )  * ONEDAY ) ); 
		}
		if(firstShabbatAfterNextWed == null) {
			firstShabbatAfterNextWed = new Date() ; 
			firstShabbatAfterNextWed.setTime( nextWednesday.getTime() + (3 * ONEDAY)  ) ; 
		}
		return ; 
	}
	

/*	
function getNext(TargetDayOfWeek, dateObject)
	{
		var outputDate = new Date() ;  var inputDate = new Date() ;  inputDate = dateObject ;
		var target = 0 ;  target = TargetDayOfWeek ;
		outputDate.setTime( inputDate.getTime() + ((( target+7-inputDate.getDay() )%7) * ONEDAY )  ) ;	
		return tempDate; 	
	}
*/	


var FriNiteService = null ;
var SatNiteService = null ;

function setShabbatServiceTimes()
	{
		if (FriNiteService==null) {
			
			getNextFriday() ;
			FriNiteService = getCandlelighting( nextFriday.getMonth(), nextFriday.getDate(), nextFriday.getDay(), nextFriday.getFullYear() ) ;
			FriNiteService = roundToQuarterHour(FriNiteService) ;
			SatNiteService = FriNiteService - 15 ;
			if ( (SatNiteService%100)>60 ) SatNiteService = SatNiteService -40 ;
			FriNiteService = sevenOrEarlier(FriNiteService) ; 
		}			
		return ; 	
	}
		 
function displayFriNiteServiceTime()
	{
		setShabbatServiceTimes() ;
		var temp = getTimeString(FriNiteService); 
		document.writeln(temp) ;
		return ;
	}
function displaySatNiteServiceTime()
	{
		setShabbatServiceTimes() ;
		var temp = getTimeString(SatNiteService); 
		document.writeln(temp) ;
		return ;
	}
	
function displayNextLighting()  
	{
		getNextFriday();
		TTT = getCandlelighting( nextFriday.getMonth(), nextFriday.getDate(), nextFriday.getDay(), nextFriday.getFullYear() ) ;
		temp=getTimeString(TTT);
		document.writeln(temp) ;
	}
	
		
	
	
/* 
var now = new Date(); 
var weekdayIndex = 0; var dateIndex = 0; var monthIndex = 0;



 	        function getNow()
                 {
                        if(now == null) 
                              now = new Date();
			      weekdayIndex = now.getDay();
				dateIndex = (now.getDate() - 1);
				monthIndex = now.getMonth();
			}
		  
	
	        function displayWeekday(AppendComma)
		  // Pass a 1 to append a comma. 
              {
                      if (AppendComma == 1) {extra = ","} else {extra = ""} ; 
			    getNow();
                      document.writeln(weekdayNameStrings[weekdayIndex] + extra );
              }
		    

             function displayGregorianDate(){
                     getNow();
			   
			
// Determine platform

var strBrowser = navigator.appName;
var strVersion = navigator.appVersion.substring(0,4);
strPlatform ="Win"
if ((navigator.appVersion.indexOf("Mac")> -1)){;strPlatform ="Mac";};

     
//                     if ((strBrowser == 'Netscape') && (strVersion >4.49) ){;
//                          dw=monthNameStrings[today.getMonth()] + " " + today.getDate() + ", " + (today.getYear()+1900);
//                     } else {
//                          dw=monthNameStrings[today.getMonth()] + " " + today.getDate() + ", " + (today.getYear()+1900-1900);
//                     }
//                     if(( navigator.appName.indexOf("Explorer")> -1)&&(strVersion < 4.0) ){
//                          dw=monthNameStrings[today.getMonth()] + " " + today.getDate() + ", " + (today.getYear()+1900);
//                     }
//			   
			   document.writeln( monthNameStrings[monthIndex] + " " + today.getDate() + ", " + today.getFullYear() )
			   // Full Year won't return less than zero in Navigator.  That is, there's no B.C.E. possible.
              }
		
		 



var weekdayNameStrings = new weekdayArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
              function weekdayArray(d0,d1,d2,d3,d4,d5,d6)
              {
              this[0] = d0; this[1] = d1; this[2] = d2; this[3] = d3; this[4] = d4; this[5] = d5; this[6] = d6;
              }
var weekdayAbbrevStrings = new weekdayArray("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var weekdayMinusDayStrings = new weekdayArray("Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur");


var monthNameStrings = new gregorianMonthArray("January","February","March","April","May","June","July","August","September","October","November","December");
 
var monthAbbrevStrings = new gregorianMonthArray("Jan.","Feb.","Mar.","Apr.","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec.");
var month3LetterStrings = new gregorianMonthArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var monthNumberStrings = new gregorianMonthArray("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
var monthTwoDigitStrings = new gregorianMonthArray("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");

var dateStrings = new gregorianDatesArray("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28", "29","30","31");
var dateTwoDigitStrings = new gregorianDatesArray("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28", "29","30","31");

*/

function thirtyoneArray(d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30)
      {
      this[0]  = d0;  this[1]  = d1;  this[2]  = d2;  this[3]  = d3;  this[4]  = d4;  
	this[5]  = d5;  this[6]  = d6;  this[7]  = d7;  this[8]  = d8;  this[9]  = d9;  
	this[10] = d10; this[11] = d11; this[12] = d12; this[13] = d13; this[14] = d14; 
	this[15] = d15; this[16] = d16; this[17] = d17; this[18] = d18; this[19] = d19; 
	this[20] = d20; this[21] = d21; this[22] = d22; this[23] = d23; this[24] = d24; 
	this[25] = d25; this[26] = d26; this[27] = d27; this[28] = d28; this[29] = d29; 
	this[30] = d30; 
      }
	


// -->

