// JavaScript Document

var xmlHttp;

function makeQuickSearchLink(str,chc)

{
	
if (str.length==0)
  { 
    //document.getElementById("txtHint").innerHTML="";
  return;
  }

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

xmlHttp.onreadystatechange=stateChanged(str,chc);

} 

function stateChanged(str,chc) 

{

var sFirstChar; 
var sUrl;
var nst;
var str2;
var str3;
var regexpSlash = /\//g;
var regexpSpace = / /g;

// change '/' to '%2F'
str2 = str;

str3 = str2.replace(regexpSlash, '%2F'); // should replace all slashes with %02F
str3 = str3.replace(regexpSpace, '%20'); // should replace all spaces with %20F


if (chc=="q") {
			sFirstChar = str.charAt(0);
                        
			if (x= isan(sFirstChar))
			{
				nst="c";
			}else{
				nst="l";
			}
			sURL = "http://biblion.exeter.edu/search/?searchtype=" + nst + "&searcharg=" + str3
	
}else{
	 sURL = "http://biblion.exeter.edu/search/" + chc + "?" + str3			

}
        

document.getElementById("txtSearchLink").href=sURL

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



function isan(string) {
    if (string.length == 0)
        return false;
    for (var i=0;i < string.length;i++)
        if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9'))
            return false;
    
    return true;
}


function goSerialSolutions()
{
     			var url = "http://ta5ad5zn7x.search.serialssolutions.com/"
				var	qstr = "?V=1.0&N=100&L=TA5AD5ZN7X&S="
				qstr += document.getElementById("S").value
                qstr += "&C="
				qstr += document.getElementById("SS_CFocusTag").value
			    var url_qstr = url + qstr
			    var strFeatures = "height=" + screen.availHeight-200 + ",width=679" + ",scrollbar=yes,menubar=no, resizable=yes,status=no,toolbar=no";		
	//	var strFeatures = "height=300, width=400 ,scrollbar=no,menubar=no,status=no,toolbar=no";
		
				window.open(url_qstr,'_blank',strFeatures);		
				document.getElementById("SS_CFocusTag").value = ""
				

}

/////////////////////////////////////////////////////////////////////////////////

function whichSearch(searchBoxId)

// this function sets the value of a hidden field to be the id of the search box being used

{
//alert(xyz)
document.getElementById("txt_hidden_which_search").value = searchBoxId
}

/////////////////////////////////////////////////////////////////////////////////
function onEnter(evt,frm,box_id)

// this function gives intelligence to the enter key. it decides which button code to execute.

// Fixed two problems with Biblion Catalog Search Box in this code on 5/5/09. 
// 	First Problem: If user pressed enter and did not enter any query in the Search Box, a new library landing page window would appear. 
//                     I put in a check to make sure the search query length is greater than 0.
//      Second Problem: (From Ticket #104188) User enters search query, presses enter. The search result window opens (as expected). However
//                     if user then goes from that window back to library landing page and enters a new query and presses enter, nothing happens.
//                     The problem was the browser already thinks the search result window is open because the id for the window was called
//                     myWindow. I put a random number generator in to create different window names so the browser now thinks it's opening a new
//                     window (which it is).  5/5/09 JRF

{

var keyCode = null;

if( evt.which ) 
{
keyCode = evt.which;
} 
else if( evt.keyCode ) 
{
keyCode = evt.keyCode;
}


if( 13 == keyCode ) 
{

//alert("execute code on button assssociated with: " + box_id);

  switch(box_id)
  {

   case "txtSearch":  
     var strQuery;
     var intLength;
     strQuery = document.getElementById("txtSearch").value;
     intLength = strQuery.length;
     if (intLength > 0)
     	{
        var go_url = document.getElementById("txtSearchLink").href;
        //  alert(document.getElementById("txtSearchLink").href)
        //  window.open(go_url,"mywindow","menubar=1,resizable=1,width=800,height=650");
        var intWindowName;
        var strWindowName;
        
        intWindowName = Math.floor(Math.random() * (1000 + 1));
        strWindowName = intWindowName + ' ';
        strWindowName = RTrim(strWindowName);
        //window.open(go_url,"myWindow"); 
        window.open(go_url, strWindowName);
        }
     break;
   case "SS_CFocusTag":
     //var go_url = document.getElementById("SS_CfocusTag").href
     goSerialSolutions() 
     break;
   case "userInput":
     x_text = document.getElementById("userInput").value;
	 var x_new_url = "http://biblion.exeter.edu/search/X?%28%22opposing%20viewpoints%22%20or%20%22Reference%20Shelf%22%29%20and%20" + x_text; 
	 window.open(x_new_url)
     break;
   default:
     alert("default")
  }
  

  return false;
}
  return true;
}

// Removes ending whitespaces acts as a Right Trim - added 5/5/09 JRF
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}


// this is now residing directly within the content class.

//function setSearchBoxClass() 
//{

  //var x_visitor_ip = '<%= Request.ServerVariables("remote_addr") %>';
 // var iparray = x_visitor_ip.split(".")
  
  //var x_searchbox = document.getElementById("onCampusSSDiv");		 
 // var x_text_link = document.getElementById("offCampusSSDiv");		
   
 // if (x_searchbox) {
	//	 if (iparray[0] == "172" || iparray[0] == "10") {
  
	//	     x_searchbox.className = "show"
	//         x_text_link.className = "hide"	
  //       } 
	//	else
	//	 {

	//	     x_searchbox.className = "hide"
	//		 x_text_link.className = "show"
			 
	//     }
 // }
//}

