//ml  move web-div and web-tab to end of list for next two lines.
var divIds = new Array("books-div", "articles-div", "video-div", "reserve-div", "web-div"); 
var tabIds = new Array("books-tab", "articles-tab", "video-tab", "reserve-tab", "web-tab"); 

function selectTab(tab) { 
    // Get our color scheme
    var color = getStyleById("search-area", "color");
    var bgcolor = getStyleById("search-area", "backgroundColor");

    // Hide everything 
    for(var i = 0; i < tabIds.length; i++) { 
	if (i != tab) {
	    var e = document.getElementById(divIds[i]);
	    if (e != null) {
			e.style.display='none';
	
			e = document.getElementById(tabIds[i]);
			e.style.borderBottomColor = "#000000";
			e.style.backgroundColor = bgcolor;
			e.style.color = color;
			}
		}
    } 
    // Show the target tab 
    var e = document.getElementById(divIds[tab]); 
    e.style.display='block';

    e = document.getElementById(tabIds[tab]);
    setStyleById(tabIds[tab], "borderBottomColor", color);

    e.style.backgroundColor = color;
    e.style.color =  bgcolor;

    return false;
} 

function catalogSearch(searchType, searchTerm, limitTerm) {
    var url = "http://libcat.dartmouth.edu/search/";
    var term = searchTerm.replace("^ +", "").replace(" +$", "");
    
    if (term.length == 0) {
		alert("Please type some words in the search box.");
		return false;
    }

    if (searchType == "Keywords") {
		url += "X";
    }
    else if (searchType == "Author") {
		url += "a";
    }
    else if (searchType == "Title") {
		url += "t";
    }
    else if (searchType == "Subject") {
	        url += "d";
    }
    else if (searchType == "Course Name") {
		url += "r";
    }
    else if (searchType == "Instructor") {
		url += "p";
    }
    url += "?SEARCH=" + term;
	
	if (limitTerm != null) {
		url += "&" + limitTerm;
	}
	
    document.location.href=url;

    return false;
}
 


function bookSearch() {
    var e = document.bookSearchForm;
    var searchType = e.field.value;
    var term = e.term.value;
    
	return catalogSearch(searchType, term, "");
 }
 
function videoSearch() {
    var e = document.videoSearchForm;
    var searchType = e.field.value;
    var term = e.term.value;
    
	return catalogSearch(searchType, term, "m=g");
 }

function reserveSearch() {
    var e = document.reserveSearchForm;
    var searchType = e.field.value;
    var term = e.term.value;
    
 	return catalogSearch(searchType, term, null);
}

function websiteSearch() {
    var url = "http://www.google.com/search";
    var e = document.webSearchForm;
    var term = e.term.value;
    
    term = term.replace("^ +", "").replace(" +$", "");
    
    if (term.length == 0) {
	alert("Please type some words in the search box. xx");
	return false;
    }

    url += "?rls=en-us&q=" + term + " site:library.dartmouth.edu OR site:www.dartmouth.edu/~library";
    document.location.href=url;

    return false;
}

// dumpstuff is for debugging only
function dumpstuff() {
    return;
    var sheets = document.styleSheets;
    
    alert("dumping " + sheets.length);
    // loop over each sheet
    for(var x = 0; x < sheets.length; x++) {
	var sheet = sheets[x];
	document.write("<p>sheet: " + sheet.title + " (" + sheet.href+ ") </p>\n");
	// grab stylesheet rules
	var rules = sheet.cssRules;

	for(var y = 0; y < rules.length; y++) {
	    // selectorText broken in NS 6/Mozilla: see
	    // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
	    var rule = rules[y];
	    document.write("<p>    rule: " + rule.selectorText + "</p>\n");
	}
    }

    return true;
}
