// ================================
// Functions
// ================================

// グローバル変数
//// パス
var PATH = '';
//// 画像のファイル名
var NUMBER_URL = new Array("0.gif", "1.gif", "2.gif", "3.gif", "4.gif", "5.gif", "6.gif", "7.gif", "8.gif", "9.gif");
var WEEKDAY_URL = new Array("daySun.gif", "dayMon.gif", "dayTue.gif", "dayWed.gif", "dayThu.gif", "dayFri.gif", "daySat.gif");
// パスの定義
function setPath(path)
{
	PATH = path;
}

// 日付の描画
function drawDate(strYear, strMonth, strDate, nWeekday, strHour, strMinute, strSecond)
{
	var output = '<img src="' + PATH + '/images/dateHead.gif" />';
	output += replaceNumber(strYear) + '<img src="' + PATH + '/images/period.gif" />';
	output += replaceNumber(strMonth) + '<img src="' + PATH + '/images/period.gif" />';
	output += replaceNumber(strDate);
	//output += '<img src="' + PATH + '/images/' + WEEKDAY_URL[getWeekday(Number(strYear), Number(strMonth), Number(strDate))] + '" />';
	output += '<img src="' + PATH + '/images/' + WEEKDAY_URL[nWeekday] + '" />';
	output += replaceNumber(strHour) + '<img src="' + PATH + '/images/colon.gif" />';
	output += replaceNumber(strMinute) + '<img src="' + PATH + '/images/colon.gif" />';
	output += replaceNumber(strSecond);
	document.write(output);
}
// 数文字列を画像タグに置き換え
function replaceNumber(str)
{
	var output = '';
	for(var i = 0; i < str.length; i++)
	{
		var n = str.substr(i, 1);
		if(0 <= n && n <= 9)
		{
			output += '<img src="' + PATH + '/images/' + NUMBER_URL[n] + '" alt="' + n + '" />';
		}
	}
	return output;
}
// 曜日の算出
function getWeekday(year, month, date)
{
	if (month <= 2)
	{
		year--;
		month += 12;
	}
	var weekday = (year + Math.floor(year / 4) - Math.floor(year / 100) + Math.floor(year / 400) + Math.floor((13 * month + 8) / 5) + date) % 7;
	return weekday;
}
