 
Ext.Button = Ext.extend(Ext.Element, {
	renderTo: '',
    text: '',
    handler: function(){},
	 
    constructor: function(config) {
		config = config || {};
        
		Ext.apply(this, config);
		 if(!this.template){
            if(!Ext.Button.buttonTemplate){
                // hideous table template
                Ext.Button.buttonTemplate = new Ext.Template(
                    '<table id="{1}-tbl" cellspacing="0" class="x-btn x-btn-noicon"><tbody class="x-btn-small x-btn-icon-small-left">',
                    '<tr><td class="x-btn-tl"><i>&#160;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&#160;</i></td></tr>',
                    '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em unselectable="on"><button type="button" class="x-btn-text" id="{1}-btn">{2}</button></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>',
                    '<tr><td class="x-btn-bl"><i>&#160;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&#160;</i></td></tr>',
                    '</tbody></table>');
                Ext.Button.buttonTemplate.compile();
            }
            this.template = Ext.Button.buttonTemplate;
        }
		this.el = Ext.get(this.renderTo);
		this.initMarkup();
		this.initEvents();

    },
	initMarkup: function(){
	 var dh = Ext.DomHelper;
	 this.btn = this.template.append(this.el, {1:this.renderTo,2:this.text}, true);
 	},
	
	 initEvents: function() {
        this.btn.on('click', this.handler, this);
	 }
});





Ext.MessageBox = function(){
    var dlg, opt, mask, waitTimer;
    var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
    var buttons, activeTextEl, bwidth;

    // private
    var handleButton = function(button){
        dlg.hide();
        Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
    };

    // private
    var handleHide = function(){
        if(opt && opt.cls){
            dlg.el.removeClass(opt.cls);
        }
        if(waitTimer){
            Ext.TaskMgr.stop(waitTimer);
            waitTimer = null;
        }
    };

    // private
    var updateButtons = function(b){
       
        return '';
    };

    // private
    var handleEsc = function(d, k, e){
        if(opt && opt.closable !== false){
            dlg.hide();
        }
        if(e){
            e.stopEvent();
        }
    };

    return {
        /**
         * Returns a reference to the underlying {@link Ext.BasicDialog} element
         * @return {Ext.BasicDialog} The BasicDialog element
         */
        getDialog : function(){
           if(!dlg){
		     dlg = new Ext.Template(
                   '<div class="{classCSS}" id="{type}"><div class="message">',
				   '<h3>{title}</h3>',
					'<p>{msg}</p>',
					'</div></div>');
                dlg.compile();
		   	}
            return dlg;
        },

        /**
         * Updates the message box body text
         * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
         * the XHTML-compliant non-breaking space character '&amp;#160;')
         * @return {Ext.MessageBox} This message box
         */
        updateText : function(text){
     
            return this;
        },

        updateProgress : function(value, text){
            if(text){
                this.updateText(text);
            }
            pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
            return this;
        },        

   
        isVisible : function(){
            return dlg && dlg.isVisible();  
        },

        hide : function(){
            if(this.isVisible()){
                dlg.hide();
            }  
        },

      
        show : function(options){
			var d = this.getDialog();
            opt = options || {id:'', classCSS:'',title:'',msg:''};
			opt.id = opt.id || 'messagebox';
			opt.classCSS = opt.classCSS || 'Confirmation';
         	var message = d.append(Ext.getBody(), {type :opt.id,classCSS:opt.classCSS,title:opt.title,msg:opt.msg}, true);
			MessageBar("messagebox");
            return this;
        },

    
        progress : function(title, msg){
            this.show({
                title : title,
                msg : msg,
                buttons: false,
                progress:true,
                closable:false,
                minWidth: this.minProgressWidth
            });
            return this;
        },

 
        alert : function(title, msg, fn, scope){
            this.show({
              	id : 'messagebox',
                classCSS : 'Erreur',
			
			    title : title,
                msg : msg,
                buttons: this.OK,
                fn: fn,
                scope : scope
            });
            return this;
        },

        wait : function(msg, title){
            this.show({
				id:"messagebox",
				classCSS:"Confirmation",
                title : title,
                msg : msg,
                buttons: false,
                closable:false,
                progress:true,
                modal:true,
                width:300,
                wait:true
            });
			/*
            waitTimer = Ext.TaskMgr.start({
                run: function(i){
                   // Ext.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
                },
                interval: 1000
            });
			*/
            return this;
        },

    
        confirm : function(title, msg, fn, scope){
            this.show({
                title : title,
                msg : msg,
                buttons: this.YESNO,
                fn: fn,
                scope : scope
            });
            return this;
        },

      
        prompt : function(title, msg, fn, scope, multiline){
            this.show({
                title : title,
                msg : msg,
                buttons: this.OKCANCEL,
                fn: fn,
                minWidth:250,
                scope : scope,
                prompt:true,
                multiline: multiline
            });
            return this;
        },

        /**
         * Button config that displays a single OK button
         * @type Object
         */
        OK : {ok:true},
        /**
         * Button config that displays Yes and No buttons
         * @type Object
         */
        YESNO : {yes:true, no:true},
        /**
         * Button config that displays OK and Cancel buttons
         * @type Object
         */
        OKCANCEL : {ok:true, cancel:true},
        /**
         * Button config that displays Yes, No and Cancel buttons
         * @type Object
         */
        YESNOCANCEL : {yes:true, no:true, cancel:true},

        /**
         * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
         * @type Number
         */
        defaultTextHeight : 75,
        /**
         * The maximum width in pixels of the message box (defaults to 600)
         * @type Number
         */
        maxWidth : 600,
        /**
         * The minimum width in pixels of the message box (defaults to 100)
         * @type Number
         */
        minWidth : 100,
        /**
         * The minimum width in pixels of the message box if it is a progress-style dialog.  This is useful
         * for setting a different minimum width than text-only dialogs may need (defaults to 250)
         * @type Number
         */
        minProgressWidth : 250,
        /**
         * An object containing the default button text strings that can be overriden for localized language support.
         * Supported properties are: ok, cancel, yes and no.
         * Customize the default text like so: Ext.MessageBox.buttonText.yes = "Sí";
         * @type Object
         */
        buttonText : {
            ok : "OK",
            cancel : "Cancel",
            yes : "Yes",
            no : "No"
        }
    };
}();
/**
 * Shorthand for {@link Ext.MessageBox}
 */
Ext.Msg = Ext.MessageBox;

function callPopUp(a){var args=callPopUp.arguments;pUrl=(!args[0]) ? null : args[0];if(!pUrl){ return;};var w=(!args[1]) ? 770 : args[1];var h=(!args[2]) ? 'auto' : args[2]+"px";var h2=(!args[2]) ? 'auto' : (args[2]-30)+"px";Ext.fly('TitrePopupSite').update((!args[3]) ? '' : args[3]);divPopupSite.update('');Ext.fly('spryPopupSite').setWidth(w + 'px');divPopupSite.setWidth(w + 'px').setHeight(h2);Ext.select('#spryPopupSite div:first').setHeight(h);spryPopupSite.displayPopupDialog(true);divPopupSite.load({url:pUrl,scripts:true});return false;};

