﻿
Type.registerNamespace('USAirways.Web.Shared.UI.Controls');

USAirways.Web.Shared.UI.Controls.PopOverBehavior = function(element) {

    USAirways.Web.Shared.UI.Controls.PopOverBehavior.initializeBase(this, [element]);

    // Properties
    this._objPopover = null;
    this._updatePanelID = null;
    this._offsetX = null;
    this._offsetY = null;
    this._pageRequestManager = null;
    this._calloutWidth = 15;
    this._positionElementID = null;
    this._timerID = null;
    this._origeltid = null;
    this._shown = false;
    //Handlers
    this._pageEndRequestHandler = null;
    this._windowResizeHandler = null;
    this._bodyClickHandler = null;
    this._updatePanelClickHandler = null;
    this._hideOnEsc = true;
    this._top = 0;
    this._left = 0;


    this._objPopover = new function() {
        this.elt = null;
        this.position = 'absolute';
        this.divShadow = null;
        this.tblCallout = null;
        this.IframeIE6 = null;
        this.ModalBackground = null;
        this.divModal = null;
    };
}

USAirways.Web.Shared.UI.Controls.PopOverBehavior.prototype = {
    initialize: function() {
        USAirways.Web.Shared.UI.Controls.PopOverBehavior.callBaseMethod(this, 'initialize');

        //var elt = this.get_element();
        this._objPopover.elt = this.get_element();


        this._addHandlers();

        //Fix for UpdatePanel not having CSS
        //handles actually enabling the show() method to work
        var parentNode = elt.parentNode;
        if (parentNode) {
            if (parentNode.style.display == 'none')
                parentNode.style.display = 'inline';
            if (parentNode.style.visibility == 'hidden')
                parentNode.style.visibility = '';
        }
        if (this._showAfterPostBack && this._loadVisible) {
            this.show();
        }
        else {
            this.hide();
        }
    },
    dispose: function() {
        this._clearHandlers();
        this._hoverCloseHandlers();
        USAirways.Web.Shared.UI.Controls.PopOverBehavior.callBaseMethod(this, 'dispose');
    },

    _setLocation: function(obj, x, y) {
        $(obj).css("top", y);
        $(obj).css("left", x);
    },
    //
    // Public methods
    //
    positionPopover: function() {

        var elt = this._objPopover.elt;

        this._objPopover.divShadow = (this._showDropShadow) ? this._initializeShadowDiv() : null;
        this._objPopover.tblCallout = (this._iCallOutDisplay()) ? this._initializeCalloutTable() : null;
        this._objPopover.IframeIE6 = (this._iframeRequiredIE6()) ? this._initializeIframeIE6() : null;
        this._objPopover.ModalBackground = (this._iModalDisplay()) ? this._initializeModalBackground() : null;

        //elt.style.position = 'absolute';
        elt.style.position = this._objPopover.position;
        elt.style.zIndex = this._calloutZindex;

        var positionEltLocation = this._positionEltLocation();
        var x = positionEltLocation.x;
        var y = positionEltLocation.y;
        this._top = y;
        this._left = x;
        this._setLocation(elt, x, y);
        //Sys.UI.DomElement.setLocation(elt, x, y);

        var bounds = this._getbounds(elt);
        var panelWidth = bounds.width;
        var panelHeight = bounds.height;

        if (this._objPopover.divShadow != null) {
            if (this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.Left) {
                this._setLocation(this._objPopover.divShadow, x - 3, y + 3);
                //Sys.UI.DomElement.setLocation(this._objPopover.divShadow, x - 3, y + 3);
            } else {
                this._setLocation(this._objPopover.divShadow, x + 3, y + 3);
                //Sys.UI.DomElement.setLocation(this._objPopover.divShadow, x + 3, y + 3);
            }
            this._setVisible(this._objPopover.divShadow, true);

            this._objPopover.divShadow.style.width = panelWidth + 'px';
            this._objPopover.divShadow.style.height = panelHeight + 'px';
        }
        //alert("show3");
        if (this._objPopover.tblCallout != null) {

            if (this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupLeft ||
                this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupRight) {
                this._setLocation(this._objPopover.tblCallout, x + panelWidth, y);
                //Sys.UI.DomElement.setLocation(this._objPopover.tblCallout, x + panelWidth, y);
            } else {
                this._setLocation(this._objPopover.tblCallout, x - this._calloutWidth, y);
                //Sys.UI.DomElement.setLocation(this._objPopover.tblCallout, x - this._calloutWidth, y);
            }
            this._setVisible(this._objPopover.tblCallout, true);
            this._setLocation(this._objPopover.tblCallout, x, y);
        }

        //handles the placement of the iframe if working with IE6 browsers, and takes into account if there is a drop shadow
        if (this._objPopover.IframeIE6 != null) {
            if (this._objPopover.divShadow == null) {
                if (this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.Left) {
                    this._setLocation(this._objPopover.IframeIE6, x - 3, y);
                    //Sys.UI.DomElement.setLocation(this._objPopover.IframeIE6, x - 3, y);
                }
                else {
                    this._setLocation(this._objPopover.IframeIE6, x + 3, y);
                    //Sys.UI.DomElement.setLocation(this._objPopover.IframeIE6, x + 3, y);
                }
                this._objPopover.IframeIE6.style.width = panelWidth + 6 + 'px';
                this._objPopover.IframeIE6.style.height = panelHeight + 3 + 'px';
            }
            else {
                this._setLocation(this._objPopover.IframeIE6, x , y);
                //Sys.UI.DomElement.setLocation(IframeIE6, x, y);
                this._objPopover.IframeIE6.style.width = panelWidth + 3 + 'px';
                this._objPopover.IframeIE6.style.height = panelHeight + 3 + 'px';
            }
            this._setVisible(this._objPopover.IframeIE6, true);
        }

        //this handles if modal is selected and formats iframe and background div
        if (this._objPopover.ModalBackground != null) {
            this._setLocation(this._objPopover.ModalBackground, 0, 0);
            //Sys.UI.DomElement.setLocation(this._objPopover.ModalBackground, 0, 0);
            this._objPopover.ModalBackground.style.width = this.documentWidth() + 'px';
            this._objPopover.ModalBackground.style.height = this.documentHeight() + 'px';
            //if (!elt.divModal) 
            if (this._objPopover.divModal == null) {
                var divModal = document.createElement('div');
                divModal.innerHTML = '&nbsp;';
                divModal.style.zIndex = this._calloutZindex - 5;
                divModal.style.position = 'absolute';
                divModal.style.display = 'none';
                divModal.style.border = 'none';

                elt.parentNode.insertBefore(divModal, elt);
                this._objPopover.divModal = divModal;
            }
            this._setLocation(this._objPopover.divModal, 0, 0);
            //Sys.UI.DomElement.setLocation(this._objPopover.divModal, 0, 0);
            //alert(this._modalBackgroundCSS);
            this._objPopover.divModal.className = this._modalBackgroundCSS;
            this._objPopover.divModal.style.width = this._objPopover.ModalBackground.style.width;
            this._objPopover.divModal.style.height = this._objPopover.ModalBackground.style.height;
            this._setVisible(this._objPopover.ModalBackground, true);
            this._setVisible(this._objPopover.divModal, true);
        }
    },

    show: function() {

        if (this._preDisplayScript !== null && this._preDisplayScript !== undefined) {
            eval(this._preDisplayScript);
        }

        if (this._blockHover && this._iHoverDisplay()) {
            return;
        }

        if (!this._positionElementExists()) {
            alert("Error Code: 100: No popover postioning element exists. Method: Show()");
            return;
        }

        var elt = this._objPopover.elt;
        if (elt == null || elt == undefined) {
            elt = this._objPopover.elt = this.get_element();
        }

        this._setVisible(elt, true);
        //if we hide it dont load it back after postback
        this._loadVisible = true;
        this.positionPopover();

        //this is used to stop an auto hide from the document click event that loads when the
        //hide on blur property is true
        this._shown = true;

        if (this._postDisplayScript !== null && this._postDisplayScript !== undefined) {
            eval(this._postDisplayScript);
        }

        //reset the object with the changes
        this._objPopover.elt = elt;



    },
    hide: function() {

        var elt = this._objPopover.elt;

        this._setVisible(elt, false);
 
        //if we hide it dont load it back after postback
        this._loadVisible = false;

        if (this._objPopover.divShadow != null)
            this._setVisible(this._objPopover.divShadow, false);

        if (this._objPopover.tblCallout != null)
            this._setVisible(this._objPopover.tblCallout, false);

        if (this._objPopover.IframeIE6 != null)
            this._setVisible(this._objPopover.IframeIE6, false);

        if (this._objPopover.ModalBackground != null)
            this._setVisible(this._objPopover.ModalBackground, false);

        if (this._objPopover.divModal != null)
            this._setVisible(this._objPopover.divModal, false);

        //need to clear these out so the zindexing can reset to the correct order
        this._objPopover.divShadow = null;
        this._objPopover.tblCallout = null;
        this._objPopover.IframeIE6 = null;
        this._objPopover.ModalBackground = null;
        this._objPopover.divModal = null;
 
        this.fireClosed();


    },

    /* Events */

    // Adds "closed" event handler.
    // Created by: PF
    add_closed: function(handler) {
        this.get_events().addHandler('closed', handler);
    },

    // Removes "closed" event handler.
    // Created by: PF
    remove_closed: function(handler) {
        this.get_events().removeHandler('closed', handler);
    },

    // Fires the "closed" event.
    // Created by: PF
    fireClosed: function() {
        var handler = this.get_events().getHandler('closed');
        if (handler) handler(this, Sys.EventArgs.Empty);
    },

    windowHeight: function() {
        var h = 0;
        try {
            return $(window).height();
        }
        catch (e) { return 768; }

    },
    windowWidth: function() {
        try {
            return $(window).width();
        }
        catch (e) { return 1024; }
    },
    documentHeight: function() {
        try {
            return $(document).height();
        }
        catch (e) { return 768; }
    },
    documentWidth: function() {
        try {
            return $(document).width();
        } catch (e) { return 1024; }

    },

    windowScrollLeft: function() {
        try {
            return $(window).scrollLeft();
        } catch (e) { }
        return 0;

    },

    windowScrollTop: function() {
        try {
            return $(window).scrollTop();
        } catch (e) { }
        return 0;
    },
    _createboundsobject: function() {
        //this will always return a valid bounds object, so no errors will get thrown.
        // worst case is position will be off
        var bounds = new Object();
        bounds.left = 0;
        bounds.top = 0;
        bounds.width = 0;
        bounds.height = 0;
        bounds.rightx = 0;
        bounds.bottomy = 0;
        return bounds;
    },
    _getbounds: function(elt) {
        var bounds = this._createboundsobject();
        try {

            var xy = $("#" + elt.id).position();
            var offsetxy = $("#" + elt.id).offset({ border: true, padding: true });
            bounds.left = bounds.x = parseInt((xy.left >= offsetxy.left ? xy.left : offsetxy.left));
            bounds.top = bounds.y = parseInt((xy.top >= offsetxy.top ? xy.top : offsetxy.top));
            bounds.width = parseInt($("#" + elt.id).outerWidth());
            bounds.height = parseInt($("#" + elt.id).outerHeight());
            bounds.rightx = bounds.left + bounds.width;
            bounds.bottomy = bounds.top + bounds.height;
        } catch (e) { }

        return bounds;
    },

    _onHover: function() {
        this.show();
    },
    _onUnhover: function() {
        this.hide();
    },
    //
    // Private methods
    //
    _addHandlers: function() {
        this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
        //var elt = this.get_element();
        elt = this._objPopover.elt;
        //alert("_addHandlers= " + elt.id);

        this._pageEndRequestHandler = Function.createDelegate(this, this._onEndRequest);
        this._pageRequestManager.add_pageLoaded(this._pageEndRequestHandler);

        this._pageInitRequestHandler = Function.createDelegate(this, this._onInitRequest);
        this._pageRequestManager.add_initializeRequest(this._pageInitRequestHandler)

        this._updatePanelClickHandler = Function.createDelegate(this, this._onClick);
        $addHandler(elt, 'click', this._updatePanelClickHandler);

        this._updatePanelKeyPressHandler = Function.createDelegate(this, this._onKeyPress);
        $addHandler(elt, 'keypress', this._updatePanelKeyPressHandler);

        this._windowResizeHandler = Function.createDelegate(this, this._onWindowResize);
        $addHandler(window, 'resize', this._windowResizeHandler);

        this._bodyClickHandler = Function.createDelegate(this, this._onBodyClick);
        //changed this from document.body to just document, to handle if popover is placed
        //outside of document body
        $addHandler(document, 'click', this._bodyClickHandler);


        if (this._iHoverDisplay()) {
            this._hoverHandlers();
        }

        this._postBackDelegate = Function.createDelegate(this, this._doPostBack);

    },
    _hoverHandlers: function() {

        this._hoverCloseHandlers();

        //add handlers
        var clickElement = $get(this._positionElementID);
        this._hoverHandler = Function.createDelegate(this, this._onHover);
        $addHandler(clickElement, 'mouseover', this._hoverHandler);
        $addHandler(clickElement, 'focus', this._hoverHandler);

        this._unhoverHandler = Function.createDelegate(this, this._onUnhover);
        $addHandler(clickElement, 'mouseout', this._unhoverHandler);
        $addHandler(clickElement, 'blur', this._unhoverHandler);


    },
    _hoverCloseHandlers: function() {
        try {
            //get the client click
            //alert("hover element= " + this._positionElementID);
            var clickElement = $get(this._positionElementID);

            //clear old ones so no
            if (this._hoverHandler) {
                $removeHandler(clickElement, 'mouseover', this._hoverHandler);
                $removeHandler(clickElement, 'focus', this._hoverHandler);
                this._hoverHandler = null;
            }

            if (this._unhoverHandler) {
                $removeHandler(clickElement, 'mouseout', this._unhoverHandler);
                $removeHandler(clickElement, 'blur', this._unhoverHandler);
                this._unhoverHandler = null;
            }
        } catch (e) { }
    },
    _clearHandlers: function() {

        //var elt = this.get_element();
        elt = this._objPopover.elt;
        //alert("clear handlers");
        try {


            if (this._pageRequestManager) {
                if (this._pageEndRequestHandler) {
                    this._pageRequestManager.remove_pageLoaded(this._onEndRequest);
                    this._pageEndRequestHandler = null;
                    this._pageRequestManager.remove_initializeRequest(this._onInitRequest);
                    this._pageInitRequestHandler = null;
                }
                this._pageRequestManager = null;
            }
        } catch (e) { }

        try {
            if (this._updatePanelClickHandler) {
                $removeHandler(elt, 'click', this._updatePanelClickHandler);
                this._updatePanelClickHandler = null;
            }
        } catch (e) { }

        try {
            if (this._updatePanelKeyPressHandler) {
                $removeHandler(elt, 'keypress', this._updatePanelKeyPressHandler);
                this._updatePanelKeyPressHandler = null;
            }
        } catch (e) { }


        try {
            if (this._windowResizeHandler) {
                $removeHandler(window, 'resize', this._windowResizeHandler);
                this._windowResizeHandler = null;
            }
        } catch (e) { }

        try {
            if (this._bodyClickHandler) {
                //changed this from document.body to just document, to handle if popover is placed
                //outside of document body
                $removeHandler(document, 'click', this._bodyClickHandler);
                this._bodyClickHandler = null;
            }
        } catch (e) { }

        this._postBackDelegate = null;



    },
    _positionEltLocation: function() {
        var clickElement = $get(this._positionElementID);
        //alert(clickElement.id);

        //var elt = this.get_element();
        elt = this._objPopover.elt;

        var eltbounds = this._getbounds(elt);

        //gets the x, y, width, height properties of the click element
        var clickbounds = this._getbounds(clickElement);

        var parentclickbounds;
        if (this._parentContainerID != null && this._parentContainerID != undefined) {
            //get the parentid bounds
            var parentclickElement = $get(this._parentContainerID);
            if (parentclickElement != null) {
                parentclickbounds = this._getbounds(parentclickElement);
                clickbounds.x = clickbounds.x - parentclickbounds.x;
                clickbounds.y = clickbounds.y - parentclickbounds.y;
            }
        }
        var x = 0;
        var y = 0;
        if (this._useOffsetPositionOnly) {
            x = this._offsetX;
            y = this._offsetY;
        }
        else {
            switch (this._horizontalAlign) {
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.Left:
                    x = clickbounds.x + this._determineXOffset();
                    //this is the triangle shadow point on the side of the updatepanel
                    //alert(this._iCallOutDisplay());
                    if (this._iCallOutDisplay()) {
                        x += this._calloutWidth;
                    }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.Center:
                    x = clickbounds.x + this._determineXOffset();
                    x += parseInt(clickbounds.width / 2);
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x += this._calloutWidth;
                    }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.Right:
                    x = clickbounds.x + this._determineXOffset() + clickbounds.width;
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x += this._calloutWidth;
                    }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.CenterScreen:
                    x = this._determineXOffset() + (parseInt((this.windowWidth() / 2)) - parseInt((eltbounds.width / 2)));
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x += this._calloutWidth;
                    }
                    x += this.windowScrollLeft();
                    if (x < 0) { x = 0; }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.CenterPage:
                    x = this._determineXOffset() + (parseInt((this.documentWidth() / 2)) - parseInt((eltbounds.width / 2)));
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x += this._calloutWidth;
                    }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupLeft:
                    x = clickbounds.x - this._determineXOffset();
                    x -= eltbounds.width;
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x -= this._calloutWidth;
                    }
                    break;
                case USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupRight:
                    x = clickbounds.x - this._determineXOffset();
                    x -= eltbounds.width;
                    x += clickbounds.width;
                    //this is the triangle shadow point on the side of the updatepanel
                    if (this._iCallOutDisplay()) {
                        x -= this._calloutWidth;
                    }
                    break;
            }

            y = clickbounds.y + this._determineYOffset();
            switch (this._verticalAlign) {
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.Middle:
                    y += parseInt(clickbounds.height / 2);
                    break;
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.Top:
                    break;
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.Bottom:
                    y += clickbounds.height;
                    break;
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.MiddleScreen:
                    y = this._determineYOffset() + (parseInt((this.windowHeight() / 2)) - parseInt((eltbounds.height / 2)));
                    y += this.windowScrollTop();
                    if (y < 0) { y = 0; }
                    break;
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.MiddlePage:
                    y = this._determineYOffset() + (parseInt((this.documentHeight() / 2)) - parseInt((eltbounds.height / 2)));
                    break;
                case USAirways.Web.Shared.UI.Controls.VerticalAlign.Above:
                    y -= eltbounds.height;
                    break;
            }
        }

        if (this._keepInView) {
            var keepinview = this._checkforinview(parentclickbounds, eltbounds, x, y);
            if (keepinview.x > 0) {
                x -= keepinview.x;
            }
            if (keepinview.y > 0) {
                y -= keepinview.y;
            }
        }

        return new Sys.UI.Point(x, y);
    },
    _determineYOffset: function() {
        if (this._ignoreOffsetPosition) {
            return 0;
        }
        return this._offsetY;
    },
    _determineXOffset: function() {
        if (this._ignoreOffsetPosition) {
            return 0;
        }
        return this._offsetX;
    },
    _checkforinview: function(parentclickbounds, eltbounds, currentx, currenty) {
        var w = 0;
        var h = 0;
        var windoww = this.windowWidth();
        var windowh = this.windowHeight();
        var parentouterx = 0;
        var parentoutery = 0;
        var keepinviewx = 0;
        var keepinviewy = 0;
        var objectx = (currentx + eltbounds.width);
        var objecty = (currenty + eltbounds.height);

        if (this._parentContainerID != null && this._parentContainerID != undefined) {
            w = parentclickbounds.width;
            h = parentclickbounds.height;
            if (w > windoww) {
                w = windoww;
            }
            if (h > windowh) {
                h = windowh
            }
            parentouterx = w + parentclickbounds.x;
            parentoutery = h + parentclickbounds.y;
            //since this object is contained in a parent, and positioning will be 0,0 at parents x,y need to
            //adjust of the parents offset from the window(0,0) position
            objectx += parentclickbounds.x;
            objecty += parentclickbounds.y;

        } else {
            w = windoww;
            h = windowh;
            parentouterx = w;
            parentoutery = h;
        }
        //adjust for any scrolling the user may have done
        parentouterx += this.windowScrollLeft();
        parentoutery += this.windowScrollTop();

        //used in debug
        //window.status = "X: " + eltbounds.x + "Y: " + eltbounds.y + " W: " + eltbounds.width + " H: " + eltbounds.height + " ID: " + this._parentContainerID;
        //this tests for bottom and right
        if (objectx > parentouterx) {
            keepinviewx = (objectx - parentouterx + 15) //used for padding ;
        }
        if (objecty > parentoutery) {
            keepinviewy = (objecty - parentoutery + 20) //used for padding ;
        }

        //this tests for top and left
        if (currentx < 0) {
            keepinviewx = (currentx + 15) //used for padding ;
        }
        if (currenty < 0) {
            keepinviewy = (currenty + 20) //used for padding ;
        }

        return new Sys.UI.Point(keepinviewx, keepinviewy);
    },
    _positionElementExists: function() {
        //alert(this._positionElementID);
        if (this._positionElementID) {
            var positionElement = $get(this._positionElementID);
            if (positionElement != null) {
                return true;
            }
        }
        return false;
    },
    _isInsideUpdatePanel: function(element) {
        while (element) {
            if (element.id && element.id === this.get_element().id) {
                return true;
            }
            element = element.parentNode;
        }
        return false;
    },
    _iCallOutDisplay: function() {
        return (this._calloutType !== USAirways.Web.Shared.UI.Controls.CalloutType.None);
    },
    _iModalDisplay: function() {
        return (this._displayType === USAirways.Web.Shared.UI.Controls.DisplayTypes.Modal);
    },
    _iHoverDisplay: function() {
        return (this._displayType === USAirways.Web.Shared.UI.Controls.DisplayTypes.Hover);
    },
    _iframeRequiredIE6: function() {
        return ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && (Sys.Browser.version < 7));
    },
    _updatePanelVisible: function() {
        return this._getVisible(this.get_element());
    },
    _initializeShadowDiv: function() {
        var divShadow = this._objPopover.divShadow;

        if (divShadow == null) {
            divShadow = document.createElement('div');
            divShadow.innerHTML = '&nbsp;';
            divShadow.style.zIndex = this._calloutZindex - 1;
            divShadow.style.position = 'absolute';
            divShadow.style.display = 'none';
            divShadow.style.backgroundColor = (this._calloutDropShadowColor) ? this._calloutDropShadowColor : '#999999';
            divShadow.style.opacity = .5;
            divShadow.style.MozOpacity = .5;
            divShadow.style.KhtmlOpacity = .5;
            divShadow.style.filter = 'alpha(opacity=50)';
            divShadow.id = this._objPopover.elt.id + "_divshadow";

            this._objPopover.elt.parentNode.insertBefore(divShadow, this._objPopover.elt);
        }
        return divShadow;
    },
    _initializeIframeIE6: function() {

        var iframeOverlay = this._objPopover.IframeIE6;

        if (iframeOverlay == null) {
            iframeOverlay = document.createElement('iframe');
            iframeOverlay.style.zIndex = this._calloutZindex - 3;
            iframeOverlay.src = 'javascript:false';
            iframeOverlay.style.position = 'absolute';
            iframeOverlay.style.display = 'none';
            iframeOverlay.style.margin = '0px';
            iframeOverlay.style.padding = '0px';
            iframeOverlay.style.opacity = 0;
            iframeOverlay.style.MozOpacity = 0;
            iframeOverlay.style.KhtmlOpacity = 0;
            iframeOverlay.style.filter = 'alpha(opacity=0)';
            iframeOverlay.style.border = 'none';
            //iframeOverlay.id = this._objPopover.elt.id + "_iframeIE6";

            this._objPopover.elt.parentNode.insertBefore(iframeOverlay, this._objPopover.elt);

        }

        return iframeOverlay;
    },

    _initializeModalBackground: function() {
        var ModalBackgroundOverlay = this._objPopover.ModalBackground;

        if (ModalBackgroundOverlay == null) {
            if (this._iframeRequiredIE6()) {
                ModalBackgroundOverlay = document.createElement('iframe');
                ModalBackgroundOverlay.src = 'javascript:false';
            }
            else {
                ModalBackgroundOverlay = document.createElement('div');
            }
            ModalBackgroundOverlay.style.zIndex = this._calloutZindex - 7;
            ModalBackgroundOverlay.style.position = 'absolute';
            ModalBackgroundOverlay.style.display = 'none';
            ModalBackgroundOverlay.style.margin = '0px';
            ModalBackgroundOverlay.style.padding = '0px';
            ModalBackgroundOverlay.style.opacity = 0;
            ModalBackgroundOverlay.style.MozOpacity = 0;
            ModalBackgroundOverlay.style.KhtmlOpacity = 0;
            ModalBackgroundOverlay.style.filter = 'alpha(opacity=0)';
            ModalBackgroundOverlay.style.border = 'none';
            //ModalBackgroundOverlay.id = this._objPopover.elt.id + "_ModalBackground";
            this._objPopover.elt.parentNode.insertBefore(ModalBackgroundOverlay, this._objPopover.elt);
        }

        return ModalBackgroundOverlay;
    },

    //this creates the triangle call out portion of the update panel
    _initializeCalloutTable: function() {

        var tblCallout = this._objPopover.tblCallout;

        if (tblCallout == null) {
            //alert("incallout");
            var tbl = document.createElement('table');
            var tb = document.createElement('tbody');

            tbl.style.position = 'absolute';
            tbl.style.display = 'none';
            tbl.border = '0px';
            tbl.cellPadding = '0px';
            tbl.cellSpacing = '0px';
            tbl.style.zIndex = this._calloutZindex + 10;

            if (this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupLeft ||
                this._horizontalAlign == USAirways.Web.Shared.UI.Controls.HorizontalAlign.PopupRight) {
                //alert(this._horizontalAlign);
                for (var i = 0; i < this._calloutWidth; i++) {
                    var tr = document.createElement('tr');

                    for (var j = this._calloutWidth; j > 0; j--) {
                        var tc = document.createElement('td');
                        if (j > i - 1) {
                            tc.style.backgroundColor = (this._calloutDropShadowColor) ? this._calloutDropShadowColor : '#999999';
                            var opacity = (1 - j / this._calloutWidth);
                            if (this._calloutType === USAirways.Web.Shared.UI.Controls.CalloutType.TransparentGradient) {
                                tc.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
                                tc.style.opacity = opacity;
                                tc.style.MozOpacity = opacity;
                                tc.style.KhtmlOpacity = opacity;
                                tc.style.MozOpacity = opacity;
                            }
                        }
                        //this is the border around the callout triangle
                        if ((j == i) || (i == 0)) {
                            tc.style.backgroundColor = (this._calloutBorderColor) ? this._calloutBorderColor : this._calloutColor;
                        }
                        tc.style.width = '1px';
                        tc.style.height = '1px';
                        tr.appendChild(tc);
                    }
                    tb.appendChild(tr);
                }
            }
            else {
                for (var i = 0; i < this._calloutWidth; i++) {
                    var tr = document.createElement('tr');
                    for (var j = 0; j < this._calloutWidth; j++) {
                        var tc = document.createElement('td');
                        if (j > i - 1) {
                            tc.style.backgroundColor = (this._calloutDropShadowColor) ? this._calloutDropShadowColor : '#999999';
                            var opacity = (1 - j / this._calloutWidth);
                            if (this._calloutType === USAirways.Web.Shared.UI.Controls.CalloutType.TransparentGradient) {
                                tc.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
                                tc.style.opacity = opacity;
                                tc.style.MozOpacity = opacity;
                                tc.style.KhtmlOpacity = opacity;
                                tc.style.MozOpacity = opacity;
                            }
                        }
                        //this is the border around the callout triangle
                        if ((j == i) || (i == 0)) {
                            tc.style.backgroundColor = (this._calloutBorderColor) ? this._calloutBorderColor : this._calloutColor;
                        }
                        tc.style.width = '1px';
                        tc.style.height = '1px';
                        tr.appendChild(tc);
                    } //end for
                    tb.appendChild(tr);
                } //end for
            } //end if
            tbl.appendChild(tb);

            tblCallout = tbl;
            this._objPopover.elt.parentNode.insertBefore(tblCallout, this._objPopover.elt);

        }

        return tblCallout;
    },
    _getVisible: function(elt) {
        try {
            return (elt.style.display !== 'none');
        }
        catch (e) {
            return false;
        }
    },
    _setVisible: function(elt, value) {
        if (value) {
            elt.style.display = '';

        }
        else {
            elt.style.display = 'none';
        }

    },
    _doPostBack: function() {
        if (this.get_fireCloseEvent()) {
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.abortPostBack();
            //alert("postback");
            __doPostBack(this.get_uniqueID(), '');
        }
        //alert("hiding postback");
        this.hide();
    },

    //
    // Event delegates
    //
    _onInitRequest: function(sender, arg) {
        var element = arg.get_postBackElement();
        //alert("_onInitRequest=" + element.id);
        if (this._updatePanelVisible() && this.get_fireCloseEvent()) {
            //alert(element.id);
            //alert(this.get_clientID());
            if (this.get_clientID() !== element.id) {
                if (!this._isInsideUpdatePanel(element)) {
                    arg.set_cancel(true);
                }
            }
        }
    },
    _onEndRequest: function(sender, arg) {
        var elt = this.get_element();
        if (!elt) {
            return;
        }
        if (this._iHoverDisplay()) {
            //clear and reset
            this._hoverHandlers();
        }
        var dataItems = arg.get_dataItems()[this.get_clientID()];
        if (dataItems !== undefined) {
            //var dataObject = eval('(' + dataItems + ')');
            if (typeof (dataItems) === 'object') {
                this._positionElementID = dataItems[0].Value;
                if (dataItems[1].Value) {
                    this.show();
                }
                else {
                    this.hide();
                }
            }
        }
        else {
            if (this._updatePanelVisible()) {
                var updatedPanels = arg.get_panelsUpdated();

                for (i = 0; i < updatedPanels.length; i++) {
                    if (updatedPanels[i].id === elt.id) {
                        this.show();
                    }
                }
            }
        }

        if (this._timerID) {
            window.clearTimeout(this._timerID);
            this._timerID = null;
        }
    },
    _onBodyClick: function(e) {
        if (this._updatePanelVisible()) {
            var element = e.target ? e.target : e.srcElement;
            if (!this._isInsideUpdatePanel(element)) {
                if (this.get_fireCloseEvent()) {
                    //Delay to handle multiple requests when
                    //user clicks on postback element on page
                    //causing another postback event
                    //alert("onbodyclick");
                    this._timerID = window.setTimeout(this._postBackDelegate, 50);
                }
                else {
                    //only allow a onblur hide if set to true in properties
                    //alert(this._hideOnBlur);
                    if (this._hideOnBlur && !this._shown) {
                        //alert("hiding");
                        this.hide();
                    }
                    //this is used to stop an auto hide from the document click event that loads when the
                    //hide on blur property is true
                    this._shown = false;
                }
            }
        }
    },
    _onWindowResize: function() {
        if (this._updatePanelVisible()) {
            this.show();
        }
    },
    _onKeyPress: function(e) {
        try {
            if (e.charCode == 27) {
                if (this._hideOnEsc == true)
                    this.hide();
                else {
                    e.cancel = true;
                    e.cancelBubble = true;
                    e.returnValue = false;
                    e.stopPropagation();
                    e.preventDefault();
                    return false;
                }
            }
        } catch (e) { }
    },
    _onClick: function(e) {
        if (this._updatePanelVisible()) {
            var target = e.target ? e.target : e.srcElement;
            //Safari fix
            if (e.target) {
                if (e.target.nodeType == 3) {
                    target = target.parentNode;
                }
            }

            if ((target.getAttribute('uppHide') == 'true')
                && (target.getAttribute('uppTarget') == this.get_element().id)) {
                //alert("onlick");
                if (this.get_fireCloseEvent()) {
                    this._doPostBack();
                } else {
                    this.hide();
                }

            }
        }
    },
    //
    // Properties: these are required for serverside to client side passthrough. must be one for
    // every porperty available server side, that you wish to access from client
    //
    get_ignoreOffsetPosition: function() {
        return this._ignoreOffsetPosition;
    },
    set_ignoreOffsetPosition: function(value) {
        this._ignoreOffsetPosition = value;
    },
    get_topPosition: function() {
        return this._top;
    },
    get_leftPosition: function() {
        return this._left;
    },
    get_behaviorID: function() {
        return this._behaviorID;
    },
    set_behaviorID: function(value) {
        this._behaviorID = value;
    },

    get_offsetX: function() {
        return this._offsetX;
    },
    set_offsetX: function(value) {
        this._offsetX = value;
    },

    get_offsetY: function() {
        return this._offsetY;
    },
    set_offsetY: function(value) {
        this._offsetY = value;
    },

    get_clientID: function() {
        return this._clientID;
    },
    set_clientID: function(value) {
        this._clientID = value;
    },

    get_uniqueID: function() {
        return this._uniqueID;
    },
    set_uniqueID: function(value) {
        this._uniqueID = value;
    },

    get_calloutColor: function() {
        return this._calloutColor;
    },
    set_calloutColor: function(value) {
        this._calloutColor = value;
    },

    get_calloutBorderColor: function() {
        return this._calloutBorderColor;
    },
    set_calloutBorderColor: function(value) {
        this._calloutBorderColor = value;
    },

    get_calloutDropShadowColor: function() {
        return this._calloutDropShadowColor;
    },
    set_calloutDropShadowColor: function(value) {
        this._calloutDropShadowColor = value;
    },

    get_showDropShadow: function() {
        return this._showDropShadow;
    },
    set_showDropShadow: function(value) {
        this._showDropShadow = value;
    },

    get_calloutType: function() {
        return this._calloutType;
    },
    set_calloutType: function(value) {
        this._calloutType = value;
    },

    get_displayType: function() {
        return this._displayType;
    },
    set_displayType: function(value) {
        this._displayType = value;
    },

    get_horizontalAlign: function() {
        return this._horizontalAlign;
    },
    set_horizontalAlign: function(value) {
        this._horizontalAlign = value;

    },

    get_verticalAlign: function() {
        return this._verticalAlign;
    },
    set_verticalAlign: function(value) {
        this._verticalAlign = value;
    },

    get_loadVisible: function() {
        return this._loadVisible;
    },
    set_loadVisible: function(value) {
        this._loadVisible = value;
    },

    get_positionElementID: function() {
        return this._positionElementID;
    },
    set_positionElementID: function(value) {
        this._positionElementID = value;
    },

    get_fireCloseEvent: function() {
        return this._fireCloseEvent;
    },
    set_fireCloseEvent: function(value) {
        this._fireCloseEvent = value;
    },


    get_calloutWidth: function() {
        return this._calloutWidth;
    },
    set_calloutWidth: function(value) {
        this._calloutWidth = value;
    },

    get_showAfterPostBack: function() {
        return this._showAfterPostBack;
    },
    set_showAfterPostBack: function(value) {
        this._showAfterPostBack = value;
    },

    get_preDisplayScript: function() {
        return this._preDisplayScript;
    },
    set_preDisplayScript: function(value) {
        this._preDisplayScript = value;
    },

    get_postDisplayScript: function() {
        return this._postDisplayScript;
    },
    set_postDisplayScript: function(value) {
        this._postDisplayScript = value;
    },

    get_keepInView: function() {
        return this._keepInView;
    },
    set_keepInView: function(value) {
        this._keepInView = value;
    },

    get_calloutZindex: function() {
        return this._calloutZindex;
    },
    set_calloutZindex: function(value) {
        this._calloutZindex = value;
    },

    get_hideOnBlur: function() {
        return this._hideOnBlur;
    },
    set_hideOnBlur: function(value) {
        this._hideOnBlur = value;
    },

    get_parentContainerID: function() {
        return this._parentContainerID;
    },
    set_parentContainerID: function(value) {
        this._parentContainerID = value;
    },

    get_useOffsetPositionOnly: function() {
        return this._useOffsetPositionOnly;
    },
    set_useOffsetPositionOnly: function(value) {
        this._useOffsetPositionOnly = value;
    },

    get_calloutColor: function() {
        return this._calloutColor;
    },
    set_calloutColor: function(value) {
        this._calloutColor = value;
    },

    get_blockHover: function() {
        return this._blockHover;
    },
    set_blockHover: function(value) {
        this._blockHover = value;
    },

    get_modalBackgroundCSS: function() {
        return this._modalBackgroundCSS;
    },
    set_modalBackgroundCSS: function(value) {
        this._modalBackgroundCSS = value;
    }


}

USAirways.Web.Shared.UI.Controls.PopOverBehavior.registerClass('USAirways.Web.Shared.UI.Controls.PopOverBehavior', Sys.UI.Behavior);


//Enums

USAirways.Web.Shared.UI.Controls.HorizontalAlign = function() {
    throw Error.invalidOperation();
};
USAirways.Web.Shared.UI.Controls.HorizontalAlign.prototype =
{
    Right: 0,
    Center: 1,
    Left: 2,
    CenterScreen: 3,
    PopupLeft: 4,
    CenterPage: 5,
    PopupRight: 6
}
USAirways.Web.Shared.UI.Controls.HorizontalAlign.registerEnum('USAirways.Web.Shared.UI.Controls.HorizontalAlign');


USAirways.Web.Shared.UI.Controls.VerticalAlign = function() {
    throw Error.invalidOperation();
};
USAirways.Web.Shared.UI.Controls.VerticalAlign.prototype =
{
    Middle: 0,
    Top: 1,
    Bottom: 2,
    MiddleScreen: 3,
    Above: 4,
    MiddlePage: 5
}
USAirways.Web.Shared.UI.Controls.VerticalAlign.registerEnum('USAirways.Web.Shared.UI.Controls.VerticalAlign');

USAirways.Web.Shared.UI.Controls.CalloutType = function() {
    throw Error.invalidOperation();
};
USAirways.Web.Shared.UI.Controls.CalloutType.prototype =
{
    TransparentGradient: 0,
    Solid: 1,
    None: 2
}
USAirways.Web.Shared.UI.Controls.CalloutType.registerEnum('USAirways.Web.Shared.UI.Controls.CalloutType');



USAirways.Web.Shared.UI.Controls.DisplayTypes = function() {
    throw Error.invalidOperation();
};
USAirways.Web.Shared.UI.Controls.DisplayTypes.prototype =
{
    Modal: 0,
    Hover: 1,
    Popout: 2
}
USAirways.Web.Shared.UI.Controls.DisplayTypes.registerEnum('USAirways.Web.Shared.UI.Controls.DisplayTypes');


// Notifiy that the script is loaded.
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

