function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function pausecomp(millis){
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

var playerLoadStats = new Array();
function addLoadStats(email, md5email) {
	playerLoadStats.push(Array(email, md5email));
}

function loadAllStats(){
	playerLoadStats.reverse();
	setInterval ( "loadPlyStat()", 500 );
}

function loadPlyStat(){
	if(playerLoadStats.length > 0){
		var tempArr = playerLoadStats.pop();
		playerInfo(tempArr[0], tempArr[1]);
	}
}

function playerInfo(email, md5email){
	if (email=="" || md5email==""){
		return;
	}
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var xmldoc = xmlhttp.responseXML;
			var root = xmldoc.getElementsByTagName('root').item(0);
			var registered = root.childNodes[1].getAttribute("registered");
			if(registered == "true"){
				//var steamid = root.childNodes[1].getAttribute("steamid");
				var onlineTime = root.childNodes[1].getAttribute("onlineTime");
				var ptsAvail = root.childNodes[1].getAttribute("ptsAvail");
				var ulibGroup = root.childNodes[1].getAttribute("ulibGroup");
				var profileUrl = root.childNodes[1].getAttribute("profileUrl");
				
				var statsUl = document.getElementById(md5email+'_gmcInfo');
				
				
				var gmc_d = Math.floor(onlineTime / 1440);
				var gmc_h = Math.floor((onlineTime - gmc_d * 1440) / 60);
				var gmc_m = onlineTime - (gmc_d * 1440) - (gmc_h * 60);
				onlineTime = gmc_d+" <i>D</i>,  "+gmc_h+" <i>H</i>,  "+gmc_m+" <i>M</i>";
				
				var htmlcode = "<li>\n";
				htmlcode += "	<span class='ft'>GMC Time:</span>\n";
				htmlcode += "	<span class='fc'>"+onlineTime+"</span>\n";
				htmlcode += "</li>\n";
				htmlcode += "<li>\n";
				htmlcode += "	<span class='ft'>GMC Pts:</span>\n";
				htmlcode += "	<span class='fc'>"+ptsAvail+"</span>\n";
				htmlcode += "</li>\n";
				htmlcode += "<li>\n";
				htmlcode += "	<span class='ft'>GMC Group:</span>\n";
				htmlcode += "	<span class='fc'>"+ulibGroup+"</span>\n";
				htmlcode += "</li>\n";
				htmlcode += "<li>\n";
				htmlcode += "	<span class='fc'><a href='"+profileUrl+"' target='_blank'>View GMC Profile</a></span>\n";
				htmlcode += "</li>\n";
				
				statsUl.innerHTML = htmlcode;
				
			}else{
				var statsUl = document.getElementById(md5email+'_gmcInfo');
				
				var htmlcode = "<li>\n";
				htmlcode += "	<span class='ft'>GMC Time:</span>\n";
				htmlcode += "	<span class='fc'>Not Registered</span>\n";
				htmlcode += "</li>\n";
				
				statsUl.innerHTML = htmlcode;
			}
		}
	}
	xmlhttp.open("GET","/forums/page/gmcproxy.php?email="+urlencode(email),true);
	xmlhttp.send();
}