function submitRequest(u,m)
{
  if (window.ActiveXObject) {
    try {
	xhr=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
	try {
	  xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (E) {
	  xhr=new ActiveXObject("Microsoft.XMLDOM");
	}
    }
  }
  else {
    xhr=new XMLHttpRequest();
  }
  if (m != null)
    xhr.onreadystatechange=m;
  xhr.open("GET",u);
  xhr.send("");
}
var id,wait_id;
function getContent(i,u,w) {
  id=i;
  if (w == undefined)
    wait_id=null;
  else
    wait_id=w;
  document.body.style.cursor='wait';
  if (wait_id != null && document.getElementById(wait_id)) {
    d=document.getElementById(wait_id);
    if (typeof(window.innerWidth) == 'number') {
	d.style.top=document.body.scrollTop+window.innerHeight/3+"px";
	d.style.left=document.body.scrollLeft+(window.innerWidth-parseInt(d.style.width))/2+"px";
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
	d.style.top=document.body.scrollTop+document.documentElement.clientHeight/3+"px";
	d.style.left=document.body.scrollLeft+(document.documentElement.clientWidth-parseInt(d.style.width))/2+"px";
    }
    else {
	d.style.top=document.body.scrollTop+document.body.clientHeight/3+"px";
	d.style.left=document.body.scrollLeft+(document.body.clientWidth-parseInt(d.style.width))/2+"px";
    }
    d.style.visibility="visible";
  }
  submitRequest(u,showContent);
}
function showContent() {
  if (xhr.readyState == 4) {
    document.getElementById(id).innerHTML=xhr.responseText;
    if (typeof(xhr2) == "undefined" || xhr2.readyState == 4)
	document.body.style.cursor='';
    if (wait_id != null && document.getElementById(wait_id))
	document.getElementById(wait_id).style.visibility="hidden";
  }
}
var id2;
function getBrowseContent(i,u,i2,u2)
{
  document.body.style.cursor='wait';
  getContent(i,u);
  id2=i2;
  if (window.ActiveXObject) {
    try {
	xhr2=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
	xhr2=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else {
    xhr2=new XMLHttpRequest();
  }
  xhr2.onreadystatechange=showBrowseContent;
  xhr2.open("GET",u2);
  xhr2.send("");
//  document.title=i;
}
function showBrowseContent() {
  if (xhr2.readyState == 4) {
//    document.body.scrollTop=0;
    setTimeout('document.getElementById(id2).innerHTML=xhr2.responseText',100);
    if (typeof(xhr) == "undefined" || xhr.readyState == 4)
	document.body.style.cursor='';
  }
}
var boxids=new Array(-1,-1);
var next=0;
var key="";
function initializeCompareBoxes() {
  for (n=0; n < document.compare.elements.length; n++)
    document.compare.elements[n].checked=false;
}
function checkBrowseBox(o) {
  if (document.compare.thisKey != key) {
    boxids[0]=boxids[1]=-1;
    next=0;
  }
  key=document.compare.thisKey;
  for (n=0; n < document.compare.elements.length; n++) {
    if (document.compare.elements[n] == o) {
	if (o.checked) {
	  if (boxids[next] >= 0)
	    document.compare.elements[boxids[next]].checked=false;
	  boxids[next]=n;
	  next=1-next;
	}
	else {
	  if (boxids[0] == n)
	    boxids[0]=-1;
	  else
	    boxids[1]=-1;
	}
	break;
    }
  }
}
function checkBrowseCompare(b,s,n,t) {
  if (boxids[0] < 0 || boxids[1] < 0)
    alert("Choose two datasets to compare");
  else {
    b.disabled=true;
    document.title='Comparing Datasets';
    window.location='/cgi-bin/rdabrowse?compare='+document.compare.elements[boxids[0]].value+'&compare='+document.compare.elements[boxids[1]].value+'&start='+document.compare.start.value+'&npp='+document.compare.npp.value;
  }
}
function seenBulletins(i,u) {
  id=i;
  document.body.style.cursor='wait';
  submitRequest(u,hideBulletins);
}
function hideBulletins() {
  if (xhr.readyState == 4) {
//    document.body.scrollTop=0;
    document.getElementById(id).innerHTML=xhr.responseText;
    if (typeof(xhr2) == "undefined" || xhr2.readyState == 4)
      document.body.style.cursor='';
    window.location.reload();
  }
}
