//  standardLib.js 
//  version 1.4a
//  author: Wesley S. Rast, GE Power Systems

var isNS4 = false;
var isNS5 = false;
var isIE4 = false;
var isIE5 = false;
var isIE6 = false;
var isIE7 = false;

if (document.layers)
{
    isNS4 = true;
    window.onresize = ns4ResizeFix;
    origWidth = innerWidth;
    origHeight = innerHeight;
    var layerRef = 'document.layers.';
    var styleRef = '';
}
if (document.all && navigator.appVersion.indexOf("MSIE 4") != -1)
{
    isIE4 = true;
    var layerRef = 'document.all.';
    var styleRef = '.style';
}
if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 5) {
    isNS5 = true;
}
if (navigator.appVersion.indexOf("MSIE 5") != -1) {
    isIE5 = true;
}
if (navigator.appVersion.indexOf("MSIE 6") != -1) {
    isIE6 = true;
}

if (navigator.appVersion.indexOf("MSIE 7") != -1) {
    isIE7 = true;
}

function ns4ResizeFix()
{
    if (innerWidth != origWidth || innerHeight != origHeight)
    {
        origWidth = innerWidth;
        origHeight = innerHeight;
        location.reload();
    }
}

function doNothing() {/*for making null links*/
}

function debugObject(objectToDebug, isString)
{
    var tempObj = (isString != null)?(isString)?eval('' + objectToDebug):objectToDebug:objectToDebug;
    var counter = 1;
    var modulusCheck = (isNS5)?25:50;
    var alertString = '';
    for (x in tempObj)
    {
        var newObjectEntry = 'Object ' + counter + ' inside the object ' + objectToDebug + ' is: ' + x + ' - value : ' + tempObj[x] + '\n';
        alertString += (newObjectEntry.length <= 150)?newObjectEntry:'Object ' + counter + ' inside the object ' + objectToDebug + ' is: ' + x + ' - value : VERY LONG ENTRY\n';
        counter++;
        if (counter % modulusCheck == 0)
        {
            alert(alertString);
            alertString = '';
        }
    }
    alert(alertString);
}

function changeBgColor(thisLayerName, newColor)
{
    if (isNS4) eval(layerRef + thisLayerName + styleRef + '.bgColor=newColor');
    else if (isIE4) eval(layerRef + thisLayerName + styleRef + '.backgroundColor=newColor');
    else if (isIE5 || isIE6 || isIE7 || isNS5)
    {
        document.getElementById(thisLayerName).style.backgroundColor = newColor;
    }
}

function changeClip(thisLayerName, newTop, newRight, newBottom, newLeft)
{
    if (isNS4)
    {
        eval(layerRef + thisLayerName + '.clip.top=newTop');
        eval(layerRef + thisLayerName + '.clip.right=newRight');
        eval(layerRef + thisLayerName + '.clip.bottom=newBottom');
        eval(layerRef + thisLayerName + '.clip.left=newLeft');
    }
    else if (isIE4)
    {
        eval(layerRef + thisLayerName + styleRef + '.clip="rect(' + newTop + 'px ' + newRight + 'px ' + newBottom + 'px ' + newLeft + 'px)"');
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        document.getElementById(thisLayerName).style.clip = "rect(" + newTop + "px " + newRight + "px " + newBottom + "px " + newLeft + "px)";
    }
}

function changeFontColor(thisLayerName, newColor)
{
    if (isIE4) document.all[thisLayerName].style.color = newColor;
    else if (isIE5 || isIE6 || isIE7 || isNS5) document.getElementById(thisLayerName).style.color = newColor;
}

function changeLayerHTML(thisLayerName, newHTMLString)
{
    if (isNS4)
    {
        eval('document.' + thisLayerName + '.document.write(newHTMLString)');
        eval('document.' + thisLayerName + '.document.close()');
    }
    else if (isIE4)
    {
        eval('document.all.' + thisLayerName + '.innerHTML=newHTMLString');
    }
    else if (isIE5 || isIE6 || isIE7 || isNS5)
    {
        document.getElementById(thisLayerName).innerHTML = newHTMLString;
    }
}

function changeVisible(layerName, toWhat)
{
    var visibilityString = (toWhat)?'visible':'hidden';
    if (isNS4 || isIE4)
    {
        eval(layerRef + layerName + styleRef + '.visibility="' + visibilityString + '"');
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        document.getElementById(layerName).style.visibility = visibilityString;
    }
}

function changeZIndex(thisLayerName, toWhat)
{
    if (isNS4 || isIE4)
    {
        eval(layerRef + thisLayerName + styleRef + '.zIndex=' + toWhat);
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        document.getElementById(thisLayerName).style.zIndex = toWhat;
    }
}

function createCSS()
{
    document.write('<style>');
    for (x = 0; x < createCSS.arguments.length; x++)
    {
        createLayerCSS(createCSS.arguments[x]);
    }
    document.write('</style>');
}

function createLayerCSS(thisLayerName)
{
    document.write('\n#' + thisLayerName + ' {position:absolute;visibility:hidden;}');
}


var htmlBin = "";
function createLayerHTML(thisLayerName, contentString)
{
    document.write('<div id="' + thisLayerName + '">\n' + contentString + '\n</div>\n');
    htmlBin += '<div id="' + thisLayerName + '">\n' + contentString + '\n</div>\n';
}

function getClipValue(thisObjectName, thisClip)
{
    if (isNS4 || isIE4)
    {
        var thisObject = eval(layerRef + thisObjectName + styleRef);
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        var thisObject = document.getElementById(thisObjectName).style;
    }
    if (isNS4) {
        if (thisClip == 't') return thisObject.clip.top;
        if (thisClip == 'r') return thisObject.clip.right;
        if (thisClip == 'b') return thisObject.clip.bottom;
        if (thisClip == 'l') return thisObject.clip.left;
    }
    else if (isIE4 || isIE5 || isIE6 || isIE7 || isNS5)
    {
        var clipArray = thisObject.clip.match(/\d+/g);
        if (thisClip == 't') return parseInt(clipArray[0]);
        if (thisClip == 'r') return parseInt(clipArray[1]);
        if (thisClip == 'b') return parseInt(clipArray[2]);
        if (thisClip == 'l') return parseInt(clipArray[3]);
    }
}

function getHeight(thisLayerName)
{
    if (isNS4 || isIE4)
    {
        var tempHeight = eval(layerRef + thisLayerName + styleRef + '.height');
        if (isIE4)
        {
            var tempArray = tempHeight.match(/\d+/);
            tempHeight = parseInt(tempArray[0]);
        }
        else
        {
            var tempArray = new Array(tempHeight);
        }
    }
    if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        var tempHeight = document.getElementById(thisLayerName).style.height;
        var tempArray = tempHeight.match(/\d+/);
        tempHeight = parseInt(tempArray[0]);
    }
    return tempHeight;
}

function getPositionLeft(thisLayerName)
{
    var tempPositionLeft;
    var match;
    var thisLayerObj = layerRef + thisLayerName + styleRef;
    if (isNS4)
    {
        tempPositionLeft = eval(thisLayerObj + '.left');
    }
    else if (isIE4)
    {
        tempPositionLeft = eval(thisLayerObj + '.left');
        match = parseInt(tempPositionLeft);
        tempPositionLeft = parseInt(match);
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        tempPositionLeft = document.getElementById(thisLayerName).style.left;
        match = parseInt(tempPositionLeft);
        tempPositionLeft = parseInt(match);
    }
    return tempPositionLeft;
}

function getPositionTop(thisLayerName)
{
    var tempPositionTop;
    var match;
    var thisLayerObj = layerRef + thisLayerName + styleRef;
    if (isNS4)
    {
        tempPositionTop = eval(thisLayerObj + '.top');
    }
    else if (isIE4)
    {
        tempPositionTop = eval(thisLayerObj + '.top');
        match = parseInt(tempPositionTop);
        tempPositionTop = parseInt(match);
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        tempPositionTop = document.getElementById(thisLayerName).style.top;
        match = parseInt(tempPositionTop);
        tempPositionTop = parseInt(match);
    }
    return tempPositionTop;
}

function getRealLeft(elementName)
{
    if (isNS4) elemPoint = document.layers[elementName];
    if (isNS5 || isIE5 || isIE6 || isIE7) elemPoint = document.getElementById(elementName);
    if (isIE4) elemPoint = document.all[elementName];
    if (isIE4 || isIE5 || isIE6 || isIE7)
    {
        xPos = elemPoint.offsetLeft;
        tempEl = elemPoint.offsetParent;
        while (tempEl != null)
        {
            xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
        return xPos;
    }
    else if (isNS5) {
        return elemPoint.offsetLeft + document.getElementsByTagName("body")[0].offsetLeft;
    }
    else if (isNS4) {
        return elemPoint.pageX;
    }
}

function getRealTop(elementName)
{
    if (isNS4) elemPoint = document.layers[elementName];
    if (isNS5 || isIE5 || isIE6 || isIE7) elemPoint = document.getElementById(elementName);
    if (isIE4) elemPoint = document.all[elementName];
    if (isIE4 || isIE5 || isIE6 || isIE7)
    {
        yPos = elemPoint.offsetTop;
        tempEl = elemPoint.offsetParent;
        while (tempEl != null)
        {
            yPos += tempEl.offsetTop;
            tempEl = tempEl.offsetParent;
        }
        return yPos;
    }
    else if (isNS5) {
        return elemPoint.offsetTop + document.getElementsByTagName("body")[0].offsetTop;
    }
    else if (isNS4) {
        return elemPoint.pageY;
    }
}

function getWidth(thisLayerName)
{
    if (isNS4 || isIE4)
    {
        var tempWidth = eval(layerRef + thisLayerName + styleRef + '.width');
        if (isIE4)
        {
            var tempArray = tempWidth.match(/\d+/);
            tempWidth = parseInt(tempArray[0]);
        }
        else
        {
            var tempArray = new Array(tempWidth);
        }
    }
    if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        var tempWidth = document.getElementById(thisLayerName).style.width;
        var tempArray = tempWidth.match(/\d+/);
        tempWidth = parseInt(tempArray[0]);
    }
    return tempWidth;
}

function getVisibility(thisLayerName)
{
    if (isNS4 || isIE4) return eval(layerRef + thisLayerName + styleRef + '.visibility');
    else if (isNS5 || isIE5 || isIE6 || isIE7) return document.getElementById(thisLayerName).style.visibility;
}

function getZIndex(thisLayerName)
{
    if (isNS4 || isIE4) return eval(layerRef + thisLayerName + styleRef + '.zIndex');
    else if (isNS5 || isIE5 || isIE6 || isIE7) return document.getElementById(thisLayerName).style.zIndex;
}

function initLayer(layerId, thisBgColor, thisZIndex, topPos, leftPos, thisWidth, thisHeight, clipTop, clipRight, clipBottom, clipLeft, thisVis)
{
    var prop;
    if (isNS4) prop = document.layers[layerId];
    else if (isIE4) prop = document.all[layerId].style;
    else if (isIE5 || isIE6 || isIE7 || isNS5) prop = document.getElementById(layerId).style;
    (isNS4)?prop.bgColor = thisBgColor:prop.backgroundColor = thisBgColor;
    prop.zIndex = thisZIndex;
    prop.left = leftPos;
    prop.top = topPos;
    prop.width = thisWidth;
    prop.height = thisHeight;
    if (isNS4)
    {
        prop.clip.top = clipTop;
        prop.clip.right = clipRight;
        prop.clip.bottom = clipBottom;
        prop.clip.left = clipLeft;
    }
    else
    {
        prop.clip = "rect(" + clipTop + "px " + clipRight + "px " + clipBottom + "px " + clipLeft + "px)";
    }
    prop.visibility = thisVis;
}

function moveLayerAbs(thisLayerName, newLeftPosition, newTopPosition)
{
    if (isNS4 || isIE4)
    {
        eval(layerRef + thisLayerName + styleRef + '.left=' + newLeftPosition);
        eval(layerRef + thisLayerName + styleRef + '.top=' + newTopPosition);
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        document.getElementById(thisLayerName).style.left = newLeftPosition;
        document.getElementById(thisLayerName).style.top = newTopPosition;
    }
}

function moveLayerRel(thisLayerName2, leftModify, topModify)
{
    var currentLeft;
    var currentTop;
    if (isNS4 || isIE4)
    {
        var thisLayerObj = layerRef + thisLayerName2 + styleRef;
        (isNS4)?currentLeft = eval(thisLayerObj + '.left'):currentLeft = eval(thisLayerObj + '.pixelLeft');
        (isNS4)?currentTop = eval(thisLayerObj + '.top'):currentTop = eval(thisLayerObj + '.pixelTop');
        eval(thisLayerObj + '.left=(currentLeft+leftModify)');
        eval(thisLayerObj + '.top=(currentTop+topModify)');
    }
    else if (isNS5 || isIE5 || isIE6 || isIE7)
    {
        document.getElementById(thisLayerName2).style.left = getPositionLeft(thisLayerName2) + parseInt(leftModify);
        document.getElementById(thisLayerName2).style.top = getPositionTop(thisLayerName2) + parseInt(topModify);
    }
}

function slide(thisLayerName, leftMove, topMove, numberOfFrames, delay)
{
    if (numberOfFrames > 0)
    {
        moveLayerRel(thisLayerName, parseInt(leftMove), parseInt(topMove));
        setTimeout('slide("' + thisLayerName + '",parseInt(' + leftMove + '),parseInt(' + topMove + '),' + (numberOfFrames - 1) + ',' + delay + ')', delay);
    }
}

function slideTo(thisLayerName, newLeft, newTop, numberOfSteps, timeDelay)
{
    var stepXDistance = (newLeft - getPositionLeft(thisLayerName)) / numberOfSteps;
    var stepYDistance = (newTop - getPositionTop(thisLayerName)) / numberOfSteps;
    slide(thisLayerName, stepXDistance, stepYDistance, numberOfSteps, timeDelay);
}
