// JavaScript Document
function strftime()	// JavaScript
{
	var $argc = strftime.arguments.length;
	var $argv = strftime.arguments;
	if ($argc==0) $t = _strftime("TZ");
	if ($argc==1) $t = _strftime("TZ",$argv[0]);
	if ($argc==2) $t = _strftime("TZ",$argv[0],$argv[1]);
	return $t;
}
function gmstrftime()	// JavaScript
{
	var $argc = gmstrftime.arguments.length;
	var $argv = gmstrftime.arguments;
	if ($argc==0) $t = _strftime("UTC");
	if ($argc==1) $t = _strftime("UTC",$argv[0]);
	if ($argc==2) $t = _strftime("UTC",$argv[0],$argv[1]);
	return $t;
}

function _strftime()	// JavaScript
{
	var $argc = _strftime.arguments.length;
	var $argv = _strftime.arguments;
	if ($argc == 1)
	{
		$my_format = "%Y-%m-%d %H:%M:%S";
		$my_time = Number(new Date());
	}
	else if ($argc == 2)
	{
		$my_format = $argv[1];
		$my_time = Number(new Date());
	}
	else
	{
		$my_format = $argv[1];
		$my_time = $argv[2];
	}
	if ($my_time === false)
	{
		return " &nbsp;";
	}
	$my_time = new Date($my_time*1000);
	$my_format = $my_format.replace("%D", "%m/%d/%y");
	$my_format = $my_format.replace("%r", "%I:%M:%S %p");

	if ($argv[0] == "TZ")
	{
		$my_format = $my_format.replace("%Y", "" + $my_time.getFullYear());
		$my_format = $my_format.replace("%y", "" + $my_time.getFullYear());
		$my_format = $my_format.replace("%m", pre0($my_time.getMonth()+1, 2));
		$my_format = $my_format.replace("%d", pre0($my_time.getDate(), 2));
		$my_format = $my_format.replace("%H", "" + pre0($my_time.getHours(), 2));
		$my_format = $my_format.replace("%M", "" + pre0($my_time.getMinutes(), 2));
		$my_format = $my_format.replace("%S", "" + pre0($my_time.getSeconds(), 2));
		$my_format = $my_format.replace("%I", "" + (($my_time.getHours() + 11) % 12 + 1));
		$my_format = $my_format.replace("%p", "" + ($my_time.getHours() < 12 ? "AM" : "PM"));
		$my_format = $my_format.replace("%B", "" + getLang("months_long").split(",")[$my_time.getMonth()]);
		$my_format = $my_format.replace("%b", "" + getLang("months_short").split(",")[$my_time.getMonth()]);
		$my_format = $my_format.replace("%A", "" + getLang("day_long").split(",")[$my_time.getDay()]);
		$my_format = $my_format.replace("%a", "" + getLang("day_short").split(",")[$my_time.getDay()]);
		$my_format = $my_format.replace("%%", "%");
	}
	if ($argv[0] == "UTC")
	{
		$my_format = $my_format.replace("%Y", "" + $my_time.getUTCFullYear());
		$my_format = $my_format.replace("%y", "" + $my_time.getUTCFullYear());
		$my_format = $my_format.replace("%m", pre0($my_time.getUTCMonth()+1, 2));
		$my_format = $my_format.replace("%d", pre0($my_time.getUTCDate(), 2));
		$my_format = $my_format.replace("%H", "" + pre0($my_time.getUTCHours(), 2));
		$my_format = $my_format.replace("%M", "" + pre0($my_time.getUTCMinutes(), 2));
		$my_format = $my_format.replace("%S", "" + pre0($my_time.getUTCSeconds(), 2));
		$my_format = $my_format.replace("%I", "" + (($my_time.getUTCHours() + 11) % 12 + 1));
		$my_format = $my_format.replace("%p", "" + ($my_time.getUTCHours() < 12 ? "AM" : "PM"));
		$my_format = $my_format.replace("%B", "" + getLang("months_long").split(",")[$my_time.getUTCMonth()]);
		$my_format = $my_format.replace("%b", "" + getLang("months_short").split(",")[$my_time.getUTCMonth()]);
		$my_format = $my_format.replace("%A", "" + getLang("day_long").split(",")[$my_time.getUTCDay()]);
		$my_format = $my_format.replace("%a", "" + getLang("day_short").split(",")[$my_time.getUTCDay()]);
		$my_format = $my_format.replace("%%", "%");
	}
	return $my_format;

}
function pre0($v,$l)	// JavaScript
{
	$v = "" + $v;
	if ($v.length < $l) {
		for (var $i=0; $i<($l-$v.length); $i++)
			$v = "0" + $v;
	}
	return $v;
}
function getLang(a)	// JavaScript
{
	if (typeof(cal_text) == 'object')
	{
		switch (a)
		{
			case "day_short":
			case "day_long":
			case "months_short":
			case "months_long":
			{
				return cal_text[a];
			}break;
			default:
				return "undef";
		}
	}
	else
	{
		var $b;
		return typeof($b);
	}
}

