/*
	Sets cookie storing state of a hideable control
*/
function fwes_setDisplayCookie( name, state )
{
	var expiry = new Date( );
	var nowPlusOneWeek = expiry.getTime( ) + (7* 24 * 60 * 60 * 1000);
	expiry.setTime( nowPlusOneWeek );
	
	document.cookie = "cs_" + name + "=" + state + "; expires=" + expiry.toGMTString( );
}

/* 
	Toggles display (visibility) of an element
	
	Parameters:
		elementId: id of the element as string
 */
function fwes_toggleVisibility( elementId )
{
	var element = document.getElementById(elementId);
	if ( element == null )
		return 0;
		
	if ( element.style.display == "none" )
	{
		element.style.display = "inline";
		fwes_setDisplayCookie( elementId, 1 );
	}
	else
	{
		element.style.display  = "none";
		fwes_setDisplayCookie( elementId, 0 );
	}
		
	return 1;
}


//
// Removes leading whitespaces
//
function LTrim( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace( re, "$1" );
}


//
// Removes ending whitespaces
//
function RTrim( value ) 
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace( re, "$1" );
}


//
// Removes leading and ending whitespaces
//
function trim( value ) 
{
	return LTrim( RTrim( value ) );
}

// Description:	Enables or disables a control based on whether there is any data in any of the text fields or not
// 				Typically used to enable/disable a submit button based on whether a text control contains text or not.
//				Can also be used for enabling / disabling other controls that support the enabled/disabled property.
//
// Arguments:	inputControl is the input control that contains the textual value to check
// 				targetControl is the Id of the control to enable/disable
// Returns:		Nothing, nada, zip, zilgh, rien mon ami
//
function fwes_ConditionalEnable( inputControl, targetControl )
{
	if ( inputControl )
	{
		if ( targetControl )
		{
			inputControl.value = trim( inputControl.value );
			targetControl.disabled = inputControl.value.length >= 1 ? false : true;
		}
	}
}