// JavaScript Document for the SLU Catalog Search

var searchscope, lib, srch, str, type, needSrch;

function clearform2(findBook){

  if (findBook.value==" search the catalog" || findBook.value==" last, first" || findBook.value==" ex: RA 1151" || findBook.value==" type search term(s)")

  findBook.value="";

}

function searchType(){

  index = document.myform.menu1.selectedIndex;

  if(index  == 0 || (index > 1 && index < 5)){

	srchVal = " search the catalog";

  }

  if(index  == 1){

	srchVal = " last, first";

  }

  if(index  == 5){

	srchVal = " ex: RA 1151";

  }

  document.myform.SEARCH.value = srchVal;

}



function library(index)		//finds what library to search (SLU, Pius, MCL, Law)

{

  var library;

  switch(index)

  {

    case 0:

	  library = "S3";

	  break

	case 1:

	  library = "S1";

	  break

	case 2:

	  library = "S2";

	  break

	case 3:

	  library = "S5";

	  break

  }

  return library;

}

function OnSubmitForm()

{

  searchscope="";											//needed for keyword searches

  lib = library(document.myform.menu2.selectedIndex);		//gets the library abbrev for correct library (ie: S3 for pius)

  srch = document.myform.SEARCH.value;						//gets the search criteria

  str = srch.replace(" ", "+");								//replaces spaces with plus signs

  type = document.myform.menu1.selectedIndex;				//gets the type of search (ie: title)

  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==0) type="t";

  if(type==1) type="a";

  if(type==2) type="s";

  if(type==4) type="d";

  if(type==5) type="c";

  if(type==3)	//keyword search

  {

	type="Y";

	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","searchResults", "left=0, top=0, toolbar, menubar, scrollbars, location, status, resizable");

	wait(300);

  }

}

function wait(delay){

	string="pauseforalert("+delay+");";

	setTimeout(string,delay);

}

function pauseforalert(delay)

{

	//alert("Ok "+delay/1000+" seconds have elapsed");

	window.open("http://libcat.slu.edu/search~"+lib+"/"+type+"?SEARCH="+str+searchscope,"searchResults", "left=0, top=0, toolbar, menubar, scrollbars, location, status, resizable");

}

<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
