ReservationTable.prototype = {
	initialize : function(calendar){
		this.calendar = calendar;
		
		this.set_up();
	},
	
	set_up : function(){
		this.year = this.calendar.year;
		this.month = this.calendar.month;
		this.days = this.calendar.get_days();
		this.week = this.calendar.get_firstday();
		this.shop_holiday = this.calendar.get_shop_holiday();
		
		this.init_table();
		this.make_table();
	},
	
	init_table : function(){
		this.table = new Array( this.days);
		for( var i = 0; i < this.days; i++){
			this.table[i] = new Array(4);
		}
		
		for(var i = 0; i < this.days; i++){
			this.table[i][0] = "";
			for(var j = 1; j < 4; j++){
				this.table[i][j] = "-";
			}
		}
	},
	
	make_table : function(){
		for(var i = 0; i < this.days; i++){
			this.table[i][0] = i + 1;
			
			if( i + 1 == this.shop_holiday){
				this.table[i][0] += " 定休日";
			}else{
				this.table[i][0] += " " + week_table[(this.week + i) % 7];
			}
		}
		
		for(var i = 0; i < reservation.data.length; i++){
			if(reservation.data[i].year == this.year && reservation.data[i].month == this.month + 1){
				this.table[reservation.data[i].day - 1][reservation.data[i].table + 1] = reservation.data[i].time + "～[ reserved ]";
			}
		}
		
		for(var i = 0; i < this.days; i++){
			if(this.table[i][1] != "-" && this.table[i][2] != "-" && this.table[i][3] != "-"){
				this.table[i][0] += " 満席";
			}
		}
	},
	
	get_table : function(){
		return this.table;
	}
}

ReservationView.prototype = {
	initialize : function(elm_reservation, reservation_table){
		this.element = elm_reservation;
		this.reservation_table = reservation_table;
		
		this.create_html();
		this.print_html();
	},
	
	create_html : function(){
		this.inner_html = "<table class='reservation'>";
		this.create_head_line();
		this.create_table();
	},
	
	create_head_line : function(){
		var month = this.reservation_table.month;
		
		this.inner_html += "<tr><th class='month_name'>";
		this.inner_html += month_name_table[month];												// 月名の表示
		this.inner_html += "</th>";
		this.inner_html += "<th class='table_name'>table'A'</th>";			// テーブル名の表示
		this.inner_html += "<th class='table_name'>table'B'</th>";
		this.inner_html += "<th class='table_name'>table'D'</th>";
		this.inner_html += "</tr>";
	},
	
	create_table : function(){
		var today = this.reservation_table.calendar.today;
		var days = this.reservation_table.calendar.get_days();
		var table = this.reservation_table.get_table();
		
		for(i = 0; i < days; i++){												// 予約行の書き込み開始
			this.inner_html += "<tr>";	
			for(j = 0; j < 4; j++){
				this.inner_html += "<td class='js_contents'";
				if(j == 0){
					this.inner_html += " id='details" + (i + 1) + "'>";
				}else{
					this.inner_html += ">";
				}
				this.inner_html += table[i][j];
				this.inner_html += "</td>";
			}
			this.inner_html += "</tr>";															// Contents行の終了
		}
		this.inner_html += "</table>";	
	},
	
	print_html : function(){
		this.element.innerHTML = this.inner_html;
	}
}

function ReservationTable(calendar){
	this.initialize(calendar);
}

function ReservationView(elm_reservation, reservation_table){
	this.initialize(elm_reservation, reservation_table);
}