﻿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];
}


function trim(str) {
    if (str == "") {
        return str;
    }

    if (str == null || str == undefined) {
        return "";
    } else {
        str = str.replace(/^\s+|\s+$/g, '');
        return str;
    }
}
function getBrowserWidth() {
    var theWidth
    // Window dimensions:
    if (window.innerWidth) {
        theWidth = window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        theWidth = document.documentElement.clientWidth;
    }
    else if (document.body) {
        theWidth = document.body.clientWidth;
    }
    return theWidth;
}

function getBrowserHeight() {
    var theHeight;
    // Window dimensions:
    if (window.innerHeight) {
        theHeight = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        theHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        theHeight = document.body.clientHeight;
    }
    return theHeight;
}

function popit(url, name) {
    var newWin = window.open(url, name, "margintop=0,width=300, height=720, resizable=0, scrollbars=no, menubar=no, status=no");
}


function setSidebar() {
    var sidebar = document.getElementById('sidebarDiv');
    var login = document.getElementById('btnMenuHome');
    
    var content = document.getElementById('content');
    if (!sidebar) {
        return false;
    }
    if (!login) {
        return false;
    }
    var pos = findPos(login); 
    sidebar.style.position = 'absolute';
    //sidebar.style.width = login.offsetWidth + 1;
    var x;
    var y;
//    alert(pos);
    x = pos[0];
    y = pos[1] - 130;
    sidebar.style.left = '1px';
    sidebar.style.top = y + 'px';
    sidebar.style.zIndex = 1;
    if (sidebar.offsetHeight > content.offsetHeight) {
        content.style.height = sidebar.offsetHeight + 'px';
    } else {
        sidebar.style.height = content.offsetHeight + 'px';
    }
}

function shutSlideDivs(openDivName) {
    
    var divArray = new Array();

    divArray[0] = 'companyProfile';
    divArray[1] = 'consumerEducation';
    divArray[2] = 'financialTools';
    divArray[3] = 'ourServices';
    divArray[4] = 'careers';

    for (var i = 0; i < divArray.length; i++) {
        if (divArray[i] != openDivName) {
            var div = document.getElementById(divArray[i]);
            if (div) {
                if (div.style.display != "none") {
                    div.style.display = "none";
                }
            }
        }
    }
}

