//
// Define a list of Microsoft XML HTTP ProgIDs.
//
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
  "Msxml2.XMLHTTP.7.0",
  "Msxml2.XMLHTTP.6.0",
  "Msxml2.XMLHTTP.5.0",
  "Msxml2.XMLHTTP.4.0",
  "MSXML2.XMLHTTP.3.0",
  "MSXML2.XMLHTTP",
  "Microsoft.XMLHTTP"
);

//
// Define ready state constants.
//
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

//
// Returns XMLHttpRequest object.
//
function getXMLHttpRequest(url)
{
  // Create the appropriate HttpRequest object for the browser.
  if (window.XMLHttpRequest != null)
  {
    myXmlHttpRequest = new window.XMLHttpRequest();
    myXmlHttpRequest.onreadystatechange = xmlhttpChange;
    myXmlHttpRequest.open("GET", url, false);
    myXmlHttpRequest.send(null);
  }
  else if (window.ActiveXObject != null)
  {
    // Must be IE, find the right ActiveXObject.
    var success = false;
    
    for (var i=0; i<XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
    {
      try
      {
        myXmlHttpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
        success = true;
      }
      catch (ex)
      {}
    }

    if (success)
    {
      myXmlHttpRequest.onreadystatechange = xmlhttpChange;
      myXmlHttpRequest.open("GET", url, false);
      myXmlHttpRequest.send();
    }
  }
}



//
// Used to load XML string into objXmlDom
//
function LoadXMLFromExternalString (xmlstr)
{
	var objXmlDom = null;

	if (xmlstr == '') return; 	// Return if XML string is null
	objXmlDom = LoadXMLString(xmlstr);
	return(objXmlDom);
}

//
// Used to load XML from URL Page into objXmlDom
//
function LoadXML (sURL)
{
	var objXmlDom = null;
	var xmlstr = null;

	// Get XML Data
	xmlstr = GetXMLData(sURL);
	// Return if XML string is null
	if (xmlstr == '') return;

	objXmlDom = LoadXMLString(xmlstr);

	return(objXmlDom);
}

function GetXMLData(sURL)
{
	var objXMLHTTP = null;
	var success = false;
	var szReply = "";
  
	if (window.XMLHttpRequest)
	{
		objXMLHTTP = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		for (var i=0; i<XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
		{
			try
			{
				objXMLHTTP = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
				success = true;
			}
			catch (ex){}
		}
	}
	else if (document.getElementById)
	{
		objXMLHTTP = new XMLHttpRequest();
	}
	
	if (sURL.indexOf("?") > 0)
		sURL = sURL + "&";
	else
		sURL = sURL + "?";
		
	sURL = sURL + "XMLId=" + document.getElementById("XMLId").value;
	

	objXMLHTTP.open("POST", sURL, false);
	objXMLHTTP.setRequestHeader("Content-Length", "5");
	objXMLHTTP.send("xid=1");
	
	var szReply;
	
		if (objXMLHTTP.status == 200)
			szReply = objXMLHTTP.responseText;
		else
		szReply = "";
	
	return szReply;
}

function LoadXMLString (xmlstr)
{
	var fRet = null;
	var objXmlDom = null;
	var IE = 0;
	var NS = 0;

	// Return if XML string is null
	if (xmlstr == '') return;

	if (document.implementation && document.implementation.createDocument) {
		objXmlDom = document.implementation.createDocument("", "", null); 			// Detect Netscape 6+/Mozilla 1.2+
		NS=1;
	}
	else if (window.ActiveXObject) {
		objXmlDom = new ActiveXObject("Microsoft.XMLDOM");											// Detect IE 6+
		IE=1;
	}
	// Return if objXmlDom doesn't exist is null
	if (objXmlDom == null) return;

	if (IE == 1)// IE
	{
		if (objXmlDom.loadXML(xmlstr))	fRet = objXmlDom;
	}
	else 
		if (NS == 1) {	// NS
			// parse the string to a new doc	
			var doc2 = (new DOMParser()).parseFromString(xmlstr, "text/xml");
			
			// insert and import nodes
			for (var i = 0; i < doc2.childNodes.length; i++) {
				objXmlDom.appendChild(objXmlDom.importNode(doc2.childNodes[i], true));
			}
			fRet = objXmlDom;
		}
	return(fRet);
}
	
		
function GetValue(Node)
{
	if (Node != null)	{
		return Node.data;
	}	else	{
		return '';
	}
}

function inspect(elm)
{
  var str = ""; 
  for (var i in elm){ 
    str += i + ": " + elm.getAttribute(i) + "\n";
  }
} 

function removeChildren(n)
{ // Reverse the order of the children of Node n
  if (n != null) {
    var kids = n.childNodes; // Get the list of children 
    var numkids = kids.length; // Figure out how many children there are 
    for(var i = numkids-1; i >= 0; i--) { // Loop backward through the children 
      var c = n.removeChild(kids[i]); // Remove a child 
    }
  }
}

var NRFirstTime=0;

function NextRaceToJumpLoop(LoopType)
{
  if (NRFirstTime > 0) {
	  NextRaceToJump(LoopType);
  } else {
	  NRFirstTime=1;
	}
  setTimeout("NextRaceToJumpLoop(" + LoopType + ")", 60000);
}

function NextRaceToJump(LoopType)
{
	// Load Object DOM
	var sURL;
	if (LoopType == 1) {
	  sURL = "/XMLData/HTML_NextToJump.aspx";
	} else if (LoopType == 2) {
	  sURL = "/XMLData/HTML_NextToJumpHoriz.aspx";
	}
  var sHTML = GetXMLData(sURL);
	if (sHTML == '') {
	  window.status='Next To Jump Refresh Failed.......';			
	} else {
	  document.getElementById("nextjump").innerHTML = sHTML;
	}
}
