var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}

	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {

		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}

function fcn(url, divID) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', url, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
		    //alert(xhr[xhri].responseText);
			document.getElementById(divID).innerHTML=xhr[xhri].responseText;
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}

function GetRestsDL(st, selectbox) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', '../files/geteclubrests.aspx?state='+st, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			//clear the dropdown list first 
			for (var j = (selectbox.options.length-1); j >= 0; j--){
         		selectbox.options[j]=null;
     		}
			var arrRests = xhr[xhri].responseText.split("$|$");
			var i = 0
			for(i=0;i<arrRests.length-1;i++){
				var restArr = arrRests[i].split("||");
				var optn = document.createElement("OPTION");
				optn.text = restArr[1];
				optn.value = restArr[0];
				selectbox.options.add(optn);
			}
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}


function gotoURL(URL) { 
	window.location.hash = URL;
}

function hideDiv(src) {
	document.getElementById("coverDiv").style.display = 'none';
	document.getElementById(src).style.display = 'none';
}	

function hideDivComp() {
	if(window.location.href.indexOf('home.asp') >0){
		var so = new SWFObject("../assets/C6Preloader.swf", "prom", "604", "409", "8");
		so.addParam("wmode", "transparent");
		so.write("promotionDiv");
	}
	document.getElementById("flashDiv").style.display = 'none';
	document.getElementById("closeDiv").style.display = 'none';
	document.getElementById("coverBgDiv").style.display = 'none';
}	

function showDiv(src) {
	document.getElementById("coverDiv").style.display = 'block';
	document.getElementById(src).style.display = 'block';
}	

function showDivComp() {
	document.getElementById("flashDiv").style.display = 'block';
	document.getElementById("closeDiv").style.display = 'block';
	document.getElementById("coverBgDiv").style.display = 'block';
}	



function getHomeTabInfo(psid){
    fcn('../varfiles/gettabinfo.aspx?psid='+psid,'featureDiv');
}



function getEventDetails(EventID){
	fcn('../varfiles/geteventdetails.aspx?EventID='+EventID+'&sid='+Math.random(),'EventHolder');
    window.location.hash ="#s"
}

function getGameDetails(GameID, TypeID){
	fcn('../varfiles/getgamedetails.aspx?GameID='+GameID+'&TypeID='+TypeID+'&sid='+Math.random(),'EventHolder');
}

