<!-- hide code from other browsers
/*
 * Today's Hebrew Date
 * (c) Copyright 1996: Right to Left Software
 *
 * Reference: Understanding The Jewish Calendar / Rabbi Nathan Bushwick
 */
var HebrewLeapYears = "0010010100100100101";
var Version = 1.00;

function IsHebrewLeapYear(year)
{
	var y = (year - 1) % 19;
	return parseInt(HebrewLeapYears.charAt(y));
}

function InitHebrewMonthsNames(isleap)
{
	this.length = (isleap) ? 13 : 12;
	this[0] = "Tishrei";
	this[1] = "Cheshvan";
	this[2] = "Kislev";
	this[3] = "Tevet";
	this[4] = "Shvat";
	this[5] = "Adar";

	var incr = 0;

	if (isleap) {
		this[5] = "Adar1";
		this[6] = "Adar2";
		incr = 1;
	}

	this[6+incr] = "Nisan";
	this[7+incr] = "Iyyar";
	this[8+incr] = "Sivan";
	this[9+incr] = "Tamuz";
	this[10+incr] = "Av";
	this[11+incr] = "Elul";
}

var HebrewMonthsNames = new InitHebrewMonthsNames(false);
var HebrewMonthsNamesLeap = new InitHebrewMonthsNames(true);

function InitGlobalTable()
{
	this.length = 2001;
	this[1980] = "11S0";
	this[1981] = "29S2";
	this[1982] = "18S3";
	this[1983] = "08S3";
	this[1984] = "27S2";
	this[1985] = "16S0";
	this[1986] = "04O3";
	this[1987] = "24S2";
	this[1988] = "12S0";
	this[1989] = "30S3";
	this[1990] = "20S2";
	this[1991] = "09S3";
	this[1992] = "28S0";
	this[1993] = "16S3";
	this[1994] = "06S2";
	this[1995] = "25S3";
	this[1996] = "14S0";
	this[1997] = "02O2";
	this[1998] = "21S3";
	this[1999] = "11S3";
	this[2000] = "30S0";
	this[2001] = "18S2";
	this[2002] = "07S3";
	this[2003] = "27S3";
	this[2004] = "16S0";
	this[2005] = "04O2";
	this[2006] = "23S3";
	this[2007] = "13S0";
	this[2008] = "30S2";
	this[2009] = "19S3";
	this[2010] = "09S3";
	this[2011] = "29S2";
	this[2012] = "17S0";
	this[2013] = "05S3";
	this[2014] = "25S2";
	this[2015] = "14S3";
	this[2016] = "03O0";
	this[2017] = "21S2";
	this[2018] = "10S3";
	this[2019] = "30S3";
	this[2020] = "19S0";
}

var GlobalTable = new InitGlobalTable();
/*
 * Convert Julian year to Hebrew year
 */

function JulianYearToHebrew(/* int */ year)
{
	return year + 3760;
}

function HebrewToJulianYear(/* int */ year)
{
	return year - 3760;
}
/*
 * Year length in days
 * indexed by the year type, given in GlobalTable
 */
function InitYearLength(isleap)
{
	this.length = 4;

	if (isleap) {
		this[0] = 383;
		//this[1] = ; error
		this[2] = 384;
		this[3] = 385;
	} else {
		this[0] = 353;
		//this[1] = ; error
		this[2] = 354;
		this[3] = 355;
	}
}

var HebrewYearLengthLeap = new InitYearLength(true);
var HebrewYearLength = new InitYearLength(false);
var Tishrei = 0;
var Cheshvan = 1;
var Kislev = 2;
var Adar1 = 5;
var Adar2 = 6;
var HebMonths30 =     "1010101010101";
var HebMonths30Leap = "10101011010101";

function DaysInHebrewFixedMonth(month, year)
{
	var incr;
	if (IsHebrewLeapYear(year))
		incr = parseInt(HebMonths30Leap.charAt(month));
	else
		incr = parseInt(HebMonths30.charAt(month));
	return 29 + incr; // 29 or 30
}

function DaysInCheshvan(hebyear)
{
	var ytype = GlobalTable[HebrewToJulianYear(hebyear)-1].charAt(3);
	if (ytype == 3)
		return 30;
	else
		return 29;
}

function DaysInKislev(hebyear)
{
	var ytype = GlobalTable[HebrewToJulianYear(hebyear)-1].charAt(3);
	if (ytype == 0)
		return 29;
	else
		return 30;
}

function DaysInHebrewMonth(month, year)
{
	if (month == Cheshvan)
		return DaysInCheshvan(year);
	else if (month == Kislev)
		return DaysInKislev(year);
	else
		return DaysInHebrewFixedMonth(month, year);
}

function DaysInHebrewYear(year)
{
	var ytype = GlobalTable[year].charAt(3);
	if (IsHebrewLeapYear(year)) {
		return HebrewYearLengthLeap[ytype];
	} else {
		return HebrewYearLength[ytype];
	}
}

var MsecPerDay = 1000*3600*24;  // miliseconds per day
/*
 * Add days to a Julian date
 */
function	AddDays(
	/* date */ date,
	/* int */  days)
{
	var time = date.getTime();

	time += days*MsecPerDay;

	date.setTime(time);



	return date;

}





/*

 * given a Julian date of a holiday (e.g. rosh hashana),

 * returns the date that the same holiday occurred in the year 'toyear'

 */

function SameHolidayInJulianYear(

	/* date */ rosh_shana,

	/* int */  toyear)

{

	var fromyear = rosh_shana.getFullYear() + 1900;

	var incr = 1; // increment fromyear



	if (fromyear == toyear)

		return rosh_shana;

	else if (fromyear > toyear)

		incr = -1; // decrement from_year



	var days;

	for (days = 0 ; fromyear != toyear ; fromyear += incr) {
		days += DaysInHebrewYear(JulianYearToHebrew(fromyear));

	}

	AddDays(rosh_shana, incr*days);

	return rosh_shana;

}

// returns date when Rosh Hashana occurs on this year
function GetRoshHashana(/* int */ cvyear)
{
	var month;
	var day;
	var yearstr = GlobalTable[cvyear];
	var m = yearstr.charAt(2);
	month = 8; // usually September
	if (m == 'O')
		month = 9; // sometimes October
	day = parseInt(yearstr.charAt(0))*10 + parseInt(yearstr.charAt(1));
	return new Date(cvyear, month, day);
}

/*
 * The following functions are methods for
 * HebrewDate object
 */

// is last month of the year?
function IsHebLastMonth()
{
	if (this.month == 11 && !IsHebrewLeapYear(this.year))
		return true;

if (this.month == 12 && IsHebrewLeapYear(this.year))
		return true;

	return false;
}

// go to next Hebrew month
function HebNextMonth()
{
	if (this.IsLastMonth()) {
		this.year++;
		this.month = 0;
	} else
		this.month++;
	this.DaysInThisMonth = DaysInHebrewMonth(this.month, this.year);
}

// next Hebrew day
function HebNextDay()
{
	this.day++;
	if (this.day > this.DaysInThisMonth) {
		this.day = 1;
		this.NextMonth();
	}
}

// add days to Hebrew date
function HebAddDays(days)
{
	while (days > 0) {
		if (this.day == 1 && days >= this.DaysInThisMonth) {
			days -= this.DaysInThisMonth;
			this.NextMonth();
		} else {
			days--;
			this.NextDay();
		}
	}
//document.write("Current date: " + this.day + ", " + this.month + ", " + this.year + "<br>");
}


// print Hebrew date
function HebPrint()
{
	var ThisMonthName = (IsHebrewLeapYear(this.year)) ?
											HebrewMonthsNamesLeap[this.month] :
											HebrewMonthsNames[this.month];
	document.write("" + this.day + "&nbsp;" + ThisMonthName + "&nbsp;" + this.year);
}


// the following functions are for printing the date in Hebrew
function HebPrintHebrewString()
{
	if (this.length == 1)
		document.write('<img src="ssquote.gif">');

	for (var i = this.length-1 ; i >= 0 ; i--) {
		var s = ""; // ot sofit

		if (i == this.length-1 && i > 0 &&
			 (this[i] == 20 || this[i] == 40 ||
			  this[i] == 50 || this[i] == 80 || this[i] == 90)) {
			s = "s";
		}

		document.write('<img src="s' + this[i] + s + '.gif">');
		if (i > 0 && i == this.length - 1)
			document.write('<img src="sdquote.gif">');
	}
}



// constructor function for Hebrew string object
function IntegerToHebrewString(num)
{
	var len = 0;

	while (num > 0) {
		var incr = 100;
		var i;

		if (num == 15 || num == 16) {
			this[len++] = 9;
			this[len++] = num - 9;
			break;
		}

		for (i = 400 ; i > num ; i -= incr) { // tav to aleph
			if (i == incr)
				incr = incr / 10;
		}

		this[len++] = i;
		num -= i;
	}

	this.length = len;

	// print method
	this.Print = HebPrintHebrewString;
}


// print date in Hebrew
function HebPrintHebrew()
{
	var HebYear = new IntegerToHebrewString(this.year - 5000);
	HebYear.Print();
	document.write('<img src="sspace.gif">');

	var ThisMonthName = (IsHebrewLeapYear(this.year)) ?
										HebrewMonthsNamesLeap[this.month] :
										HebrewMonthsNames[this.month];
	ThisMonthName = ThisMonthName.toLowerCase();


	document.write('<img src="s_' + ThisMonthName + '.gif">');
	document.write('<img src="sspace.gif">');

	var HebDay = new IntegerToHebrewString(this.day);
	HebDay.Print();
}

// constructor for HebrewDate object
function InitHebrewDate(day, month, year)
{
	// fields
	this.day = day;
	this.month = month;
	this.year = year;

	this.DaysInThisMonth = DaysInHebrewMonth(month, year);

	// methods
	this.IsLastMonth = IsHebLastMonth;
	this.NextMonth = HebNextMonth;
	this.NextDay = HebNextDay;
	this.AddDays = HebAddDays;
	this.Print = HebPrint;
	this.PrintHebrew = HebPrintHebrew;
}

// end of HebrewDate object definition

var Today = new Date();

function ShowHebrewDate(date)

{

	//var MyRoshHashana = new Date(99, 8, 11); // sep 11, 1999

	var PrevYear = date.getFullYear() - 1;

	var PrevRoshHashana = GetRoshHashana(PrevYear);

	var DiffDays = Math.floor((date.getTime() - PrevRoshHashana.getTime()) / MsecPerDay);

	var HebrewYear = JulianYearToHebrew(PrevYear);

	var HebrewDate = new InitHebrewDate(1, 0, HebrewYear+1); // 1, Tishrei, year

	HebrewDate.AddDays(DiffDays);


   // date in English
	document.fgColor = "#08399c";
	HebrewDate.Print();

}

function OldShowHebrewDate(date)
{
/*
	if (date == Today)
		document.write('<center><img src="moondate.gif" width=390 height=93
				alt="Today\'s Hebrew Date"></center>');
	else
		document.write("<center><h3>" + date + "</h3></center>");
*/



//	var MyRoshHashana = new Date(96, 8, 14); // sep 14, 1996
//	var MyRoshHashana = new Date(97, 9, 2); // oct 2, 1997
//	var MyRoshHashana = new Date(99, 8, 11); // sep 11, 1999

	var PrevYear = date.getYear() - 1 + 1900;
	var PrevRoshHashana = SameHolidayInJulianYear(MyRoshHashana, PrevYear);

	var DiffDays = Math.floor((date.getTime() - PrevRoshHashana.getTime()) / MsecPerDay);

	var HebrewYear = JulianYearToHebrew(PrevYear);
	var HebrewDate = new InitHebrewDate(1, 0, HebrewYear+1); // 1, Tishrei, year
	HebrewDate.AddDays(DiffDays);


	document.write("<table><tr>");
	document.write("<td>");

   // date in English
	document.fgColor = "#08399c";
	document.write("<font size=+1>");
	HebrewDate.Print();
	document.write("</font>");

	document.write("</td><td>");

	// link
	document.write('<a href="today.html" target=_top>');
   	document.write('<img align=middle src="sdateicon.gif" width=170 height=38 border=0></a>');

	document.write("</td><td align=right>");

   // date in Hebrew
	HebrewDate.PrintHebrew();



	document.write("</td></tr></table>");

	//document.write('<a href="include.html" target=_top>');
        //document.write("<font size=-2>how to include today's date in your home page</font></a>");
	document.write('<a href="today.html" target=_top>');
	document.write("<font size=-2>more Hebrew dates: </font></a>");

}

document.bgColor = "#FFFFFF";
document.fgColor = "#08399c";
ShowHebrewDate(Today);
document.fgColor = "#000000";

// end hiding -->
