// --------------------------------------------------------
//
// File:     dept-cat.js
// Author:   Paul Lieberman
// Created:  2006
//
// Purpose: Javascript functions for department Catalog and Schedule pages
//
//
// Modified:
//      
//      17-Nov-2206 - PL - Added schedule. Left the name as dept-cat.js to avoid having to change Publish template
//
// -----------------------------------------------------------

// Display Faculty Information
function facdat_name(name) {
    var url = "/cgi/userinfo.cgi?name=" + name;
    var cwind = window.open(url,'','width=680,height=350,toolbar=no,location=no,resizable=no,status=no,scrollbars=no,menubar=no');
}

// Faculty info Popup
function facdat_id(id) {
    var url = "/cgi/userinfo.cgi?id=" + id;
    var cwind = window.open(url,'','width=680,height=350,toolbar=no,location=no,resizable=no,status=no,scrollbars=no,menubar=no');
}

// ---------- Catalog -----------------------


// Display different catalog year
function catyear(year, dept) {
    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    if (!http_request) {
        alert('Giving upÊ:( Cannot create an XMLHTTP instance');
        return false;
    }           
    
    http_request.onreadystatechange = function() { displayCatalog(http_request); };
    http_request.open('GET', '/cgi/dept-cat.cgi?dept=' + dept + '&year=' + year, true);
    http_request.send(null);

}

function displayCatalog(http_request) {

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
           var xmldoc = http_request.responseText;
           var catdiv = document.getElementById("catalog");
           catdiv.innerHTML = xmldoc;
                      
        } else {
            alert('There was a problem with the request.');
        }
    }

}


// ------------ Schedule ---------------------

// Course description popup window
function course(subj, num, term, crn, title) {
    var url = "/cgi/course.cgi?subj=" + subj + "&num=" + num + "&term=" + term + "&crn=" + crn + "&title=" + title;
        var cwind = window.open(url,'','width=450,height=300,toolbar=no,location=no,resizable=yes,status=no,scrollbars=no,menubar=no');
}

// Check print
	function chkprint() {
		if (document.sched.print.checked) {
			with(document.sched){			
				subject  = subj.value;
				for (var i = 0; i < term.length; i++){
					if (term[i].checked) {
						termcode = term[i].value;
					}
				}
			}
			var url = "schedule.cgi?sprint=1&subj=" + subject + "&term=" + termcode;
			var pwin = window.open(url,'pwin','width=800,height=600,toolbar=yes,location=no,resizable=yes,status=no,scrollbars=yes,menubar=yes');
			pwin.focus();
		}
	}


// Footnotes
function footnote(subj,term) {
    var url = "/cgi/footnote.cgi?subj=" + subj + "&term=" + term;
    var cwind = window.open(url,'','width=600,height=400,toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,menubar=no');
}


// Display different term
function schedterm(term, subj) {
    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    if (!http_request) {
        alert('Giving upÊ:( Cannot create an XMLHTTP instance');
        return false;
    }           
    
    http_request.onreadystatechange = function() { displaySchedule(http_request); };
    http_request.open('GET', '/cgi/deptsched.cgi?subj=' + subj + '&term=' + term, true);
    http_request.send(null);

}

function displaySchedule(http_request) {

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
           var xmldoc = http_request.responseText;
           var catdiv = document.getElementById("schedule");
           catdiv.innerHTML = xmldoc;
                      
        } else {
            alert('There was a problem with the request.');
        }
    }

}
    