/*
 * displayPage (page url, element ID) - Requests a page and displays it in the specified element space.
*/
var request = null;
var ID = null;


function searchDatabase()
{
	var code = document.searchSelect.code.value;
	var state = document.searchSelect.state.value;
	var abet = document.searchSelect.abet.value;
	var degree = document.searchSelect.degree.value;
	var searchString = "searchDatabase.php?";
									 
	if (code != 'ALL')
	{
		searchString = searchString + "code=" +code+ "&";
	}
	if (state != 'ALL')
	{
		searchString = searchString + "state=" +state+ "&";
	}
	if (abet != 'ALL')
	{
		searchString = searchString + "abet=" +abet+ "&";
	}
	if (degree != 'EVERYTHING')
	{ 
		searchString = searchString + "degree=" +degree+ "&";
	}
	displayPage(searchString,'content');
	
}

function listStateInstitutions()
{
		var state = document.listState.state.value;
		var func = "listSchools";
		
		if (state != 'ALL')
		{
			searchString = "searchDatabase.php?state=" +state+ "&func="+func;
		}
		else 
		{
			searchString ="searchDatabase.php?func=" +func;
		}
		displayPage(searchString,'content');
}

function watchState(ID)
{
		if (request.readyState==1)
		{
			document.getElementById(ID).innerHTML="Please wait... Loading...";
		}
		
		if (request.readyState==4 || request.readyState=="complete")
		{
			document.getElementById(ID).innerHTML=request.responseText;
		}
}

function displayText(text, ID)
{
	document.getElementById(ID).innerHTML=text;
}

function displayPage(page, ID)
{

		
		//Creates an XMLHttpRequest object for most modern browsers with the exception of Internet Explorer.
		if (window.XMLHttpRequest != null)
		{
			request = new XMLHttpRequest();
			request.onload=function() { watchState(ID); };
			request.onerror=function() { watchState(ID); };
			request.onreadystatechange=function() { watchState(ID); };
		}
		else
		{
			//The browser must be Internet Explorer, so an ActiveX object must be created.
			try
			{	
				request = new ActiveXObject("Microsoft.XMLHTTP");
				request.onreadystatechange=function() { watchState(ID); };
			}
			catch(e)
			{
				try
				{
					request = new ActiveXObject("Msxml2.XMLHTTP");
					request.onreadystatechange=function() { watchState(ID); };
				}
				catch(e)
				{
					alert("Error.  If you are using Microsoft Internet Explorer, ActiveX objects may not be enabled.");
				}
			}
		}
	
		try
		{
			if (request != null)
			{
				request.open("GET",page,true);
				request.send(null);
				scroll(0,0);
			}
		}
		catch (e)
		{
			alert("Warning: Failed to create the XMLHttpRequest object.");
		}
	
}