document.write('<li>Quick Search');
document.write('<table border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="body"><tr><td>'
  +'<form id="myform" name="myform" action="javascript:OnSubmitForm();" method="POST" style="margin-bottom:0;">'
	+'<select name="menu1" onChange="selectMainSearch()" style="width:200px">'
	  +'<option selected>MCL</option>'
	  +'<option>Pius</option>'
	  +'<option>Law</option>'
	  +'<option>All SLU Libraries</option>'
	  +'<option>MOBIUS</option>'
	+'</select><br>'
	+'<select id="merlin" name="merlin" onChange="searchType()" style="width:200px;">'
	  +'<option value="t" selected>Title</option>'
	  +'<option value="a">Author</option>'
	  +'<option value="s">Journal</option>'
	  +'<option value="Y">Keyword</option>'
	  +'<option value="d">Subject</option>'
	  +'<option value="l">Call #</option>'
	+'</select>'
	+'<select id="mobius" name="searchtype" style="width:200px; display:none; visibility:hidden;">'
	  +'<option value="Y">Keyword</option>'
	  +'<option value="t">Title</option>'
	  +'<option value="a">Author</option>'
	  +'<option value="s">Journal Title</option>'
	  +'<option value="d">LC Subject</option>'
	  +'<option value="m">Medical Subject (MESH)</option>'
	+'</select>'
/*	+'<select id="libLoc" name="libLoc" style="width:80px;">'
	  +'<option value="S1" selected>HSC</option>'
	  +'<option value="S5">SLU</option>'
	  +'<option value="">MERLIN</option>'
	+'</select><br>'
*/
	+'<br>'
	+'<input id="SEARCH" name="SEARCH" type="text" onFocus="this.value=\'\'" value=" enter search term here" style="width:175px">'
	+'&nbsp;<input ID="SUBMIT" name="SUBMIT" type="image" value="go" src="../images/go.png" style="vertical-align:text-bottom;"><br>'
  +'</form>'
+'</td></tr></table>');
document.write('</li>');

selectMainSearch();

// Changes name, value, and action of input and submit objects corresponding to the user's selection
// Also calls hide() and show() functions
function selectMainSearch(){
  var index = document.myform.menu1.selectedIndex;
  var idAry1 = new Array("mobius", "merlin");
  document.getElementById('myform').target="";

  for(i=0; i < idAry1.length; i++){
	document.getElementById(idAry1[i]).style.display='none';
	document.getElementById(idAry1[i]).style.visibility="hidden"; 
  }
  
  if(index==4){
	document.getElementById('mobius').style.display='';
	document.getElementById('mobius').style.visibility="visible"; 
	document.getElementById('SEARCH').name="searcharg";
	document.getElementById('SUBMIT').name="cmdSubmit";
	document.getElementById('SUBMIT').value="Search";
	document.getElementById('myform').action="javascript:OnSubmitFormMobius()";
  }
  else{
	document.getElementById('merlin').style.display='';
	document.getElementById('merlin').style.visibility="visible";
	document.getElementById('SEARCH').name="user";
	if(index==0)
	  document.getElementById('myform').action="javascript:OnSubmitForm(0)";
	else if(index==1) 
	  document.getElementById('myform').action="javascript:OnSubmitForm(1)";
	else if (index==2)
	  document.getElementById('myform').action="javascript:OnSubmitForm(2)"; 
	else 
	  document.getElementById('myform').action="javascript:OnSubmitForm(3)";   
  }
}

// CODE FOR SEARCHING MERLIN
var searchscope, lib, srch, str, type, needSrch;

function searchType(){
  type = document.myform.merlin.value;
  if(type=="a")
	srchVal = " last, first";
  else if(type=="l")
	srchVal = " ex: RA 1151";
  else
	srchVal = " enter search term here";

  document.getElementById('SEARCH').value = srchVal;
}

function OnSubmitForm(index)
{
  //gets the library abbrev for correct library (S1 for HSC, '' for All Merlin)
  if(index==0)
    lib = "S1";
  else if(index==1)
    lib = "S3";
  else if(index==2)
    lib = "S2";
  else
    lib = "S5";

  searchscope="";											//needed for keyword searches
  srch = document.getElementById('SEARCH').value;			//gets the search value
  type = document.getElementById('merlin').value;			//gets the type of search (ie: title)
  needSrch = 0;												//used if no search term is entered
	
  if(srch.slice(0,1) == " " || srch == ""){
	document.myform.SEARCH.value = " type search term(s)";
	needSrch = 1;
  }

  if(type=="Y"){
	//slices the S off the value of 'lib' unless its an All Merlin search
	if(lib.length > 1)
	  lib2 = lib.slice(1);		

	searchscope="&searchscope="+lib2+"&b=&l=&s=&m=&c=&i=&o=&p=&g=&Da=&Db=&SORT=R";
  }
  for(i=0; i<srch.length; i++)						//replaces spaces with plus signs
  {
    srch = srch.replace(" ", "+");
  }
  if(needSrch == 0){
	//window.open("http://libcat.slu.edu","searchResults", "left=0, top=0, toolbar, menubar, scrollbars, location, status, resizable");
	wait(100);
  }
}
function wait(delay){
	string="pauseforalert("+delay+");";
	setTimeout(string,delay);
}
function pauseforalert(delay){
 window.open("http://libcat.slu.edu/search~"+lib+"/"+type+"?SEARCH="+srch+searchscope,"searchResults");
}

//Code for searching MOBIUS doesnt require as much as the code for searching Merlin
function OnSubmitFormMobius(){
  type = document.getElementById('mobius').value;
  term = document.getElementById('SEARCH').value;
  for(i=0; i<term.length; i++)
    term = term.replace(" ", "+");					//replaces spaces with plus signs
  window.open("http://mobius.missouri.edu/search/Y?searchtype="+type+"&searcharg="+term+"&SORT=D","searchResults", "left=0, top=0, toolbar, menubar, scrollbars, location, status, resizable");
}