/****************************************************************
*
* DHTML API for NN6+ and IE4+. Accounts for W3C DOM and IE4 DOM.
* AUTHOR: Fernando Drabik (some functions from Danny Goodman)
* DATE: Dec, 01 2003
*
* Modified:
*   2007/01/18 - Miranda Hawarden-Ogata
*     changed image paths for menu images (toggleArrow)
*
* Reproduction of this code in part or its totallity is prohibited
* without written authorization
*
*****************************************************************/

// Globals
var isCSS, isW3C, isIE4, isIE6CSS, bodyFontSize;
// Initialize onload to check for object support

function initFlags () {
    if(document.images) {
        // Check for CSS  and scripted positioning objects.
        isCSS = (document.body && document.body.style) ? true : false
        isW3C = (isCSS && document.getElementById) ? true : false
        isIE4 = (isCSS && document.all) ? true : false
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;

    }
    if (!isIE4 && !isW3C) {
        window.location.replace("noDHTML.html");
    }

}

// Call initflags *after* the window loads, so that <body> tag is loaded
// first enabling browsers to check for the document object or body elem.
window.onload = initFlags;
//check this for resize and rendering elements



function getObject(obj) {
    var theObj;
    // Check if the object is passed as a name string or raw object
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else {
            theObj = document.all(obj);
        }
    } else {
        theObj = obj;
    }
    return theObj;
}

function getStyle(obj) {
    var theObj = getObject(obj);
    var theObjStyle;
    if (theObj && isCSS) {
        theObjStyle = theObj.style;
    }
    return theObjStyle;
}

function shiftTo(obj, x, y) {
    var theObjStyle = getStyle(obj);
    if (theObjStyle) {
        var units = (typeof theObjStyle.left == "string") ? "px" : 0;
        theObjStyle.left = x + units;
        theObjStyle.top  = y + units;
    }
}

function shiftBy(obj, deltaX, deltaY) {

    var theObjStyle = getStyle(obj);
    var units = (typeof theObjStyle.left == "string") ? "px" : 0;
    theObjStyle.left = getObjectLeft(obj) + deltaX + units;
    theObjStyle.top  = getObjectTop(obj) + deltaY + units;
}

function setZIndex(obj, zOrder) {
    var theObjStyle = getStyle(obj);
    if (theObjStyle) {
        theObjStyle.zIndex = zOrder;
    }
}

function setBGColor(obj, color) {
    var theObjStyle = getStyle(obj);
    if (theObjStyle) {
        theObjStyle.backgroundColor = color;
    }
}

function show(obj) {
    var theObjStyle = getStyle(obj);
    if(theObjStyle) {
        theObjStyle.visibility = "visible";
    }
}

function hide(obj) {
    var theObjStyle = getStyle(obj);
    if(theObjStyle) {
        theObjStyle.visibility = "hidden";
    }
}

function getObjectLeft(obj) {
    var elem = getObject(obj);
    var left = 0;
    if (document.defaultView) { // W3C DOM
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem,"");
        left = cssDecl.getPropertyValue("left");
    } else if (document.currentStyle) { // IE DOM
        left = elem.currentStyle.left;
    } else if (elem.style) {
        left = elem.style.left;
    }
    return parseInt(left);
}

function getObjectTop(obj) {
    var elem = getObject(obj);
    var top = 0;
    if (document.defaultView) { // W3C DOM
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem,"");
        top = cssDecl.getPropertyValue("top");
    } else if (document.currentStyle) { // IE DOM
        top = elem.currentStyle.top;
    } else if (elem.style) {
        top = elem.style.top;
    }
    return parseInt(top);
}

function getObjectWidth(obj) {
    var elem = getObject(obj);
    var width = 0;
    if (elem.offsetWidth) {
        if (elem.scrollWidth && (elem.offsetWidth != elem.scrollWidth)) {
            width = elem.scrollWidth;
        } else {
            width = elem.offsetWidth;
        }
    } else if (elem.clip && elem.clip.width) {
        width = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        width = elem.style.pixelWidth;
    }
    return parseInt(width);
}

function getObjectHeight(obj) {
    var elem = getObject(obj);
    var height = 0;
    if (elem.offsetHeight) {
        height = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        height = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        height = elem.style.pixelHeight;
    }
    return parseInt(height);
}

function getInsideWindowWidth () {
    if(window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS){
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth){
        return document.body.clientWidth;
    }
    return 0;
}

function getInsideWindowHeight () {
    if(window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS){
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight){
        return document.body.clientHeight;
    }
    return 0;
}

function getObjectCenter(obj) {
    var elem = getObject(obj);
    var center = {x:0, y:0};
    if (theObjectStyle) {
        center.x = getObjectLeft(obj) + (getObjectWidth(obj) / 2);
        center.y = getObjectTop(obj) + (getObjectHeight(obj) / 2);
    }
    return center;
}

function expandObject(obj) {
    var theObjStyle = getStyle(obj);
    if (theObjStyle && theObjStyle.display) {
        theObjStyle.display = "inline";
    }

}



function collapseObject(obj) {
    var theObjStyle = getStyle(obj);
    if (theObjStyle && theObjStyle.display) {
        theObjStyle.display = "none";
    }
}

function centerObjectHorizontal(obj) {
    var x = Math.round((getInsideWindowWidth() / 2) - (getObjectWidth(obj) / 2));
    var y = getObjectTop(obj);
    shiftTo(obj, x, y);
}

function centerObjectVertical(obj) {
    var x = getObjectLeft(obj);
    var y = Math.round((getInsideWindowHeight() / 2) - (getObjectHeight(obj) / 2));
    shiftTo(obj, x, y);
}

// Centers an object in the browser window
function centerObject(obj) {
    centerObjectVertical(obj);
    centerObjectHorizontal(obj);}

// Centers an object in the parent object's box
function centerNestedObject(obj, parent) {
}


function cropObject(obj, dir){
    var theObj = getObject(obj);
    var theStyle = theObj.style;
    var top = 'auto';
    var right = 'auto';
    var bottom = 'auto';
    var left = 'auto';

    switch (dir) {
        case 'top' : {

        }
        case 'right' : {

        }
        case 'bottom' : {

        }
        case 'left' : {

        }


    }
}


function increaseFont() {
    switch (bodyFontSize) {
        case '12px' : {
            document.body.style.fontSize = "14px";
            bodyFontSize = "14px";
            break;
        }
        case '14px' : {
            document.body.style.fontSize = "16px";
            bodyFontSize = "16px";
            break;
        }
        default : {
            document.body.style.fontSize = "12px";
            bodyFontSize = "12px";
        }

    }
}

function toggleArrow(obj) {
    obj = getObject(obj);
    if (! obj.open) {
        expandObject(obj);
        MM_swapImage('i' + obj.id,'', '/images/' + (obj.id).toString() + 'Open.gif',1);
        obj.open = true;

    } else {
        collapseObject(obj);
        MM_swapImage('i' + obj.id,'', '/images/' + (obj.id).toString() + ".gif",1);
        obj.open = false;
    }
    createCookie(obj.id, obj.open);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

