function swapImageOn(id) {
	var reg=new RegExp("(off)", "g");
   	document.getElementById(id).src = document.getElementById(id).src.replace(reg,"on");
}
function swapImageOff(id) {
	var reg=new RegExp("(on)", "g");
   	document.getElementById(id).src = document.getElementById(id).src.replace(reg,"off");
}
	// FONCTION SUR LE ONCHANGE DU SELECTEUR PROFIL
	function switch_profil() {
		Ext.Ajax.request({
			url : 'setHomepage.php',
			method: 'GET'
		});
	}
	// OUVERTURE DU PANEL CONTENANT LES LANCEURS DES WIDGETS
	function openGadget() {
		document.getElementById('id-panel-portlet').style.display='block';
		document.getElementById('home_bg_bottom').style.display='none';
		Ext.getCmp('test-collapse').expand();
		Ext.getCmp('test-collapse').setTitle('');
		
	}
	// FERMETURE DU PANEL CONTENANT LES LANCEURS DES WIDGETS
	function closeGadget() {
		Ext.getCmp('test-collapse').collapse();
		document.getElementById('home_bg_bottom').style.display='block';
		document.getElementById('id-panel-portlet').style.display='none';
	}
	// AJOUT D'UN WIDGET DEPUIS LE PANEL CONTENANT LES LANCEURS DES WIDGETS
	function addPortlet(id,title,gadget) {
		if (Ext.get(id))
			return;

		var tempWidget = new Ext.ux.Portlet({
			id:id,
			title: title,
			tools: [{
				id:"close",
				handler: function(e, target, panel) {
					reorderWidget(panel);
				}
			}],
			collapsible:false,
			//autoLoad:gadget,
			// Ajout MR - 10/12/2008
			autoLoad: 'spip.php?page=widget&id_article=' + id,
			baseCls:'yellow-panel',
			height:237
		});
	
		for(var i=1;i<10;i++)
		{
			if (Ext.getCmp('viewport-col-' + i).items.getCount() == 0)
			{
				Ext.getCmp('viewport-col-' + i).add(tempWidget);
				Ext.getCmp('viewport-col-' + i).doLayout();
				Ext.Ajax.request({
					url : 'setCookie.php',
					params: {colonne1:'viewport-col-' + i,widget1:tempWidget.id + "," + tempWidget.title},
					method: 'GET',
					success: function ( result, request ) {},
					failure: function () {}
				});
				return;
			}
		}
	}
	// RENVOIE LA COLONNE
	function getNextColumn(idColumn) {
		var numColumn = parseInt(idColumn.charAt(13));
		if (numColumn == 9)
			return 0;
		return "viewport-col-" + (numColumn + 1);
	}
	// REORGANISE LES WIDGETS APRES UNE SUPPRESSION
	function reorderWidget(panel) {
	    Ext.Ajax.request({
		    url : 'getCookie.php',
			method: 'GET',
			params:{"allid":"1"},
			success: function ( result, request) {
			Ext.getCmp('test-collapse').load({
				url: "spip.php?page=gadgets&idList=" + result.responseText.replace(panel.id,"")
				    });
		    },
			failure: function (){},scope:this
						   });
		// ID DE LA COLONNE COURANTE
		var idColumn = panel.el.dom.parentNode.id;
		panel.ownerCt.remove(panel, true);
	
		// DEPLACEMENTS DES WIDGETS
		while (getNextColumn(idColumn))
		{
			if (Ext.getCmp(getNextColumn(idColumn)).items.itemAt(0))
				Ext.getCmp(idColumn).insert(0,Ext.getCmp(getNextColumn(idColumn)).items.itemAt(0));
			idColumn = getNextColumn(idColumn);	
		}
		
		Ext.getCmp('portal-viewport-fntp1').doLayout();
		Ext.getCmp('portal-viewport-fntp2').doLayout();
		Ext.getCmp('portal-viewport-fntp3').doLayout();
	
//		((Ext.getCmp("viewport-col-1").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":"");
		// ENREGISTREMENT DES MODIFICATIONS
		Ext.Ajax.request({
			url : 'setCookie.php',
			params: {
				"viewport-col-1":((Ext.getCmp("viewport-col-1").items.itemAt(0))?Ext.getCmp("viewport-col-1").items.itemAt(0).id+","+Ext.getCmp("viewport-col-1").items.itemAt(0).title+((Ext.getCmp("viewport-col-1").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-2":((Ext.getCmp("viewport-col-2").items.itemAt(0))?Ext.getCmp("viewport-col-2").items.itemAt(0).id+","+Ext.getCmp("viewport-col-2").items.itemAt(0).title+((Ext.getCmp("viewport-col-2").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-3":((Ext.getCmp("viewport-col-3").items.itemAt(0))?Ext.getCmp("viewport-col-3").items.itemAt(0).id+","+Ext.getCmp("viewport-col-3").items.itemAt(0).title+((Ext.getCmp("viewport-col-3").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-4":((Ext.getCmp("viewport-col-4").items.itemAt(0))?Ext.getCmp("viewport-col-4").items.itemAt(0).id+","+Ext.getCmp("viewport-col-4").items.itemAt(0).title+((Ext.getCmp("viewport-col-4").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-5":((Ext.getCmp("viewport-col-5").items.itemAt(0))?Ext.getCmp("viewport-col-5").items.itemAt(0).id+","+Ext.getCmp("viewport-col-5").items.itemAt(0).title+((Ext.getCmp("viewport-col-5").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-6":((Ext.getCmp("viewport-col-6").items.itemAt(0))?Ext.getCmp("viewport-col-6").items.itemAt(0).id+","+Ext.getCmp("viewport-col-6").items.itemAt(0).title+((Ext.getCmp("viewport-col-6").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-7":((Ext.getCmp("viewport-col-7").items.itemAt(0))?Ext.getCmp("viewport-col-7").items.itemAt(0).id+","+Ext.getCmp("viewport-col-7").items.itemAt(0).title+((Ext.getCmp("viewport-col-7").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-8":((Ext.getCmp("viewport-col-8").items.itemAt(0))?Ext.getCmp("viewport-col-8").items.itemAt(0).id+","+Ext.getCmp("viewport-col-8").items.itemAt(0).title+((Ext.getCmp("viewport-col-8").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty"),
				"viewport-col-9":((Ext.getCmp("viewport-col-9").items.itemAt(0))?Ext.getCmp("viewport-col-9").items.itemAt(0).id+","+Ext.getCmp("viewport-col-9").items.itemAt(0).title+((Ext.getCmp("viewport-col-9").items.itemAt(0).body.dom.className.charAt(0) == 'v')?",v":""):"empty")
			},
			method: 'GET',
			success: function (result,request) {},
			failure: function () {}
		});
	}
	
	// AJOUTE LES WIDGETS SUR LA HOME EN FONCTION DU COOKIE
	function addCookieWidget(response) {
		ret = response.split(",");
		if (ret[1] == "empty")
			return;
		
		var tools = [{
			id:"close",
			handler: function(e, target, panel){
				
				reorderWidget(panel);

				
			}
		}];

		
		var tempWidgetViolet = new Ext.ux.Portlet({
			id: ret[1],
			title: ret[2],
			collapsible:false,
			autoLoad: 'spip.php?page=widget&id_article=' + ret[1],
			baseCls: 'violet-panel',
			height:237
		});
		
		var tempWidgetJaune = new Ext.ux.Portlet({
			id: ret[1],
			title: ret[2],
			tools: tools,
			collapsible:false,
			autoLoad: 'spip.php?page=widget&id_article=' + ret[1],
			baseCls: 'yellow-panel',
			height:237
		});
		if (ret[3])
			Ext.getCmp(ret[0]).add(tempWidgetViolet);
		else
			Ext.getCmp(ret[0]).add(tempWidgetJaune);
		Ext.getCmp(ret[0]).doLayout();
	}


	Ext.onReady(function(){
		// PANEL CONTENANT LES LANCEURS DES WIDGETS
		
		var panelDescendant = new Ext.Panel({
			id: 'test-collapse',
			collapsed:true,
			renderTo : 'id-panel-portlet',
			//autoLoad:'spip.php?page=gadgets',
			baseCls:'gadget-panel'
		});

		Ext.Ajax.request({
			    url : 'getCookie.php',
			    method: 'GET',
			    params:{"allid":"1"},
			    success: function ( result, request) {
			    Ext.getCmp('test-collapse').load({
				    url: "spip.php?page=gadgets&idList=" + result.responseText 				    
				});
			    },
			    failure: function (){},scope:this
		    });

		/* That tells Ext where to find the empty image it needs for some widgets (preferably from your own server/domain). */
		Ext.BLANK_IMAGE_URL = "ext-2.2/resources/images/default/s.gif";
		// LIGNE DE WIDGETS NUMERO 1																																																																																								
        var viewportFirstLine = new Ext.Panel({
        layout:"border",
        items:[{
			id:"portal-viewport-fntp1",
            xtype:"portal",
			renderTo: "widgets-zone-first-line",
            width:730,
            style:"margins:0px 0px 0px 0px;padding:0px;",
            items:[{
	   			id:"viewport-col-1",
                columnWidth:.3333,
                style:"padding:0px 7px 10px 0px"
            },{
	   			id:'viewport-col-2',
                columnWidth:.3333,
                style:"padding:0px 7px 10px 0px"
            },{
	   			id:'viewport-col-3',
                columnWidth:.3333,
                style:"padding:0px 0px 10px 1px"
            	}]
        	}]
    	});
		// LIGNE DE WIDGETS NUMERO 2
		var viewportSecondLine = new Ext.Panel({
			layout:'border',
			width:730,
			items:[{
				id:'portal-viewport-fntp2',
				xtype:'portal',
				renderTo: "widgets-zone-second-line",
				margins:'0 7 5 0',
				items:[{
					id:'viewport-col-4',
					columnWidth:.3333,
					style:"padding:0px 7px 10px 0px"
				},{
					id:'viewport-col-5',
					columnWidth:.3333,
					style:"padding:0px 7px 10px 0px"
				},{
					id:'viewport-col-6',
					columnWidth:.3333,
					style:"padding:0px 0px 10px 0px"
				}]
			}]
		});
		// LIGNE DE WIDGETS NUMERO 3
		var viewportThirdLine = new Ext.Panel({
			layout:'border',
			width:730,
			items:[{
				id:'portal-viewport-fntp3',
				xtype:'portal',
				renderTo: "widgets-zone-third-line",
				margins:'0 7 5 0',
				items:[{
					id:'viewport-col-7',
					columnWidth:.3333,
					style:"padding:0px 7px 10px 0px"
				},{
					id:'viewport-col-8',
					columnWidth:.3333,
					style:"padding:0px 7px 10px 0px"
				},{
					id:'viewport-col-9',
					columnWidth:.3333,
					style:"padding:0px 0px 10px 0px"
				}]
			}]
		});
	
	// MISE EN PLACE DES WIDGETS
		for (var i = 1;i < 10; i++)
		{
			Ext.Ajax.request({
				url : 'getCookie.php',
				method: 'GET',
				params:{"idcolumn":"viewport-col-" + i},
				success: function ( result, request) {
					addCookieWidget(result.responseText);					
				},
				failure: function (){}
			});
		}
		
	});
	
	
	// Fonction de changement d'images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_selectZone(e){
document.getElementById('formation_area').value=document.getElementById('formation_area').value+e;
}