// global.js -- Provides access to functions needed across the site
// Created: 7-2-2004
// Last update: $Id: global.js,v 1.8 2008/01/15 19:24:52 dunlapm Exp $



function createProxyLink() {
	var d = document;
	var url,link,linktext;
	if(d.location.href.search("offcampus")>0) {
		//linktext = "[You are logged in]";
		linktext = '<img src="/images/proxy-unlocked.gif" alt="Icon indicating that the current user is logged into off-campus access" />';
		link = linktext;
	} else {
		thelink = d.location.href;
		thelink = thelink.replace("script>",""); //added because people think url script injection is dangerous
		url = "http://offcampus.lib.washington.edu/login?url=" + thelink;
		//linktext = "Off-Campus Access";
		linktext = '<img src="/images/proxy-locked.gif" alt="Icon indicating that the current user is not logged into off-campus access" />';
		link = '<a title="Log in to the proxy server" href="' + url + '">' + linktext + '</a>';
	}
	d.write(link);
}



function processSearch(type, search, frm) {
	var search_string = search;
	try {
		search_string = escape(search);
	} catch (e) {
		try {
			search_string = encodeURI(search);
		} catch (e2) {
			search_string = search;
		}
	}

	//get id from select
	frm.elements['id'].value = type;

	if(type != "HealthLinks" && type != "eJournals" && type != "9439D6CC-B23B-49DE-BE10-1C360127F11A") {
                newLoc = "/queryProcessor.jsp?id=" + frm.elements['select'].value + "&term=" + search_string;
                window.open(newLoc);
                return false;
        } else if(type == "9439D6CC-B23B-49DE-BE10-1C360127F11A"){
                newLoc = "/queryProcessor.jsp?id=" + frm.elements['select'].value + "&term=" + search_string;
                document.location.href = newLoc;
                return false;
        } else {
                newLoc = "/search.jsp?select=" + type + "&q=" + search_string;
                document.location.href = newLoc;
        }
	return true;
}
	
