// Hong Gyu Han
function FindIn(keyword)  
{
  temp = keyword.split("\"");
  keyword = "";  
  for(var i=0;i<temp.length;i++)
  {
    if (i%2==0)
    { // outside a quote
      keyword += temp[i].replace(/\bin\b/ig, "\"in\"");
    }
    else
    { // inside a quote
      // no process is needed
      keyword += "\"" + temp[i] + "\"";
    }
  }
//	alert(keyword);
	return keyword;
}

function cSearch(){
	var stype = document.getElementById('catalogOption').value;
	// var catalogForm = document.forms['TowersSearch'];
	var searchForm = document.getElementById('SearchForm'); 
	// alert(stype);
	
	if (stype == 'Y')
		searchForm.action = "http://towers.missouri.edu/search/Y";
	else if (stype == 't')
		searchForm.action = "http://towers.missouri.edu/search/t";
	else if (stype == 'a')
		searchForm.action = "http://towers.missouri.edu/search/a";
	else if (stype == 'd')
		searchForm.action = "http://towers.missouri.edu/search/d";
	else if (stype == 'm')
		searchForm.action = "http://towers.missouri.edu/search/m";
	else if (stype == 'e'){
		searchForm.action = "http://towers.missouri.edu/search/Y";
		var input = document.createElement("input");
		input.name = "m"; input.value = "2"; input.type = "hidden";
		// catalogForm.cmdSubmit.insertBefore(input);
		document.forms['TowersSearch'].appendChild(input);
	}	
	else if (stype == 'i'){
		searchForm.action = "http://towers.missouri.edu/search/Y";
		var input = document.createElement("input");
		input.name = "m"; input.value = "i"; input.type = "hidden";
		// catalogForm.cmdSubmit.insertBefore(input);
		document.forms['TowersSearch'].appendChild(input);
	}
	else if (stype == 'g'){
		searchForm.action = "http://towers.missouri.edu/search/Y";
		var input = document.createElement("input");
		input.name = "m"; input.value = "g"; input.type = "hidden";
		// catalogForm.cmdSubmit.insertBefore(input);
		document.forms['TowersSearch'].appendChild(input);
	}
}

var ipchecking = "http://www.nwmissouri.edu/library/ipchecking.asp?";

function articleSearch(){
	var db = document.getElementById('dbOption').value;
	var keyword = document.getElementById("TowersCatalogtabcontent2").value;
	var keyLen =  keyword.length;

	if (db == 'EBSCO')
		ebscoHostSearchGo(keyword);
	else if (db == 'InfoTrac')
		InfoTracQuickSearch(keyword, keyLen);	
	else if (db == 'WilsonWeb')
		WilsonWebSearch(keyword);
}

// ebsco search
function ebscoHostSearchGo(keyword) {
  var ebscohosturl="http://search.ebscohost.com/login.aspx?direct=true&site=ehost-live&scope=site&type=1&db=afh&db=aph&db=ahl&db=buh&db=ufh&db=ehh&db=eoah&db=eric&db=8gh&db=hia&db=lxh&db=loh&db=kah&db=mzh&db=pdh&db=psyh&db=s3h&db=lph&bquery="
	keyword = FindIn(keyword);
	document.location = ipchecking + ebscohosturl + keyword;
}

// InfoTrac -- tried
//function InfoTracQuickSearch(keyword, keyLen)  {
//	var infotracurl = "http://access.gale.com/cgi-bin/widgets/v2/search.pl?id=6991__nwmosu_owens&prod=&host=&pub=&keyword=" + keyword; 
//    keyword = FindIn(keyword);
//	document.location = ipchecking + infotracurl;
//}

function InfoTracQuickSearch(keyword, keyLen)  {
	var infotracurl = "http://find.galegroup.com/ips/infomark.do?dblist=SPJ.SP09_SPJ.SP19_SPN.SP26_CDB_SPJ.SP08_SPJ.SP17_EAIM_SPJ.SP20_SPJ.SP03_SPJ.SP04_SPJ.SP06_SPJ.SP07_SPJ.SP10_SPJ.SP11_GVRL.LiteraryNewsmakers_GVRL.Drama_SPJ.SP25_GVRL.LitThemes_SPJ.SP21_GVRL.Novels_SPJ.SP22_GVRL.ShortStory_SPJ.SP24_GVRL.Poetry_GVRL.Shakespeare_SPJ.SP12_SPJ.SP15_SPJ.SP16_GVRL-0_OVRC_AONE_HRCA_IFME_PPAG_BCPM_PPBE_PPCM_PPCJ_PPCA_PROF_PPFA_PPGL_PPHI_PPTH_PPPM_GRGM_DC_&subjectParam=Locale(en,US,):FQE=(SU," + keyLen + ")" + keyword +"$&type=search&sort=DateDescend&subjectAction=DISPLAY_SUBJECTS&prodId=IPS&userGroupName=nwmsu_owens&version=1.0&sgHitCountType=None&searchType=BasicSearchForm&queryId=Locale(en,US,):FQE=(KE," + keyLen + ")" + keyword + "$&source=library";
	 keyword = FindIn(keyword);
	document.location = ipchecking + infotracurl;
}

/* http://find.galegroup.com/ips/infomark.do?action=interpret&subjectParam=Locale(en,US,):FQE=(SU,16)lolita%20in%20tehran$&sgHitCountType=None&sort=DateDescend&searchType=BasicSearchForm&type=search&subjectAction=DISPLAY_SUBJECTS&prodId=IPS&source=library&queryId=Locale(en,US,):FQE=(KE,16)lolita%20in%20tehran:And:LQE=(AC,None,8)fulltext$&version=1.0&userGroupName=nwmsu_owens&finalAuth=true
*/

// WilsonWeb
function WilsonWebSearch(keyword)  {
	var wilsonweburl = "http://vnweb.hwwilsonweb.com/hww/jumpstart.jhtml?prod=EDUFT,BAIN,RGR,ERIC&query=";
	keyword = FindIn(keyword);
	document.location = ipchecking + wilsonweburl + keyword + "+%3Cin%3E+kw";
}

function ebookSearch(){
	var eb = document.getElementById('ebookOption').value;
	var keyword = document.getElementById("TowersCatalogtabcontent4").value;
	
	if (eb == 'ebrary')
		ebrarySearch(keyword);
	else if (eb == 'credo')
		credoSearch(keyword);
	else if (eb == 'galeVR')
		galeVRSearch(keyword);
//	else if (eb == 'safari')
//		safariSearch(keyword);
}

function ebrarySearch(keyword){
	var ebrary = "http://site.ebrary.com/lib/nwmsu/Top?layout=search&nosr=1&frm=smp.x&p00=";
	document.location = ipchecking + ebrary  + keyword;
}

function credoSearch(keyword){
	var credo = "http://www.credoreference.com/search.do?query=" + keyword + "&subject=all&view=facet";
	document.location = ipchecking + credo; 
}

function galeVRSearch(keyword){
	var galeVR = "http://go.galegroup.com/ps/i.do?action=interpret&ty=bs&v=2.1&u=nwmosu_owens&it=search&s=RELEVANCE&p=GVRL&searchType=BasicSearchForm&st=T003&qt=KE~" + keyword + "&sw=w&authCount=1";
	document.location = ipchecking + galeVR; 
}



/*function safariSearch(keyword){
	var safari = "http://proquestcombo.safaribooksonline.com/search?" + "searchSelect=&" + keyword + "&searchmode=simple&page=0&searchview=books&sort=rank&order=desc&_searchsurvey=1&__nestedsearch";
	
	// searchmode=simple&page=0&searchview=books&sort=rank&order=desc&_searchsurvey=1&__nestedsearch
	alert(safari);
	document.location = ipchecking + safari; 
}
*/

// JavaScript Document


