function getStardate(year, month, day, hour)
{
/*----------------------------------------------------------------------------
	Stardate script copyright(c) 2009 Steven Roper.
	Contact: stever@starburstpublishing.com.au.
	Released under Creative Commons by-nc-sa License as shown at
	http://creativecommons.org/licenses/by-nc-sa/3.0/
	
	Notes:
	This script calculates ST:TNG/VOY style stardates from either the current
	date or a provided date. It accepts a date as 4 integers, as follows:
	year: in YYYY format (eg 2009)
	month: in MM format (eg 6)
	day: in DD format (eg 12)
	hour: in 24 hour hh format (eg 15)
	If it is called with no parameters, the script will return the stardate
	for the current date and time.
	
	Stardates are largely arbitrary, although the ST:TNG/VOY stardates followed
	a basic convention:
	- The first digit is the century following 1900, so in TNG these started
	with 4, representing the 24th century.
	- The second digit is the "season", ostensibly a year, although this is
	questionable in the context of the Star Trek universe as discussed below.
	- The next three digits are a number from 000 to 999, increasing apparently
	at random during the course of a season, representing the "day" of the
	season.
	- The digit after the decimal point is supposedly a tenth of a "day".
	
	In designing this script I ran into a few problems. If we assume that
	the second digit represents a year, and the next three represent the day of
	that year, the stardate misses out the decade. This means that every ten
	years within a century, the stardate would reset to the same as it was ten
	years before. In Voyager, the year that would have been the 10th season of
	TNG simply wrapped into the century digit; that is, the 4 became 5. The
	problem with following this method for this script is that the century digit
	for this century (the 21st century) would have become 2 (representing the
	22nd century) by 2010, and 4 (representing the 24th century) by 2040. This
	meant that I could not use Voyager's convention here.
	
	However, I noted a quote by Gene Roddenberry, as follows:
		"...One hour aboard the USS Enterprise at different times may equal as
		little as three Earth hours..."
		(Gene Roddenberry, "The Making of Star Trek", Whitfield 1991)
	Ah, time dilation! From this, it follows that if 1 hour on the Enterprise
	= 3 hours on Earth, then 1 day on the Enterprise = 3 days on Earth. This led
	to the following solution:
	
	If a "season" becomes a decade on Earth (thus a little over 3 years on the
	Enterprise), then the next three digits would be thousandths of a decade.
	A thousandth of a decade is 3.652 or 3.653 days - very close to the time
	dilation ratio envisioned by Roddenberry above. The decimal place digit then
	becomes a tenth of this 3.65x day period. This also resolved the thousandths
	of a decade digits having to wrap at 365/366 if they represented day-of-year.
	
	Therefore this is the solution I've implemented in this script, so:
	- The first digit is the century, 1 = 21st century.
	- The second digit is the decade.
	- The next three digits are the thousandths of a decade that have elapsed
	since the start of the decade (millidecades = 3.652 or 3.653 days).
	- The decimal point digit is tenths of a millidecade (= period of about 8.76
	hours.)
----------------------------------------------------------------------------*/

	Date.prototype.getDayOfYear = function()
	{
		var start = new Date(this.getFullYear(),0,1);
		return Math.ceil((this - start) / 86400000);
	}
	var today = new Date();
	
//Set date to parameters if given
	if (year)
	{
		if (year < 100){year += 2000;}
		today.setFullYear(year);
	}
	if (month){today.setMonth(month);}
	if (day){today.setDate(day);}
	if (hour){today.setHours(hour);}
	
	var toyear = today.getFullYear();
	
//Get century digit
	var century = (toyear - 1900) / 100; century = parseInt(century.toString());
	
//Get decade digit	
	var decade = parseInt((toyear.toString()).substr(2, 1));
	
//Get thousandths-of-decade digits
	var daysindec = 0;
	if (((decade * 10) % 20)){daysindec = 3652;}
	if(!(toyear % 100) && (toyear % 400)){daysindec = 3652;}
	else{daysindec = 3653;}
	var startofdec = (parseInt(parseFloat(toyear) / 10.0)) * 10;
	var yearofdec = toyear - startofdec;
	var dayofdec = 0; var chkyear = 0; var dayadd = 0;
	for (i = 0; i < yearofdec; i++)
	{
		chkyear = startofdec + i;
		if (chkyear % 4){dayadd = 365;}
		else{if(!(chkyear % 100) && (chkyear % 400)){dayadd = 365;}
		else{dayadd = 366;}}
		dayofdec += dayadd;
	}
	dayofdec += today.getDayOfYear();
	var millidec = parseInt((dayofdec / daysindec) * 1000);

//Get decimal point digit	
	var hrsinmd = (daysindec * 24) / 1000;
	var hrsover = (dayofdec - ((millidec / 1000) * daysindec)) * 24 ;
	var tenth = parseInt((hrsover / hrsinmd) * 10);
	if (millidec < 10){millidec = '00'+millidec.toString();}
	else{if(millidec < 100){millidec = '0'+millidec.toString();}
	else{millidec = millidec.toString();}}

	return century.toString() + decade.toString() + millidec + '.' + tenth.toString();
}

