/*
FUNCTION to run multiple functions upon refresh/reload
*/
function LoadFuncs()
{
	if (perform_function == 1)
	{
		loadState();
	}
}

var xmlhttp;
var stateIdx;
var formname="application-supplement";

/*
FUNCTIONS to process the XML document
*/
function getXML()
{
	var newXML = null;
	if(window.XMLHttpRequest) 
	{
		try 
		{
			newXML = new XMLHttpRequest();
		}
		catch(e) 
		{
			newXML = false;
		}
	}
	else if(window.ActiveXObject) 
	{
		try 
		{
			newXML = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) 
		{
			try 
			{
				newXML = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) 
			{
				newXML = false;
			}
		}
	}
	return newXML;
}

function loadXMLDoc(url, stateIndex) 
{
	stateIdx = stateIndex;
	url= url +"?RandomKey="+ Math.random() * Date.parse(new Date());
	//document.getElementById("test").innerHTML = url;
	xmldoc=null;
	if(xmlhttp==null)
	{
		xmlhttp = getXML();
	}
	else if(xmlhttp)
	{
		xmlhttp.abort();
	}

	if(xmlhttp) 
	{
		xmlhttp.onreadystatechange = processReqChange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send("");
	}
	else
	{
		alert("The XMLHttpRequest Object is not supported");
	}
}

function findCEEB(url, hsIndex) 
{
	hsIdx = hsIndex;
	url= url +"?RandomKey="+ Math.random() * Date.parse(new Date());
	//document.getElementById("test").innerHTML = url;
	xmldoc=null;
	if(xmlhttp==null)
	{
		xmlhttp = getXML();
	}
	else if(xmlhttp)
	{
		xmlhttp.abort();
	}

	if(xmlhttp) 
	{
		xmlhttp.onreadystatechange = processHSChange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send("");
	}
	else
	{
		alert("The XMLHttpRequest Object is not supported");
	}
}

function processReqChange()
{
	var tempindex = 0;
	if (xmlhttp.readyState == 4) 
	{
		if (xmlhttp.status == 200 || xmlhttp.status == 0) 
		{
			xmlDoc = xmlhttp.responseXML;

			var stateAbbr = document.forms[formname].hs_state.options[stateIdx].value;
			var hs_list = document.getElementById("hs_name");
			var name_html= "";
			var StateLen = xmlDoc.getElementsByTagName(stateAbbr);
			var i=0;
			var optionTemp = null;
			document.forms[formname].hs_name.options.length = 1;
			document.forms[formname].hs_name.options[0] = new Option('select school:', '');
			var curOption = 1;
			for (i=0; i<StateLen.length; i++)
			{
				optionTemp = StateLen[i].childNodes[0].firstChild.nodeValue;
				if (the_name == optionTemp)
				{
					tempindex = curOption;
				}
				
				document.forms[formname].hs_name.options[curOption] = new Option(optionTemp, optionTemp);
				curOption++;
			}
			document.forms[formname].elements["hs_name"].selectedIndex = tempindex;
			
		}
		else 
		{
			alert("There was an issue retrieving the data:\n" + "Reason: " + xmlhttp.statusText);
		}
	} 
	else
	{
		document.forms[formname].hs_name.options.length = 1;
		document.forms[formname].hs_name.options[0] = new Option("Loading...", "Loading...");
	}
}

function processHSChange()
{
	var tempindex = 0;
	if (xmlhttp.readyState == 4) 
	{
		if (xmlhttp.status == 200 || xmlhttp.status == 0) 
		{
			xmlDoc = xmlhttp.responseXML;
			var stateIdx = document.getElementById("hs_state").selectedIndex;
			var stateAbbr = document.getElementById("hs_state").options[stateIdx].text;
			var hsCEEB = xmlDoc.getElementsByTagName(stateAbbr)[hsIdx-1].childNodes[1].firstChild.nodeValue;
			document.forms[formname].hs_CEEB.value = hsCEEB;
			
//			tempvar = document.getElementById("how_influenced_rhodes");
//			tempvar.value = "the ceeb code is: " + hsCEEB;
			
		}
		else 
		{
			alert("There was an issue retrieving the data:\n" + "Reason: " + xmlhttp.statusText);
		}
	} 
}

/* function to show/hide big text blocks
*/

function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}


/*
FUNCTION to load 1st dropdown with the states
*/
function loadState()
{
	var i=0;
	var tempindex = 0;
	var optionTemp = null;
/*	document.forms[formname].hs_state.options.length = 1; */
	document.getElementById("hs_state").options.length = 1;
	var curOption = 0;


	optionTemp = "select state:";
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "AL";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "AZ";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "AR";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "CA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "CO";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "CT";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "DE";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "DC";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "FL";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "GA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "HI";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "ID";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "IL";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "IN";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "IA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "KS";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "KY";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "LA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "MA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "ME";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MD";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MS";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MI";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MN";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MS";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MO";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "MT";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "NE";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NV";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NH";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NJ";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NM";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NY";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "NC";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "ND";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "OH";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "OK";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "OR";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "PA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "RI";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "SC";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "SD";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "TN";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "TX";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	curOption++;
	optionTemp = "UT";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "VT";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "VA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);

	curOption++;
	optionTemp = "WA";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "WV";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "WI";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	curOption++;
	optionTemp = "WY";
	if (the_state == optionTemp)
	{
		tempindex = curOption;
	}
	document.forms[formname].hs_state.options[curOption] = new Option(optionTemp, optionTemp);
	
	document.forms[formname].elements["hs_state"].selectedIndex = tempindex;
	if (tempindex >= 1)
	{
		loadXMLDoc('HS4WEBCEEB.xml', tempindex);
	}
}