	// We like ugly fixes.
	is_ie = false;
	//
	var isOk = true;
	var msgPoste = false;
	var nomAjax = 'ajax';
	var timer_in = 0;
	var nomNavigateur = navigator.userAgent;
	var debutUrlSite = 'http://www.univers-ps.com';
	var decoShout = false;	
	var tempsVerifRefresh;
	var tempsVerifRefresh2;
	var timerActiviteShout;	
	var utilisateurShoutActif = true;
	var rebootActualisation1;
	var rebootActualisation2;
	var tempsIconeActu;
	var dernierId = 0;
	

	function afficheShout()
	{		
		document.getElementById('listeConnectesLobby').innerHTML = "<p>Cliquez sur un des lobbys pour vous connecter à la shoutbox.</p>";	}

	function lireListeConnectesLobby()
	{ 
		var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
		var date_du_jour = new Date();
		var date_du_jour = date_du_jour.getTime();		
		var _adresseRecherche = "recupereListeConnecteShout.php?time=" + date_du_jour; //l'adresse à interroger
		var valret = ""; //valeur de retour



			if(_xmlHttp&&_xmlHttp.readyState!=0){
				_xmlHttp.abort()
			}
			_xmlHttp=http();
			if(_xmlHttp){
				//appel à l'url distante
				_xmlHttp.open("GET",_adresseRecherche,true);

				_xmlHttp.onreadystatechange=function() {
					if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
						valret = _xmlHttp.responseText;
						document.getElementById('listeConnectesLobby').innerHTML = valret;
					}
				};
				// envoi de la requête
				_xmlHttp.send(null);
			}
						setTimeout('lireListeConnectesLobby()',15000);	
				
	} 

	function handle(e)
	{
		switch (e.name)
		{
			//Is it our error? :)
			case "E_USER_ERROR":
			case "E_CORE_ERROR":
				message(e.message, true);				return '';
			break;

			default:
			{

				tmp = 'Il y a eu une erreur JavaScript. \nErreur: ';
				tmp += e.message;
				if (e.lineNumber)
				{
					tmp += '\nLigne: ';
					tmp += e.lineNumber;
				}
				if (e.fileName)
				{
					tmp += '\nFichier: ';
					tmp += e.fileName;
				}
				message(tmp, true);				return '';
			}
		}
		return '';
	}

	function load_shout()
	{		
		
		try
		{
			var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1) && (clientPC.indexOf('PLAYSTATION') != -1) && (clientPC.indexOf('iPhone') != -1) );
			if (display_shoutbox == false)
			{
				return;
			}
			
			if (document.getElementById('shoutbox') == null)
			{
			
				var ev = err_msg('La Shoutbox ne peut être affichée.');	
		
				ev.name = 'E_CORE_ERROR';
				throw ev; 
				return;
			}
			else
			{			
				div = document.getElementById('shoutbox');

				// Display message ;)
				message('Chargement en cours');
				// HTTP vars, required to relead/post things.
				hin = http();
				
				if (!hin)
				{
					return;
				}
				hin2 = http();
				huit = http();	
				hsmilies = http();
				hnr = http();
								// Div exists in the html, write it.					
				write_main();				
				
				//active les décos pour les inactifs
				verifActiviteShout();	

				
			}
		}
		catch (e)
		{
				handle(e);
				return;
		}
	}

	function write_main()
	{
		try
		{
			// Write the base.		
			var base = ce('ul');
			base.className = 'topiclist forums';
			base.id = 'base_ul'

			var li = ce('li');
			li.style.display = 'none';
			var dl = ce('dl');
			dl.style.width = '98%';

			var posting_form = ce('dt');
			posting_form.id = 'post_message';
			posting_form.className = 'row';
			posting_form.width = '98%';
			posting_form.style.display = 'none';
			posting_form.height = '20px';
			posting_form.style.width = '98%';
			
			var posting_box = ce('form');
			posting_box.id = 'chat_form';		

						
			posting_form.appendChild(posting_box);
			dl.appendChild(posting_form);
			li.appendChild(dl);
			base.appendChild(li);
			var msg_txt = ce('div');
			msg_txt.id = 'msg_txt';
			msg_txt.height = '180px';
			msg_txt.appendChild(tn(' '));
			base.appendChild(msg_txt);
			
			lireListeConnectesLobby();			//In this div, the chats will be placed ;)
			var post = ce('div');
			post.style.display = 'block';
			post.id = 'msg';
			post.style.position = 'relative';	
			post.style.width = '98%';
			
						
			
			
							post.style.height = '220px';
							post.style.overflow = 'auto';
									post.appendChild(tn('Chargement en cours'));
			base.appendChild(post);

			// Nr div
			var nr_d = ce('div');
			nr_d.id = 'nr';

			base.appendChild(nr_d);
			 
			div.innerHTML = '';
			div.appendChild(base);
			
			// Everyting loaded, lets select posts :)
			setTimeout("initialiseShout()", 1);
			
					
		}
		catch (e)
		{
			handle(e);
			return;
		}
	}


	function initialiseShout()
	{
		setTimeout("reload_post()", 0);
		setTimeout("reload_page()", 0);
		document.getElementById("chat_message").spellcheck = "true";
		
			}

	function reload_page()
	{
		if (hnr.readyState == 4 || hnr.readyState == 0)
		{
			// Lets got some nice things :D
			hnr.open('GET','./'+nomAjax+'.php?m=number&rand='+Math.floor(Math.random() * 1000000),true);

			hnr.onreadystatechange = function()
			{
				try
				{
					if (hnr.readyState == 4)
					{
						xml = hnr.responseXML;
						if (xml.getElementsByTagName('error') && xml.getElementsByTagName('error').length != 0)
						{
							err = xml.getElementsByTagName('error')[0].childNodes[0].nodeValue;
							message(err, true);
							clearTimeout(timer_in);

							setTimeout('reload_post();',500);
						}
						else
						{
							var nr = xml.getElementsByTagName('nr')[0].childNodes[0].nodeValue;
							var f = document.getElementById('nr');
							f.innerHTML = '';
							var d = ce('div');
							
							if (nr < 40)
							{
								return;
							}
							
							var per_page = 40;
							
							var total_pages = Math.ceil(nr / per_page);
							
							if (total_pages == 1 || !nr)
							{
								return;
							}				

							on_page = Math.floor(count / per_page) + 1;
							
							var p = ce('span');
							var a = ce('a');
							var b = ce('strong');
							
							if (on_page == 1)
							{
								b.appendChild(tn('1'));
								p.appendChild(b);
								b = ce('strong');
							}
							else
							{
								a.c = ((on_page - 2) * per_page);
								a.href = 'javascript:;';
								a.onclick = function()
								{
									count = this.c;
									last = 0; // Reset last, otherwise it will not be loaded.
									clearTimeout(timer_in);
									reload_post();
									reload_page();
								}
								
								a.appendChild(tn('Précédente'));
								
								p.appendChild(a);
								
								p.appendChild(tn(' '));
								
								a = ce('a');						
							
								a.c = 0;
								a.href = 'javascript:;';
								a.onclick = function()
								{
									count = this.c;
									last = 0; // Reset last, otherwise it will not be loaded.
									clearTimeout(timer_in);
									reload_post();
									reload_page();
								}
								
								a.appendChild(tn('1'));
								
								p.appendChild(a);
								a = ce('a');
							} 
							
							if (total_pages > 5)
							{
								var start_cnt = Math.min(Math.max(1, on_page - 4), total_pages - 5);
								var end_cnt = Math.max(Math.min(total_pages, on_page + 4), 6);
								
								p.appendChild((start_cnt > 1) ? tn(' ... ') : cp());
								
								for (var i = start_cnt + 1; i < end_cnt; i++)
								{
									if (i == on_page)
									{
										b.appendChild(tn(i));
										p.appendChild(b);
										b = ce('strong');	
									}
									else
									{
										a.c = (i - 1) * per_page;
										a.href = 'javascript:;';
										a.onclick = function()
										{
											count = this.c;
											last = 0; // Reset last, otherwise it will not be loaded.
											clearTimeout(timer_in);
											reload_post();
											reload_page();
										}
										
										a.appendChild(tn(i));
										
										p.appendChild(a);
										a = ce('a');			
									}
									if (i < end_cnt - 1)
									{
										p.appendChild(cp());
									}
								}
								
								p.appendChild((end_cnt < total_pages) ? tn(' ... ') : cp());							
							}
							else
							{
								p.appendChild(cp());
								for (var i = 2; i < total_pages; i++)
								{
									if (i == on_page)
									{
										b.appendChild(tn(i));
										p.appendChild(b);
										b = ce('strong');	
									}
									else
									{
										a.c = (i - 1) * per_page;
										a.href = 'javascript:;';
										a.onclick = function()
										{
											count = this.c;
											last = 0; // Reset last, otherwise it will not be loaded.
											clearTimeout(timer_in);
											reload_post();
											reload_page();
										}
										
										a.appendChild(tn(i));
										
										p.appendChild(a);
										a = ce('a');			
									}
									if (i < total_pages)
									{
										p.appendChild(cp());
									}
								}						
							}
							
							if (on_page == total_pages)
							{
								b.appendChild(tn(total_pages));
								p.appendChild(b);
								b = ce('strong');
							}
							else
							{
								
								a = ce('a');						
							
								a.c = ((total_pages - 1) * per_page);
								a.href = 'javascript:;';
								a.onclick = function()
								{
									count = this.c;
									last = 0; // Reset last, otherwise it will not be loaded.
									clearTimeout(timer_in);
									reload_post();
									reload_page();
								}
								
								a.appendChild(tn(total_pages));
								
								p.appendChild(a);
								a = ce('a');

								a.c = ((on_page) * per_page);
								a.href = 'javascript:;';
								a.onclick = function()
								{
									count = this.c;
									last = 0; // Reset last, otherwise it will not be loaded.
									clearTimeout(timer_in);
									reload_post();
									reload_page();
								}
								
								a.appendChild(tn('Suivante'));
								
								p.appendChild(tn(' '));
								
								p.appendChild(a);
								a = ce('a');
							}						
							
							f.appendChild(p);
						}
					}
				}
				catch (e)
				{
					handle(e);
					return;
				}
			}
			hnr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

			hnr.send(null);
		}
	}

	function echecActualisation()
	{
		timer_in = setTimeout('reload_post();',5000);
	}
	
	function stopiconeprogression()
	{
		setTimeout(function() { document.getElementById('iconeprogression').src = 'shoutbox/refresh0.gif'; }, 1500);			
	}
	
	function verifPlantage()
	{		
		clearTimeout(rebootActualisation1);
		clearTimeout(tempsIconeActu);
		document.getElementById('iconeprogression').src = 'shoutbox/refresh0.gif';
		rebootActualisation1 = setTimeout("echecActualisation()", 5000);			
		hin.abort();
		document.getElementById('msg_txt').innerHTML = 'Erreur d\'actualisation #1! Redémarrage de l\'actualisation...';		
	}	
	
	function verifPlantage2()
	{		
		clearTimeout(rebootActualisation2);
		document.getElementById('iconeprogression').src = 'shoutbox/refresh0.gif';
		rebootActualisation2 = setTimeout("echecActualisation()", 5000);	
		hin2.abort();
		document.getElementById('msg_txt').innerHTML = 'Erreur d\'actualisation #2! Redémarrage de l\'actualisation...';	
	}		
	
	function reload_post()
	{
		
		document.getElementById('msg_txt').innerHTML = '';		
	
		
		
		
		// First check if there new posts.
		if (isOk && (hin2.readyState == 4 || hin2.readyState == 0))
		{		
			hin2.open('GET','./'+nomAjax+'.php?m=check&msgPoste='+msgPoste+'&decoShout='+decoShout+'&last=' + last + '&rand='+Math.floor(Math.random() * 1000000),true);
			msgPoste = false;			
			tempsVerifRefresh2 = setTimeout('verifPlantage2()',20000) ;
			document.getElementById('iconeprogression').src = 'shoutbox/refresh1.gif';



			
			hin2.onreadystatechange = function()
			{			
				try
				{
					if (hin2.readyState == 4)
					{
						clearTimeout(tempsVerifRefresh2);
						stopiconeprogression();


					
						//si la requete a échouée, on relance l'actualisation
						if(hin2.status != 200)
						{
							clearTimeout(rebootActualisation2);
							rebootActualisation2 = setTimeout("echecActualisation()", 5000);
						}
						else
						{

						
						
							
						
							if (!hin2.responseXML)
							{
								throw err_msg('Erreur XML.');
							}
							var xml = hin2.responseXML;		
							if (xml.getElementsByTagName('error') && xml.getElementsByTagName('error').length != 0)
							{
								err = xml.getElementsByTagName('error')[0].childNodes[0].nodeValue;
								throw err_msg(err);
								return;
							}
												
							var t = xml.getElementsByTagName('time')[0].childNodes[0].nodeValue;
							
							if (t == '0')
							{
								// If start is true, we let notice that there are no messages
								if (start == true)
								{
															
									var posts = document.getElementById('msg');
									posts.innerHTML = '';
									posts.appendChild(tn('Aucun message.'));
								}
							}
							else
							{

							
								if (hin.readyState == 4 || hin.readyState == 0)
								{
									last = xml.getElementsByTagName('last')[0].childNodes[0].nodeValue;
									// Lets got some nice things :D							
									hin.open('GET','./'+nomAjax+'.php?m=view&start=' + count + '&rand='+Math.floor(Math.random() * 1000000),true);
									document.getElementById('iconeprogression').src = 'shoutbox/refresh1.gif';

								
									tempsVerifRefresh = setTimeout('verifPlantage()',20000) ;
									hin.onreadystatechange = function()
									{
										try
										{
											if (hin.readyState == 4)
											{
												clearTimeout(tempsVerifRefresh);
												stopiconeprogression();

										
												//si la requete a échouée, on relance l'actualisation
												if(hin.status != 200)
												{
													clearTimeout(rebootActualisation1);
													rebootActualisation1 = setTimeout("echecActualisation()", 5000);												
												}
												else
												{

													if (!hin.responseXML)
													{
														throw err_msg('Erreur XML.');
														return;
													}
													var xml = hin.responseXML;
													if (xml.getElementsByTagName('error') && xml.getElementsByTagName('error').length != 0)
													{
														var msg = xml.getElementsByTagName('error')[0].childNodes[0].nodeValue;
														throw err_msg(msg);
														return;
													}
													else
													{
														start = false;
														var tmp = xml.getElementsByTagName('posts');
														if (tmp.length == 0)
														{
																										
															var posts = document.getElementById('msg');
															posts.innerHTML = '';
															posts.appendChild(tn('Aucun message.'));												
															setTimeout('reload_post();',5000);												
															return;
														} 
														var posts = document.getElementById('msg');
														posts.innerHTML = '';
														//ajout kra
														posts.style.height = '370px';														
														
														
														

														var row = false;
														for (var i = 0; i < tmp.length ; i++)
														{
															var li = ce('li');
															li.className = (!row) ? 'row row1' : 'row row2';
															row = !row;
															
															var dl = ce('dl');
															var dd = ce('dd');
															var dt = ce('dt');
															var inh = tmp[i];
															dt.style.width = '0%';
															dt.style.styleFloat = dt.style.cssFloat = 'left';
															dd.style.styleFloat = dd.style.cssFloat = 'left';

															dd.style.paddingLeft = '1px';

															var s = ce('span');
															
															
																														var msg = parse_xml_to_html(inh.getElementsByTagName('shout_text')[0]);
															

															

															dd.appendChild(parse_xml_to_html(inh.getElementsByTagName('username')[0]));
															dd.appendChild(parse_xml_to_html(inh.getElementsByTagName('shout_time')[0]));
															dd.appendChild(tn(': '));
															dl.appendChild(dt);
															dd.appendChild(msg);
															dd.id = 'msgbody';
															dl.appendChild(dd);
															li.appendChild(dl);
															posts.appendChild(li);																							
														}

																											}
												}
											}
										}
										catch (e)
										{
											timer_in = setTimeout('reload_post();',5000);
											handle(e);
											return;
										}
									}
									hin.send(null);
								}
								else
								{
							
								}
							}
							timer_in = setTimeout('reload_post();',5000);		
						}
					}
				}
				catch (e)
				{
					handle(e);
					return;			
				}			
			}
			hin2.send(null);
		}
	}


	function no_ajax()
	{
		return 'Ajax est inactif';
	}

	function cp()
	{
		var sep = ce('span');
		sep.className = 'page-sep';
		sep.appendChild(tn(', '));
		return sep;
	}
	
	function verifActiviteShout()
	{
		
		if(utilisateurShoutActif == false)
		{
			window.location.href = "http://www.univers-ps.com/forum/iconeShout/images_deco/image_deco.php";			
			
		}
		else
		{		
			utilisateurShoutActif = false;
			timerActiviteShout = setTimeout('verifActiviteShout()',1000*120*60);
		}
		
	}	
	
	function zikmu()
	{
		var zikmu = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="300" height="315"> <param name="movie" value="http://www.univers-ps.com/forum/lecteurRadio/flamme/flam-player.swf"> <param name="flashVars" value="fp_root_url=http://www.univers-ps.com/forum/lecteurRadio/flamme/&ovr_color=0x94DBFF&ovr_langage=fr&ovr_playlist=default_playlist&ovr_author=all&ovr_order=name_artist&ovr_order_direction=ASC&ovr_autoplay=1&ovr_loop_playlist=1&ovr_loop_tracks=0&ovr_shuffle=1"> <param name="menu" value="false"> <param name="quality" value="best"> <param name="wmode" value="transparent"> <param name="bgcolor" value="#FFFFFF"> <embed src="http://www.univers-ps.com/forum/lecteurRadio/flamme/flam-player.swf" flashVars="fp_root_url=http://www.univers-ps.com/forum/lecteurRadio/flamme/&ovr_color=0x94DBFF&ovr_langage=fr&ovr_playlist=default_playlist&ovr_author=all&ovr_order=name_artist&ovr_order_direction=ASC&ovr_autoplay=1&ovr_loop_playlist=1&ovr_loop_tracks=0&ovr_shuffle=1" menu="false" quality="best" wmode="transparent" bgcolor="#FFFFFF" width="300" height="315" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
		document.getElementById('debugarea1').innerHTML = zikmu;	
	}	
