var Ajax = false;

var Cache = new Array( );
var Cache_menu = new Array( );

function clearCache( ) { Cache = new Array( ); }

function load(url, parameters, area, cache) {
	Ajax = false;

	if ( cache ) var cacheID = parameters;
	else var cacheID = false;

	if ( Cache[cacheID] ) document.getElementById(area).innerHTML = Cache[cacheID];
	else {
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			Ajax = new XMLHttpRequest();
			if (Ajax.overrideMimeType) {
				Ajax.overrideMimeType('text/html');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				Ajax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					Ajax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!Ajax) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}



		Ajax.onreadystatechange = function() { alertContents(area, cacheID); };
		Ajax.open('POST', url, true);
		Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded;");
		Ajax.setRequestHeader("Content-length", parameters.length);
		Ajax.setRequestHeader("Connection", "close");
		Ajax.send(parameters);
	}
}

function alertContents(area, cacheID) {
	if (Ajax.readyState == 4) {
		if (Ajax.status == 200) {

			var resp = Ajax.responseText

			if ( area == 'login' && resp == '0' )
			window.location = './';
			else if ( area == 'logout' )
			window.location = './';
			else {
				if ( cacheID != false ) {
					if ( cacheID.indexOf('subMenu') == 0 )
					Cache_menu[cacheID] = resp;
					else
					Cache[cacheID] = resp;
				}
				document.getElementById(area).innerHTML = resp;
			}

		} else {
			alert('There was a problem with the request.');
		}
	}
}

function bibliography( )
{
	
	var filters = document.filter_bibliography;
	
	var annotation_author = filters.annotation_author.value;
	var author = filters.author.value;
	var year = filters.year.value;
	var subfield = filters.subfield.value;
			
	
	postStr = 'useRequest=true&annotation_author='+annotation_author+'&author='+author+'&year='+year+'&subfield='+subfield;
	
	load('bibliography.php', postStr, 'bibliographyList', true);
	
}

function cdevelopment( )
{
	
	var filters = document.filter_bibliography;
	
	var author = filters.author.value;
	var topic = filters.topic.value;
			
	
	postStr = 'useRequest=true&author='+author+'&topic='+topic;
	
	load('c-development.php', postStr, 'bibliographyList', true);
	
}
