var extLogPanel;
var extTabPanel;
var extWinTabPanel;
var extWinShowPdf;
var spot;
var winP;


function resizeW(div,wn)
{
//	retDiv(div).height=wn.getInnerHeight();
}
function retDivHeight(id)
{
        return retDiv_(id,0).offsetHeight;
}
function retDivWidth(id)
{
        return retDiv_(id,0).offsetWidth;
}
function resizeIFRAME_(id)
{
        h=id.offsetHeight+38;
	winP.setHeight((h<450?h:450));
}
function Ext_showIFRAME(titl,href,w,h,spt,max)
{
	if(winP)
		winP.close();

	winP = new Ext.Window({
		id : 'idIFRAME',
		title : titl,
		width : w, minWidth: w,
		height: h, minHeight: h,
		plain: true,
		layout: 'fit',
		bodyStyle:'',
		maximizable:max,
		items: {
			      xtype: 'panel',
			      contentEl : new Ext.ux.ManagedIFrame({
					      autoCreate: {
						       id: 'iFR',
						       frameBorder:0,
						       style:{
						       overflow:'auto;',
/*
						       height:'100%',
*/
						       width:'100%'
						       }
					       }
			       }) ,
			      listeners: 
				{
					render:function(panel){ Ext.get('iFR').dom.src = href; }, 
					beforedestroy : function() {Ext.get('iFR').dom.src = 'javascript:false';},
					single:true
				}
			}
		});
	if(spt)
	{
		winP.on('beforeshow',  function(){ updateSpot('idIFRAME'); });
		winP.on('beforeclose', function(){ updateSpot(); });
	}
	winP.on('maximize',    function(){ Ext.get('iFR').dom.src = href; });
	winP.on('restore',     function(){ Ext.get('iFR').dom.src = href; });
	winP.show();
//	resizeIFRAME();
}

var winI='';
function Ext_showINFOS(w,h,t,n)
{
	//------------------------
	var conn = new Ext.data.Connection();
	conn.request({
	    url: 'show_infos.php',
	    method: 'GET',
	    params: {"t": t, "n": n},
	    success: function(responseObject) 
			{ 
				winI = new Ext.Window({
					id : 'idINFOS',
					title : 'Informations pratiques',
					width : w,
					height: h,
					bodyStyle:'padding:5px;',
					maximizable:true,
					html : responseObject.responseText 
				});
				winI.on('beforeshow',  function(){ updateSpot('idINFOS'); });
				winI.on('beforeclose', function(){ updateSpot(); });
				winI.show();
			},
	    failure: function() { Ext.Msg.alert('Status', 'oupsssssssssssssss.'); }
	});
	//------------------------
}
function Ext_showContact(w,h,ct,sem)
{
        //------------------------
        var conn = new Ext.data.Connection();
        conn.request({
            url: 'show_contact.php',
            method: 'GET', 
            params: {"ct": ct, "sem": sem},
            success: function(responseObject)
                        {
				loadSCRIPT(responseObject.responseText);

				var
                                winC = new Ext.Window({
                                        id : 'idCONTACT',
                                        title : "Demande d'informations",
                                        width : w,
                                        height: h,
                                        bodyStyle:'padding:5px;',
                                        maximizable:true,
                                        loadScripts:true,
                                        html : responseObject.responseText
                                });
                                winC.on('beforeshow',  function(){ updateSpot('idCONTACT'); });
                                winC.on('beforeclose', function(){ updateSpot(); });
                                winC.show();
                        },
            failure: function() { Ext.Msg.alert('Status', 'oupsssssssssssssss.'); }
        });
        //------------------------
}
function Ext_show(titl,href,w,h,spt,max)
{
        //------------------------
        var conn = new Ext.data.Connection();
        conn.request({
            url: href,
            method: 'GET',
            params: {},
            success: function(responseObject)
                        {
                                loadSCRIPT(responseObject.responseText);

                                var
                                winC = new Ext.Window({
                                        id : 'idS',
                                        title : titl,
                                        width : w,
                                        height: h,
                                        bodyStyle:'padding:5px;',
                                        maximizable:max,
                                        loadScripts:true,
                                        html : responseObject.responseText
                                });
				if(spt)	
				{
                                	winC.on('beforeshow',  function(){ updateSpot('idS'); });
                                	winC.on('beforeclose', function(){ updateSpot(); });
				}
                                winC.show();
                                h=retDivHeight('idS')+1; winC.setHeight((h>100?h:100));
                                w=retDivWidth('idS')+1;  winC.setWidth((w>300?w:300));
                        },
            failure: function() { Ext.Msg.alert('Status', 'oupsssssssssssssss.'); }
        });
        //------------------------
}
function loadSCRIPT(HTML)
{
	replaceDiv("divSpec",HTML);
}
function updateSpot(id)
{
	if(bw.ns4 || bw.ns6) // pour eviter IE
	{
			if(typeof id == 'string' && id!='') 	spot.show(id);
		else 	if(!id && spot.active) 			spot.hide();
	}
}
function Ext_showIdent()
{
   var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 90,
        url:'/?pg=mcom',
        defaultType: 'textfield',

        items: [{
            fieldLabel: 'Identifiant',
            name: 'login',
            anchor:'100%'  // anchor width by percentage
        },{
            fieldLabel: 'Mot de passe',
            name: 'pass',
            anchor: '100%'  // anchor width by percentage
        }]
    });

    extLogPanel = new Ext.Window({
        title: 'Identification',
        id: 'idIdent',
        width: 260,
        height:130,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,

        buttons: [{
            text: 'Valider'
        }]
    });
	extLogPanel.on('beforeshow',  function(){ updateSpot('idIdent'); });
	extLogPanel.on('beforeclose', function(){ updateSpot(); });
	extLogPanel.show();
}

Ext.onReady(
	function()
	{
		spot = new Ext.Spotlight({
		       easing: 'easeOut',
		       duration: 0.1
		});


	//-------------- TEST WINDOW ------------------------------

	extTabPanel= new Ext.TabPanel({ 

			layoutOnTabChange: true,
		  //    defaults:{autoHeight: true},
		     // autoScroll:true,

			    applyTo        : 'hello-tabs',
			    autoTabs       : true,
			    activeTab      : 0,
			    deferredRender : false,
			    border         : false
			});

	    extTabPanel.getItem(0).on('beforeshow', function() { resizeLst(1); });
	    extTabPanel.getItem(1).on('beforeshow', function() { resizeLst(2); });
	    extTabPanel.getItem(2).on('beforeshow', function() { resizeLst(3); });

	    extWinTabPanel = new Ext.Window({
			applyTo     : 'hello-win',
			width 	    : 290, minWidth: 290, maxWidth: 290,
			height      : 411, minHeight: 353,
/*
closable: false,
draggable: true,
resizable : false,
*/
closeAction : 'show',
			plain       : true, 
			layout      : 'fit',
			items       : extTabPanel


		    });
	    extWinTabPanel.setPosition(4,121);
	    extWinTabPanel.show();
	    extWinTabPanel.on('resize', function() { extWinTabPanel.setWidth(290); resizeLstAfterResize(); });
/*
	//-------------- TEST WINDOW2 ------------------------------
	//    Ext.state.Manager.setProvider(
	 //           new Ext.state.SessionProvider({state: Ext.appState}));

	    var button = Ext.get('show2');

	    button.on('click', function(){


		// tabs for the center
		var tabs = new Ext.TabPanel({
		    region    : 'center',
		    margins   : '3 3 3 0',
		    activeTab : 0,
		    defaults  : {
					autoScroll : true
				},
		    items     : [{
			title    : 'Bogus Tab',
			html     : Ext.example.bogusMarkup
		     },{
			title    : 'Another Tab',
			html     : Ext.example.bogusMarkup
		     },{
			title    : 'Closable Tab',
			html     : Ext.example.bogusMarkup,
			closable : true
		    }]
		});

		// Panel for the west
		var nav = new Ext.Panel({
		    title       : 'Navigation',
		    region      : 'west',
		    split       : true,
		    width       : 200,
		layout: 'accordion',
		    collapsible : true,
		    margins     : '3 0 3 3',
		    cmargins    : '3 3 3 3'

		,items:[{
		     stateId:'first'
		    ,title:'First'
		    ,html: 'First'
		},{
		     stateId:'second'
		    ,title:'Second'
		    ,html: 'Second'
		}]
		});

		var win = new Ext.Window({
		    title    : 'Layout Window',
		    closable : true,
		    width    : 600,
		    height   : 350,
		    //border : false,
		    plain    : true,
		    layout   : 'border',
		    items    : [nav, tabs]
		});

		win.show(button);
	    });
	//-------------- TEST WINDOW3 ------------------------------
	    var button = Ext.get('show3');

	    button.on('click', function(){

		var accordion = new Ext.Panel({
			layout: 'accordion',
			layoutConfig: {
			titleCollapse: false,
			animate: true,
			fill: false
			},
			width: 200,
			collapsible: true,
			items: [ 
				{ title: 'Panel 1', html: 'Content' },
				{ title: 'Panel 2', html: 'Content' },
				{ title: 'Panel 3', html: 'Content' },
				{ title: 'Panel 4', html: 'Content' },
				{ title: 'Panel 5', html: 'Content' }
			],
			renderTo: 'acc-ct'
		});

		accordion.show(button);
	    });
	//-------------- TEST ACCORDION WINDOW ------------------------------
*/

	/*
	  region:'west',
			    id:'west-panel',
			    title:'Main Navigation Menu',
			    split:false,
			    width: 150,
			    collapsible: true,
			    margins:'0 0 0 5',
			    layout:'accordion',
			    layoutConfig:{
				fill:false,
				animate:true                        
			    },
			    items: [{
				contentEl: 'browse_menu',
				title:'Browse Categories',
				border:false,
			    },{
				title:'Menu 2',
				html: '
					<a href="#" id="link1">Link 1</a><br />
					<a href="#" id="link2">Link 2</a>
				       ',
				border:false,
			    },{
				title:'Menu 3',
				html: '
					<a href="#" id="link1">Link 1</a><br />
					<a href="#" id="link2">Link 2</a>
				       ',
				border:false,
			    }]
	*/
	//-------------- TEST ACCORDION WINDOW ------------------------------
	/*
	    var win_2 = new Ext.Window({
			applyTo     : 'hello-win',
			layout      : 'fit',
			width       : 300,
			height      : 392,
			closeAction :'hide',
			plain       : true, 
			items       : new Ext.TabPanel({ 
			    applyTo        : 'hello-tabs',
			    autoTabs       : true,
			    activeTab      : 0,
			    deferredRender : false,
			    border         : false
			}),

			buttons: [{
			}]
		    });
	    var button= Ext.get('show-btn');
	    win_2.setPosition(4,108);
	    win_2.show(button);


	    createWindow : function(){
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('acc-win');
		if(!win){
		    win = desktop.createWindow({
			id: 'acc-win',
			title: 'Accordion Window',
			width:250,
			height:400,
			iconCls: 'accordion',
			shim:false,
			animCollapse:false,
			constrainHeader:true,

			tbar:[{
			    tooltip:{title:'Rich Tooltips', text:'Let your users know what they can do!'},
			    iconCls:'connect'
			},'-',{
			    tooltip:'Add a new user',
			    iconCls:'user-add'
			},' ',{
			    tooltip:'Remove the selected user',
			    iconCls:'user-delete'
			}],

			layout:'accordion',
			border:false,
			layoutConfig: { animate:false },

			items: [
			    new Ext.tree.TreePanel({
				id:'im-tree',
				title: 'Online Users',
				loader: new Ext.tree.TreeLoader(),
				rootVisible:false,
				lines:false,
				autoScroll:true,
				tools:[{
				    id:'refresh',
				    on:{
					click: function(){
					    var tree = Ext.getCmp('im-tree');
					    tree.body.mask('Loading', 'x-mask-loading');
					    tree.root.reload();
					    tree.root.collapse(true, false);
					    setTimeout(function(){ // mimic a server call
						tree.body.unmask();
						tree.root.expand(true, true);
					    }, 1000);
					}
				    }
				}],
				root: new Ext.tree.AsyncTreeNode({
				    text:'Online',
				    children:[{
					text:'Friends',
					expanded:true,
					children:[{
					    text:'Jack',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Brian',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Jon',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Tim',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Nige',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Fred',
					    iconCls:'user',
					    leaf:true
					},{
					    text:'Bob',
					    iconCls:'user',
					    leaf:true
					}]
				    },{
					text:'Family',
					expanded:true,
					children:[{
					    text:'Kelly',
					    iconCls:'user-girl',
					    leaf:true
					},{
					    text:'Sara',
					    iconCls:'user-girl',
					    leaf:true
					},{
					    text:'Zack',
					    iconCls:'user-kid',
					    leaf:true
					},{
					    text:'John',
					    iconCls:'user-kid',
					    leaf:true
					}]
				    }]
				})
			    }), {
				title: 'Settings',
				html:'<p>Something useful would be in here.</p>',
				autoScroll:true
			    },{
				title: 'Even More Stuff',
				html : '<p>Something useful would be in here.</p>'
			    },{
				title: 'My Stuff',
				html : '<p>Something useful would be in here.</p>'
			    }
			]
		    });
		}
		win.show();
	    }
	*/
	// for example purposes

		  //  accordion.render($('me'));
	       // 	win_2.show($('show-btn'));

		Ext.QuickTips.init();

		// formulaire -------------------------------
		// formulaire -------------------------------
		// formulaire -------------------------------
		// formulaire -------------------------------
		var converted;
	/*
		converted = new Ext.form.ComboBox( { typeAhead: true, triggerAction: 'all', transform:'pays', width:135, forceSelection:true });
		converted = new Ext.form.ComboBox( { typeAhead: true, triggerAction: 'all', transform:'reg', width:135, forceSelection:true });
		converted = new Ext.form.ComboBox( { typeAhead: true, triggerAction: 'all', transform:'R_For', width:135, forceSelection:true });
		converted = new Ext.form.ComboBox( { typeAhead: true, triggerAction: 'all', transform:'R_date', width:135, forceSelection:true });
		converted = new Ext.form.ComboBox( { typeAhead: true, triggerAction: 'all', transform:'R_nbp', width:135, forceSelection:true });
	*/
	}
);


