//code for ajax based bible search
//handles drop down search as well as keyword search.
function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function dochange(src, val) {
     var req = Inint_AJAX();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById(src).innerHTML=req.responseText; //return value
               } 
          }
     };
     req.open("GET", "populate-dd.php?data="+src+"&val="+val); //make connection
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req.send(null); //send value
}

window.onLoad=dochange('bibles', -1);         // value in first dropdown used only when page loads (one time)

function getchaptertext(in1, in2, in3) {
     var req2 = Inint_AJAX(); 	//req2 is just another var as we are creating different xmlHttp request
     req2.onreadystatechange = function () { 
	 if(req2.readyState == 1){
// 	 	document.getElementById("divBibleChapter").innerHTML = '<div id="bibleBook"><img src="images/indicator.gif" height="48" width="48" /></div>'; 
 	 	document.getElementById("divBibleChapter").innerHTML = '<div id="bibleBook"><img src="images/indicator.gif" /></div>'; 
		}
        if (req2.readyState==4) {
               if (req2.status==200) {
                      var targetNode = document.getElementById("divBibleChapter");   //This id can be anything as long as it matches with one below. 
                      targetNode.innerHTML = req2.responseText ;
               } 
          }
     };
//	 alert ('You are in getchaptertext with var : ' + in1 + '   ' + in2 + '   ' + in3); 
     req2.open("GET", "getchapter.php?bible="+in1+"&book="+in2+"&chapter="+in3, true); //make connection //true=asynchronous. does not seem to matter. 
     req2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req2.send(null); //send value
}

function getkeywordtext(inputkeywords) {
	//function variable cannot have "_" in it for some reason. e.g. input_keyword did nt work in the open request below. 
     var req3 = Inint_AJAX(); 	//req3 is just another var as we are creating different xmlHttp request
     req3.onreadystatechange = function () { 
	 if(req3.readyState == 1){
 	 	document.getElementById("divBibleChapter").innerHTML = '<div id="bibleBook"><img src="images/indicator.gif" /></div>'; 
		}
        if (req3.readyState==4) {
               if (req3.status==200) {
                      var targetNode = document.getElementById("divBibleChapter");   //This id can be anything as long as it matches with one below. 
                      targetNode.innerHTML = req3.responseText ;
               } 
          }
     };
     req3.open("GET", "keywords-search.php?keywords="+inputkeywords, true); //make connection //true=asynchronous. does not seem to matter. 
     req3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req3.send(null); //send value
}

//function to get first, previous, next, last pages. Same as earlier function. 
function getkeywordpages(inputkeywords, pagenum) {
	//function variable cannot have "_" in it for some reason. e.g. input_keyword did nt work in the open request below. 
     var req4 = Inint_AJAX(); 	//req3 is just another var as we are creating different xmlHttp request
     req4.onreadystatechange = function () { 
	 if(req4.readyState == 1){
 	 	document.getElementById("divBibleChapter").innerHTML = '<div id="bibleBook"><img src="images/indicator.gif" /></div>'; 
		}
        if (req4.readyState==4) {
               if (req4.status==200) {
                      var targetNode = document.getElementById("divBibleChapter");   //This id can be anything as long as it matches with one below. 
                      targetNode.innerHTML = req4.responseText ;
               } 
          }
     };
     req4.open("GET", "keywords-search.php?keywords="+inputkeywords+"&pagenum="+pagenum, true); //make connection //true=asynchronous. does not seem to matter. 
     req4.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req4.send(null); //send value
}
