var xmlHttp;
var xmlHttp2;
var xmlHttp3;

function updateMenu() {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		return;
	} 

	var url="javascript/check_messages.php";
	xmlHttp.onreadystatechange=updateMail;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	xmlHttp2=GetXmlHttpObject()
	if (xmlHttp2==null) {
		return;
	} 

	var url="javascript/check_friends.php";
	xmlHttp2.onreadystatechange=updateFriends;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
	
	xmlHttp3=GetXmlHttpObject()
	if (xmlHttp3==null) {
		return;
	} 

	var url="javascript/check_watched.php";
	xmlHttp3.onreadystatechange=updateWatched;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
} 

function updateMail() { 
	if (xmlHttp.readyState==4) { 
		if ( xmlHttp.responseText > 0 ) {
			document.getElementById("mail_image").src = 'style/newmail.png';
		} else {
			document.getElementById("mail_image").src = 'style/mail.png';
		}
		document.getElementById("mail_image").title = xmlHttp.responseText + ' nya meddelanden';
		
	}
}

function updateFriends() { 
	if (xmlHttp2.readyState==4) { 
		if ( xmlHttp2.responseText > 0 ) {
			document.getElementById("friends_image").src = 'style/newfriends.png';
		} else {
			document.getElementById("friends_image").src = 'style/friends.png';
		}
		document.getElementById("friends_image").title = xmlHttp2.responseText+' obesvarade vänner';
	}
}

function updateWatched() { 
	if (xmlHttp3.readyState==4) { 
		var message = '';
		if ( xmlHttp3.responseText > 0 ) {
			document.getElementById("watched_image").src = 'images/eye_open.png';
			message = 'Nya bevakade inlägg!';
		} else {
			document.getElementById("watched_image").src = 'images/eye_closed.png';
			message = 'Inga nya bevakade inlägg';
		}
		document.getElementById("watched_image").title = message;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}