
/* Function to allow multiple page loading events by Simon Willison. */

function addLoadEvent(func) {
    if (!document.getElementById) return false;
    var oldOnload = window.onload;
    if (typeof window.onload != "function") {
        window.onload = func;
		return false;
    } else {
        window.onload = function() {
            oldOnload();
            func();
        };
		return false;
    };
}

/* Function to open a popup window, either generic or with a close event. */

function targetWindow(url) {
	var win;
	var features = "menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
	win = window.open(url,"jrnlview",features);
	win.focus;
	return false;
}

function openWindow(url,high,wide,flag) {
    var newWindow = null;
    if (!window.open) return false;
    if (flag) {
        newWindow = window.open(url,"","height="+high+",width="+wide+",status=no,resizable=yes,scrollbars=yes");
    } else {
        newWindow = window.open("","","height="+high+",width="+wide+",status=no,resizable=yes,scrollbars=yes");
        newWindow.document.write("<html><head><title>"+url+"</title></head><body title='Click to close' style='cursor:pointer' onClick='window.close()'><img src="+url+" /></body></html>");
	newWindow.document.close();
    };
    newWindow.focus();
    return false;
}

/* Function to enable quote tags in Internet Explorer -- required for IE7 too. */

function setQuotes() {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieVersion = new Number(RegExp.$1);
        if (ieVersion < 8) {
            var quoteTags = document.getElementsByTagName("q");
            for (var i = 0; i < quoteTags.length; i++) {
                quoteTags[i].innerHTML = '&ldquo;' + quoteTags[i].innerHTML + '&rdquo;';
            };
        };
    };
}

/* Dropdown menu function */

var menuids = ["drop"];
function dropMenu() {
	for (var i = 0; i < menuids.length; i++) {
		var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul");
		for (var j = 0; j < ultags.length; j++) {
			if (ultags[j].parentNode.parentNode.id == menuids[i]) {
				ultags[j].style.top = ultags[j].parentNode.offsetHeight+"px";
			} else {
				ultags[j].style.left = ultags[j-1].getElementsByTagName("a")[0].offsetWidth+"px";
			};
			ultags[j].parentNode.onmouseover = function() {
				this.getElementsByTagName("ul")[0].style.visibility = "visible";
			};
			ultags[j].parentNode.onmouseout = function() {
				this.getElementsByTagName("ul")[0].style.visibility = "hidden";
			};
		};
	};
}
/*
// a generic delay before calling a function
function genericDelay(fn, ms) {
   var timer;
   return function() {
      clearTimeout(timer);
      timer = setTimeout(fn, ms || 500);
   }
};
// get the element you want to set a event handler for
var element = document.getElementById('drop');
// now just wrap your functions with genericDelay() to get delayed execution
element.onHover = genericDelay(function() { /** your onhover code */ //}, 200);

/* Function to perform a basic CUNY+ OPAC search. */

function searchCat(x,y) {
	if ( y.value.length < 1 ) {
		alert("Please enter a search string.");
		return false;
	} else {
		for ( var i = 0; i < x.length; i++ ) {
			if ( x[i].selected ) {
				var opt = x[i].value.split("_");
				if ( opt[0] == "find" ) {
					document.forms['searchjs'].find_code.value = opt[1];
					document.forms['searchjs'].request.value = y.value;
					document.forms['searchjs'].action = "http://apps.appl.cuny.edu:83/F";
					document.forms['searchjs'].submit();
					break;
				} else {
					document.forms['browsejs'].scan_code.value  = opt[1];
					document.forms['browsejs'].scan_start.value = y.value;
					document.forms['browsejs'].action = "http://apps.appl.cuny.edu:83/F";
					document.forms['browsejs'].submit();
					break;
				};
			};
		};
		return true;
	};
}

/* Function to reveal Javascript-only features. */

function revealHidden(conceal) {
	var tested = document.getElementsByTagName("div");
	for ( var i = 0; i < tested.length; i++ ) {
		if (tested[i].className && tested[i].className == "conceal") {
			tested[i].style.display = "block";
		};
	};
}


/* Wish List */

function showList( obj )
	{
		document.getElementById( obj ).style.display = 'block';
		document.getElementById( 'wishListTitle' ).style.display = 'none';
		document.getElementById( 'wishListHide' ).style.display = 'block';
	}
	
function hideList( obj )
	{
		document.getElementById( obj ).style.display = 'none';
		document.getElementById( 'wishListTitle' ).style.display = 'block';
		document.getElementById( 'wishListHide' ).style.display = 'none';
	}
	
function hide()
	{
		document.getElementById( 'wishListHide' ).style.display = 'none';
	}


/* Page loading events. */

addLoadEvent(dropMenu);
addLoadEvent(revealHidden);
addLoadEvent(setQuotes);

/*
addLoadEvent(showList);
addLoadEvent(hideList);
addLoadEvent(hide);
*/


