/* FUNCTIONS FOR SCREEN - Search */

var btnCritera_Show = '';
var btnCritera_Hide = '';
var strInvalidTextChars = '';

function fn_CheckSearchFormTag(frm) {
	if (frm.tag.value == "") {
		alert('Please enter the word[s] to search for');
		frm.tag.focus();
		return false;
	} else if (isNotValidChar(document.searchForm.tag.value,strInvalidTextChars)) {
		alert ('The word[s] to search for cannot contain the following characters: ' + strInvalidTextChars);
		frm.tag.focus();
	} else {
		frm.submit();
	}
}

//loop through all check boxes - if name matches the one selected then set the checked value to that chosen
function fn_selectcategories(thisBox) {
	for (var i = 0; i < document.searchForm.elements.length; i++) {
	    var e = document.searchForm.elements[i];
		if ((e.name == 'searchCategory') && (e.value != 'all') && (e.type == 'checkbox')) {
			e.checked = thisBox.checked;
	    }
	}
}

//if any of the categories is not selected, then deselect the 'all' option
function fn_checkcategories(thisBox) {
	var itemDeselected = false;
	for (var i = 0; i < document.searchForm.elements.length; i++) {
	    var e = document.searchForm.elements[i];
		if ((e.name == 'searchCategory') && (e.value != 'all') && (e.type == 'checkbox')) {
			if (!e.checked) {
				itemDeselected = true;
				document.getElementById("searchCategoryAll").checked = false;
				break;
			}
	    }
	}
	if (!itemDeselected) {
		document.getElementById("searchCategoryAll").checked = true;
	}
}

function fn_DisplayCritera() {
	var btn = document.getElementById('btnCriteria');
	var div = document.getElementById('divCriteria');
	if (btn.value == btnCritera_Show) {
		div.className = '';
		btn.value = btnCritera_Hide;
	} else {
		div.className = 'hiddenSection';
		btn.value = btnCritera_Show;
	}
}

