function dbg(s)
{
	var lines = ("" + s).split("\n");
	for (i=0;i<lines.length;i++)
		System.Debug.outputString("[Gadget " + System.Gadget.name + " v" + System.Gadget.version + "] : " + lines[i]);
}

function formatMSec(ms)
{
	if (ms>3600000)
	{
		var h = Math.floor(ms / 3600000);
		var m = Math.floor((ms % 3600000)/60000);
		
		return h + "h " + m + "min"
	}
	else if (ms>60000)
	{
		var m = Math.floor(ms / 60000);
		return m + "min";
	}
	else
	{
		return Math.floor(ms / 1000) + "sec"
	}
}

function formatDuree(d)
{
	var h = Math.floor(d/3600);
	var m = Math.floor((d - h*3600)/60);
	return h.toString() + "h " + ((m<10)?("0"+m):m.toString()) + "min";
}

function launchUrl(s)
{
	System.Shell.execute(s);
}

Number.prototype.format = function(n){
	var s = "" + this.valueOf();
	var l = s.length;
	for (i = 0; i < n-l; i++)
		s = "0" + s;
	return s;
}

Date.prototype.formatShort = function(){
	return this.getDate().format(2) + "/" + (this.getMonth() + 1).format(2) + "/" + this.getFullYear().format(4);
}

Date.prototype.formatLong = function(){
	var s = "";
	
	var days = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
	var months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
	
	return days[this.getDay()] + " " + this.getDate() + " " + months[this.getMonth()] + " " + this.getFullYear();
}

function parseDate(s){
	var ar = s.split(/[-T:]/);

	if (ar.length != 6)
		return undefined;
		

	for (i=0;i<ar.length;i++)
	{
		var v = parseInt(ar[i]);
		if (isNaN(v))
			return undefined;
		ar[i] = v;
	}

	var dt = new Date();

	dt.setFullYear(ar[0]);
	dt.setMonth(ar[1]-1);
	dt.setDate(ar[2]);
	dt.setHours(ar[3]);
	dt.setMinutes(ar[4]);
	dt.setSeconds(ar[5]);

	return dt;
}

