﻿var xmlHttpMain;
function createXMLHttpRequest()
{
    if (window.ActiveXObject)
    {
        xmlHttpMain = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {
        xmlHttpMain = new XMLHttpRequest();
    }
    else if (Msxml2.ActiveXObject)
    {
        xmlHttpMain = new ActiveXObject("Msxml2.XMLHTTP");
    }
}
function StartClew() 
{
    createXMLHttpRequest();
    ClewPollServer();
    setInterval("ClewPollServer()", 6000);
}

function ClewCallback() 
{

    if (xmlHttpMain.readyState == 4) 
    {
        if (xmlHttpMain.status == 200) 
        {
            Apply();
        }
    }
}

function ClewPollServer() 
{
    var url = "/userManage/newMessage.aspx?timeSpan=" + new Date().getTime();
    xmlHttpMain.open("GET", url, true);
    xmlHttpMain.onreadystatechange = ClewCallback;
    xmlHttpMain.send(null);
}

function Apply()
{
    var liclew = document.getElementById("liclew");
    if (xmlHttpMain.responseText == "true") 
    {
        liclew.style.background = "url(/usermanage/images/message1.gif) no-repeat center 50%"
        liclew.innerHTML = "<embed src='/images/NewMessage.wav' width='0' height='0' id='music' autostart='true'></embed>";
    }
    else 
    {
        liclew.style.background = "url(/usermanage/images/message2.gif) no-repeat center 50%";
        liclew.innerHTML = "";
    }
}

