﻿function getDateTimeNow() {
	var now = new Date();

	var year = now.getYear(); // 年
	// FirefoxなどECMAscript系のブラウザでは紀元1900年からの年を返すので対応
	if ( year < 1900 ) { 
		year += 1900;
	}
	var month = now.getMonth() + 1; // 月
	var day = now.getDate(); // 日
	var hour = now.getHours().toString(); // 時
	if ( hour.length == 1 ) {
		hour = "0" + hour;
	}
	var min = now.getMinutes().toString(); // 分
	if ( min.length == 1 ) {
		min = "0" + min;
	}
	var sec = now.getSeconds().toString(); // 秒
	if ( sec.length == 1 ) {
		sec = "0" + sec;
	}

	dojo.byId("mainphoto_date").innerHTML = year + "年" 
		+ month + "月"
		+ day + "日"
		+ hour + ":"
		+ min + ":"
		+ sec + "現在";
}

function getJobTotalCountNow() {
	dojo.xhrPost({
		preventCache: true,
		url: "./ajax_php/getJobTotalCountNow.php",
		handleAs: "json",
		load: function (response, args) {
			dojo.byId("mainphoto_number").innerHTML = response;
			return response;
		},
		//無限の待機を防ぐために、エラー処理とタイムアウトは必須
		error: function (response, args) {
			console.debug("以下のエラーが発生しました。", data);
			return response;
		},
		timeout: 5000
	});
}

dojo.addOnLoad( function() {
	setInterval(getDateTimeNow, 1000);
	setInterval(getJobTotalCountNow, 1000);
});