// IE7 has a problem where masking and unmasking a panel causes it to render in
// the top left hand corner of the screen, so we add a check for IE7 before
// using setStyle.
//
// http://extjs.com/forum/showthread.php?t=13102

Ext.override( Ext.Element, {
    mask : function(msg, msgCls){
        if(!Ext.isIE7 && this.getStyle("position") == "static"){
            this.setStyle("position", "relative");
        }
        if(this._maskMsg){
            this._maskMsg.remove();
        }
        if(this._mask){
            this._mask.remove();
        }

        this._mask = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask"}, true);

        this.addClass("x-masked");
        this._mask.setDisplayed(true);
        if(typeof msg == 'string'){
            this._maskMsg = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask-msg", cn:{tag:'div'}}, true);
            var mm = this._maskMsg;
            mm.dom.className = msgCls ? "ext-el-mask-msg " + msgCls : "ext-el-mask-msg";
            mm.dom.firstChild.innerHTML = msg;
            mm.setDisplayed(true);
            mm.center(this);
        }
        if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && this.getStyle('height') == 'auto'){             this._mask.setSize(this.dom.clientWidth, this.getHeight());
        }
        return this._mask;
    }
});


// Fixes a bug where IE8 only displays half of the datetime calendar.
// http://extjs.com/forum/showthread.php?t=63677
Ext.override(Ext.menu.Menu, {
    autoWidth : function(){
        var el = this.el, ul = this.ul;
        if(!el){
            return;
        }
        var w = this.width;
        var isIE8 = navigator.userAgent.toLowerCase().indexOf('msie 8')>-1;
        if(w){
            el.setWidth(w);
        }else if(Ext.isIE && !isIE8){
            el.setWidth(this.minWidth);
            var t = el.dom.offsetWidth; // force recalc
            el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
        }
    }
});


// In IE7 setting hideTrigger to true on a combo box causes it to disappear.
// This fixes that.
Ext.form.TriggerField.override({
    afterRender: function() {
         Ext.form.TriggerField.superclass.afterRender.call(this);
    }
});

