/*****************************************************************************
**		 __      __  ____     ____     __  __  ________   ________      	**
**		/\ \  __/\ \/\  _`\  /\  _`\  /\ \/\ \/\_____  \ /\_____  \    		**
**		\ \ \/\ \ \ \ \ \L\ \\ \ \L\ \\ \ \ \ \/____//'/'\/____//'/'   		**
**		 \ \ \ \ \ \ \ \  _ <'\ \  _ <'\ \ \ \ \   //'/'      //'/'    		**
**		  \ \ \_/ \_\ \ \ \L\ \\ \ \L\ \\ \ \_\ \ //'/'___   //'/'___  		**
**		   \ `\___x___/\ \____/ \ \____/ \ \_____\/\_______\ /\_______\		**
**			'\/__//__/  \/___/   \/___/   \/_____/\/_______/ \/_______/		**
**																			**
**	This site created by Drew Loomer for the West Bloomfield Township 		**
**	Public Library Youth Department.  										**
**	Completed on 9-14-2009													**
**	loomerdr@wblib.org														**
**	Sorry about the lame ASCII art - it was just too tempting...			**
**																			**
**	This page holds the AJAX that is used when a user clicks on an entry	**
**	in the calendar.  														**
**																			**
*****************************************************************************/


//Global variable
var xmlhttp;


//Replace the information in the target div with that of another
function replaceContent (source)
{
	//Create the XML Object
	xmlhttp = getXmlHttpObject();

	//If the browser doesn't support XMLHTTP, tell them their browser is too old
	if (xmlhttp == null)
	{
		document.writeln("Your browser is too old to support this calendar.");
		return;
	}

	//Call our php script
	var url = "get_program.php";
	url = url + "?eid=" + source;
	url = url + "&sid=" + Math.random();

	xmlhttp.onreadystatechange = stateChanged;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);

	showBox("calendarBoxContent");

}


//Function to fade in the div.		
function showBox(box)
{

	//Display the box and set its opacity to 0			
	document.getElementById(box).style.display = "inline";
	document.getElementById(box).style.opacity = 0;
	document.getElementById(box).style.filter = "alpha(opacity=0)";
				
	
	//Loop through and increment the opacity.			
	var timer = 0;
	var i = 0;


	while (i != 50)
	{
	
		setTimeout("changeOpac(" + (i * 2) + ",'" + box + "')", (timer * 3));
						
		timer++;
		
		i++;
				
	}
	
}
		
		
//Function to fade out the black box		
function hideBox(box)
{
			
	//Display the login box and set its opacity to 100			
	document.getElementById(box).style.display = "inline";
	document.getElementById(box).style.opacity = 1;	
	document.getElementById(box).style.filer = "alpha(opacity=100)";	
	
	
	//Loop through a decrement the opacity.		
	var timer = 0;				
	var i = 50;


	while (i != 0)
	{								
		setTimeout("changeOpac(" + (i * 2) + ",'" + box + "')", (timer * 3));
		
		timer++;
		
		i--;				
	}
	
	setTimeout("resetBoxes('" + box + "')", 500);
						
}


//Function to reset the fading box
function resetBoxes(box)
{
	document.getElementById(box).style.display = "none";
}






//Function to determine which XML request to use.
function getXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;
}



function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		var rep = document.getElementById("calendarBoxContent");
		rep.innerHTML = xmlhttp.responseText;
		rep.style.display = "inline";		
	}
}



//Show the text of a procedures entry
function showGroup (name)
{
	//Get the element name.
	var divName = document.getElementById(name);
	
	
	//If it isn't visible, display it and change the image next to the link.  
	if (divName.style.display == "none" || divName.style.display == "")
	{
		divName.style.display = "inline";
		var imgName = document.getElementById(name + "_img");
		imgName.src = "../images/open_box.gif";	
	}
	else
	{
		divName.style.display = "none";
		var imgName = document.getElementById(name + "_img");
		imgName.src = "../images/closed_box.gif";
	}
	
	
	//Unselect the link because it looks stupid.
	if (document.selection)
	{
		document.selection.empty();
	}
	else if (window.getSelection)
	{
		window.getSelection().removeAllRanges();	
	}
}
