<?xml version="1.0" encoding="UTF-8"?>
<application active="1">
	<property value="name">Chat</property>
	<property value="description">Cette application vous permet de dialoguer facilement avec les autres personnes connectées.</property>
	<property value="dir">chat</property>
	<property value="etatAvancement">beta</property>
	<property value="version">1.0</property>
	<property value="lang">fr_FR</property>
	<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
	<property value="js">
		<![CDATA[
			function runApplication(property, display, json)
			{
				formulaire = document.createElement("form");
				formulaire.onsubmit = sendMessage;
					formfield = document.createElement("fieldset");
					formfield.style.margin = "auto";
						labelmess = document.createElement("label");
						labelmess.innerHTML = "Message : ";
						labelmess.setAttribute("for", "message");
						formfield.appendChild(labelmess);
						inputmessage = document.createElement("input");
						inputmessage.name = "message";
						inputmessage.id = "message";
						inputmessage.size = "40";
						formfield.appendChild(inputmessage);
					formulaire.appendChild(formfield);
				$('corps').appendChild(formulaire);
				tableMessages = document.createElement("table");
				tableMessages.style.margin = "auto";
				tableMessages.style.width = "90%";
					theMess = document.createElement("thead");
						trMess = document.createElement("tr");
							thMess = document.createElement("th");
							thMess.innerHTML = "Date et heure";
							trMess.appendChild(thMess);
							thMess = document.createElement("th");
							thMess.innerHTML = "Message";
							trMess.appendChild(thMess);
						theMess.appendChild(trMess);
					tableMessages.appendChild(theMess);
					tboMess = document.createElement("tbody");
					tboMess.style.textAlign = "left";
					tboMess.id = "chat";
					tableMessages.appendChild(tboMess);
				$('corps').appendChild(tableMessages);

				printEtat(0);
				chat_MAJ();
			}

			function sendMessage()
			{
				if ($('message').value == "!cls")
				{
					chat_clearScreen();
					$('message').value = "";
				}
				else if ($('message').value == "!maj")
				{
					chat_refreshScreen();
					$('message').value = "";
				}
				else if ($('message').value == "!reset")
				{
					chat_reset();
					$('message').value = "";
				}
				else if ($('message').value == "!quit" || $('message').value == "!exit" || $('message').value == "!deco" || $('message').value == "!deconnexion")
				{
					first_page();
				}
				else if ($('message').value.toString().indexOf("!changerefreshtime ") == 0 || $('message').value.toString().indexOf("!changeRefreshtime ") == 0 || $('message').value.toString().indexOf("!changerefreshTime ") == 0 || $('message').value.toString().indexOf("!changeRefreshTime ") == 0)
				{
					split = $('message').value.toString().split(" ");
					$('message').value = "";
					chat_changeRefreshTime(split[1]);
				}
				else if ($('message').value == "!clear" || $('message').value == "!online" || $('message').value == "!help" || $('message').value == "!hlp" || $('message').value == "!aide")
				{
					chat_sendCommande($('message').value);
					$('message').value = "";
				}
				else
				{
					new Ajax.Request(
					 'ajax.php?d=action&amp;a=chat',
					 {
						method: 'post',
						parameters: {message: $('message').value},
						onSuccess: function(transport, json) {
							$('message').value = "";
							},
						onFailure: function() { if (confirm("La requête a échouée, voulez-vous réessayer de renvoyer votre message ?")) sendMessage(); }
					 }
					);
				}
				return false;
			}

			function chat_MAJ()
			{
				var date = new Date();
				var newRow = $('chat').insertRow(0);
				var newCell = newRow.insertCell(0);
				newCell.innerHTML = '<em>JS</em> ' + (date.getHours()<10?"0"+date.getHours():date.getHours()) + ":" + (date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes()) + ":" + (date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds());
  				newCell = newRow.insertCell(1);
				newCell.innerHTML = "<em>Connexion au chat</em>";
				$('message').focus();
				chat_refresh = setTimeout("chat_MAJ()", 150);
			}
		]]>
	</property>

	<security default="connected" />

	<display value="titre">chat.png</display>
	<display value="js">app.js</display>

	<config value="table_bdd">chat</config>
</application>