// put global variable to prevent simultaneous requests

function toggleMonitor(id)
{
    var xmlHttp;
    
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp= new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
        	parts = xmlHttp.responseText.split('|');
        	resp = parts[0];
        	count = parts[1];
        	if (resp == 'on' || resp == 'off')
        	{
				document.getElementById('wbi_'+id).src='/img/monitor-'+resp+'.jpg';
			}
			if (count != '')
			{
				document.getElementById("w_count").innerText = count;
			}
        }
    }

	nc = Math.random();
    xmlHttp.open("GET", "/toggle-watch.php?id=" + id + '&nc=' + nc, true);
    xmlHttp.send(null);
    
    return false;
}

function toggleSend(option)
{
    var xmlHttp;
    
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp= new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
        	resp = xmlHttp.responseText.split('|');
        	if (resp == 'on' || resp == 'off')
        	{
				document.getElementById('wbi_'+option).src='/img/monitor-'+resp+'.jpg';
			}
        }
    }
    
    nc = Math.random();
    xmlHttp.open("GET", "/toggle-send.php?option=" + option + '&nc=' + nc, true);
    xmlHttp.send(null);
    
    return false;
}