/*******************************************************************************
File Name:	infostation.js
Purpose:	Contains JavaScript functions for the infostation service offering
*******************************************************************************/
/*****************************************************
Name:		isValidSearch
Purpose:	To search if the user has entered text to search upon
Input:		N/A
Output:		N/A
/*****************************************************/
function isValidSearch()
{
	var re = /\s/g; 
	var strSearchString = document.frmSearch.txtSearchString.value;
	strSearchString = strSearchString.replace(re,''); 
	if (strSearchString.length == 0) 
	{	
		document.frmSearch.txtSearchString.focus();
		alert("Please enter text to search.");
	}
	else if (isValidSearchChar(document.frmSearch.txtSearchString,1,"enter search criteria"))
		document.frmSearch.submit();
	else return false;
}	 
/************************************************************
Name:		isValidSearchChar
Purpose:	To validate (depending on the type of field) 
			what are the valid characters

Input:		str - The field that is being validated
			req - Required (0 = not required, 1 = required)			
			strInfo - the action of the item (enter/select/click) + the item's name (your First Name)
Output:		True/False if the characters are valid
************************************************************/  
function isValidSearchChar(str,req,strInfo) 
{
	str.value = trimStr(str.value);
	var strValidChar="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz*- ";
	var strValidNum="0123456789/'%" + '"';
	var gchar=str.value;
	var blnCharIsValid = ""
	
	if((req==0) && (str.value=="")) return true;
	if((req==1) && (isWhiteSpace(gchar)))
	{
		showBWCMsg("Please " + strInfo + ".",1,str); 
		return false;
	}
	
	//Numbers are optional in the search, but they cannot be alone so set
	//the flag to false if it isn't a digit or valid char, and only set it 
	//to true is a valid char is found
	for (var i=0; i < gchar.length; i++) 
	{
		temp = "" + gchar.substring(i, i+1);
		if (strValidChar.indexOf(temp) == "-1") 
		{
			if (strValidNum.indexOf(temp) == "-1") 
			{
				blnCharIsValid=false; break;
			}
		}
		else
			blnCharIsValid = true;
	}

	if(blnCharIsValid == "")
		showBWCMsg("Cannot search on numbers alone, please " + strInfo + " correctly.",1,str);
	else if(blnCharIsValid) 
		return true;
	else
		showBWCMsg("Invalid characters used, please " + strInfo + " correctly.",1,str);
	return false;

}
/*******************************************************************************
Name:		onBWCFormLoad
Purpose:	set focus to the first text box on the page
Input:		None
Output:		None
*******************************************************************************/
function onBWCFormLoad()
{
	if (document.frmSearch.txtSearchString !== void 0)
	{
		document.frmSearch.txtSearchString.focus();	
	}
}
