

	/**
	*The function is used trapping any key press over the text box
	*@param: event to be checked and the field 
	*/
	function entergoto(field, event) 
	{
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) 
		{
			gobtn();
		}
	}
	
	/**
	*The function is used for checking whether the passed argument is a number.
	*@param: string to be checked
	*/
	function isnumber(txtValue)
	{
		var hiFlag = false;
		for(v=0; v < txtValue.length; v++)
		{
			chc=txtValue.charAt(v);
	        if(chc == '-')
	        {
	        	hiFlag = true;
	        }
	        if((chc>='0' && chc<='9')||(chc>= 'A' && chc <= 'Z')||(chc>= 'a' && chc <= 'z')||(chc == '-')||(chc == ' ')||(chc == '\'')||(chc == '&')||(chc == '.')||(chc == ','))	
	        {
	           	continue;
	       	}
		    else
		    {
		       return false;
			}
		}  
       	var oldValue = document.PhotoLibSimSearchForm.simsearch1.value;			 
		for(v=0; v < txtValue.length; v++)
		{		 
   	        chc=txtValue.charAt(v);
   	        if(hiFlag && chc == '-')
   	        {  
				var newValue = oldValue.replace('-','$');
				document.PhotoLibSimSearchForm.simsearch.value = newValue;
	         	oldValue=newValue;
			}
   			else 
   			{
   				document.PhotoLibSimSearchForm.simsearch.value=oldValue;
			}
   		}
   		var chkValue = document.PhotoLibSimSearchForm.simsearch.value;
   		chkValue=chkValue.replace('\'','\'\'');
   		document.PhotoLibSimSearchForm.simsearch.value = chkValue;
		return true;
	}


/*
		JIRA # 		- PHOTOLIB-113
		Description - Framework team needs to gather statistics regarding searches in Photo Library. 
					  Current simple search page and advanced search page does not have the search 
					  term in the URL.We need to have the search term in the URL so that framework 
					  can track what is the search term used.
		Author Name - K.Rajendra Babu
*/				


	/**
	*The function is used for doing all the validation and submits the form.
	*/
	function gobtn()
	{
		var stringVal = document.PhotoLibSimSearchForm.simsearch1.value
		if(checkForEmptyString(stringVal))
		{
			var txtValue= document.PhotoLibSimSearchForm.simsearch1.value;
			var flagForValue = isnumber(txtValue);
			if(flagForValue)
			{	
				document.PhotoLibSimSearchForm.action="http://secure.worldbank.org/photolibrary/servlet/main?menuPK=148507&theSitePK=265652&pagePK=50039804&piPK=50039803"
				document.PhotoLibSimSearchForm.method="POST";
				document.PhotoLibSimSearchForm.submit();
			}
			else
			{
				alert("Please enter the correct value.");
				return false;
			}
		}
		else
			return false;
	}
	/**
	*The function is used for checking empty String.
	*@param: string to be checked
	*/
	function checkForEmptyString(strValue)
	{
		var sLeftTrim = leftTrim(strValue)
		var sRightTrim = rightTrim(strValue)
		if(sRightTrim.length == 0)
		{
			alert("Please enter the correct value")
			return false;
		}
		else
			return true;
		
	}
	/**
	*The function is used for left trimming entered String value.
	*@param: string to be trimmed
	*/
	function leftTrim(strV)
	{			
		strL=strV;
		while(strL.length > 0 && strL.charAt(0) == " ")
		{
			strL=strL.substring(1,strL.length);
		} 
		return strL;
	}
				
	/**
	*The function is used for right trimming entered String value.
	*@param: string to be trimmed
	*/
	function rightTrim(strV)
	{
		strL=strV;
		while(strL.length > 0 && strL.charAt(strL.length - 1) ==" ")
		{
			strL=strL.substring(0,strL.length-1);
		}
		return strL;
	}

