function getElement(name) {
if (document.getElementById) {
return document.getElementById(name);
} else if (document.all) {
return document.all[name];
}

return null;
}

function submitSearch() {
control = getElement("search");
if (!requiredField(control, "Search Site")) {
return false;
}

if ( control.value.length < 5 ) {
alert("Searched phrase is too short.");
return false;
}

// alert(control.value);
window.location.href = "search.php?q=" + control.value;
control.value = "";
return false;
}

function Trim(s) {	
	if (typeof(s) != "string")
		return null;
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function showError(control, msg) {
	alert(msg);
	control.focus();
	if (control.select)
		control.select();				
}

function getFieldValue(control) {
	if (control.options) {
		return control.options[control.selectedIndex].value;
	} else {
		control.value = Trim(control.value);
		return control.value;
	}
}

function requiredField(control, name) {
	if (!control) {
		alert(name + " field is missing.");
		return false;
	}
	
	value = getFieldValue(control);
	if (value.length == 0) {
		showError(control, name + " field is required.");
		return false;
	}
	
	return true;
}
