﻿
var v_IS_INPUT_MODE = false;

var Gacha = {
	OpenBuyTicket : function(v_is_login, gt_code){
		if(v_is_login != 'True'){
			alert(ErrMsgGachaLogin);
			return false;
		}
		openPopup('buy_ticket', '/Shop/Gacha/ticket/buy_ticket.asp?gtcode=' + gt_code, '570', '430');
	},
	BuyTicket : function(v_user_yarou){
		v_item_price = Number(document.GachaTicketForm.SlotTicketPrice.value);
		if (Number(v_user_yarou) == 0 || v_user_yarou < v_item_price){
			alert(ErrMsgYarou);
			return false;
		}
		if(v_IS_INPUT_MODE)
			return false;
				
		v_IS_INPUT_MODE	= true;
		var v_create_form_name	= 'GachaTicketForm';
		var objForm = document.forms[v_create_form_name];
		if (!objForm){
			alert(ErrMsgFormCreate);
			v_IS_INPUT_MODE = false;
			return;
		}
		CallxmlRequest('buy_ticket_proc.asp', 'CALLFUNCTION', PROCESS_LAYER_COMMON, objForm);
	},
	CallbackBuyTicket : function(v_result){
		if(v_result == 0){
			alert(SuccMsgBuyTicket);
			opener.tkSlot.RefreshStatus();
			self.close();
		}else{
			alert(ErrMsgBuyTicket + ' Err : ' + v_result);
		}
		v_IS_INPUT_MODE = false;
	},
	OpenGacha : function(){
		openPopup('gacha', 'play/play_gacha.asp', '500', '500')
	},
	CheckUserInfo : function(){
	},
	OpenItemList : function(){
		openPopupScroll('itemlist', 'item_list.asp', '585', '750')
	},
	ItemPriceDisplay : function(v_code){
		//var v_ticket_code = Number(v_code.substring(6, 8));
		var v_ticket_price = document.getElementById(v_code).value;
		document.getElementById('DisplayItemPrice').innerHTML = v_ticket_price;
		document.GachaTicketForm.SlotTicketPrice.value = v_ticket_price;
	}
};

var tkSlot = {

	id			: "swfTkSlot",
	swfUrl		: "/shop/gacha/swf/TK_Web_Slot",
	installUrl	: "/blogparts/swf/playerProductInstall",
	width		: "640",
	height		: "470",

	show		: function(nickname) {
		document.write( this.getTag(nickname) );
	},

	getTag		: function(nickname) {
		nickname = nickname ? nickname.toString() : "";
		var wmode = (nickname=="") ? "opaque" : "window";

		var hasProductInstall = DetectFlashVer(6, 0, 65);
		var hasRequestedVersion = DetectFlashVer(9, 0, 124);
		if ( hasProductInstall && !hasRequestedVersion ) {
			var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
			var MMredirectURL = window.location;
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			var MMdoctitle = document.title;
			return AC_FL_GetContent(
				"id", this.id,
				"src", this.installUrl,
				"flashvars", "MMredirect"+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
				"width", this.width,
				"height", this.height,
				"quality", "high",
				"wmode", wmode,
				"bgcolor", "#000000",
				"name", this.id,
				"allowScriptAccess", "always",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
		} else if (hasRequestedVersion) {
			return AC_FL_GetContent(
			"id", this.id,
			"src", this.swfUrl,
			"flashvars", "nickname=" + encodeURIComponent(nickname),
			"width", this.width,
			"height", this.height,
			"quality", "high",
			"wmode", wmode,
			"bgcolor", "#000000",
			"name", this.id,
			"allowScriptAccess", "always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
		} else {
			var alternateContent = '<table id="'+ this.id +'" width="'+ this.width +'" height="' + this.height +'" border="0"><tr><td align="center" valign="middle">'
			+ '<a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://image.gameyarou.jp/tekki/blogparts/get_adobe_flash_player.png" '
			+ 'width="158" height="39" alt="Get Flash Player" title="このサイトをご覧になるには「Flash Player」が必要です。" border="0"/></a>'
			+ '</td></tr></table>';
			return alternateContent;
		}

	},

	IsInitialized	: function() {
		var obj = document.getElementById(this.id);
		if (obj) return true;
		else return false;
	},

	RefreshStatus	: function() {
		var obj = document.getElementById(this.id);
		if (obj && obj.refreshStatus) return obj.refreshStatus();
		else return false;
	},
	
	IsProgressing	: function() {
		var obj = document.getElementById(this.id);
		if (obj && obj.isProgressing) return obj.isProgressing();
		else return false;
	},

	Finalize	: function() {
		var obj = document.getElementById(this.id);
		if (obj && obj.finalize) obj.finalize();
	},
	
	Login		: function() {
		return;
	},
	
	Reload		: function() {
		self.location.reload();
	},

	Close		: function() {
		self.location.replace("/");
	},

	BuyYaro		: function() {
		return;
	},

	BuyBet		: function() {
		return;
	}

};

window.onbeforeunload = function () {
	if (tkSlot.IsInitialized()) {
		if (tkSlot.IsProgressing()) {
			return "メタルスロットが動作中です。\n終了しても現在動作結果はゲームに適用されます。\n\nメタルスロットを終了しますか?";
		}else{
			tkSlot.Finalize();
		}
    }
};

window.unload = function () {
	if (tkSlot.IsInitialized()) tkSlot.Finalize();
};
