var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function loadFragmentInToElement(fragment_url, element_id) { 

    var element = document.getElementById(element_id);


    if(element == null || document.forms[0] == null || document.forms[0].Search_Arg == null || document.forms[0].Search_Arg.value == "" || document.forms[0].Search_Code.value == "CALL")
	{
	//If there no "spellcheck" div on the page quit.
	//OR If for some reason the querybox form (number0) doesn't exist, quit.
	//OR If there is no search term -> quit
	return;
    	}

    //Change this to match your catalogue url
  var searchBaseUrl = '/cgi-bin/Pwebrecon.cgi?';
    var searchCode = document.forms[0].Search_Code.value;
    var pid = document.forms[0].PID.value;
    var seq = document.forms[0].SEQ.value;
    var cnt = document.forms[0].CNT.value;
    var urlSuffix = '&HIST=1';
    // element.innerHTML = 'Loading ...'; 
    xmlhttp.open("GET", fragment_url); 
    xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 

	if(xmlhttp.responseText == "-spellingcorrect-")
	{
	//The query was spelt correctly so skip so return
	return;
        }
	var htmlString = 'Did you mean: <a href="';
	htmlString = htmlString + searchBaseUrl + 'Search_Arg=' + xmlhttp.responseText + '&Search_Code=' + searchCode;

	if(document.forms[0].SL && document.forms[0].SL.value != "" && document.forms[0].SL.value != "none")
	{
	htmlString = htmlString + '&SL=' + document.forms[0].SL.value;
	}

	htmlString = htmlString + '&PID=' + pid + '&SEQ=' +seq + '&CNT=' + cnt + urlSuffix; 
	htmlString = htmlString + '">' + xmlhttp.responseText + '</a>';

      element.innerHTML = htmlString;
      } 
    } 
    xmlhttp.send(null); 
} 
