//---------------------------------------------------------------------------
// Utility routines used by various javascript functions to create new querys
// from existing urls.  If current browser url does not reflect current query,
// these functions are not useful (since they are not aware of the current
// application state.)  These functions are used sparingly in the reference
// implementation only in conjunction with modules that contain form element.
//---------------------------------------------------------------------------

function ConstructURL(url,removeterms,addterms) {
	var params = BuildURLArray(url);
	var newurl = "";
	for (var i=0; i<params.length; i++) {
		val = CheckArray(removeterms,params[i][0]);
		if (val == -1)
			newurl = newurl + "&" + params[i][0] + "=" + params[i][1];
	}
	for (var i=0; i<addterms.length; i++) {
		newurl = newurl + "&" + addterms[i];
	}
	if (newurl.length > 0) {
		newurl = newurl.substr(1);
		newurl = "?"+newurl;
	}
	else {
		newurl = "?N="+eneroot;
	}
	return newurl;
}
function BuildURLArray(oldurl) {
	var returnArray = new Array();
	var url;
	if (oldurl == "CURRENTURL")
		url = location.search;
	else if (oldurl == "BLANKURL") {

	}
	else {
		var tokens = oldurl.split("?");
		url = "?"+tokens[1];
	}		
	if (url) {
		url = url.substr(1);
		var params = url.split("&");
		for (var i=0; i<params.length; i++) {
			var param = params[i].split("=");
			returnArray[i] = param;
		}
	}
	return returnArray;
}
function CheckArray(removeterms,checkterm) {
	for (var i=0; i<removeterms.length; i++) {
		if (removeterms[i] == checkterm)
			return 1;
	}
	return -1;
}
function GetValue(url, term) {
	var params = BuildURLArray(url);
	for (var i=0; i<params.length; i++) {
		if (params[i][0] == term) {
			return params[i][1];
		}
	}
	return -1;
}

//Swap image functions
function hdrImgRestore(e) { 
	var img = 'images/topnav_' + e + '.gif';
	document.getElementById(e).src = img;
}
function swapHdrImage(e) { 
	var img =  'images/topnav_' + e + '_on.gif';
	document.getElementById(e).src = img;
}

//Swap image functions for the Blaze subfoler
function hdrBlazeImgRestore(e) { 
	var img = '../images/blaze_topnav_' + e + '.gif';
	document.getElementById(e).src = img;
}
function swapBlazeHdrImage(e) { 
	var img =  '../images/blaze_topnav_' + e + '_on.gif';
	document.getElementById(e).src = img;
}

//Swap image function for the Kids subfolder
function hdrKidsImgRestore(e) { 
	var img = '../images/topnav_' + e + '.gif';
	document.getElementById(e).src = img;
}
function hdrKidsRootImgRestore(e) { 
	var img = '../images/topnav_' + e + '.gif';
	document.getElementById(e).src = img;
}
function swapHdrKidsImage(e) { 
	var img =  '../images/topnav_kids_' + e + '_on.gif';
	document.getElementById(e).src = img;
}

// Drop down set function
function set_select(sel_obj,val){
var num_sm=sel_obj.length;
 for(ca=0;ca<num_sm;++ca){
   if(val==sel_obj.options[ca].value){
	sel_obj.options[ca].selected=true;
   }
 }
}

// Database open script
function openResourceWindow(theURL) { //v2.0
  if(theURL != "") {
    if(theURL.indexOf("restricted.jsp") != -1){
	  window.open(theURL,'restricted','top=0,left=0,scrollbars=yes,resizable=yes,width=340,height=275');
    }else {
	  	window.open(theURL,'','left=0,top=0,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=780,height=500');
	    //06/01/04: JH - This code will redirect the db.jsp links to survey if uncommented.
		//if(theURL.indexOf("resid=" != -1 )) { 
	  	  //var id = theURL.substring((theURL.indexOf("=")+1));
	  	  //var rurl = "dbSurvey.jsp?resid="+id;
	  	  //parent.window.location.replace(rurl);  	  
	    //}
    }
  }
}

function displayPatronItem(e){
	// Turn on 
	if(document.getElementById(e).style.display == "none") {
		document.getElementById(e).style.display = "";
	
	// Turn off
	}else {
		document.getElementById(e).style.display = "none";
	}
}


