//################################################################################################################################			
// search_validation_<version>.js
//
// This is the primary validation script for Intranet v2004 screens.
// Each modification needs to be commented in the history below.
// Each modification requires this file be saved as a new version (incremental filename), and should be referenced in the 
// includes/html/javascripts/search_validation_javascripts.asp include file.
//
//################################################################################################################################			
// Modification History:
// Version	Date		Initials	Comments
// v1.00	28/11/2006	SBH			Initial release, based on generic form_validation_07.js, now superceded.
//################################################################################################################################			

//#################################################			
function validateForm(formname) {
	//alert("starting validation for " + formname + "...");

	//#################################################			
	//Validation for search kickoff entry:
	//#################################################			
	if (formname=="BasicSearchForm") {
		//this page features a revealable "searching" div - set it flashing here:
		flash('searching', 1);
		//var strDOM = "searching.style.visibility";
		//eval(strDOM + ' = "hidden";');
			
		var submitOkay = true;
		var fieldValue = eval("document." + formname + ".searchbox.value");
		
		//Prohibit blank search string
		if ( fieldValue == "" ) {
			alert("Please specify a search string.");
			submitOkay = false;
		}
		
		//Prohibit % in search string
		if ( fieldValue.indexOf("%") > -1 ) {
			alert("Sorry, % is an illegal search character, please remove from your search text.");
			submitOkay = false;
		}
		
		//Prohibit ultra-common words in search string unless it's an exact match search:
		//alert(fieldValue.indexOf('"') + " ... " + fieldValue.lastIndexOf('"'));
		var bExactMatch = false;
		if ( fieldValue.indexOf('"') == 0 && fieldValue.lastIndexOf('"') == (fieldValue.length-1)) {
			bExactMatch = true;
		}
		if (bExactMatch == false) {
			var arrCommonWords = new Array("and", "the", "or", "of", "it", "an", "a");
			var strThisCommonWord;
		
			for (var wordLoop = 0; wordLoop < arrCommonWords.length; wordLoop++) {
				strThisCommonWord = " " + arrCommonWords[wordLoop] + " ";
				if (fieldValue.indexOf(strThisCommonWord) > -1) {
					alert("You have entered a very common word (" + strThisCommonWord + ") as part of your search string, please remove from your search text.");
					submitOkay = false;
					break;
				}
			}
		}
		
		//look for prohibited characters in the specified string:
		if (containsProhibitedCharacters("search", fieldValue)) {
			return false;
		}
		
		
		if (submitOkay == false) {
			//this page features a reveal "searching" div, so we need to kill the flash timeout process and re-hide it again now:
			clearTimeout(flashTimeoutID);
			
			var strDOM = "searching.style.visibility";
			eval(strDOM + ' = "hidden";');
		
			return false;
		}
	}
	//#################################################			
	//End of validation for search kickoff entry.	
	//#################################################			

	
	//#################################################	
	//Return to sender:
	//#################################################			
	//debug:
	//return false;
	return true;
}
