Skip to content
Snippets Groups Projects
search-box.js 5.57 KiB
addLoadEvent(onLoadPublicViewSearch);

function onLoadPublicViewSearch()
{
    if (document.getElementById('refineSearchLink')) {
        document.getElementById('refineSearchLink').onclick = handleRefineSearchLinkClick;
    }
    document.getElementById('college').onchange = handleChangeSelectHierarchy;
    document.getElementById('department').onchange = handleChangeSelectHierarchy;
    handleChangeSelectHierarchy();
    
    if (document.getElementById('printButton')) {
        document.getElementById('printButton').onclick = function() {
            window.print();
        };
    }

    var helpLinks = getElementsByClassName('hoverHelp');
    for (var i = 0; i < helpLinks.length; i++) {
        helpLinks[i].onmouseover = displayHoverHelp;
        helpLinks[i].onmouseout = hideHoverHelp;
        helpLinks[i].onclick = function() {return false;};
    }
    
    document.getElementById('ace').onclick = function() {
        document.getElementById('aceOutcomes').disabled = !this.checked;
        var options = document.getElementById('aceOutcomes').getElementsByTagName('option');
        for (var i = 0; i < options.length; i++) {
            options[i].selected = this.checked;
        }
        document.getElementById('aceOutcomes').focus();
    }
    
    if (document.getElementById('reset')) {
        document.getElementById('reset').onclick = function() {
            clearForm(this.form);
            return false;
        }
    }
}

function handleRefineSearchLinkClick()
{
    document.getElementById('searchSummary').style.display = 'none';
    document.getElementById('searchForm').style.display = '';
}


function handleChangeSelectHierarchy()
{
    var collegeSelect = document.getElementById('college');
    var departmentSelect = document.getElementById('department');
    var subjectSelect = document.getElementById('subject');
    
    var selectedCollegeId = collegeSelect.options[collegeSelect.selectedIndex].value;
    var options = departmentSelect.getElementsByTagName('option');
    for (var i = options.length - 1; i >= 0; i--) {
    	// hack to make Computer Science show up in both Arts and Sciences and Engineering
    	var multiCollegeDepartmentOverride = false;
    	if (options[i].value == 13 && selectedCollegeId == 2) {
    		multiCollegeDepartmentOverride = true;
    	}
    	
        if (options[i].getAttribute('rel') == selectedCollegeId || collegeSelect.value == 0 || options[i].value == 0 || multiCollegeDepartmentOverride) {
            options[i].style.display = '';
        } else {
            options[i].style.display = 'none';
        }
    }
    
    var selectedDepartment = departmentSelect.options[departmentSelect.selectedIndex];
    if (selectedDepartment.style.display == 'none') {
        departmentSelect.selectedIndex = 0;
    }
    
    var selectedDepartments = new Array();
    
    if (departmentSelect.selectedIndex == 0) {
        var options = departmentSelect.getElementsByTagName('option');
        for (var i = options.length - 1; i >= 0; i--) {
            if (options[i].style.display == 'none') {
                continue;
            }
            selectedDepartments.push(options[i].value);
        }
    } else {
        selectedDepartments.push(departmentSelect.options[departmentSelect.selectedIndex].value);
    }

    options = subjectSelect.getElementsByTagName('option');

    for (var i = options.length - 1; i >= 0; i--) {
        if (selectedDepartments.inArray(options[i].getAttribute('rel')) || options[i].value == 0) {
            options[i].style.display = '';
        } else {
            options[i].style.display = 'none';
        }
    }

    var selectedSubject = subjectSelect.options[subjectSelect.selectedIndex];
    if (selectedSubject.style.display == 'none') {
        subjectSelect.selectedIndex = 0;
    }
}


function displayHoverHelp(e)
{

    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        cursor.x = e.clientX +
            (document.documentElement.scrollLeft || document.body.scrollLeft) -
            (document.documentElement.clientLeft || document.body.clientLeft);
        cursor.y = e.clientY +
            (document.documentElement.scrollTop || document.body.scrollTop) -
            (document.documentElement.clientTop || document.body.clientTop);
    }

    var helpDiv, helpText;
    if(!document.getElementById('floating_help_text_div')) {
        helpDiv = document.createElement('div');
        helpDiv.style.display = 'none';
        helpDiv.id = 'floating_help_text_div';
        helpText = document.createTextNode('');
        helpDiv.style.position = 'absolute';
        helpDiv.appendChild(helpText);
        document.body.appendChild(helpDiv);
    } else {
        helpDiv = document.getElementById('floating_help_text_div');
    }
    if(getElementsByClassName('hoverHelpText', this, 'span')[0].childNodes[0]) {
        helpDiv.childNodes[0].data = getElementsByClassName('hoverHelpText', this, 'span')[0].childNodes[0].data;
        helpDiv.style.borderWidth = '1px';
        if(document.body.clientWidth - cursor.x < cursor.x) {
            helpDiv.style.left = '';
            helpDiv.style.right = (document.body.clientWidth - cursor.x + 5) + 'px';
        } else {
            helpDiv.style.left = (cursor.x + 5) + 'px';
            helpDiv.style.right = '';
        }
        helpDiv.style.top = (cursor.y + 5) + 'px';
        helpDiv.style.display = 'block';
    }
}

function hideHoverHelp()
{
    if(document.getElementById('floating_help_text_div')) {
        document.getElementById('floating_help_text_div').style.display = 'none';
    }
}