function redirect() {
    var this_url = window.location;

    if (this_url.search.match('page=') == null) {

        var new_url = '/framework.php?page=' + this_url;
        window.location = new_url;
    }
}

function imageMouseOver(img_ref) {
    img_ref.src = img_ref.src.replace('.png', '_over.png');
}

function imageMouseOut(img_ref) {
    img_ref.src = img_ref.src.replace('_over.png', '.png');
}

function searchLinkClick() {

    var my_form =
        document.getElementById('searchbox_002939805342883453938:ju-6s-1c2jo');

    my_form.submit();

    return false;
}

function changeLinks() {
//    return newChangeLinks();

    var links = document.links;

    var framework = 'http://rmyl.byu.edu/framework.php';

    for (var i = 0; i < links.length; ++i) {
        var link = links[i];

		if (link.className.match('literal') == null &&
                link.href.match('.html') != null &&
                link.hostname == 'rmyl.byu.edu'
                && (link.search.match('page=') == null)) {
			link.href = framework + '?page=' + link.href;
		}
    }
}

function newChangeLinks() {
    var links = document.links;

    for (var i = 0; i < links.length; ++i) {
        var link = links[i];

		if (link.className.match('literal') == null &&
                link.href.match('.html') != null &&
                link.hostname == 'rmyl.byu.edu'
                && (link.search.match('page=') == null)) {
			link.onclick = function() {
                return linkClick(this);
            }
		}
    }
}

function linkClick(link) {
    changeContent(link.href);  
    return false;
}

function changeContent(href) {
    var params = new Array();
    params['page'] = href;

    var param_list = makeParamList(params);     
    var callback_function = 'changeContentCallback';
    var url = 'http://rmyl.byu.edu/rmyl_new/changeContent.php';
    var return_xml = false;

    makeHttpRequest(url, callback_function, param_list, return_xml);
}

function changeContentCallback(response_html) {
    setContent(response_html);

    newChangeLinks();

    return true;
}

function setContent(html) {
    var content_div = getContentDiv();

    content_div.innerHTML = html;
    
    return true;
}

function getContentDiv() {
    return document.getElementById('div_content_padding');
}

function getWindowDimensions() {
    var width = null;
    var height = null;

    if (self.innerWidth) {
        width = parseInt(self.innerWidth);
        height = parseInt(self.innerHeight);
    } else if (document.documentElement &&
            document.documentElement.clientWidth) {
        width = parseInt(document.documentElement.clientWidth);
        height = parseInt(document.documentElement.clientHeight);
    } else if (document.body) {
        width = parseInt(document.body.clientWidth);
        height = parseInt(document.body.clientHeight);
    } else {
        alert('error getting window dimensions');
        return null;
    }

    var dimensions = new Array();
    dimensions['width'] = width;
    dimensions['height'] = height;

    return dimensions;
}

function getWindowHeight() {
    var dimensions = getWindowDimensions();

    if (dimensions == null) {
        alert('error getting window height');
        return null;
    }

    return dimensions['height'];
}

function windowResize() {
    var height = getWindowHeight();

    if (height == null) {
        alert('error resizing content div');
        return false;
    }

    var div_top_bar = document.getElementById('div_top_bar');
    var div_logo = document.getElementById('div_logo');
    var div_menu_bar = document.getElementById('div_menu_bar');
    var div_green = document.getElementById('div_green');
    var div_red = document.getElementById('div_red');
    var div_footer = document.getElementById('div_footer');

    var div_content = document.getElementById('div_content');

    height = height - getHeight(div_top_bar)
        - getHeight(div_logo) - getHeight(div_menu_bar)
        - getHeight(div_green) - getHeight(div_red) - getHeight(div_footer);

    var variance = -11;

    /*
    if (window.g_is_ie) {
        variance = -4;
    }
    */

    setHeight(div_content, height + variance);
}

function setHeight(elem_ref, height) {
    elem_ref.style.height = height + 'px'; 
}

function getHeight(elem_ref) {

    var height = 0;

    if (!document.defaultView) {
        height = elem_ref.offsetHeight;
        //alert(elem_ref.nodeName + '\n' + elem_ref.id + '\n' + height);
    } else {
        var computed_style 
            = document.defaultView.getComputedStyle(elem_ref, null);

        height = parseInt(computed_style.getPropertyValue('height'));
    }

    return height;
}

var g_functions = new Array(); // holds global functions
function addEvent(elem_ref, event_type, function_obj, use_capture) {

    var result = null;

    if (g_functions[elem_ref.nodeName + event_type] == undefined) {
        g_functions[elem_ref.nodeName + event_type] = new Array();

        var myFunc = function() {
            evalFunctions(elem_ref, event_type);
        }

        if (elem_ref.addEventListener && !window.opera &&
                !(!document.all && document.childNodes && 
                !navigator.taintEnabled)) {
            elem_ref.addEventListener(event_type, myFunc, use_capture);
            result = true;
        } else {
            if (event_type == 'DOMContentLoaded') {
                checkForDOMContentLoaded();
            } else { 
                
                if (elem_ref.attachEvent) {
                    var r = elem_ref.attachEvent('on' + event_type, myFunc);
                    result = r;
                } else { 
                    elem_ref['on' + event_type] = myFunc;
                }
            }
        }
    }

    g_functions[elem_ref.nodeName + event_type].push(function_obj);

    return result;
}

function checkForDOMContentLoaded() {

    if (document.body) {
        evalFunctions(document, 'DOMContentLoaded');
    } else {
        setTimeout('checkForDOMContentLoaded()', 50);
    }
}

function evalFunctions(elem_ref, event_type) {
    var functions = g_functions[elem_ref.nodeName + event_type];

    if (!functions) {
        return false;
    }

    for (var i = 0; i < functions.length; ++i) {
        var func = functions[i];

        func();
    }

    return true;
}

function MM_openBrWindow(url, win_name, features) {
    window.open(url, win_name, features);
}

