var http = createRequestObject();

function createRequestObject() {
	// find the correct xmlHTTP, works with IE, FF and Opera
	var xmlhttp;
	try {
  	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
    	xmlhttp=null;
    }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function sendRequest() {
	var name = document.getElementById("name").value;
	var email = document.getElementById("email").value;
	var rnd = Math.random();
	if(email.length<500 && email.length >0) {
		name=escape(name);
		email=escape(email);
	try{
    http.open("GET", "/responsexml.php?name="+name+'&email='+email+'&rnd='+rnd, true);
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleResponse;
		http.send(null);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
		// disable button until end of response
		document.getElementById('go').disabled = true;
		document.getElementById('go').value = "Hold On";
		// hide any previous returned values
		document.getElementById('returned_value').style.display="none";
	} else {
		alert("Comments should be between 5 and 500 characters.");
	}
}


function sendShout() {
	var fromid = document.getElementById("fromid").value;
	var shout = document.getElementById("shout").value;
	var rnd = Math.random();
	var profileid = document.getElementById("profileid").value; 
	
	if(shout.length<455 && shout.length >0) {
		fromid=escape(fromid);
		shout=escape(shout);
		profileid=escape(profileid);
	try{
    http.open("GET", "/shout.php?fromid="+fromid+'&shout='+shout+'&profileid='+profileid+'&rnd='+rnd, true);
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleShout;
		http.send(null);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
		// disable button until end of response
		document.getElementById('go').disabled = true;
		document.getElementById('go').value = "Hold On";
		// hide any previous returned values
		document.getElementById('returned_value').style.display="none";
	} else {
		alert("Comments should be between 5 and 500 characters.");
	}
}



function addFriend(fromid, profileid) {
	
	try{
	document.getElementById("friendid").innerHTML =    '<span style="font-family: Arial;font-size: 11px;font-weight: bold; color: #009933;">Friend added.</span>';	
    http.open("GET", "/addfriend.php?fromid="+fromid+'&profileid='+profileid, true);
    http.setRequestHeader('Content-Type',  "text/xml");
    //http.onreadystatechange = handleShout;
		http.send(null);
	}
	catch(e){
		// caught an error
		alert('Friend could not be added.');
	}
		 
}

function removeFriend(fromid, profileid) {
	
	try{
	document.getElementById("friendid").innerHTML =    '<span style="font-family: Arial;font-size: 11px;font-weight: bold; color: #009933;">Friend removed.</span>';	
    http.open("GET", "/removefriend.php?fromid="+fromid+'&profileid='+profileid, true);
    http.setRequestHeader('Content-Type',  "text/xml");
    //http.onreadystatechange = handleShout;
		http.send(null);
	}
	catch(e){
		// caught an error
		alert('Friend could not be added.');
	}
		 
}

	
	

	



function sendLogin() {


	var name = document.getElementById("name").value;
	var email = document.getElementById("email").value;
	var rnd = Math.random();
	//alert(email);
	if(email.length<500 && email.length >0) {
		name=escape(name);
		email=escape(email);
	try{
    var params = "email_address="+email+'&password='+name+'&type=ajax';
    http.open("POST", "/login.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleLogin;
		http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
		// disable button until end of response
		document.getElementById('go').disabled = true;
		document.getElementById('go').value = "Hold On";
		// hide any previous returned values
		document.getElementById('returned_value').style.display="none";
	} else {
		alert("Comments should be between 5 and 500 characters.");
	}



}

function sendHeaderLogin() {


	var name = document.getElementById("nameheader").value;
	var email = document.getElementById("emailheader").value;

	var rnd = Math.random();
	if(email.length<500 && email.length >0) {
		name=escape(name);
		email=escape(email);
	try{
    var params = "email_address="+email+'&password='+name+'&type=ajax';
    http.open("POST", "/login.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleLogin;
		http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
		// disable button until end of response
		document.getElementById('go').disabled = true;
		document.getElementById('go').value = "Hold On";
		// hide any previous returned values
		document.getElementById('returned_value').style.display="none";
	} else {
		alert("Comments should be between 5 and 500 characters.");
	}



}


function sendSpam() {


	var recipients = document.getElementById("recipients").value;
	var myname = document.getElementById("myname").value;
	var myemail = document.getElementById("myemail").value;
	var message = document.getElementById("message").value;
	var gid = document.getElementById("gid").value;
	var gname = document.getElementById("gname").value;
	
	var error = 0;
	if(recipients.length==0 || myname.length==0){
		error = 1;
	}
    var rnd = Math.random();
	if(error==0) {
		recipients=escape(recipients);
		myemail=escape(myemail);
		myname=escape(myname);
		message=escape(message);
		gid=escape(gid);
		gname=escape(gname);
	try{
    var params = "recipients="+recipients+'&myname='+myname+"&myemail="+myemail+"&message="+message+"&gid="+gid+"&gname="+gname+'&type=ajax';
    http.open("POST", "/spamfriend.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleSpam;
	 http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
		// disable button until end of response
		document.getElementById('gospam').disabled = true;
		document.getElementById('gospam').value = "Sending...";
		// hide any previous returned values
		document.getElementById('returned_value').style.display="none";
	} else {
		document.getElementById("fielderror").innerHTML =    'Please fill in the required fields!';
	}



}



function sendFlag(cid) {



	try{
    var params = "cid="+cid;
    http.open("POST", "/commentflag.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    //http.onreadystatechange = handleLogin;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}

}






function sendRecycle(gid,pid) {



	try{
     //alert("testt: " + gid);
    var params = "gid="+gid+"&act=r"+"&pid="+pid;
    http.open("POST", "/considergames.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    //http.onreadystatechange = handleLogin;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}

}


function sendFeature(gid,pid) {

	try{
     //alert("testt: " + gid);
    var params = "gid="+gid+"&act=f"+"&pid="+pid;
    http.open("POST", "/considergames.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    //http.onreadystatechange = handleLogin;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}

}


function handleSpam() {

	try{

    if((http.readyState == 4)&&(http.status == 200)){

      document.getElementById("fielderror").innerHTML =
      'Your friend(s) have been notified! ';

          // re-enable the button
      document.getElementById('gospam').disabled = false;
      document.getElementById('gospam').value = "Send To Friend(s)";
      document.getElementById('returned_value').style.display="";
		}
  }
	catch(e){
		// caught an error
		alert('Response failed.');
	}
	finally{}
}


function handleShout() {


     
	try{

    if((http.readyState == 4)&&(http.status == 200)){

        
        var response = http.responseXML.documentElement;
      	var n = response.getElementsByTagName('name')[0].firstChild.nodeValue;
        var e = response.getElementsByTagName('shout')[0].firstChild.nodeValue;
      	var r = response.getElementsByTagName('random')[0].firstChild.nodeValue;
        var a = response.getElementsByTagName('avatar')[0].firstChild.nodeValue;
        var t = response.getElementsByTagName('time')[0].firstChild.nodeValue;
        var uid = response.getElementsByTagName('uid')[0].firstChild.nodeValue;
        
      //document.getElementById("formready").innerHTML = " ";

      document.getElementById("returned_value").innerHTML =
      '<table bgcolor= "#C3DAF9" border="0" width="100%" cellspacing="3" cellpadding="0">' +
	  '<tr>'+
	  '<td width="10%"valign="top" rowspan="2"><a href="http://www.onlypoints.com/arcadeindex.php/profile/'+ uid +'"><img border="0" width="40" height="40" src="http://www.onlypoints.com/images/avatars/'+a+'" ></a></td>'+
      '<td width="90%" valign="top"><span class="gmplinks"><a href="http://www.onlypoints.com/arcadeindex.php/profile/'+ uid +'">'+n+'</a></span><span class="ranktext">'+r+'</span><span style="font-family: Arial;font-size: 12px; color:#333333; margin-left:50px; "> '+t+'<span></td>'+
      '</tr>'+
	  '<tr>'+
	  '<td colspan="3"><span style="font-family: Arial;font-size: 12px; color:#333333;  ">'+e+'</span></td>'+
	  '</tr>'+
      '</table>';
 
   

      // re-enable the button
      document.getElementById('go').disabled = false;
      document.getElementById('go').value = "Submit";
      document.getElementById('returned_value').style.display="";
		}
  }
	catch(e){
		// caught an error
		//alert('Response failed.');
	}
	finally{}
}


function handleResponse() {

	try{

    if((http.readyState == 4)&&(http.status == 200)){



        var response = http.responseXML.documentElement;
      	var n = response.getElementsByTagName('name')[0].firstChild.nodeValue;
        var e = response.getElementsByTagName('email')[0].firstChild.nodeValue;
      	var r = response.getElementsByTagName('random')[0].firstChild.nodeValue;
        var a = response.getElementsByTagName('avatar')[0].firstChild.nodeValue;
        var t = response.getElementsByTagName('time')[0].firstChild.nodeValue;
        var exp = response.getElementsByTagName('exp')[0].firstChild.nodeValue;
        var lev = response.getElementsByTagName('lev')[0].firstChild.nodeValue;
     //   alert(n);
    	// write out response
   //   document.getElementById("returned_value").innerHTML =
   //   '<br /><strong>Returned:</strong> <a href="mailto:'+e+
   //   '">'+n+'</a> ('+e+') <strong>Random:</strong> '+r;     experience

      document.getElementById("experience").innerHTML =
      'You earned ' + exp + ' exp. <br>'+ 'You need ' + lev;

      document.getElementById("returned_value").innerHTML =
      '<table bgcolor= "#F0F0F0" border="0" width="100%" cellspacing="3" cellpadding="0">' +
	  '<tr>'+
	  '<td width="4%"valign="top" rowspan="2"><img border="0" width="20" height="20" src="http://www.onlypoints.com/images/avatars/'+a+'" ></td>'+
      '<td width="40%" valign="top"><font color="#000000"><u>'+n+'</u></font><br>'+t+'</td>'+
      '<td width="5%"><div class="ranktext">'+r+' </div></td>'+
      '<td>&nbsp;</td>'+
	  '</tr>'+
	  '<tr>'+
	  '<td colspan="3">'+e+'</td>'+
	  '</tr>'+
      '</table>';


      // re-enable the button
      document.getElementById('go').disabled = false;
      document.getElementById('go').value = "Submit";
      document.getElementById('returned_value').style.display="";
		}
  }
	catch(e){
		// caught an error
		//alert('Response failed.');
	}
	finally{}
}



function handleLogin() {

	try{

    if((http.readyState == 4)&&(http.status == 200)){

          window.location.reload( true );

         //  window.location.href = sURL;

//        document.getElementById("returned_value").innerHTML = 'test545645465465465465465465';
   /*     '<fieldset><br />'+
		'<label><input type="hidden" id="name" name="name" ></label>&nbsp;'+
        '<label>Post Your Comment: </label> <br>'+
		'<textarea rows="4" cols="70" id="email" name="email" ></textarea> &nbsp;'+   '<br>'+
		'<input type="button" value=" Post " id="go" onClick="sendRequest()">'+
		'<br /><br /> '+
    	'</fieldset> ';     */



      // re-enable the button
      document.getElementById('go').disabled = false;
      document.getElementById('go').value = "Submit";
      document.getElementById('returned_value').style.display="";
		}
  }
	catch(e){
		// caught an error
		//alert('Response failed.');
	}
	finally{}
}




function showForm(logged,pid){


  if(logged == 1){

      document.getElementById("formready").innerHTML =
        '<fieldset ><br />'+
        '<label> Posting Rules:       </label></br>'+
        '<lable> 1. Do not post duplicate comments for the same game. </label></br>'+
        '<label> 2. If you have nothing to say DO NOT say it. </label></br>'+
        '<label> People who abuse the system will be banned. </label></br></br>'+
		'<label><input type="hidden" id="name" name="name" value='+pid+'   ></label>&nbsp;'+
        '<label>Post Your Comment: </label> <br>'+
		'<textarea rows="4" cols="50" id="email" name="email" ></textarea> &nbsp;'+   '<br>'+
		'<input type="button" value=" Post " id="go" onClick="sendRequest()">'+
		'<br /><br /> '+
    	'</fieldset> ';
  }else{

        document.getElementById("formready").innerHTML =
        '<fieldset><br />'+
        '<label> Login to post comments.    </label><br>'+
        '<label>Email: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="email" name="email"></label>&nbsp;<br>'+
		'<label>Password: <input type="password" id="name" name="name"></label>&nbsp;<br>'+
		'<input type="button" value=" Login " id="go" onClick="sendLogin()">'+
        '<div id ="link" align="right"> <a href="http://www.onlypoints.com/create_account.php"><u>New Member? Register Here.</u></a></div>'+
		'</fieldset> ';

  }
}


function showShoutForm(logged,pid,prid){


  if(logged == 1){

      document.getElementById("formready").innerHTML =
        '<fieldset ><br />'+
        '<label><input type="hidden" id="fromid" name="fromid" value='+pid+'   ></label>&nbsp;'+
        '<label><input type="hidden" id="profileid" name="profileid" value='+prid+'   ></label>&nbsp;'+
       '<label>Shout message: </label> <br>'+
		'<textarea rows="4" cols="50" id="shout" name="shout" ></textarea> &nbsp;'+   '<br>'+
		'<input type="button" value=" Post " id="go" onClick="sendShout()">'+
		'<br /><br /> '+
    	'</fieldset> ';
  }else{

        document.getElementById("formready").innerHTML =
        '<fieldset><br />'+
        '<label> Login to shout a message.    </label><br>'+
        '<label>Email: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="email" name="email"></label>&nbsp;<br>'+
		'<label>Password: <input type="password" id="name" name="name"></label>&nbsp;<br>'+
		'<input type="button" value=" Login " id="go" onClick="sendLogin()">'+
        '<div id ="link" align="right"> <a href="http://www.onlypoints.com/create_account.php"><u>New Member? Register Here.</u></a></div>'+
		'</fieldset> ';

  }
}




function showLogin(){


     //   alert("test");

       document.getElementById("formready").innerHTML =
        '<fieldset><br />'+
         '<label> Login to post comments.    </label><br>'+
        '<label>Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="email" name="email"></label>&nbsp;<br>'+
		'<label>Password: <input type="password" id="name" name="name"></label>&nbsp;<br>'+
		'<input type="button" value=" Login " id="go" onClick="sendLogin()">'+
        '<div id ="link" align="right"> <a href="http://www.onlypoints.com/create_account.php"><u>New Member? Register Here.</u></a></div>'+
	   	'</fieldset> ';
}


function flagComment (cid){

       document.getElementById("flagged"+cid).innerHTML =    'This comment was flagged.';
       sendFlag(cid);
}

function recGame (gid,pid){

      document.getElementById("story").innerHTML =    'This game will be recycled.';
      //alert("test: "+gid);
      sendRecycle(gid,pid);
}

function featureGame (gid,pid){

      document.getElementById("story").innerHTML =    'This game will be featured.';
      //alert("test: "+gid);
      sendFeature(gid,pid);
}

function showError (){

      document.getElementById("story").innerHTML =    'You need to login to recycle games....';

}

function tellfriend (gid,gname){
	
	//alert(gname);
	document.getElementById("formtellfriend").innerHTML =
        '<fieldset style="background-color : #C3DAF9; padding-left:5;padding-top:3;padding-bottom:3;padding-right:3;">'+        
        '<label><b> Recommend this game to your friends.<b></label><br><br>'+
        '<label>Recipients*(seperate e-mails with comma)<input type="text" id="recipients" name="recipients"></label>&nbsp;<br>'+
		'<label>Your name* <input type="text" id="myname" name="myname"></label>&nbsp;<br>'+
		'<label>Your Email &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="myemail" name="myemail"></label>&nbsp;<br>'+
		'<label>Your message* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea rows="4" cols="20" id="message" name="message" ></textarea></label> &nbsp;'+   '<br>'+
		'<input type="hidden" id="gid" name="gid" value="'+gid+'">'+
		'<input type="hidden" id="gname" name="gname" value="'+gname+'">'+'<br>'+
		'<input type="button" value=" Send To Friend(s) " id="gospam" onClick="sendSpam()">'+
		'</fieldset>'+
		'<div id="fielderror"></div>';
	
}

function getGamepots(){
	var numgames = 10;

	try{
    var params = "numgames="+numgames+'&type=ajax';
    http.open("POST", "/getgamepots.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleGamePots;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
	

}



function handleGamePots(){
	
//	alert("test");
	//document.getElementById("conheader").innerHTML ="tesat";
 try{

    if((http.readyState == 4)&&(http.status == 200)){

        var outputheader = '<span style="margin-left:5px;padding-bottom:3px;border: 1px solid #CCCCCC; padding-left:3px; padding-right:3px; font-family: Verdana; font-size: 12px;  "><a  href="#1" onclick="getLatestScores();" > Latest Scores</a>  </span><span style="margin-left:5px; border: 1px solid #CCCCCC; padding-left:3px;padding-right:3px; font-family: Verdana; font-weight:bold;font-size: 12px;background-color:#E8E8E8;  "> Highest Game Pots   </span>';
        document.getElementById("conheader").innerHTML = outputheader;
        
        var subheader = '<div class="contestplayer"><span style="padding-left:26px;">Game</span><span style="padding-left:66px;">Pot</span><span style="padding-left:60px;">Resets</span>';
        
        document.getElementById("contest_1").innerHTML = subheader;
        
        var outputblock = '<table id="contestsboard" width="290"  border="0" cellpadding="0" cellspacing="0" align="left" ><thead> <tr><th ></th><th class="gname"></th><th class="pot"></th><th class="timer"></th></tr></thead>';
       
        
        
        var response = http.responseXML.documentElement;
        var totalgames = response.getElementsByTagName('game').length;
        
              
        
        var a = 0;
        for (var i = 0; i < totalgames; i++){
             var a = a + 1;
             if(a==1){
				var cl = "class ='even'";
			}else{
			    var cl = "class ='odd'";	
			}
            
           	var game = response.getElementsByTagName('game')[i];
      	    var name = game.getElementsByTagName('name')[0].firstChild.nodeValue;
            var pot = game.getElementsByTagName('pot')[0].firstChild.nodeValue;
      	    var pic = game.getElementsByTagName('pic')[0].firstChild.nodeValue;
      	    var gid = game.getElementsByTagName('gid')[0].firstChild.nodeValue;
            var reset = game.getElementsByTagName('reset')[0].firstChild.nodeValue +" PT";
            
            
                    
           outputblock = outputblock + "<tr>";
           outputblock = outputblock + "<td width='20' height='25' align='right' valign='top' "+cl+" ><img style='border: 1px solid #000000; margin-top: 0px; ' src='http://www.onlypoints.com"+pic+"' width='20' height='20'></td>";
            outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span class='contestlink' style='font-family: Arial; font-size: 11px; margin-left:5px;'><a href='http://www.onlypoints.com/arcadeindex.php/game/"+gid+"/' >"+name+"</a> </span></td>";
            outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+pot+" </span></td>";
            outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+reset+" </span></td>";
           
           outputblock  =  outputblock + "</tr>";        
         
           if(a==2){
		      a=0;	
		   }       

          // alert(name);
        }
        outputblock  =  outputblock + "</table>";
        document.getElementById("cblock").innerHTML = outputblock;
  
		}
  }
	catch(e){
		// caught an error
		alert('Response failed.');
	}
	finally{}
	
	
}


function getLatestScores(){
	
		
	var numgames = 10;

	try{
    var params = 'type=ajax';
    http.open("POST", "/getlatestscores.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleLatestScores;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
	

}

function handleLatestScores(){
	
	 try{

             if((http.readyState == 4)&&(http.status == 200)){
    	
    	           var outputheader = '<span style="margin-left:5px;margin-right:7px; border: 1px solid #CCCCCC; padding-left:3px;padding-right:3px; font-family: Verdana; font-weight:bold;font-size: 12px;background-color:#E8E8E8;  "> Latest Scores   </span><span style="padding-bottom:3px;border: 1px solid #CCCCCC; padding-left:3px; padding-right:3px; font-family: Verdana; font-size: 12px;  "><a  href="#1" onclick="getGamepots();" > Highest Game Pots </a>  </span>';
                  document.getElementById("conheader").innerHTML = outputheader;
                  
                   var subheader = '<div class="contestplayer"><span style="padding-left:28px;">Player</span><span style="padding-left:94px;">Game</span><span style="padding-left:62px;">Score</span></div>';
        
                   document.getElementById("contest_1").innerHTML = subheader;
    	         
    	          var outputblock = '<table id="contestsboard" width="290" border="0" cellpadding="0" cellspacing="0" align="left" ><thead><tr><th ></th><th class="username"></th><th class="gname"></th><th class="score"></th></tr></thead>';
			 
			      var response = http.responseXML.documentElement;
                  var totalgames = response.getElementsByTagName('game').length;
                  
                  var a = 0;
                  for (var i = 0; i < totalgames; i++){
                        a = a + 1;
                        if(a==1){
				             var cl = "class ='even'";
			            }else{
			                 var cl = "class ='odd'";	
			            }
                       
                       var game = response.getElementsByTagName('game')[i];
           	           var avatar = game.getElementsByTagName('avatar')[0].firstChild.nodeValue;
      	               var rank = game.getElementsByTagName('rank')[0].firstChild.nodeValue;
                       var name = game.getElementsByTagName('name')[0].firstChild.nodeValue;
      	               var player = game.getElementsByTagName('player')[0].firstChild.nodeValue;
                       var score = game.getElementsByTagName('score')[0].firstChild.nodeValue;   
                       var gid = game.getElementsByTagName('gid')[0].firstChild.nodeValue;
                       
                        outputblock = outputblock + "<tr>";
                        outputblock = outputblock + "<td width='20' height='20' align='right' valign='top' "+cl+" ><img style='border: 1px solid #000000; margin-top: 0px; ' src='http://www.onlypoints.com/images/avatars/"+avatar+"' width='15' height='15'></td>";
                        outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+player+" </span><span class='ranktext'>"+rank+"</span></td>";   
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span class='contestlink' style='font-family: Arial; font-size: 11px; margin-left:5px;'><a href='http://www.onlypoints.com/arcadeindex.php/game/"+gid+"/'>"+name+"</a></span></td>";    
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+score+"</span></td>";    
                       outputblock  =  outputblock + "</tr>";
                       if(a==2){
		                  a=0;	
		               }  
                  
			      }
			      outputblock  =  outputblock + "</table>";
                  document.getElementById("cblock").innerHTML = outputblock;
			 }      
    }
	catch(e){
		// caught an error
		alert('Response failed.');
	}
	finally{}
	
}


function getLeaders(order){
	
    //alert(order);

	try{
   // var params = 'order='+order+'&type=ajax';
    http.open("GET", "/getleaders.php?order="+order, true);
    //http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //http.setRequestHeader("Content-length", params.length);
    //http.setRequestHeader("Connection", "close");
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleLeaders;
	http.send(params);
	}
	catch(e){
		// caught an error
		alert('Request send failed.');
	}
	finally{}
	

}



function handleLeaders () {
  	
	 try{

             if((http.readyState == 4)&&(http.status == 200)){
    	
    	         
    	           var response = http.responseXML.documentElement;
                   var totalgames = response.getElementsByTagName('player').length;
                   
                   var player = response.getElementsByTagName('player')[0];
                   var order = player.getElementsByTagName('sort')[0].firstChild.nodeValue;
    	   
                   if(order == 1){
    	               	           
    	                     var outputheader = '<span style="margin-left:5px;margin-right:7px; border: 1px solid #CCCCCC; padding-left:3px;padding-right:3px; font-family: Verdana; font-weight:bold;font-size: 12px;background-color:#FFFFFF;  "><a  href="#1" onclick="getLeaders(0);" > Most Experience </a></span><span style="padding-bottom:3px;border: 1px solid #CCCCCC; padding-left:3px; padding-right:3px; font-family: Verdana; font-size: 12px; background-color:#E8E8E8;  "> Most Points </span>';
    	           }else{
					         var outputheader = '<span style="height:40px; margin-left:5px;margin-right:7px; border: 1px solid #CCCCCC; padding-left:3px;padding-right:3px; font-family: Verdana; font-weight:bold;font-size: 12px;background-color:#E8E8E8;  "> Most Experience </span> <span style="height:40px;border: 1px solid #CCCCCC;padding-bottom:3px; padding-left:3px; padding-right:3px; font-family: Verdana; font-size: 12px;  "><a  href="#1" onclick="getLeaders(1);" > Most Points </a>  </span>';
				   }  
    	           
                 document.getElementById("leaderheader").innerHTML = outputheader;
                  
                 
    	         
    	          var outputblock = '<table id="leaderboard" width="430" border="0" cellpadding="0" cellspacing="0" align="left" ><thead><tr><th ></th><th class="usernameL"></th><th class="leaderank"></th><th class="xp"></th> <th class="points"></th> <th class="joindate"></th> </tr></thead>';
			 
			      
                
                  var a = 0;
                  for (var i = 0; i < totalgames; i++){
                        a = a + 1;
                        if(a==1){
				             var cl = "class ='even'";
			            }else{
			                 var cl = "class ='odd'";	
			            }
                       
                       var player = response.getElementsByTagName('player')[i];
                       
          	           var avatar = player.getElementsByTagName('avatar')[0].firstChild.nodeValue;
      	               var rank = player.getElementsByTagName('rank')[0].firstChild.nodeValue;
                       var username = player.getElementsByTagName('username')[0].firstChild.nodeValue;
      	               var exp = player.getElementsByTagName('exp')[0].firstChild.nodeValue;
                       var points = player.getElementsByTagName('points')[0].firstChild.nodeValue;   
                       var custid = player.getElementsByTagName('custid')[0].firstChild.nodeValue;
                       var date = player.getElementsByTagName('joined')[0].firstChild.nodeValue;
                       var datef = date.substr(1,10);
                       //alert(date);
                        
                        outputblock = outputblock + "<tr>";
                        outputblock = outputblock + "<td width='24' height='24' align='right' valign='top'  "+cl+" ><img style='border: 1px solid #000000; margin-top: 0px; ' src='http://www.onlypoints.com/images/avatars/"+avatar+"' width='20' height='20'></td>";
                        outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span class= 'pplinks' style='margin-left:5px;'><a href='http://www.onlypoints.com/index.php/profile/"+custid+"'>"+username+"</a></span> </td>";  
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'></span><span class='ranktext'>"+rank+"</span> </td>"; 
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+exp+" </span></td>";    
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+points+"</span></td>";   
						outputblock = outputblock + "<td "+cl+" style=' height: 20px;' align='left'><span style='font-family: Arial; font-size: 11px; margin-left:5px;'>"+datef+"</span></td>"; 
                       outputblock  =  outputblock + "</tr>";
                       if(a==2){
		                  a=0;	
		               }  
                  
			      } 
			      outputblock  =  outputblock + "</table>";
                  document.getElementById("lblock").innerHTML =  outputblock; 
			 }      
    }
	catch(e){
		// caught an error
		alert('Response failed.');
	}
	finally{}  
}

//CHECK FORM ERROR STARTS HERE***********************************
function validateFormOnSubmit(theForm) {
var reason = "";

  
  reason += validateGameName(theForm.name);
  reason += validateDesc(theForm.desc);
  reason += validateIns(theForm.instructions);
  reason += validateTags(theForm.tags);
  //reason += validateEmpty(theForm.from);
      
  if (reason != "") {
    //alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateGameName(fld) {
    var error = "";
    
    
    if (fld.value == "") {
    	
    	error = "You didn't enter a game name.\n";
    	fld.style.background = '#FFCECE'; 
        document.getElementById("name_error").innerHTML = "*You didn't enter a game name.";
     }else{
		fld.style.background = 'White'; 
        document.getElementById("name_error").innerHTML = "";
		
	} 
   
    return error;
}


function validateDesc(fld) {
    var error = "";
    
    
    if (fld.value == "") {
    	fld.style.background = '#FFCECE'; 
    	error = "You didn't enter a game desription.\n";
        document.getElementById("desc_error").innerHTML = "*You didn't enter a game description.";
        
    } else if (fld.value.length < 30) {
        fld.style.background = '#FFCECE'; 
        error = "The description is too short.";
        document.getElementById("desc_error").innerHTML = "*The description is too short.";
    }else{
		fld.style.background = 'White'; 
        document.getElementById("desc_error").innerHTML = "";
		
	} 

    
    return error;
}



function validateIns(fld) {
    var error = "";
    
    
    if (fld.value == "") {
    	fld.style.background = '#FFCECE'; 
    	error = "You didn't enter a game desription.\n";
        document.getElementById("ins_error").innerHTML = "*You didn't enter game instructions.";
        
    } else if (fld.value.length < 20) {
        fld.style.background = '#FFCECE'; 
        error = "The instructions are too short.";
        document.getElementById("ins_error").innerHTML = "*The instructions are too short.";
    }else{
		fld.style.background = 'White'; 
        document.getElementById("ins_error").innerHTML = "";
		
	} 

    
    return error;
}


function validateTags(fld) {
    var error = "";
    
    
    if (fld.value == "") {
    	fld.style.background = '#FFCECE'; 
    	error = "You didn't enter a game desription.\n";
        document.getElementById("tag_error").innerHTML = "*You didn't enter any game tags.";
        
    } else if (fld.value.length < 5) {
        fld.style.background = '#FFCECE'; 
        error = "The instructions are too short.";
        document.getElementById("tag_error").innerHTML = "*Please enter at least two tags.";
    }else{
		fld.style.background = 'White'; 
        document.getElementById("tag_error").innerHTML = "";
		
	} 

    
    return error;
}

