// Highwire JS 

// Util function to init HTTPRequest object
function initHTTPRequest() {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
		return new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
		return new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
			return new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        return false;
        }
      }
    }
  }

// Util function to handle making the call
function doAJAX(url,target_id) {
	var xmlHttp;
	
	xmlHttp = initHTTPRequest();
	
	// Bail if it didn't work.
	if (xmlHttp === false) { return false }
	
	xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) {
		// Slap the result into the target div
		document.getElementById(target_id).innerHTML =  xmlHttp.responseText;
		}
    }

	// Execute the call
	xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
	
}
   
  
// Function used on browse pages to execute search when clicking menu items
function doSearch(thesid,coll_id,term,display_term) {
	var cgi_name;
	var url;
	var target_id;
	
	// This is so the browse search knows what url to return to
	cgi_name = coll_id == 'CORR' ? 'recipient' : 'subject';

	// The search url.  What a mouthful. 
	url =  'http://carlyleletters.dukejournals.org/cgi/browsesearch?' +
			'thesid=' 				+ thesid 		+  '&' +
			'browse_coll=' 			+ escape(coll_id) 		+  '&' +
			'browse_term=' 			+ escape(term)    		+  '&' +
			'browse_display_term='  + escape(display_term) 	+  '&' +
			'browse_cgi='			+ escape(cgi_name)		+  '&' +
			'include_narrower_terms=1';				

		target_id = 'colD_c2';
	
	// Execute search!
	doAJAX(url,target_id);
}