var xmlHttp;
function createXMLHttpRequest() {
   if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlHttp=new XMLHttpRequest();
  }
   else
  {// code for IE6, IE5
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}  


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

checkCookie()

function bubbles() {
    document.body.style.backgroundImage = "url('../../../../wakin_checker/bubbles.gif')";
}

function checkCookie()
{
  LastID=getCookie("LastID")
	  if (LastID != "") {
		  timedCount()
	  }
}


function timedCount()
 {
	 // var ThisUrl =  location.pathname;
	 
	 // if(ThisUrl == "/wall" || ThisUrl == "/wall/") {
	  setTimeout("CheckWakin()",5000)
     // }
 }
 
 function CheckWakin()
{	  
    LastID=getCookie("LastID")
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = ReportCheck;
    xmlHttp.open("GET", "../../../../wakin_checker/checking.php?max_id="+LastID, true);
    xmlHttp.send(null);  
}

function ReportCheck()
{
    if(xmlHttp.readyState == 4) {
		
        if(xmlHttp.status == 200) { 
		
		var ReportNew = xmlHttp.responseText; 
				         
         if(ReportNew != "0") {
			 
			     AnnounceNEW()
				 document.cookie = "LastID="+ReportNew;
				 
		   } else {
			   
			   timedCount()

		   }
        }
    }
}

function AnnounceNEW() {
	bubbles()
}

