var xmlHttp

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 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=="login"){document.getElementById("login").innerHTML=xmlHttp.responseText}
		if(obj=="logout"){document.getElementById("login").innerHTML=xmlHttp.responseText}			
		if(obj=="Contact"){
			if(xmlHttp.responseText=="ok"){document.getElementById("Contact").innerHTML="<div class='panna'>The E-Mail has been sent!</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;}
