//	showRpt.js
//	Created: 10 May 2006
//	Author: Ray Dahl
//	Project: FIR Datamart Ajax Edition

var xmlHttp;
var searchType = "";
var eo = '';	// eo (Event Object) is different based on the browser


var req;

function createXMLHttpRequest() {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			xmlHttp = new XMLHttpRequest();
        } catch(e) {
			xmlHttp = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlHttp = false;
        	}
		}
    }
}


function startProc(){
	if(xmlHttp.readyState != 4){	
		t = "16px";
		l = "100px";
		document.getElementById('procTip').style.top = t;
		document.getElementById('procTip').style.left = l;
		document.getElementById('procTip').style.visibility = 'visible';
	}
}

function stopProc(){
	document.getElementById('procTip').style.visibility = 'hidden';
}

function displayForm(){ 
	startProc();
	if(xmlHttp.readyState == 4){
		stopProc();
		if(xmlHttp.status==200){
			eval("document.getElementById('"+searchType+"Req').innerHTML = xmlHttp.responseText");
		}
	}
}

function displayData(){ 
	startProc();
	if(xmlHttp.readyState == 4){
		stopProc();
		if(xmlHttp.status==200){
			document.getElementById('rptData').innerHTML = xmlHttp.responseText;
		}
	}
}

function detailRpt(id){
	createXMLHttpRequest();	
	xmlHttp.onreadystatechange = displayData;
	xmlHttp.open("GET", "apps/detailRpt.php?q="+id, true);
	xmlHttp.send(null);
}

function showForm(f){		//	used to display the layer with the correct form elements.
	searchType = f;
	createXMLHttpRequest();	
	xmlHttp.onreadystatechange = displayForm;
	
	switch (searchType){
		case 'name':
			document.getElementById('deptReq').style.display = 'none';
			document.getElementById('rptData').style.display = 'none';
			document.getElementById('nameReq').style.display = 'inline';
			document.getElementById('fQuery').report.value = 'nameReq';
			xmlHttp.open("GET", "apps/nameReq.php", true);
		break;
		case 'dept':
			document.getElementById('nameReq').style.display = 'none';
			document.getElementById('rptData').style.display = 'none';
			document.getElementById('deptReq').style.display = 'inline';
			document.getElementById('fQuery').report.value = 'deptReq';
			xmlHttp.open("GET", "apps/deptReq.php", true);
		break;
	}
	
	xmlHttp.send(null);
}

function getData(type,attrib){
	document.getElementById('intro').style.display = "none";
	document.getElementById('rptData').style.display = 'block';
	createXMLHttpRequest();	
	xmlHttp.onreadystatechange = displayData;
	f = document.getElementById('fQuery');
	
	switch (type){
		case 'nameReq':
			lName = f.lName.value ;	//	gets the last name
			fName = f.fName.value ;	//	gets the first name
			url = "apps/nameRpt.php?lName="+lName+"&fName="+fName;
			xmlHttp.open("GET",url , true);
		break;
		case 'deptReq':
			tDept = f.tDept.options[f.tDept.selectedIndex].value ;	//	gets the tenure home department
			es = f.empStat.options[f.empStat.selectedIndex].value ;	//	gets the employment status
			ft = f.facType.options[f.facType.selectedIndex].value ;	//	gets the employment status
			
			xmlHttp.open("GET", "apps/deptRpt.php?tDept="+tDept+"&empStat="+es+"&facType="+ft, true);
		break;
		case 'deptList':
			url= "apps/deptRpt.php?tDept="+attrib+"&facType=all&empStat=all&qt=dept";
			xmlHttp.open("GET", url, true);
		break;
	}
	xmlHttp.send(null);
}

