var curmaxFrame = 0;
var deleteLoop;
var LoadResult = false;
var strSwfPath;
var cur;
var movie;
var strExitOptions;
strExitOptions = "";
function tmpcurrent()
{
		//cur = movie.TGetProperty(strSwfPath, 4);
		//cur = movie.TCurrentFrame("/");
		cur = movie.TCurrentFrame(strSwfPath);
		cur = parseInt(cur);
		if (cur > curmaxFrame)
			curmaxFrame = cur;
	setTimeout('tmpcurrent()',1000);
}

function setLevel(typeCode, level) {
	location.href = "_SettingLevel.asp?typeCode="+typeCode+"&level="+level;
}

//¼öÁ¤µÇÁö ¾ÊÀº ÄÁµ§Ã÷ ¸¶Ä¡±â
var endCheck = 0;
var vPageLoad;
var vResult=0;
var vPassed;
function send(PlayTime, SendValue, Result, isPassed, isPageLoad) {		//? ±¸ ÄÜÅÙÃ÷ ±×¸¸ÇÏ±â
	if ( typeof(Result) == "undefined" ) Result = 0
	vResult = Result;
	vPassed = isPassed;
	vPageLoad = isPageLoad;

	if ( SendValue == "end" || typeof(SendValue) == "undefined" ){
		if ( typeof(vPageLoad) == "undefined"  || (ConType =="KoreanLang" || ConType =="Mathematics" || ConType =="ChineseCharLang") )	 endCheck = 0;
		top.window.close();
	}else{
		if ( !PlayTime ) {
			PlayTime = '0,0,0';
			var e = PlayTime.split(",");
			PlayTime = e[0];
		}
		gameExit(PlayTime, SendValue, EndFrame);
	}
}

//GEniEnglish,ÇÑ±Û,¼ö¸®,ÇÑÀÚ,¿µ¾î Àü¿ë ¸¶Ä¡±â(ÈÊ³¯ ¸ðµç ¿µ¿ª µîµµ Àû¿ë°¡´É)
function gameExit(PlayTime, SendValue, EndFrame) {
	var strSavePage;
	var strGStep = "";
	var strCState = "";
	var strContentsOpenPath = "";
	var intThemeNo = "";

	if ( SendValue == "move" ){
		isMSIE ? top.detachEvent("onbeforeunload", top.fswf.ContentsSave) : top.removeEventListener("beforeunload", top.fswf.ContentsSave, false);
	}

	if ( typeof(ConLoadSel) != "undefined" && ConLoadSel != "" )	endCheck = 0;	//¿¬°èÄÁÅÙÃ÷´Â ÀúÀåÇÏ´Â½ÃÁ¡ÀÌ µû·ÎÀÖ±â¶§¹®¿¡ Ä«¿îÅÍ Ã¼Å©ÇÏÁö¾ÊÀ½

	switch (endCheck) {
		case 0 :
			if ( !EndFrame ) {
				EndFrame = 1;
			}
			if( ! LoadResult ){		//¿¬°èÄÁÅÙÃ÷´Â endframe Ã¼Å©ÇÏÁö¾ÊÀ½.. ÇÁ·¹ÀÓ ÁøÇà½Ã Result = 1°ª ¼ÂÆÃ
				if (ConType.substr(0,9) != "ThinkGame"){
					GENIKIDS_PLAYPNY = checkcurrent();
					var eframe = GENIKIDS_PLAYPNY;
					if (eframe * 1.1 > EndFrame) {
						Result=1;
					}	else {
						Result=0;
					}
				}
				if (typeof(Result) == "undefined") Result = 1;
			}

			if ( vResult != 0 && typeof(vResult) != "undefined" ) Result = vResult;
			if ( strGameStep != "" ) strGStep = "&strGameStep="+strGameStep;	//´Ü°è
			if ( strChestState != "" ) strCState = "&strChestState="+strChestState;	//¿ÊÀå
			if ( typeof(strExitOptions) == "undefined" ) strExitOptions = "";
			if (typeof(top.opener.top.index) != "undefined"){			// ÄÜÅÙÃ÷¸¦ ¾î´À ¿µ¿ª¿¡¼­ Çß´ÂÁö ¾Ë¾Æº¸ÀÚ.
				var arrContentOpenPath = top.opener.document.URL.split("/");
				if(arrContentOpenPath.length > 4 )
					strContentsOpenPath = arrContentOpenPath[4].substring(0,arrContentOpenPath[4].lastIndexOf("."));
			}
			if(top.opener.ThemeNo!=undefined) intThemeNo = top.opener.ThemeNo;
			strSavePage = "ContentsExit.asp?ConID="+ConID+"&ConType="+ConType+"&PlayTime="+PlayTime+"&SendValue="+SendValue+"&Result="+Result+"&ListCode="+ListCode+"&EndFrame="+ EndFrame +"&COP=" + strContentsOpenPath +"&ThemeNo=" + intThemeNo + strGStep + strCState+ strExitOptions;
			if ( typeof(vPageLoad) != "undefined" ){		//´Ü°èÆò°¡ÀúÀå
				//alert("/Contents/SaveLevelTestResult.asp?ConID="+ConID+"&ConType="+ConType+"&PlayTime="+PlayTime+"&SendValue="+SendValue+"&Result="+Result+"&isPassed="+vPassed+"&isPageLoad="+vPageLoad);
				top.opener.top.hidBottom.document.location.href = "/Contents/SaveLevelTestResult.asp?ConID="+ConID+"&ConType="+ConType+"&PlayTime="+PlayTime+"&SendValue="+SendValue+"&Result="+Result+"&isPassed="+vPassed+"&isPageLoad="+vPageLoad;
			}else{
			//	if (top.opener.document.URL.split("/")[4].substring(0,14) == "PopupRecommend"){
			//		top.opener.top.opener.top.hidBottom.document.location.href = strSavePage;
			//	}else{
					top.opener.top.hidBottom.document.location.href = strSavePage;
			//	}
			}
			//alert(strSavePage);
			//--´Ü°èÆò°¡°¡ ¾Æ´Ò¶§¸¸ detach¸¦ ÇÑ´Ù. (´Ü°èÆò°¡´Â ÀúÀåÇÏ°í ÀÌµ¿½Ã attachEvent ½ÇÇàÇÏ±â¶§¹®¿¡ detach¸¦ÇÏÁö ¾Ê´Â´Ù.)
			if ( typeof(vPageLoad) == "undefined" )	 isMSIE ? top.detachEvent("onbeforeunload", top.fswf.ContentsSave) : top.removeEventListener("beforeunload", top.fswf.ContentsSave, false);
			break;
		case 1 :
			alert("ÄÁÅÙÃ÷ ½ÇÇà³»¿ëÀ» ÀúÀåÇÏ°í ÀÖ½À´Ï´Ù. Àá½Ã¸¸ ±â´Ù·ÁÁÖ¼¼¿ä.\n\n ¸î ÃÊÈÄ¿¡µµ Ã¢ÀÌ ´ÝÈ÷Áö ¾ÊÀ¸¸é ±×¸¸ÇÏ±â¸¦ ÇÑ¹ø ´õ ´­·¯ÁÖ¼¼¿ä.");
			break;
		default :
			top.window.close();
	}
	endCheck++;
	LoadResult = false;
}

var OpenWindowMove = function(ConID){
	isMSIE ? top.detachEvent("onbeforeunload", top.fswf.ContentsSave) : top.removeEventListener("beforeunload", top.fswf.ContentsSave, false);
	top.bswf.send(top.bswf.document.getElementById("swfBottom").mcSendTime(),'move');
	top.opener.OpenWindow(ConID);
	//top.window.close();
}

function checkcurrent()
{
	//cur = movie.TGetProperty(strSwfPath,4);
	//cur = movie.TCurrentFrame("/");
	cur = movie.TCurrentFrame(strSwfPath);

	if(parseInt(cur) > parseInt(curmaxFrame))
		return cur;
	else
		return curmaxFrame;
}

/*
function checkend()
{
	var movie = document.all.GAMESWF;
	var tot = movie.TGetProperty("/",5);
	return tot;
}

function checkfinish()
{
	var movie = document.all.GAMESWF;
	var cur = movie.TGetProperty("/",4);
	var tot = movie.TGetProperty("/",5);
	return parseInt((cur/tot)*100);
}
*/

//¹Ø¿¡ µÎ ÇÔ¼ö´Â ¹Ù³ª³ë »ç°í·Â°ÔÀÓ1 ÀÇ ½ºÅ©¸³Æ®ÀÔ´Ï´Ù.
function getBNNHelp(CurLevel, CurUnit, useCoin) {	//1: ¹Ù³ª³ë, 2:ÇÏ¾áµµ±úºñ, 3:º¸³ë
	//alert(CurLevel + "/"+CurUnit+ "/"+useCoin);
	if( CurLevel == "3" ){
		top.D_send_2.location.href = "useSmartStar.asp?CurLevel="+CurLevel+"&CurUnit="+CurUnit+"&Coin="+useCoin;
	}else{
		top.D_send_2.location.href = "useCoin.asp?CurLevel="+CurLevel+"&CurUnit="+CurUnit+"&Coin="+useCoin;		//090513 ±âÁ¸Ã³¸®
	}
	//location.href = "useCoin.asp?curUnit="+stage+"&Coin="+useCoin;
}
//ÇÏ¾áµµ±úºñ ³¡³»±â...
function exitNoneQuery() {
	top.opener.document.location.reload();
	top.close();
}
function passWhiteTrolls(themeCode){
	if (themeCode==0){ EndFrame = 1;}
	else if(themeCode==1){EndFrame = 41;}
	else{EndFrame =81;}
	location.href = "ContentsOpen.asp?ConType=ThinkGame2&ConID=newgame_2_play_"+ themeCode +"&isFree=5&isIncludeMenuBar=True&EndFrame="+ EndFrame +"&ListCode=BNN&CurLevel=2&noneStop=1";
}
function contentView(str) {
	top.opener.top.index.contentView(str);
	top.close();
}

var SwfConChange = function( conid, sel, playtime ){		//ÄÁÅÙÃ÷ ¼Ó ÄÁÅÙÃ÷ ÀúÀå-¿¬°èÄÁÅÙÃ÷ (ex. ÇÑ±Û¸»³îÀÌ)-Zzan
//	alert("SwfConChange")
	if ( top.ConID != "" &&  top.ConID != conid ) top.bswf.send( playtime , 'move'); //Ã³À½ ·Îµå¹«ºñÇÏ´Â ÄÁÅÙÃ÷´Â ÀúÀå¾ÈÇÔ
	top.ConID = conid;
	top.fswf.ConID = conid;
	top.fswf.ConLoadSel = sel;
 	top.fswf.Result = 0; 	// °á°ú°ª
 	LoadResult = true;	//¿¬°èÄÁÅÙÃ÷
}

var SwfConResultSetting = function(){
	LoadResult = true;	//¿¬°èÄÁÅÙÃ÷
	top.fswf.Result = 1;
}

var LevelTest_BookPreview = function(ChangeLevel, GroupCode, Level, Unit){
	var strPage = "";
	top.opener.parent.viewBookimg(GroupCode, Level, Unit);
	GroupCode == "0100" ? strPage = "hanlevel" : strPage = "sulevel";
	document.location.href="/Contents/save_"+ strPage +".asp?level="+ ChangeLevel;
}

var LevelTest_GoMall = function(ChangeLevel, UpperCatCode, seCode){
	var strPage = "";
	top.opener.parent.goMallGoodsList(UpperCatCode, seCode);
	UpperCatCode == "100201" ? strPage = "hanlevel" : strPage = "sulevel";
	document.location.href="/Contents/save_"+ strPage +".asp?level="+ ChangeLevel;
}

var LevelTest_GoParentCorner = function(ChangeLevel, GroupCode){
	var strPage = "";
	top.opener.parent.parentCorner();
	GroupCode == "0100" ? strPage = "hanlevel" : strPage = "sulevel";
	document.location.href="/Contents/save_"+ strPage +".asp?level="+ ChangeLevel;
}

var setContentsOptions = function(strOptions){
	strExitOptions = strOptions;
}
//--document.getElementById("GAMESWF").setVariable("genicheck",0)
