
Ext.override(Ext.data.Store, {
    startAutoRefresh : function(interval, params, callback, refreshNow){
        if(refreshNow){
            this.load({params:params, callback:callback});
        }
        if(this.autoRefreshProcId){
            clearInterval(this.autoRefreshProcId);
        }
        this.autoRefreshProcId = setInterval(this.load.createDelegate(this, [{params:params, callback:callback}]), interval*1000);
    },

    stopAutoRefresh : function(){
        if(this.autoRefreshProcId){
            clearInterval(this.autoRefreshProcId);
        }
    }    
    
});

Ext.override(Ext.LayoutRegion, {
	closeClicked : function(){
	    if(this.activePanel){
		 	Ext.MessageBox.confirm('Nieuwsbrief sluiten', 'Weet u zeker dat u de geopende nieuwsbrief wilt sluiten ? (Eventuele wijzigingen in een openstaande nieuwsbrief zijn automatisch opgeslagen.)', function(btn){
				if (btn == 'yes') {
			        this.remove(this.activePanel);				 
				} 
			}, this);
	    }
	}
})

Ext.Element.prototype.highlightX =  function(color, borderColor, borderSize, o){
    var el = this.getFxEl();
    o = o || {};

    el.queueFx(o, function(){
     	borderColor = borderColor || '#d3c41f';
        color = color || "ffff9c";
        attr = o.attr || "backgroundColor";

        this.clearOpacity();
        this.show();

        var origColor = this.getColor(attr);
        var restoreColor = this.dom.style[attr];
        endColor = (o.endColor || origColor) || "ffffff";

		var origBorder = this.dom.style['border'];
		var restoreBorder = (origBorder || "none");
		endBorder = (origBorder || "none");

        var after = function(){
            el.dom.style[attr] = restoreColor;
            el.dom.style['border'] = restoreBorder
            el.afterFx(o);
        };

        var a = {};
        a[attr] = {from: color, to: endColor};
        this.setStyle('border', '1px solid ' + borderColor);
        arguments.callee.anim = this.fxanim(a,
            o,
            'color',
            1,
            'easeIn', after);
    });
    return this;
}

/*
Ext.data.Connection.override({
    handleResponse : function(response){
	 	if (logindlg.verify(response)){
	        this.transId = false;
	        var options = response.argument.options;
	        this.fireEvent("requestcomplete", this, response, options);
	        if(typeof options.callback == "function"){
	            options.callback.call(options.scope||window, options, true, response);
	        }
	    }
    }
});*/

Ext.tree.TreeEditor.override({
    beforeNodeClick : function(node){
    }
});


Ext.form.Form.override({
	render : function(ct){
        ct = Ext.get(ct);
        var o = this.autoCreate || {
            tag: 'form',
            method : this.method || 'POST',
            id : this.id || Ext.id()
        };

        this.initEl(this.autoCreate === false ? ct : ct.createChild(o));
        this.root.render(this.el);

        this.items.each(function(f){
            f.render('x-form-el-'+f.id);
        });

        if(this.buttons.length > 0){
            // tables are required to maintain order and for correct IE layout
            var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
                cls:"x-form-btns x-form-btns-"+this.buttonAlign,
                html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
            }}, null, true);
            var tr = tb.getElementsByTagName('tr')[0];
            for(var i = 0, len = this.buttons.length; i < len; i++) {
                var b = this.buttons[i];
                var td = document.createElement('td');
                td.className = 'x-form-btn-td';
                b.render(tr.appendChild(td));
            }
        }
        return this;
    },
    
    getValues : function(){
        var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
        return Ext.urlDecode(fs);
    }    
	
});

Ext.LayoutRegion.override({
    hide : function(){
     alert('a');
        if(!this.collapsed){
            this.el.dom.style.left = "-2000px";
            this.el.hide();
            this.titleEl.hide();
        }else{
            this.collapsedEl.dom.style.left = "-2000px";
            this.collapsedEl.hide();
        }
        this.visible = false;
        this.fireEvent("visibilitychange", this, false);
    }
});

Ext.tree.TreeNode.override({

    removeChild : function(node){
        this.getOwnerTree().getSelectionModel().unselect(node);
        Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
        // if it's been rendered remove dom node
        if(this.childrenRendered){
            node.ui.remove();
        }
        if(this.childNodes.length < 1){
            this.collapse(false, false);
        }else{
            this.ui.updateExpandIcon();
        }
        return node;
    }
});

    
