// ************************************************************************************************
// *** Groups utilities methods
// ************************************************************************************************

function FormatTools() {
	// ************************************************************************************************
	// *** Interface
	// ************************************************************************************************	

	this.formatSeconds = tools_FormatSeconds;
	this.getSubstring = tools_GetSubstring;
	
	
	// ************************************************************************************************
	// *** Implementations
	// ************************************************************************************************
	
	// Formats the seconds passed as argument to hh:mm:ss format (hh just appears if the number of hours is greater than 0)
	function tools_FormatSeconds(seconds) {
		var hrs, min, sec;
		
		// Hours
		hrs = parseInt(seconds / 3600);
		
		// Minutes
		seconds = seconds % 3600;
		min = parseInt(seconds / 60);
		if(min < 10) 
			min = '0' + min;
		
		// Seconds
		sec = parseInt(seconds % 60);
		if(sec < 10) 
			sec = '0' + sec;
		
		// Formatted string
		return ((hrs > 0) ? (hrs + ':') : '') + min + ':' + sec;
	}
	
	//gets substring and adds sufix to it
	function tools_GetSubstring(text, length, sufix)
	{
		if((length - sufix.length) < sufix.length)
		{
			return ("");
		}
		
		if(text.length > length)
		{
			return (text.substring(0, length - sufix.length) + sufix);
		}

		return (text);
	}
}

