///////////////////////////////////////////////////////////////////////////////
//
// onLoad()
//
// Called when the page loads
// 
// Preselect and set appropriate form field values
//
function onLoad() {
	var form = document.getElementById('frm_search');
	// Display advanced options is any of them are populated
	if ( form.txt_strSearchRoot.value.length > 0 ) {
		var advancedOptions = document.getElementById('tbl_advancedOptions');
		advancedOptions.style.visibility = "visible";
		advancedOptions.style.display = "block";
		form.chk_advancedOptions.checked = true;
	}
}

///////////////////////////////////////////////////////////////////////////////
//
// frm_search_onSubmit()
//
// Called when the search form is submitted
// Perform sanity check before submitting form
//
function frm_search_onSubmit() {
	var form = document.getElementById('frm_search');
	if ( form.txt_strCriteria.value.length == 0 ) {
		alert("Please enter search criteria");
		return false;
	} else {
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////////
//
// chk_advancedOptions_onClick()
//
// Called when the advanced options checkbox is checked
// Toggles visibility of the advanced options section
//
function chk_advancedOptions_onClick(source) {
	var advancedOptions = document.getElementById('tbl_advancedOptions');			
	if ( source.checked == true ) {
		advancedOptions.style.visibility = "visible";
		advancedOptions.style.display = "block";
	} else {
		advancedOptions.style.visibility = "hidden";
		advancedOptions.style.display = "none";
	}
}

///////////////////////////////////////////////////////////////////////////////
//
// toggleRow(row,nextRow)
//
// Toggle the style of the specified result row
// 
// row: object reference to the table row to be toggled
// nextRow: if true, toggle the nextrow as well, otherwise toggle the previous
//			row
//
function toggleRow(row,nextRow) {
	if ( row.className == 'results' ) {
		row.className = 'results-hover';
		if ( nextRow ) {
			row.nextSibling.className = 'results-hover';
		} else {
			row.previousSibling.className = 'results-hover';
		}
	} else {
		row.className = 'results';
		if ( nextRow ) {
			row.nextSibling.className = 'results';
		} else {
			row.previousSibling.className = 'results';
		}
	}
}

