﻿
function CSVToArray3( strData) {

	var allRows = CSVToArray2(strData,";");
	for (var in2 = 0, l = allRows.length; in2 < l; in2 += 1)
	{
		allRows[in2] = CSVToArray2(allRows[in2]);
	}
	return allRows;
}
function CSVToArray2( strData,sep) {
  for (var foo = strData.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
    if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
      if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
        foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
      } else if (x) {
        foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
      } else foo = foo.shift().split(sep).concat(foo);
    } else foo[x].replace(/""/g, '"');
  } return foo;
};
// This will parse a delimited string into an array of
 // arrays. The default delimiter is the comma, but this
 // can be overriden in the second argument.
 function CSVToArray( strData, strDelimiter ){
	 // Check to see if the delimiter is defined. If not,
	 // then default to comma.
	 strDelimiter = (strDelimiter || ",");

	 // Create a regular expression to parse the CSV values.
	 var objPattern = new RegExp(
	 (
	 // Delimiters.
	 "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +

	 // Quoted fields.
	 "(?:\"([^\"](?:\"\"[^\"]))\"|" +

	 // Standard fields.
	 "([^\"\\" + strDelimiter + "\\r\\n]))"
	 ),
	 "gi"
	 );


	 // Create an array to hold our data. Give the array
	 // a default empty first row.
	 var arrData = [[]];

	 // Create an array to hold our individual pattern
	 // matching groups.
	 var arrMatches = null;


	 // Keep looping over the regular expression matches
	 // until we can no longer find a match.
	 while (arrMatches = objPattern.exec( strData )){

		 // Get the delimiter that was found.
		 var strMatchedDelimiter = arrMatches[ 1 ];

		 // Check to see if the given delimiter has a length
		 // (is not the start of string) and if it matches
		 // field delimiter. If id does not, then we know
		 // that this delimiter is a row delimiter.
		 if (
		 strMatchedDelimiter.length &&
		 (strMatchedDelimiter != strDelimiter)
		 ){

			 // Since we have reached a new row of data,
			 // add an empty row to our data array.
			 arrData.push( [] );

		}


		 // Now that we have our delimiter out of the way,
		 // let’s check to see which kind of value we
		 // captured (quoted or unquoted).
		 if (arrMatches[ 2 ]){

			 // We found a quoted value. When we capture
			 // this value, unescape any double quotes.
			 var strMatchedValue = arrMatches[ 2 ].replace(
			 new RegExp( "\"\"", "g" ),
			 "\""
			 );

		 } else {

		 // We found a non-quoted value.
		 var strMatchedValue = arrMatches[ 3 ];

		 }


		 // Now that we have our value string, let’s add
		 // it to the data array.
		 arrData[ arrData.length - 1 ].push( strMatchedValue );
	 }

	 // Return the parsed data.
	 return( arrData );
 }


//English
var monCount = new makeArray(1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366);

function makeArray() {
	this[0] = makeArray.arguments.length;
	for (i = 0; i < makeArray.arguments.length; i = i + 1)
		this[i+1] = makeArray.arguments[i];
}

function doy(d, m, y) {
	return monCount[m] + d + (m > 2 && leap(y));
}


function suntime(
	dy, mn, yr,
	sundeg, sunmin,
	londeg, lonmin, ew,
	latdeg, latmin, ns,
	timezone)
{
	if (mn > 3 && mn < 11)
		timezone = timezone + 1;
	var invalid = 0;	// start out as OK

	longitude = (londeg + lonmin/60.0) * ((ew == 0) ? -1 : 1);
	latitude  = (latdeg + latmin/60.0) * ((ns == 0) ? 1 : -1);

	var yday = doy(dy, mn, yr);

	var A = 1.5708; 
	var B = 3.14159; 
	var C = 4.71239; 
	var D = 6.28319;      
	var E = 0.0174533 * latitude; 
	var F = 0.0174533 * longitude; 
	var G = 0.261799 * timezone; 

	var R = Math.cos(0.01745 * (sundeg + sunmin/60.0));

	var J;

	// two times through the loop
	//    i=0 is for sunrise
	//    i=1 is for sunset
	for (i = 0; i < 2; i++) { 

		if(!i)
			J =  A;	// sunrise 
		else
			J = C;	// sunset

		var K = yday + ((J - F) / D); 
		var L = (K * .017202) - .0574039;              // Solar Mean Anomoly 
		var M = L + .0334405 * Math.sin(L);            // Solar True Longitude 
		M += 4.93289 + (3.49066E-04) * Math.sin(2 * L); 
		
		// Quadrant Determination 
		if (D == 0) {
			alert("Trying to normalize with zero offset...");
			exit;
		} 

		while(M < 0)
			M = (M + D);

		while(M >= D)
			M = (M - D);

		if ((M / A) - Math.floor(M / A) == 0)
			M += 4.84814E-06;

		var P = Math.sin(M) / Math.cos(M);                   // Solar Right Ascension 
		P = Math.atan2(.91746 * P, 1); 

		// Quadrant Adjustment 
		if (M > C)
			P += D;
		else {
			if (M > A)
				P += B;
		} 

		var Q = .39782 * Math.sin(M);      // Solar Declination 
		Q = Q / Math.sqrt(-Q * Q + 1);     // This is how the original author wrote it! 
		Q = Math.atan2(Q, 1); 

		var S = R - (Math.sin(Q) * Math.sin(E)); 
		S = S / (Math.cos(Q) * Math.cos(E)); 

		if(Math.abs(S) > 1)
			invalid = 1;	// uh oh! no sunrise/sunset

		S = S / Math.sqrt(-S * S + 1); 
		S = A - Math.atan2(S, 1); 

		if(!i)
			S = D - S;	// sunrise

		var T = S + P - 0.0172028 * K - 1.73364;  // Local apparent time 
		var U = T - F;                            // Universal timer 
		var V = U + G;                            // Wall clock time 
		
		// Quadrant Determination 
		if(D == 0) {
			alert("Trying to normalize with zero offset...");
			exit;
		} 
		
		while(V < 0)
			V = V + D;
		while(V >= D)
			V = V - D;
		V = V * 3.81972; 

		if(!i)
			sr = V;	// sunrise
		else
			ss = V;	// sunset
	} 

	var ret = new Object();
	ret[1] = invalid;
	ret[2] = sr;
	ret[3] = ss;
	return ret;
}


function timeadj(t, ampm) {
	var hour;
	var min;

	var time = t;

	var hour = Math.floor(time);
	var min  = Math.floor((time - hour) * 60.0 + 0.5);

	if(min >= 60) {
		hour += 1;
		min  -= 60;
	}

	if(hour < 0)
		hour += 24;

	if(ampm) {
		ampm_str = (hour > 11) ? ' PM' : ' AM';
		hour %= 12;
		hour = (hour < 1) ? 12 : hour;
	}
	else
		ampm_str = '';

	var str = hour + ':' + ((min < 10) ? '0' : '') + min + ampm_str;
//	var str = hour + ':' + min + ampm_str;
	return str;

}



/* kzman.js - Kaluach halachic times Javascript routines
 *   Version 0.01 (initial beta release)
 *   Version 0.02 (fixed bug in display of Shabbat times)
 *   Version 1.00 (fixed bug displaying locations at 0 deg lat/lon)
 *   Version 2.01 (handle invalid sunrise/set, different knissat shabbat times)
 * Copyright (C) 5760,5761 (2000 CE), by Abu Mami and Yisrael Hersch.
 *   All Rights Reserved.
 *   All copyright notices in this script must be left intact.
 * Acknowledgment given to scripts by:
 *   - P. Lutus <lutusp@arachnoid.com>
 *     available under the www.arachnoid.com CareWare program
 *	 - Tomer and Yehuda Shiran (docjs.com)
 *   - irt.org
 *   - javascripter.net
 * Permission will be granted to use this script on your web page
 *   if you wish. All that's required is that you please ask.
 *   (Of course if you want to send a few dollars, that's OK too :-)
 * website: http://www.kaluach.net
 * email: abumami@kaluach.org
 */


var month = 0, day = 0, year = 0;
var lat = 0, lng = 0;	// sun's location
var latd = -1, latm = 0;// lat on earth
var lngd = -1, lngm = 0;// long on earth
var ns = 'N', ew = 'E';	// hemisphere
var dst = -1;			// daylight saving time
var ampm = 0;			// am/pm or 24 hour display


function leap(y) {
	return ((y % 400 == 0) || (y % 100 != 0 && y % 4 == 0));
}

function civMonthLength(month, year) {
	if(month == 2)
		return 28 + leap(year);
	else if(month == 4 || month == 6 || month == 9 || month == 11)
	   return 30;
	else
		return 31;
}

function set_ampm(val) {
	ampm = val;
	doit("");
}

function set_dst() {
	dst = document.data.dst.checked;
	doit("");
}


function change_year(num) {
	var y = parseInt(document.data.year.value);
	y += num;
	document.data.year.value = y;
	year = y;
	date_vars_doit();
}

function list_pos(w) {
	var str, place, desc
	var i;

	i = w.options.selectedIndex;
	with(document.data) { // reset all prior selections
		israel_city.options[0].selected = 1;
		diaspora_city.options[0].selected = 1;
	}
	w.options[i].selected = 1; // restore current selection
	with (w) {
		desc = options[0].text;
		str = options[options.selectedIndex].value;
		place = options[options.selectedIndex].text;
		if(i == 0)
			document.data.placename.value = '';
	}

	i = str.indexOf(",");
	ns = str.substring(0, i);
	str = str.substring(i+1, str.length);

	i = str.indexOf(",");
	latd = eval(str.substring(0, i));
	str = str.substring(i+1, str.length);

	i = str.indexOf(",");
	latm = eval(str.substring(0, i));
	str = str.substring(i+1, str.length);

	i = str.indexOf(",");
	ew = str.substring(0, i);
	str = str.substring(i+1, str.length);

	i = str.indexOf(",");
	lngd = eval(str.substring(0, i));
	str = str.substring(i+1, str.length);

	i = str.indexOf(",");
	lngm = eval(str.substring(0, i));

	var tz = eval(str.substring(i+1, str.length));

	if((latd != -1) && (lngd != -1)) {
		document.data.tz.options[12+tz].selected = 1;
		doit("(" + desc + ") " + place);
	}

}

function man_pos() {

	latd = Math.abs(eval(document.data.latd.value));
	latm = Math.abs(eval(document.data.latm.value));
	ns = (document.data.lats[1].checked) ? 'S' : 'N';

	lngd = Math.abs(eval(document.data.lngd.value));
	lngm = Math.abs(eval(document.data.lngm.value));
	ew = (document.data.lngs[1].checked) ? 'E' : 'W';

	var tz = - (12 - document.data.tz.options.selectedIndex);
	document.data.tz.options[12+tz].selected = 1;
	doit("(manual entry)");
	return 1;
}

function doit(title) {

	var d, m, y;
	var nsi, ewi;
	var i;
 
	if(title != "")
		document.data.placename.value = title;
 
	document.data.latd.value = latd;
	document.data.latm.value = latm;
	i = ns.indexOf("N");
	nsi = (i != -1) ? 0 : 1;
	document.data.lats[nsi].checked = 1;
 
	document.data.lngd.value = lngd;
	document.data.lngm.value = lngm;
	i = ew.indexOf("W");
	ewi = (i != -1) ? 0 : 1;
	document.data.lngs[ewi].checked = 1;
 
	d = day + 1;
	m = month + 1;
	y = year;
 
	var adj = - (12 - document.data.tz.options.selectedIndex);
	adj += dst;

	var time;
	var sunrise, sunset;
	var shaa_zmanit;

	time = suntime(d, m, y, 90, 50, lngd, lngm, ewi, latd, latm, nsi, adj);
	if(time[1] == 0) {
		sunrise = time[2];
		sunset  = time[3];
		document.data.hanetz.value = timeadj(sunrise, ampm);
		document.data.shkia.value = timeadj(sunset, ampm);
		shaa_zmanit = (sunset - sunrise) / 12;
	}
	else {
		document.data.hanetz.value = "";
		document.data.shkia.value = "";
	}

	time = suntime(d, m, y, 106, 6, lngd, lngm, ewi, latd, latm, nsi, adj);
	if(time[1] == 0)
		document.data.alot.value = timeadj(time[2], ampm);
	else
		document.data.alot.value = "";

	time = suntime(d, m, y, 101, 0, lngd, lngm, ewi, latd, latm, nsi, adj);
	if(time[1] == 0)
		document.data.misheyakir.value = timeadj(time[2], ampm);
	else
		document.data.misheyakir.value = "";

	time = suntime(d, m, y, 96, 0, lngd, lngm, ewi, latd, latm, nsi, adj);
	if(time[1] == 0)
		document.data.tzeit.value = timeadj(time[3], ampm);
	else	
		document.data.tzeit.value = "";

	document.data.shema.value    = timeadj(sunrise + shaa_zmanit * 3, ampm);
	document.data.tefillah.value = timeadj(sunrise + shaa_zmanit * 4, ampm);
	document.data.chatzot.value  = timeadj(sunrise + shaa_zmanit * 6, ampm);
	document.data.minchag.value  = timeadj(sunrise + shaa_zmanit * 6.5, ampm);
	document.data.minchak.value  = timeadj(sunrise + shaa_zmanit * 9.5, ampm);
	document.data.plag.value     = timeadj(sunrise + shaa_zmanit * 10.75, ampm);

	var yom = new Date (y, m-1, d);
	if(yom.getDay() == 6) {

		// motzei shabbat (3 small stars)
		time = suntime(d, m, y, 98, 30, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.data.motzeiShabbat.value = timeadj(time[3], ampm);
		else
			document.data.motzeiShabbat.value = "";

		// knissat shabbat (sunset from day before)
		var day_before = new Date(yom.getTime() - 86400000);
		db = day_before.getDate();
		mb = day_before.getMonth() + 1;
		yb = day_before.getYear();
		if(yb < 1900)
			yb += 1900;
		time = suntime(db, mb, yb, 90, 50, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(document.data.placename.value == "(Israel) Jerusalem")
			document.data.knissatShabbat.value = timeadj(time[3] - 40.0/60.0, ampm);
		else if(document.data.placename.value == "(Israel) Haifa")
			document.data.knissatShabbat.value = timeadj(time[3] - 30.0/60.0, ampm);
		else if(document.data.placename.value == "(Israel) Be'er Sheva")
			document.data.knissatShabbat.value = timeadj(time[3] - 30.0/60.0, ampm);
		else if(document.data.placename.value == "(Israel) Karnei Shomron")
			document.data.knissatShabbat.value = timeadj(time[3] - 22.0/60.0, ampm);
		else if(document.data.placename.value == "(Israel) Tel Aviv")
			document.data.knissatShabbat.value = timeadj(time[3] - 22.0/60.0, ampm);
		else if(document.data.placename.value == "(Israel) Karnei Shomron")
			document.data.knissatShabbat.value = timeadj(time[3] - 22.0/60.0, ampm);
		else
			document.data.knissatShabbat.value = timeadj(time[3] - 18.0/60.0, ampm);
	}
	else {
		document.data.motzeiShabbat.value = '';
		document.data.knissatShabbat.value = '';
	}


}
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}
function printing()
{
	//document.data.misheyakir.value = "hello";
}

function printShabbess(platd,platm,ns,plngd,plngm,ew) {
	var d, m, y;
	var nsi, ewi;
	var ns, ew;
	var i;
	latd = Math.abs(eval(platd));
	latm = Math.abs(eval(platm));
	//ns = pns;

	lngd = Math.abs(eval(plngd));
	lngm = Math.abs(eval(plngm));
	//ew = pew;
	
	i = ns.indexOf("N");
	nsi = (i != -1) ? 0 : 1;

	i = ew.indexOf("W");
	ewi = (i != -1) ? 0 : 1;
	
	var now = new Date();
	var weekday = now.getDay();
	now = addDays(now,6-weekday);
	var day = now.getDate();
	var month = now.getMonth()+1 ;
	var year = now.getYear();
	
	if(year < 1900)
		year += 1900;

	d = day;
	m = month;
	y = year;
 
	var adj = 2;
	adj += dst;


	var yom = new Date (y, m-1, d);
	if(yom.getDay() == 6) {
		// motzei shabbat (3 small stars)
		 //document.write(yom + " " + d + " " + m + " " + y + " " + 98 + " " + 30 + " " + lngd + " " + lngm + " " + ewi + " " + latd + " " + latm + " " + nsi + " " + adj);
		
		// knissat shabbat (sunset from day before)
		var day_before = new Date(yom.getTime() - 86400000);
		db = day_before.getDate();
		mb = day_before.getMonth() + 1;
		yb = day_before.getYear();
		if(yb < 1900)
			yb += 1900;
		time = suntime(db, mb, yb, 90, 50, lngd, lngm, ewi, latd, latm, nsi, adj);
		document.write("<td>" +timeadj(time[3] - 18.0/60.0, ampm)+"</td>");
		
		time = suntime(d, m, y, 98, 30, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.write("<td>"+timeadj(time[3], ampm)+"</td>");
	}
}

function printFast(now,platd,platm,ns,plngd,plngm,ew) {
	var d, m, y;
	var nsi, ewi;
	var ns, ew;
	var i;
	latd = Math.abs(eval(platd));
	latm = Math.abs(eval(platm));
	//ns = pns;

	lngd = Math.abs(eval(plngd));
	lngm = Math.abs(eval(plngm));
	//ew = pew;
	
	i = ns.indexOf("N");
	nsi = (i != -1) ? 0 : 1;

	i = ew.indexOf("W");
	ewi = (i != -1) ? 0 : 1;
	
	//var now = new Date();
	var day = now.getDate();
	var month = now.getMonth()+1 ;
	var year = now.getYear();
	
	if(year < 1900)
		year += 1900;

	d = day;
	m = month;
	y = year;
 
	var adj = 2;
	adj += dst;


	var yom = new Date (y, m-1, d);
	
		// motzei shabbat (3 small stars)
		 //document.write(yom + " " + d + " " + m + " " + y + " " + 98 + " " + 30 + " " + lngd + " " + lngm + " " + ewi + " " + latd + " " + latm + " " + nsi + " " + adj);
		
		// knissat shabbat (sunset from day before)
		var day_before = new Date(yom.getTime() - 86400000);
		db = day_before.getDate();
		mb = day_before.getMonth() + 1;
		yb = day_before.getYear();
		if(yb < 1900)
			yb += 1900;
		time = suntime(db, mb, yb, 106, 6, lngd, lngm, ewi, latd, latm, nsi, adj);
		document.write("<td>" +timeadj(time[2], ampm)+"</td>");
		
		time = suntime(d, m, y, 96, 0, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.write("<td>"+timeadj(time[3], ampm)+"</td>");
}

function printJomKipur(now,platd,platm,ns,plngd,plngm,ew) {
	var d, m, y;
	var nsi, ewi;
	var ns, ew;
	var i;
	latd = Math.abs(eval(platd));
	latm = Math.abs(eval(platm));
	//ns = pns;

	lngd = Math.abs(eval(plngd));
	lngm = Math.abs(eval(plngm));
	//ew = pew;
	
	i = ns.indexOf("N");
	nsi = (i != -1) ? 0 : 1;

	i = ew.indexOf("W");
	ewi = (i != -1) ? 0 : 1;
	
	//var now = new Date();
	var day = now.getDate();
	var month = now.getMonth()+1 ;
	var year = now.getYear();
	
	if(year < 1900)
		year += 1900;

	d = day;
	m = month;
	y = year;
 
	var adj = 2;
	adj += dst;


	var yom = new Date (y, m-1, d);
	
		// motzei shabbat (3 small stars)
		 //document.write(yom + " " + d + " " + m + " " + y + " " + 98 + " " + 30 + " " + lngd + " " + lngm + " " + ewi + " " + latd + " " + latm + " " + nsi + " " + adj);
		
		// knissat shabbat (sunset from day before)
		var day_before = new Date(yom.getTime() - 86400000);
		db = day_before.getDate();
		mb = day_before.getMonth() + 1;
		yb = day_before.getYear();
		if(yb < 1900)
			yb += 1900;
		time = suntime(db, mb, yb, 90, 50, lngd, lngm, ewi, latd, latm, nsi, adj);
		document.write("<td>" +timeadj(time[3] - 18.0/60.0, ampm)+"</td>");
		
		time = suntime(d, m, y, 98, 30, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.write("<td>"+timeadj(time[3], ampm)+"</td>");

}

function printJomTov(now,platd,platm,ns,plngd,plngm,ew) {
	var d, m, y;
	var nsi, ewi;
	var ns, ew;
	var i;
	latd = Math.abs(eval(platd));
	latm = Math.abs(eval(platm));
	//ns = pns;

	lngd = Math.abs(eval(plngd));
	lngm = Math.abs(eval(plngm));
	//ew = pew;
	
	i = ns.indexOf("N");
	nsi = (i != -1) ? 0 : 1;

	i = ew.indexOf("W");
	ewi = (i != -1) ? 0 : 1;
	
	//var now = new Date();
	var day = now.getDate();
	var month = now.getMonth()+1 ;
	var year = now.getYear();
	
	if(year < 1900)
		year += 1900;

	d = day;
	m = month;
	y = year;
 
	var adj = 2;
	adj += dst;


	var yom = new Date (y, m-1, d);
	
		// motzei shabbat (3 small stars)
		 //document.write(yom + " " + d + " " + m + " " + y + " " + 98 + " " + 30 + " " + lngd + " " + lngm + " " + ewi + " " + latd + " " + latm + " " + nsi + " " + adj);
		
		// knissat shabbat (sunset from day before)
		var day_before = new Date(yom.getTime() - 86400000);
		db = day_before.getDate();
		mb = day_before.getMonth() + 1;
		yb = day_before.getYear();
		if(yb < 1900)
			yb += 1900;
		time = suntime(db, mb, yb, 90, 50, lngd, lngm, ewi, latd, latm, nsi, adj);
		document.write("<td>" +timeadj(time[3] - 18.0/60.0, ampm)+"</td>");
		
		time = suntime(d, m, y, 98, 30, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.write("<td>"+timeadj(time[3], ampm)+"</td>");
			
		d = now.getDate();
		m = now.getMonth()+1 ;
		y = now.getYear();
		
		if(y < 1900)
			y += 1900;
		time = suntime(d, m, y, 98, 30, lngd, lngm, ewi, latd, latm, nsi, adj);
		if(time[1] == 0)
			document.write("<td>"+timeadj(time[3], ampm)+"</td>");

	
}





function set_date_vars() {
	month = document.data.month.selectedIndex;
	day   = document.data.day.selectedIndex;
	year  = document.data.year.value;

	var len = civMonthLength(month+1, year);
	if(day >= len) {
		day = len - 1;
		document.data.day.selectedIndex = day;
	}
}

function date_vars_doit() {
	set_date_vars();
	doit("");
}

function set_default_date() {
	var now = new Date();
	//document.write("now" + now + "<br>");
	//document.write("week" + now.getDay() + "<br>");
	var d = now.getDate();
	//document.write("d" + d+ "<br>");
	var m = now.getMonth();
	//document.write("m" + m+ "<br>");
	year = now.getYear();
	//document.write("year" + year+ "<br>");
	if(year < 1900)
		year += 1900;
	document.data.month.selectedIndex = m;
	document.data.day.selectedIndex = d - 1;
	document.data.year.value = year;
	set_date_vars("");
}




/* kdate.js - Kaluach Javascript Hebrew date routines
 *   Version 0.03 (beta release)
 * Copyright (C) 5760 (2000 CE), by Abu Mami and Yisrael Hersch.
 *   All Rights Reserved.
 *   All copyright notices in this script must be left intact.
 * Based on the formula by Gauss
 * Terms of use:
 *   - Permission will be granted to use this script on personal
 *     web pages. All that's required is that you please ask.
 *     (Of course if you want to send a few dollars, that's OK too :-)
 *   - Use on commercial web sites requires a $50 payment.
 * website: http://www.kaluach.net
 * email: abu-mami@kaluach.net
 */

function makeArray() {
	this[0] = makeArray.arguments.length;
	for (i = 0; i < makeArray.arguments.length; i = i + 1)
		this[i+1] = makeArray.arguments[i];
}

var hebMonth = new makeArray(
	'Nisan', 'Iyyar', 'Sivan', 'Tammuz', 'Av', 'Elul',
	'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Shevat',
	'Adar', 'Adar I', 'Adar II');

var civMonth = new makeArray(
	'January', 'February', 'March', 'April', 'May', 'June',
	'July', 'August', 'September', 'October', 'November', 'December');

var weekDay = new makeArray(
	'Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Shabbat');

function Gauss(year) {
	var a,b,c;
	var m;
	var	Mar;	// "day in March" on which Pesach falls (return value)

	a = Math.floor((12 * year + 17) % 19);
	b = Math.floor(year % 4);
	m = 32.044093161144 + 1.5542417966212 * a +  b / 4.0 - 0.0031777940220923 * year;
	if (m < 0)
		m -= 1;
	Mar = Math.floor(m);
	if (m < 0)
		m++;
	m -= Mar;

	c = Math.floor((Mar + 3 * year + 5 * b + 5) % 7);
	if(c == 0 && a > 11 && m >= 0.89772376543210 )
		Mar++;
	else if(c == 1 && a > 6 && m >= 0.63287037037037)
		Mar += 2;
	else if(c == 2 || c == 4 || c == 6)
		Mar++;

	Mar += Math.floor((year - 3760) / 100) - Math.floor((year - 3760) / 400) - 2;
	return Mar;
}

function leap(y) {
	return ((y % 400 == 0) || (y % 100 != 0 && y % 4 == 0));
}

function civMonthLength(month, year) {
	if(month == 2)
		return 28 + leap(year);
	else if(month == 4 || month == 6 || month == 9 || month == 11)
	   return 30;
	else
		return 31;
}

function heb2civ(hday, hmonth, hyear) {
document.write("heb2civ");
	var hd = hday;
	var	hm = hmonth;
	var hy = hyear;
	var y;
	var pesach;
	var anchor;
	var adarType;

	hm -= 1; //how many month passed already
	//if (m <= 0) { // Jan or Feb
		//m += 12;
		//y -= 1;
	//}

	for(var m = 0; m <= hm; m++) {
		if(m == 1 && anchor % 30 == 2)
			d += 30; // Cheshvan
		else if(m == 2 && anchor % 30 == 0)
			d += 29; // Kislev
		else
			d += 30 - m % 2;
		if(d <= days)
			break;
		d -= days;
	}

	d += Math.floor(7 * m / 12 + 30 * (m - 1)); // day in March
	hy = y + 3760;	// get Hebrew year
	pesach = Gauss(hy);
	document.write("pes: " + pesach +"<br>");
	if (d <= pesach - 15) { // before 1 Nisan
		anchor = pesach;
		d += 365;
		if(leap(y))
			d++;
		y -= 1;
		hy -= 1;
		pesach = Gauss(hy);
	}
	else
		anchor = Gauss(hy + 1);

	d -= pesach - 15;
	anchor -= pesach - 12;
	y++;
	if(leap(y))
		anchor++;

	for(m = 0; m < 11; m++) {
		var days;
		if(m == 7 && anchor % 30 == 2)
			days = 30; // Cheshvan
		else if(m == 8 && anchor % 30 == 0)
			days = 29; // Kislev
		else
			days = 30 - m % 2;
		if(d <= days)
			break;
		d -= days;
	}

	adarType = 0;			// plain old Adar
	if (m == 11 && anchor >= 30) {
		if (d > 30) {
			adarType = 2;	// Adar 2
			d -= 30;
		}
		else
			adarType = 1;	// Adar 1
	}

	if(m >= 6)		// Tishrei or after?
		hy++;		// then bump up year

	if(m == 11)			// Adar?
		m += adarType;	// adjust for Adars

	return (d + ' ' + m + ' ' + hy);
}



function civ2heb(day, month, year) {
	var d = day;
	var	m = month;
	var y = year;
	var hy;
	var pesach;
	var anchor;
	var adarType;

	m -= 2;
	if (m <= 0) { // Jan or Feb
		m += 12;
		y -= 1;
	}

	d += Math.floor(7 * m / 12 + 30 * (m - 1)); // day in March
	hy = y + 3760;	// get Hebrew year
	pesach = Gauss(hy);

	if (d <= pesach - 15) { // before 1 Nisan
		anchor = pesach;
		d += 365;
		if(leap(y))
			d++;
		y -= 1;
		hy -= 1;
		pesach = Gauss(hy);
	}
	else
	{
		anchor = Gauss(hy + 1);
	}
	d -= pesach - 15;
	anchor -= pesach - 12;

	y++;
	if(leap(y))
	{
		anchor++;

	}
	for(m = 0; m < 11; m++) {
		var days;
		if(m == 7 && anchor % 30 == 2)
			days = 30; // Cheshvan
		else if(m == 8 && anchor % 30 == 0)
			days = 29; // Kislev
		else
			days = 30 - m % 2;
		if(d <= days)
			break;
		d -= days;
	}

	adarType = 0;			// plain old Adar
	if (m == 11 && anchor >= 30) {
		if (d > 30) {
			adarType = 2;	// Adar 2
			d -= 30;
		}
		else
			adarType = 1;	// Adar 1
	}

	if(m >= 6)		// Tishrei or after?
		hy++;		// then bump up year

	if(m == 11)			// Adar?
		m += adarType;	// adjust for Adars

	return (d + ' ' + m + ' ' + hy);
}


function Easter(Y) {
	// based on the algorithm of Oudin
    var C = Math.floor(Y / 100);
    var N = Y - 19 * Math.floor(Y / 19);
    var K = Math.floor((C - 17) / 25);
    var I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
    I = I - 30*Math.floor((I / 30));
    I = I - Math.floor(I / 28) * (1 - Math.floor(I / 28) * Math.floor(29 / (I + 1)) * Math.floor((21 - N) / 11));
    var J = Y + Math.floor(Y / 4) + I + 2 - C + Math.floor(C / 4);
    J = J - 7 * Math.floor(J / 7);
    var L = I - J;
    var M = 3 + Math.floor((L + 40) / 44);
    var D = L + 28 - 31 * Math.floor(M / 4);

	var ret = new Object();
	ret[1] = M;
	ret[2] = D;
	return ret;
}

function DOW(day,month,year) {
	var a = Math.floor((14 - month)/12);
	var y = year - a;
	var m = month + 12*a - 2;
	var d = (day + y + Math.floor(y/4) - Math.floor(y/100) +
			Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
	return d + 1;
}

function NthDOW(nth,weekday,month,year) {
	if (nth > 0)
		return (nth - 1) * 7 + 1 + (7 + weekday - DOW((nth - 1) * 7 + 1, month, year)) % 7;
	var days = civMonthLength(month, year);
	return days - (DOW(days, month, year) - weekday + 7) % 7;
}

function holidays(cday, cmonth, cyear) {
	// American civil holidays and some major religious holiday
	if (cmonth == 1 && cday == 1)
		return "New Year's Day";
	else if (cmonth == 2 && cday == 12)
		return "Lincoln's Birthday";
	else if (cmonth == 2 && cday == 14)
		return "Valentine's Day";
	else if (cmonth == 2 && cday == NthDOW(3, 2, 2, cyear))
		return "President's Day";
	else if (cmonth == 3 && cday == 17)
		return "St. Patrick's Day";
	else if (cmonth == 3 || cmonth == 4) {
		var e = Easter(cyear);
	    if (cmonth == e[1] && cday == e[2])
			return "Easter";
	}
	else if (cmonth == 5 && cday == NthDOW(2, 1, 5, cyear))
		return "Mother's Day";
	else if (cmonth == 5 && cday == NthDOW(3, 7, 5, cyear))
		return "Armed Forces Day";
	else if (cmonth == 5 && cday == NthDOW(0, 2, 5, cyear))
		return "Memorial Day";
	else if (cmonth == 6 && cday == 14)
		return "Flag Day";
	else if (cmonth == 6 && cday == NthDOW(3, 1, 6, cyear))
		return "Father's Day";
	else if (cmonth == 7 && cday == 4)
		return "Independence Day";
	else if (cmonth == 9 && cday == NthDOW(1, 2, 9, cyear))
		return "Labor Day";
	else if (cmonth == 10 && cday == NthDOW(2, 2, 10, cyear))
		return "Columbus Day";
	else if (cmonth == 10 && cday == 31)
		return "Halloween";
	else if (cmonth == 11 && cday == 11)
		return "Veterans' Day";
	else if (cmonth == 11 && cday == NthDOW(4, 5, 11, cyear))
		return "Thanksgiving";
	else if (cmonth == 12 && cday == 25)
		return "Christmas";

	return "";
}
function shabbess(cday, cmonth, cyear){
	var dow;
	dow = DOW(cday,cmonth,cyear);
	if(dow == 7) {
		return "Shabbath ";
	}
	return "";
}
function moadim(cday, cmonth, cyear, hday, hmonth) {
	var dow;
	dow = DOW(cday,cmonth,cyear);
	if(hmonth == 6) {
		if(hday == 1)
			return "Rosh Hashana"
		else if (hday == 2)
			return "Rosh Hashana ||"
		else if(hday == 3 && dow != 7)
			return "Fast of Gedalia";
		else if(hday == 4 && dow == 1)
			return "Fast of Gedalia";
		else if(hday == 10)
			return "Yom Kippur"
		else if(hday >= 15 && hday <= 22)
			return "Sukkot"
		else if(hday == 23)
			return "Sukkot (d)"
	}
	else if(hmonth == 8) {
		if(hday >= 25)
			return "Chanukkah"
	}
	else if(hmonth == 9) {
		if(hday <= 2) {
			return "Chanukkah"
		}
		else if(hday == 3) {
			// Kislev can be malei or chaser
			if(cday == 1) {
				cday = 29;
				cmonth = 11;
			}
			else if(cday == 2) {
				cday = 30;
				cmonth = 11;
			}
			else
				cday -= 3;
			var hdate = civ2heb(cday, cmonth, cyear);
			hd = eval(hdate.substring(0, hdate.indexOf(' ')));
			if(hd == 29)
				return "Chanukkah"
		}
		else if(hday == 10)
			return "Fast of Tevet"
	}
	else if(hmonth == 10) {
		if(hday==15)
			return "Tu b'Shvat"
	}
	else if(hmonth == 11 || hmonth == 13) {
		if(hday == 11 && dow == 5)
			return "Taanit Esther"
		else if(hday == 13 && dow != 7)
			return "Taanit Esther"
		else if(hday == 14)
			return "Purim"
		else if(hday == 15)
			return "Shushan Purim"
	}
	else if(hmonth == 0) {

		if(hday == 12 && dow == 5)
			return "Taanit Bechorot"
		else if(hday == 14 && dow != 7)
			return "Taanit Bechorot"
		else if(hday >= 15 && hday <= 21)
			return "Pesach"
		else if(hday == 22)
			return "Pesach (d)"
	}
	else if(hmonth == 1) {
		if(hday == 3 && dow == 5)
			return "Yom Ha'Atzmaut"
		else if(hday == 4 && dow == 5)
			return "Yom Ha'Atzmaut"
		else if(hday == 5 && dow != 6 && dow != 7)
			return "Yom Ha'Atzmaut"
		if(hday == 14)
			return "Pesah sheni"
		else if(hday == 18)
			return "Lag B'Omer"
		if(hday == 28)
			return "Yom Yerushalayim"
	}
	else if(hmonth == 2) {
		if(hday == 6)
			return "Shavuot"
		else if(hday == 7)
			return "Shavuot || "
	}
	else if(hmonth == 3) {
		if(hday == 17 && dow != 7)
			return "Fast of Tammuz"
		if(hday == 18 && dow == 1)
			return "Fast of Tammuz"
	}
	else if(hmonth == 4) {
		if(hday == 9 && dow != 7)
			return "Tisha B'Av"
		if(hday == 10 && dow == 1)
			return "Tisha B'Av"
		if(hday == 15)
			return "Tu B'Av"
	}

	return "";
}

function isWhat(tday, tmonth, tyear, hDay, hMonth)
{
	var regel = moadim(tday, tmonth, tyear, hDay, hMonth);
	
	return regel;
}

function isRegalim(regel)
{
	if ((regel == "Shavuot") || (regel == "Rosh Hashana") || (regel == "Sukkot") ||(regel == "Sukkot (d)"))
	{
		return true;
	}	
	return false;
}

function isYomKipur(regel)
{
	if (regel == "Yom Kippur")
	{
		return true;
	}	
	return false;
}

function isFast(regel)
{
	if (regel == "Fast of Gedalia")
	{
		return true;
	}	
	return false;
}


function printDate(now){

	// First display the Hebrew date
	var tday = now.getDate();
	var tmonth = now.getMonth() + 1;
	var tyear = now.getYear();
	if(tyear < 1900)
		// if date from Netscape, then add 1900
		tyear += 1900;
	var hebDate = civ2heb(tday, tmonth, tyear);
	var hmS = hebDate.substring(hebDate.indexOf(' ')+1, hebDate.length);
	var	hDay = eval(hebDate.substring(0, hebDate.indexOf(' ')));
	var hMonth = eval(hmS.substring(0, hmS.indexOf(' ')));
	var hYear = hmS.substring(hmS.indexOf(' ')+1, hmS.length);
	
	// Then display the corresponding civil dates
	var day, month, year;
	var today = new Date;
	today = now;
    var yesterday = new Date(today.getTime() - 86400000);
	day   = yesterday.getDate();
	month = yesterday.getMonth() + 1;
	year  = yesterday.getYear();
	if(year < 1900)
		year += 1900; // if date from Netscape, then add 1900
	
	//document.write(civMonth[month] + ' ' + day + ', ' + year');
	day   = today.getDate();
	month = today.getMonth() + 1;
	year  = today.getYear();
	if(year < 1900)
		year += 1900; // if date from Netscape, then add 1900
	document.write(shabbess(day, month, year) + moadim(day, month, year, hDay, hMonth));
	document.write('<br>' + hDay + ' ' + hebMonth[hMonth+1] + ' ' + hYear);
	document.write('<br>');
	document.write(civMonth[month] + ' ' + day + ', ' + year);
	
	}

//---------------------------------------------------//---------------------------------------------------//---------------------------------------------------//---------------------------------------------------//---------------------------------------------------

function printHeader(root,marque){
document.write("<div id='header'> 	<table style='border-right:0' dir='ltr'  width='100%'> 	<tr> 	<td width='33%' align='center'><h1> <a href='index.html' color='blue' >Kosher<br/>גרמניה</a></h1> </td> <td width='33%' align='center'><img align='center' id='frontphoto' src='" + root + "pictures/NewLogo.gif'  width='230' height='200'alt='' bgcolor='#286ea0'/> </td> <td width='33%' align='center'><h1><a href='index.html' color='blue' >Germany<br/>כשרות</a></h1> </td> 	</tr>	<tr><td colspan='2' ><font color='red'><b> <MARQUEE  BGCOLOR='lightblue' SCROLLDELAY='100' SCROLLAMOUNT='3' DIRECTION='left' BEHAVIOR='scroll'>" + marque + "</MARQUEE></b></font></td>	<td	align='right' >		<strong>languages:</strong> <a href='" + root + "hebrew/'>עברית</a> &middot; <a href='" + root + "'>English</a> &middot; <a href='" + root + "deutsh/'>Deutsch</a> &middot;&middot;	</td>	</tr> 	</table> <br/><!--img id='frontphoto' src='img/NewLogo.gif'  width='100' height='100'alt='' bgcolor='#286ea0'/--> <!--img id='frontphoto' src='img/front.jpg' width='660' height='175' alt='' /--> </div>");

}

function printExtra(root){


	document.write("<div id='extras' dir='ltr'>");
	var noPlaces = 6;
	var places=new Array(noPlaces);

	places[0]=new Array(52,31,"N",13,20,"E","Berlin");
	places[1]=new Array(51,13,"N",6,47,"E","Dusseldorf");
	places[2]=new Array(50,02,"N",8,34,"E","Frankfurt");
	places[3]=new Array(50,56,"N",6,57,"E","Koln");
	places[4]=new Array(48,8,"N",11,35,"E","Munich");
	places[5]=new Array(48,47,"N",9,17,"E","Stuttgart");
	
	

	var now = new Date();
	var weekday = now.getDay();
	now = addDays(now,6-weekday);

	document.write("<table>");
	document.write("<tr><th colspan='4' align='center'></th></tr>");
	
	
		//print JomTov
	var today = new Date();
	for (;today < now; today = addDays(today,1)){
		
		var tday = today.getDate();
		var tmonth = today.getMonth() + 1;
		var tyear = today.getYear();
		if(tyear < 1900)
			// if date from Netscape, then add 1900
			tyear += 1900;
		var hebDate = civ2heb(tday, tmonth, tyear);
		var hmS = hebDate.substring(hebDate.indexOf(' ')+1, hebDate.length);
		var	hDay = eval(hebDate.substring(0, hebDate.indexOf(' ')));
		var hMonth = eval(hmS.substring(0, hmS.indexOf(' ')));

		var regel = isWhat(tday, tmonth, tyear, hDay, hMonth);
		if (isRegalim(regel)==true) {
				document.write("<tr><th colspan='4' align='center'>");
				printDate(today);
				document.write("</th> </tr><tr><th>City</th><th>	Begin|</th><th>	Begin||</th><th>	End</th></tr>");

				for (var x = 0; x < noPlaces; x++)
				{
				   	document.write("<tr><td><b>" + places[x][6] +"</b></td>");
					printJomTov(today,places[x][0],places[x][1],places[x][2],places[x][3],places[x][4],places[x][5]);
					document.write("</tr>");
				}
		}
		
		else if (isYomKipur(regel)==true) {
				document.write("<tr><th colspan='3' align='center'>");
				printDate(today);
				document.write("</th> </tr><tr><th>City</th><th>	Begin|</th><th>	End</th></tr>");

				for (var x = 0; x < noPlaces; x++)
				{
				   	document.write("<tr><td><b>" + places[x][6] +"</b></td>");
					printJomKipur(today,places[x][0],places[x][1],places[x][2],places[x][3],places[x][4],places[x][5]);
					document.write("</tr>");
				}
		}
		
		else if (isFast(regel)==true) 
		{
				document.write("<tr><th colspan='3' align='center'>");
				printDate(today);
				document.write("</th> </tr><tr><th>City</th><th>	Begin</th><th>	End</th></tr>");

				for (var x = 0; x < noPlaces; x++)
				{
				   	document.write("<tr><td><b>" + places[x][6] +"</b></td>");
					printFast(today,places[x][0],places[x][1],places[x][2],places[x][3],places[x][4],places[x][5]);
					document.write("</tr>");
				}
		}

	}
	
	
	//print Shabbess
	document.write("<tr><th colspan='3' align='center'>");
	printDate(now);
	document.write("</th> </tr><tr><th>City</th><th>	Begin</th><th>	End</th></tr>");

	for (var x = 0; x < noPlaces; x++)
	{
	   	document.write("<tr><td><b>" + places[x][6] +"</b></td>");
		printShabbess(places[x][0],places[x][1],places[x][2],places[x][3],places[x][4],places[x][5]);
		document.write("</tr>");
	}
	


	document.write("<tr><td colspan='3' align='center'><a href='http://www.kaluach.org'>www.kaluach.org</a>");
	if (now.getMonth() > 2 && now.getMonth() < 10)	
		document.write("<br/>Summer Time");
	else
		document.write("<br/>Winter Time");
	document.write("</td></tr>");


	document.write("<tr><td colspan='3' align='center'><br><h1><hr>Recommended Links<hr></h1>		<a align='center' href='http://www.ordonline.de/'><img align='center'  border='1' src='" + root + "pictures/ORD.bmp' alt='' ></a>		<a href='http://www.schlagfix.de/'><img src='" + root + "pictures/Deckel.jpg'  alt=''></a> </td></tr></table></div>");


}

function setfocus() {
 	
	//if (document.forms['questionForm'] !== 0)
	{
		//document.forms['questionForm'].elements['name'].focus(); 	
	}


}
function navigationCollapse(id) 	{  		el = document.getElementById(id); 		var display = el.style.display ? '' : 'none'; 		el.style.display = display; 		return false; 	}





//English
var marq = 'Welcome to the new KosherGermany Website!';
//document.write("	<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> ";

//document.write("<head> <meta HTTP-EQUIV='content-type' CONTENT='text/html; charset=utf-8 COLLATE=utf8_unicode_ci ' /> <meta name='description' content='kosher germany.' /> <meta name='keywords' content='kosher germany' /> <meta name='author' content='David Hirsch' /> <link rel='stylesheet' type='text/css' href='css\andreas01.css' media='screen,projection' />)"
document.write("<title>KosherGermany | all about kosher certificates & products</title></head>  ");

document.write("<body onload='setfocus()'> <div id='wrap'>");

printHeader("./",marq);

document.write("<div id='leftside'> <!--navigation--> <ul class='avmenu'> 		<li><a class='current' href='http://www.koshergermany.com/'>Home Page</a></li> 		<li><a href='./kosherGuide.html' title='Kosher Guide Germany'>Rabbi ist das Koscher?</a></li> 		<li><a href='#' onClick=\"navigationCollapse('ProductsNavigation')\">Kosher Lists</a> 		<ul id='ProductsNavigation' style='display:'> 			<li><a href='http://www.ordonline.de/index.php?option=com_kosherlist&view=default&Itemid=20' title='Kosher Products - Germany - Link to ORD site'>Kosher Products</a></li> 			<li><a href='./alcohol.html'>Alcohol Drink List</a></li>  </ul> </li> 		<li><a href='#' onClick=\"navigationCollapse('QANavigation')\">Question & Answers</a> 		<ul id='QANavigation' style='display:'>		<li><a href='./Q&A.html'>FAQ</a></li> 			<li><a href='./questionForm.html'>Ask the Rabbi</a></li> 		</ul>		</li>		<li><a href='./informationPage.html'>Basic Kosher Concepts</a></li>		<li><a href='./travellersGuide.html'>Travellers' Guide</a></li>		<li><a href='./addresses.html' title='Rabbis, Restaurants & Shops'>Important Addresses</a></li>		<li><a href='./bibliography.html'>About Us</a></li>	<li><a href='./contact.html'>Contact Us</a></li>	</ul> <!--/*		<div class='announce'>		<h2>Version history</h2>		<p>Previous versions of the andreas01 website template:</p>		<p><strong>Jan 11, 2007:</strong><br />		Improved: v2.5!</p>		<p><strong>June 25, 2006:</strong><br />	Major upgrade: v2.0.</p>		<p><strong>June 25, 2005:</strong><br />		First release: v1.0.</p>		<p class='textright'><a href='#'>Read more...</a></p>	</div>	/*	<li><a href='#'>Subpage demo</a>		<ul>		<li><a href='#'>Subpage 1</a></li>		<li><a href='#'>Subpage 2</a></li> 		</ul>	</li>	<li>		<a href='print.html'>Print stylesheet</a>	</li>	*/*/--></div>");


printExtra("./");
	