var dialogueWindows = new Object();

onunload = closeAllDialogues;

function openDialogue(windowName, windowUrl, windowWidth, windowHeight, scrollbars) {
    var dialogue = dialogueWindows[windowName];
    var windowTop = (screen.height / 2) - (windowHeight / 2);
    var windowLeft = (screen.width / 2) - (windowWidth / 2);

    var features = 'height=' + windowHeight + ',width=' + windowWidth + ',top=' + windowTop + ',left=' + windowLeft + ',resizable=yes,status=yes';

    if (scrollbars)
        features += ",scrollbars=yes";

    if (dialogue && !dialogue.closed)
        dialogue.close();

    dialogueWindows[windowName] = window.open(windowUrl, windowName, features);
}

function closeDialogue() {
    if (window.opener && !window.opener.closed) {
        window.opener.focus();
    }
    window.close();
}

function closeAllDialogues() {
    for (windowName in dialogueWindows) {
        var dialogue = dialogueWindows[windowName];

        if (dialogue && !dialogue.closed) {
            dialogue.close();
        }
    }
}

function completeDialogue() {
    if (window.opener && !window.opener.closed) {
        window.opener.location.reload();
    }
    closeDialogue();
}

function parseGetVars() {
    var args = new Array();
    var query = window.location.search.substring(1);
    if (query) {
        var strList = query.split('&');
        for (str in strList) {
            var parts = strList[str].split('=');
            args[unescape(parts[0])] = unescape(parts[1]);
        }
    }
    return args;
}


function fitImage() {
    // Only modify window size if this is a popup window - TB 08/10/2007
    if (window.opener && !window.opener.closed) {
        var offsetWidth = 12;
        var offsetHeight = 30;

        if (window.outerWidth)
            offsetWidth = window.innerWidth - window.outerWidth;
        if (window.outerHeight)
            offsetHeight = window.outerHeight - window.innerHeight;

        var windowWidth = document.images[0].width + offsetWidth;
        var windowHeight = document.images[0].height + offsetHeight;

        var windowTop = (screen.height / 2) - (windowHeight / 2);
        var windowLeft = (screen.width / 2) - (windowWidth / 2);

        window.moveTo(windowLeft, windowTop);
        window.resizeTo(windowWidth, windowHeight);
    }

    self.focus();
}

onload = SetLinks;

// Uses the url to find the link to the current page and select it
function SetLinks() {
    var links = document.getElementsByTagName("a");

    for (var i = 0; i < links.length; i++) {
        var link = links[i];

        if (link.href == window.location || link.href.replace("default.aspx", "") == window.location) {
            link.className += " Active";
        }
    }
}

function addEventHandler(targetObject, eventType, handlerFunc) {
    if (targetObject.addEventListener) {
        targetObject.addEventListener(eventType, handlerFunc, true);
    }
    else if (targetObject.attachEvent) {
        targetObject.attachEvent('on' + eventType, handlerFunc);
    }
}
