﻿
//****************************************************************************
//* closes the popup window and refreshes the parent window
//*
//*
//*****************************************************************************
function RefreshParentBrowser()
{
    if(opener && !opener.closed)
    {
        opener.location.href = "Default.aspx";
    }

    window.close();
}

//****************************************************************************
//*changes the image source of a given image control's Id 
//*
//*****************************************************************************
function ChangeImage(img_name, img_src)
{
    document[img_name].src = img_src;
}
  
//****************************************************************************
//* Swaps the image of the given image id
//*
//*@param imageId the ID of the image element that needs it image source to be changed
//*@param imagePath1 source path of image1
//*@param imagePath2 source path of image2
//*@return the image is toggled or not
//*****************************************************************************
function SwapImage(imageId, imagePath1,imagePath2, toggled)
{
    var imgMain = document.getElementById(imageId);
    if(imgMain==null)
    {
        //nothing to do
        return;
    }
    
    var divParent;
    
    if(toggled)
    {
        imgMain.src = imagePath2;
    }
    else
    {
        imgMain.src = imagePath1;    
    }
}

/**
 * Handles browser-specific behaviour and values
 */
function BrowserManager()
{    
    // properties
    this.BrowserName = null;
    this.BrowserVersion = null;
    
    /**
     * detects browser name and version
     */
    this.DetermineBrowser = function()
    {
        var browserId = null;
        
        if(navigator.appVersion.indexOf("MSIE") != -1)
        {
            browserId = navigator.appVersion.split("MSIE")[1].split(';')[0];
            if(parseFloat(browserId) >= 5.5)
            {
                this.BrowserName="msie";
                this.BrowserVersion=browserId;
            }
        }
        else if(navigator.userAgent.indexOf("Gecko") != -1)
        {
            browserId = navigator.userAgent.substring(navigator.userAgent.indexOf("rv")+3, navigator.userAgent.length);
			// Gecko 1.5 or higher
            if(parseInt(browserId.split('.')[1]) >= 5)
            {
                this.BrowserName="firefox";
                this.BrowserVersion=3;
            }
        }
        else if(navigator.userAgent.indexOf("Safari") != -1)
        {
            browserId = navigator.userAgent.substring(navigator.userAgent.indexOf("Version/")+8, navigator.userAgent.indexOf("Safari") - 1);
            if(parseInt(browserId.charAt(0)) >= 2)
            {
                this.BrowserName="safari";
                this.BrowserVersion = browserId;
            }
            else
            {
                browserId = navigator.userAgent.substring(navigator.userAgent.indexOf("Safari/")+7, navigator.userAgent.length);
                if(parseInt(browserId.split('.')[0]) >= 412)
                {
                    this.BrowserName= "safari";
                    this.BrowserVersion = "2";
                }
            }
        }

        if(this.BrowserName == null || this.BrowserVersion == null)
        {
            this.BrowserName = "other";
            this.BrowserVersion = "unknown";
        }
    }
    
    /**
     * Sets up browser-specific resources
     */
    this.SetupResources = function() {
        if (this.BrowserName == null || this.BrowserVersion == null) {
            return;
        }

        //defaults: fallbacks for any values without browser-specific overrides below
        resources.CloseMiniOffset = 151;
        resources.OpenMiniTop = 0;
        resources.NavControlTop = 0;
        resources.HiddenTopNavBorder = "2px";
        resources.VisibleTopNavBorder = "0px";
        resources.HiddenCloseMiniOffset = -2;
        resources.VisibleCloseMiniOffset = 0;
        resources.HiddenCloseMiniPaddingTop = 0;
        resources.EroFooterTopLarge = 0;
        resources.EroFooterTopSmall = 0;
        resources.DDRoutePinLeft = "1px";
        resources.DDRoutePinTop = "-10px";

        var backgroundPanel = document.getElementById('BackgroundPanel') != null ? document.getElementById('BackgroundPanel') : null;

        if (this.BrowserName == "msie") {
            var version = parseFloat(this.BrowserVersion);

            //IE general overrides
            resources.VisibleCloseMiniOffset = 2;
            resources.HiddenCloseMiniPaddingTop = 2;
            resources.DDRoutePinLeft = "-13px";
            resources.DDRoutePinTop = "2px";

            // fix for notes tabs being positioned too high in IE
            if (document.getElementById('NotesTab') != null) {
                var tab = document.getElementById('NotesTab');
                tab.style.position = 'relative';
                tab.style.top = '3px';
            }

            if (version >= 6.0 && version < 7.0) {
                //IE 6 overrides
                resources.EroFooterTopLarge = 8;
                resources.EroFooterTopSmall = 15;

                // fixes vertical gap with tabs in IE6
                var tabTop = (queryLang == 'EN' ? '3px' : '6px');
                var tabPosition = 'relative';
                if (document.getElementById('FindOnaMap') != null && document.getElementById('FindaBusiness') != null && document.getElementById('FindaPerson') != null && document.getElementById('GetDrivingDirections') != null) {
                    document.getElementById('FindOnaMap').style.top = tabTop;
                    document.getElementById('FindOnaMap').style.position = tabPosition;
                    document.getElementById('FindaBusiness').style.top = tabTop;
                    document.getElementById('FindaBusiness').style.position = tabPosition;
                    document.getElementById('FindaPerson').style.top = tabTop;
                    document.getElementById('FindaPerson').style.position = tabPosition;
                    document.getElementById('GetDrivingDirections').style.top = tabTop;
                    document.getElementById('GetDrivingDirections').style.position = tabPosition;
                }

                if (backgroundPanel != null) {
                    backgroundPanel.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50);";
                    backgroundPanel.style.height = document.documentElement.clientHeight + "px";
                }

                //resources.OpenMiniTop = -10;
                //resources.NavControlTop = -10;
            }
            //IE 7 
            else {
                resources.CloseMiniOffset = 150;
                resources.CloseMiniBorderOffset = 1;

                if (backgroundPanel != null) {
                    backgroundPanel.style.filter = "alpha(opacity=50)";
                }
            }
        }
        else if (this.BrowserName == "firefox") {
            //Firefox general overrides
            if (backgroundPanel != null) {
                backgroundPanel.style.opacity = "0.5";
            }
        }
        else if (this.BrowserName == "safari") {
            //Safari general overrides
            if (backgroundPanel != null) {
                backgroundPanel.style.opacity = "0.5";
            }
        }
    }
    
    this.GetWindowHeight=function()
    {
        if(this.BrowserName == "msie")
        {
            windowHeight = document.documentElement.clientHeight;
        }
        else
        {
            windowHeight = window.innerHeight;
        }
    }    
}