var index_title;var index_header;var index_menu;var index_data;var index_update;var last_index;var timer_id;var timer_id_update;var buffer_data;var mode = -1;var mode_bridge = 0;var mode_bridge_dir;var mode_update_dir;// -------------------------------------------------- //// trace error// -------------------------------------------------- //function traceError(request){	alert('Sorry. There was an error. ' + request);}// -------------------------------------------------- //// getSubString// -------------------------------------------------- //function getSubString(str, index, separator){		var sub = '';	var cindex = 1;		for (pos = 0; pos < str.length; pos++) 		{		if (str.charAt(pos) == separator)			{			if (cindex == index) return sub;			cindex = cindex + 1;				}		else if (cindex == index) 			{			sub = sub + str.substr(pos, 1);			}		}	return sub;}// -------------------------------------------------- //// getXMLHttpRequest// -------------------------------------------------- //function getXMLHttpRequest() {	var xhr = null;	if(window.XMLHttpRequest) 		{		xhr = new XMLHttpRequest();		}	else if(window.ActiveXObject) 		{		try {xhr = new ActiveXObject("Msxml2.XMLHTTP");} 		catch (e) {xhr = new ActiveXObject("Microsoft.XMLHTTP");}		}	else xhr = false;	return xhr;}// -------------------------------------------------- //// Fade Effect// -------------------------------------------------- //function startFade(eid){	var element = document.getElementById(eid);	if (element == null) return;	if (element.FadeState == 1) return;	element.FadeState = 1; 	element.style.opacity = 0;	element.FadeTimeLeft = 300.0;	setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33); }function animateFade(lastTick, eid){  	var element = document.getElementById(eid);	if (element == null) return;	var curTick = new Date().getTime();	var elapsedTicks = curTick - lastTick;	if (element.FadeTimeLeft <= elapsedTicks)		{		element.style.opacity = '1';		element.style.filter = 'alpha(opacity = 100)';		element.FadeState = 2;		return;		}	element.FadeTimeLeft -= elapsedTicks;	var newOpVal = element.FadeTimeLeft/300.0;	newOpVal = 1 - newOpVal;	element.style.opacity = newOpVal;	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';	setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);}// -------------------------------------------------- //// class AjaxElementUpdater// -------------------------------------------------- //function AjaxElementUpdater(p_element, p_file){	var element = p_element;	var xhr = getXMLHttpRequest();	xhr.onreadystatechange = function ()		{		if (xhr.readyState != 4) return;		document.getElementById(element).innerHTML = xhr.responseText;		}	xhr.open("get", p_file, true);	xhr.send(null);}// -------------------------------------------------- //// loadTimer// -------------------------------------------------- //function loadTimer(){	timer_id = setTimeout("loadTimer()", 10000);	var xhr = getXMLHttpRequest();    xhr.onreadystatechange = function() { answerTimer(xhr); };    xhr.open("get", 'live.php' + '?' + Math.random(), true);    xhr.send(null);}function answerTimer(xhr){	if (xhr.readyState != 4) return;	var docTEXT;	try {docTEXT = xhr.responseText;} catch(e){alert(e);}	if (docTEXT.length == 0) return;	checkData(index_title, 'data_title', getSubString(docTEXT, index_title, ';'));	checkData(index_menu, 'data_menu', getSubString(docTEXT, index_menu, ';'));	checkData(index_data, 'data', getSubString(docTEXT, index_data, ';'));	//---toutes les 5 secondes, mise à jour des fichiers	clearTimeout(timer_id);	timer_id = setTimeout("loadTimer()", 5000);}function checkData(index, eid, data_index){	if (last_index[index] == data_index) return;	last_index[index] = data_index;	if (index == 9)		{		index_update = 0;		}	else		{		var file = 'text.php?file=data' + index + '_' + data_index%10 + '.txt';		new AjaxElementUpdater(eid, file + '&' + Math.random()%1000);		}}// -------------------------------------------------- //// Update// -------------------------------------------------- //function loadTimerUpdate(){	timer_id_update = setTimeout("loadTimerUpdate()", 10000);	//gestion socket	if (mode_bridge == 1) 		{		manageBridge.connect('www.vola-racing.com', 8339);		mode_bridge = 0;		return;		}	if (mode_bridge != 0) 		{		//document.getElementById('debug1').innerHTML = 'socket mode';		return;		}	//gestion ajax	var xhr = getXMLHttpRequest();    xhr.onreadystatechange = function() { answerTimerUpdate(xhr); };    xhr.open("get", 'update.php?dir=' + mode_update_dir + '&index=' + index_update + '&' + Math.random()%1000, true);	//document.getElementById('debug1').innerHTML = 'update.php?index=' + index_update;	xhr.send(null);}function answerTimerUpdate(xhr){	if (xhr.readyState != 4) return;	if (mode != 1) return;	if (mode_bridge != 0) return;	var docTEXT;	try {docTEXT = xhr.responseText;} catch(e){alert(e);}	makeData(docTEXT);	clearTimeout(timer_id_update);	timer_id_update = setTimeout("loadTimerUpdate()", 2500);}function makeData(data){		if (mode != 1) return;	buffer_data += data;	var pos = buffer_data.indexOf('\3');	while (pos != -1)		{		var new_data = buffer_data.substring(0, pos);		var eid = getSubString(new_data, 2, '\4');		var element = document.getElementById(eid);		if (element)			{			var new_class = getSubString(new_data, 3, '\4');			var new_html = getSubString(new_data, 4, '\4');			var length = new_class.length;			if (length > 0 && new_class.charAt(length-1) == '*')				{				new_class = new_class.substring(0, length-1);				startFade(eid);				}			if (element.innerHTML != new_html) element.innerHTML = new_html;			if (element.className != new_class) element.className = new_class;			}		index_update = getSubString(new_data, 1, '\4');		buffer_data = buffer_data.substring(pos + 1, buffer_data.length);		pos = buffer_data.indexOf('\3');		}}// -------------------------------------------------- //// class manageBridge// -------------------------------------------------- //var so;var manageBridge = {	connect : function(server, port) {	this.flashMovie.connect(server, port);	//document.getElementById('debug1').innerHTML = 'connect';},stop : function() {	if (mode_bridge != 2) return;	this.flashMovie.write('STOP\3');	//document.getElementById('debug2').innerHTML = 'stop';},	start : function() {	if (mode_bridge != 2) return;	this.flashMovie.write('START\3');	//document.getElementById('debug2').innerHTML = 'start';},		loaded : function() {	mode_bridge = 1;	this.flashMovie = document.getElementById("bridge");	//document.getElementById('debug1').innerHTML = 'loaded';},connected : function() {	mode_bridge = 2;	this.flashMovie.write(mode_bridge_dir + '\3');	this.start();	//document.getElementById('debug1').innerHTML = 'connected';},disconnected : function() {	mode_bridge = 1;	//document.getElementById('debug1').innerHTML = 'disconnected';},		ioError: function(msg) {	mode_bridge = 0;	//document.getElementById('debug1').innerHTML = 'ioError';},						securityError: function(msg) {	mode_bridge = 0;	//document.getElementById('debug1').innerHTML = 'securityError';},								receive: function(msg) {	makeData(msg);	//document.getElementById('debug4').innerHTML = 'receive';}												};// -------------------------------------------------- //// start// -------------------------------------------------- //function start(new_mode){	if (mode == new_mode) return;	//document.getElementById('debug1').innerHTML = '';	//document.getElementById('debug2').innerHTML = '';	//document.getElementById('debug3').innerHTML = '';	//document.getElementById('debug4').innerHTML = '';	//document.getElementById('debug5').innerHTML = '';	//initialisation	if (mode == -1) 		{		timer_id = 0;		timer_id_update = 0;		last_index = new Array(10);			}	else		{		var edata = document.getElementById('data');		if (edata != null) edata.innerHTML = '';			}	mode = new_mode;	//mise à jour des indexs	index_update = 0;	buffer_data = '';	index_title = 1;	if (mode == 1)		{		index_menu = 2;		index_data = 9;		}	if (mode == 2)		{		index_menu = 3;		index_data = 5;		}	if (mode == 3)		{		index_menu = 4;		index_data = 6;		}	last_index[index_menu] = 0;	last_index[index_data] = 0;	//mise à jour des timers et socket	if (timer_id != 0) 		{		clearTimeout(timer_id);		timer_id = setTimeout("loadTimer()", 50);		}	else		{		timer_id = setTimeout("loadTimer()", 500);		}	if (timer_id_update != 0) 		{		clearTimeout(timer_id_update);		timer_id_update = 0;		if (mode == 1) timer_id_update = setTimeout("loadTimerUpdate()", 150);		}	else		{		if (mode == 1) timer_id_update = setTimeout("loadTimerUpdate()", 1500);			}	if (mode == 1) manageBridge.start();	else manageBridge.stop();}// -------------------------------------------------- //// init// -------------------------------------------------- //function init(new_dir){	mode_bridge_dir = new_dir;	mode_update_dir = new_dir.replace('\\', ':');	start(1);}
