/* frame breaker code! 
if (top.location != self.location) {
top.location = self.location.href
} */


/* this function returns a string containing the date
 * 
 * mode		format
 * 1			[weekday], [month name] [day digit]
 * 2			MM/DD/YYYY
 */
function getDate(mode) {
	var string = '';
	var d=new Date();
	var day=d.getDate();
	var month=d.getMonth();
	var year=d.getFullYear();

	if (mode == 2) { 
		string = (month + 1) + '/' + day + '/' + year;
	}
	else { // mode = 1; this is the default mode
		var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var ending = "";
		switch (day) {
			case 1:
			case 21:
			case 31:
				ending = "st";
				break;
			case 2:
			case 22:
				ending = "nd";
				break;
			case 3:
			case 23:
				ending = "rd";
				break;
			default:
				ending = "th";
		}
		string = weekday[d.getDay()] + ', ' + monthname[d.getMonth()] + " ";
		string += day + ending;
	}
	return string;
}

function validateQS(form) {
	var query = form.query.value;
	var type = form.type.value;
	var url;
	var options = 'location=yes,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,titlebar=yes,directories=yes,width=720,height=480';
	var win;
	var displayWindow = 'new';

	// check to make sure this is a valid query
	if (query == form.query.defaultValue || query == "") {
		return false;
	}


	query = sanitize(query);
	switch(type) {
		case 'webcat': // webcat
			url = "http://www.calvin.edu/cgi-bin/lib/permcat.pl?searchdata1=" + query;
		break;
		case 'google': // www.google.com
			url = "http://www.google.com/search?q=" + query;
		break;
		case 'calvin': // Calvin College with google
			url = "http://www.google.com/u/calvincollege?sa=Google+Search&sitesearch=calvin.edu&domains=calvin.edu&q=" + query;
		break;
		case 'dictionary': // merriam-webster dictionary
			url = "http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=" + query;
		break;
		case 'encyclopedia': // encyclopedia britanica
			url = "http://search.eb.com/search?query=" + query;
		break;
		case 'oxford': // Oxford Reference Premium Collection
			url = "http://www.oxfordreference.com/views/SEARCH_RESULTS.html?q=" + query;
		break;
		case 'scholar': // scholar.google.com
			url = "http://scholar.google.com/scholar?q=" + query;
		break;
		case 'sfx_ejournal': // search sfx ejournal collection
			displayWindow = 'existing';
			url = "http://sfx4.exlibrisgroup.com:3210/calvin/azlist/default?perform=searchTitle&textSearchType=contains&type=textSearch&pattern=" + query;
		break;
		case 'content_search_objects': // search content objects, both internal and external objects
			var ptids = [27,21,2,8,25,26,5,29,14,17,6];
			var ptid_string = "";
			for (i in ptids) {
				ptid_string += "&ptids[]=" + ptids[i];
			}
			displayWindow = 'existing';
			url = "/?module=search&q=" + query + ptid_string;
		break;
		case 'content_search_pages': // search free-form content (pages) of both internal and external pages
			displayWindow = 'existing';
			// ptid of free-form is 20
			url = "/?module=search&ptids[]=20&q=" + query;
		break;
		case 'site': // search this site with google
			displayWindow = 'existing';
			url = "http://www.google.com/u/hekman?q=" + query;
		break;


		// individual searches for objects
		case 'content_search_objects_blog_instruction':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=27';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_btracker':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=21';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_docs':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=2';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_downloads':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=8';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_generic':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=25';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_hda_images':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=26';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_pictures':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=5';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_private_downloads':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=29';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_resource_abstract':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=14';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_staff':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=17';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;
		case 'content_search_objects_weblinks':
			displayWindow = 'existing';
			var ptid_string = '&ptids[]=6';
			url = "/?t=advanced&module=search&q=" + query + ptid_string;
		break;


		case '-': // line break - do nothing
		return false;
		break;
		default: // invalid search type - alert message
		alert ("unknown search type '" + type + "'.");
		return false;
	}

	if (displayWindow == 'new') {
		win = window.open(url,'win',options);
		win.focus();
	}
	else {
		document.location = url;
	}
	return false;
}

function clearSearch(obj) {
	if (obj.defaultValue == obj.value) {
		obj.value = "";
	}
	else {
		// do nothing
	}
}

function sanitize(string) {
	return string.replace(/"/g,'%22');
}

function validateDropDown(DDid) {
	dd = document.getElementById(DDid);
	url = '/xarpages/getpage/';
	val = dd.options[dd.selectedIndex].value; 
	if (val != '') {
		document.location = url+val;
	}
	return false; // always return false
}

/* simple function to toggle an elements visibility */
function elementShowHide(elemID,dowhat) {
	try {
		var elem = document.getElementById(elemID);
		if (dowhat == 'show') {
				elem.style.display = '';
		} else if (dowhat == 'hide') {
				elem.style.display = 'none';
		} else {
			if (elem.style.display == 'none') {
				elem.style.display = '';
			} else {
				elem.style.display = 'none';
			}
		}
	} catch(e) {
		alert(e.name+": "+e.message);
	}
}



/**************** subject guide javascript below!!! ************/
function confirmDeleteResource(url) {
	if (confirm('Deleting this content will remove it from this and ALL Pages/Guides in which it resides!')) {
		location.href = url;
	}
	return false;
}

/******************************** Popup javascript ****************/
function popitup(url, windowname)
{
	if (!window.newwindow) newwindow = ''; // define newwindow if not defined
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,windowname,'height=400,width=410,resizable=yes,scrollbars=yes,location=yes,status=yes,toolbar=yes,directories=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function open_item_picker(url,dd_id,extra_args) {
	var args = '';
	for (x in extra_args) {
		args += '&' + extra_args[x];
	}
	popitup(url + '?selected=' + document.getElementById(dd_id).value + args + '#selected','popitup');
}



/* this function prepares POST data and then opens
 * a new list itemizer window, sending the prepared data
 * to the script in the new window
 * parameters:
 * url - the url of the script running in the popupwindow
 * cids_array - a javascript array containing the cids of
 * 				the category chosen
 * ptid - the pubtypeid of the currently selected pubtype for this list
 * 
 *
 * 
 */
function openitemizer(url,ptid,cids_array_serialized) {
	if (cids_array_serialized == '' || cids_array_serialized == 'N;') {
		alert('Active categories must first be selected before editing list items');
		return false;
	}
	/*
	alert('url = '+url);
	alert('ptid = '+ptid);
	alert('cids_array = '+cids_array);
	return false;
	*/
	var windowname = 'popitup';
	popitup('',windowname);
	theform = document.createElement('form');

	// create cids hidden input
	cids = document.createElement('input');
	cids.name = "cids";
	cids.type = "hidden";
	cids.value = cids_array_serialized;
	theform.appendChild(cids);

	// create ptid hidden input
	ePtid = document.createElement('input');
	ePtid.name = "ptid";
	ePtid.type = "hidden";
	ePtid.value = ptid;
	theform.appendChild(ePtid);
	
	/*
	// create dd_display input
	myid = document.createElement('input');
	myid.name = "display_id";
	myid.type = "hidden";
	myid.value = jtargetids[1];
	catpopup.appendChild(myid);
	
	// create cids_serialized hidden input
	cids = document.createElement('input');
	cids_from_dd = document.getElementById(jtargetids[0]);
	cids.name = "cids_serialized";
	cids.type = "hidden";
	cids.value = cids_from_dd.value;
	catpopup.appendChild(cids);
	*/

	theform.action = url;
	theform.target = windowname;
	theform.method = 'GET';
	theform.name = 'itemizer';
	docBody = document.getElementsByTagName("body").item(0);
	docBody.appendChild(theform);
	theform.submit();
	return false;
}


/* this function prepares POST data and then opens
 * a new category popupwindow, sending the prepared data
 * to the script in the new window
 * parameters:
 * url - the url of the script running in the popupwindow
 * rcids_array - a javascript array containing the cids of
 * 				the category roots to display
 * jtargetids - array; array[0] = the name of the DD input field (usually hidden)
 *					array[1] = the name of the display div to update
 * field of the cids to be stored/retrieved
 */
function submititup(url,rcids_array,jtargetids) {
	if (rcids_array.length == 0) {
		// then we should select all categories: cid = 0
		rcids_array = new Array('0');
	}
	var windowname = 'popitup';
	popitup('',windowname);
	catpopup = document.createElement('form');

	// create rootcids hidden input (one for each root)
	for (key in rcids_array) {
		roots = document.createElement('input');
		roots.name = "rootcids[]";
		roots.type = "hidden";
		roots.value = rcids_array[key];
		catpopup.appendChild(roots);
	}

	// create dd_id input
	myid = document.createElement('input');
	myid.name = "dd_id";
	myid.type = "hidden";
	myid.value = jtargetids[0];
	catpopup.appendChild(myid);
	
	// create dd_display input
	myid = document.createElement('input');
	myid.name = "display_id";
	myid.type = "hidden";
	myid.value = jtargetids[1];
	catpopup.appendChild(myid);
	
	// create cids_serialized hidden input
	cids = document.createElement('input');
	cids_from_dd = document.getElementById(jtargetids[0]);
	cids.name = "cids_serialized";
	cids.type = "hidden";
	cids.value = cids_from_dd.value;
	catpopup.appendChild(cids);

	catpopup.action = url;
	catpopup.target = windowname;
	catpopup.method = 'post';
	catpopup.name = 'catpopup';
	docBody = document.getElementsByTagName("body").item(0);
	docBody.appendChild(catpopup);
	catpopup.submit();
	return false;
}

/******************* PHP-javascript functions *********************/
/*
* PHP Serialize
* Morten Amundsen
* mor10am@gmail.com
*/
function php_serialize(obj)
{
    var string = '';
	var count = 0;

    if (typeof(obj) == 'object') {
        if (obj instanceof Array) {
            string = 'a:';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                tmpstring += php_serialize(obj[key]);
                count++;
            }
            string += count + ':{';
            string += tmpstring;
            string += '}';
        } else if (obj instanceof Object) {
            classname = obj.toString();

            if (classname == '[object Object]') {
                classname = 'StdClass';
            }

            string = 'O:' + classname.length + ':"' + classname + '":';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                if (obj[key]) {
                    tmpstring += php_serialize(obj[key]);
                } else {
                    tmpstring += php_serialize('');
                }
                count++;
            }
            string += count + ':{' + tmpstring + '}';
        }
    } else {
        switch (typeof(obj)) {
            case 'number':
                if (obj - Math.floor(obj) != 0) {
                    string += 'd:' + obj + ';';
                } else {
                    string += 'i:' + obj + ';';
                }
                break;
            case 'string':
                string += 's:' + obj.length + ':"' + obj + '";';
                break;
            case 'boolean':
                if (obj) {
                    string += 'b:1;';
                } else {
                    string += 'b:0;';
                }
                break;
        }
    }
    return string;
}

/* simple "unserialize" function
 * that returns a simple array of
 * the literal array elements in the
 * PHP serialized string
 */
function simple_unserialize(string) {
	result = Array();
	ctr = 1;
	while (string.indexOf('"') > 0) {
		//alert('ctr = ' + ctr + ' and indexof " = ' + string.indexOf('"'));
		if (ctr > 15) break;
		string = string.substring(string.indexOf('"')+1);
		myitem = string.substring(0,string.indexOf('"'));
		string = string.substring(string.indexOf('"')+1);
		result.push(myitem);
		ctr++;
	}
	return result;
}


/* simple "overwrite innerHTML" function
 * args: id - element of id
 * html - the html string to overwrite
 */
function updateHtml(id,html) {
	document.getElementById(id).innerHTML = html;
}

/******************************************
** General Page javascript below!
******************************************/
function getSelectValueById(id) {
	// this function is necessary because IE and Firefox deal with option.value differently!!!
	var elem = document.getElementById(id);
	if (elem && elem.options && elem.options[elem.selectedIndex]) {
		var option = elem.options[elem.selectedIndex];
		if (option.value) {
			return option.value; // always works with firefox
		} else {
			return option.innerHTML; // IE fallback if option doesn't have a 'value=' defined
		}
	} else {
		return '';
	}
}
function clearAllText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ''
} 

function validate(field, str) {
	// validate a string of field "field"
	if (field == "") field = "string";
	if (field == "email" || field == "mailfr") {
		// validate the string as an email
		if (str.indexOf('@') < 1 || (str.length - str.indexOf('@')) < 3 || str.indexOf(' ') > -1) {
			alert("Please enter a valid email address");
			return false;
		}
	}
	else if (field == "dropdown") {
		// validate dropdown object (str)
		
		if (typeof(str.selectedIndex) == "undefined") {
			alert('invalid dropdown object passed to validateMulti()');
			return false;
		}
		if (str.selectedIndex == 0) {
			alert('Please select a '+str.name+' from the dropdown menu');
			return false;
		}
	}
	else if (str == undefined || str.length < 1 || str.match(/^ +$/)) {
		alert ("The " + field + " field is required.");
		return false;
	}
	return true;
}

function validateGeneric(theform) {
// this function makes sure that text/textarea fields in the form are not empty
        for (var i=0;i<theform.elements.length;i++) {
                e = theform.elements[i];
                //alert(i + " = " + document.forms['cu_problems'].elements[i]);
                if (e.type && (e.type == 'text' || e.type == 'textarea')) {
                        if (e.value == '') {
                                alert('All fields are required');
                                return false;
                        }
                }
        }
	return true;
}

function validateMulti() {
// this function loops through validate arrays passed in for multiple validations
	for (i=0;i<validateMulti.arguments.length;i++) {
		valarray = validateMulti.arguments[i];
		if (!validate(valarray[0],valarray[1])) {
			return false;
		}
	}
	return true;
}

function validateAll() {
	if (validate('email',document.form1.email.value) && validate('name', document.form1.fullname.value)) {
		return true;
	}
	return false;
}

// this is a special function to update a hidden field for an ILL form
function ill_calcDate(objSelect,fieldid) {

        // get the number of days the user has selected
        var days = objSelect.options[objSelect.selectedIndex].value;

        // 'now' in milliseconds
        var now = new Date();

        // a future date of now plus so many days
        var futureDate = new Date(now.getTime()+days*86400000);

        // set the date in the future
        // document.getElementById(fieldid).value = futureDate.toDateString();
        document.getElementById(fieldid).value = (futureDate.getMonth() + 1) + '/' + futureDate.getDate() + '/' + futureDate.getFullYear();
}

// function to update ILL form with information, as well as create a new hidden form element for CGI variables passed in (used as a openURL handler)
function ill_prep_sfx(form) {
	// loop through the CGI variables
	var extra_string = '';
	var is_sfx = false;
	var sfx_menu_url =  'http://sfx4.exlibrisgroup.com:3210/calvin?ctx_enc=info:ofi/enc:UTF-8&ctx_ver=Z39.88-2004&rfr_id=info:sid/hekman:ill&url_ctx_fmt=info:ofi/fmt:kev:mtx:ctx&url_ver=Z39.88-2004';
	var request_type;
	// determine request type
	if (form.Journal_Title != "undefined") {
		request_type = 'journal';
		sfx_menu_url += '&rft_val_fmt=info:ofi/fmt:kev:mtx:article&sfx.title_search=exact&rft.genre=article';
	} else {
		request_type = 'book';
		sfx_menu_url += '&rft_val_fmt=info:ofi/fmt:kev:mtx:book&rft.genre=book'; 
	}

	var varArray = new Array;
	if (document.location.href.indexOf('?') != -1) {
		varArray = document.location.href.split('?')[1];
		if (document.location.href.indexOf('&') != -1) {
			varArray = varArray.split('&');
		}
	}
	for(var x=0; x<varArray.length; x++)
	{
		var tmp = varArray[x].split('=');
		/* 2008-11-05-dbw2
		tmp[0] = decodeURIComponent(tmp[0]);
		tmp[1] = decodeURIComponent(tmp[1]);
		*/
		tmp[1] = tmp[1].replace(/\+/g,' ');
		tmp[0] = unescape(tmp[0]);
		tmp[1] = unescape(tmp[1]);
		tmp[1] = tmp[1].replace(/\#.*$/g,'');
		extra_string += tmp[0] + ' = ' + tmp[1] + "\n";
		
		// case statements
		switch(tmp[0]) {
			case 'author':
				if (typeof(form.Author) != "undefined") {
					form.Author.value = tmp[1];
				}
				if (typeof(form.Article_Author) != "undefined") {
					form.Article_Author.value = tmp[1];
				}
			break;

			case 'sender':
				if (typeof(form.mailfr) != "undefined") {
					form.mailfr.value = tmp[1];
				}
			break;

			case 'name':
				if (typeof(form.Name) != "undefined") {
					form.Name.value = tmp[1];
				}
			break;

			case 'bookTitle':
				if (typeof(form.Title) != "undefined") {
					form.Title.value = tmp[1];
				}
			break;

			case 'article':
				if (typeof(form.Article_Title) != "undefined") {
					form.Article_Title.value = tmp[1];
				}
			break;

			case 'journal':
				if (typeof(form.Journal_Title) != "undefined") {
					form.Journal_Title.value = tmp[1];
				}
			break;

			case 'volume':
				if (typeof(form.Vol_num) != "undefined") {
					form.Vol_num.value = tmp[1];
				}
			break;

			case 'issue':
				if (typeof(form.Issue_num) != "undefined") {
					form.Issue_num.value = tmp[1];
				}
			break;

			case 'year':
				if (typeof(form.Place_Date_Publication) != "undefined") {
					form.Place_Date_Publication.value = form.Place_Date_Publication.value + ', ' + tmp[1];
				}
				if (typeof(form.Year) != "undefined") {
					form.Year.value = tmp[1];
				}
			break;

			case 'pages':
				if (typeof(form.Pages) != "undefined") {
					form.Pages.value = tmp[1];
				}
			break;

			case 'ISSN':
				if (typeof(form.ISSN_num) != "undefined") {
					form.ISSN_num.value = tmp[1];
				}
			break;

			case 'edition':
				if (typeof(form.Edition) != "undefined") {
					form.Edition.value = tmp[1];
				}
			break;

			case 'publisher':
				if (typeof(form.Publisher) != "undefined") {
					form.Publisher.value = tmp[1];
				}
			break;

			case 'publiPlace':
				if (typeof(form.Place_Date_Publication) != "undefined") {
					form.Place_Date_Publication.value = form.Place_Date_Publication.value + ', ' + tmp[1];
				}
			case 'source': // assume this is an SFX openURL referral to the ILL request form if it has a 'source' parameter
				if (tmp[1].indexOf('sfxit.com:') > -1) { is_sfx = true; }
			break;
		}
	}

	// add sfx hidden field information
	if (extra_string.length != 0 && document.createElement) {
                if (document.referer && document.referer != '') {
                        extra_string += 'Referer URL = ' + document.referer + "\n";
		}
		var extra_field = document.createElement('input');
		extra_field.type = 'hidden';
		extra_field.name = 'Extra_ILL_Request_Information';
		extra_field.value = extra_string;
		form.appendChild(extra_field);
	}

	// show SFX ILL notification box
	if (is_sfx) {
		var sfx_msg = '<strong>Note:</strong> Your ILL request will automatically include information from SFX';
		document.getElementById('illformnotify').innerHTML = sfx_msg;
		document.getElementById('illformnotify').style.display = '';
	}
}

function construct_sfx_url(form) {
	var isJournal = false;
	var sfx_url = 'http://sfx4.exlibrisgroup.com:3210/calvin?ctx_enc=info:ofi/enc:UTF-8&ctx_ver=Z39.88-2004&rfr_id=info:sid/hekman:ill&url_ctx_fmt=info:ofi/fmt:kev:mtx:ctx&url_ver=Z39.88-2004';

	// construct openurl
	if (typeof(form.Journal_Title) != "undefined") { 
		isJournal = true;
		sfx_url += '&rft_val_fmt=info:ofi/fmt:kev:mtx:article&sfx.title_search=exact&rft.genre=article';
		// journal title
		sfx_url += '&rft.jtitle=' + form.Journal_Title.value;
	} else { // this is a book
		sfx_url += '&rft_val_fmt=info:ofi/fmt:kev:mtx:book&rft.genre=book';
	}

	// book title
	if (typeof(form.Title) != "undefined") {
		sfx_url += '&rft.btitle=' + form.Title.value;
	}
	// volume
	if (typeof(form.Vol_num) != "undefined") {
		sfx_url += '&rft.volume=' + form.Vol_num.value;
	}
	// issue
	if (typeof(form.Issue_num) != "undefined") {
		sfx_url += '&rft.issue=' + form.Issue_num.value;
	}
	// article title
	if (typeof(form.Article_Title) != "undefined") {
		sfx_url += '&rft.atitle=' + form.Article_Title.value;
	}
	// date / year
	if (typeof(form.Year) != "undefined") {
		sfx_url += '&rft.date=' + form.Year.value;
	}
	// page range
	if (typeof(form.Pages) != "undefined") {
		matches = form.Pages.value.match(/^(\d+)(\s*-\s*(\d+))?/);
		if (/^\d+$/.test(matches[1])) {
			sfx_url += '&rft.spage=' + matches[1];
		}
		if (/^\d+$/.test(matches[3])) {
			sfx_url += '&rft.epage=' + matches[3];
		}
	}
	// issn
	if (typeof(form.ISSN_num) != "undefined") {
		sfx_url += '&rft.issn=' + form.ISSN_num.value;
	}
	form.SFXURL.value = encodeURI(sfx_url);
}


/* content search javascript */
function toggleSearchView() {
	
	if (document.getElementById('articles_advanced_search').style.display == 'none') {
		updateHtml('searchtitle','HDLux Content Search');
		updateHtml('search_mode_link','Hide Options');
		elementShowHide('articles_advanced_search','show');
	} else {
		updateHtml('searchtitle','HDLux Content Search');
		updateHtml('search_mode_link','Show Options');
		elementShowHide('articles_advanced_search','hide');
	}
}

function checkbox_array_change(array_name,select_or_deselect) {
	checkboxes = document.getElementsByName(array_name);
	for (x in checkboxes) {
		if (checkboxes[x].type == 'checkbox') {
			if (select_or_deselect == 'deselect') {
				checkboxes[x].checked = false;
			} else if (select_or_deselect == 'select') {
				checkboxes[x].checked = true;
			}
		}
	}
} 

function blur_default_text(obj) {
	if (obj.value == '') {
		obj.value = obj.defaultValue;
	}
}

// this function determines if the *reference desk* is open for a given date object
// returns true if we are open and false if we are closed
function isRefDeskOpen(dateObj) {
	hour = dateObj.getHours();
	minute = dateObj.getMinutes();
	day = dateObj.getDay();

	// we are never open on sundays
	if (day == 0) {
		return false;
	}

	// we are never open before 7am
	if (hour < 7) {
		return false;
	}

	// mon-thur never open after midnight
	//if (day >= 1 && day <= 4 && hour >= 22) {
	//	return false;
	//}

	// friday closed after 8pm
	if (day == 5 && hour >= 20) {
		return false;
	}

	// saturday we are open 9am-8pm
	if (day == 6 && (hour <= 9 || hour >= 20)) {
		return false;
	}

	// we must be open then!
	return true;
}

// this function was copied from http://www.quirksmode.org/js/detect.html
// it works immediately and you can query three properties of the object:
// BrowserDetect.browser
// BrowserDetect.version
// BrowserDetect.OS
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
