/* This is the javascript used to implement the AJAX for the custom frames page.  It first adds the event handler to the dropdown menus, calling the server anytime either
of the menus is changed.  It takes the resulting table from the server and replaces the appropriate div with that table.  */

var request;
var sizenode;
var sortnode;

function ajaxCall() {
	// From "Head Rush Ajax" by Brett McLaughlin
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = null;
			}
		}
	}
	
	if (request == null) {
		alert("Error creating request object!");
	}
}

function process(event) {
	
	var z= "cframesearch.php?query="+sizenode.value+"&sort="+sortnode.value;
	
	//Send Data to Server via a GET request
	request.open("GET",z,true);
	request.onreadystatechange = callback;
	request.send(null);
}

function initialize() {
	sizenode = document.getElementById("framesize");
	sortnode = document.getElementById("sort");
	sizenode.onchange= process;
	sortnode.onchange= process;
	
	request = null;
	ajaxCall();
}

function callback(){
	
	//Check if server is still processing the call...
	if(request.readyState<4){
		return;
	}
	
	else if (request.responseText == "") {
		return;
	}
	
	else {
		document.getElementById("results").innerHTML = request.responseText;
	}
}
