﻿var chatTimer;
function checkXMLHTTP() 
{
var	obj = null;
	if (window.XMLHttpRequest) 
	{
		obj = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		obj = new ActiveXObject("Microsoft.XMLHTTP")
		if (!obj) 
		{
			try 
			{
				obj = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch(e) 
			{
				try 
				{
					obj = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch(e) 
				{
					obj = null;
				}
			}
		}
    }
	return obj;
}
function requestChat()
{
    try
    {
        
        LiveHelpXMLHTTP = checkXMLHTTP();
            if (LiveHelpXMLHTTP)
	         {		
		        if (LiveHelpXMLHTTP.readyState != 0)
		         {
			        LiveHelpXMLHTTP.abort();
		         }
		        // alert(msg);
		        var URL = 'getChat.aspx';
		        var params="action=NewChat";
		        LiveHelpXMLHTTP.open('post',URL);		 
		        LiveHelpXMLHTTP.onreadystatechange = getChat;
		        LiveHelpXMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		        LiveHelpXMLHTTP.send(params);
	        }       
        
    }
    catch(err)
    {
    }
}
function getChat()
{ 
    //alert(LiveHelpXMLHTTP.readyState);
    if (LiveHelpXMLHTTP.readyState == 4)
	  {	
	    //alert(LiveHelpXMLHTTP.status);		 
        if (LiveHelpXMLHTTP.status == 200)
	    {	    
           try
           {
         //alert(LiveHelpXMLHTTP.responseText);
        // document.getElementById(
                if(LiveHelpXMLHTTP.responseText!="0")
                {
                   eval(LiveHelpXMLHTTP.responseText);
                }
                
           //var msgDiv=document.getElementById('divMsg');
           //msgDiv.scrollLeft=0;
           //msgDiv.scrollTop= msgDiv.scrollHeight + msgDiv.scrollHeight;
           }
           catch(err)
           {
                alert(err);
           }           
        }
	  }  
      chatTimer = window.setTimeout('requestChat();', 5000);
}
