// Search box function for tan/red pages
//<!--
//5/2/06 this function checks for the value of the pressed key to find enter 
function checkEnter(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.searchForm.sa.focus();
document.searchForm.sa.click();	 //submit the form
}
}
// 5/2/06 startsearch function determines the correct action for each option
// Based on a script by Jari Aarniala [www.mbnet.fi/~foo -- foo@mbnet.fi]
// Hacked by Web Services :)
// Uses a seemingly-clumsy workaround for Innopac search. 
// Innopac won't be satisfied with anything more elegant.

function startSearch(){
	// This string loads a Google results page customised with the Libraries' header (requires /Custom switch)
	var customResults = '&sa=Google+Search&cof=S:http://libinfo.uark.edu;GL:0;AH:center;LH:100;L:http://libinfo.uark.edu/libimages/tanred/tanredfacadelettersonly.gif;LW:666;AWFID:221b7f17c0f1f558%3B&domains=libinfo.uark.edu;"'
	
	// old string S%3Ahttp%3A%2F%2Flibinfo.uark.edu%3BGL%3A0%3BAH%3Aleft%3BLH%3A72%3BL%3Ahttp%3A%2F%2Flibinfo.uark.edu%2FLibimages%2Fblueimages%2Fmullinstitleblocksmall.gif%3BLW%3A473%3BAWFID%3A221b7f17c0f1f558%3B&domains=libinfo.uark.edu';//
	searchString = ""
	searchString = document.searchForm.searchText.value; 
	if(searchString != ""){
		searchEngine = document.searchForm.whichEngine.selectedIndex + 1;
		finalSearchString = "";
	
	if(searchEngine == 1){	//case of parameters is specified by Innopac
		document.searchForm.method = "post";
		document.searchForm.action = "http://library.uark.edu/search/~";
		document.searchForm.searchtype.value = "X";
		document.searchForm.searcharg.value = document.searchForm.searchText.value;  //Innopac will not accept parameter from dropdown even if it is renamed dynamically :(
		document.searchForm.searchText.value= "";  //but Innopac WILL read this later and duplicate the searchstring grrr.....
		document.searchForm.SORT.value = "D";
		document.searchForm.whichEngine.name = "";
		document.searchForm.submit();
	}
	
	else 
		{
		if(searchEngine == 2){
		finalSearchString = "http://libinfo.uark.edu/eresources/search.asp?searchstring=" + searchString;
		}
		if(searchEngine == 3){
		finalSearchString = "http://www.google.com/custom?q=" + searchString + customResults + "&sitesearch=libinfo.uark.edu";
		}
		if(searchEngine == 4){
		finalSearchString = "http://www.google.com/custom?q=" + searchString + customResults + "&sitesearch=uark.edu";
		}
		if(searchEngine == 5){
		finalSearchString = "http://www.google.com/custom?sa=Google%20Search&q=" + searchString + customResults + "&sitesearch=";
		}
		
		location.href = finalSearchString;
		}
	}
}

//5/1/06 ignore everything after this line; failed attempts to make Enter key work - BJ 

function addElement(controlname) {
  var ni = document.getElementById('searchForm');
  //var numi = document.getElementById('theValue');
  //var num = (document.getElementById('theValue').value -1)+ 2;
  //numi.value = num;
  var newcontrol = document.createElement('controlname');
  var newcontrolIDName = 'controlname';
  newcontrol.setAttribute('id',newcontrolIDName);
  //newdiv.innerHTML = 'Element Number '+num+' has been added! <a href='#' onclick='removeElement('+divIdName+')'>Remove the div "'+divIdName+'"</a>';
  ni.appendChild(newcontrol);
}


function removeElement(controlName) {
  //var d = document.getElementById('searchForm');
  //var doomed = document.getElementById(controlName);
  //d.removeChild(doomed);
  var el = document.getElementById('controlname');
	el.parentNode.removeChild(el);
}



function startSearch2(){//this one works
	// This string loads a Google results page customised with the Libraries' header (requires /Custom switch)
	var customResults = 'S%3Ahttp%3A%2F%2Flibinfo.uark.edu%3BGL%3A0%3BAH%3Aleft%3BLH%3A72%3BL%3Ahttp%3A%2F%2Flibinfo.uark.edu%2FLibimages%2Fblueimages%2Fmullinstitleblocksmall.gif%3BLW%3A473%3BAWFID%3A221b7f17c0f1f558%3B';
	var searchString = document.searchForm.searchText.value;
	
	if(searchString != ""){
		var searchEngine = document.searchForm.whichEngine.selectedIndex + 1;
		var finalSearchString = "";
	
	if(searchEngine == 1){	//case of parameters is specified by Innopac
		document.searchForm.method = "post";
		document.searchForm.action = "http://library.uark.edu/search/~";
		addElement("searchtype");
		document.searchForm.searchtype.value = "X";
		addElement("searcharg");
		document.searchForm.searcharg.value = document.searchForm.searchText.value;  //Innopac will not accept parameter from dropdown even if it is renamed dynamically :(
		document.searchForm.searchText.value= "";  //but Innopac WILL read this later and duplicate the searchstring grrr.....
		addElement("SORT");
		document.searchForm.SORT.value = "D";
		document.searchForm.whichEngine.name = "";
		document.searchForm.submit();
	}
	
	else 
		{
		
		
		if(searchEngine == 2){//this one works
		//finalSearchString = "http://libinfo.uark.edu/eresources/search.asp?searchstring=" + searchString;
		document.searchForm.action = "http://libinfo.uark.edu/eresources/search.asp?searchstring=" + searchString;
		document.searchForm.method = "post";
		document.searchForm.submit();
		}
		
		//============================================================================
		//
		if(searchEngine == 3){

		document.searchForm.whichEngine.value = "GOTCHA!";
		var el = document.getElementById('whichEngine');
		el.parentNode.removeChild(el);
		el = "";
		el = document.getElementById('SORT');
		el.parentNode.removeChild(el);
		el = "";		
		el = document.getElementById('searchtype');
		el.parentNode.removeChild(el);
		el = "";
		el = document.getElementById('searcharg');
		el.parentNode.removeChild(el);
		//var finalSearchString = "http://www.google.com/custom?q=" + searchString + customResults + "&sitesearch=libinfo.uark.edu";	
		document.searchForm.action = "http://www.google.com/custom"; 
		//document.searchForm.action = finalSearchString;
		document.searchForm.method = "get";
		document.searchForm.searchText.name = "q";
		//document.searchForm.SORT.name = "cof";
		addElement(cof);
		addElement(domains);
		addElement(sitesearch);
		//document.searchForm.searchtype.name = "domains";
		//document.searchForm.searcharg.name = "sitesearch";
		
		document.searchForm.cof.value = "S%3Ahttp%3A%2F%2Flibinfo.uark.edu%3BGL%3A0%3BAH%3Aleft%3BLH%3A72%3BL%3Ahttp%3A%2F%2Flibinfo.uark.edu%2FLibimages%2Fblueimages%2Fmullinstitleblocksmall.gif%3BLW%3A473%3BAWFID%3A221b7f17c0f1f558%3B";
		document.searchForm.domains.value = "libinfo.uark.edu";
		document.searchForm.sitesearch.value = "libinfo.uark.edu";
		document.searchForm.sa.value = "Google Search";
		document.searchForm.submit();
		}

//=======================================		
		
		if(searchEngine == 4){
		finalSearchString = "http://www.google.com/custom?q=" + searchString + customResults + "&sitesearch=uark.edu";
		}
		if(searchEngine == 5){
		finalSearchString = "http://www.google.com/custom?sa=Google%20Search&q=" + searchString + customResults + "&sitesearch=";
		}
		
		//location.href = finalSearchString;
		}
	}
}
//-->