function CommandParse() {
		
}

CommandParse.prototype = {
	"lstCommandes" : {},
	
	'parseCommande' : function (txt, salleCourrante) {
		var resultat = new Commande();
		
		if (txt.charAt(0) == "/") {
			var firstSpace = (txt.indexOf(" ") != -1) ? txt.indexOf(" ") : txt.length;
			var cmd = txt.substring(1,firstSpace);
			resultat.setCommandeName(cmd);
			
			if (isset(CommandParse.prototype.lstCommandes[cmd])) {
				var paramListe = CommandParse.prototype.lstCommandes[cmd][0];
				resultat.setCallback(CommandParse.prototype.lstCommandes[cmd][1]);
				var currentIndex = firstSpace;
				var paramObj = {};
				
				for (var i=0; i<paramListe.length; i++) {
					nextSpace = (txt.indexOf(" ", currentIndex + 1) != -1) ? txt.indexOf(" ", currentIndex + 1) : txt.length;
					nextSpace = (i+1 == paramListe.length) ? txt.length : nextSpace;
					paramObj[paramListe[i]] = txt.substring(currentIndex + 1, nextSpace);
					currentIndex = nextSpace;
				}
				
				resultat.setCommandParam(paramObj);
			}
		} else {
			if (salleCourrante.charAt(0) == "#") {
				resultat.setCommandeName("msg");
				resultat.setCommandParam({
					"salle" : salleCourrante.substr(1),
					"data" : txt
				});
				resultat.setCallback(CommandParse.prototype.lstCommandes["msg"][1]);
			} else {
				resultat.setCommandeName("privmsg");
				resultat.setCommandParam({
					"user" : salleCourrante.substr(1),
					"data" : txt
				});
				resultat.setCallback(CommandParse.prototype.lstCommandes["privmsg"][1]);
			}
		}
		
		return resultat;
	}
	,
	
	'addCommande' : function (nom, lstParam, callback) {
		CommandParse.prototype.lstCommandes[nom] = [lstParam, callback];
	}
};

function Commande() {}

Commande.prototype = {
	'commandeName' : '',
	'commandParam' : {},
	'callback' : function () {},
	
	'setCommandeName' : function (name) {
		this.commandeName = name;
	}
	,
	
	'getCommandeName' : function () {
		return this.commandeName;
	}
	,
	
	'setCommandParam' : function (param) {
		this.commandParam = param;
	}
	,
	
	'getCommandParam' : function () {
		return this.commandParam;
	}
	,
	
	'setCallback' : function (callback) {
		this.callback = callback;
	}
	,
	
	'getCallback' : function () {
		return this.callback;
	}
};