/*
courseList.js
last modified 11/26/06
created by Darren Smith

loads course list XML data and outputs it as formatted HTML
*/

var reqList;

function getList(){
	loadListXMLData("_data/getCourseList.php");
}
function loadListXMLData(url){
	reqList = false;
	//find available XML object
    if(window.XMLHttpRequest) {
    	try {
			reqList = new XMLHttpRequest();
			if (reqList.overrideMimeType) {
				reqList.overrideMimeType('text/xml');
			}
        } catch(e) {
			reqList = false;
        }
    } else if(window.ActiveXObject) {
       	try {
        	reqList = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqList = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqList = false;
        	}
		}
    }
	//if XML capable, set listener, open XML document
	if(reqList) {
		reqList.onreadystatechange = processReqListChange;
		reqList.open("GET", url, true);
		reqList.send("");
	}
}
function processReqListChange() {
	//wait for loading to complete
    if (reqList.readyState == 4) {
		//make sure loading was successful
        if (reqList.status == 200) {
			writeList();
        } else {
			//failure alert
            alert("There was a problem retrieving the XML data:\n" + reqList.statusText);
        }
    }
}
function writeList(){
	//determine number of courses
	var numLinks = reqList.responseXML.firstChild.childNodes.length;
	//build course table
	var linkTable = '<table class="courseList">';
	var rowType = "oddRow";
	//loop through each course and add to the courseTable
	for(var i = 0; i < numLinks; ++i){
		linkTable += '<tr class="' + rowType + '"><td>';
		linkTable += '<div style="padding-top: 5px;"><a href="javascript:getDetailsPopup(' + reqList.responseXML.firstChild.childNodes[i].firstChild.firstChild.nodeValue + ')" ';
		linkTable += 'onMouseOver="window.status=\'Course Information\'; return true;" ';
		linkTable += 'onMouseOut="window.status=\'Done\'; return true;">';
		linkTable += reqList.responseXML.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue + '</a></div>';
		linkTable += '</td></tr>';
		if(rowType == "oddRow"){
			rowType = "evenRow";
		} else {
			rowType = "oddRow";
		}
	}
	linkTable += '</table>';
	//populate course table
	document.getElementById("courseLinks").innerHTML = linkTable;
}
