/*
   dynUI.js 
   Copyright (C) 2005 Deryck Hodge <hodgedg@auburn.edu>

   Functions to create a dynamic interface.  Functionality includes:
   form populating and submitting, cross-browser style fixes, page
   specific titles, etc.

   This script may be freely used, modified, or redistributed 
   as long as the above copyright and this statement are preserved.
*/


/***********************************************************
  Forms
***********************************************************/


// Load options into form (a work around for width setting)
function loadOpts()
{
	if (document.forms[1] && document.forms[1].Search_Code) {

		var selectSect = document.forms[1].Search_Code;

		for (i=0; i<=selectSect.options.length; i++) {
			selectSect.options[i] = null;
		}
		
		// Initialize new options
		selectSect.options[0] = new Option(true);

		// add new items
		selectSect.options[0] = new Option("Title", "TALL");
		selectSect.options[1] = new Option("Author(Last Name First)", "NAME");
		selectSect.options[2] = new Option("Journal Title", "JALL");
		selectSect.options[3] = new Option("Browse Subjects", "SUBJ+");
		selectSect.options[4] = new Option("Browse Authors", "NAME+");
		selectSect.options[5] = new Option("Browse Call Numbers", "CALL+");
		selectSect.options[6] = new Option("Advanced Search", "CMD");
		selectSect.options[7] = new Option("Quick Search", "FT*");
	}
}

// Handles submit when pressing enter from the select menus 
function submitOnEnter(event,formName)
{
	if (event.keyCode) {
		if (event.keyCode == 13) {
			formName.submit();
		}
	}
}


// Handles FAQ menu submission
function answerFaq(question) {
	thisAnswer = question.options[question.selectedIndex].value 

	if (thisAnswer != "" && thisAnswer != "How do I...") { 
		document.location.href = thisAnswer
	} 
}


/**********************************************************
  Styles
**********************************************************/


// Adjust the wrap position depending on window size
function setPosition()
{
	var wrap = document.getElementById('wrap');
	var browserWidth;

	if (is_ie) {
		browserWidth = document.body.offsetWidth;
	} else {
		browserWidth = window.outerWidth;
	}

	if (browserWidth <= 800) {
		wrap.style.right = '0px';
	} else {
		wrap.style.right = '10px';
	}

}	

function setSidebarBorder()
{
	if (document.getElementById('sidebar')) {
		var content = document.getElementById('content');
		var sidebar = document.getElementById('sidebar');
		var contentY;
		var sidebarY;

		if (is_ie) {
			contentY = content.offsetHeight;
			sidebarY = sidebar.offsetHeight;
		} else {
			contentY = window.getComputedStyle(content, '').getPropertyValue('height');
			sidebarY = window.getComputedStyle(sidebar, '').getPropertyValue('height');
			contentY = parseInt(contentY.slice(0,-2));
			sidebarY = parseInt(sidebarY.slice(0,-2));
		}

		if (contentY > sidebarY) {
			sidebar.style.height = (contentY - 100).toString() + 'px';
		}
	}
}


/***********************************************************
  Search Plugins
***********************************************************/
function addEngine(name,ext,cat)
{
	if ( (typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function") ) {
	window.sidebar.addSearchEngine(
	"http://test.lib.auburn.edu/find/ffplugins/"+name+".src",
	"http://test.lib.auburn.edu/find/ffplugins/"+name+"."+ext,name,cat );
	} else {
		alert("Netscape 6 or Mozilla is needed to install a sherlock plugin");
	}
}
