//---------------------------------------------------------------------------------------------------------
//	String functions
//---------------------------------------------------------------------------------------------------------
function str_trim( str )
{
	var resultStr = "";
	
	resultStr = str_trimleft(str);
	resultStr = str_trimright(resultStr);
	
	return resultStr;
} 

function str_trimleft( str )
{
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
	{
		return null;
	}

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
	{
		resultStr = "";
	}
	else
	{	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
		{
			i++;
		}

	   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
} 

function str_trimright( str )
{
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
	{
		resultStr = "";
	}
	else
	{
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
		{
 			i--;
		}
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
} // end TrimRight


function str_replacechar( findchar, replacestring, searchstring )
{
	newstring = "";
	for ( c=0; c < searchstring.length ; c++ )
	{
		string_char = searchstring.charAt( c );
		if (  string_char == findchar )
		{
			newstring = newstring + replacestring;
		}
		else
		{
			newstring = newstring + string_char;
		}
	}

	return newstring;
}

//---------------------------------------------------------------------------------------------------------
//	Window functions
//---------------------------------------------------------------------------------------------------------
function openWindow(url,name,sizeX,sizeY)
{
	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

	//	Open the window
	winobject	= window.open(url,name,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos);
	winobject.focus();
}

//---------------------------------------------------------------------------------------------------------
//	Validation functions
//---------------------------------------------------------------------------------------------------------
function is_valid_date( testdate )
{
	testdate = new Date( testdate );
	return ( testdate != 'NaN' )
}

//---------------------------------------------------------------------------------------------------------
//	Swap Image source
//---------------------------------------------------------------------------------------------------------
function changeImgSrc( obj, source )
{
	obj	= document.getElementById(obj);
	obj.setAttribute('src', source );
}

