// JavaScript Document

/* ===================================================
     SendGoogleSearch.js
     Used for all search engines
     
     Created by Autumn 2010
     Updated 7/27/11 by Jason - documentation, added News search
	 
================================================== */	
/*

To go on the page:---------------------------------------

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
	google.load('search', '1');
	google.setOnLoadCallback(function() {
		google.search.CustomSearchControl.attachAutoCompletion(
		'013219616395457722490:hf8sehi1km0 ',                    //Unique Google CSE ID
		document.getElementById('librarySearch'),                //ID & NAME of input element below
		'cse-search-box');
	});
</script>

<div>
 <input type="text" name="librarySearch" id="librarySearch" autocomplete="off" size="31" />    //ID & NAME of input element above
 <input type="button" name="sa" value="Search" onclick="SendSearchLibrary();" />               //Unique function name below
</div>

<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
*/


/* ==================== Search functions ==================== */
function SendSearch() //Global Search in #header
{
	var searchTerm = $("#q").val();
	window.location.replace('http://www.seattleu.edu/searchresults.aspx?cx=013219616395457722490:ave_ey_xavm&cof=FORID:10&ie=UTF-8&q='+searchTerm);
}

function SendSearchLibrary() //library
{
	var searchTerm = $("#librarySearch").val();
	window.location.replace('http://www.seattleu.edu/searchresults.aspx?cx=013219616395457722490:hf8sehi1km0&cof=FORID:10&ie=UTF-8&q='+searchTerm);
}

function SendSearchMagazine() //magazine
{
	var searchTerm = $("#magazineSearch").val();
	window.location.replace('http://www.seattleu.edu/magazine/searchresults.aspx?cx=013219616395457722490:thoe-oldhqi&cof=FORID:10&ie=UTF-8&q='+searchTerm);
}
function SendSearchNews() //magazine
{
	var searchTerm = $("#newsSearch").val();
	window.location.replace('http://www.seattleu.edu/news/searchresults.aspx?cx=013219616395457722490:qwj45oonqng&cof=FORID:10&ie=UTF-8&q='+searchTerm);
}


function clearSearchField(text){
	if(text.value == 'Search Seattle University'){ /* if the default text... */
		document.getElementById('q').value = ''; /* replace with nothing */
		document.getElementById('q').setAttribute('className', 'TabOn'); /* switch class to "used" for IE */
		document.getElementById('q').setAttribute("class", "used"); /* switch class to "used" the rest of the world */
	}
	/* SU magazine */
	if(text.value == 'Search SU Magazine'){ /* if the default text... */
		document.getElementById('magazineSearch').value = ''; /* replace with nothing */
		document.getElementById('magazineSearch').setAttribute('className', 'TabOn'); /* switch class to "used" for IE */
		document.getElementById('magazineSearch').setAttribute("class", "used"); /* switch class to "used" the rest of the world */
	}
	/* SU news */
	if(text.value == 'Search SU News'){ /* if the default text... */
		document.getElementById('newsSearch').value = ''; /* replace with nothing */
		document.getElementById('newsSearch').setAttribute('className', 'TabOn'); /* switch class to "used" for IE */
		document.getElementById('newsSearch').setAttribute("class", "used"); /* switch class to "used" the rest of the world */
	}
}





function checkForEnterKey(keypress) {            
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = keypress.which;     //firefox
	if(key == 13) {
		SendSearch();
		return false;
	}
	else {
		return true;
	}
}
function checkForEnterKeyMagazine(keypress) {            
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = keypress.which;     //firefox
	if(key == 13) {
		SendSearchMagazine();
		return false;
	}
	else {
		return true;
	}
}
function checkForEnterKeyNews(keypress) {            
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = keypress.which;     //firefox
	if(key == 13) {
		SendSearchNews();
		return false;
	}
	else {
		return true;
	}
}


