﻿var nowdate = new Date();
var year = nowdate.getFullYear(); // 年
//var newyear = nowdate.getFullYear(); // 年
var mon0  = nowdate.getMonth() + 1; // 月
var mon1  = nowdate.getMonth() + 2; // 月
var mon2  = nowdate.getMonth() + 3; // 月
var mon3  = nowdate.getMonth() + 4; // 月
var mon4  = nowdate.getMonth() + 5; // 月
//var newmon  = nowdate.getMonth() + 1; // 月
var date = nowdate.getDate(); // 日

function yoyakutab(target,newmon){
var newyear = nowdate.getFullYear();
   if(newmon<=0){
		newmon=newmon+12;
		newyear=newyear-1;
		}
		else if(newmon>=13){
		newmon=newmon-12;
		newyear=newyear+1;
		};
		$(function(){
		  $(target).html(+newyear+'年'+newmon+'月');
		});
};

function yoyakuhyou(target,newmon,tab){
var newyear = nowdate.getFullYear();
   if(newmon<=0){
		newmon=newmon+12;
		newyear=newyear-1;
		}
		else if(newmon>=13){
		newmon=newmon-12;
		newyear=newyear+1;
		};
		$(function(){
		  $('#month-tab').html(+newyear+'年'+newmon+'月の予約状況');
		  $('.yoyakutabs a').css('background','url(img/tab-off.jpg)');
		  $(tab).css('background','url(img/tab-on.jpg)');
		  $(target).csv2table('data.csv',
							{
//							col_sep:'\t',
							where : [{'年月日':'>='+(year*10000+mon0*100+date)},'&&',{'年月':'=='+(newyear*100+newmon*1)}],
							select : [0,1,2,3],
							sortable : false,
							onload : function(id,op,data,ary){
								$('table','#'+id).css('width','740px').end()
								$('table','#'+id).css('margin','20px').end()
								$('th','#'+id).css('border','solid 1px #aaa').end()
								$('td','#'+id).css('text-align','left').end()
								$('td:nth-child(1)','#'+id).css('width','100px').end()
								$('td:nth-child(3)','#'+id).css('display','none').end()
								$('td:nth-child(4)','#'+id).css('display','none').end()
								.find('th:contains(年月日)').css('display','none').end() 
								.find('th:contains(年月)').css('display','none').end() 
								.find('tr:contains((土))').css('background','#f5ffd0').end()
								.find('tr:contains((日))').css('background','#fae9d6').end()
								.find('td:contains(ツアー受付不可)').css('background','#dddddd').end()
							}
							}
						);
		});
};

yoyakutab('#yoyakuhyou-title0',mon0);
yoyakutab('#yoyakuhyou-title1',mon1);
yoyakutab('#yoyakuhyou-title2',mon2);
yoyakutab('#yoyakuhyou-title3',mon3);
yoyakuhyou('#hyou',mon0,"#yoyakuhyou-title0");

$(function(){
	$("#yoyakuhyou-title0").click(function(){yoyakuhyou('#hyou',mon0,"#yoyakuhyou-title0");});
	$("#yoyakuhyou-title1").click(function(){yoyakuhyou('#hyou',mon1,"#yoyakuhyou-title1");});
	$("#yoyakuhyou-title2").click(function(){yoyakuhyou('#hyou',mon2,"#yoyakuhyou-title2");});
	$("#yoyakuhyou-title3").click(function(){yoyakuhyou('#hyou',mon3,"#yoyakuhyou-title3");});
});
