var xmlHttp
function showCustomer(){ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
	alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="/read.php";
    url=url+"?sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
	
}
function stateChanged(){ 
    if (xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
		}else{
			document.getElementById("txtHint").innerHTML="There was a problem with the request!"+xmlHttp.status;
		};
    }
}


function showFriendsprofil(page,iduser){ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
	alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="/ajax/showfriendsprofil.php";
    url=url+"?sid="+Math.random();
	url=url+"&page="+page;
	url=url+"&iduser="+iduser;
    xmlHttp.onreadystatechange=stateFriends;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
	
}
function showFriends(page,iduser){ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
	alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="/ajax/showfriends.php";
    url=url+"?sid="+Math.random();
	url=url+"&page="+page;
	url=url+"&iduser="+iduser;
    xmlHttp.onreadystatechange=stateFriends;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
	
}
function stateFriends(){ 
    if (xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			document.getElementById("friends").innerHTML=xmlHttp.responseText;
		}else{
			document.getElementById("friends").innerHTML="There was a problem with the request!"+xmlHttp.status;
		};
    }
}

var xmlHttp3
function showPms(){ 
    xmlHttp3=GetXmlHttpObject();
    if (xmlHttp3==null){
	alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="/ajax/getpms.php";
    url=url+"?sid="+Math.random();
    xmlHttp3.onreadystatechange=stateChanged3;
    xmlHttp3.open("GET",url,true);
    xmlHttp3.send(null);
	
}
function stateChanged3(){ 
    if (xmlHttp3.readyState==4){
		if(xmlHttp3.status==200){
			document.getElementById("ajaxpms").innerHTML=xmlHttp3.responseText;
		}else{
			document.getElementById("ajaxpms").innerHTML="There was a problem with the request!"+xmlHttp3.status;
		};
    }
}


var xmlHttp2
var pageloadstart
function showonlineusers(){ 
	pageloadstart = new Date();
    xmlHttp2=GetXmlHttpObject();
    if (xmlHttp2==null){
	alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="/online_users.php";
    url=url+"?sid="+Math.random();
    xmlHttp2.onreadystatechange=stateChanged2;
    xmlHttp2.open("GET",url,true);
    xmlHttp2.send(null);
	showPms();
}
function stateChanged2(){ 
    if (xmlHttp2.readyState==4){ 
		if(xmlHttp2.status==200){
			document.getElementById("onlineusers").innerHTML=xmlHttp2.responseText;
			//timp de incarcare
			var pageloadend = new Date();
			var pageloadtime = pageloadend.getTime() - pageloadstart.getTime();
			if(pageloadtime<100) // less than 2 seconds is very fast
					lc = pageloadtime+'ms <img src="/images/signal-1.png" style="vertical-align:middle;" alt="ping" title="calitate conexiune foarte buna '+pageloadtime+'ms" />';
			else if (pageloadtime<150) // 5 seconds = fast
					lc = pageloadtime+'ms <img src="/images/signal-2.png" style="vertical-align:middle;" alt="ping" title="calitate conexiune buna '+pageloadtime+'ms" />'
			else if (pageloadtime<200) // 10 seconds medium
					lc = pageloadtime+'ms <img src="/images/signal-3.png" style="vertical-align:middle;" alt="ping" title="calitate conexiune slaba '+pageloadtime+'ms" />';
			else if (pageloadtime<250) // 30 seconds - sluggish
					lc = pageloadtime+'ms <img src="/images/signal-4.png" style="vertical-align:middle;" alt="ping" title="calitate conexiune foarte slaba '+pageloadtime+'ms" />'
			else lc = '999ms <img src="/images/firewall.png" style="vertical-align:middle;" alt="firewall" title="calitatea conexiunii nu poate fi calculata '+pageloadtime+'ms" />';
			document.getElementById("timpincarcare").innerHTML="calitate conexiune: "+lc;		
		}else{
			document.getElementById("onlineusers").innerHTML="There was a problem with the request!"+xmlHttp2.status;
		};	
    }
}

function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
        xmlHttp=new XMLHttpRequest();
    }
    catch(e){
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e){
	    try{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                  alert("Your browser does not support AJAX!");
                  return false;
            }
        }
    }
    return xmlHttp;
}

