/**
 * カレンダーテンプレート読み込み
 *  //カレンダーYUIのWEBパスを設定
 */
YahhoCal.loadYUI(); //カレンダーテンプレート読み込み
var	MapIconUrl = 'http://www.monthlyfukuoka.com/img/icon.gif';
if	(document.all)	{	var	g_EventFuncMap_ = new Object(),	g_EFMC_ = 0;	}
function	addEvent(obj, type, func)	{
	if	(!obj)	{	return	false;	}
	if	(document.all)	{
		var	had, emc;	try	{	had = obj.attachEvent;	}	catch	(e)	{	had = null;	}
		if	(!had)	{	return	false;	}
		if	(obj.eventMark_ == undefined)	{	obj.eventMark_ = ++g_EFMC_;	}
		emc = obj.eventMark_;
		if	(!g_EventFuncMap_[emc])	{
			g_EventFuncMap_[emc] = new Object();	g_EventFuncMap_[emc]["cnt"] = 0;
		}
		g_EventFuncMap_[emc][func] = function(event){func.call(obj, event);};
		g_EventFuncMap_[emc]["cnt"] += 1;
		obj.attachEvent("on" + type, g_EventFuncMap_[emc][func]);
	}	else if	(obj.addEventListener)	{
		obj.addEventListener(type, func, false);
	}	else	{
		return	false;
	}
	return	true;
}
function	checkDate()	{
	var	syear = document.getElementById('syear').value
	,	smonth = document.getElementById('smonth').value
	,	sday = document.getElementById('sday').value
	,	eyear = document.getElementById('eyear').value
	,	emonth = document.getElementById('emonth').value
	,	eday = document.getElementById('eday').value
	,	sdate = syear || smonth || sday ? new Date(syear, smonth-1, sday) : null
	,	edate = eyear || emonth || eday ? new Date(eyear, emonth-1, eday) : null
	,	curd = new Date()
	,	cur = new Date(curd.getFullYear(), curd.getMonth(), curd.getDate())
	;

	var	targetmonth = 3;
	var	date = new Date();
	var	month = date.getMonth();
		date.setMonth(month+targetmonth);
	var	yy = date.getYear();
		if ( yy < 2000 ) yy += 1900;
		mm = date.getMonth() + 1;
		if ( mm < 10 ) mm = "0" + mm;
	var	dd = date.getDate();
		if ( dd < 10 ) dd = "0" + dd;
	var	after3mon = yy+''+mm+''+dd;
		//alert(after3mon+' '+yy+'/'+mm+'/'+dd);
		date.setMonth(month);

		yy = sdate.getYear();
		if ( yy < 2000 ) yy += 1900;
		mm = sdate.getMonth() + 1;
		if ( mm < 10 ) mm = "0" + mm;
		dd = sdate.getDate();
		if ( dd < 10 ) dd = "0" + dd;
	var	ydate = yy+''+mm+''+dd;
	
	if	(!sdate || !edate)	{
		alert('日付を入力して下さい');
		return	false;
	}	else if	(
		sdate.getFullYear() != syear || sdate.getMonth() != smonth-1 || sdate.getDate() != sday
	||	edate.getFullYear() != eyear || edate.getMonth() != emonth-1 || edate.getDate() != eday
	)	{
		alert('不正な日付です');
		return	false;
	}	else if	(edate < sdate)	{
		alert('日付の関係が不正です')
		return	false;
	}	else if	(sdate < cur || edate < cur)	{
		alert('本日以降の日付を入力して下さい。');
		return	false;
	}	else if	((edate.getTime() - sdate.getTime()) < (60*60*24*6*1000))	{
		alert('７日以上の期間を入力して下さい。');
		return	false;
	}	else if (ydate > after3mon)
	{

		alert('予約受付開始日を、本日より3ヶ月以内で検索ください。');
		return	false;
	}
	return	true;
}

addEvent(window, 'load', function(){
	if	(!document.getElementById('se-button'))	{	return;	}
	if	(this.addEventListener)	{
		document.getElementById('se-button').parentNode.addEventListener('submit', function(e){
			if	(!checkDate())	{
				e.preventDefault();
			}
		}, false);
	}	else	{
		document.getElementById('se-button').parentNode.onsubmit = function(){
			return	checkDate();
		};
	}
});

function	checkDate2()	{
	var	syear = document.getElementById('syear2').value
	,	smonth = document.getElementById('smonth2').value
	,	sday = document.getElementById('sday2').value
	,	eyear = document.getElementById('eyear2').value
	,	emonth = document.getElementById('emonth2').value
	,	eday = document.getElementById('eday2').value
	,	sdate = syear || smonth || sday ? new Date(syear, smonth-1, sday) : null
	,	edate = eyear || emonth || eday ? new Date(eyear, emonth-1, eday) : null
	,	curd = new Date()
	,	cur = new Date(curd.getFullYear(), curd.getMonth(), curd.getDate())
	;

	var	targetmonth = 3;
	var	date = new Date();
	var	month = date.getMonth();
		date.setMonth(month+targetmonth);
	var	yy = date.getYear();
		if ( yy < 2000 ) yy += 1900;
		mm = date.getMonth() + 1;
		if ( mm < 10 ) mm = "0" + mm;
	var	dd = date.getDate();
		if ( dd < 10 ) dd = "0" + dd;
	var	after3mon = yy+''+mm+''+dd;
		//alert(after3mon+' '+yy+'/'+mm+'/'+dd);
		date.setMonth(month);

		yy = sdate.getYear();
		if ( yy < 2000 ) yy += 1900;
		mm = sdate.getMonth() + 1;
		if ( mm < 10 ) mm = "0" + mm;
		dd = sdate.getDate();
		if ( dd < 10 ) dd = "0" + dd;
	var	ydate = yy+''+mm+''+dd;

	if	(!sdate || !edate)	{
		alert('日付を入力して下さい');
		return	false;
	}	else if	(
		sdate.getFullYear() != syear || sdate.getMonth() != smonth-1 || sdate.getDate() != sday
	||	edate.getFullYear() != eyear || edate.getMonth() != emonth-1 || edate.getDate() != eday
	)	{
		alert('不正な日付です');
		return	false;
	}	else if	(edate < sdate)	{
		alert('日付の関係が不正です')
		return	false;
	}	else if	(sdate < cur || edate < cur)	{
		alert('本日以降の日付を入力して下さい。');
		return	false;
	}	else if	((edate.getTime() - sdate.getTime()) < (60*60*24*6*1000))	{
		alert('７日以上の期間を入力して下さい。');
		return	false;
	}	else if (ydate > after3mon)
	{

		alert('予約受付開始日を、本日より3ヶ月以内で検索ください。');
		return	false;
	}
	return	true;
}

addEvent(window, 'load', function(){
	if	(!document.getElementById('se-button2'))	{	return;	}
	if	(this.addEventListener)	{
		document.getElementById('se-button2').parentNode.addEventListener('submit', function(e){
			if	(!checkDate2())	{
				e.preventDefault();
			}
		}, false);
	}	else	{
		document.getElementById('se-button2').parentNode.onsubmit = function(){
			return	checkDate2();
		};
	}
});

function	zoomImage(src)	{
	var	wnd = openWindowDocument('about:blank', 'zoom', 'width=600, height=600, menubar=no, toolbar=no, resizable=yes');
	wnd.document.write('<html><head><style type="text/css">'
	+	' body { margin: 0; padding: 0; }'
	+	' img { vertical-align: top; border-style: none; }'
	+	' div { width: 100%; height: 100%; background-color: #808080; text-align: center; }'
	+	' html, body { overflow: hidden; }'
	+	'</style><script type="text/javascript">'
	+	'window.onresize = function(){load();};'
	+	'function load(){var img = document.getElementsByTagName("img")[0], div = img.parentNode;'
	+	'if ((img.width / img.height) < (div.offsetWidth / div.offsetHeight)) {'
	+	' img.style.width = ""; img.style.height = "100%";'
	+	' img.style.marginTop = "0px";'
	+	' }'
	+	'else {'
	+	' img.style.width = "100%"; img.style.height = "";'
	+	' img.style.marginTop = ((div.offsetHeight - ((div.offsetWidth / img.width) * img.height)) / 2)+"px";'
	+	' }'
	+	'}</'+'script></head><body><div>'
	+	'<img onload="load()" src="' + src + '"/>'
	+	'</div></body></html>');
	wnd.document.close();
}

function	openWindowDocument(wurl, wname, wopt)	{
	var	wnd = window.open(wurl, wname, wopt);
	try	{
		wnd.document.open();
	}	catch	(e)	{
		wnd.close();
		while	(!wnd.closed)	{}
		wnd = window.open(wurl, wname, wopt);
		wnd.document.open();
	}
	return	wnd;
}

