Ext.onReady(function(){
	var v = navigator.userAgent;
	var ie6 = (v.indexOf('MSIE 6') != -1 ? true : false);
	var ie7 = (v.indexOf('MSIE 7') != -1 ? true : false);
	var ff = (v.indexOf('Firefox') != -1 ? true : false);
	
	if (!ie6 && !ie7 && !ff)
		alert("L'application n'a pas �t� test�e avec votre navigateur internet, il est probable qu'elle ne fonctionne pas correctement.\n\n" +
		"Pour pouvoir utiliser cette application de fa�on optimale, utilisez Internet Explorer en version 6 ou sup�rieure ou Mozilla Firefox en version 2 ou sup�rieure.");	
	
	Ext.QuickTips.init();

	var getListRequestURL = 'synchro.jsp?codeLangue=fr&idFormation=1&listId=';
 	document.listes.liste_Investigations = new fcbm.model.List(getListRequestURL + 'Investigations');
	document.listes.liste_Diagnostics = new fcbm.model.List(getListRequestURL + 'Diagnostics'); 
	document.listes.liste_CytoSigns = new fcbm.model.List(getListRequestURL + 'CytoSigns'); 
	
	new fcbm.model.Compteurs ("FrequentationGlobale");
	
	document.currentFile = null;
	/*
	 * Tabpanel de base
	 * Contient la page d'accueil
	 */
	var tabPanel = new Ext.TabPanel({
		region:'center',
		id: 'mainTabPanel',
		deferredRender: false,
		layoutOnTabChange: true,
		bodyStyle: 'background-color: #E7D8DA',
		autoScroll: true,
		activeTab: 0,
		items: [{
				xtype: 'panel',
				contentEl:'accueil',
				title: 'Accueil',
				id: 'home',
				bodyStyle: 'background: #E7D8DA url(../images/fond-contenu.gif) no-repeat fixed right 100px',
				closable:false,
				autoScroll:true,
				autoHeight: true,
				buttonAlign: 'right',
				buttons: [{
					text: "Commencez � travailler !",
					id: 'buttonBeginWork',
					ctCls: 'divBeginWork',
					handler: function () {Ext.getCmp('documentList').expand();}
				}],
				buttonAlign: 'left'
			},
			{
				xtype: 'panel',
				title: 'Aide',
				bodyStyle: 'background: #E7D8DA url(../images/fond-contenu.gif) no-repeat fixed right 100px; padding: 5px;',
				autoScroll: true,
				autoLoad: {
				    url: "data/help/" + user.codeLangue + "/index.htm", 
				    discardUrl: false, 
				    nocache: false,
				    text: "Chargement de l'aide...",
				    timeout: 30,
				    scripts: false
				}	
			}]
	});
   
	// DocumentList
	document.grid_dossiers = new fcbm.component.DocumentList ({
		title: 'Les dossiers � �tudier', 
 		documentType: 'training',
 		tabPanel: tabPanel,
 		codeLangue: user.codeLangue
	});
	document.grid_atlas = new fcbm.component.DocumentList ({
		title: "Les pages d'atlas � consulter", 
 		documentType: 'atlas',
 		tabPanel: tabPanel,
 		codeLangue: user.codeLangue
	});

	var viewport = new Ext.Viewport({
        layout:'border',
        items:[
				{
				/*
				 * Liste des documents
				 */
                region:'west',
                id:'documentList',
                title:'Cliquez pour s�lectionner :',
                width: 300,
                margins:'0 0 0 0',
				split: true,
				collapsible: true,
				collapsed: true,
                layoutConfig:{
                    animate:false
                },
                items: [
					document.grid_dossiers,
					document.grid_atlas
			]
            },
			/*
			 * Tabpanel
			 */
			tabPanel
         ]
    });

	/*
	 * Hack pour que les composants dans le tabpanel se resize correctement
	 * lorsque que l'on affiche/masque la liste des documents
	 */
	Ext.getCmp('documentList').on('beforecollapse', function (container, layout) {
		for (var i = 0; i < this.els.length; i++) {
			var el = Ext.getCmp(this.els[i]);
			if (el != null) 
				el.doLayout(true);
		}
	}, elResizeManuel, {delay: 100});
	Ext.getCmp('documentList').on('beforeexpand', function (container, layout) {
		for (var i = 0; i < this.els.length; i++) {
			var el = Ext.getCmp(this.els[i]);
			if (el != null) 
				el.doLayout(true);
		}
	}, elResizeManuel, {delay: 1000});
	

	// Loader
	var varArray = new Array (
		"document.listes.liste_CytoSigns.ready",
		"document.listes.liste_Investigations.ready",
		"document.listes.liste_Diagnostics.ready", 
		"document.grid_dossiers.ready",
		"document.grid_atlas.ready"
	);
	
	document.loader = new fcbm.component.Loader("Initialisation de l'application", varArray);
	
});








