function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}




function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function remove_email()
{

	if(document.frm_name.EMAIL.value == "Enter Email Address")
	{
		document.frm_name.EMAIL.value = "";
		return false;
	}
}

function display_email()
{
	if(document.frm_name.EMAIL.value == "")
	{
		document.frm_name.EMAIL.value = "Enter Email Address";
		return false;
	}
}



//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Please enter Email Address');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}



function simcha_val() {
	if(document.calen_disp.name.value == '' ){
		alert("Please Enter Name")	;
		document.calen_disp.name.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.email.value,1,1))
	{
		document.calen_disp.email.focus();
		return false;
	}
	
	if(document.calen_disp.mazel.value == '' ){
		alert("Please enter (s) for Mazel Tov")	;
		document.calen_disp.mazel.focus();
		return false;
	}
	
	if(document.calen_disp.simchatype.value == '' ){
		alert("Please choose the Type of Simcha")	;
		document.calen_disp.simchatype.focus();
		return false;
	}
	
	if(document.calen_disp.dtDate.value == '' ){
		alert("Please Select Event Date")	;
		document.calen_disp.dtDate.focus();
		return false;
	}
	
	
	if(document.calen_disp.eventdescr.value == '' ){
		alert("Please enter Event Description")	;
		document.calen_disp.eventdescr.focus();
		return false;
	}
	return true;
	
	
}

function wheelemail1_val(a) {
	if(a.yname.value == '' ){
		alert("Please Enter your Name")	;
		a.yname.focus();
		return false;
	}
	if (!validateEmail(a.email.value,1,1))
	{
		a.email.focus();
		return false;
	}
	if(a.frname.value == '' ){
		alert("Please Enter your Friend Name")	;
		a.frname.focus();
		return false;
	}
	if (!validateEmail(a.fremail.value,1,1))
	{
		a.fremail.focus();
		return false;
	}
	return true;
	
	
}

function cal_val() {
	if(document.calen_disp.name.value == '' ){
		alert("Please Enter Name")	;
		document.calen_disp.name.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.email.value,1,1))
	{
		document.calen_disp.email.focus();
		return false;
	}
	if(document.calen_disp.dtDate.value == '' ){
		alert("Please Select Event Date")	;
		document.calen_disp.dtDate.focus();
		return false;
	}
	
	if(document.calen_disp.eventname.value == '' ){
		alert("Please enter Event Name")	;
		document.calen_disp.eventname.focus();
		return false;
	}
	if(document.calen_disp.eventdescr.value == '' ){
		alert("Please enter Event Description")	;
		document.calen_disp.eventdescr.focus();
		return false;
	}
	return true;
	
	
}

function commentvalidation() {
	if(document.commentform.com_name.value == '' ){
		alert("Please Enter your Name")	;
		document.commentform.com_name.focus();
		return false;
	}
	if (!validateEmail(document.commentform.com_email.value,1,1))
	{
		document.commentform.com_email.focus();
		return false;
	}
	
	if(document.commentform.com_comment.value == '' ){
		alert("Please enter the Comment")	;
		document.commentform.com_comment.focus();
		return false;
	}

	return true;
	
	
}


function articleemail1_val() {
	if(document.calen_dispmail.name.value == '' ){
		alert("Please Enter your Name")	;
		document.calen_dispmail.name.focus();
		return false;
	}
	if (!validateEmail(document.calen_dispmail.email.value,1,1))
	{
		document.calen_dispmail.email.focus();
		return false;
	}
	
	if(document.calen_dispmail.frname.value == '' ){
		alert("Please Enter your Friend's Name")	;
		document.calen_dispmail.frname.focus();
		return false;
	}
	if (!validateEmail(document.calen_dispmail.fremail.value,1,1))
	{
		document.calen_dispmail.fremail.focus();
		return false;
	}
	


	return true;
	
	
}


function articleemail_val() {
	if(document.calen_disp.yname.value == '' ){
		alert("Please Enter your Name")	;
		document.calen_disp.yname.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.email.value,1,1))
	{
		document.calen_disp.email.focus();
		return false;
	}
	if(document.calen_disp.frname.value == '' ){
		alert("Please Enter your Friend Name")	;
		document.calen_disp.frname.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.fremail.value,1,1))
	{
		document.calen_disp.fremail.focus();
		return false;
	}
	


	return true;
	
	
}



function adv_val() {
	if(document.calen_disp.name.value == '' ){
		alert("Please Enter Your Name")	;
		document.calen_disp.name.focus();
		return false;
	}
	if(document.calen_disp.companyname.value == '' ){
		alert("Please Enter Business Name")	;
		document.calen_disp.companyname.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.email.value,1,1))
	{
		document.calen_disp.email.focus();
		return false;
	}
	if(document.calen_disp.phone.value == '' ){
		alert("Please Enter the Phone Number")	;
		document.calen_disp.phone.focus();
		return false;
	}
	
	if(document.calen_disp.file.value == '' ){
		alert("Please Choose the File Name")	;
		document.calen_disp.file.focus();
		return false;
	}
	if(document.calen_disp.comment.value == '' ){
		alert("Please enter Comments")	;
		document.calen_disp.comment.focus();
		return false;
	}
	return true;
	
	
}
function class_val() {
	
	if(document.calen_disp.name.value == '' ){
		alert("Please Enter Your Name")	;
		document.calen_disp.name.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp.email.value,1,1))
	{
		document.calen_disp.email.focus();
		return false;
	}
	if(document.calen_disp.phone.value == '' ){
		alert("Please Enter the Phone Number")	;
		document.calen_disp.phone.focus();
		return false;
	}
	
	if(document.calen_disp.comment.value == '' ){
		alert("Please enter Comments")	;
		document.calen_disp.comment.focus();
		return false;
	}
	return true;	
}



function wheel_val() {
	
	if(document.calen_disp1.name.value == '' ){
		alert("Please Enter Your Name")	;
		document.calen_disp1.name.focus();
		return false;
	}
	if (!validateEmail(document.calen_disp1.email.value,1,1))
	{
		document.calen_disp1.email.focus();
		return false;
	}
	if(document.calen_disp1.phone.value == '' ){
		alert("Please Enter the Phone Number")	;
		document.calen_disp1.phone.focus();
		return false;
	}
	
	if(document.calen_disp1.address.value == '' ){
		alert("Please enter Address")	;
		document.calen_disp1.address.focus();
		return false;
	}
	
	if(document.calen_disp1.answers.value == '' ){
		alert("Please enter Answers")	;
		document.calen_disp1.answers.focus();
		return false;
	}
	
	if(document.calen_disp1.jumble.value == '' ){
		alert("Please enter Bonus Word Jumble")	;
		document.calen_disp1.jumble.focus();
		return false;
	}
	
	
	if(document.calen_disp1.fav.value == '' ){
		alert("Please enter Favorite Vues Advertiser")	;
		document.calen_disp1.fav.focus();
		return false;
	}	
	
	
	return true;	
}


function pop_box(url,width,height)
{
	//var width = 600;
	//var height = 600; 
	var left = screen.width/2 - (width/2);
	var top = 100;
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height='+height+',width='+width+',left='+left+',top='+top+'');
	if (window.focus) {newwindow.focus()}
}


function wheelemail_val(a) {
	if(a.yname.value == '' ){
		alert("Please Enter your Name")	;
		a.yname.focus();
		return false;
	}
	if (!validateEmail(a.email.value,1,1))
	{
		a.email.focus();
		return false;
	}
	if(a.frname.value == '' ){
		alert("Please Enter your Friend Name")	;
		a.frname.focus();
		return false;
	}
	if (!validateEmail(a.fremail.value,1,1))
	{
		a.fremail.focus();
		return false;
	}
	


	return true;
	
	
}



function simchaemail_val(a) {
	
	
	if(a.yname.value == '' ){
		alert("Please Enter your Name")	;
		a.yname.focus();
		return false;
	}
	if (!validateEmail(a.email.value,1,1))
	{
		a.email.focus();
		return false;
	}
	if(a.frname.value == '' ){
		alert("Please Enter your Friend Name")	;
		a.frname.focus();
		return false;
	}
	if (!validateEmail(a.fremail.value,1,1))
	{
		a.fremail.focus();
		return false;
	}
	
	
	
}

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;
	} else {
		return true;
	}
}

//Email Validation Script
//Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function showMonthCalendar() {
		//alert('aa');
			document.getElementById('dispcalMonth').style.display='block';
		}
		function hide() {
		//alert('aa');
			document.getElementById('dispcalMonth').style.display='none';
		}
		function gotocal(){
			var Mon = document.choosecal.selmonth.value;
			//alert(Mon );
			var year = document.choosecal.selyr.value;
			
			if(Mon == '') {
				alert('Please Choose the Month');
				document.choosecal.selmonth.focus();
				return false
			} else if(year == '') {
				alert('Please Choose the Year');
				document.choosecal.selyr.focus();
				return false
			}  else {
				window.location.href="calendar.php?mm="+Mon+"-"+year;
			}
		}
		function gotocal1(){
		
			var Mon = document.choosecal1.selmonth.value;
			//alert(Mon );
			var year = document.choosecal1.selyr.value;
			
			if(Mon == '') {
				alert('Please Choose the Month');
				document.choosecal1.selmonth.focus();
				return false
			} else if(year == '') {
				alert('Please Choose the Year');
				document.choosecal1.selyr.focus();
				return false
			}  else {
				window.location.href="calendar.php?mm="+Mon+"-"+year;
			}
		}
		
		
		
	function GetXmlHttpObject1_join()
	{
		var xmlHttp=null;
		try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
		catch (e){
		// Internet Explorer
		try{
		var aVersions = [ "MSXML2.XMLHttp.5.0",
			"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
			"MSXML2.XMLHttp","Msxm12.XMLHTTP","Microsoft.XMLHttp"];
			for (var i = 0; i < aVersions.length; i++) 
			{
			try
			{
			var xmlHttp = new ActiveXObject(aVersions[i]);
			return xmlHttp;
			} 
			catch (oError) 
			{
			//Do nothing
			}
		}
		}
		catch (e)
		{
		}
		}
		if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
		} 
		return xmlHttp;
	}

	function joinmailfun(){ 
		if (xmlViewHttp.readyState==1){ 
			document.getElementById("newsloader1").style.display = "block";
		}

		if (xmlViewHttp.readyState==4){ 
			document.getElementById("newsloader1").style.display="none";
			//document.getElementById("friend_approval").style.display="none";
			//alert(xmlViewHttp.responseText);
			document.getElementById("topright").innerHTML=xmlViewHttp.responseText;	
		}
	}
	
	function joinmailAjax (form) 
	{
	//alert('aa');
		var email = form.email.value;

		 if(!validateEmail(email,1,1)) 
		{
			form.email.focus();
			return false;
		}
		else
		{
			xmlViewHttp=GetXmlHttpObject1_join();
			xmlViewHttp.onreadystatechange = joinmailfun;
			//alert(joinmailfun);
			xmlViewHttp.open("GET","subscriber_action.php?email="+email,true);
			xmlViewHttp.send(null);
		}
	}




        <!-- Date Script For Top text  to hide script contents from old browsers


        /*
         *      This script was adapted from C sources written by
         *      Scott E. Lee, which contain the following copyright notice:
         *
         *      Copyright 1993-1995, Scott E. Lee, all rights reserved.
         *      Permission granted to use, copy, modify, distribute and sell so long as
         *      the above copyright and this permission statement are retained in all
         *      copies.  THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
         *
         *      Bill Hastings
         *      RBI Software Systems
         *      bhastings@rbi.com
         */
        var GREG_SDN_OFFSET = 32045,
                DAYS_PER_5_MONTHS = 153,
                DAYS_PER_4_YEARS = 1461,
                DAYS_PER_400_YEARS = 146097;
        var HALAKIM_PER_HOUR = 1080,
                HALAKIM_PER_DAY = 25920,
                HALAKIM_PER_LUNAR_CYCLE = ((29 * HALAKIM_PER_DAY) + 13753),
                HALAKIM_PER_METONIC_CYCLE = (HALAKIM_PER_LUNAR_CYCLE * (12 * 19 + 7));
        var HEB_SDN_OFFSET = 347997,
                NEW_MOON_OF_CREATION = 31524,
                NOON = (18 * HALAKIM_PER_HOUR),
                AM3_11_20 = ((9 * HALAKIM_PER_HOUR) + 204),
                AM9_32_43 = ((15 * HALAKIM_PER_HOUR) + 589);
        var SUN = 0,
                MON = 1,
                TUES = 2,
                WED = 3,
                THUR = 4,
                FRI = 5,
                SAT = 6;
        var today = null,
                hebrewMonth = 0,
                hebrewDate = 0,
                hebrewYear = 0,
                metonicCycle = 0,
                metonicYear = 0,
                moladDay = 0,
                moladHalakim = 0;
        var gWeekday = new weekdayarr("Sun","Mon","Tues","Wednes","Thurs","Fri","Satur");
        var gMonth = new gregmontharr("January","February","March","April","May","June","July","August","September","October","November","December");
        var hMonth = new hebrewmontharr("Tishri","Heshvan","Kislev","Tevet","Shevat","Adar-I","Adar-II","Nisan","Iyyar","Sivan","Tammuz","Av","Elul");
        var mpy = new monthsperyeararr(12,12,13,12,12,13,12,13,12,12,13,12,12,13,12,12,13,12,13);

        function weekdayarr(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;
        }

        function gregmontharr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11)
        {
                this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
                this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
                this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
        }

        function hebrewmontharr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13)
        {
                this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
                this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
                this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
                this[12] = m12; this[13] = m13;
        }

        function monthsperyeararr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,
                                                          m10,m11,m12,m13,m14,m15,m16,m17,m18)
        {
                this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
                this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
                this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
                this[12] = m8; this[13] = m13; this[14] = m14; this[15] = m15;
                this[16] = m16; this[17] = m17; this[18] = m18;
        }
        function getToday()
        {
                if(today == null)
                        today = new Date();
        }
        function displayWeekday()
        {
                getToday();
                document.writeln(gWeekday[today.getDay()] + "day,");
        }
        function displayGregorianDate()
        {
                getToday();
                document.writeln(gMonth[today.getMonth()] + " " + today.getDate() + ", " + today.getFullYear());
        }
        function displayHebrewDate()
        {
                if(hebrewDate != 0 && hebrewMonth != 0 && hebrewYear != 0)
                        document.writeln(hebrewDate + " " + hMonth[hebrewMonth-1] + " " + hebrewYear);
        }
        function GregorianToSdn(inputYear,inputMonth,inputDay)
        {
                var year = 0,
                        month = 0,
                        sdn;
                getToday();
                // Make year a positive number
                if (inputYear < 0)
                        year = inputYear + 4801;
                else
                        year = inputYear + 4800;
                // Adjust the start of the year
                if (inputMonth > 2) {
                        month = inputMonth - 3;
                }
                else {
                        month = inputMonth + 9;
                        year--;
                }
                sdn      = Math.floor((Math.floor(year / 100) * DAYS_PER_400_YEARS) / 4);
                sdn += Math.floor(((year % 100) * DAYS_PER_4_YEARS) / 4);
                sdn += Math.floor((month * DAYS_PER_5_MONTHS + 2) / 5);
                sdn += inputDay - GREG_SDN_OFFSET;
                return sdn;
        }
        function SdnToHebrew(sdn)
        {
                var inputDay,
                        tishri1 = 0,
                        tishri1After = 0,
                        yearLength = 0,
                inputDay = sdn - HEB_SDN_OFFSET;
                FindTishriMolad(inputDay);
                tishri1 = Tishri1(metonicYear,moladDay,moladHalakim);
                if (inputDay >= tishri1) {
                        // It found Tishri 1 at the start of the year.
                        hebrewYear = metonicCycle * 19 + metonicYear + 1;
                        if (inputDay < tishri1 + 59) {
                                if (inputDay < tishri1 + 30) {
                                        hebrewMonth = 1;
                                        hebrewDate = inputDay - tishri1 + 1;
                                }
                                else {
                                        hebrewMonth = 2;
                                        hebrewDate = inputDay - tishri1 - 29;
                                }
                                return;
                        }
                        // We need the length of the year to figure this out,so find Tishri 1 of the next year.
                        moladHalakim += HALAKIM_PER_LUNAR_CYCLE * mpy[metonicYear];
                        moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
                        moladHalakim = moladHalakim % HALAKIM_PER_DAY;
                        tishri1After = Tishri1((metonicYear + 1) % 19,moladDay,moladHalakim);
                }
                else {
                        // It found Tishri 1 at the end of the year.
                        hebrewYear = metonicCycle * 19 + metonicYear;
                        if (inputDay >= tishri1 - 177) {
                                // It is one of the last 6 months of the year.
                                if (inputDay > tishri1 - 30) {
                                        hebrewMonth = 13;
                                        hebrewDate = inputDay - tishri1 + 30;
                                }
                                else if (inputDay > tishri1 - 60) {
                                        hebrewMonth = 12;
                                        hebrewDate = inputDay - tishri1 + 60;
                                }
                                else if (inputDay > tishri1 - 89) {
                                        hebrewMonth = 11;
                                        hebrewDate = inputDay - tishri1 + 89;
                                }
                                else if (inputDay > tishri1 - 119) {
                                        hebrewMonth = 10;
                                        hebrewDate = inputDay - tishri1 + 119;
                                }
                                else if (inputDay > tishri1 - 148) {
                                        hebrewMonth = 9;
                                        hebrewDate = inputDay - tishri1 + 148;
                                }
                                else {
                                        hebrewMonth = 8;
                                        hebrewDate = inputDay - tishri1 + 178;
                                }
                                return;
                        }
                        else {
                                if (mpy[(hebrewYear - 1) % 19] == 13) {
                                        hebrewMonth = 7;
                                        hebrewDate = inputDay - tishri1 + 207;
                                        if (hebrewDate > 0)
                                                return;
                                        hebrewMonth--;
                                        hebrewDate += 30;
                                        if (hebrewDate > 0)
                                                return;
                                        hebrewMonth--;
                                        hebrewDate += 30;
                                }
                                else {
                                        hebrewMonth = 6;
                                        hebrewDate = inputDay - tishri1 + 207;
                                        if (hebrewDate > 0)
                                                return;
                                        hebrewMonth--;
                                        hebrewDate += 30;
                                }
                                if (hebrewDate > 0)
                                        return;
                                hebrewMonth--;
                                hebrewDate += 29;
                                if (hebrewDate > 0)
                                        return;
                                // We need the length of the year to figure this out,so find Tishri 1 of this year.
                                tishri1After = tishri1;
                                FindTishriMolad(moladDay - 365);
                                tishri1 = Tishri1(metonicYear,moladDay,moladHalakim);
                        }
                }
                yearLength = tishri1After - tishri1;
                moladDay = inputDay - tishri1 - 29;
                if (yearLength == 355 || yearLength == 385) {
                        // Heshvan has 30 days
                        if (moladDay <= 30) {
                                hebrewMonth = 2;
                                hebrewDate = moladDay;
                                return;
                        }
                        moladDay -= 30;
                }
                else {
                        // Heshvan has 29 days
                        if (moladDay <= 29) {
                                hebrewMonth = 2;
                                hebrewDate = moladDay;
                                return;
                        }
                        moladDay -= 29;
                }
                // It has to be Kislev.
                hebrewMonth = 3;
                hebrewDate = moladDay;
        }
        function FindTishriMolad(inputDay)
        {
                // Estimate the metonic cycle number.  Note that this may be an under
                // estimate because there are 6939.6896 days in a metonic cycle not
                // 6940,but it will never be an over estimate.   The loop below will
                // correct for any error in this estimate.
                metonicCycle = Math.floor((inputDay + 310) / 6940);
                // Calculate the time of the starting molad for this metonic cycle.
                MoladOfMetonicCycle();
                // If the above was an under estimate,increment the cycle number until
                // the correct one is found.  For modern dates this loop is about 98.6%
                // likely to not execute,even once,because the above estimate is
                // really quite close.
                while (moladDay < inputDay - 6940 + 310) {
                        metonicCycle++;
                        moladHalakim += HALAKIM_PER_METONIC_CYCLE;
                        moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
                        moladHalakim = moladHalakim % HALAKIM_PER_DAY;
                }
                // Find the molad of Tishri closest to this date.
                for (metonicYear = 0; metonicYear < 18; metonicYear++) {
                        if (moladDay > inputDay - 74)
                                break;
                        moladHalakim += HALAKIM_PER_LUNAR_CYCLE * mpy[metonicYear];
                        moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
                        moladHalakim = moladHalakim % HALAKIM_PER_DAY;
                }
        }
        function MoladOfMetonicCycle()
        {
                var r1,r2,d1,d2;
                // Start with the time of the first molad after creation.
                r1 = NEW_MOON_OF_CREATION;
                // Calculate gMetonicCycle * HALAKIM_PER_METONIC_CYCLE.  The upper 32
                // bits of the result will be in r2 and the lower 16 bits will be in r1.
                r1 += metonicCycle * (HALAKIM_PER_METONIC_CYCLE&0xFFFF);
                r2 = r1 >> 16;
                r2 += metonicCycle * ((HALAKIM_PER_METONIC_CYCLE >> 16)&0xFFFF);
                // Calculate r2r1 / HALAKIM_PER_DAY.  The remainder will be in r1,the
                // upper 16 bits of the quotient will be in d2 and the lower 16 bits
                // will be in d1.
                d2 = Math.floor(r2 / HALAKIM_PER_DAY);
                r2 -= d2 * HALAKIM_PER_DAY;
                r1 = (r2 << 16) | (r1&0xFFFF);
                d1 = Math.floor(r1 / HALAKIM_PER_DAY);
                r1 -= d1 * HALAKIM_PER_DAY;
                moladDay = (d2 << 16) | d1;
                moladHalakim = r1;
        }
        function Tishri1(metonicYear,moladDay,moladHalakim)
        {
                var tishri1 = moladDay;
                var dow = tishri1 % 7;
                var leapYear =  metonicYear == 2 || metonicYear == 5 || metonicYear == 7 || metonicYear == 10 ||
                                                metonicYear == 13 || metonicYear == 16 || metonicYear == 18;
                var lastWasLeapYear =   metonicYear == 3 || metonicYear == 6 || metonicYear == 8 || metonicYear == 11 ||
                                                                metonicYear == 14 || metonicYear == 17 || metonicYear == 0;
                // Apply rules 2,3 and 4
                if ((moladHalakim >= NOON) ||
                        ((!leapYear) && dow == TUES && moladHalakim >= AM3_11_20) ||
                        (lastWasLeapYear && dow == MON && moladHalakim >= AM9_32_43))
                {
                        tishri1++;
                        dow++;
                        if (dow == 7)
                                dow = 0;
                }
                // Apply rule 1 after the others because it can cause an additional delay of one day.
                if (dow == WED || dow == FRI || dow == SUN) {
                        tishri1++;
                }
                return tishri1;
        }
        //      end hiding contents from old browsers  -->
        

<!--
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open
('','printwin','left=100,top=100,width=400,height=400')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
//-->

