

var NS = (document.layers) ? true : false; 
var IE = (document.all) ? true : false; 
var DOM = (document.getElementById) ? true : false; 
if (IE) DOM = false; 
var MAC = (navigator.platform) && (navigator.platform.toUpperCase().indexOf("MAC") >= 0); 
if (NS) MAC = false; 

var commandImage; 
var sendImage = true;
var checkImgTimer = null;

// Call this function when ever you want to check if chat is available or not
function checkChatAvailability(strChatAvailabilityURL)
{
	 //window.status += " +";
	 if ( sendImage )
	 { 
 		 sendRequest(strChatAvailabilityURL);
 		 checkImgTimer = setInterval("checkImage()", 1000);
	 }
}

function sendRequest(strChatAvailabilityURL) 
{ 

	 if (DOM && IE) { 
	 		 document.body.removeChild(commandImage); 
	 		 commandImage = document.createElement('IMG'); 
	 		 commandImage.style.visibility = "hidden"; 
	 		 document.body.appendChild(commandImage); 
	 } 
	else if (!MAC) {
	 		 commandImage= new Image; 
	 }
	 var pageID = Math.round(Math.random()*9999999999); 
	 //var url = "https://collaborateextst.verizon.com/aims/encore/ChatAvailabilityStatus.serv?appid=8" + "&id=" + pageID;
	 var url = strChatAvailabilityURL + "&id=" + pageID;
	 
	 commandImage.src = url;  

	 sendImage = false; 
}

function checkImage() 
{ 
	if (!sendImage) 
	{
 		 if (!commandImage.complete)
		{ 
 		 	 return; 
 		 } 
 		 var w = commandImage.width; 
 		 var h = commandImage.height; 
 		 sendImage = true;
		 if( checkImgTimer!=null )
		{
		 	 clearInterval( checkImgTimer );
		 	 checkImgTimer = null;
		 }
 		 checkChatAvailabilityResult(w,h); 
 	 } 
}

function checkChatAvailabilityResult( w, h )
{
	if( w=="1" && h=="1" )
	{	
		// Chat Available
		//alert("Chat Available...");
try{		
document.getElementById('ChatAvailable').style.display = "block";
		document.getElementById('ChatUnavailable').style.display = "none";
}
catch(e){}
	}
	else
	{		
	 	// Chat not available
		//alert("Chat not Available...");
try{	
	document.getElementById('ChatAvailable').style.display = "none";
		document.getElementById('ChatUnavailable').style.display = "block";

}
catch(e){}
	}
try{
	checkChat();
}
catch(e){}
}



