function validateQuickSearch() {
	var text = trim(document.quicksearch.searchText.value);
	if (! isTextValid(text)) {
		alert("Please provide some search text.");
		return false;
	}
	return true;
}

function validateAdvancedSearch() {
	var title = trim(document.advancedsearch.title.value);
	var description = trim(document.advancedsearch.description.value);
	var locationName = trim(document.advancedsearch.locationName.value);
	var tag = trim(document.advancedsearch.tag.value);
	var author = trim(document.advancedsearch.author.value);

	if (isTextValid(title) == false
			&& isTextValid(description) == false
			&& isTextValid(locationName) == false
			&& isTextValid(tag) == false
			&& isTextValid(author) == false) {
		alert("Please provide some search text.");
		return false;
	}
	
	return true;	
}

function isTextValid(text) {
	text = trim(text);
	return (text != null 
			&& text.length > 0 
			&& text != '%'
			&& text != '*'
			&& text != '?');
}

function trim(s) {
	if (s == null || s.length == 0) return s;

	var len = s.length;
	var st = 0;

	while ((st < len) && (s.charAt(st) <= ' ')) {
	    st++;
	}
	while ((st < len) && (s.charAt(len - 1) <= ' ')) {
	    len--;
	}
	return ((st > 0) || (len < s.length)) ? s.substring(st, len) : s;
	
}