var months = new Array("January", "February", "March", 
					   "April", "May", "June", "July", "August", "September", 
					   "October", "November", "December");
	
var weekdays = new Array("Sunday", "Monday", "Tuesday",
						 "Wednesday", "Thursday", "Friday", "Saturday");


/*
 * Converts the start/stop time from (ex. 5:00 pm, 6:30 pm) to 5-6:30pm
 * and adds the date (ex. 5-6:30pm - thursday, january 31)
 */
function formatStartStopDateTime(start, stop, eventDate)
{
	//alert(eventDate);
	
	if (start.search("am") >= 0 && stop.search("am") >= 0)		// start and stop time = 'am'
	{
		start = start.replace("am", "");
		start = start.replace(" ", "");
	}
	else if (start.search("pm") >= 0 && stop.search("pm") >= 0)		// start and stop time = 'pm'
	{
		start = start.replace("pm", "");
		start = start.replace(" ", "");
	}
	else
	{
		start = start.replace(" ", "");
	}
	
	// remove the space between the time and 'am/pm' from the stop time
	stop = stop.replace(" ", "");
	
	// remove ':00' from the start and stop times
	start = start.replace(":00", "");
	stop = stop.replace(":00", "");
	
	// add a dash between the start and stop times
	var time = (stop != "") ? start + "-" + stop : start;
	
	// create the date string
	var date = null;
	
	if (eventDate == "true")	// set today's date
	{
		date = new Date();
	}
	else if (eventDate == "false")	// set tomorrow's date
	{
		var today = new Date();
		date = new Date((today.getMonth() - 0 + 1) + "/" + 
						(today.getDate() - 0 + 1) + "/" + 
						 today.getFullYear());
	}
	else	// set the date using the given upcoming date
	{
		date = new Date(eventDate);
	}
	
	var weekday = date.getDay();
	var day = date.getDate();
	var month = date.getMonth();
	var strDate = weekdays[weekday] + ", " + months[month] + " " + day;
	
	return time + " &#150; " + strDate.toLowerCase();
}

function getHTML()
{
	//var url = 'http://www.rockharbor.org/resources/locations/content.php';
	var url = 'http://localhost/locations/content.php';
	var pars = '?'+Date();
	
	var myAjax = new Ajax.Updater(
		'events', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});
	setTimeout("getHTML()",1000)		
}

function displayDateTime()
{
	if (!document.all && !document.getElementById)
		return;
	
	var date = new Date();
	var hours = date.getHours();
	var minutes = date.getMinutes();
	var seconds = date.getSeconds();
	var ampm = "PM";
	
	if (hours < 12) ampm = "AM";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;
		
	var time = hours + ":" + minutes + " " + ampm;
	var weekday = date.getDay();
	var month = date.getMonth();
	var day = date.getDate();
	var todaysDate = weekdays[weekday] + ", " + months[month] + " " + day;
	var todaysDateTimeHtml = formatDateTime(todaysDate.toLowerCase(), time.toLowerCase());
	
	return todaysDateTimeHtml;
}

function formatDateTime(strDate, strTime)
{
	var html = "<table class='datetime' cellpadding='0' cellspacing='0'>" + 
			   "  <tr>" + 
			   "    <td class='datetime' align='center' valign='bottom'>" + 
	  		   		  strDate + "&nbsp;&nbsp;&#8212;&nbsp;&nbsp;" + strTime + 
	  		   "    </td>" + 
	  		   "  </tr>" + 
	  		   "</table>";
	return html;
}

var sURL = unescape(window.location.pathname);

function doLoad()
{
	setTimeout("refresh()", 30 * 60 * 1000);
}

function refresh()
{
    window.location.href = sURL;
}

