﻿// ---- BEGIN BROWSER DETECTION FUNCTIONS ----

var isIE4 = (document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;

function GetViewableBrowserDimension(dimension) {
    var bWidth = 0, bHeight = 0;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        bWidth = window.innerWidth;
        bHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        bWidth = document.documentElement.clientWidth;
        bHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        bWidth = document.body.clientWidth;
        bHeight = document.body.clientHeight;
    }
    else {
        bWidth = document.offsetWidth;
        bHeight = document.offsetHeight;
    }

    if (dimension.toLowerCase() == 'w') {
        return bWidth;
    }
    else if (dimension.toLowerCase() == 'h') {
        return bHeight;
    }
}

function GetViewableBrowserWidth() {
    return GetViewableBrowserDimension('w');
}

function GetViewableBrowserHeight() {
    return GetViewableBrowserDimension('h');
}

function GetScrollPosition(scrollType) {
    var vXOffset;
    var vYOffset;

    if (typeof (window.pageXOffset) == 'number') {
        //Non-IE
        vXOffset = window.pageXOffset;
        vYOffset = window.pageYOffset;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE 6+ in 'standards compliant mode'
        vXOffset = document.documentElement.scrollLeft;
        vYOffset = document.documentElement.scrollTop;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //IE 4 compatible
        vXOffset = document.body.scrollLeft;
        vYOffset = document.body.scrollTop;
    }

    if (scrollType.toLowerCase() == 'x') {
        return vXOffset;
    }
    else if (scrollType.toLowerCase() == 'y') {
        return vYOffset;
    }
}

function GetScrollPositionWidth() {
    return GetScrollPosition('x');
}

function GetScrollPositionHeight() {
    return GetScrollPosition('y');
}

function GetObjectPosition(obj, positionType) {
    var curLeft = 0;
    var curTop = 0;

    if (obj.offsetParent) {
        //        alert('IN IF STATEMENT');
        curLeft = obj.offsetLeft;
        curTop = obj.offsetTop;

        while (obj = obj.offsetParent) {
            curLeft += obj.offsetLeft;
            curTop += obj.offsetTop;
        }
    }
    else {
        //        alert(obj.offsetParent);
        //        alert('Left is: ' + obj.x + '\n Top is: ' + obj.y);
    }

    if (positionType.toLowerCase() == 'x') {
        return curLeft;
    }
    else if (positionType.toLowerCase() == 'y') {
        return curTop;
    }
}

function GetObjectPositionX(obj) {
    return GetObjectPosition(obj, 'x');
}

function GetObjectPositionY(obj) {
    return GetObjectPosition(obj, 'y');
}

// ---- END BROWSER DETECTION FUNCTIONS ----

// ---- BEGIN POPUP WINDOW FUNCTIONS ----

function OpenPopup(URL, width, height) {
    window.self.name = "main";
    //var now = new Date();
    //var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
    var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
    remote.resizeTo(parseInt(width) + 2, parseInt(height) + 35);
    remote.focus();
}

function OpenBarlessScrollingPopup(URL, width, height) {
    window.self.name = "main";
    //var now = new Date();
    //var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
    var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
    remote.resizeTo(parseInt(width) + 2, parseInt(height) + 35);
    remote.focus();
}

function OpenBarlessPopup(URL, width, height) {
    window.self.name = "main";
    //var now = new Date();
    //var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
    var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
    remote.resizeTo(parseInt(width) + 2, parseInt(height) + 35);
    remote.focus();
}

function OpenScrollingPopup(URL, width, height) {
    window.self.name = "main";
    //var now = new Date();
    //var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
    var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
    remote.resizeTo(parseInt(width) + 2, parseInt(height) + 35);
    remote.focus();
}

function OpenFullPopup(URL, width, height) {
    window.self.name = "main";
    //var now = new Date();
    //var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
    var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=1,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
    remote.resizeTo(parseInt(width) + 2, parseInt(height) + 35);
    remote.focus();
}

// ---- END POPUP WINDOW FUNCTIONS ----

// ---- BEGIN DHTML DISPLAY FUNCTIONS ----

function ToggleDivDisplay(div) {
    if (document.getElementById(div).style.display == 'none') {
        document.getElementById(div).style.display = 'block';
    }
    else {
        document.getElementById(div).style.display = 'none';
    }
}

function ShowDivLayer(divID) {
    document.getElementById(divID).style.visibility = 'visible';
    document.getElementById(divID).style.display = 'block';
}

function HideDivLayer(divID) {
    document.getElementById(divID).style.visibility = 'hidden';
    document.getElementById(divID).style.display = 'none';
}

function CenterLayerPosition(divLayer) {
    var elem = document.getElementById(divLayer);
    var scrollX = parseInt(GetViewableBrowserWidth());
    var scrollY = parseInt(GetViewableBrowserHeight());

    elem.style.left = ((scrollX / 2) - (parseInt(elem.style.width) / 2)) + 'px';
    elem.style.top = ((scrollY / 2) + (parseInt(elem.style.height) / 2) + GetScrollPositionHeight() - 120) + 'px';
    elem = null;
}

function CenterOffsetLayerPosition(divLayer, offsetX, offsetY) {
    var elem = document.getElementById(divLayer);
    var scrollX = parseInt(GetViewableBrowserWidth());
    var scrollY = parseInt(GetViewableBrowserHeight());

    elem.style.left = ((scrollX / 2) - offsetX - (parseInt(elem.style.width) / 2)) + 'px';
    elem.style.top = ((scrollY / 2) + (parseInt(elem.style.height) / 2) + GetScrollPositionHeight() - 120) + 'px';
    elem = null;
}

function CenterParentOffsetLayerPosition(divLayer, divParent) {
    //var offsetX = GetObjectPositionX(divParent);
    //var offsetY = GetObjectPositionY(divParent);
    viewport.getAll();
    document.getElementById(divLayer).style.position = 'absolute';

    //manually setting these values
    var leftColumnOffset = 175;
    var progressBarWidth = 125;
    var headerOffset = 125;

    var offsetX = 0;
    if (viewport.width > 960) {
        offsetX = (viewport.width - 960) / 2
    }
    document.getElementById(divLayer).style.left = ((viewport.width + viewport.scrollX) / 2 - progressBarWidth) - offsetX - leftColumnOffset + "px";
    document.getElementById(divLayer).style.top = ((viewport.height) / 2 + viewport.scrollY - headerOffset) + "px";

    //return CenterOffsetLayerPosition(divLayer,155,500);
}

//function CenterLayerPosition(divLayer)
//{
//    var elem = document.getElementById(divLayer);
//    var scrollY = parseInt(GetViewableBrowserHeight());

//    elem.style.left = (785 - (parseInt(elem.style.width)/2)) + 'px';
//    elem.style.top = ((scrollY/2) - (parseInt(elem.style.height)/2) + GetScrollPositionHeight() - 120) + 'px';
//    elem = null;
//}

// ---- END DHTML DISPLAY FUNCTIONS ----

// ---- BEGIN CLEAR DROP MENU FUNCTION ----

function ClearDropMenu(menu) {
    if (document.getElementById(menu)) {
        document.getElementById(menu).selectedIndex = 0;
    }
}

function ClearFormBox(field) {
    if (document.getElementById(field)) {
        document.getElementById(field).value = '';
    }
}

// ---- END CLEAR DROP MENU FUNCTION ----

// ---- BEGIN FORM RELATED FUNCTIONS ----

function SetFocus(frmInput) {
    if (document.getElementById(frmInput)) {
        document.getElementById(frmInput).focus();
    }
}

// ---- END FORM RELATED FUNCTIONS ----

/*************************************************************************

dw_viewport.js
version date Nov 2003
  
This code is from Dynamic Web Coding 
at http://www.dyn-web.com/
Copyright 2003 by Sharon Paine 
See Terms of Use at http://www.dyn-web.com/bus/terms.html
Permission granted to use this code 
as long as this entire notice is included.

*************************************************************************/

viewport = {
    getWinWidth: function() {
        this.width = 0;
        if (window.innerWidth) this.width = window.innerWidth - 18;
        else if (document.documentElement && document.documentElement.clientWidth)
            this.width = document.documentElement.clientWidth;
        else if (document.body && document.body.clientWidth)
            this.width = document.body.clientWidth;
    },

    getWinHeight: function() {
        this.height = 0;
        if (window.innerHeight) this.height = window.innerHeight - 18;
        else if (document.documentElement && document.documentElement.clientHeight)
            this.height = document.documentElement.clientHeight;
        else if (document.body && document.body.clientHeight)
            this.height = document.body.clientHeight;
    },

    getScrollX: function() {
        this.scrollX = 0;
        if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
        else if (document.documentElement && document.documentElement.scrollLeft)
            this.scrollX = document.documentElement.scrollLeft;
        else if (document.body && document.body.scrollLeft)
            this.scrollX = document.body.scrollLeft;
        else if (window.scrollX) this.scrollX = window.scrollX;
    },

    getScrollY: function() {
        this.scrollY = 0;
        if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)
            this.scrollY = document.documentElement.scrollTop;
        else if (document.body && document.body.scrollTop)
            this.scrollY = document.body.scrollTop;
        else if (window.scrollY) this.scrollY = window.scrollY;
    },

    getAll: function() {
        this.getWinWidth(); this.getWinHeight();
        this.getScrollX(); this.getScrollY();
    }

}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }

    return [curleft, curtop];
}