var xmlHttp

// Show the specials
function addRating(id)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="helper.php"
	url=url+"?mode=rating&id="+id
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function addComment()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	var comment = document.addcomment.comment.value;

	var url="helper.php"
	url=url+"?comment="+comment;
	document.addcomment.comment.value = "";

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

// Process the specials update
function updateSpecials()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	var dropdown = document.getElementById("specials");
	var myindex  = dropdown.selectedIndex
	var daySelected = dropdown.options[myindex].value

	var parameterString = "";

	for (counter = 1; counter <= 3; counter++){
		var current_special = "special_"+counter;
		var special_value = document.getElementById(current_special).value;
		parameterString = parameterString + "&special_" + counter + "=" + special_value; 
	}

	var url="update_specials.php"
	url=url+"?day="+daySelected+parameterString;
	xmlHttp.onreadystatechange=stateChanged

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function addEvent(mode)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	/* Gather the event data */

	/* Send Event data */

	var event_name = document.getElementById("event_name").value;
	var event_location = document.getElementById("event_location").value;
	var start = document.getElementById("start").value;
	var stop = document.getElementById("stop").value;

	// TODO: Can we pass the form values as an array?....

	parameterString = "&event_name="+event_name
						+"&event_location="+event_location
						+"&start="+start
						+"&stop="+stop;

	var url="event_handler.php"
	url=url+"?mode="+mode+parameterString;
	xmlHttp.onreadystatechange=stateChanged

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

// Return information back to the calling page div
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("rating").innerHTML=xmlHttp.responseText 
 } 
}

function commentAdded() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("comments").innerHTML=xmlHttp.responseText;
 } 
}

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;
}
