// JavaScript Document for the SLU Catalog Search
var searchscope, lib, srch, str, type, needSrch;

function searchType(){
  index = document.myform.menu1.value;
  srchVal = " search the catalog";
  if(index  == "a"){
	  	srchVal = "last, first";
  }
  if(index  == "c"){
	srchVal = " ex: RA 1151";
  }
  document.myform.SEARCH.value = srchVal;
}

function OnSubmitForm(){
  searchscope="";											//needed for keyword searches
  lib  = document.myform.menu2.value;
  srch = document.myform.SEARCH.value;						//gets the search criteria
  str  = srch.replace(" ", "+");								//replaces spaces with plus signs
  type = document.myform.menu1.value;
  needSrch = 0;												//used if no search term is entered
  if(srch == " search the catalog" || srch == " last, first" || srch == " ex: RA 1151" || srch == " type search term(s)" || srch == "")
  {
	document.myform.SEARCH.value = " type search term(s)";
	needSrch = 1;
  }

  if(type=="Y")	//keyword search
  {
	lib2 = lib.slice(1);	//slices the S off the value of 'lib'
	searchscope="&SORT=D&searchscope="+lib2+"&Submit=Search";
  }

  for(i=0; i<srch.length; i++)
  {
    str = str.replace(" ", "+");
  }

  if(needSrch == 0){
	window.open("http://libcat.slu.edu/search~"+lib+"/"+type+"?SEARCH="+str+searchscope,"searchResults", "left=0, top=0, toolbar, menubar, scrollbars, location, status, resizable");
  }
}
