	var actdata_loading;
	var koiid = null;
	var now_price = 0;
	var poeAuction = false;

	Number.prototype.number_format=function() {
		if (this == "") return;
		var s = this.toString().split("\.");
		return s[0].replace(/((^[+-])?(\d)+?)(?=(\d{3})+$)/g, "$1,") + 
		 (s[1]? "." + s[1].replace(/(\d{3})(?=\d+)/g, "$1,") : "");
	}

	function playVideo () {
		if (video_url == "") return;
		$("video_frame").src = video_url;
		$("btn_video_play").hide();
		$("video_frame").show();
	}

	function openVideo (video) {
		if (video == "") return false;
		$("video_frame").src = '';
		$("video_frame").hide();
		$("btn_video_play").show();
		window.open(video, 'video', 'width=600, height=580, menubar=no, toolbar=no, location=no');return false;
	}

	function bidListView () {
		if ($('btn_bid_list_view').checked == false) {
			$$('.bid_false').each(function(obj){ Element.show(obj); });
		} else {
			$$('.bid_false').each(function(obj){ Element.hide(obj); });
		}
	}

	function loadActData () {
		if (working == true) return;
		working = true;

		Element.update("load_time", getLT("更新中","updating"));
		objDate = new Date();
		new Ajax.Request(
			root_url + "/act_ajax.php", {
				method: "get", parameters: "r=loadactdata&e=" + live_event_id + "&s=" + skey + "&stamp" + objDate.toTimeString(),
				onComplete : printActData,
				onFailure : function() { working = false; },
				onException : function() { working = false; }
			}
		);
	}

	function printActData (httpObj) {
		if (httpObj.responseText == "") { working = false; return; }
		var data = httpObj.responseText.evalJSON();
		if (data.length <= 0) { working = false; return; }
		for (var i=0; i<data.length; i++) {
			if ($("timeleft_" + data[i].koiid)) {
				switch (data[i].state) {
					case "ok" :   Element.update("timeleft_" + data[i].koiid, data[i].timeleft); break;
					case "wait" : Element.update("timeleft_" + data[i].koiid, getLT("　準備中　","Preparing")); break;
					case "end" :  Element.update("timeleft_" + data[i].koiid, getLT("　終　了　","End")); break;
				}

				if (skey != "" && window.navigator.appVersion.toLowerCase().indexOf("msie 6.0") < 0) {
					if (data[i].bid_flg == 0) {
						$$(".row_" + data[i].koiid).each(function(obj){ Element.addClassName(obj, 'bid_false'); });
					} else {
						$$(".row_" + data[i].koiid).each(function(obj){ Element.removeClassName(obj, 'bid_false'); });
					}
					Element.update("nowprice_" + data[i].koiid, data[i].now_price.number_format());
					if (data[i].history_count > 0) {
						Element.update("history_count_" + data[i].koiid, "(" + data[i].history_count + ")");
					}
				} else {
					$('ctr_bid_list_view').hide();
				}
				printActButton(data[i].koiid, data[i].state);
				if (skey != "" && skey == data[i].maxbid_user) {
					$("bidder_area_" + data[i].koiid).show();
					Element.setStyle("bidder_area_" + data[i].koiid, {color:"white",backgroundColor:"red"});
				} else {
					$("bidder_area_" + data[i].koiid).hide();
					Element.setStyle("bidder_area_" + data[i].koiid, {color:"black",backgroundColor:"black"});
				}
			} else if (data[i].koiid == 'message') {
				if (lang_mode == 'en' && data[i].message_en != undefined && data[i].message_en != '') {
					$("box_message").show();
					Element.update('box_message', data[i].message_en);
				} else if (lang_mode != 'en' && data[i].message_jp != undefined && data[i].message_jp != '') {
					$("box_message").show();
					Element.update('box_message', data[i].message_jp);
				} else {
					$("box_message").hide();
				}
			}
		}
		if (data.load_time) {
			Element.update("load_time", data.load_time);
		} else {
			objDate = new Date();
			Element.update("load_time", objDate.toLocaleTimeString());
		}

		working = false;
		loadBidRoom();	// 表示中なら入札エリアを更新
	}

	function printActButton (koiid, state) {
		if (state == "" || state == null) return;
		$("btn_bidroom_" + koiid).src = imgsrc + "btn_bid" + state + ".gif";
		if (state == "ok") {
			Event.observe($("btn_bidroom_" + koiid), "click", viewBidRoom);
		} else {
			Event.stopObserving($("btn_bidroom_" + koiid), "click", viewBidRoom);
		}
	}

	function viewBidRoom () {
		if (skey == "") {
			alert(getLT("ログイン後にお越しください","Please come after it login."));
			if (lang_mode == 'en') {
				location.href='http://www.narita-koi.com/live/english/';
			} else {
				location.href='http://www.narita-koi.com/live/';
			}
			return;
		}

		koiid = this.id.replace("btn_bidroom_", "");
		if (koiid == "" || koiid == null) return;

		now_price = 0;
		$(window).scroll(0,600);
		$("bid_confirm_check").checked = false;
		$("txt_bidprice").value = "";
		$("bidroom_area").hide();
		loadBidRoom();
	}

	function loadBidRoom () {
		if (koiid == null || koiid == "") return;
		if (working == true) return;
		working = true;

		objDate = new Date();
//location.href = root_url + "/act_ajax.php?" + "r=loadbidroom&e=" + live_event_id + "&p=" + koiid + "&s=" + skey;
		new Ajax.Request(
			root_url + "/act_ajax.php", {
				method: "get", parameters: "r=loadbidroom&e=" + live_event_id + "&p=" + koiid + "&s=" + skey + "&stamp" + objDate.toTimeString(),
				onComplete : printBidRoom,
				onException: function() { working = false; }
			}
		);
	}

	function printBidRoom (httpObj) {
		if (httpObj.responseText == "") { working = false; return; }

		var data = httpObj.responseText.evalJSON();
		if (typeof(data) != "object") { working = false; return; }

		if (data.state != "ok") {
			alert(getLT("入札は締め切りました。ご利用ありがとうございます。","The bid was closed. Thank you for using."));
			$("bidroom_area").hide();
			koiid = null;
			working = false; return;
		}

		$("bidroom_area").show();
		if (skey != "" && skey == data.maxbid_user) {
			$("ico_bidder").show();
		} else {
			$("ico_bidder").hide();
		}

		$("room_photo").src = root_url + "/thumb.php?width=115&image=" + narita_url + data.main_photo;
		Element.update("room_code",   data.product_code);
		if (lang_mode != 'en') {
			Element.update("room_maker",  data.maker);
			Element.update("room_kind",   data.kind);
			Element.update("room_age",    data.age_text);
			Element.update("room_sex",    data.sex);
			Element.update("room_report", data.report);
		} else {
			Element.update("room_maker",  data.e_maker);
			Element.update("room_kind",   data.e_kind);
			Element.update("room_age",    data.e_age_text);
			Element.update("room_sex",    data.e_sex);
			Element.update("room_report", data.e_report);
		}
		Element.update("room_size",   data.size + " cm");
		if (skey != "") {
			Element.update("room_price",  parseInt(data.price).number_format() + " " + getLT("円","Yen"));
		} else {
			Element.update("room_price",  " -- " + getLT("円","Yen"));
		}
		if (data.history_html != "" && skey != "") {
			Element.update("room_history_link", getLT("履歴","Log") + '(' +data.history_count  + ')');
			Element.update("history_area", data.history_html);
		} else {
			Element.update("room_history_link", '');
			Element.update("history_area", '');
		}

		Element.update("room_endtime",  data.endtime);
		Element.update("room_timeleft", data.timeleft);

		if (skey != "") {
			Element.update("room_nowprice", parseNum(data.now_price).number_format() + " " + getLT("円","Yen"));
		} else {
			Element.update("room_nowprice", " -- " + getLT("円","Yen"));
		}
		now_price = parseNum(data.now_price);

		if (skey != "" && skey == data.maxbid_user) {
			Element.update("bidder_price", parseNum(data.max_price).number_format() + " " + getLT("円","Yen"));
			$("bidder_title").show();
			$("bidder_price").show();
		} else {
			$("bidder_title").hide();
			$("bidder_price").hide();
		}

		permitBid();
		working = false;
	}

	function fcsBidPrice () {
		$("txt_bidprice").value = parseNum($F("txt_bidprice").replace(",", ""));
		Element.setStyle($("txt_bidprice"), { color:"#000" })
	}

	function burBidPrice () {
		if (isNaN($F("txt_bidprice")) || $F("txt_bidprice") == "") {
			$("txt_bidprice").value = ""; return;
		}
		bid_price = parseNum($F("txt_bidprice")).number_format();
		$("txt_bidprice").value = bid_price;
		if (parseNum(now_price) >= (parseNum(bid_price.replace(",", "")) * 1000)) {
			Element.setStyle($("txt_bidprice"), { color:"#f00" });
		} else {
			Element.setStyle($("txt_bidprice"), { color:"#000" });
		}
	}

	function exeBidEnter() {
		if (koiid == "" || koiid == null) return;

		// 同意チェック
		if ($('bid_confirm_check').checked == false) {
			alert(getLT('規約をご確認頂き、「同意する」にチェックをしてください。','Please confirm the Special Affairs and check "Confirm".'));
			return;
		}

		// 金額チェック
		bid_price = parseNum($F("txt_bidprice").replace(",", "")) * 1000;
		if (bid_price == "") {
			alert(getLT('入札額を入力してください。','Please input bid price.'));
			$("txt_bidprice").focus(); return;
		}
		if (now_price >= bid_price) {
			alert(getLT('現在の価格以下の入札額を設定されています。', 'The bidding price is below the present price.'));
			$("txt_bidprice").focus(); return;
		}

		// ニックネームを要求
		if (reqNickName() == false) {
			return;
		}

		msg = (parseNum($F("txt_bidprice").replace(",", "")) * 1000).number_format();
		msg = getLT( msg + "円 で入札してよろしいですか？", "Do you want to bid for " + msg + "JPY?");
		if (confirm(msg) == false) {
			return;
		}

		if (working == true) return;
		working = true;

		objDate = new Date();
//		location.href = root_url + "/act_ajax.php?r=execbid&p=" + koiid + "&b=" + bid_price + "&s=" + skey + "&n=" + nick_name;
		new Ajax.Request(
			root_url + "/act_ajax.php", {
				method: "get", parameters: "r=execbid&p=" + koiid + "&b=" + bid_price + "&s=" + skey + "&n=" + nick_name + "&stamp" + objDate.toTimeString(),
				onComplete : compBid,
				onException: function() { working = false; }
			}
		);
	}

	function reqNickName () {
		if (nick_name == "") {
			Element.show('form_nick_name');
			iBox.showURL('#form_nick_name', '', { width:'350', height:'100' });
			return false;
		} else {
			return true;
		}
	}

	function checkNickName () {
		if ($("txt_nick_name").value == "") { alert(getLT("ニックネームを入力してください。", "Please enter nickname.")); return; }
		if ($("txt_nick_name").value.length < 3) { alert(getLT("ニックネームは3文字以上で入力してください", "Please enter nickname by three characters or more.")); return; }
		nick_name = $("txt_nick_name").value;
		iBox.hide($('form_nick_name'));
	}

	function onBidEnter () { $("btn_bidenter").src = imgsrc + "btn_bidenter_on.gif"; }

	function offBidEnter () { $("btn_bidenter").src = imgsrc + "btn_bidenter.gif"; }

	function permitBid () {
		if ($("bid_confirm_check").checked) {
			reqNickName();
			offBidEnter();
			Event.observe($("btn_bidenter"), "mouseover", onBidEnter);
			Event.observe($("btn_bidenter"), "ouseout", offBidEnter);
		} else {
			$("btn_bidenter").src = imgsrc + "btn_bidenter_off.gif";
			Event.stopObserving($("btn_bidenter"), "mouseover", onBidEnter);
			Event.stopObserving($("btn_bidenter"), "ouseout", offBidEnter);
		}
	}

	function compBid (httpObj) {
		if (httpObj.responseText == "") { working = false; return; }
		var data = httpObj.responseText.evalJSON();
		if (typeof(data) != "object") { working = false; return; }
		switch (data.state) {
			case "win":
				alert(data.msg);
				$("txt_bidprice").value = "";
				break;
			case "lose":
			case "err":
				alert(data.msg);
				Element.setStyle($("txt_bidprice"), { color:"#f00" });
			break;
		}
		
		working = false;
		loadActData();
	}

	// 英語版注文確認
	function loadEngConfirm() {
		var param = new Object();
		param['width']  = 400; param['height'] = 400;
		iBox.showURL('/store/live/confirm/e_order.php', '', param);
	}

	// 英語版注文処理
	function odrEngProduct() {
		if (skey == "") { alert("Please login to order."); return; }
		params = "r=ordproduct";
		params += "&skey=" + skey;
		params += "&lang=" + lang_mode;

		var a = new Ajax.Request(
			"/store/live/ajax.php", {
				method: "post", postBody: params,
				onSuccess: function(httpObj) {
					switch (httpObj.responseText) {
						case "ok": alert("Thank you for the order."); break;
						case "login": alert("Please login to order."); break;
						case "err": alert("An error occurred. Please contact us."); break;
					}
					Element.update($("pdtconfirm_button"), "<a href='javascript:void(0);' onclick='iBox.hide();'><img src='/store/user_data/packages/default/img/english/btn_live_close.gif' alt='Close' /></a>");
					return;
				},
				onFailure: function(httpObj) {
					alert('An error occurred. Please contact us.');
					return;
				},
				onException: function (httpObj) {
					return;
				}
			}
		);
	}

	function getLT (jp_txt, en_txt) {
		if (lang_mode == 'en') {
			return en_txt;
		} else {
			return jp_txt;
		}
	}

