﻿/********************************************
 *
 * Javascripts for /Library site
 *
 ********************************************/

function searchLibrarySite()
{
	searchKeywords = trimStr(document.getElementById("librarySiteSearchText").value);
	if(searchKeywords == "")
	{
		alert("Please enter your search keyword(s)");
		return;
	}
	searchKeywords = formatSearchKeyword(searchKeywords);
	scopeUrl = encodeHtml(window.location.href.substring(0,window.location.href.lastIndexOf('/Pages')));
	window.location.href = "/Search/Results.aspx?k=" + searchKeywords + "&cs=This%20Site&u="+scopeUrl;
}

function searchOPAC()
{
	searchKeywords = trimStr(document.getElementById("BS_Keyword").value);
	if(searchKeywords == "")
	{
		alert("Please enter your search keyword(s)");
		return;
	}

	BS_URL = "http://libopac.np.edu.sg/cgi-bin/spydus.exe/ENQ/OPAC/BIBENQ";
	BS_Category = "ENTRY1_NAME=" + encodeHtml(document.getElementById("BS_Category").value);
	BS_Key = "ENTRY1=" + formatSearchKeyword(searchKeywords);
	BS_TYPE = "ENTRY1_TYPE=K"; //default to keywords 
	BS_Limit = "GMD=" + encodeHtml(document.getElementById("BS_Limit").value);

	finalUrl = BS_URL + "?" + BS_Category + "&" + BS_TYPE + "&" + BS_Key + "&" + BS_Limit + "&ENTRY1_OPER=%2B&CF=GEN";	
	openSearchWindow(finalUrl, "OPAC_Search");
}

function formatSearchKeyword(keyword)
{
	keyword = encodeHtml(keyword);
	keyword= keyword.replace("%20", "+");
	return keyword;
}


function searcheBooks(formHandler)
{
	keywords = trimStr(document.getElementById("eBooks_Keywords").value);
	if(keywords == "")
	{
		alert("Please enter your search keyword(s)");
		return;
	}
	
	category = document.getElementById("eBooks_Category").value;
	keywords = formatSearchKeyword(keywords);
		
	if(category == "opac")
	{
		BS_URL = "http://libopac.np.edu.sg/cgi-bin/spydus.exe/ENQ/OPAC/BIBENQ";
		BS_Category = "ENTRY1_NAME=BS";
		BS_Key = "ENTRY1=" + keywords;
		BS_TYPE = "ENTRY1_TYPE=K";
		BS_Limit = "GMD=" + encodeHtml("e-book");

		finalUrl = BS_URL + "?" + BS_Category + "&" + BS_TYPE + "&" + BS_Key + "&" + BS_Limit + "&ENTRY1_OPER=%2B&CF=GEN";	
		openSearchWindow(finalUrl, "eBooks_Search");
	}
	else
	{
		url = "http://libsearch.np.edu.sg:8331/V/M7YM3NGIQRTJ3U2VBMFRNH5GFKXRK9893RGF8KUFGQIIKBAR58-19192?func=quick-1-check1&mode=advanced&find_code_2=WRD&group_number=000000109&find_request_2=";
		url = url + encodeHtml(keywords);
		openSearchWindow(url, "eBooks_Search");
	}
}

function openSearchWindow(searchURL, windowTitle)
{
	return window.open(searchURL, windowTitle, "width=640,height=480,resizable=yes,scrollbars=1");
}
