/*	
             ID: $Id: Trim.js,v 1.1 2004/02/20 17:23:26 toby Exp $

        Project: InSight
                 Copyright © 2004 PBE Systems Ltd. All rights reserved.

           File: Trim.js

    Description: Javascript string trimming routines

        Created: 28/05/2003
     Created by: Shyama Sundar.S

       Modified: $Date: 2004/02/20 17:23:26 $
    Modified by: $Author: toby $

            Log:
                 $Log: Trim.js,v $
                 Revision 1.1  2004/02/20 17:23:26  toby
                 Initial import of code into CVS.


*/

function funLTrim(strString)
{
	var strWhiteSpace, strTemp;
	var nCount, nLength;

	strWhiteSpace 	= new String(" \t\n\r");
	strTemp 		= new String(strString);

	if (strWhiteSpace.indexOf(strTemp.charAt(0)) != -1) 
	{
		// We have a string with leading blank(s)...
		
		nCount 		= 0;
		nLength 	= strTemp.length;
		
		// Iterate from the far left of string until we don't have any more whitespace...
		while ( nCount < nLength && strWhiteSpace.indexOf( strTemp.charAt( nCount ) ) != -1 )
			nCount++;
		
		// Get the substring from the first non-whitespace character to the end of the string...
		strTemp = strTemp.substring( nCount, nLength );
   }
   return strTemp;
}

function funRTrim(strString)
{
	var strWhiteSpace, strTemp;
	var nLength;

	strWhiteSpace 	= new String(" \t\n\r");
	strTemp 		= new String(strString);
	
	if (strWhiteSpace.indexOf(strTemp.charAt(strTemp.length-1)) != -1) 
	{
		// We have a string with trailing blank(s)...
		
		nLength 		= strTemp.length - 1;       // Get length of string
		
		// Iterate from the far right of string until we don't have any more whitespace...
		while (nLength >= 0 && strWhiteSpace.indexOf(strTemp.charAt(nLength)) != -1)
			nLength--;

		// Get the substring from the front of the string to where the last non-whitespace character is...
		strTemp = strTemp.substring(0, nLength + 1);
	}

   return strTemp;
}

function funTrim(strString)
{
	strString	= funRTrim( funLTrim( strString ) );
	while (strString.indexOf("  ") != -1) 
	{ 
		// Note that there are two spaces in the string - look for multiple spaces within the string
	strString = strString.substring(0, strString.indexOf("  ")) + strString.substring(strString.indexOf("  ") + 1, strString.length); // Again, there are two spaces in each of the strings
	}
	return strString;
}
