﻿
var launcher = null;  
var checklauncheraccess = false;
var serverclosemessage = null;

function LoadLauncher()
{
	// 비스타 테스트적용
	CheckOS();
	
	if (document.all["Launcher"]) {
		launcher = document.all["Launcher"];
	} else if (parent && parent != this && parent.document.all["Launcher"]) {
		launcher = parent.document.all["Launcher"];
	}

	if (launcher != null) {
		return;
	} else {
		
		if(!isVistar)
		{
			var str='<object id="Launcher" codebase="http://su.hanbiton.com/Game/HLauncher.cab#version=1,1,0,0" classid="CLSID:B01AAFA1-2478-44a3-8894-BE4D4C23C271" style="display:none"></object>';
		}
		else
		{
			var str='<object id="Launcher" codebase="http://su.hanbiton.com/Game/HLauncher.cab#version=1,1,0,0" classid="CLSID:B01AAFA1-2478-44a3-8894-BE4D4C23C271" style="display:none"></object>';
		}
		
		document.write(str);	
		launcher = document.all["Launcher"];
	}
}



function ActiveCheck()
{	
	try
	{
		if(document.all["Launcher"] == null || typeof(document.all["Launcher"]) == "undefined" || document.all["Launcher"].object == null )
		{
		//alert("1")
			return false;
		}
		else
		{
		//alert("2")
			return true;
		}
	}
	catch(ex)
	{
	//alert("3")
		return false;
	}
}



//
function checkWebGameAccess()
{
	
	// add parameters 	  
	var paramNames = new Array();
	var paramValues = new Array();

	paramNames[0] = "ID"
	paramValues[0] = "ID";

	CallHanbitONWebService("GetWebGameAccess", paramNames, paramValues, getWebGameAccess);	
}



function getWebGameAccess()
{ 		
	if (objHttp.readyState == 4) 
	{		
		var szResponse = objHttp.responseText;
		
		if (objHttp.status == 200) {
		
			var res = objHttp.responseXML.documentElement;		
			if (res.getElementsByTagName('GetWebGameAccessResult/Serverstate')[0].firstChild.data=="1")
			{
				//alert('서버가 살아 있네요');
				checklauncheraccess = true;
				serverclosemessage = null;			
			}
			else
			{
				//alert('서버가 죽었네요');
				checklauncheraccess = false; 							
				serverclosemessage = res.getElementsByTagName('GetWebGameAccessResult/Closemessage')[0].firstChild.data;

			}									
		}
		
	}
	else
	{
		//alert("====>"+objHttp.readyState);
	}
}


//var NowDate = new Date();   //<--CBT 당첨자 체크 완료후 삭제
function ExecuteLauncher(RegInfo,GameParams,CheckFileList,DnPath,UserID)
{
    // CBT당첨자 체크
    
//    year        = NowDate.getFullYear();
//    month       = NowDate.getMonth() + 1;
//    Date        = NowDate.getDate();
//    time        = NowDate.getHours();
//    
//    checkdate = year+"-"+"0"+month+"-"+"0"+Date+" "+time;
//    
//    if( checkdate <= "2008-09-05 23")
//    {
//        FriendTestLuncherPlay(UserID);
//        if (PlayLauncher != "0")
//        {
//            return false;
//        }
//    }

	var rtn = 0;
	
	paramNames ="";
	paramValues ="";
	
	checkWebGameAccess();
	
//	alert(ActiveCheck());
	
	
	if(ActiveCheck()){
//		checklauncheraccess = true;
		
		if(checklauncheraccess){	
			var rtn = launcher.fnExecuteGame(RegInfo,GameParams,CheckFileList,DnPath);
			var str="";
			
			switch(rtn)
			{
				case 0 :	
					str = "";
					break;
				case 1 :
				    alert('클라이언트를 설치해 주세요.');
				    window.open("/Pds/download_pop.html","pop_agree","width=350,height=400,toolbar=0,scroll=0,resizable=no")
					//str = "Fail to get registry info\n\n레지스트리에 게임실행경로를 입력해주세요.\n\n";
					
                    //str += "예) [HKEY_CURRENT_USER\\Software\\Launcher Demo] \n\n path=\"C:\\Program Files\\Launcher Demo\\GameClient.exe\" ";		
					//opencdn("SpikeGirlsTest_V600.exe");
					break;
				case 2 :	
					str = "패치 다운로드를 실패 했습니다.";
					break;
				case 3 :	
					str = "패치 실행에 실패 했습니다.";
					break;
				case 4 :
				    window.open("/Pds/client_download.html","pop_down","width=345,height=180,toolbar=0,scroll=0,resizable=no")
					str = "Need to download all files";
					//opencdn("SpikeGirlsTest_V600.exe");
					break;
				default :  
					str = "--;";
			}
		
			if(str != "") alert(str); 
			
		}
		else
		{
			if(serverclosemessage){
				alert(ReplaceStr(serverclosemessage, "<br>", "\n"));
				serverclosemessage = null;
			}
			else{
				//alert('점검중입니다.');
				serverclosemessage = null;
			}
			location.reload();
		}						
	}
	else {
		alert('ActiveX가 정상적으로 설치 되지 않았습니다.\r\n고객센터 FAQ를 확인해 주세요.')
	}

}

function ReplaceStr(strOriginal, strFind, strChange)
{
	return strOriginal.split(strFind).join(strChange);
}

var opId = null;

function opencdn(downloadfile)
{
	CheckOS();
	var opUrl;
	

     opUrl = "http://downloader.hyosungcdn.com/spikegirls/SetupDown.asp?downfilename="+downloadfile;    	 
	     
	if(isVistar){
        window.open(opUrl,"Game");			        
	}
	else{
	     	     
		if(opId == null)
		{
			 opId = window.open(opUrl, "GE","titlebar = no, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=375");
		}
		else
		{ 
			if(opId.closed)
			{
				opId = null;
				opId = window.open(opUrl, "GE","titlebar = no, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=375");
			}
		}
    }
}


