﻿    var Data = new Array();
    var Header = new Array();
    var numData, numHeader;
    var indStatus, indLast, indFirst, indEmail, indOffice, indPhone, indFax, indLogin, indYear, indAdvisor;
    var indWeb, indDegree, indPhD, indTitle, indPhoto, indSound, indAlg, indAnal, indAppl, indLogic, indLat, indGeom, indTop, indProb;
        
    function makeRequest(url) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { displayContents(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send(null);

    }

    function displayContents(httpRequest) {
        var strText = "", strTable = "";
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {            	
                strText = httpRequest.responseText;
                makeData(strText);
                displayData();
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
    
    function makeData(strText) {
    	var i, j, len;
    	var FileData = new Array();
    	FileData = strText.split('\n');
    	Header = FileData[0].split('\t');	
    	numHeader = Header.length - 1;
    	for (j=0; j < numHeader; j++) {
    		switch (Header[j]) {
    			case "Status":
    				indStatus = j;
    				break;
    			case "Last":
    				indLast = j;
    				break;
    			case "First":
    				indFirst = j;
    				break;
    			case "Email":
    				indEmail = j;
    				break;
    			case "Office":
    				indOffice = j;
    				break;
    			case "Phone":
    				indPhone = j;
    				break;
    			case "Fax":
    				indFax = j;
    				break;
    			case "Login":
    				indLogin = j;
    				break;
    			case "Web":
    				indWeb = j;
    				break;
    			case "Title":
    				indTitle = j;
    				break;    				
    			case "Photo":
    				indPhoto = j;
    				break;
    			case "Sound":
    				indSound = j;
    				break;    				
    			case "Degree":
    				indDegree = j;
    				break;
    			case "PhD":
    				indPhD = j;
    				break;
    			case "Year":
    				indYear = j;
    				break;
    			case "Advisor":
    				indAdvisor = j;
    				break;
    			case "Alg":
    				indAlg = j;
    				break;
    			case "Anal":
    				indAnal = j;
    				break;
    			case "Appl":
    				indAppl = j;
    				break;
    			case "Logic":
    				indLogic = j;
    				break;
    			case "Lat":
    			    indLat = j;
    				break;
    			case "Geom":
    				indGeom = j;
    				break;
    			case "Top":
    				indTop = j;
    				break;
    			case "Prob":
    				indProb = j;
    				break;
    			default:
    		}
    	}
    	
    	numData = FileData.length - 2;
    	for (i=0; i < numData; i++){
    		Data[i] = FileData[i+1];
    		Data[i] = Data[i].split('\t');
    		for (j=0; j < numHeader; j++) {
    			if (Data[i][j].indexOf('"') != -1) { // remove double quotes
    				var re = new RegExp('"', "g");
    				Data[i][j] = Data[i][j].replace(re, '');
    			}
    		}
    	}    	
    }
