//Retrieves event information for a specified day
function getEvent(mon, day, year)
{
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url = "events.php?mon=" + mon;
	url += "&day=" + day;
	url += "&year=" + year;
	url += "&get=1";
	xmlHttp.onreadystatechange = stateChangedGetEvent;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

//Retrieves all Events for the month
function getAllEvents(mon, year)
{
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url = "events.php?mon=" + mon;
	url += "&year=" + year;
	url += "&get=2";
	xmlHttp.onreadystatechange = stateChangedGetEvent;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

//Retrieves all events for a specified type (i.e. Educational)
function getEventType(type, mon, year)
{
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url = "events.php?type=" + type;
	url += "&mon=" + mon;
	url += "&year=" + year;
	url += "&get=3";

	xmlHttp.onreadystatechange = stateChangedGetEvent;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChangedGetEvent()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		var xmlDoc = xmlHttp.responseXML;
		//alert(xmlDoc);return;
		
		var str = "";
		var event_list = xmlDoc.getElementsByTagName('event');
		if(event_list.length == 0)
			str = "There are no events for this criteria at this time.";
		else
		{
			for(var i = 0; i < event_list.length; i++)
			{
				var title = xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue;
				var desc  = xmlDoc.getElementsByTagName('desc')[i].childNodes[0].nodeValue;
				var url   = xmlDoc.getElementsByTagName('url')[i].childNodes[0].nodeValue;
				var email = xmlDoc.getElementsByTagName('email')[i].childNodes[0].nodeValue;
				var cat   = xmlDoc.getElementsByTagName('cat')[i].childNodes[0].nodeValue;
				var start = xmlDoc.getElementsByTagName('start')[i].childNodes[0].nodeValue;
				var end   = xmlDoc.getElementsByTagName('end')[i].childNodes[0].nodeValue;
				var date  = xmlDoc.getElementsByTagName('date')[i].childNodes[0].nodeValue;
				
				//Change military time to standard time
				var tmp = start.split(':');
				if ((tmp[0] * 1) > 12) {
					tmp[0] = tmp[0] * 1 - 12;
					start = tmp.join(':');
					start += " pm";
				}
				else {
					tmp[0] = tmp[0] * 1;
					start = tmp.join(':');
					start += " am";	
				}
				
				tmp = end.split(':');
				if ((tmp[0] * 1) > 12) {
					tmp[0] = tmp[0] * 1 - 12;
					end = tmp.join(':');
					end += " pm";
				}
				else {
					tmp[0] = tmp[0] * 1;
					end = tmp.join(':');
					end += " am";
				}
				
				str += "<h1>" + title + " - " + cat + "</h1>" + desc + "<br />"
				if (url != "NULL") {
					var google = "<a href=\"http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=";
					google += escape(url.replace(/http:\/\//, ""));
					google += "&sll=34.132892,-117.869565&sspn=0.007238,0.008723&ie=UTF8&z=17\">";
					
					str += google + "Click to View in Google Maps<br /></a>";
				}
				str += "<i>" + date + "</i><br />" + start + " - " + end;
			
				if(email != "NULL")
					str += "<br /><a href=\"mailto:" + email + "\">" + email + "</a>";
				
				if(title == "3rd Annual Martini Madness")
				{
					str += '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
					str += '<input type="hidden" name="cmd" value="_s-xclick">';
					str += '<input type="hidden" name="hosted_button_id" value="8894011">';
					str += '<table>';
					str += '<tr><td><input type="hidden" name="on0" value="Prices">Prices</td></tr><tr><td><select name="os0">';
					str += '<option value="Single">Single $95.00';
					str += '<option value="Couple">Couple $175.00';
					str += '</select> </td></tr>';
					str += '</table>';
					str += '<input type="hidden" name="currency_code" value="USD">';
					str += '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">';
					str += '<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">';
					str += '</form>';
					/*str += '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
					str += '<input type="hidden" name="cmd" value="_s-xclick">';
					str += '<input type="hidden" name="hosted_button_id" value="8894011">';
					str += '<table>';
					str += '<tr><td><input type="hidden" name="on0" value="Prices">Prices</td></tr><tr><td><select name="os0">';
					str += '<option value="Single">Single $95.00';
					str += '<option value="Couple">Couple $175.00';
					str += '</select> </td></tr>';
					str += '</table>';
					str += '<input type="hidden" name="currency_code" value="USD">';
					str += '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">';
					str += '<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"';
					str += '</form>';*/
				}
				str += "<br /><br />";
			}
		}
		document.getElementById('events').innerHTML = str;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
 	{
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp = new XMLHttpRequest();
 	}
	catch (e)
 	{
 		//Internet Explorer
 		try
  		{
  			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e)
  		{
  			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}