function openAgreement() { $('#agreement-bg').show(); $('#agreement-popup').show(); }
function closeAgreement() { $('#agreement-bg').hide(); $('#agreement-popup').hide(); }

// login Check
function LoginCheck() { if (loginYN == "N") { alertify.alert('로그인 후 이용해주세요.'); return false; } return true; }

function gameAgreement(gameUrl) { if (!LoginCheck()) return; openAgreement(); $('#btn-agreement').html('<a href="javascript:' + gameUrl + '" class="btn01 btn-style1" id="btn-agreement">동의</a>'); }

// 게임준비중
function goComingsoon() { alert('게임 준비중입니다.'); }

function goHLGame(game_title, os, vendor, game_id) { gameAgreement("gameStartNew(1280,820,'" + game_title + "','" + os + "','" + vendor + "','" + game_id + "')"); }

// Minigame
function goMinigame() { gameAgreement("gameStart('MINI','')"); }
// Taisan
function goTgame() { gameAgreement("gameStart('TCD','')"); }
//호게이밍
function goHgame() { gameAgreement("gameStart('HO','')"); }

// LMG
function goLMGgame() { gameAgreement("gameStart('LMG','')"); }
// Asian
function goAsian() { gameAgreement("gameStart('C_An')"); }
function goAsia() { gameAgreement("window.open('game/asia_lobby','slot','top=0,left=50,width=1280,height=780,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no')"); }
function goAsiaMobile() { gameAgreement("window.open('game/asia_lobby','_self','slot')"); }
// GamePlay
function goGameplay() { gameAgreement("gameStart('C_Gpy')"); }
// Allbet
function goAllbet() { gameAgreement("gameStart('C_All')"); }
// Aristo
function goAristo() { gameAgreement("gameStart('C_Aro')"); }
// DG
function goDGAllbet() { gameAgreement("gameStart('DG_All','')"); }
function goDGAllbetMobile() { gameAgreement("gameStartMobile3('DG_All','')"); }
// PT Live
function goPTLive() { gameAgreement("gameStartPTLive('PT')"); }
// PT Live
function goPinnacle() { gameAgreement("gameStartx(1024,768,'Pinn')"); }
// SBO
function goSBO() { gameAgreement("gameStartx(1024,768,'SBO')"); }
// BBin
function goBbin() { gameAgreement("gameStart('C_Bbin')"); }
// Cagayan
function goCagayan() { gameAgreement("gameStart('C_Cagayan')"); }
// Oriental
function goOriental() { gameAgreement("gameStart('C_Oriental')"); }
// Midas
function goMidas() { gameAgreement("window.open('game/midas_lobby','slot','top=0,left=50,width=1280,height=780,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no')"); }
function goMidasMobile() { gameAgreement("window.open('game/midas_lobby','_self','slot')"); }
// W88
function goW88() { gameAgreement("window.open('game/w88_lobby','','top=0,left=50,width=1280,height=780,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no')"); }
function goW88Mobile() { gameAgreement("window.open('game/w88_lobby','_self','')"); }
// 마이크로 슬롯
function goMicroSlot() { gameAgreement("gameStart('MCD','slot')"); }
function goMicroSlotMobile() { gameAgreement("gameStartMobile2('MCD','slot')"); }
// 에볼루션
function goEvo(webType, gameType) { gameAgreement("gameStartx(1024,768,'EvoNew','" + webType + "','" + gameType + "')"); }
function goEvoZetta(webType, gameType) { gameAgreement("gameStartx(1024,768,'EvoZetta','" + webType + "','" + gameType + "')"); }
function goEvoLuch(webType, gameType) { gameAgreement("gameStartx(1024,768,'EvoLuch','" + webType + "','" + gameType + "')"); }
// 프라그마틱
function goPPZetta(webType, gameType) { gameAgreement("gameStartx(1280,820,'PPZetta','" + webType + "','" + gameType + "')"); }
function goPPSlotZetta() { gameAgreement("window.open('game/ppslot','slot','top=0,left=50,width=1280,height=780,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no')"); }
// 베가스
function goVegasZetta(webType, gameType) { gameAgreement("gameStartx(1280,820,'VegasZetta','" + webType + "','" + gameType + "')"); }

//추가
function goMicroLive3(type) {
	gameStart('MCD', type);
}

//추가
function goMicroSlot3(type, gameId) {
	goMicroExec3(type, gameId);
}

//추가
function goMicroExec3(gameType, gameId) {
	$.ajax({
		type: "GET",
		url: "/game/micro_start3",
		data: { "gameType": gameType, "gameId": gameId },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}



// IDNPoker
function goIDNPoker(webType) { gameAgreement("gameStartx(1100,840,'IDNPoker','" + webType + "')"); }
// Stag8
function goStag8() { gameAgreement("goStag8ex();"); }

function goStag8ex() {
	$.ajax({
		type: "GET",
		url: "/game/stag8_lobby",
		data: { "game_code": 'stag8' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}


var gamecount = 0;

//마이크로 라이브 게임 실행하기
function gameStartMobile2(game_title, game_type) {
	if (loginYN == "N") {
		if (gamecount == 0) {
			gamecount += 1;
			if (!alert("로그인 후 이용해주세요.")) {
				gamecount += -1;
			}
		}
	} else {
		if (game_title == 'MCD') {
			url = "/game/micro_start_mobile?GameTitle=" + game_title + "&GameType=" + game_type;
			window.open(url, '_self', game_title); // ,'top=0,left=50,width=968,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no');";
			//	  document.location.href = "casino://goldentree/login/";
			//	  goMicroExec('MCD', '');
		} else {
			$.ajax({
				type: "GET",
				url: "/game/mobile_game_start",
				data: {
					"game_title": game_title
				},
				dataType: 'json',
				success: function (data, textStatus) {
					if (data.status != '0') {
						alert(data.msg);
					} else {
						window.open(data.data.m_url, '_blank');
					}
				},
				error: function (data, textStatus) {
					alert('게임접속이 원할하지 않습니다.');
				}
			});
		}
	}
}

//모바일 게임 실행하기
function gameStartMobile3(game_title) {
	if (loginYN == "N") {
		if (gamecount == 0) {
			gamecount += 1;
			if (!alert("로그인 후 이용해주세요.")) {
				gamecount += -1;
			}
		}
	} else {
		goGameExec3('DG_All', '');
	}
}

function goGameExec3(gameType, gameId) {
	$.ajax({
		type: "GET",
		url: "/game/mobile_game_start",
		data: {
			"gameType": gameType,
			"gameId": gameId
		},
		dataType: "text",
		success: function (data, textStatus) {
			//	alert(data);
			document.location.href = data;
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}

//게임 실행하기
function gameStart(game_code, type) {
	if (loginYN == "N") {
		if (gamecount == 0) {
			gamecount += 1;
			if (!alert("로그인 후 이용해주세요.")) {
				gamecount += -1;
			}
			return;
		}
	} else {
		$.ajax({
			type: "GET",
			url: "/game/game_check",
			data: { "game_code": game_code },
			dataType: "text",
			success: function (data, textStatus) {
				var retdata = data;
				var array_data = retdata.split("|");
				if (array_data[0] == 'Y') {
					alert(array_data[1]);
				} else if (array_data[0] == 'L') {
					alert('로그인 후 이용해주세요.');
					location.href = "/";
				} else {
					if (game_code == 'MINI') {
						goMiniExec();
					} else if (game_code == 'MCD') {
						goMicroExec3(type, '');
					} else if (game_code == 'C_Gpy') {
						goGameExec(game_code);
					} else if (game_code == 'C_An') {
						goAsiaExec();
					} else if (game_code == 'C_Bbin') {
						goBbinExec();
					} else if (game_code == 'C_Cagayan') {
						goCagayanExec();
					} else if (game_code == 'C_Oriental') {
						goOrientalExec();
					} else if (game_code == 'C_W88') {
						goW88Exec();
					} else if (game_code == 'C_All') {
						goAllbetExec();
					} else if (game_code == 'Pinn') {
						goGameExec(game_code);
					} else if (game_code == 'DG_All') {
						goGameExec(game_code);
					} else if (game_code == 'MPCD') {
						goMicroExec(type, '');
					} else {
						alert('게임코드가 올바르지 않습니다.');
					}
				}
			},
			error: function (data, textStatus) {
				alert('게임접속이 원할하지 않습니다.[GAMESTART]');
			}
		});
	}
}

// Taishan 실행
function goTaishanExec() {
	$.ajax({
		type: "GET",
		url: "/game/taishan_start",
		data: { "game_code": 'Taishan' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}

// Mini 실행
function goMiniExec() {
	$.ajax({
		type: "GET",
		url: "/game/mini_start",
		data: { "game_code": 'Mini' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}

// Hogame 실행
function goHgameExec(mode) {
	$.ajax({
		type: "GET",
		url: "/game/hgame_start",
		data: { "game_code": 'HO', "mode": mode },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}


//마이크로 게임 실행
function goMicroExec(gameType, gameId) {
	//	if(flashVerCheck() == false){
	//		return;
	//	}

	$.ajax({
		type: "GET",
		url: "/game/micro_start",
		data: { "gameType": gameType, "gameId": gameId },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}

//asia 실행
function goAsiaExec() {
	$.ajax({
		type: "GET",
		url: "/game/asia_start",
		data: { "game_code": 'C_An' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//bbin 실행
function goBbinExec() {
	$.ajax({
		type: "GET",
		url: "/game/bbin_start",
		data: { "game_code": 'C_Bbin' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//cagayan 실행
function goCagayanExec() {
	$.ajax({
		type: "GET",
		url: "/game/cagayan_start",
		data: { "game_code": 'C_Cagayan' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//oriental 실행
function goOrientalExec() {
	$.ajax({
		type: "GET",
		url: "/game/oriental_start",
		data: { "game_code": 'C_Oriental' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//w88 실행
function goW88Exec() {
	$.ajax({
		type: "GET",
		url: "/game/w88_start",
		data: { "game_code": 'C_W88' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//allbet 실행
function goAllbetExec() {
	$.ajax({
		type: "GET",
		url: "/game/allbet_start",
		data: { "game_code": 'C_All' },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

var gameRunStatus = false;
//게임 실행하기
function gameStartx(width, height, game_code, type, gametype) {
	if (gameRunStatus == true) {
		alert('게임이 실행중입니다. 잠시만 기다려 주시기 바랍니다.');
		return;
	}
	gameRunStatus = true;

	if (loginYN == "N") {
		if (gamecount == 0) {
			gamecount += 1;
			if (!alert("로그인 후 이용해주세요.")) {
				gamecount += -1;
			}
			gameRunStatus = false;
			return;
		}
	} else {
		$.ajax({
			type: "GET",
			url: "/game/game_check",
			data: { "game_code": game_code },
			dataType: "text",
			success: function (data, textStatus) {
				var retdata = data;
				var array_data = retdata.split("|");
				if (array_data[0] == 'Y') {
					alert(array_data[1]);
				} else if (array_data[0] == 'L') {
					alert('로그인 후 이용해주세요.');
					location.href = "/";
				} else {
					goGameExecx(width, height, game_code, type, gametype);
				}
				gameRunStatus = false;
			},
			error: function (data, textStatus) {
				alert('게임접속이 원할하지 않습니다.[GAMESTART]');
				gameRunStatus = false;
			}
		});
	}
}

//Game 실행
function goGameExec(game_code) {
	$.ajax({
		type: "GET",
		url: "/game/game_start0",
		data: { "game_code": game_code },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}
//Game 실행
function goGameExecx(width, height, game_code, mode, gametype) {
	$.ajax({
		type: "GET",
		url: "/game/game_startx",
		data: { "width": width, "height": height, "game_code": game_code, "mode": mode, "gametype": gametype },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

// Midas game 
function goMidasGame(game_code) {
	//	window.open('game/midasgame?GameType=C_Mds&GameId=&LoginName=a&Password=b','slot','top=0,left=50,width=968,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no');
	window.open('game/gameopener?height=780&game_code=' + game_code, 'slot', 'top=0,left=50,width=1280,height=780,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no');
	//game/micro_post?GameType=slot
}
// PT game 
function gameStartPT(game_code) {
	//	window.open('game/midasgame?GameType=C_Mds&GameId=&LoginName=a&Password=b','slot','top=0,left=50,width=968,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no');
	window.open('game/gameListPT?height=720&game_code=' + game_code, 'pt', 'top=0,left=50,width=968,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no');
	//game/micro_post?GameType=slot
}
function gameStartPTLive(game_code) {
	var ptL = window.open('game/gameOpenPTLive?height=720&game_code=' + game_code, 'pt', 'top=0,left=50,width=968,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,directories=no');
	//	ptl.askTempandLaunchGame('', '7bal');
}

// Toto 실행
function goTotoExec() {
	$.ajax({
		type: "GET",
		url: "/game/toto_start",
		data: { "game_code": 'Toto' },
		dataType: "json",
		success: function (data, textStatus) {
			var domain = 'http://toto' + data.url.substring(data.url.indexOf(".")) + '/calltotogame.php';

			var form = document.createElement("form");
			form.setAttribute("method", "post");
			form.setAttribute("action", domain);

			// setting form target to a window named 'formresult'
			form.setAttribute("target", "Toto");

			var hiddenField = document.createElement("input");
			hiddenField.setAttribute("name", "ggg");
			hiddenField.setAttribute("value", data.ggg);
			form.appendChild(hiddenField);
			var hiddenField2 = document.createElement("input");
			hiddenField2.setAttribute("name", "url");
			hiddenField2.setAttribute("value", data.url);
			form.appendChild(hiddenField2);
			document.body.appendChild(form);

			// creating the 'formresult' window with custom features prior to submitting the form
			window.open('about:blank', 'Toto', 'top=0,left=50,width=1025,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no');

			form.submit();


			//	document.cookie = "g=" + data.ggg + ";expires=" + myDate + ";domain=." + data.url + ";path=/";		
			//		window.open('http://'+data.url+'/Deposit_ProcessLogin.aspx?lang=en&act=livecasino','Toto','top=0,left=50,width=1025,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no');
			// $scriptString="window.open('".$rs_game_data["url"]."','".$game_code."','top=0,left=50,width=1025,height=720,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no');";
			//eval(data);
		},
		error: function (data, textStatus) {
			alert('게임접속이 원할하지 않습니다.');
		}
	});
}


// new
function gameStartNew(width, height, game_title, os, vendor, game_id) {
	if (gameRunStatus == true) {
		alert('게임이 실행중입니다. 잠시만 기다려 주시기 바랍니다.');
		return;
	}
	gameRunStatus = true;

	if (loginYN == "N") {
		if (gamecount == 0) {
			gamecount += 1;
			if (!alert("로그인 후 이용해주세요.")) {
				gamecount += -1;
			}
			gameRunStatus = false;
			return;
		}
	} else {
		$.ajax({
			type: "GET",
			url: "/game/game_check_new",
			data: { "game_title": game_title },
			dataType: "text",
			success: function (data, textStatus) {
				var retdata = data;
				var array_data = retdata.split("|");
				if (array_data[0] == 'Y') {
					alert(array_data[1]);
				} else if (array_data[0] == 'L') {
					alert('로그인 후 이용해주세요.');
					location.href = "/";
				} else {
					goGameExecNew(width, height, game_title, vendor, os, game_id);
				}
				gameRunStatus = false;
			},
			error: function (data, textStatus) {
				alert('게임접속이 원할하지 않습니다.[GAMESTART]');
				gameRunStatus = false;
			}
		});
	}
}

//Game 실행
function goGameExecNew(width, height, game_title, vendor, os, game_id) {
	$.ajax({
		type: "GET",
		url: "/game/game_start_new",
		data: { "width": width, "height": height, "game_title": game_title, "vendor": vendor, "os": os, "game_id": game_id },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}

//Slot 실행
function goSlotExecNew(width, height, game_title) {
	$.ajax({
		type: "GET",
		url: "/game/slot_games_popup",
		data: { "width": width, "height": height, "game_title": game_title },
		dataType: "text",
		success: function (data, textStatus) {
			eval(data);
		},
		error: function (data, textStatus) {
			alertify.error('게임접속이 원할하지 않습니다.');
		}
	});
}