// JavaSunrise.js

var gDayOfWeek = 0;
var gDate = 0;
var gMonth = 0;
var anchorTime = 0;

// -------------------------------------------------------

function init_anchor() 
{
	now = new Date();

	gDayOfWeek = now.getDay();		// 0 = Sunday 
	gDate = now.getDate();			// [1..31]
	gMonth = now.getMonth() + 1;

	amt = (gDayOfWeek + 7) * (1000 * 24 * 60 * 60);
	now.setTime(now.getTime() - amt);

	anchorTime = now.getTime();
	
	gDayOfWeek = now.getDay();		// 0 = Sunday 
	gDate = now.getDate();			// [1..31]
	gMonth = now.getMonth() + 1;

	return true
}

// -------------------------------------------------------

function setup_calendar(theMonth) 
{
	now = new Date();

	if (theMonth > 12) 
		{
		now.setFullYear(now.getFullYear()+1);
		now.setMonth(theMonth-13);
		}
	else
		now.setMonth(theMonth-1);

	now.setDate(1);
	
	gDayOfWeek = now.getDay();		// 0 = Sunday 
	gDate = now.getDate();			// [1..31]
	gMonth = now.getMonth() + 1;

	amt = gDayOfWeek * (1000 * 24 * 60 * 60);
	now.setTime(now.getTime() - amt);

	anchorTime = now.getTime();
	
	gDayOfWeek = now.getDay();		// 0 = Sunday 
	gDate = now.getDate();			// [1..31]
	gMonth = now.getMonth() + 1;

	return true
}

// -------------------------------------------------------

function display_date() 
{
	now = new Date();
	switch(now.getDay()){
		case 0: dStr = "Sunday"; break;
		case 1: dStr = "Monday"; break;
		case 2: dStr = "Tuesday"; break;
		case 3: dStr = "Wednesday"; break;
		case 4: dStr = "Thursday"; break;
		case 5: dStr = "Friday"; break;
		case 6: dStr = "Saturday"; break;
	}
	
	document.writeln('Today is ' + dStr + "  " + now.toLocaleDateString() + "<br>");
//	document.writeln("<p>&nbsp;</p>");

	return true
}

// -------------------------------------------------------

function display_page_banner_date(theMonth) 
{
	now = new Date();
	var sYear = "";
	var y = 0;
	
	switch(theMonth){
		case 1: dStr = "January"; break;
		case 2: dStr = "February"; break;
		case 3: dStr = "March"; break;
		case 4: dStr = "April"; break;
		case 5: dStr = "May"; break;
		case 6: dStr = "June"; break;
		case 7: dStr = "July"; break;
		case 8: dStr = "August"; break;
		case 9: dStr = "September"; break;
		case 10: dStr = "October"; break;
		case 11: dStr = "November"; break;
		case 12: dStr = "December"; break;
		case 13: dStr = "January"; break;
	}
	
	y = now.getFullYear();
	if (theMonth > 12)
		y++;
	sYear = y.toString();
	
	document.writeln('Tides for the Month of ' + dStr + ", " + sYear );

	return true
}


// -------------------------------------------------------

function wrGIF(offset)
{
	var d = 0;
	var m = 0;
	var y = 0;
	var sMonth = "";
	var sDay = "";
	var sYear = "";
	var theAmt = offset * (1000 * 24 * 60 * 60);
	
	theDate = new Date();
	
	theDate.setTime(anchorTime + theAmt);
	
	d = theDate.getDate();
	m = theDate.getMonth() + 1;
	y = theDate.getFullYear();
	
	if (m < 10)
		sMonth = "0" + m.toString();
	else
		sMonth = m.toString();
		
	if (d < 10)
		sDay = "0" + d.toString();
	else
		sDay = d.toString();
	
	sYear = y.toString();
	

if (0) {
	document.writeln("<td>");
	document.writeln("Date is " + sDay + "<br>");
	document.writeln("Month is " + sMonth + "<br>");
	document.writeln("</td>");
	}
	
	document.writeln('<td><img src="DayTides/Tides_' + sYear + '_' + sMonth + '_' + sDay + '.gif" width="120" height="120"></td>');

//	document.writeln('<td><img src="DayTides/Tides_2006_04_30.gif" width="120" height="120"></td>');


}

// -------------------------------------------------------

function ouput_week(weeknum)
{

	document.writeln("<tr>");

	 for (var i = 0; i < 7; i++) {
	 	wrGIF((weeknum * 7) + i);
	 	}

	document.writeln("</tr>");

}

// -------------------------------------------------------

function DayOfTheYear()
{
	today = new Date();
	var dayOfYear = 1;
	var nowTime = today.getTime();
	today.setMonth(0);
	today.setDate(1);
	dayOfYear = Math.floor((nowTime - today.getTime()) / (1000 * 24 * 60 * 60));
	return dayOfYear;
}


// -------------------------------------------------------

function output_sunset()
{
	today = new Date();
	var dayOfYear = 1;
	var theStr = "";
	var now = 0;
	var firstofyear = 0;
	
	now = today.getTime();
	today.setMonth(0);
	today.setDate(1);
	dayOfYear = Math.floor( ((now - today.getTime()) / (1000 * 24 * 60 * 60)) / 7 );
	
	switch (dayOfYear + 1) {
		case 1: theStr = "5:05 PM"; break;
		case 2: theStr = "5:12 PM"; break;
		case 3: theStr = "5:19 PM"; break;
		case 4: theStr = "5:27 PM"; break;
		case 5: theStr = "5:35 PM"; break;
		case 6: theStr = "5:42 PM"; break;
		case 7: theStr = "5:50 PM"; break;
		case 8: theStr = "5:57 PM"; break;
		case 9: theStr = "6:04 PM"; break;
		case 10: theStr = "6:10 PM"; break;
		case 11: theStr = "7:16 PM"; break;
		case 12: theStr = "7:22 PM"; break;
		case 13: theStr = "7:28 PM"; break;
		case 14: theStr = "7:34 PM"; break;
		case 15: theStr = "7:40 PM"; break;
		case 16: theStr = "7:46 PM"; break;
		case 17: theStr = "7:52 PM"; break;
		case 18: theStr = "7:58 PM"; break;
		case 19: theStr = "8:04 PM"; break;
		case 20: theStr = "8:10 PM"; break;
		case 21: theStr = "8:16 PM"; break;
		case 22: theStr = "8:21 PM"; break;
		case 23: theStr = "8:25 PM"; break;
		case 24: theStr = "8:28 PM"; break;
		case 25: theStr = "8:30 PM"; break;
		case 26: theStr = "8:31 PM"; break;
		case 27: theStr = "8:31 PM"; break;
		case 28: theStr = "8:29 PM"; break;
		case 29: theStr = "8:25 PM"; break;
		case 30: theStr = "8:20 PM"; break;
		case 31: theStr = "8:14 PM"; break;
		case 32: theStr = "8:07 PM"; break;
		case 33: theStr = "7:58 PM"; break;
		case 34: theStr = "7:49 PM"; break;
		case 35: theStr = "7:39 PM"; break;
		case 36: theStr = "7:29 PM"; break;
		case 37: theStr = "7:18 PM"; break;
		case 38: theStr = "7:08 PM"; break;
		case 39: theStr = "6:57 PM"; break;
		case 40: theStr = "6:47 PM"; break;
		case 41: theStr = "6:36 PM"; break;
		case 42: theStr = "6:27 PM"; break;
		case 43: theStr = "6:18 PM"; break;
		case 44: theStr = "6:10 PM"; break;
		case 45: theStr = "5:03 PM"; break;
		case 46: theStr = "4:58 PM"; break;
		case 47: theStr = "4:54 PM"; break;
		case 48: theStr = "4:51 PM"; break;
		case 49: theStr = "4:51 PM"; break;
		case 50: theStr = "4:52 PM"; break;
		case 51: theStr = "4:54 PM"; break;
		case 52: theStr = "4:59 PM"; break;
		case 53: theStr = "5:04 PM"; break;
		case 54: theStr = "5:11 PM"; break;
		case 55: theStr = "5:18 PM"; break;
	}
	document.writeln(theStr);
}

// -------------------------------------------------------

function output_sunrise()
{
	today = new Date();
	var dayOfYear = 1;
	var theStr = "";
	var now = 0;
	var firstofyear = 0;
	
	now = today.getTime();
	today.setMonth(0);
	today.setDate(1);
	dayOfYear = Math.floor( ((now - today.getTime()) / (1000 * 24 * 60 * 60)) / 7 );
	
	switch (dayOfYear + 1) {
		case 1: theStr = "7:22 AM"; break;
		case 2: theStr = "7:21 AM"; break;
		case 3: theStr = "7:19 AM"; break;
		case 4: theStr = "7:16 AM"; break;
		case 5: theStr = "7:11 AM"; break;
		case 6: theStr = "7:04 AM"; break;
		case 7: theStr = "6:57 AM"; break;
		case 8: theStr = "6:48 AM"; break;
		case 9: theStr = "6:39 AM"; break;
		case 10: theStr = "6:29 AM"; break;
		case 11: theStr = "7:19 AM"; break;
		case 12: theStr = "7:08 AM"; break;
		case 13: theStr = "6:58 AM"; break;
		case 14: theStr = "6:48 AM"; break;
		case 15: theStr = "6:38 AM"; break;
		case 16: theStr = "6:28 AM"; break;
		case 17: theStr = "6:19 AM"; break;
		case 18: theStr = "6:11 AM"; break;
		case 19: theStr = "6:04 AM"; break;
		case 20: theStr = "5:58 AM"; break;
		case 21: theStr = "5:53 AM"; break;
		case 22: theStr = "5:50 AM"; break;
		case 23: theStr = "5:48 AM"; break;
		case 24: theStr = "5:48 AM"; break;
		case 25: theStr = "5:49 AM"; break;
		case 26: theStr = "5:51 AM"; break;
		case 27: theStr = "5:55 AM"; break;
		case 28: theStr = "5:59 AM"; break;
		case 29: theStr = "6:04 AM"; break;
		case 30: theStr = "6:10 AM"; break;
		case 31: theStr = "6:15 AM"; break;
		case 32: theStr = "6:21 AM"; break;
		case 33: theStr = "6:27 AM"; break;
		case 34: theStr = "6:33 AM"; break;
		case 35: theStr = "6:38 AM"; break;
		case 36: theStr = "6:44 AM"; break;
		case 37: theStr = "6:49 AM"; break;
		case 38: theStr = "6:55 AM"; break;
		case 39: theStr = "7:01 AM"; break;
		case 40: theStr = "7:06 AM"; break;
		case 41: theStr = "7:12 AM"; break;
		case 42: theStr = "7:18 AM"; break;
		case 43: theStr = "7:25 AM"; break;
		case 44: theStr = "7:32 AM"; break;
		case 45: theStr = "6:39 AM"; break;
		case 46: theStr = "6:46 AM"; break;
		case 47: theStr = "6:53 AM"; break;
		case 48: theStr = "7:00 AM"; break;
		case 49: theStr = "7:06 AM"; break;
		case 50: theStr = "7:12 AM"; break;
		case 51: theStr = "7:17 AM"; break;
		case 52: theStr = "7:20 AM"; break;
		case 53: theStr = "7:21 AM"; break;
		case 54: theStr = "7:21 AM"; break;
		case 55: theStr = "7:20 AM"; break;
	}
	document.writeln(theStr);
	return 0;
}

// -------------------------------------------------------

// -------------------------------------------------------

function setup_next_month()
{
	var theStr = "";
	
	now = new Date();
	gMonth = now.getMonth();
	
	switch (gMonth+2) {
		case  1: theStr = "JanTides.htm"; break;
		case  2: theStr = "FebTides.htm"; break;
		case  3: theStr = "MarTides.htm"; break;
		case  4: theStr = "AprTides.htm"; break;
		case  5: theStr = "MayTides.htm"; break;
		case  6: theStr = "JunTides.htm"; break;
		case  7: theStr = "JulTides.htm"; break;
		case  8: theStr = "AugTides.htm"; break;
		case  9: theStr = "SepTides.htm"; break;
		case 10: theStr = "OctTides.htm"; break;
		case 11: theStr = "NovTides.htm"; break;
		case 12: theStr = "DecTides.htm"; break;
		case 13: theStr = "JanNxTides.htm"; break;
		case 14: theStr = "JanNxTides.htm"; break;
		}
		
	document.writeln( '<A HREF="' + theStr + '">Next Months Tides -></A><br>'  );
	return 0;
}

// -------------------------------------------------------
// End of File

