function navigationtype_change()
{
	navtype = document.getElementById('navigationtype');

	switch (navtype.options[navtype.selectedIndex].value) {
		case 'showall':
			document.getElementById('department').style.display = 'none';
			document.getElementById('pubyear').style.display = 'none';
			document.getElementById('outputmedium').style.display = 'none';
			showall();
			break;
		case 'department':
			document.getElementById('department').style.display = 'block';
			document.getElementById('pubyear').style.display = 'none';
			document.getElementById('outputmedium').style.display = 'none';
			department_change();
			break;
		case 'pubyear':
			document.getElementById('department').style.display = 'none';
			document.getElementById('pubyear').style.display = 'block';
			document.getElementById('outputmedium').style.display = 'none';
			pubyear_change();
			break;
		case 'outputmedium':
			document.getElementById('department').style.display = 'none';
			document.getElementById('pubyear').style.display = 'none';
			document.getElementById('outputmedium').style.display = 'block';
			outputmedium_change();
			break;
	}
}


function showall()
{
	theform = document.getElementById('listpublications');
	
	theform.action = 'index.php?module=pagesetter&tid=8';
	theform.submit();
}


function department_change()
{
	var theform = document.getElementById('listpublications');
	var thefilters = document.getElementById('filters');
	var thedepartment = document.getElementById('department');
	var thedepartmentpublications = document.getElementById('department' + thedepartment.value);

	var thepublications = thedepartmentpublications.value.split("|");

	var filters = '';
	for (var i = 0; i < thepublications.length; i++) {
		if (i == 0)	filters = 'no^eq^' + thepublications[i];
		else		filters = filters + '|no^eq^' + thepublications[i];
	}

	thefilters.value = filters;
	theform.action = 'index.php?module=pagesetter&tid=8';
	theform.submit();
}


function pubyear_change()
{
	theform = document.getElementById('listpublications');
	thepubyear = document.getElementById('pubyear');
	
	theform.action = 'index.php?module=pagesetter&tid=8&filter=pubyear^like^' + thepubyear.options[thepubyear.selectedIndex].value;
	theform.submit();
}


function outputmedium_change()
{
	theform = document.getElementById('listpublications');
	theoutputmediumselect = document.getElementById('outputmedium');
	
	theselectedvalue = theoutputmediumselect.options[theoutputmediumselect.selectedIndex].value;
	if (theselectedvalue == '251-0') {
		theform.action = 'index.php?module=pagesetter&tid=8&filter=outputmedium^sub^251,peerreview^eq^0';
	}
	else if (theselectedvalue == '251-1') {
		theform.action = 'index.php?module=pagesetter&tid=8&filter=outputmedium^sub^251,peerreview^eq^1';
	}
	else {
		theform.action = 'index.php?module=pagesetter&tid=8&filter=outputmedium^sub^' + theselectedvalue;
	}
	
	theform.submit();
}


function publication_navigationtype_change()
{
	navtype = document.getElementById('navigationtype');

	switch (navtype.options[navtype.selectedIndex].value) {
		case 'pubyear':
			document.getElementById('pubyear').style.display = 'block';
			document.getElementById('outputmedium').style.display = 'none';
			publication_pubyear_change();
			break;
		case 'outputmedium':
			document.getElementById('pubyear').style.display = 'none';
			document.getElementById('outputmedium').style.display = 'block';
			publication_outputmedium_change();
			break;
	}
}


function publication_pubyear_change()
{
	var theform = document.getElementById('listpublications');

	var tid = document.getElementById('tid').value;
	var pid = document.getElementById('pid').value;

	var pubyear = document.getElementById('pubyear');
	var pubyearval = pubyear.options[pubyear.selectedIndex].value;

	theform.action = 'index.php?module=pagesetter&func=viewpub&tid=' + tid + '&pid=' + pid + '&tpl=publications&navigationtype=pubyear&pubyear=' + pubyearval;
	theform.submit();
}


function publication_outputmedium_change()
{
	var theform = document.getElementById('listpublications');

	var tid = document.getElementById('tid').value;
	var pid = document.getElementById('pid').value;

	var outputmedium = document.getElementById('outputmedium');
	var outputmediumval = outputmedium.options[outputmedium.selectedIndex].value;

	theform.action = 'index.php?module=pagesetter&func=viewpub&tid=' + tid + '&pid=' + pid + '&tpl=publications&navigationtype=outputmedium&outputmedium=' + outputmediumval;
	theform.submit();
}


function publication_simplesearch(formid)
{
	var theform  = document.getElementById(formid);
	var thequery = document.getElementById('query').value;

	thequery = thequery.replace(/^\s+/g, '').replace(/\s+$/g, '');

	var searchqueries = new Array();
	searchqueries = thequery.split(' ');

	var searchkeys = new Array('bibtitle', 'abstract');

	var thefilter = '';
	var thefilters = new Array();

    /* OR search
	for (var i = 0, count = 0; i < searchkeys.length; i++) {
		var thefilter = '';
		for (var j = 0; j < searchqueries.length; j++) {
			if (thefilter.length)	thefilter = thefilter + ',';
			thefilter = thefilter + searchkeys[i] + '^like^' + escape(searchqueries[j]);
		}
		if (thefilter.length) {
			thefilters[count++] = thefilter;
		}
	}

	var thefilter = '';
	for (var i = 0; i < count; i++) {
		if (count > 1)	thefilter = thefilter + '&filter' + (i + 1) + '=' + thefilters[i];
		else			thefilter = thefilter + '&filter=' + thefilters[i];
	}
	*/

    /* AND search */
	var thefilters = new Array();
	for (var i = 0, count = 0; i < searchkeys.length; i++) {
		var thefilter = '';
		for (var j = 0; j < searchqueries.length; j++) {
			if (thefilter.length)	thefilter = thefilter + ',';
			thefilter = thefilter + searchkeys[i] + '^like^' + escape(searchqueries[j]);
		}
		if (thefilter.length) {
			thefilters[count++] = thefilter;
		}
	}

	var thefilter = '';
	for (var i = 0; i < count; i++) {
		if (count > 1)	thefilter = thefilter + '&filter' + (i + 1) + '=' + thefilters[i];
		else			thefilter = thefilter + '&filter=' + thefilters[i];
	}
	
	theform.action = 'index.php?module=pagesetter&tid=8' + thefilter;
	theform.submit();
}

