/* 	******************************************************** 
	****	Talossan Decimal Time Javascript Library 	**** 
	********************************************************
	Created by FreeXenon Consulting 
	Last Modified: 2005.10.31 @800 TST
	
	Talossan Standard Time based off of the following sources
	Swatch Internet Time 
		src: http://www.swatch.com/internettime/
	which is modifed to Greenwich Mean Time (GMT) +0 
		src: http://wwp.greenwichmeantime.com/
	instead of Biel Mean Time (BMT) which was equal to GMT +1
	****											**** */
	
function getDateTimeGMT0(convDate)
	/* ****	function getDateTime0GMT 	****
	Description:
		Obtains the value of the date object in milliseconds and subtracts the Time Zone Offset in milliseconds
		so that we can work with Talossan Standard Time which is equal to Greenwich Mean Time +0
		Returns Date object set to GMT +0 even though the Date object itself says the local GMT. 
		The date object that is retured is still in Local Standard Time which is modified to be GMT +0.
	
	Arguments: 	- convDate (Date Object) the date to be converted
	
	Return: 	- a date object with the current time set to +0 GMT
				- null if parameter convDate is not a Date Object
	****								**** */
{
	if ( TypeOf(convDate) == "Date") 
	{
		convDate.setTime ( convDate.getTime() + (convDate.getTimezoneOffset() * 60 * 1000) );
		return convDate;
	}
	else return null;
} // end getDateTimeGMT0()


function CutDecimals(n, count)
	/* 	****	function CutDecimals(n, count)	****
	Description: 
		Truncates a given number to n decimal places 
	****									**** */
{
    var str = n.toString();
    var pos = str.indexOf(".");
	
    if ( pos > 0 )
    {
        if ( count < 1 )
        {
    		str = str.substr(0, pos -1 )
        }
        else
        {
    		str = str.substr(0, pos + count + 1);
        }
    }
	
	/* Add leading Zeros to time */
	if ( str.match(/^\d{1}\./) ) str = "0" + str;
	if ( str.match(/^\d{2}\./) ) str = "0" + str;
    return str;
} // end CutDecimals()


function ToDecimalTime(dateIn)
	/* 	****	function toDecimalTime 	****
	Description: 
		Converts the time of the date object parameter (dateIn) to seconds and then divides that total by 86.4 
		to get the number of beats. A beat is equal to 1 minute 26.4 seconds of non-decimal time.
	
	Arguments: 	- dateIn - Date Object
	
	Return: 	- String of time in decimal format
	****							**** */
{
	var beat = ( dateIn.getHours() * 3600 + dateIn.getMinutes() * 60 + dateIn.getSeconds() ) / 86.4;
    return beat;
} // end ToDecimalTime()


function TSTtime(dateTST)
/* 	****	function TSTtime(dateTST)	****
	Description:
		Takes the Date object (dateTST) and passes it into ToDecimalTime which will convert dateTST to its 
		decimal time equivalent as referenced fron +0 GMT and then truncates the result at 2 decimal places.
		An Ampersand (@) is added to the front of the result to designate it as a Decimal Time Format.
	
	Arguments:	- dateTST - Date Object
	
	Return:		- A string with the time of the Date Object (dateTST) as referenced from +0 GMT 
					in decimal format (ie @123.12)
				- null if the parameter dateTST is not a Date Object
	****								**** */
{
	if ( TypeOf(dateTST) == "Date") 
		return "@ " + CutDecimals( ToDecimalTime(dateTST) , 2);
	else return null;
} // end TSTTime()
