/** Chat **/

function popChat(channel, pseudo) {
	skyLocalStorage.init(function () {
		var s;
        try
        {
            s = skyLocalStorage.get('chatpopupsize');
        }
        catch (e)
        {
            s = null;
        }
		var appletSize = '0x0';
		if (s && s.match(/^\d{2,4}x\d{2,4}$/)) {
			appletSize = s;
		}

		if (!pseudo) pseudo = '';

		var url = www_path + 'chat/popup.php' + '?ts=' + (new Date()).getTime();

		if (channel) {
			url += '&chan=' + channel;
		}
		if (pseudo) {
			url += '&query=' + pseudo;
		}
		if (typeof firstroom != 'undefined') {
			url += '&firstroom=' + firstroom;
		}

		/* En taille adaptée, on ne passe plus la taille, c'est le navigateur qui se
		 * chargera d'ouvrir la popup à une taille adéquate. */
		var size = appletSize.split('x');
		// taille mini de la fenetre
		size[0] = Math.max(990, parseInt(size[0]));
		size[1] = Math.max(620, parseInt(size[1]));
		// innerHeight innerWidth pour FF
		var wnd = window.open('', 'skyChatWindow', 'resizable=yes,location=no,innerHeight=' + size[1] + ',innerWidth=' + size[0] + ',height=' + size[1] + ',width=' + size[0] + ',menubar=no,status=no,scrollbars=no');

		try {
			var handle = wnd.document.getElementById('skyrockChat');
		} catch (e) {
			var handle = false;
		}

		if (!handle) {
			wnd.location = url;
			wnd.focus();
			return true;
		}

		// Chat déjà ouvert, on passe les infos qu'on a précisé
		handle.openTab(pseudo, unescape(channel));
		wnd.focus();
		return true;
	});
}

// on aura besoin de skyLocalStorage, il faut l'init assez tot.
onload_funcs.push(function () {
	skyLocalStorage.init(function () {});
});
