
/*Custom version of the innerHTML.html script from the Asleson and Schutta book
Re-Scripted by David DuRocher for ADL, January, 2006

insource - the url of the page that is to be the source of information
inDestination - the ID of the container that the "insource" page will land in
inCaller - the id of the item that contains the value that is passed into the "searchInfo"
inHideContainer - supposed to be whether or not to hide the inDestination if it is blank
value - the value to pass in directly

Still in development
*/

var xmlHttp;
var source, destination, caller, hideContainer;

var sources = new Array();
sources[0] = "searchOne";
sources[1] = "searchTwo";

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
/*
example of how to call this script
"javascript:startRequest('http://dev_intranet/work/XHTTPREQUEST/inetoptionResults.asp','liveChange2',this,true);"
As you type use onKeyUp
from a button use onMouseUp etc
*/    
//takes in the script to retrieve, the destination container, and the item that contains the value of the searchInfo
function startRequest(inSource,inDestination,inCaller,inHideContainer) {
			source=inSource;
			destination=inDestination;
			caller=inCaller;
            createXMLHttpRequest();
            xmlHttp.onreadystatechange = handleStateChange;
            xmlHttp.open("GET", source +"?searchInfo="+inCaller.value, true);
            xmlHttp.send(null);
}

/*
specifically for passing in a value through
*/
function startRequestFromValue(inSource,inDestination,value,inHideContainer)
	{
	source=inSource;
	destination=inDestination;
		
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", source +"?searchInfo="+value, true);
	xmlHttp.send(null);
	}

/*
specifically for calling from a select box
onChange="startRequestFromSelect('inetoptionResults.asp','liveChange3',this,false)"
*/
function startRequestFromSelect(inSource,inDestination,inCaller,inHideContainer)
	{
	source=inSource;
	destination=inDestination;
	
	var selectedValue = inCaller.options[inCaller.selectedIndex].value;
	//alert(selectedValue);
	//alert(document.getElementById(inStorageElement).value);
	
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", source +"?searchInfo="+selectedValue, true);
	xmlHttp.send(null);
	}

function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            document.getElementById(destination).innerHTML = xmlHttp.responseText;

			if (xmlHttp.responseText == "")
				{
				document.getElementById(destination).style.display="none"
				}
			else
				{
				document.getElementById(destination).style.display="block"
				}
        }
    }
}