/********************tabs*************************/
function Browser(){
  var detect = navigator.userAgent.toLowerCase(); // get user browser
  this.dom = document.getElementById?1:0;
  this.ie = detect.indexOf("msie") + 1;
  this.ff = detect.indexOf("firefox") + 1;
  this.opera = detect.indexOf("opera") + 1;
  this.safari = detect.indexOf("safari") + 1;
  this.mozilla4 = detect.indexOf("mozilla/4") + 1;
  this.mozilla5 = detect.indexOf("mozilla/5") + 1;
  this.mozilla = (this.mozilla5 && !this.mozilla4)?1:0;
  this.ns6 = (this.dom && !document.all)?1:0;
}
var browser = new Browser();
var ie4 = document.all;
var nn6 = document.getElementById && !document.all;
var emptySc = "";
var icon_path = "";

if (navigator.appVersion.indexOf("2.") != -1){
   check = false;
}
if ((navigator.appVersion.indexOf("3.") != -1) && (navigator.appName.indexOf("Explorer") != -1)){
   check = false;
}
else {
   check = true;
}

var imageStay = "";

function imageon(name){
  if (imageStay != name){
     document[name].src = eval(name + "on.src");
  }
}
function imageoff(name){
  if (imageStay != name){
     document[name].src = eval(name + ".src");
  }
}

function on(name){
  if (check == true){
     imageon(name);
  }
}
function off(name){
  if (check == true){
     imageoff(name);
  }
}

function stay(name){
  if (check == true){
     document[name].src = eval(name + "stay.src");
     if (imageStay != name){
        if (imageStay != ""){
           document[imageStay].src = eval(imageStay + ".src");
        }
     }
     imageStay = name
  }
}
/********************tabs ends*************************/


/******** hide & show ********/
function toggleVisibility(id, NNtype, IEtype, WC3type) {
  if (document.getElementById) {
     eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
  } else {
     if (document.layers) {
        document.layers[id].visibility = NNtype;
     } else {
        if (document.all) {
           eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
        }
     }
  }
}
/******** hide & show ********/

/***** Exit window *****/

function hideObject00() {

   if (ie4) {
      window.Exit.document.write (emptySc);
      document.all['n00'].style.visibility = "hidden";
      document.all['n00'].style.height = "0px";
   }
   else if (nn6) {
      document.getElementById('n00').style.visibility = "hidden";
      document.getElementById('n00').style.height = "0px";
   }
}

// Show/Hide functions for pointer objects

function showObject00(loc) {
   if (ie4) {
      document.all['n00'].style.visibility = "visible";
      document.all['n00'].style.height = "152px";
   }
   else if (nn6) {
      document.getElementById('n00').style.visibility = "visible";
      document.getElementById('n00').style.height = "152px";
   }
   window.Exit.location.href = loc;
}

/******** help window ********/
function open_window_help (loc) {
    var w = window.open (loc, "Help", "scrollbars=no,menubar=no,location=no,resizable=yes,directories=no,height=470,width=330, left=485, top=115");
     w.focus();
}
/******** help window ends ********/

var parentWindowName = "metalibMainWin";
function setWindowName() {
  window.name = "metalibMainWin";
}
function winPop(event, url, isModal, width, height)
{
	var wWidth=width; // window width
	var wHeight=height; // window height
	var iMyWidth;
	var iMyHeight;
	
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (wWidth/2 + 10);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (wHeight/2 + 50);
	//Give the parent window a name we know (to reference it from the child)
	window.self.name = parentWindowName;
	//Open the window.
	var win2 = window.open(url,"Window2","status=no,height="+ wHeight +",width="+ wWidth +",resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
	win2.focus();
}  
function winClose()
{
	var win2 = window.open("","Window2","height=1,width=1");
	win2.close();
}  

function handlePopupSubmitConditional(form,retarget){
	if (retarget != "no"){
		handlePopupSubmit(form);
	}
}
function handlePopupSubmit(form){
	form.target = parentWindowName;
	//these are attempts to make this nicer:
	//(but in reality we've already done the important stuff above)
	window.opener.window.focus();
	setTimeout("self.close()",1000); //1000 miliseconds = 1 sec
}

function handlePopupLink(link){
	link.target = parentWindowName;
	window.opener.window.focus();
}

function handlePopupLinkAndClose(link){
	handlePopupLink(link);
	setTimeout("self.close()",1000); //1000 miliseconds = 1 sec
}
/*--------------- popup script ----------- */
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function loadmenu(url,width,height,direction){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("nav_menu").style.display=''
document.getElementById("nav_menu").style.width=initialwidth=width+"px"
document.getElementById("nav_menu").style.height=initialheight=height+"px"

if (direction=="left")
	document.getElementById("nav_menu").style.left="10px"
else
	document.getElementById("nav_menu").style.right="10px"
document.getElementById("nav_menu").style.top=ns6? window.pageYOffset*1+80+"px" : iecompattest().scrollTop*1+80+"px"
document.getElementById("cframe").src=url
}
}

function closemenu(){
document.getElementById("nav_menu").style.display="none"
}

function parentRedirect(loc){
	try{
		//alert(window.opener.window.location.href);
		if ((window.opener.window.location.href  = loc) != false){
			window.opener.window.focus();
			window.self.close();
		}
	}catch(e){
		window.location = loc;
	}
	
	return false;
}

// Used to get the value of form elements specifically in popup windows.
function getValue(id){
	try{
		var o = document.getElementById(id);
		if (o.value){
			return o.value;
		}else{
			return "";
		}
	}catch(e){
		return "";
	}
}

function setIconPath(path) {
icon_path = path;
}

helpArray = new Array ( 
  'Hint: For better results, remove any "quotes"', 
  'Hint: for more results, enter fewer words', 
  'Hint: using "and" between words narrows your search', 
  'Hint: using "or" between words broadens your search', 
  'Hint: for better results, remove (parentheses)' 
); 
 
function getRandomHelp() { 
  index = Math.round(Math.random()* helpArray.length); 
  if (index >= helpArray.length) { 
    index = helpArray.length - 1; 
  } 
  return helpArray[index]; 
} 
 
 
/*-------------------------------------------- 
 Is there a cookie? If so, muck with the help text. 
------------------------------------*/ 
 
function hasCookie() { 
  var cookies = document.cookie; 
  var pos = cookies.indexOf("ML_SESSION_ID="); 
  if (pos != -1) 
  { 
    return true; 
  } 
  return false; 
} 

/* Time to look for things to update */
function update_image(i) {
    var s = i.parentNode.previousSibling;
    while(s !=null && s.nodeName != 'TD' ) { s = s.previousSibling; }
    var c = s.childNodes;
    var j = 0;
    var h = '';
    for( ; j < c.length; j++ ){
        if( c[j].nodeName == 'A' ) {
            h = c[j].href ;
            break;
        }
    }
    i.onload = function () {};
    i.src = '/cgi-bin/can-search.pl?' + h.substr(h.indexOf('resource=')+9,8);
    
}

(function () {
var re = new RegExp(/ckbox=UMI[0-9]{5,5}|group_number=[0-9]{1,9}|resource=UMI[0-9]{5,5}/g);
var clean = new RegExp(/ckbox=|group_number=|resource=/);
var qe = new RegExp(/find_request_[0-9]+=[^&]*/g);
var qlean = new RegExp(/find_request_[0-9]+=/);
var fe = new RegExp(/func=[^&]*/);
var flean = new RegExp(/func=/);
var m = document.location.search.toString().match(re);
var s = 'http://beta.lib.umich.edu/logger.php';
var sorig = s.length;
var conjunction = '?';
var i = null;
if(m!= null) {
  for(i=0; i< m.length; ++i) {
    m[i] = m[i].replace(clean,'');
  }
  s += conjunction + 'db=' + encodeURIComponent(m.toString());
  conjunction = '&';
}
m = document.location.search.toString().match(qe);
if(m!=null) {
  for(i=0; i < m.length; ++i) {
    m[i] = m[i].replace(qlean,'');
  }
  s += conjunction + 'q=' + encodeURIComponent(m.toString());
}
if(s.length > sorig) {
  m = document.location.search.toString().match(fe);
  if(m!=null) {
    for(i=0; i< m.length; ++i) {
      m[i] = m[i].replace(flean,'');
    }
    s += conjunction + 'func=' + encodeURIComponent(m.toString());
  }
  i = new Image;
  i.src = s;
}
})();
