﻿function Search(){
    if (CheckForm())
        window.location='SearchResults.aspx?Vl=S&Srch='+ document.getElementById('txtSearch').value;
}

//Check the form before submitting
function CheckForm () {

	//Check for a word to search
var SrchVal = trim(document.getElementById('txtSearch').value);
	if (SrchVal.length==0){
		alert("Please enter at least one keyword to search");
		document.getElementById('txtSearch').value="";
		document.getElementById('txtSearch').focus();
		return false;
	}
	
	return true
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}