// Tool:   GDK_FORMATTING.js
// Author: Anthony James Blackshaw
// Date:   11-2002

// Getme Ltd (c)2002. All rights reserved.

/*
The GDK_FORMATTING object supports for the formatting of data via the client-side
browser.
*/

/*
	<script type="text/javascript" src="GDK_formatting.js"></script>

	<script type="text/javascript">
	<!--
			
		formatting = new GDK_FORMATTING();
			
	-->
	</script>
*/

function GDK_FORMATTING()
	{
	// Public
		
	// Properties
	this.version = 0.1;
	
	// Methods
	this.lTrim   = lTrim_GDK_FORMATTING;
	this.rTrim   = rTrim_GDK_FORMATTING;
	this.trim    = trim_GDK_FORMATTING;
	this.removeWhitespaces = removeWhitespaces_GDK_FORMATTING;
	this.hex2Dec = hex2Dec_GDK_FORMATTING;
	this.dec2Hex = dec2Hex_GDK_FORMATTING;	
	
	// Private
	
	// Properties
	this._hex = new Array
		( 
		'0',
		'1',
		'2', 
		'3', 
	 	'4', 
		'5',
		'6', 
		'7', 
		'8',
		'9', 
		'A', 
		'B', 
		'C', 
		'D',
		'E',
		'F' 
		);

	// Methods
		
	}
	
function lTrim_GDK_FORMATTING( str )
	{
	// Trim all white spaces left of string
	return str.replace( /^\s*/, "" );
	}

function rTrim_GDK_FORMATTING( str )
	{
	// Trim all white spaces right of string
	return str.replace( /\s*$/, "" );
	}

function trim_GDK_FORMATTING( str )
	{
	// Trim all white space both left and right of string
	return this.rTrim( this.lTrim( str ) );
	}
	
function removeWhitespaces_GDK_FORMATTING( str )
	{
	// Trim all white from the string
	return str.replace( /\s*/g, "" );
	}
	
function hex2Dec_GDK_FORMATTING( str )
	{
	// Convert hexidecimal value to decimal value
	return parseInt( str, 16 );
	}
	
function dec2Hex_GDK_FORMATTING( str )
	{
	hexStr = '';
	
	// Convert decimal value to hexidecimal value
	do
		{
		// Divide str by 16, then round down
		roundedDown = Math.floor( str / 16 );
			
		// Calculate the difference between str and roundedDown
		difference = str - ( roundedDown * 16 );
			
		// Lookup difference aa hex value, append the value to hexStr
		hexStr = this._hex[ difference ] + hexStr;
			
		// Move str to next digit
		str = roundedDown;
		}
		while( roundedDown > 15 ); // Repeat until last digit
	
	// Append the final left digit to hexStr
	hexStr = this._hex[ str ] + hexStr;
	
	return hexStr;
	}