var requestVars;
var tableDiv;
//basic Ajax function call, all functions with request call this one, after formatting the request string
//url: the aspx file to handle the server stuff
//targetDiv: Where to put the output of the aspx file
//requestVar: the request variables sent to the aspx file, it uses the get method
function sendRequest (url, targetDiv, requestVar){

	var req = createXMLHTTPObject();
	if (!req){ 
		//alert ("Not Found");
		return;
	}
	
	url += "?r=" + requestVar; 

	req.onreadystatechange = function (){
		if (req.readyState==4){ //ready state
			//alert(req.status);			
			if (req.status == 200){ //OK status
				//alert("Reponse Text");				
				var response = req.responseText;
				document.getElementById(targetDiv).innerHTML = response; //set response			
			}else{
				//alert(req.responseText);
				alert("Problem: " + req.statusText + " " +req.status);
			}
		}else{
			document.getElementById(targetDiv).innerHTML = '<span class="loading">Loading...</span>'; //loading message
		}
	}
	
	req.open("GET", url, true); //send request to file
	req.send(null);			
}
//the creation functions for XmlHttpObjects for the different browsers
var XMLHttpFactories = [
	function() {return new XMLHttpRequest()}, //firefox
	function() {return new ActiveXObject("Microsoft.XMLHTTP")}, //IE
	function() {return new ActiveXObject("Msxml2.XMLHTTP")}, //IE
	function() {return new ActiveXObject("Msxml3.XMLHTTP")} //IE
];
//create a XmlHttpObject using the different methods for different browsers
function createXMLHTTPObject(){
	var xmlhttp = false;
	
	for (var n=0; n<XMLHttpFactories.length; n++){
		try{
			xmlhttp = XMLHttpFactories[n]();
		}catch (e){
			continue;
		}
		break;
	}
	return xmlhttp;
}

//the year of WQI info has been changed, called from dropdownlist
function sendDivision(divisionID){	
	//alert(requestVar);
	sendRequest ('DivisionOutput.aspx','divisionInfo',divisionID);
	var ullist = document.getElementById("submenulist").childNodes;	
	
	for (var n=0; n<ullist.length; n++){
	 
	    if (ullist[n].tagName == 'LI'){
	        if (ullist[n].id == 'divisionlist'+divisionID){
	            ullist[n].className = 'submenu-select';
	        }else{
	            ullist[n].className = 'submenu';
	        }
	    }	 
	    //alert(ullist[n].className);
	}
	return false;
}
function printTheDiv(divid){
alert("GAAH!!");
    /*var div = Document.getElementById(divid);
    var winPrint = window.open('','','left=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
    winPrint.document.open();
    winPrint.document.write (div.innerHTML);
    winPrint.document.close();
    winPrint.focus();
    winPrint.print();
    //winPrint.close();    */
}
