/*
 Author:
	RUS
 Created:
	04-JAN-2005
 Description:
	Common javascript validation functions are defined here
 Parameters:
	
 Usage:
 	include the script file using <script src=""> tag

 Modifications: 
	
*/

	/*
	  Purpose	 : function to validate selection box
				   function checks for the value of the currently selected item
				   if the item value is -1 error message string is displayed
	  Parameters :
				   pObjSelectionbox selection box object
				   pstErrorMessage  error message string to be displayed

	  Returns	 :
					boolean
					true if valid selection is selected in the drop down
					false if invalid selection is selected in the drop down
				
	*/
		
		function validateSelectBox(pObjSelectionbox,pstErrorMessage)
		{
			
			if(pObjSelectionbox.options[pObjSelectionbox.selectedIndex].value==0)
			{
					alert(pstErrorMessage);
					pObjSelectionbox.focus();
					return false;
			}
			return true;
		}
		function validateSelectBox1(pObjSelectionbox)
		{
			
			if(pObjSelectionbox.options[pObjSelectionbox.selectedIndex].value==0)
			{
					
					return false;
			}
			return true;
		}
		
	/*
	  Purpose	 : function to validate text box
	  Parameters :
				   pObjTextbox text box object
				   pstErrorMessage  error message string to be displayed

	  Returns	 :
					boolean
					true if not text box is not empty
					false if text box is empty
				
	*/
		function validateTextBox(pObjTextbox,pstErrorMessage)
		{
			
			if(trimchar(pObjTextbox.value)=="")
			{
					alert(pstErrorMessage);
					pObjTextbox.focus();
					return false;
			}
		
			return true;
		}
		
		
		
		/*
	  Purpose	 : function to validate text box
	  Parameters :
				   pObjTextbox text box object
				   pstErrorMessage  error message string to be displayed when textbox is empty
				   pstErrorLentghMessage  error message string to be displayed when textbox  length is greater than the specified value
				   pinMaxLength  maximum length for the textbox
	  Returns	 :
					boolean
					true if not text box is not empty or length is less than Maximum length of textbox
					false if text box is empty or length is greater than maximum length of textbox
				
	*/
		function validateTextBox1(pObjTextbox,pstErrorMessage,pstErrorLengthMessage,pinMaxLength)
		{
			if(trimchar(pObjTextbox.value)=="")
			{
					alert(pstErrorMessage);
					pObjTextbox.focus();
					return false;
			}
			else
			{
				if(trimchar(pObjTextbox.value).length > pinMaxLength)
					{
					
						alert(pstErrorLengthMessage);
						pObjTextbox.focus();
						return false;
					}
			}
		
			return true;
		}
			
	/*
	  Purpose	 : function to trim a string
	  Parameters :
				   
	  Returns	 :
					boolean
					true if valid selection is selected in the drop down
					false if invalid selection is selected in the drop down
				
	*/
		function trimchar(pstr)
		{
			var lenstr = pstr.length;
			for(var i = 0 ; pstr.charAt(i) == " "; i++);
			for(var j = pstr.length - 1; pstr.charAt(j)== " "; j--);
			j++;
			if (i > j)
				pstr = "";
			else
				pstr = pstr.substring(i,j);
			return pstr;
		}
			/*
	  Purpose	 : to check a string is null 
	  Parameters :
				   
					String
	  Returns	 :
				  true or false;
				  true if null else false
	*/
	function isNull(aStr)
	{
		var index;
		for (index=0; index < aStr.length; index++)
			if (aStr.charAt(index) != ' ')
			return false;
		return true;
	}
	/*
	  Purpose	 : to check a maximum length of the string 
	  Parameters :
				   
					String
	  Returns	 :
				  true or false;
				  true if equal to maximum length  else false
	*/
	function isMaxLen(aStr,pinMaxLength)
	{
		if(trimchar(aStr)!="")
			{
				if(trimchar(aStr).length > pinMaxLength)
					{
					return false;
					}
			}
		else
		{
		return true;
		}	
	}
	

