<!--
// These global variables are created when this javascript file is loaded, 
// when the request head is received.

var isCSS; // browser is CSS compatible
var isW3C; // browser is compliant with W3C standard (www.w3c.org)
var isIE4; // browser uses document.all model
var isNN4; // browser uses document.layers model
var isIE6CSS; // browser is IE6 

// this function is here because it has to be defined (and thus compiled)
// before it can be used. It's used by the lines just below, which are executed
// at load time.
// 
// the version number for IE matters because many of the compatibility problems
// were fixed as of IE 7. 
function getIEVersionNumber( ) {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

// the next couple of lines add the style sheet to the document header. 
//
// all browsers except IE6 use the default stylesheet. Really!
document.write("<link rel='stylesheet' type='text/css' href='css/topic.css'>");
// IE6 has its own stylesheet. The compound conditional guards against Opera being
// identified as IE, as it calls itself IE.
if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.userAgent.indexOf("Opera") == -1)) {
    if (getIEVersionNumber() <= 6) {
	document.write("<link rel='stylesheet' type='text/css' href='/css/topic-ie6.css'>");
    }
}

// Initialize upon load to let all browsers establish content objects
function initDHTMLAPI( ) {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? 
            true : false;
    }
}

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}
  
// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}
 
// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}
  
// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}
   
// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}
   
function getElementStyle(elemID, IEStyleAttr, CSSStyleAttr) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleAttr];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleAttr);
    }
    return "";
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}
   
// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

function getPositionedEventCoords(obj, evt) {
    var coords = {left:0, top:0};
    if (evt.layerX) {
        var borders = {left:parseInt(getElementStyle(obj, "borderLeftWidth", "border-left-width")),
                       top:parseInt(getElementStyle(obj, "borderTopWidth", "border-top-width"))};
        coords.left = evt.layerX - borders.left;
        coords.top = evt.layerY - borders.top;
    } else if (evt.offsetX) {
        coords.left = evt.offsetX;
        coords.top = evt.offsetY;
    }
    return coords;
}

function openCommentForm(comment) {
    setZIndex(comment, 100);
    show(comment);
}

function closeCommentForm(comment) {
    setZIndex(comment, 0);
    hide(comment);
}

function showDesc(topic) {
    setZIndex(topic, 100);
    show(topic);
}

function hideDesc(topic) {
    hide(topic);
    setZIndex(topic, 0);
}

function highlightOn(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        var elem = (evt.srcElement) ? evt.srcElement : evt.target;
        elem.className = "commentcontrol_on";
    }
}

function highlightOff(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        var elem = (evt.srcElement) ? evt.srcElement : evt.target;
        elem.className = "commentcontrol_off";
    }
}
-->

