﻿var BaseUI =
{
    OldScroll:   null,
    OldResize:   null,
    PopupPanel1: null,
    PopupPanel2: null,
    PopupPanel3: null,
    Initialize:  function()
    {
        BaseUI.Background = document.createElement('div')
        BaseUI.SetClass(BaseUI.Background, 'popupback')
        document.body.appendChild(BaseUI.Background)
        BaseUI.Popup       = document.getElementById('popup')
        BaseUI.PopupPanel1 = document.getElementById('popup-panel1')
        BaseUI.PopupPanel2 = document.getElementById('popup-panel2')
        BaseUI.PopupPanel3 = document.getElementById('popup-panel3')
        
        //Workaround for IE6 not supporting Fixed positioning
        if (BaseUI.IsIE6())
        {
            BaseUI.Background.style.position = 'absolute'
            BaseUI.Background.style.height   = '100%'
            BaseUI.Background.style.width    = '100%'

            BaseUI.OldScroll = window.onscroll
            BaseUI.OldResize = window.onresize

            window.onscroll = function()
            {
                if (BaseUI.OldScroll) BaseUI.OldScroll()
                BaseUI.WindowScroll()
            }
            
            window.onresize = function()
            {
                if (BaseUI.OldResize) BaseUI.OldResize()
                BaseUI.WindowResize()
            }

            BaseUI.WindowResize()
        }
        
        BaseUI.Collapse(BaseUI.Popup)
    },
    WindowResize: function()
    {
        BaseUI.Background.style.height = document.documentElement.clientHeight + document.documentElement.scrollTop  + "px"
        BaseUI.Background.style.width  = document.documentElement.clientWidth  + document.documentElement.scrollLeft + "px"
    },
    WindowScroll: function()
    {
        BaseUI.Background.style.height = document.documentElement.clientHeight + document.documentElement.scrollTop  + "px"
        BaseUI.Background.style.width  = document.documentElement.clientWidth  + document.documentElement.scrollLeft + "px"
    },
    IsIE6: function()
    {
        return (BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)
    },
    ShowPopup: function()
    {
        if (BrowserDetect.browser == 'Safari')
        {
            setTimeout('document.body.scrollTop = 0;', 100);
        }
        else
        {
            window.scrollTo(0, 0)
        }
        
        BaseUI.Expand(BaseUI.PopupPanel1)
        BaseUI.Collapse(BaseUI.PopupPanel2)
        BaseUI.Collapse(BaseUI.PopupPanel3)

        BaseUI.Expand(BaseUI.Background)
        BaseUI.Expand(BaseUI.Popup)
        
        return false
    },
    HidePopup: function()
    {       
        BaseUI.Collapse(BaseUI.Background)
        BaseUI.Collapse(BaseUI.Popup)
    },
    SetClass: function(el, className)
    {
        if (el)
        {
            try
            {
                if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version < 8))
                {
                    el.className = className
                }
                else
                {
                    el.setAttribute("class", className)
                }
            }
            catch (e) {}
        }
    },
    Expand: function(el)
    {
        if (el)
        {
            el.style.visibility = 'visible'
            el.style.display    = 'block'
        }
    },
    Collapse: function(el)
    {
        if (el)
        {
            el.style.visibility = 'hidden'
            el.style.display    = 'none'
        }
    },
    SetMask: function(el, mask, maskclass, normalclass)
    {
        if (el.value == '')
        {
            el.value = mask
        }
        
        if (el.value == mask)
        {
            BaseUI.SetClass(el, maskclass)    
        }
        else
        {
            BaseUI.SetClass(el, normalclass)
        }

        el.Mask        = mask
        el.MaskClass   = maskclass
        el.NormalClass = normalclass
        
        el.onfocus = function()
        {
            if (this.value == el.Mask)
            {
                this.value = ''
                BaseUI.SetClass(this, this.NormalClass)
            }
        }
        el.onblur = function()
        {
            if ((this.value == '') || (this.value == this.Mask))
            {
                this.value = this.Mask
                BaseUI.SetClass(this, this.MaskClass)
            }
            else
            {
                BaseUI.SetClass(this, this.NormalClass)
            }
        }
    }
}

var theOldOnLoad = window.onload

window.onload = function()
{
    if (theOldOnLoad) theOldOnLoad()
    
    BaseUI.Initialize()
}

