function _xul_open_directory(dir)
{//Ouvre l'explorer avec le chemin
	var fp = 			Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  
	fp.initWithPath(dir);
  
	try
	{
		fp.reveal();
	}
	catch(e)
	{
		openExternal(fp);
	}
}

function showConsole()
{
	window.open("chrome://global/content/console.xul", "_blank",  "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
}

function showAddons()
{
	var wm = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
	var em = wm.getMostRecentWindow('Extension:Manager');
	
	if (em)
	{
		em.focus();
		
		return;
	}
	
	window.openDialog('chrome://mozapps/content/extensions/extensions.xul', '', 'chrome,menubar,extra-chrome,toolbar,dialog=no,resizable');
}

function filePicker(mode, titre, Filtres, directory)
{
/*
Mode
	[ modeOpen / modeOpenMultiple / modeGetFolder / modeSave ]
	[ displayDirectory ] ???
	
Filtres (Array())
	[ filterAll, filterXML, filterXUL, filterText, filterHTML, filterImages, filterAudio, filterVideo, filterApps ]
	[ filterAllowURLs ] ???
	
	[ txt__*.ext, txt2__*.ext2 ]
*/


	var nsIFilePicker = Ci.nsIFilePicker;
	var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
	
	fp.init(window, titre, eval("nsIFilePicker."+mode));
	
	for (let i=0, T=Filtres.length; i<T; i++)
	{
		if (Filtres[i].indexOf("__")>-1)
		{
			let filtre= Filtres[i].split("__");
			fp.appendFilter(filtre[0], filtre[1]);
		}
		else
		{
			let filtre= eval("nsIFilePicker.filter"+Filtres[i]);
			fp.appendFilters(filtre);
		}
	}
	
	if (directory!=undefined)
	{
		var dir = Cc["@mozilla.org/file/directory_service;1"]
		.getService(Ci.nsIProperties)
		.get("ProfD", Ci.nsILocalFile);
		
		dir.initWithPath(directory);
		fp.displayDirectory = dir;
	}
	
	//fp.defaultExtension="";
	//fp.defaultString="";
	//fp.filterIndex="2";
	
	var res = fp.show();

	if (res == nsIFilePicker.returnOK)
	{
		if (mode=="modeOpenMultiple")
			return fp.files;
		else
			return fp.file;
	}
	else
	if (res == nsIFilePicker.returnReplace)
	{//pas encore géré
		return fp.file;
	}
	else
	if (res == nsIFilePicker.returnCancel)
		return false;
	
	return true;
}

function sqliteConn(db)
{
	var ifile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);

	//if the database does not exist, storageService.openDatabase creates it
	ifile.initWithPath(db);

	//Warning,  if the file does not exist, openDatabase below will create if for you 
	if(!(ifile.exists()))
	{
		Alert("DB ERROR", "Le fichier DATAS n'existe pas");
		
		return false;
	}
	else
	{	
		var storageService = Cc["@mozilla.org/storage/service;1"]
		.getService(Ci.mozIStorageService);
	 
		try
		{
			var mDBConn = storageService.openDatabase(ifile);
			
			return mDBConn;
	
			// if the db does not exist it does not give us any indication
			//	mDBConn.lastErrorString returns "not an error"
	
		}
		catch (e)
		{
			Alert("DB ERROR", "Impossible d'ouvrir le fichier DATAS");
			//gjSQLonerror(e, strDB.value ," Error on Open ");
		}
	}
	
	return true;

	// After and Open or Create of a DB above doSQL gets the column names and  
	// the data from the SQLite DB and stores it the helper object (theResults = new gjSQLHelper;) 
/*
	if(doSQL(mDBConn,theResults, strQuery.value))
	{
			// display whatever results we have
			doDisplay (theResults);
	}
*/

}

function barreEtat()
{
	var etat=$('mnu_stb1').getAttribute('checked');
	
	$('stb1').collapsed=	!etat;
	
	if (etat)//putin de bug
		ecrirePref('bool', 'barre.visible', true);
	else
		ecrirePref('bool', 'barre.visible', false);
}