function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function chkQuery()
{
		var gobalSearchURL = "http://www.c2i.ntu.edu.sg/Search/C2i/index.php";
		var pubSearchURL = "http://155.69.147.17/publications/";

		//Getting value for SEARCH BOX + remove trailing/ ending spaces
		query = new String(document.FORM1.query.value);
		tmpQuery = trim(query);
				
		//Getting value for CHECK BOX/  RADIO BOXES
		//searchPublications = (document.FORM1.bPublications.checked)? true:false;	//Check box
		//searchPublications = (document.FORM1.bPublications[1].checked)? true:false;	//Radio box
		searchPublications = false;
		reloc = "";		
		
		//NO query entered, redirect to respective page
		if(tmpQuery=="")
		{	
			if (searchPublications)
				reloc = pubSearchURL;	//Goto Basilic main page
			else
				reloc = gobalSearchURL;	//Goto Sphider main page
		}
		
		//Do search with query
		else
		{
			if (searchPublications)
				//Input query to Basilic search link
				reloc = "http://155.69.147.17/publications/?title=" + tmpQuery +"&year=-1&display=list&full=true";
			else
				//Input query to Sphider search link
				reloc = gobalSearchURL + "?query=" + tmpQuery + "&search=1";			
		}
		
		this.location.href= reloc;
		return true;
}

function submitEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
		chkQuery();
		return false;
	}
	else
		return true;
}

function searchNTU(query)
{
	window.open("http://gemssearch.ntu.edu.sg/NTUNative/search.jsp?query="+ query);	
}

function searchStaff(query)
{
	window.open("https://wis.ntu.edu.sg/webexe88/owa/TDR_TELDIR.NAME_SEARCH?STAFF_NAME="+ query);	
}