	
	/**
	 *  Function to set the default value of a text field.
	 *  This will ensure that:
	 *   - The value of the text field is set to the default string on page load (as long as there isn't already a value in place)
	 *   - When the user clicks in the text field, if the value is the default string, the text field is emptied
	 *   - When the user clicks out of the text field, if the field is empty it's set back to the default again
	 *
	 * @author       Tom McQuarrie <tom@webxpress.com.au>
	 * @copyright    WebXpress 2009
	 */
	function textfield_setDefaultValue( id, text )
	{
		/** grab the specified field */
		var txt = document.getElementById(id);
		
		/** make sure the field exists */
		if( txt )
		{
			/** function to check the current field value and update accordingly */
			txt.checkChange = function()
			{
				if( this.value == this.defaulttext )
				{
					if( this.f && !this.k ) this.value = '';
					
					this.addClass( 'textfieldDefaultValue' );
				}
				else if( this.value == '' )
				{
					if( ! this.f ) this.value = this.defaulttext;
					
					this.addClass( 'textfieldDefaultValue' );
				}
				else
				{
					this.removeClass( 'textfieldDefaultValue' );
				}
			}
			
			/** use the check function on keyup */
			txt.onkeyup = function()
			{
				this.k = true;
				this.checkChange();
				this.k = false;
			}
			
			/** use the check function on focus */
			txt.onfocus = function()
			{
				this.f = true;
				this.checkChange();
			}
			
			/** use the check function on blur */
			txt.onblur = function()
			{
				this.f = false;
				this.checkChange();
			}
			
			/** add a class to this element */
			txt.addClass = function( cls )
			{
				var oldClass = this.className;
				
				oldClass = oldClass.split( ' ' );
				
				for( var i=0; i<oldClass.length; i++ )
				{
					if( oldClass[i] == cls ) return; 
				}
				
				this.className += ' '+cls;
			}
			
			/** remove a class from this element */
			txt.removeClass = function( cls )
			{
				var oldClass = this.className;
				
				oldClass = oldClass.split( ' ' );
				
				var newClass = [];
				
				for( var i=0; i<oldClass.length; i++ )
				{
					if( oldClass[i] !== cls ) newClass.push( oldClass[i] );
				}
				
				this.className = newClass.join( ' ' );
			}
			
			/** if the field is empty */
			if( txt.value == "" )
			{
				/** set it to the default text */
				txt.value = text;
			
				/** add the default field class */
				txt.addClass( 'textfieldDefaultValue' );
			}
			
			/** set focused status to false */
			txt.f = false;
			
			/** set keyup status to false */
			txt.k = false;
			
			/** store the default text in the DOM of the field so we can retrieve it later */
			txt.defaulttext = text;
		}
	}