var filterActive = false;
var interval = null;
function StandardXMLHttpRequest(){
	if(window.XMLHttpRequest){
		try{
			return new XMLHttpRequest();
		}catch(e){
			return false;
		}
	} else if(window.ActiveXObject){
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return false;
			}
		}
	}else{
		return false;
	}
}
function hideAll(){
	var tables = document.getElementsByTagName("table");
	for(i = 0; i < tables.length; i++){
		if(tables[i].id.indexOf("events-")!=-1){
			tables[i].style.display="none";
		}
	}
	
	var rows = document.getElementsByTagName("tr");
	for(i = 0; i < rows.length; i++){
		if(rows[i].id.indexOf("event-row-")!=-1){
			rows[i].style.display="none";
		}
	}
}
function getChecked(){
	var chbox = new Array();
	var boxes = new Array();
	var x = document.getElementsByTagName("input");
	var f = 0;
	for(n = 0; n < x.length; n++){
		if(x[n].type=="checkbox"){
			chbox[f] = x[n];
			f++;
		}
	}
	var j = 0;
	for (i = 0;i < chbox.length;i++){
		if (chbox[i].name.substring(0,2) == "mt"){			if(chbox[i].checked == 1){
				boxes[j] = chbox[i].value;
				j++;
			}
		}
	}
	return boxes;
}
function showSelected(checked){
	var fks = checked||getChecked();
	if(fks.length>1)
		hideAll();
	var rows = document.getElementsByTagName("tr");
	for(i = 0; i < rows.length; i++){
		for(j = 0; j < fks.length; j++){
			if(rows[i].id.indexOf(fks[j])!=-1){
				rows[i].style.display = "";
				rows[i].parentNode.parentNode.style.display = "";
			}
		}
	}
	filterActive = true;
}
function checkSelected(checked){
	for (i = 0;i < checked.length;i++){
		document.getElementById("mt" + checked[i]).checked = 1;
	}
}
function refreshPage(url){
	var checked = getChecked();
	var oHttpRequest = new StandardXMLHttpRequest();
	if(!oHttpRequest){
		var oDocRoot = document.getElementById("live");
		oDocRoot.innerHTML = "XMLRequest cannot be initialized";
	}else{
		oHttpRequest.onreadystatechange = function () {
			if(oHttpRequest.readyState==4 && oHttpRequest.status==200){
				if(oHttpRequest.responseText){
					var oDocRoot = document.getElementById("live");
					oDocRoot.innerHTML = oHttpRequest.responseText;
					if(filterActive==true){
						showSelected(checked);
					}
					checkSelected(checked);
				}else{
					var oDocRoot = document.getElementById("live");
					oDocRoot.innerHTML = "Fejl under indlæsning";
				}
			}
		}
		oHttpRequest.open("GET",url, true);oHttpRequest.send(null);
	}
}

function refreshPage1(){
	var url = "getContent.php?d="+VAR_day+"&showLeagues="+VAR_showLeagues+(VAR_Country!="false"?"&Countries="+VAR_Country:"")+"&date=" + new Date().toString();
	var oHttpRequest = new StandardXMLHttpRequest();
	if(!oHttpRequest){
		var oDocRoot = document.getElementById("enetpulse-match-holders-s");
		oDocRoot.innerHTML = "XMLRequest cannot be initialized.";
	}else{
		oHttpRequest.onreadystatechange = function () {
			if(oHttpRequest.readyState==4 && oHttpRequest.status==200){
				if(oHttpRequest.responseText){
					var oDocRoot = document.getElementById("enetpulse-match-holders-s");
					oDocRoot.innerHTML = oHttpRequest.responseText;
					if (interval == null) {
						interval = setInterval("blink()", 500);
					}
					setTimeout("refreshPage1()", 15000);
				}else{
					var oDocRoot = document.getElementById("enetpulse-match-holders-s");
					oDocRoot.innerHTML = "Error reading content. Trying again now...";
					setTimeout("refreshPage1()", 2000);
				}
			}
		}
		oHttpRequest.open("GET",url, true);oHttpRequest.send(null);
	}
}

function blink(){
	$("span.squote").each(function (count, element){ 
		if(element.innerHTML=="'"){
			element.innerHTML="&nbsp;";
		}else{
			element.innerHTML="'";
		}
	});
}