function toggleDesc(id) {

	if (document.getElementById(id).style.display != 'inline') {
		http[id] = createRequestObject();
		content = 'id=' + id;

		http[id].open('post', 'desc.php');
		try {
			http[id].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		} catch (e) { ; }

		http[id].onreadystatechange = function() { // begin anon function

			if(http[id].readyState == 4) {
				try {
					if (http[id].status == 200) {

						node = document.getElementById(id + 'short');
						node.style.display = 'none';

						node = document.getElementById(id);
						node.innerHTML = http[id].responseText;
						node.style.display = 'inline';

						var addthis_config = {
								addthis:url = "http://www.lib.unb.ca/eresources/index.php?doSearch=1&id=" + id,
								addthis:title =  "Add This",
								addthis:description =  "Add This",
								username: "UNBLibraries",
								ui_cobrand: "UNB Libraries",
								ui_header_color: "#ffffff",
								ui_header_background: "#000000"
						};
						addthis.init();

					} else {
						alert("There was an error when the AJAX call happened.  Error was: \n " + http[id].statusText);
					}
				} catch (e) { ; }
			}
		} // end anon function

		http[id].send(content);
	} else {
		document.getElementById(id).style.display = 'none';
		node = document.getElementById(id + 'short');
		node.style.display = 'inline';
	}
}

function doGuidesBrowseCategory(c, tab) {
	node = document.getElementById('searchInProgress');
	node.style.display = 'inline';
	category = c;
	sndReq(tab, 'doGuidesBrowseCategory', tab);	
}
function doBrowse(l, tab) {

	node = document.getElementById('searchInProgress');
	node.style.display = 'inline';
	letter = l;
	sndReq(tab, 'doBrowse', tab);
}

function doID(i, tab) {

	node = document.getElementById('searchInProgress');
	node.style.display = 'inline';
	recID = i;
	sndReq(tab, 'doSearch', tab);
}

function doSearch(tab) {

	node = document.getElementById('searchInProgress');
	node.style.display = 'inline';
	sndReq(tab, 'doSearch', tab);
}



function page(o, div) {

	if (div == '')
		div = 'allDiv';

	offset = o;

	sndReq(div, 'offset', div);

}

/*  this creates our request object. */ 

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http	= new Array();
var updated = new Array();
var offset = 0;
var letter = "";
var recID  = "";
var category = "";

/*  the workhorse function, which does the AJAX request. */

function sndReq(id, action, type) {

	http[type] = createRequestObject();
	request = buildContent(id, action, type);

	if (request == '' || request == null)
		return false;

	http[type].open('post', 'fedSearch.php');
	try {
		http[type].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	} catch (e) { ; }

	http[type].onreadystatechange = function() { // begin anon function

		if(http[type].readyState == 4) {
			try {
				if (http[type].status == 200) {
					updateResult(http[type].responseText, type, action);
				} else {

					alert("There was an error when the AJAX call happened.  Error was: \n " + http[type].statusText); 
				}
			} catch (e) { ; }
		}
	} // end anon function

	http[type].send(request);
	doCallback(action, type);
}

function updateResult(content, type, action) {
	if (action == 'doSearch' || action == 'doBrowse') { 
		node = document.getElementById('searchInProgress');
		node.style.display = 'none';
	}

	node = document.getElementById(type);
	if (content != '')
		node.innerHTML = content;
	else if (action == 'doSearch') 
		doSearch(type);
}

function buildContent(id, action, type) {

	var content = '';
	if (type == 'journalsDiv')
		content += 'limitResourceType=jour&';

	if (type == 'enewsDiv')
		content += 'limitResourceType=enews&';

	if (type == 'indexesDiv')
		content += 'limitResourceType=indexes&';

	if (type == 'refmatDiv')
		content += 'limitResourceType=refmat&';

	if (action == 'doSearch') {

		content += 'doSearch=1&';
		// check for an optional ID
		content += "id=" + encodeURIComponent(recID) + "&";

		// grab the keywords to search title
		node = document.getElementById('title');
		// var title = encodeURIComponent(node.value.replace(' & ', ' and '));
		var title = encodeURIComponent(node.value);
		content += "title=" + title + "&";

		// now do the radio buttons for title searching
		var radiobuttons = new Array('searchtype_exact', 'searchtype_browse', 'searchtype_every');

		for (i = 0 ; i < radiobuttons.length ; i ++) {

			node = document.getElementById(radiobuttons[i]);
			if (node.checked)
				content += 'searchtype=' + node.value + '&';
		}

	} else if (action == 'offset') {
		content += 'offset=' + offset + '&';
	} else if (action == 'doBrowse') {
		content += 'doSearch=1&browse=' + letter + '&searchtype=browse&';
	} else if (action == 'doGuidesBrowseCategory') {
		content += 'doSearch=1&browseCategory=' + category + '&searchtype=browseCategory&';
	}

	var node = document.getElementById('sub');
	var sub = encodeURIComponent(node.value);
	content += "sub=" + sub + "&";
	return content;

}

function doCallback(action, type) {

}

