/*
Ajax stream loader by Phil.
To Use:
1. Load into your document with <script type="text/javascript" src="ajax.js" />
2. Call the _init function in your body tag with <body onLoad="_init()">
*/
var xmlHttp;
var theOutput = "";
var response;
function refreshStream() {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert ("Your browser does not support AJAX!");
return;
}
var url = "/SiteCP/check_if_switched.php?rnd=" + Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
response = xmlHttp.responseText.toString();
if (theOutput == "") {
theOutput = xmlHttp.responseText.toString();
}
else {
if (theOutput.toLowerCase() != response.toLowerCase()) {
document.getElementById("the_video").innerHTML = xmlHttp.responseText;
theOutput = xmlHttp.responseText.toString();
}
}
_init();
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function _init() {
setTimeout(refreshStream, 10000); // Check every 10 seconds if the stream has changed
}