<html>
	<head>
		<script type="text/javascript" src="http://open.hive404.com/countUp.min.js"></script>
	<script>
		                        document.domain = 'open.hive404.com';
	</script>
		<style type="text/css">
			#repondre.contexte_relance:disabled {
				color: #ffffff !important;
				background-color: #4040ff !important;
			}
			.torus_tempus {
				background-color: #000000;
				border: 2px solid #ffffff;
				bottom: 0;
				color: #ffffff;
				padding: 1em;
				position: fixed;
				left: 185px;
				text-align: center;
				padding: 3px;
			}
			.end_monitor {
				position: fixed;
				top:50%;
				left: 50%;
				transform: translate(-50%,-50%);
				display: block;
				background-color: #dddddd;
				z-index: 1000;
				padding: 40px 80px;
				border: 2px solid #000000;
				text-align: center;
				font-size: 20px;
				font-family: 'DejaVu Sans', Verdana, Arial, sans-serif;
			}
			.end_monitor p {
				margin: 0 0 20px 0;
			}
			.end_monitor button {
				font-size: 20px;
			}
			#chat {
				width: 500px;
				height: 200px;
				overflow: scroll;
				border: 1px solid #000000;
				margin: auto;
			}
			#chat p {
				outline: 1px solid #000000;
				margin: 1px;
				padding: 1px 3px;
				text-align: left;
			}
			#chat .monitor {
				background-color: #c0ffc0;
			}
			#chat .anim {
				background-color: #ffc0c0;
			}
			#chat:empty:before {
				content: attr(data-value);
				white-space: pre-line;
				display: inline;
				font-weight: bold;
			}
			#contextMenu {
				cursor: pointer;
				visibility: hidden;
				background-color: #ffffff;
				border: solid 1px #000000;
				position: absolute;
				top: 0px;
				left: 0px;
				z-index: 4;
			}
			#contextMenu ul {
				list-style-type: none;
				margin: 0px;
				padding: 0px;
			}
			#contextMenu li {
				padding: 2px;
			}
			#contextMenu li:hover {
				background-color: #c0c0c0;
			}
			#contextMenu #contextMenu_specialContextRelance {
				background-color: #c0c0ff;
				border-bottom: 1px solid #000000;
			}
			#contextMenu #contextMenu_specialContextRelance:hover {
				background-color: #8080c0;
				color: #ffffff;
			}
			#contextMenu.hide li {
				display: none;
			}
			.highlight-base {
				background-color: #ff4040;
			}
			.highlight-fade {
				background-color: #ffffff;
				-webkit-transition: background-color 5s ease-in;
				-moz-transition: background-color 5s ease-in;
				transition: background-color 5s ease-in;
			}
			#notifier {
				background-color: #ffffff;
				border: solid 1px #000000;
				z-index: 3;
				position: absolute;
				left: calc(100% - 275px);
				width: 250px;
				padding: 10px;
				max-height: 175px;
				display: block;
				top: -200px;
				opacity: 0;
				transform: scale(1);
				-webkit-transition: all 0s linear;
				-moz-transition: all 0s linear;
				transition: all 0s linear;
			}
			#notifier>h4 {
				margin: 5px;
				margin-bottom: 10px;
				text-align: center;
				font-size: 16px;
				font-variant: small-caps;
			}
			#notifier>h4:first-letter {
				text-transform: capitalize;
			}
			#notifier>p {
				margin : 0;
				padding: 3px;
				display: block;
				font-family: 'DejaVu Sans', Verdana, Arial, sans-serif;
				font-size: 14px;
				background-color: #ffcccc;
			}
			#notifier.fadeIn {
				top: 10px;
				opacity: 1;
				-webkit-transition: all 2s ease;
				-moz-transition: all 2s ease;
				transition: all 2s ease;
			}
			#notifier.fadeOut {
				left: -75px;
				opacity: 0.5;
				transform: scale(0);
				-webkit-transition: all 2s ease-in;
				-moz-transition: all 2s ease-in;
				transition: all 2s ease-in;
			}
			div.synergie_msg {
				background-color: #ff00c0;
				color: #000000;
			}
			#bonus_malus {
				float: left;
				position: absolute;
				border: 1px solid #000000;
				background-color: #ffffff;
				width: 175px;
				table-layout: fixed;
				overflow: hidden;
			}
			#bonus_malus table {
				width: 175px;
				font-size: 11px;
			}
			.progress {
				position: absolute;
				z-index: 1;
				width: 8px;
				height: 32px;
				padding: 0;
				border: 1px solid #cc8888;
				top: 4px;
			}
			.name_span {
				position: absolute;
				z-index: 2;
				top: 8px;
			}
			.my_prime {
				font-family: 'DejaVu Sans', Verdana, Arial, sans-serif;
				background-color: inherit;
				padding: 40px 2px;
				margin: 0;
				position: relative;
				display: block;
				background-repeat: no-repeat;
				background-position: center center;
				background-size: 80px 80px;
				-webkit-touch-callout: none;
				-webkit-user-select: none;
				-khtml-user-select: none;
				-moz-user-select: none;
				-ms-user-select: none;
				user-select: none;
				cursor: default;
				text-align: center;
			}
			#prime_bm {
				visibility: visible !important;
				display: block;
				position: absolute;
				padding: 2px;
				left: 50%;
				transform: translate(-50%, 0);
				opacity: 0;
			}
			#prime_bm.fadeInOut {
				transform: translate(-50%, 0px);
				opacity: 0;
				-webkit-animation-name: fadeInOut;
				-webkit-animation-duration: 4s;
				-moz-animation-name: fadeInOut;
				-moz-animation-duration: 4s;
				animation-name: fadeInOut;
				animation-duration: 4s;
			}
			@-webkit-keyframes fadeInOut {
				from {
					transform: translate(-50%, 0px);
					opacity: 0;
				}
				33% {
					-webkit-animation-timing-function: ease-out;
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				66% {
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				to {
					-webkit-animation-timing-function: ease-in;
					transform: translate(-50%, 40px);
					opacity: 0;
				}
			}
			@-moz-keyframes fadeInOut {
				from {
					transform: translate(-50%, 0px);
					opacity: 0;
				}
				33% {
					-moz-animation-timing-function: ease-out;
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				66% {
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				to {
					-moz-animation-timing-function: ease-in;
					transform: translate(-50%, 40px);
					opacity: 0;
				}
			}
			@keyframes fadeInOut {
				from {
					transform: translate(-50%, 0px);
					opacity: 0;
				}
				33% {
					animation-timing-function: ease-out;
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				66% {
					transform: translate(-50%, 20px);
					opacity: 1;
				}
				to {
					animation-timing-function: ease-in;
					transform: translate(-50%, 40px);
					opacity: 0;
				}
			}
			.glow_bonus {
				-webkit-animation-name: glow_bonus;
				-webkit-animation-duration: 4s;
				-moz-animation-name: glow_bonus;
				-moz-animation-duration: 4s;
				animation-name: glow_bonus;
				animation-duration: 4s;
			}
			@-webkit-keyframes glow_bonus {
				from { background-color: inherit; -webkit-box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #aaff88; -webkit-box-shadow: 0 0 18px #aaff88; }
				to { background-color: inherit; -webkit-box-shadow: 0 0 0px #ffffff; }
			}
			@-moz-keyframes glow_bonus {
				from { background-color: inherit; -moz-box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #aaff88; -moz-box-shadow: 0 0 18px #aaff88; }
				to { background-color: inherit; -moz-box-shadow: 0 0 0px #ffffff; }
			}
			@keyframes glow_bonus {
				from { background-color: inherit; box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #aaff88; box-shadow: 0 0 18px #aaff88; }
				to { background-color: inherit; box-shadow: 0 0 0px #ffffff; }
			}
			.glow_malus {
				-webkit-animation-name: glow_malus;
				-webkit-animation-duration: 4s;
				-moz-animation-name: glow_malus;
				-moz-animation-duration: 4s;
				animation-name: glow_malus;
				animation-duration: 4s;
			}
			@-webkit-keyframes glow_malus {
				from { background-color: inherit; -webkit-box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #ff8888; -webkit-box-shadow: 0 0 18px #ff8888; }
				to { background-color: inherit; -webkit-box-shadow: 0 0 0px #ffffff; }
			}
			@-webkit-keyframes glow_malus {
				from { background-color: inherit; -moz-box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #ff8888; -moz-box-shadow: 0 0 18px #ff8888; }
				to { background-color: inherit; -moz-box-shadow: 0 0 0px #ffffff; }
			}
			@keyframes glow_malus {
				from { background-color: inherit; box-shadow: 0 0 0px #ffffff; }
				66% { background-color: #ff8888; box-shadow: 0 0 18px #ff8888; }
				to { background-color: inherit; box-shadow: 0 0 0px #ffffff; }
			}
			.msg_body:empty:before {
				content: '\200b';	
			}
			.tr-base {
				opacity: 0;
			}
			.tr-fade {
				opacity: 1;
				-webkit-transition: all 2s ease-in;
				-moz-transition: all 2s ease-in;
				transition: all 2s ease-in;
			}
			.tr-base * {
				max-height: 0px;
				overflow: hidden;
			}
			.tr-fade * {
				max-height: 60px;
				overflow: hidden;
				-webkit-transition: all 2s ease-in;
				-moz-transition: all 2s ease-in;
				transition: all 2s ease-in;
			}

			/* PHOTO SENDER */
			.photo-sender {
				width: 220px;
				display: none;
				margin-right: 75px;
				background-color: #ff7f50;
				text-align: left;
				vertical-align: top;
				text-align: center;
				border: 1px solid #bb3b10;
			}
			.photo-sender input {
				vertical-align: text-bottom;
			}
			.photo-sender>label:first-of-type {
				float: left;
			}
			.photo-sender>label:last-of-type {
				float: right;
			}
			.tags {
				clear: left;
				display: none;
				border-top: 1px solid #bb3b10;
				text-align: left;
			}
			.tags>label {
				display: inline-block;
				width: 50%;
			}
		</style>
		<script type="application/javascript">
			document.domain = 'open.hive404.com';

			window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
				var data = new FormData();
				data.append('codeAnim', myCodeAnim);
				data.append('userAgent', window.navigator.userAgent);
				data.append('errorMsg', errorMsg);
				data.append('url', url);
				data.append('lineNumber', lineNumber);
				data.append('column', column);
				data.append('errorObj', errorObj);

				var req = new XMLHttpRequest();
				req.open('POST', 'http://open.hive404.com/openajax_debug.php', true);
				req.send(data);
			}
		</script>
		<script type="application/javascript" src="./socket.io/socket.io.js"></script>
		<script type="application/javascript" src="http://open.hive404.com/openv2/city_list.js"></script>
		<script type="application/javascript" src="./context_infos.js"></script>
		<script type="application/javascript">
var myCodeAnim = null;
var socket = null;
var deja_connecte = false;
var list_anims = [];
var conv_reserve = [];
var is_processing_msg = false;
var has_typed = false;
var current_id_message = 0;
var worst_prime = -1;
var monitor_controlled = 0;
var myNameAnim = '';

// Empeche double appel de page de Chrome (Preload/Prefetch)
var preventPreloadDone = false;

var timestamp_perf = performance.now();

function secondsToString(seconds) {
	var d = Math.floor(seconds / 86400);
	var h = ('0' + Math.floor((seconds % 86400) / 3600)).slice(-2);
	var m = ('0' + Math.floor(((seconds % 86400) % 3600) / 60)).slice(-2);
	var s = ('0' + (((seconds % 86400) % 3600) % 60)).slice(-2);
	var res = '';
	if (seconds >= 0 && seconds < 60) {
		res = s + 's';
	}
	if (seconds >= 60) {
		res = m + 'm ' + res;
	}
	if (seconds >= 3600) {
		res = h + 'h ' + res;
	}
	if (seconds >= 86400) {
		res = d + ' jour(s)<br />' + res;
	}
	return res;
}

function createLabelledRadio (name, value, text, checked) {
	var label = document.createElement('label');
	var radio = document.createElement('input');
	radio.type = 'radio';
	radio.name = name;
	radio.value = value;
	radio.checked = checked;
	var labelText = document.createTextNode(text);
	label.appendChild(radio);
	label.appendChild(labelText);
	return label;
}

function displayConversation(data) {

	if(myCodeAnim == 78155){
	
		console.log(data);
	}
	var table = document.getElementById('inner_conv_table');
	var tbody = document.createElement('tbody');
	var id_chatter = 0;
	var id_chatter_p = 0;

	var conv_length = 0;

	for (var i = 0; data.conversation[i]; i++) {
		conv_length = i;
		if (i == 5 && data.cut_history > 0) {
			var tr = document.createElement('tr');
			
			var td = document.createElement('td');
			td.classList.add('cut_history');
			td.colSpan = 3;

			var p = document.createElement('p');
			p.classList.add('msg_body');
			p.innerHTML = '&gt;-------- Historique coup&eacute; (manque ' + data.cut_history + '<br />messages) --------&lt;';
			td.appendChild(p);

			tr.appendChild(td);
			tbody.appendChild(tr);
		}
		var tr = document.createElement('tr');
		tr.id = data.conversation[i][5];

		var tdClass = data.conversation[i][0] > 10000 ? 'client' : 'anim';
		if (data.conversation[i][0] > 10000) {
			id_chatter = data.conversation[i][0];
		} else if (data.conversation[i][0] != 0) {
			id_chatter_p = data.conversation[i][0];
		}

		// Message
		var td_message = document.createElement('td');
		td_message.classList.add(tdClass);
		var p_message = document.createElement('p');
		p_message.classList.add('msg_body');
		p_message.innerHTML = data.conversation[i][1];
		td_message.appendChild(p_message);

		// Nom animateur
		var td_anim = document.createElement('td');
		td_anim.classList.add(tdClass);
		var p_anim = document.createElement('p');
		p_anim.style.color = '#ffffff';
		p_anim.style.fontSize = '11px';
		var id_animateur = data.conversation[i][2];
		if (list_anims.length != 0) {
			var nom_animateur = (typeof list_anims[id_animateur] !== 'undefined' && list_anims[id_animateur] !== null) ? list_anims[id_animateur].name : '';
			p_anim.textContent = nom_animateur;
		}
		td_anim.appendChild(p_anim);

		// Temps dernier message
		var td_temps = document.createElement('td');
		td_temps.classList.add(tdClass);
		var p_temps = document.createElement('p');
		p_temps.style.whiteSpace = 'nowrap';
		p_temps.style.textAlign = 'right';
		p_temps.innerHTML = secondsToString(data.conversation[i][3]);
		if (typeof data.conversation[(i + 1)] == 'undefined' && data.conversation[i][3] >= 180) {
			p_temps.classList.add('redfont');
			p_temps.innerHTML = '<== RETARD<br />D\'ANIMATION<br />' + p_temps.innerHTML;
		}
		td_temps.appendChild(p_temps);

		tr.appendChild(td_message);
		tr.appendChild(td_anim);
		tr.appendChild(td_temps);
		tbody.appendChild(tr);
	}

	table.appendChild(tbody);
	
	if (myCodeAnim == 1983 || myCodeAnim == 783155 || myCodeAnim == 78055) {
		var table_caption = table.createCaption();
		table_caption.style.captionSide = 'bottom';
		table_caption.innerHTML = '<a href="http://gestion.lotengo.fr/animation/conversation.php?qui='+ id_chatter +'&dt='+ data.misc.id_message +'#'+ data.misc.id_message +'" target="_blank">[Admin] Voir conversation '+ id_chatter +' [Admin]</a>';
	} else {

		var table_caption = table.createCaption();
		table_caption.style.captionSide = 'bottom';

		if(data.misc.audiotel == '') 
			table_caption.innerHTML = 'ID:<span style="color:white;background-color:blue">'+id_chatter+'</span>&nbsp;&nbsp;'; 
		else
			table_caption.innerHTML = 'ID:<span style="color:white;background-color:blue">'+id_chatter+'</span>&nbsp;&nbsp;'+'<span style="color:white;background-color:red">'+data.misc.audiotel+'</span>';


		//'<a href="http://gestion.lotengo.fr/animation/conversation.php?qui='+ id_chatter +'&dt='+ data.misc.id_message +'#'+ data.misc.id_message +'" target="_blank">[Admin] Voir conversation '+ id_chatter +' [Admin]</a>';
	
	
	}

	if (data.misc.relance_courte == 1 && conv_length > 1) {
		document.getElementById('contextMenu').classList.add('hide');
		document.getElementById('contextMenu_specialContextRelance').style.display = 'block';
		document.getElementById('repondre').classList.add('contexte_relance');
		document.getElementById('repondre').value = 'RELANCE 5 MINUTES : Selectionner le contexte utilise pour repondre pour continuer...';
		disable('form_repondre');
	}

	document.getElementById('send_photo').checked = false;
	document.getElementById('c_angel').style.display = 'none';
	document.getElementById('msg_angel').style.display = 'none';
	document.getElementsByClassName('photo-sender')[0].style.display = 'none';

	//document.getElementById('block_mineur').style.display = 'inline';

	if (data.anim.photo != '') {//&& (data.client.service == 125 || data.client.service == 126 || data.client.service == 127)) {
		document.getElementById('send_photo_photo_id').value = data.anim.photo;
		document.getElementById('send_photo_sessionid').value = id_chatter;

		if (id_chatter_p == 7518 || id_chatter_p == 7520) { // angel
			document.getElementById('c_angel').style.display = 'block';
			document.getElementById('msg_angel').style.display = 'block';
			if (myCodeAnim == 1983) {
				document.getElementsByClassName('photo-sender')[0].style.display = 'inline-block';
				var photoSender = document.getElementsByClassName('photo-sender');
				var tag_list = data.anim.photos_tags;
				for (var i = 0; i < radioChk.length; i++) {
					photoSender[i].addEventListener('change', function(event) {
						if (event.target.name == 'hot') {
							var tags = photoSender[i].getElementsByClassName('tags')[0];
							while (tags.lastChild) {
								tags.removeChild(tags.lastChild);
							}
							if (event.target.checked == true) {
								var tagList;
								if (event.target.value == 0 && Array.isArray(tag_list.soft) && tag_list.soft.length > 0) {
									tagList = tag_list.soft;
								} else if (event.target.value == 1 && Array.isArray(tag_list.hot) && tag_list.hot.length > 0) {
									tagList = tag_list.hot;
								}
								tags.appendChild(createLabelledRadio('tag', 0, '(aleatoire)', true));
								if (Array.isArray(tagList)) {
									tagList.forEach(function (element, index, array) {
									tags.appendChild(createLabelledRadio('tag', element.id, element.tag, false));
									});
								}
								tags.style.display = 'block';
							} else {
								tags.style.display = 'none';
							}
						}
					});
				}
			} else {
				document.getElementById('send_photo_label').style.display = 'inline';
			}
		} else {
			document.getElementById('send_photo_label').style.display = 'inline';
		}
	} else {
		document.getElementById('send_photo_photo_id').value = '';
		document.getElementById('send_photo_sessionid').value = '';
		document.getElementById('send_photo_label').style.display = 'none';
		//document.getElementById('block_mineur').style.display = 'none';
	}

	show('center');
	enable('center');
}

function cleanConv() {
	disable('center');
	hide('center');
	removeChildren(document.getElementById('inner_conv_table'));
}

function displaySpeeds(animateurs) {
	var table = document.getElementById('speed_anim');
	var tbody = document.createElement('tbody');

	for (var i = 0; animateurs[i]; i++) {
		var tr = document.createElement('tr');

		var tdClass = animateurs[i][3] < 2 ? 'redbg' : '';

		var td_prenom = document.createElement('td');
		if (tdClass != '') {
			td_prenom.classList.add(tdClass);
		}
		td_prenom.style.width = '100px';
		td_prenom.style.textOverflow = 'clip;';
		td_prenom.textContent = animateurs[i][0];
		
		var td_nom = document.createElement('td');
		if (tdClass != '') {
			td_nom.classList.add(tdClass);
		}
		td_nom.style.width = '125px';
		td_nom.style.textOverflow = 'clip;';
		td_nom.textContent = animateurs[i][1];

		var td_speed = document.createElement('td');
		if (tdClass != '') {
			td_speed.classList.add(tdClass);
		}
		td_speed.classList.add('bold');
		td_speed.style.width = '25px';
		td_speed.textContent = Number(animateurs[i][3]).toFixed(1);
		
		tr.appendChild(td_prenom);
		tr.appendChild(td_nom);
		tr.appendChild(td_speed);
		tbody.appendChild(tr);
	}

	var tr = document.createElement('tr');

	var td = document.createElement('td');
	td.colSpan = 3;
	td.classList.add('bold');
	td.style.textAlign = 'right';
	var txt = animateurs.speed_clients > animateurs.speed_anims ? 'Animation faible !<br />' : '';
	if (txt != '') {
		td.classList.add('redbg');
	}
	td.innerHTML = txt + 'Operateurs : ' + Number(animateurs.speed_anims).toFixed(1) + ' / Clients : ' + Number(animateurs.speed_clients).toFixed(1);

	tr.appendChild(td);
	tbody.appendChild(tr);
	table.appendChild(tbody);
	show('right');
	enable('right');
}

function cleanSpeeds() {
	disable('right');
	hide('right');
	removeChildren(document.getElementById('speed_anim'));
}

function displayInfosClient(client) {
	//Ajustements valeurs
	client.taille = (client.taille == 0 ? '' : client.taille);
	client.poids = (client.poids == 0 ? '' : client.poids);
	client.region = (client.region == -1 ? '' : client.region);
	client.age = (client.age == -1 ? '' : client.age);

	document.getElementById('c_region').value = client.region;
	document.getElementById('c_age').value = client.age;
	document.getElementById('c_sexe').value = client.sexe;
	document.getElementById('c_prenom').value = client.prenom;
	document.getElementById('c_ville').value = client.ville;
	document.getElementById('c_taille').value = client.taille;
	document.getElementById('c_poids').value = client.poids;
	document.getElementById('c_physique').value = client.physique;
	document.getElementById('c_occupation').value = client.occupation;
	document.getElementById('c_tel').value = client.tel;
	document.getElementById('c_comment').value = client.comment;
	document.getElementById('c_cv').innerHTML = client.cv;

	document.getElementById('c_id_chatter').value = client.id_chatter;
	if (client.photo[0] && client.photo[0].trim() != '') {
		var img = document.createElement('img');
		img.src = 'http://sms.hive404.com/p/' + client.photo[0];
		img.style.maxWidth = '150px';
		var c_photo = document.getElementById('c_photo');
		c_photo.appendChild(img);
	}
	if (client.keyword == 113819 || client.keyword == 113820 || client.keyword == 113821) {
		document.getElementById('c_abonne').style.display = 'block';
	} else {
		document.getElementById('c_abonne').style.display = 'none';
	}
	show('left');
	enable('left');
}

function cleanInfosClient() {
	disable('left');
	hide('left');
	document.getElementById('c_region').value = '';
	document.getElementById('c_age').value = '';
	document.getElementById('c_sexe').value = '';
	document.getElementById('c_prenom').value = '';
	document.getElementById('c_ville').value = '';
	document.getElementById('c_taille').value = '';
	document.getElementById('c_poids').value = '';
	document.getElementById('c_physique').value = '';
	document.getElementById('c_occupation').value = '';
	document.getElementById('c_tel').value = '';
	document.getElementById('c_comment').value = '';
	document.getElementById('c_cv').innerHTML = '';

	document.getElementById('c_id_chatter').value = '';
	var c_photo = document.getElementById('c_photo');
	if (c_photo.lastChild) {
		c_photo.removeChild(c_photo.lastChild);
	}
}

function displayInfosAnim(anim) {
	document.getElementById('a_pseudo').textContent = anim.pseudo;
	document.getElementById('a_ville').textContent = anim.ville;
	document.getElementById('a_ville').dataset.defaultCity = anim.ville;
	document.getElementById('a_region').textContent = anim.region;
	document.getElementById('a_age').textContent = anim.age;
	document.getElementById('a_sexe').textContent = anim.sexe;
	document.getElementById('a_physique').textContent = anim.physique;
	document.getElementById('a_occupation').textContent = anim.occupation;
	document.getElementById('a_comment').textContent = anim.comment;
	document.getElementById('a_cv').textContent = anim.cv;
	if (anim.photo[0] && anim.photo[0].trim() != '') {
		var img = document.createElement('img');
		img.src = 'http://sms.hive404.com/p/' + anim.photo[0];
		img.style.maxWidth = '240px';
		img.style.marginBottom = '10px';
		var a_photo = document.getElementById('a_photo');
		a_photo.appendChild(img);
	}
	show('right');
	enable('right');
}

function cleanInfosAnim() {
	disable('right');
	hide('right');
	document.getElementById('a_pseudo').textContent = '';
	document.getElementById('a_ville').textContent = '';
	document.getElementById('a_ville').dataset.defaultCity = '';
	document.getElementById('a_region').textContent = '';
	document.getElementById('a_age').textContent = '';
	document.getElementById('a_sexe').textContent = '';
	document.getElementById('a_physique').textContent = '';
	document.getElementById('a_occupation').textContent = '';
	document.getElementById('a_comment').textContent = '';
	document.getElementById('a_cv').textContent = '';
	var a_photo = document.getElementById('a_photo');
	while (a_photo.lastChild) {
		a_photo.removeChild(a_photo.lastChild);
	}
}

function displayMsgAnim(msg) {
	document.getElementById('msg_anim').textContent = msg;
}

function cleanMsgAnim() {
	document.getElementById('msg_anim').textContent = '';
}

function displayMsgService(msg,syn) {
    syn = parseInt(syn);

	if (msg.substr(0, 5) == 'SOFT:') {
		document.getElementById('msg_service').style.backgroundColor = '#ff00c0';
		document.getElementById('msg_service').style.color = '#000000';
	}
	if(syn == 6)
		document.getElementById('msg_service').textContent = 'SERVICE DE VOYANCE. VOUVOYEZ le client, proposez un tirage, lisez lui son avenir';
	else
		document.getElementById('msg_service').textContent = msg;
}

function cleanMsgService() {
	document.getElementById('msg_service').style.backgroundColor = '';
	document.getElementById('msg_service').style.color = '';
	document.getElementById('msg_service').removeAttribute('style');
	document.getElementById('msg_service').textContent = '';
}

function displayMsgSynergie(syn) {
	syn = parseInt(syn);
	var bgcolor = '#ffffff';
	var txtcolor = '#000000';
	var msg = '';
	
	document.getElementById('left-voyance').style.display = 'none';
	document.getElementById('right-voyance').style.display = 'none';
	
	if (syn == 0) {
		return;
	}

	switch (syn) {
		case 1 : // Gay
			bgcolor = '#ff00c0';
			txtcolor = '#000000';
			msg = 'Service GAY : HOMME <-> HOMME';
			break;
		case 2 : // SM
			bgcolor = '#000000';
			txtcolor = '#ffffff';
			document.getElementById('container').style.backgroundColor = '#a0a0a0';
			msg = 'Service SM';
			break;
		case 3 : // Mature
			bgcolor = '#c0c0c0';
			txtcolor = '#000000';
			msg = 'Service MATURE';
			break;
		case 4 : // Grosse
			bgcolor = '#ff9900';
			txtcolor = '#000000';
			msg = 'Service GROSSE';
			break;
		case 5 : // Geolocalisation
			break;
		case 6 : // Voyance
			bgcolor = '#ff9900';
			txtcolor = '#000000';
			msg = 'Service VOYANCE !';
			document.getElementById('container').style.backgroundColor = '#ffd700';
			document.getElementById('left-voyance').style.display = 'table-cell';
			document.getElementById('right-voyance').style.display = 'table-cell';
			break;
		case 7 : // Trans
			bgcolor = '#cc0088';
			txtcolor = '#ffffff';
			msg = 'Service TRANS';
			break;
		case 8 : // Fetichiste
			bgcolor = '#333333';
			txtcolor = '#dddddd';
			msg = 'Service FETICHISTE';
			break;

        case 10 : // Service pere noel ! 
            bgcolor = '#ff0000';
            txtcolor = '#000000';
            msg = 'Service PERE NOEL, vous etes le pere noel vous parlez aux enfants';
            document.getElementById('container').style.backgroundColor = '#ff0000';
            //document.getElementById('left-voyance').style.display = 'table-cell';
            //document.getElementById('right-voyance').style.display = 'table-cell';
            break;

	}
	document.getElementById('msg_synergie').style.backgroundColor = bgcolor;
	document.getElementById('msg_synergie').style.color = txtcolor;
	document.getElementById('form_repondre').style.backgroundColor = bgcolor;
	document.getElementById('form_repondre').style.color = txtcolor;
	document.getElementById('repondre_label').style.color = txtcolor;
	document.getElementById('msg_synergie').textContent = msg;
}

function cleanMsgSynergie() {
	document.getElementById('container').style.backgroundColor = '';
	document.getElementById('msg_synergie').style.backgroundColor = '';
	document.getElementById('msg_synergie').style.color = '';
	document.getElementById('form_repondre').style.backgroundColor = '';
	document.getElementById('form_repondre').style.color = '';
	document.getElementById('repondre_label').style.color = '#00008b';
	document.getElementById('msg_synergie').removeAttribute('style');
	document.getElementById('msg_synergie').textContent = '';
}

function displaySpeedAnim(speed) {
	document.getElementById('myspeed').textContent = Number(speed).toFixed(1);
}

function displayTorusTempusValues(values) {
	//document.getElementById('torus_tempus').innerHTML = 'Torus : '+ values.current.torus + ' ('+ values.prev.torus +')<br>Tempus : '+ values.current.tempus + ' ('+ values.prev.tempus +')';
	document.getElementById('torus_tempus').innerHTML = 'Torus : '+ values.current.torus + '<br>Tempus : '+ secondsToString(values.current.tempus * 60 * 30);
}

function endMonitorOk(ack) {
	monitor_controlled = 0;
	is_processing_msg = false;
	cleanAll();
	document.getElementById('end_monitor').style.display = "none";
	disable('end_monitor');
	hide('end_monitor');
	ack();
	document.getElementById('end_monitor_button').removeEventListener('click', endMonitorOk);
}

function addProgress(el, max, value) {
	var to_color = 0;
	var width = 12;
	if (max != 0) {
		to_color = Math.floor(value * 10 / max) * width;
	}
	var cell;
	for (var i = 0; i < width * 10; i = i + width) {
		cell = document.createElement('div');
		cell.classList.add('progress');
		cell.style.left = i + 'px';
		if (i < to_color) {
			cell.style.backgroundColor = '#ffaaaa';
		}
		el.appendChild(cell);
	}
	// Demie barre pour ceux qui n'en ont pas
	if (to_color == 0) {
		cell = document.createElement('div');
		cell.classList.add('progress');
		cell.style.left = 0;
		cell.style.backgroundColor = '#ffaaaa';
		cell.style.width = '4px';
		cell.style.borderRight = 'none';
		el.appendChild(cell);
	}
}

function displayPositionsBonus(data, top) {
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	//TODO here we might have an error at the very begining of the month ; because data empty ? in this case test it and return if we have nothing. "!data" not enough
	if (!data) {
		return;
	} else console.log(data);

	var max_prime = 0;//data[0].anim_prime_relance + data[0].anim_prime_stop + data[0].anim_prime_qualite;
	var t_body = document.getElementById('bonus_malus_body');
	removeChildren(t_body);
	var current_row;
	var current_cell;
	var anim_displayed = false;
	for (var i = 0; i < top && i < data.length; i++) {
		current_row = t_body.insertRow(t_body.rows.length);
		if (myCodeAnim == data[i].code_anim) {
			myNameAnim = data[i].nom;
			current_row.classList.add('bold');
			current_row.style.backgroundColor = '#aaaaff';
			anim_displayed = true;
			updateGbmValues(data[i]);
		}
		// Position
		current_cell = current_row.insertCell(0);
		var img = '';
		switch (i) {
			case 0: 
				img = 'first.png';
				break;
			case 1: 
				img = 'second.png';
				break;
			case 2: 
				img = 'third.png';
				break;
			default: 
				break;
		}
		var img_tag = document.createElement('img');
		img_tag.src = 'http://open.hive404.com/openv2/' + img;
		img_tag.width = 40;
		current_cell.style.width = '40px';
		current_cell.appendChild(img_tag);
		// Operateur
		current_cell = current_row.insertCell(1);
		current_cell.style.position = 'relative';
		addProgress(current_cell, max_prime, data[i].anim_prime_relance + data[i].anim_prime_stop + data[i].anim_prime_qualite);
		var name_span = document.createElement('span');
		name_span.classList.add('name_span');
		name_span.appendChild(document.createTextNode(data[i].nom));
		current_cell.appendChild(name_span);
	}
	if(data.length > 0){

	worst_prime = data[data.length - 1].anim_prime_relance + data[data.length - 1].anim_prime_stop + data[data.length - 1].anim_prime_qualite;
	if (anim_displayed == false) {
		for (i = 0; i < data.length && anim_displayed == false; i++) {
			if (myCodeAnim == data[i].code_anim) {
				myNameAnim = data[i].nom;
				current_row = t_body.insertRow(t_body.rows.length);
				current_row.classList.add('bold');
				current_row.style.backgroundColor = '#bbbbff';
				// Position
				current_cell = current_row.insertCell(0);
				current_cell.style.fontSize = '22px';
				current_cell.style.textAlign = 'center';
				current_cell.style.width = '40px';
				current_cell.style.height = '40px';
				current_cell.appendChild(document.createTextNode(i + 1));
				// Operateur
				current_cell = current_row.insertCell(1);
				current_cell.style.position = 'relative';
				addProgress(current_cell, max_prime, data[i].anim_prime_relance + data[i].anim_prime_stop + data[i].anim_prime_qualite);
				var name_span = document.createElement('span');
				name_span.classList.add('name_span');
				name_span.appendChild(document.createTextNode(data[i].nom));
				current_cell.appendChild(name_span);
				anim_displayed = true;
				updatePrime(data[i].anim_prime_relance + data[i].anim_prime_stop + data[i].anim_prime_qualite, false);
				updateGbmValues(data[i]);
			}
		}
	}
}
}

function updateGbmValues(data) {
	gbm['anim_stop'] = data.anim_stop;
	gbm['anim_total_msg'] = data.anim_total_msg;
	gbm['anim_relance_bonus'] = data.anim_relance_bonus;
	gbm['anim_relance_malus'] = data.anim_relance_malus;
	gbm['anim_qualite_total'] = data.anim_qualite_total;
	gbm['anim_qualite_nb_msg_note'] = data.anim_qualite_nb_msg_note;
	gbm['anim_prime_relance'] = data.anim_prime_relance;
	gbm['anim_prime_stop'] = data.anim_prime_stop;
	gbm['anim_prime_qualite'] = data.anim_prime_qualite;
	recalculatePrimeTotale();
}

function updatePrime(new_value, use_notif) {
	var my_prime = document.getElementById('my_prime');
	new_value = Math.round(new_value);
	var old_value = parseInt(my_prime.textContent.replace(/[^-0-9]/g, ''));
	var diff_value = new_value - old_value;
	var mini_notif = my_prime.nextSibling;
	countup.update(new_value);
	if (new_value < 0) {
		var nuc_integer = (Math.round(new_value * 10 / worst_prime) * 10);
		if (nuc_integer > 100) {
			nuc_integer = 100;
		}
		var img = 'nuclear_' + nuc_integer + '.png';
		my_prime.parentNode.style.backgroundImage = 'url(http://open.hive404.com/openv2/nuclear/' + img + ')';
		hide('my_prime');
	} else {
		my_prime.parentNode.style.backgroundImage = '';
		show('my_prime');
		if (new_value > old_value) {
			my_prime.classList.toggle('glow_bonus', true);
		} else if (new_value < old_value) {
			my_prime.classList.toggle('glow_malus', true);
		}
		
		setTimeout(function () {
			my_prime.classList.toggle('glow_bonus', false);
			my_prime.classList.toggle('glow_malus', false);
		}, 4000);
	}
	
	if (use_notif) {
		if (new_value > old_value) {
			mini_notif.style.backgroundColor = '#bbff88';
		} else if (new_value < old_value) {
			mini_notif.style.backgroundColor = '#ff8888';
		}
		if (diff_value > 0) {
			mini_notif.innerHTML = '+' + diff_value + '&nbsp;Ar';
			mini_notif.style.top = my_prime.offsetTop;
			mini_notif.classList.add('fadeInOut');
		} else if (diff_value < 0) {
			mini_notif.innerHTML = diff_value + '&nbsp;Ar';
			mini_notif.style.top = my_prime.offsetTop;
			mini_notif.classList.add('fadeInOut');
		}
	
		setTimeout(function () {
			if (mini_notif) {
				mini_notif.classList.toggle('fadeInOut', false);
			}
		}, 4000);
	}
}

function recalculatePrimeTotale() {
	gbm['anim_prime_totale'] = 0;
	
	gbm['anim_prime_totale'] += Math.round(gbm['anim_prime_relance']);
	gbm['anim_prime_totale'] += Math.round(gbm['anim_prime_stop']);
	gbm['anim_prime_totale'] += Math.round(gbm['anim_prime_qualite']);

	setTimeout(function () {
		updatePrime(gbm['anim_prime_totale'], true);
	}, 8750);
}

function cleanSpeedAnim() {
	document.getElementById('myspeed').textContent = '';
}

function cleanTorusTempusValues() {
	document.getElementById('torus_tempus').textContent = '';
}

function callbackSelection(e) {
	var textSelection = document.getSelection();
	if (textSelection.toString().trim().length > 0) {
		var contextMenu = document.getElementById('contextMenu');
		var rect = textSelection.getRangeAt(0).getBoundingClientRect();
		contextMenu.style.top = rect.bottom + 2 + window.scrollY;
		contextMenu.style.left = rect.left + 2 + window.scrollX;
		contextMenu.style.visibility = 'visible';
		document.addEventListener('mousedown', contextMenuHandler);
		document.addEventListener('keydown', contextMenuHandler);
	}
}

function displayAll(data) {
	displayConversation(data);
	displayInfosClient(data.client);
	displaySpeeds(data.speeds);
	displayInfosAnim(data.anim);
	displayMsgAnim(data.msg_anim);
	displayMsgService(data.msg_service,data.syn);
	displayMsgSynergie(data.syn);

	// Hack pour afficher SOFT / HOT sur certains keywords
	document.getElementById('left-soft-keyword').style.display = 'none';
	document.getElementById('right-soft-keyword').style.display = 'none';
	if (data.client.keyword == 112494 || data.client.keyword == 112493 || data.client.keyword == 111262 || data.client.keyword == 112494) {
		document.getElementById('left-soft-keyword').style.display = 'table-cell';
		document.getElementById('right-soft-keyword').style.display = 'table-cell';
	}

	document.getElementById('left-hot-keyword').style.display = 'none';
	document.getElementById('right-hot-keyword').style.display = 'none';
	if (data.client.keyword == 111159) {
		document.getElementById('left-hot-keyword').style.display = 'table-cell';
		document.getElementById('right-hot-keyword').style.display = 'table-cell';
	}

	document.getElementById('left-internet-keyword').style.display = 'none';
	document.getElementById('right-internet-keyword').style.display = 'none';
	if (data.client.service == 125 || data.client.service == 126 || data.client.service == 127) {
		document.getElementById('left-internet-keyword').style.display = 'table-cell';
		document.getElementById('right-internet-keyword').style.display = 'table-cell';
	}

	document.getElementById('repondre_label').textContent = data.anim.pseudo;
	document.getElementById('repondre_count').value = 160;
	document.getElementById('inner_conv_table').addEventListener('mouseup', callbackSelection);

	current_id_message = data.misc.id_message;
	socket.emit('conv displayed', current_id_message);
	has_typed = false;
	
	var convCenter = document.getElementById('center');
	if (convCenter) { convCenter.scrollTop = convCenter.scrollHeight; }
}

function addAnimRow() {
	var tr = document.getElementById('inner_conv_table').insertRow();
	var cell = tr.insertCell();
	cell.classList.add('anim');
	var p = document.createElement('p');
	p.classList.add('msg_body');
	if (monitor_controlled == 'torus') {
		p.style.textDecoration = 'line-through';
	} else if (monitor_controlled == 'tempus') {
		p.style.fontWeight = 'bold';
		p.style.fontSize = '16px';
	}
	p.textContent = document.getElementById('repondre').value;
	cell.appendChild(p);
	cell = tr.insertCell();
	cell.colSpan = 2;
	cell.classList.add('anim');
	cell.textContent = myNameAnim;
	cell.style.fontWeight = 'bold';
	cell.style.fontSize = '13px';
	cell.style.color = '#ffffff';
	if (monitor_controlled == 'tempus') {
		cell.style.backgroundColor = '#20c020';
	} else if (monitor_controlled == 'torus') {
		cell.style.backgroundColor = '#ff4040';
	}
	tr.classList.toggle('tr-base', true);
	tr.offsetTop; // Forcer reflow de l'element
	tr.classList.toggle('tr-fade', true);
	setTimeout(function () {
		tr.classList.toggle('tr-base', false);
		tr.classList.toggle('tr-fade', false);
	}, 2000);
}

function addMonitorRow() {
	var tr = document.getElementById('inner_conv_table').insertRow();
	var cell = tr.insertCell();
	cell.classList.add('anim');
	var p = document.createElement('p');
	p.id = 'monitor_realtime_typing';
	p.classList.add('msg_body');
	p.style.fontWeight = 'bold';
	p.style.fontSize = '16px';
	cell.appendChild(p);
	cell = tr.insertCell();
	cell.colSpan = 2;
	cell.classList.add('anim');
	cell.textContent = 'Moniteur';
	cell.style.fontWeight = 'bold';
	cell.style.fontSize = '13px';
	cell.style.color = '#ffffff';
	cell.style.backgroundColor = '#20c020';
	tr.classList.toggle('tr-base', true);
	tr.offsetTop; // Forcer reflow de l'element
	tr.classList.toggle('tr-fade', true);
	setTimeout(function () {
		tr.classList.toggle('tr-base', false);
		tr.classList.toggle('tr-fade', false);
	}, 2000);
}

function cleanMonitor() {
	document.getElementById('repondre').style.backgroundColor = '#ffffff';
	document.getElementById('repondre').style.color = '#000000';
	removeChildren(document.getElementById('chat'));
	document.getElementById('form_chat').style.display = 'none';
	disable('form_chat');
	document.getElementById('chat_anim_label').style.display = 'none';
	document.getElementById('chat_anim').style.display = 'none';
	document.getElementById('status').textContent = 'En attente d\'un nouveau message a traiter...';
}

function cleanAll() {
	cleanConv();
	cleanInfosClient();
	cleanSpeeds();
	cleanInfosAnim();
	cleanMsgAnim();
	cleanMsgService();
	cleanMsgSynergie();
	cleanMonitor();
	document.getElementById('repondre_label').textContent = '';
	document.getElementById('repondre').value = '';
	document.getElementById('repondre_count').value = '';
	document.getElementById('send_photo_label').style.display = 'none';
}

function removeChildren (element) {
	while (element.hasChildNodes()) {
		element.removeChild(element.lastChild);
	}
}

function show(id) {
	el = document.getElementById(id);
	el.style.visibility = 'visible';
	c = el.getElementsByTagName('*');
	for (var i = 0; i < c.length; i++) {
		c[i].style.visibility = 'visible';
	}
}

function hide(id) {
	el = document.getElementById(id);
	el.style.visibility = 'hidden';
	c = el.getElementsByTagName('*');
	for (var i = 0; i < c.length; i++) {
		c[i].style.visibility = 'hidden';
	}
}

function disable(id) {
	el = document.getElementById(id);
	el.disabled = true;
	c = el.getElementsByTagName('*');
	for (var i = 0; i < c.length; i++) {
		c[i].disabled = true;
	}
}

function enable(id) {
	el = document.getElementById(id);
	el.disabled = false;
	c = el.getElementsByTagName('*');
	for (var i = 0; i < c.length; i++) {
		c[i].disabled = false;
	}
}

function start(code_anim) {
																			
	console.log(' ------------------------------------------- in client.html => start '+code_anim);

	if (code_anim === null) {
		do {
			code_anim = prompt('Merci de renseigner votre code operateur pour vous connecter.');
		} while (code_anim === '');
	}

	if (code_anim === null) {
		return;
	} else {
		enable('disconnect');
	}
	
	myCodeAnim = code_anim;

	// Valeurs bonus/malus, gbm : global bonus malus
	// A recup depuis le serveur dans le futur
	gbm = [];
	gbm['relance_bonus'] = 115;
	gbm['relance_malus'] = -80;
	gbm['stop_valeur_msg'] = 1;
	gbm['stop_valeur_stop'] = -300;
	gbm['qualite_coef'] = 0.5;
	gbm['relance_max_prime'] = 50000;
	gbm['stop_max_prime'] = 25000;
	gbm['qualite_max_prime'] = 50000;
	
	gbm['anim_stop'] = 0;
	gbm['anim_total_msg'] = 0;
	gbm['anim_relance_bonus'] = 0;
	gbm['anim_relance_malus'] = 0;
	gbm['anim_qualite_total'] = 0;
	gbm['anim_qualite_nb_msg_note'] = 0;
	gbm['anim_prime_relance'] = 0;
	gbm['anim_prime_stop'] = 0;
	gbm['anim_prime_qualite'] = 0;
	gbm['anim_prime_totale'] = 0;

	socket = io('/client', {forceNew: true, query: "code_anim=" + encodeURIComponent(code_anim)});

	socket.on('connect', function () {
		console.log(' ------------------------------------------- in client.html => on connect');
		connect();
		document.getElementById('status').textContent = 'En attente d\'un nouveau message a traiter...';
	});

	socket.on('connect_error', function (error) {
		document.getElementById('status').textContent = 'Erreur lors de la connection';
	});

	socket.on('error', function (error) {
		if (typeof window[error] == 'function') {
			window[error]();
		} else {
			console.log('Unknown error : ' + error);
		}
	});

	socket.on('disconnect', function () {
	//	if (myCodeAnim != 78155) {
			disconnect();
			document.getElementById('status').textContent = 'Deconnecte';
	//	}
	});
}

function connect() {
	show('form_repondre');

	// Reception d'un message a traiter
	socket.on('conv to process', function (data) {
		conv_reserve.push(data);
		if (is_processing_msg === false) {
			is_processing_msg = true;
			document.getElementById('status').textContent = ' ';
			enable('form_repondre');
			displayAll(conv_reserve.splice(0, 1)[0]);
			document.getElementById('repondre').focus();
			socket.emit('performance submit focus', performance.now() - timestamp_perf);
		}
	});
	
	/*
	socket.on('prime noel', function (prime) {
		document.getElementById('prime_noel').textContent = '+' + prime;
		document.getElementById('container_prime_noel').style.display = 'table';
	});
	*/

	socket.on('notify bonus malus', function (data, ack) {
		if (data.points != 0) {
			if (data.points > 0) {
				document.getElementById('notifier').style.backgroundColor = '#ccffcc';
			} else {
				document.getElementById('notifier').style.backgroundColor = '#ff5050';
			}
			var text = '';
			switch (data.raison) {
				case 'relance' : 
					if (data.points > 0) {
						text = 'Votre relance a fonctionne :';
						gbm['anim_relance_bonus'] += data.points;
					} else {
						text = 'Votre relance a echoue :';
						gbm['anim_relance_malus'] += data.points;
					}
					gbm['anim_prime_relance'] = (gbm['anim_relance_bonus'] * gbm['relance_bonus']) + (Math.abs(gbm['anim_relance_malus']) * gbm['relance_malus']);
					if (gbm['anim_prime_relance'] > gbm['relance_max_prime']) {
						gbm['anim_prime_relance'] = gbm['relance_max_prime'];
					}
					document.getElementById('notifier_message').textContent = data.message;
					break;
				case 'stop' :
					text = 'Votre message a provoque un stop.';
					gbm['anim_stop']++;
					gbm['anim_prime_stop'] = (gbm['anim_total_msg'] * gbm['stop_valeur_msg']) + (gbm['anim_stop'] * gbm['stop_valeur_stop']);
					if (gbm['anim_prime_stop'] > gbm['stop_max_prime']) {
						gbm['anim_prime_stop'] = gbm['stop_max_prime'];
					}
					document.getElementById('notifier_message').textContent = data.message;
					break;
				case 'qualite' :
					gbm['anim_qualite_total'] += data.points;
					gbm['anim_qualite_nb_msg_note']++;
					gbm['anim_prime_qualite'] = (gbm['anim_qualite_total'] * gbm['anim_qualite_nb_msg_note'] * gbm['qualite_coef']);
					if (data.points > 0) {
						text = 'Vous avez tape un bon message :';
					} else {
						text = 'Un de vos message aurait pu etre mieux :';
					}
					if (gbm['anim_prime_qualite'] > gbm['qualite_max_prime']) {
						gbm['anim_prime_qualite'] = gbm['qualite_max_prime'];
					}
					document.getElementById('notifier_message').textContent = data.message;
					break;
			}
			document.getElementById('notifier_raison').textContent = text;
			document.getElementById('notifier').classList.toggle('fadeIn', true);
			setTimeout(
				function () {
					document.getElementById('notifier').classList.toggle('fadeOut', true);
					document.getElementById('notifier').style.top = (document.getElementById('my_prime').getBoundingClientRect().top - 20) + 'px';
					setTimeout(
						function () {
							document.getElementById('notifier').classList.toggle('fadeOut', false);
							document.getElementById('notifier').classList.toggle('fadeIn', false);
							document.getElementById('notifier').removeAttribute('style');
							document.getElementById('notifier').offsetHeight;
							ack();
						}, 2000
					);
				},
				7000
			);
			recalculatePrimeTotale();
		}
	});

	socket.on('monitor control', function (value) {
		console.log('GOT monitor control  >>> TORUS');
		monitor_controlled = value;
		var chat = document.getElementById('chat');
		if (monitor_controlled == 'torus') {
			chat.dataset.value = "ATTENTION ! Votre message n'etait pas bon, il vient d'etre intercepte. " +
			"Patientez...";
		} else if (monitor_controlled == 'tempus') {
			chat.dataset.value = "BRAVO ! Vous avez fait un bon message ! " +
			"Patientez...";
		} else {
			chat.dataset.value = '';
		}
	});

	socket.on('timeout monitored', function () {
		conv_reserve = [];
		if (monitor_controlled == 'torus') {
			document.getElementById('repondre').style.backgroundColor = '#ff4040';
		} else if (monitor_controlled == 'tempus') {
			document.getElementById('repondre').style.backgroundColor = '#20c020';
		}
		document.getElementById('repondre').style.color = '#ffffff';
		document.getElementById('status').textContent = '';
		document.getElementById('form_chat').style.display = 'block';
		addAnimRow();
		addMonitorRow();
		disable('form_repondre');
		enable('form_chat');
	});

	socket.on('end monitor control', function (type, ack) {
		show('end_monitor');
		enable('end_monitor');
		hide('end_monitor_button');
		document.getElementById('end_monitor').style.display = "block";
		if (type == 'torus') {
			document.getElementById('end_monitor_msg').innerHTML = "ATTENTION ! Vous venez de recevoir un <b>TORUS</b>. Si vous en accumulez 5 vous recevrez un avertissement ; vous devez soigner votre animation, prenez en compte les conseils du moniteur.";
		} else if (type == 'tempus') {
			document.getElementById('end_monitor_msg').innerHTML = "BRAVO ! Vous venez de recevoir un <b>TEMPUS</b> !<br>Chaque <b>TEMPUS</b> vous ajoute du temps de travail sur votre fiche de salaire :-)";
		} else {
			document.getElementById('end_monitor_msg').innerHTML = "Pas de TEMPUS/TORUS.";
		}
		setTimeout(function () {
			document.getElementById('end_monitor_button').addEventListener('click', endMonitorOk.bind(null, ack));
			show('end_monitor_button');
		}, 2000);
	});

	socket.on('monitor realtime type', function (text) {
		if (monitor_controlled != 0) {
			document.getElementById('monitor_realtime_typing').textContent = text;
		}
	});
	
	socket.on('monitor conv processed', function (reponse) {
		disable('form_repondre');
		enable('form_chat');
		document.getElementById('chat_anim_label').style.display = 'inline';
		document.getElementById('chat_anim').style.display = 'inline';
		document.getElementById('chat_anim').focus();
	});

	socket.on('chat monitor', function (text) {
		var chat = document.getElementById('chat');
		var p = document.createElement('p');
		p.classList.add('monitor');
		p.textContent = 'Moniteur : ' + text;
		chat.appendChild(p);
		chat.scrollTop = chat.scrollHeight;
	});

	socket.on('speed anim', function (speed) {
		show('myspeed');
		enable('myspeed');
		displaySpeedAnim(speed);
	});
	
	socket.on('torus tempus value', function (values) {
		show('torus_tempus');
		enable('torus_tempus');
		displayTorusTempusValues(values);
	});

	socket.on('positions bonus', function (data) {
		displayPositionsBonus(data, 3);
	});

	console.log(' ------------------------------------------- in client.html => set listener init tarik');

	socket.on('init tarik', function (data) {

		console.log(' ----------------------------------OK--------- in client.html => SOCKET ON init tarik =>>>>>'+data);

	});

	console.log(' ------------------------------------------- in client.html => set listener init app');

	socket.on('init app', function (data, ack) {

		console.log(' ---------------------------------OK---------- in client.html => init app');

		list_anims = data.list_anims;
		console.log(' --------------------------------OK----------- in client.html => init app => list_anims, launch ack');
		ack();
		console.log(' ----------------------------------OK--------- in client.html => init app => list_anims, launched ack');
	});

	if (deja_connecte === false) {
		document.getElementById('form_infos_c').addEventListener('change', function (e) {
			if (!e.target.dataset.dispatcher) {
				e.target.dataset.dispatcher = 'direct';
			}
			socket.emit('change info client', {"info": e.target.id, "value": e.target.value, "id": document.getElementById('c_id_chatter').value, "dispatcher": e.target.dataset.dispatcher});
			e.target.dataset.dispatcher = 'direct';
		});

		document.getElementById('repondre').addEventListener('keyup', function(e) {
			socket.emit('realtime type', e.target.value);
		});

		document.getElementById('chat_anim').addEventListener('keyup', function(e) {
			socket.emit('realtime type chat', e.target.value);
		});

		document.getElementById('block_mineur').addEventListener('click', function(e) {
			disable('form_repondre');
			
			socket.emit('block teen', {"id_message": current_id_message});
			gbm['anim_total_msg']++;
			cleanAll();
			if (conv_reserve.length > 0) {
				document.getElementById('status').textContent = '';
				enable('form_repondre');
				displayAll(conv_reserve.splice(0, 1)[0]);
				document.getElementById('repondre').focus();
				socket.emit('performance submit focus', performance.now() - timestamp_perf);
			} else {
				is_processing_msg = false;
				document.getElementById('status').textContent = 'En attente d\'un nouveau message a traiter...';
			}
			e.preventDefault();
		});

		document.getElementById('form_repondre').addEventListener('submit', function(e) {
			if (document.getElementById('repondre').value.length > 10 && document.getElementById('repondre').value.length <= 160) {
				if (monitor_controlled != 0) {
					conv_reserve = [];
					if (monitor_controlled == 'tempus') {
						document.getElementById('repondre').style.backgroundColor = '#20c020';
						document.getElementById('repondre').style.color = '#ffffff';
					} else if (monitor_controlled == 'torus') {
						document.getElementById('repondre').style.backgroundColor = '#ff4040';
						document.getElementById('repondre').style.color = '#ffffff';
					}
					document.getElementById('status').textContent = '';
					document.getElementById('form_chat').style.display = 'block';
					if (monitor_controlled == 'tempus') {
						document.getElementById('chat_anim_label').style.display = 'inline';
						document.getElementById('chat_anim').style.display = 'inline';
						document.getElementById('chat_anim').focus();
					}
					addAnimRow();
					if (monitor_controlled == 'torus') {
						addMonitorRow();
					}
					disable('form_repondre');
					enable('form_chat');
					socket.emit('monitor controlled conv processed', document.getElementById('repondre').value);
					return;
				} else {
					timestamp_perf = performance.now();
					disable('form_repondre');
					
					if (myCodeAnim && document.getElementById('send_photo').checked == true) {
						var xhr = new XMLHttpRequest();
						var photoid = document.getElementById('send_photo_photo_id').value;
						var sessionid = document.getElementById('send_photo_sessionid').value;
						//xhr.open("GET", 'http://sms.hive404.com/sms/handler/snapismoney/send_photo.php?sessionid='+ sessionid +'&photoid='+ photoid +'&code='+ myCodeAnim, true);
						xhr.open("GET", 'http://sms.hive404.com/chat_photo/send_photo_from_ani.php?idc='+ sessionid +'&photo='+ photoid +'&codeanim='+ myCodeAnim, true);
						xhr.onerror = function (e) {
							console.error(xhr.statusText);
						};
						xhr.send(null);
					}

					socket.emit('conv processed', {"reponse": document.getElementById('repondre').value, "id_message": current_id_message});
					gbm['anim_total_msg']++;
					socket.emit('trace send');
					cleanAll();
					if (conv_reserve.length > 0) {
						document.getElementById('status').textContent = '';
						enable('form_repondre');
						displayAll(conv_reserve.splice(0, 1)[0]);
						document.getElementById('repondre').focus();
						socket.emit('performance submit focus', performance.now() - timestamp_perf);
					} else {
						is_processing_msg = false;
						document.getElementById('status').textContent = 'En attente d\'un nouveau message a traiter...';
					}
				}
			}
			e.preventDefault();
		});

		document.getElementById('disconnect').addEventListener('click', function(e) {
			disconnect();
		});

		var resizeTimeout;
		window.addEventListener("resize", function () {
			if (!resizeTimeout) {
				resizeTimeout = setTimeout(function() {
					resizeTimeout = null;
					socket.emit('screen size', window.innerWidth, window.innerHeight);
				}, 500);
			}
		}, false);

		var mouseTimeout;
		window.addEventListener("mousemove", function (e) {
			if (!mouseTimeout) {
				mouseTimeout = setTimeout(function() {
					mouseTimeout = null;
					socket.emit('mouse move', e.pageX, e.pageY);
				}, 500);
			}
		}, false);
	}

	socket.emit('screen size', window.innerWidth, window.innerHeight);

	deja_connecte = true;
	console.log(' ------------------------------------------- in client.html => end connect()');

	console.log(socket);

}

function disconnect() {
	socket.io.disconnect();
	disable('disconnect');
	disable('form_repondre');
	hide('form_repondre');
	disable('myspeed');
	hide('myspeed');
	disable('torus_tempus');
	hide('torus_tempus');
	disable('end_monitor');
	hide('end_monitor');
	cleanAll();
	window.top.location.replace('http://open.hive404.com');
}

function isNotPreload() {
	document.removeEventListener('visibilitychange', isNotPreload, false);
	if (preventPreloadDone == false && document.hidden == false) {
		preventPreloadDone = true;
		if (navigator.userAgent.indexOf("Firefox") != -1) {
			var tmp = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox"));
			var myVersion = parseInt(tmp.substring(tmp.indexOf('/') + 1));
	
			if (myVersion < 32) {
				var data = new FormData();
				data.append('URL', location.href);
				data.append('userAgent', window.navigator.userAgent);
				data.append('tmp', tmp);
				data.append('myVersion', myVersion);
	
				var req = new XMLHttpRequest();
				req.open('POST', 'http://open.hive404.com/openajax_debug.php', true);
				req.send(data);
				alert("Votre navigateur n'est pas a jour. Des messages risquent d'etre perdu et non comptabilises. Merci de mettre à jour votre navigateur.");
			}
		}
		
		// Envoi de la taille de l'ecran
		/*
		var data = new FormData();
		data.append('availWidth', window.screen.availWidth);
		data.append('availHeight', window.screen.availHeight);
	
		var req = new XMLHttpRequest();
		req.open('POST', 'http://open.hive404.com/openajax_debug.php', true);
		req.send(data);
		*/
	
		var radioChk = document.getElementsByClassName('radio-chk');
		for (var i = 0; i < radioChk.length; i++) {
			radioChk[i].addEventListener('change', function (event) {
				if (event.target.type == 'checkbox') {
					var chk = this.querySelectorAll('input[type=checkbox]');
					for (var j = 0; j < chk.length; j++) {
						if (chk[j].checked && chk[j].name == event.target.name && chk[j] != event.target) {
							chk[j].checked = false;
						}
					}
				}
			});
		}


		var documentQueryString = {};
		location.search.substr(1).split("&").forEach(function(item) {
			documentQueryString[item.split("=")[0]] = item.split("=")[1]
		});
		if (documentQueryString.hasOwnProperty('c')) {
			start(documentQueryString.c);
		}
	
		document.getElementById('form_chat').addEventListener('submit', function(e) {
			var input = document.getElementById('chat_anim');
			if (input != '') {
				e.preventDefault();
				socket.emit('chat anim', input.value, current_id_message);
				var chat = document.getElementById('chat');
				var p = document.createElement('p');
				p.classList.add('anim');
				p.textContent = 'Moi : ' + input.value;
				chat.appendChild(p);
				chat.scrollTop = chat.scrollHeight;
				input.value = '';
			}
		});
	
		document.getElementById('repondre').addEventListener('keyup', function(e) {
			if (!has_typed) {
				has_typed = true;
				socket.emit('conv displayed typing', current_id_message);
			}
			document.getElementById('repondre_count').value = 160 - document.getElementById('repondre').value.length;
		});
	}
}

document.addEventListener('DOMContentLoaded', function() {
    var inputElement = document.getElementById('repondre');


    inputElement.addEventListener('dragover', function(event) {
        event.preventDefault();
    });

    inputElement.addEventListener('drop', function(event) {
        event.preventDefault();
    });


});


document.addEventListener('DOMContentLoaded', function () {
	disable('form_repondre');
	hide('form_repondre');
	disable('disconnect');
	disable('myspeed');
	hide('myspeed');
	disable('torus_tempus');
	hide('torus_tempus');
	disable('end_monitor');
	hide('end_monitor');
	cleanAll();
	
	if (document.hidden == true) {
		document.addEventListener('visibilitychange', isNotPreload, false);
	} else {
		isNotPreload();
	}
});
		</script>
		<link rel="stylesheet" type="text/css" href="http://open.hive404.com/3columns.css" />
		<link rel="stylesheet" type="text/css" href="http://open.hive404.com/lotengochat.css" />
	</head>
	<body style="margin: 0; background-color:#585858">
		<div id="container" style="border: 0;">
			<div class="msgperso" id="msg_anim"></div>
			<div id="bonus_malus">
				<table>
					<tbody id="bonus_malus_body">
					</tbody>
				</table>
				<p class="my_prime"><span id="my_prime"></span><span id="prime_bm"></span></p>
				<p id="container_prime_noel" style="
					background: radial-gradient(ellipse at center,  #FF0000 0% ,#400000 100%);
					color:  #ffffff;
					text-align: center;
					width: 100%;
					min-height: 100px;
					margin: 0;
					display: none;
				">
					<span style="
						margin: auto;
						display: table-cell;
						vertical-align: middle;
					">
						<img src="http://open.hive404.com/openv2/noel.png" style="
							display: table-cell;
							width: 100%;
							transform: rotate(180deg);
						">
						Prime de fin d'ann&eacute;e
						<br>
						<span id="prime_noel"></span> Ar
						<img src="http://open.hive404.com/openv2/noel.png" style="
							display: table-cell;
							width: 100%;
						">
					</span>
				</p>
			</div>
			<div id="left">
				<form action="javascript:void(0);" id="form_infos_c">
					<table class="left_col">
						<tbody>
							<tr><th colspan="2"></th></tr>
							<tr><td colspan="2"><span id="c_photo"></span></td></tr>
							<tr><td colspan="2"><span id="c_abonne" style="display: block; text-align: center; background-color: #000000; color: #ffffff; font-weight: bold; font-size: 14px;">ABONNE</span></td></tr>
							<tr><td colspan="2"><span id="c_angel" style="display: block; text-align: center; background-color: #ff69b4; color: #000000; font-weight: bold; font-size: 14px;">ANGEL</span></td></tr>
							<tr><td>Region (01 a 95)</td><td><input size="8" id="c_region"/></td></tr>
							<tr><td>Age</td><td><input size="8" id="c_age"/></td></tr>
							<tr><td>Sexe(f ou g)</td><td><input size="8" id="c_sexe" /></td></tr>
							<tr><td>Prenom</td><td><input size="8" id="c_prenom" /></td></tr>
							<tr><td>Ville</td><td><input size="8" id="c_ville" /></td></tr>
							<tr><td>Taille</td><td><input size="8" id="c_taille" /></td></tr>
							<tr><td>Poids</td><td><input size="8" id="c_poids" /></td></tr>
							<tr><td>Physique</td><td><input size="8" id="c_physique" /></td></tr>
							<tr><td>Occupation</td><td><input size="8" id="c_occupation" /></td></tr>
							<tr><td>Tel</td><td><input size="8" id="c_tel" /></td></tr>
							<tr><td colspan="2">Commentaire</td></tr>
							<tr><td colspan="2"><textarea cols="18" rows="8" id="c_comment" style="visibility: visible; overflow-y: scroll; resize: none; width: 300px; height: 150px;"  ></textarea></td></tr>
							<tr><td colspan="2"><font color="blue"><b><i>INFOS APPEL</i></b></font><br><div id="c_cv"style="background-color:grey;width:175px;"></div></td></tr>
							<tr><td colspan="2"><div style="background-color:red">INFORMATIONS PRIORITAIRES</div></td></tr>
							<tr><td colspan="2"></td></tr>
						</tbody>
					</table>
					<input type="hidden" id="c_id_chatter" value="" />
				</form>
			</div>
			<div id="center">
				<table id="outer_conv_table">
					<tr>
						<th id="left-voyance" style="display: none; background-color: #ffffff; width: 120px;">Ici on dit "VOUS" ! Pour les sujets medicaux on ne lit pas l'avenir, on dit au client de voir avec son medecin</th>
						<th id="left-hot-keyword" style="display: none; background-color: #ff0000; padding: 0px 5px; color: #ffffff;">H<br />O<br />T</th>
						<th id="left-soft-keyword" style="display: none; background-color: #88ff88; padding: 0px 5px;">S<br />O<br />F<br />T</th>
						<th id="left-internet-keyword" style="display: none; background-color: #8888ff; padding: 0px 5px;">I<br>N<br>T<br>E<br>R<br>N<br>E<br>T</th>
						<td id="outer_conv_cell" style="padding: 0px">
							<table id="inner_conv_table" width="100%"></table>
						</td>
						<th id="right-internet-keyword" style="display: none; background-color: #8888ff; padding: 0px 5px;">I<br>N<br>T<br>E<br>R<br>N<br>E<br>T</th>
						<th id="right-soft-keyword" style="display: none; background-color: #88ff88; padding: 0px 5px;">S<br />O<br />F<br />T</th>
						<th id="right-hot-keyword" style="display: none; background-color: #ff0000; padding: 0px 5px; color: #ffffff;">H<br />O<br />T</th>
						<th id="right-voyance" style="display: none; background-color: #ffffff;">V<br />O<br />Y<br />A<br />N<br />C<br />E</th>
					</tr>
				</table>
			</div>
			<div id="right">
				<table class="right_col" id="speed_anim" style="width: 250px;"></table>
				<table style="width: 250px;">
					<tbody>
						<tr><td class="anim" colspan="2"></td></tr>
						<tr><td>Pseudo</td><td><span id="a_pseudo" style="color: darkBlue;" class="bold"></span></td></tr>
						<tr><td>Ville</td><td><span id="a_ville"></span></td></tr>
						<tr><td>Region</td><td><span id="a_region"></span></td></tr>
						<tr><td>Age</td><td><span id="a_age"></span></td></tr>
						<tr><td>Sexe</td><td><span id="a_sexe"></span></td></tr>
						<tr><td>Physique</td><td><span id="a_physique"></span></td></tr>
						<tr><td>Occupation</td><td><span id="a_occupation"></span></td></tr>
						<tr><td>Comment</td><td><span id="a_comment"></span></td></tr>
						<tr><td>CV (vu par le client)</td><td><span id="a_cv"></span></td></tr>
						<tr><td colspan="2"><span id="a_photo"></span></td></tr>
					</tbody>
				</table>
			</div>
			<div id="footer">
				<div id="msg_noel" style="display: none; padding: 0; margin: 0; height: 50px; width: 100%; position: absolute; top: 22px; text-align: center;"><img src="http://open.hive404.com/openv2/msg_noel.png" height="50"></div>
				<div class="service_msg" id="msg_service"></div>
				<div id="msg_angel" style="display:none;background-color: #ff69b4;color: #000000;font-size: 140%;text-align: center;width: 600px;margin: 0 0 5px 200px;font-weight:bold;font-family: verdana;">ANGEL : Pas de RDV, pas de telephone, pas de Skype, mais demande de cadeaux</div>
				<div class="synergie_msg" id="msg_synergie"></div>
				<form action="javascript:void(0);" id="form_repondre" autocomplete="off">
					<!-- <label for="repondre" id="repondre_label" style="color: darkblue; font-weight: bold; text-decoration: underline; background-color:white"></label> : <input type="text" id="repondre" size="80" maxlength="160" tabindex="0" onpaste="return false" /><br /> -->
					<label for="repondre" id="repondre_label" style="color: darkblue; font-weight: bold; text-decoration: underline; background-color:white"></label> :
					<input type="text" id="repondre" onpaste="return false;" size="80" minlength="16" maxlength="160" tabindex="0"  /><br />
					
					<label id="send_photo_label" for="send_photo" style="display: inline; margin-right: 75px; background-color: red;padding:10px; padding-top:0px;"><input type="checkbox" id="send_photo" onchange="document.getElementById('repondre').focus();"> Photo<input type="hidden" id="send_photo_photo_id"><input type="hidden" id="send_photo_sessionid"></label>
					<span class="photo-sender radio-chk">  
						<label><input type="checkbox" name="hot" value="0"> Photo SOFT</label>
						<label><input type="checkbox" name="hot" value="1"> Photo HOT</label>
						<span class="tags"></span>
					</span>
					
					<label for="repondre_count">Reste</label> <input type="text" id="repondre_count" readonly="readonly" size="3" autocomplete="off" />
					<input type="submit" value="Envoyer" />
					<input type="button" id="block_mineur" value="BLOQUER CE CLIENT" style="display: none; background-color: #ff0000; color: #ffffff; border: 1px solid #808080; border-radius: 4px; padding: 1px 6px 2px;"/>
				</form>
				<form action="javascript:void(0);" id="form_chat" autocomplete="off" style="display: none;">
					<div id="chat"></div>
					<label for="chat_anim" id="chat_anim_label">Chat : </label><input type="text" id="chat_anim" size="80">
					<input type="submit" value="Envoyer" style="visibility: hidden;">
					<br><br>
				</form>
				<div id="status"></div>
				<button id="disconnect">Se deconnecter</button>
			</div>
			<div class="myspeed" id="myspeed"></div>
			<div class="torus_tempus" id="torus_tempus"></div>
			<div class="end_monitor" id="end_monitor" style="display: none;">
				<p id="end_monitor_msg"></p>
				<button type="button" id="end_monitor_button">Continuer &agrave; animer...</button>
			</div>
		</div>
		<div id="contextMenu">
			<ul>
				<li id="contextMenu_specialContextRelance" style="display: none;">Contexte relance</li>
				<li id="contextMenu_region">Region</li>
				<li id="contextMenu_age">Age</li>
				<li id="contextMenu_sexe">Sexe</li>
				<li id="contextMenu_prenom">Prenom</li>
				<li id="contextMenu_ville">Ville</li>
				<li id="contextMenu_taille">Taille</li>
				<li id="contextMenu_poids">Poids</li>
				<li id="contextMenu_physique">Physique</li>
				<li id="contextMenu_occupation">Occupation</li>
				<li id="contextMenu_tel">Telephone</li>
				<li id="contextMenu_comment">Comment</li>
			</ul>
		</div>
		<div id="notifier">
			<h4 id="notifier_raison"></h4>
			<p id="notifier_message"></p>
		</div>
		<script>
			countup = new CountUp('my_prime', 0, 0, 0, 2.5, {'separator': ' ','suffix': ' Ar'});
			function msgNoel() {
				var jour = new Date();
				//if (myCodeAnim && (myCodeAnim == 1983 || myCodeAnim == 78155) && jour.getMonth() == 11 && jour.getDate() == 25) {
					document.getElementById('msg_noel').style.display = 'block';
					document.getElementById('container').style.marginTop = '50px';
					document.getElementById('left').style.top = '465px';
				//}
			}
			//setTimeout(msgNoel, 1000);
			//setInterval(msgNoel, 60000);
		</script>
	</body>
</html>
