var xmlHttp

function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, '')
}

function vote(voto,game){ 
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Vote&v="+voto+"&g="+game
	xmlHttp.onreadystatechange= function(){ stateChanged("vote") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	document.getElementById("voted").innerHTML="Your Vote: <img src='gif/vote"+voto+".gif' alt='My Vote' width='14' height='14' />"
}

function login(u,p){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Login&u="+u+"&p="+p
	xmlHttp.onreadystatechange= function(){ stateChanged("login") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function logout(){ 
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Logout"
	xmlHttp.onreadystatechange= function(){ stateChanged("logout") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function register(u,p,e,g){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Register&u="+u+"&p="+p+"&e="+e+"&g="+g
	xmlHttp.onreadystatechange= function(){ stateChanged("register") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function forgot(e){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Forgot&e="+e
	xmlHttp.onreadystatechange= function(){ stateChanged("forgot") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function Comment(c,o){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=Comment&c="+c+"&o="+o
	xmlHttp.onreadystatechange= function(){ stateChanged("Comment") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function commentDelete(u,d,o){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=commentDelete&u="+u+"&d="+d+"&o="+o
	xmlHttp.onreadystatechange= function(){ stateChanged("commentDelete") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function addLink(u,t,e){
	xmlHttp=GetXmlHttpObject()
	var url="functions.php"
	url=url+"?a=addLink&u="+u+"&t="+t+"&e="+e
	xmlHttp.onreadystatechange= function(){ stateChanged("addLink") }
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function contact(e,m){	
	xmlHttp=GetXmlHttpObject();
	var url="functions.php";
	var parametri="a=Contact&e="+e+"&m="+m;
	xmlHttp.open("POST",url,true);
	
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parametri.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange= function(){ stateChanged("Contact") }	
	xmlHttp.send(parametri)
}

function stateChanged(obj){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//if(obj=="vote"){document.getElementById("voted").innerHTML=xmlHttp.responseText}
		if(obj=="login"){document.getElementById("login").innerHTML=xmlHttp.responseText}
		if(obj=="logout"){document.getElementById("login").innerHTML=xmlHttp.responseText}
		if(obj=="register"){
			if(xmlHttp.responseText=="ok"){document.getElementById("register").innerHTML="<div class='verde'>Congratulation! An activation mail has just been sent to you.<br />Click on the link you find in the mail to activate your account!</div>"}
			if(xmlHttp.responseText=="no"){document.getElementById("error").innerHTML="Unexpected error, please check that all the fields are correctly filled."}
			if(xmlHttp.responseText=="userExists"){document.getElementById("error").innerHTML="Username already in our DataBase, please chose another one."}
			if(xmlHttp.responseText=="mailExists"){document.getElementById("error").innerHTML="Mail already in our DataBase, if you lost your Access Data <a href='forgot/'>Click Here</a> to retrive it!"}
		}
		if(obj=="Comment"){document.getElementById("Comments").innerHTML=xmlHttp.responseText}
		if(obj=="commentDelete"){document.getElementById("Comments").innerHTML=xmlHttp.responseText}
		if(obj=="forgot"){
			if(xmlHttp.responseText=="ok"){document.getElementById("forgot").innerHTML="<div class='verde'>An E-mail has just been sent to you with your Access Information.</div>"}
			if(xmlHttp.responseText=="no"){document.getElementById("error").innerHTML="E-Mail not found in our DataBase."}		
		}
		if(obj=="addLink"){
			if(xmlHttp.responseText=="ok"){document.getElementById("submitLink").innerHTML="<div class='panna'>Your link as been added to our DataBase, you have one week to activate it by linking to LorenzGames.Com on your site.<br />You will see it on this list when it will be activated by the first click from your site.</div>"}
			if(xmlHttp.responseText=="no"){document.getElementById("error").innerHTML="Fill the fields correctly!"}		
		}
		if(obj=="Contact"){
			if(xmlHttp.responseText=="ok"){document.getElementById("Contact").innerHTML="<div class='panna'>The E-Mail has been sent!<br />Our staff will answer you shortly...</div>"}
			if(xmlHttp.responseText=="no"){document.getElementById("error").innerHTML="Fill the fields correctly!"}		
		}
	} 
}

function GetXmlHttpObject(){var xmlHttp=null;
try {xmlHttp=new XMLHttpRequest();}
catch (e) {try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
return xmlHttp;}