/* Settings you might want to define */
var waittime = 800;

/* Internal Variables & Stuff */
var xmlhttp = false;
var xmlhttp2 = false;

// Get flash movie data type

function platform_DoFSCommand(command, args) {
	if (command == "send_message") { 
		submit_msg(args);
	}
}

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		flashmovie = window.document[movieName];
		// alert("1");
	}

	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[movieName]) {
			flashmovie = document.embeds[movieName];
			// alert("2");
		}
	} else {
		flashmovie = document.getElementById(movieName);
		// alert("3");
	}
}

/* Request for Reading the Chat Content */
function ajax_read(url) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}

	if (!xmlhttp) {
		alert('Giving up cannot connect to chat');
		return false;
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {

			flashmovie.SetVariable("sm", xmlhttp.responseText);

			zeit = new Date();
			ms = (zeit.getHours() * 24 * 60 * 1000)
					+ (zeit.getMinutes() * 60 * 1000)
					+ (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
			intUpdate = setTimeout("ajax_read('core/includes/chat/"+room+".txt?x=" + ms + "')", waittime);
		}
	}
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}

/* Request for Writing the Message */
function ajax_write(url) {
	if (window.XMLHttpRequest) {
		xmlhttp2 = new XMLHttpRequest();
		if (xmlhttp2.overrideMimeType) {
			xmlhttp2.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}

	if (!xmlhttp2) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	xmlhttp2.open('GET', url, true);
	xmlhttp2.send(null);
}

/* Submit the Message */
function submit_msg(msg) {
	ajax_write("core/includes/chat/submit.php?m=" + msg + "&room="+ room);
}

/* Start the Requests! ;) */
var intUpdate = setTimeout("ajax_read('core/includes/chat/"+room+".txt')",waittime);

