// JavaScript Document
/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

function processAJAX(action, passvalue){
	if ((action=='ADD_DEPT') || (action == 'REM_DEPT'))
	{
		if (action == 'ADD_DEPT')
			passvalue = document.form1.department_list.options[document.form1.department_list.selectedIndex].value;
		http.open('get', 'internal_request.php?action=' + action + 
			'&id=' + passvalue + 
			'&departments_selected=' + document.form1.departments_selected.value);
		http.onreadystatechange = handleProducts; 
		http.send(null);
	}
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('selectedareas').innerHTML = response;
	}
}

function getCounties(stateval)
{
	http.open('get', 'countylist.php?state='+stateval);
	http.onreadystatechange = handleCounties; 
	http.send(null);
}

function handleCounties(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('countyquest').innerHTML = response;
	}
}
