var objects = function() {
	var ajx = null;
	return {
		ready : function() {
			if (ajx == null) {
				if (window.XMLHttpRequest) {
					ajx = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					try {
						ajx = new ActiveXObject("Msxml2.XMLHTTP");
					} catch(e) {
						ajx = new ActiveXObject("Microsoft.XMLHTTP");
					}
				}
			}
			return ajx;
		},
		disconnect : function() {
			ajx = null;
		}
	};
};

var caption = function() {
	var that = {};
	that = objects();
	that.close = function() {
		document.getElementById('caption_box').style.visibility = "hidden";
	};
	return that;
}();
	
var panel = function() {
	var _dx, _dy, _obj = null;
	var BL_IE = false, BL_MZL = false, BL_SFR = false, BL_OPR = false;
	var USER_AGENT = navigator.userAgent;
	if (window.opera) BL_OPR = true;
	else if (document.all) BL_IE = true;
	else if (USER_AGENT.match(/Safari/)) BL_SFR = true;
	else BL_MZL = true;
	var selected_id = "";
	var that = {};
	that = objects();
	that.down = function(e) {
		if (BL_IE) {
			if (window.event.srcElement.id.match(/_dd_/)) {
				id = window.event.srcElement.id.split("_");
				selected_id = id[2];
				_obj = document.getElementById("_dd_" + id[2]);
				_dx = window.event.offsetX;
				_dy = window.event.offsetY;
			}
		} else if (BL_OPR) {
			id = e.target.id.split("_");
			selected_id = id[2];
			_obj = document.getElementById("_dd_" + id[2]);
			_dx = e.offsetX
			_dy = e.offsetY
		} else {
			if (e.target.id.match(/_dd_/)) {
				id = e.target.id.split("_");
				selected_id = id[2];
				_obj = document.getElementById("_dd_" + id[2]);
				_dx = e.layerX;
				_dy = e.layerY;
			}
		}
	};
	that.move = function(e) {
		if (_obj) {
			if (BL_IE) {
				_obj.style.left = window.event.clientX + document.scroll().x - _dx + "px";
				_obj.style.top = window.event.clientY + document.scroll().y - _dy + "px";
				window.event.returnValue = false;
			} else if (BL_MZL) {
				_obj.style.left = e.pageX - _dx + "px";
				_obj.style.top = e.pageY - _dy + "px";
			} else if (BL_SFR) {
				if (document.body.clientWidth <= 960) _obj.style.left = e.pageX - (220 + _dx) + "px";
				else _obj.style.left = e.pageX - (220 + (document.body.clientWidth-960)/2 + _dx) + "px";
				_obj.style.top = e.pageY - (370 + _dy) + "px";
			} else if (BL_OPR) {
				if (document.body.clientWidth <= 960) _obj.style.left = e.pageX - (210 + _dx) + "px";
				else _obj.style.left = e.pageX - (210 + (document.body.clientWidth-960)/2 + _dx) + "px";
				_obj.style.top = e.pageY - _dy + "px";
			}
			document.getElementById('_dd_' + selected_id + '_position').innerHTML = "Close";
		}
	};
	that.up = function(e) {
		if (_obj) {
			_obj = null;
		}
	};
	return that;
}();

var comment = function() {
	var thai40 = "タイ古式マッサージ40分＋ヘッドマッサージ20分<br />全身が疲れている方に！肩・首・頭をしっかりもみほぐします。初めての方にもおすすめです。";
	var thai90 = "タイ古式マッサージ90分<br />日頃デスクワークの多い方や、全身の疲れが気になる方におすすめです。次回どのコースでも使える10%割引券をプレゼント！";
	var thai120 = "タイ古式マッサージ90分＋オイルフットマッサージ40分<br />足にしっかり時間をかけ、全身の血行を促進させてから腰・背中・肩から頭へと徹底的にコリをほぐしていきます。";
	var oil30 = "オイルフットマッサージ30分＋フットマッサージ20分<br />足裏マッサージで体内の老廃物を循環させた後にストレッチを含むフットマッサージでさらに疲れた足をほぐします。";
	var that = {};
	that = objects();
	that.close = function() {
		document.getElementById('_dd_2').style.visibility = "hidden";
	};
	that.open = function(no, x, y) {
		document.getElementById('_dd_2').style.left = (Math.floor((document.body.clientWidth-960)/2) + x) + "px";
		document.getElementById('_dd_2').style.top = y + "px";
		document.getElementById('_dd_2').style.visibility = "visible";
		if (no == 1) document.getElementById('_dd_2_main').innerHTML = thai40;
		else if (no == 2) document.getElementById('_dd_2_main').innerHTML = thai90;
		else if (no == 3) document.getElementById('_dd_2_main').innerHTML = thai120;
		else if (no == 4) document.getElementById('_dd_2_main').innerHTML = oil30
	};
	return that;
}();

var list = function() {
	var current = "1000";
	var today = "";
	var holiday = "0";
	var next_holiday_flg = "0";
	var week = "";
	var reserve_arr = null;
	var caution_arr = null;
	var course_id = "000"
	var that = {};
	that = objects();
	that.close = function() {
		document.getElementById('_dd_1').style.visibility = "hidden";
	};
	that.after = function() {
		minute = current.substring(2);
		hour = current.substring(0, 2)*1 + Math.floor(30 * 10 / 60);
		if (hour*1 > 25) return;
		current = ((hour == 0 ? "00" : hour) + "" + (minute == 0 ? "00" : minute));
		that.write();
	};
	that.before = function() {
		if (current == "1000") return;
		minute = current.substring(2);
		hour = current.substring(0, 2)*1 - Math.floor(30 * 10 / 60);
		if (hour*1 < 10) {
			hour = "10";
			minute = "00";
		}
		current = ((hour == 0 ? "00" : hour) + "" + (minute == 0 ? "00" : minute));
		that.write();
	};
	that.write = function() {
		str = '<div style="padding:6px 0 0 6px;" id="_dd_1_desc"><img id="_dd_1_desc_image" src="image/aaseefoot_desc_' + course_id + '.png" alt="おすすめリラクゼーション" /></div>'
			+ '<div style="float:left;padding:6px 0 0 5px;" id="_dd_1_before"><img id="before" src="image/aaseefoot_before_3.png" alt="前の時間" onmouseover="list.before_over()" onmouseout="list.before_out()" onclick="list.before()" /></div>'
			+ '<div style="float:left;padding-top:7px;" id="_dd_1_after"><img id="after" src="image/aaseefoot_after_3.png" alt="続きをみる" onmouseover="list.after_over()" onmouseout="list.after_out()" onclick="list.after()" /></div>'
			+ '<div id="_dd_1_date" style="float:left;padding:12px 0 0 20px;">予約日：' + today + '</div>';
		count = 0;
		n = 0;
		while (count < 10) {
			minute = (30 * n) % 60;
			hour = 10 + Math.floor(30 * n / 60);
			image_name = ((hour == 0 ? "00" : hour) + "" + (minute == 0 ? "00" : minute));
			if (image_name == '2600') break;
			n++;
			if (current*1 > image_name*1) continue;
			count++;
			alt_name = ((hour == 0 ? "00" : hour) + ":" + (minute == 0 ? "00" : minute));
			reserve_name = "reserve_ng_2";
			if (reserve_arr[image_name] == "0") reserve_name = "reserve_ok_2";
			else if (reserve_arr[image_name] == "2") reserve_name = "reserve_1_2";
			caution_image = caution_arr[image_name];
			if (reserve_arr[image_name] == "3") caution_image = '999';
			str += '<div id="_dd_1_1000" style="padding:10px 10px 0 10px;height:2px;clear:both;">'
				+ '<div id="_dd_1_1000_a" style="float:left;padding-top:5px;"><img id="_dd_1_1000_b" src="image/aaseefoot_mark_1.png" alt="深夜も予約OK" /></div>'
				+ '<div id="_dd_1_1000_c" style="float:left;"><img id="_dd_1_1000_d" src="image/' + image_name + '.png" alt="' + alt_name + '" /></div>'
				+ '<div id="_dd_1_1000_e" style="float:left;padding:2px 0 0 3px;">'
					+ (reserve_name == 'reserve_ng_2' ? '' : '<a href="/reserve/reserve_person/shortcut_' + today + image_name + course_id + '.html">')
						+ '<img src="image/' + reserve_name + '.gif" alt="マッサージ予約" />'
					+ (reserve_name == 'reserve_ng_2' ? '' : '</a>')
				+ '</div>'
				+ (caution_arr[image_name] ? '<div id="_dd_1_1000_g" style="float:left;"><img src="image/aaseefoot_no_' + caution_image + '.png" alt=' + caution_arr[image_name] + '"分を超えるコースは選択できません" /></div>' : "")
				+ '</div>';
		}
		document.getElementById('_dd_1_main').innerHTML = str;
	};
	that.init = function(str) {
		t = str.split("\t");
		reserve_arr = new Array();
		caution_arr = new Array();
		for (i=0; i<t.length; i++){
			if (i == 0) {
				holiday = t[i];
			} else if (i == 1) {
				next_holiday_flg = t[i];
			} else if (i == 2) {
				week = t[i];
			} else if (i == 3) {
				today = t[i].substring(0, 8);
				current = t[i].substring(8);
			} else {
				s = t[i].split("|");
				reserve_arr[s[0] + s[1]] = s[2];
				caution_arr[s[0] + s[1]] = s[3];
			}
		}
	};
	that.load = function(id, x, y) {
		document.getElementById('_dd_1').style.left = (Math.floor((document.body.clientWidth-960)/2) + x) + "px";
		document.getElementById('_dd_1').style.top = y + "px";
		document.getElementById('_dd_1').style.visibility = "visible";
		course_id = id;
		that.write();
	};
	that.open = function(id, x, y) {
		document.getElementById('_dd_1').style.left = (Math.floor((document.body.clientWidth-960)/2) + x) + "px";
		document.getElementById('_dd_1').style.top = y + "px";
		document.getElementById('_dd_1').style.visibility = "visible";
		course_id = id;
		ajx = that.ready();
		ajx.onreadystatechange = function() {
			if (ajx.readyState == 4 && ajx.status == 200) {
				that.init(ajx.responseText);
				that.disconnect();
				that.write();
			}
		};
		ajx.open("POST", "/reserve/ajax", true);
		var param = new Array();
		param.push("date=" + new Date().getTime());
		param.push("pageId=reserve.info");
		param.push("actionId=select");
		param.push("courseId=" + course_id);
		ajx.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajx.send(param.join("&"));
	};
	that.before_over = function() {
		document.getElementById('before').src = "image/aaseefoot_before_2.png";
	};
	that.before_out = function() {
		document.getElementById('before').src = "image/aaseefoot_before_3.png";
	};
	that.after_over = function() {
		document.getElementById('after').src = "image/aaseefoot_after_2.png";
	};
	that.after_out = function() {
		document.getElementById('after').src = "image/aaseefoot_after_3.png";
	};
	return that;
}();

document.scroll = function() {
   return {
      x: this.body.scrollLeft || this.documentElement.scrollLeft,
      y: this.body.scrollTop || this.documentElement.scrollTop
   };
};

document.onmousedown = function(e) {
	panel.down(e);
};

document.onmousemove = function(e) {
	panel.move(e);
};

document.onmouseup = function(e) {
	panel.up(e);
};
