function toggle_led()
{
var req = false;
var led = false;
function ledComplete()
{
if(led.readyState == 4)
{
if(led.status == 200)
{
document.getElementById("ledstate").innerHTML = "<div>" + led.responseText + "</div>";
}
}
}
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
led = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
led = new ActiveXObject("Microsoft.XMLHTTP");
}
if(req)
{
req.open("GET", "/cgi-bin/toggle_led?id" + Math.random(), true);
req.send(null);
}
if(led)
{
led.open("GET", "/ledstate?id=" + Math.random(), true);
led.onreadystatechange = ledComplete;
led.send(null);
}
}