var xmlhttp;

function WriteLayer(ID,parentID,sText) { 
 if (document.layers) { 
   var oLayer; 
   if(parentID){ 
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
   }else{ 
     oLayer = document.layers[ID].document; 
   } 
   oLayer.open(); 
   oLayer.write(sText); 
   oLayer.close(); 
 } 
 else if (parseInt(navigator.appVersion)>=5&&navigator. 
appName=="Netscape") { 
   document.getElementById(ID).innerHTML = sText; 
 } 
 else if (document.all) document.all[ID].innerHTML = sText 
} 

function XMLRequest(url,method,variables,callback)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
	xmlhttp.onreadystatechange=callback;
	xmlhttp.open(method,url,true);
 	if(method=="POST"){
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  		xmlhttp.setRequestHeader("Content-length", variables.length);
  		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(variables);
	}
	else{
		xmlhttp.send(null);
	}
  	
  }
else
	{
		alert("Your browser is not supported, please use Internet Explorer or Firefox. If you are already using one of them make sure you have the latest version");
	}
}

function setGame(gid){
	var content = "gid=" + encodeURIComponent(gid);
	WriteLayer('gameLayer',null,'<div align=\'center\' class=\'smallText\'><i>Loading...</i></div>');
	XMLRequest("loadgame.asp?c=" + Math.floor(Math.random()*999),"POST",content,gdat);
	//var x = document.getElementById('lg');
	//x.src= "loadgame.asp?gid=" + gid;
}

function getMenu(){
	XMLRequest("gmenu.asp?c=" + Math.floor(Math.random()*999),"GET","x=1",gdat);
}

function gdat(){
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
			WriteLayer('gameLayer',null,'');
			WriteLayer('gameLayer',null,xmlhttp.responseText);
			//alert(xmlhttp.responseText);
    }
  else
    {
    location.reload(true);
    }
  }	
}
