// Get an XMLHttpRequest object in a portable way.
function newRequest()
{
  req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    } 
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
}

function getWatch(key)
{
 var url;
 url="/notify/exist/?" + key 
 newRequest();
 req.open("GET",url,false);
 req.send("");
 if (req.readyState == 4 && req.status == 200) { 
	var wdiv = document.getElementById(chkboxDIV);
	wdiv.style.display = ""; // display notification option because module is activated
	var ajaxresp = document.getElementById('ajaxresp');
	ajaxresp.innerHTML=req.responseText
 	var respdiv = document.getElementById('EXISTS');
	var exists = respdiv.innerHTML
	if (exists == '1') {
		var wcb = document.getElementById(chkboxID);
		wcb.checked=true;
	}
 }
}

function setWatch(key)
{
 var wcb = document.getElementById(chkboxID);
 wcb.disabled=true;  // because window.open is async, we can get multiple clicks. so let popup form re-enable
 if (wcb.checked) {
	url='/notify/add/' + urltemplate + '?' + key;
	popup(url);
 } else {
	// they are un-checking, so delete watch
	url='/notify/delete/' + urltemplate + '?' + key;
	popup(url);
 }

}

function popup(url)
{
 leftVal = (600 - screen.width) / 2;
 topVal = (300 - screen.height) / 2;
 myRef = window.open(url,'_blank','left='+leftVal+',top='+topVal+',width=600,height=300,toolbar=0,resizable=0,menubar=0,location=0');
}
