/// <reference name="MicrosoftAjax.js"/>

function SalaryMenuItemClick(strElement, hideCM)
{
    var ele = GetSalaryAppSelectedItem();
    if (ele.value != strElement) 
    {
        ele.value = strElement;
        var newPageId = cmPageId + ele.value.replace(' ', '_');
        if (!hideCM && (typeof cmCreatePageviewTag == 'function'))
        {
            cmCreatePageviewTag(newPageId, cmCategoryId); 
        }
        // Force the onchange event
        setTimeout("__doPostBack('" + ele.id + "','')", 0);
    }
}

function PageLoad()
{
    //alert(document.location);
    var loc = document.location.href;
    var index = loc.indexOf("#");
    if (index >= 0) {
        var ele = loc.substr(index + 1);
        ele = unescape(ele);
        SalaryMenuItemClick(ele, true);
    }
}

function SalaryUpgradePopup(event, ele)
{
    var hoverText = '<a href="/signup.asp?subtype=2">Upgrade to PayScale Premium</a> to view.';
    _popup.Show(event, ele.parentNode, hoverText);
}

var _popup = new PopupLink("b9d5e3", "FFFFFF", "auto");
_popup.Initialize();

function PopupLink(borderColor, backColor, width)
{
    var _this = this;
    var _borderColor = borderColor;
    var _backColor = backColor;
    var _ele = null;
    var _parentEle = null;
    var _isShown = false;
    var _width = width;
    var _elements = [];

    this.Initialize = function()
    {
        if (!backColor)
        {
            _backColor = "ffe59a";
        }

        if (!borderColor)
        {
            _borderColor = "000";
        }
        if (!width)
        {
            _width = width;
        }
    }

    this.Dispose = function()
    {
        _this = null;
    }

    this.Show = function(event, parent, hoverText)
    {
        if (_isShown)
        {
            this.Hide(event);
        }
        _ele = document.createElement("div");
        _parentEle = parent;
        _parentEle.appendChild(_ele);
        _elements.push(_ele);
        CreateDiv(hoverText);
        $addHandler(document.body, "click", _this.Hide);
        _isShown = true;

    }

    this.Hide = function(event)
    {
        if (_isShown)
        {
            if (!IsWithinParent(event))
            {
                Sys.UI.DomElement.setVisible(_ele, false);
                $removeHandler(document.body, "click", _this.Hide);
                _parentEle.removeChild(_ele);
                HideAll();
                _ele = null;
                _parentEle = null;
                _isShown = false;
            }
        }
    }

    function HideAll()
    {
        for (var i = 0; i < _elements.length; i++)
        {
            if (_elements[i])
            {
                _elements[i].style.display = "none";
            }
        }
    }

    function IsWithinParent(event)
    {
        event = event || window.event;
        if (!event) return true;
        
        var currEle = event.target || event.srcElement;

        while (currEle && currEle != _parentEle)
        {
            currEle = currEle.parentNode;
        }
        return null != currEle;
    }

    function CreateDiv(text)
    {
        Sys.UI.DomElement.setVisible(_ele, false);
        var useDropShadow = !(Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7);
        if (useDropShadow)
        {
            CreateWithDropShadow(_ele, text)
        }
        else
        {
            CreateWithoutDropShadow(_ele, text);
        }
        _ele.style.position = "absolute";
        _ele.style.left = "55px";
        Sys.UI.DomElement.setVisible(_ele, true);
    }

    function CreateWithDropShadow(newDiv, text)
    {
        newDiv.className = 'dropShadowContainer';
        newDiv.style.zIndex = '999999';

        var contentDiv = document.createElement('div');
        newDiv.appendChild(contentDiv);
        contentDiv.className = 'dropShadowContent';

        contentDiv.style.backgroundColor = "#" + _backColor;
        contentDiv.style.border = "1px solid #" + _borderColor;
        contentDiv.style.padding = "5px";
        if (_width != "auto")
        {
            contentDiv.style.width = _width + "px";
        }
        contentDiv.innerHTML = text;

        newDiv.innerHTML += '<div class="dropShadowBottomLeft"></div><div class="dropShadowBottom"></div><div class="dropShadowBottomRight"></div><div class="dropShadowBottomRightCorner"></div><div class="dropShadowRightBottom"></div><div class="dropShadowRight"></div><div class="dropShadowRightTop"></div>';
    }

    function CreateWithoutDropShadow(newDiv, text)
    {
        newDiv.style.backgroundColor = "#" + _backColor;
        newDiv.style.border = "1px solid #" + _borderColor;
        newDiv.style.padding = "5px";
        
        if (_width != "auto")
        {
            newDiv.style.width = _width + "px";
        }
        newDiv.innerHTML = text;
    }
}