var divname;
var ayaatn=-1;

function getayaat(newdiv,chap,book,hadith,tbl,hadithbook) {
  divname = newdiv;
  var url = "http://www.unitedinislam.com/islamictext/ajaxfindhadith.asp?keyword="+chap+":"+book+":"+hadith+"&divtag="+newdiv+":"+tbl+"&hadithbook="+hadithbook;
  var callback = processAjaxResponse;
  executeXhr(callback, url);
}
function executeXhr(callback, url) {
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = callback;
    req.open("GET", url, true);
    req.send(null);
  } // branch for IE/Windows ActiveX version
  else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = callback;
      req.open("GET", url, true);
      req.send();
    }
  }
}
function processAjaxResponse() {
  // only if req shows "loaded"
  if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200) {
      document.getElementById(divname).innerHTML = req.responseText;
    } else {
      alert("There was a problem retrieving the XML data:\n" +
      req.statusText);
    }
  }
}
