/*
	xmlHttp Object Loader
	
	This script loads 4 xmlHttp objects.
	The xmlhttp object allows content to be transfered to and from a web page without refreshing the page.
	The reason there are 4 objects is currently the xmlhttp object can not make multipule connections at once.
	There are 4 areas of information that need to be updated on the player so we have 4 objects.  I could have
	used a javascript timeout and used 1 object however this would not work with slower connection speeds as the
	timeout wouldn need to vary depending on the connection speed.
*/
var xmlhttp=false;
var xmlhttp2=false;
var xmlhttp3=false;
var xmlhttp4=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp3 = new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp4 = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp4 = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
	xmlhttp2 = false;
	xmlhttp3 = false;
	xmlhttp4 = false;
   }
  }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

if (!xmlhttp2 && typeof XMLHttpRequest!='undefined') {
  xmlhttp2 = new XMLHttpRequest();
}

if (!xmlhttp3 && typeof XMLHttpRequest!='undefined') {
  xmlhttp3 = new XMLHttpRequest();
}

if (!xmlhttp4 && typeof XMLHttpRequest!='undefined') {
  xmlhttp4 = new XMLHttpRequest();
}

//loadFragmentInToElement
/*
	This function loads content sent from the server into an element on the webpage. Without refreshing the browser
	Input: loaderID - xmlhttp object we will be using (there are three)
		   fragment_url - the url on the server we are calling (http://www.plr.org/player/createTimeout.html)
		   element_id - target element ID on the page (dynamicTimer)
	Output: whatever output the page we requested outputs
*/
function loadFragmentInToElement(loaderID, fragment_url, element_id) {
	//setup our target element
    var element = document.getElementById(element_id);
    //element.innerHTML = 'Loading ...';
	//If statment here branches to the xmlhttp object we will be using
	if(loaderID == 1)
	{
		//create a request for a page. Use GET, the url, asynchronous transfer (makes the transfer seemless to the user)
		xmlhttp.open("GET", fragment_url,true);
		//this is a listen event. xmlhttp will listen for the onreadystatechange
		//if the state is 4 (Response complete) and the status is 200 (The request has succeeded) we get the returned data
		xmlhttp.onreadystatechange = function() {
		  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		  //responseText is the output data from the page we requested. We stuff that data in element.innerHTML
		  element.innerHTML = xmlhttp.responseText;
		  }
		}
		//This acutally sends our request we built with xmlhttp.open
		xmlhttp.send(null);
	}
	else if(loaderID == 2)
	{
		xmlhttp2.open("GET", fragment_url,true);
		xmlhttp2.onreadystatechange = function() {
		  if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
		  element.innerHTML = xmlhttp2.responseText;
		  }
		}
		xmlhttp2.send(null);
	}
	else if(loaderID == 3)
	{
		xmlhttp3.open("GET", fragment_url,true);
		xmlhttp3.onreadystatechange = function() {
		  if (xmlhttp3.readyState == 4 && xmlhttp3.status == 200) {
		  element.innerHTML = xmlhttp3.responseText;
		  }
		}
		xmlhttp3.send(null);
	}
	else if(loaderID == 4)
	{
		xmlhttp4.open("GET", fragment_url,true);
		xmlhttp4.onreadystatechange = function() {
		  if (xmlhttp4.readyState == 4 && xmlhttp4.status == 200) {
		  element.innerHTML = xmlhttp4.responseText;
		  }
		}
		xmlhttp4.send(null);
	}
}