var TE_search_submitOK = true;

document.getElementById("TE_searchForm").onsubmit = TE_submitSearch;

function TE_submitSearch()
{   
    // leave if button is disabled - shouldn't be here...
	if (!TE_search_submitOK){
		return false;
	}
    
    // Prevent another quick submit and submit this question
    TE_disableSearch();  
    
	// Strip leading and trailing whitespace of all kinds
	var qboxValue = document.getElementById("TE_searchBox").value.replace(/^\s+/g,'').replace(/\s+$/g,'');
	document.getElementById("TE_searchBox").value = qboxValue;
    
	if (qboxValue.length > 0) {
		// Post the search to the page
    	document.getElementById("TE_searchForm").submit();
		
    	// Wait 10 seconds before submit available
    	setTimeout("TE_enableSearch();", 10000);
	} else {
		TE_enableSearch();
	}
	
    return false;
}


/***
 * Disable the search button.
 ***/
function TE_disableSearch()
{
	TE_search_submitOK = false;
	document.getElementById("TE_searchButton").disabled = true;
}

/***
 * Enable the search button.
 ***/
function TE_enableSearch()
{
	TE_search_submitOK = true;
	document.getElementById("TE_searchButton").disabled = false;
}
