function _NGM()
{
	this.strGameAXName		= "NXCOM.NxGameControl.2";
	this.strGameFPName		= "application/x-npnxgame"
	this.objNxGame			= null;
	this.versionNxGame		= 0;
	
	this.strNxMInfoAXName	= "NXCOM.NxMachineControl.2";
	this.strNxMInfoFPName	= "application/x-npnxminfo"
	this.objNxMInfo			= null;
	this.versionNxMInfo		= 0;
	
	this.strServerHost	= "platform.nexon.com/NGM/Bin/NGMDll.dll";
	this.strNGMDllCRC	= "";
	this.strGameDatas	= "";
	
	this.strInstallPage = "http://platform.nexon.com/ngm/html/pop_ngm_guide.html";
	
	// Browser Info Setting
	if (window.navigator.appName == "Microsoft Internet Explorer")
	{
		this.BrowserInfo= "IE";
	}
	else if (window.navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
	{
		this.BrowserInfo= "FF";
	}
	else if (window.navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
	{
		this.BrowserInfo= "Chrome";
	}
	else if (window.navigator.userAgent.toLowerCase().indexOf('opera') > -1)
	{
		this.BrowserInfo= "Opera";
	}
	else if (window.navigator.userAgent.toLowerCase().indexOf('safari') > -1)
	{
		this.BrowserInfo= "Safari";
	}
	else if (window.navigator.userAgent.toLowerCase().indexOf('netscape') > -1)
	{
		this.BrowserInfo= "Netscape";
	}
	else
	{
		this.BrowserInfo= "Unknown";
	}
	
	if ( this.BrowserInfo== "IE" )
	{
		this.ModuleFormat= "AX";
	}
	else if (  this.BrowserInfo== "Unknown")
	{
		this.ModuleFormat= "err";
	}
	else
	{
		this.ModuleFormat= "NP";
	}
  
	if (this.ModuleFormat == "NP")
	{
		navigator.plugins.refresh(false);
		
		var mimetype1 = navigator.mimeTypes[ this.strGameFPName ];
		
		if (mimetype1 && mimetype1.enabledPlugin)
		{
			document.write("<span style='position:absolute;top:100px;left:100px;z-index:1'><embed id=\"npnxgame\" type=\"" + this.strGameFPName + "\" pluginspage=\"" + this.strInstallPage + "\" HIDDEN=\"true\"/></span>");
		}
		
		var mimetype2 = navigator.mimeTypes[ this.strNxMInfoFPName ];
		
		if (mimetype2 && mimetype2.enabledPlugin)
		{
			document.write("<span style='position:absolute;top:100px;left:100px;z-index:1'><embed id=\"npnxminfo\" type=\"" + this.strNxMInfoFPName + "\" pluginspage=\"" + this.strInstallPage + "\" HIDDEN=\"true\"/></span>");
		}
	}
	
	this.ErrorHandler = function NGM_ErrorHandler()
	{
		window.open( this.strInstallPage, null, "height=430,width=488,status=yes,toolbar=no,menubar=no,location=no");
	}
	
	this.LoadModuleInfo = function NGM_LoadModuleInfo()
	{
		if (this.ModuleFormat== "AX")
		{
			var xmlDoc	= null;
			var xmlObj	= null;
						
			try
			{
				xmlDoc	= new ActiveXObject( "Microsoft.XMLDOM" );
			}		
			catch( ex )
			{
			}
			
			if ( xmlDoc != null )
			{
				xmlDoc.async="false";
				
				if ( xmlDoc.loadXML( NGMModuleInfo ) )
				{
					xmlObj	= xmlDoc.documentElement;
					
					var nodeNGMDll		= xmlObj.getElementsByTagName( "NGMDll" )[0];
					
					this.strServerHost	= nodeNGMDll.getAttribute( "host" );
					this.strNGMDllCRC	= nodeNGMDll.getAttribute( "crc" );
					this.strGameDatas	= "";
				}
			}
		}
		else if (this.ModuleFormat= "NP")
		{
			var parser=new DOMParser();
	 		var doc = parser.parseFromString(NGMModuleInfo,"text/xml");
			var xmlObj=doc.documentElement;

			var nodeNGMDll		= xmlObj.getElementsByTagName( "NGMDll" )[0];
			this.strServerHost	= nodeNGMDll.getAttribute( "host" );
			this.strNGMDllCRC	= nodeNGMDll.getAttribute( "crc" );

			this.strGameDatas	= "";
		} 
		
	}
	
	this.InitGameControl = function NGM_InitGameControl()
	{
		if( this.objNxGame == null )
		{
			try
			{
				if (this.ModuleFormat== "AX")
				{
					this.objNxGame = new ActiveXObject( this.strGameAXName );
				}
				else if (this.ModuleFormat= "NP")
				{
					this.objNxGame = document.getElementById('npnxgame');
				}				
			}
			catch( ex )
			{
			}

			if ( this.objNxGame != null )
			{
				this.LoadModuleInfo();
				
				this.objNxGame.ServerHost	= this.strServerHost;
				this.objNxGame.NGMDllCRC	= this.strNGMDllCRC;
				this.objNxGame.GameDatas	= this.strGameDatas;
				
				try
				{
					this.versionNxGame = this.objNxGame.GetVersion()
				}
				catch ( ex )
				{
					this.versionNxGame = 1.0;								
				}
			}
		}
	}

 	this.InitMachineControl = function NGM_InitMachineControl()
 	{
		if( this.objNxMInfo == null )
		{
			try
			{
				if (this.ModuleFormat== "AX")
				{
					this.objNxMInfo = new ActiveXObject( this.strNxMInfoAXName );
				}
				else if (this.ModuleFormat= "NP")
				{
					this.objNxMInfo = document.getElementById('npnxminfo');
				}				
			}
			catch( ex )
			{
			}
			
			if ( this.objNxMInfo != null )
			{
				try
				{
					this.versionNxMInfo = this.objNxMInfo.GetVersion()
				}
				catch ( ex )
				{							
				}
			}
		}
	}
	
	this.GenerateMID = function NGM_GenerateMID()
	{
		this.InitMachineControl();
		
		try
		{
			var mid = this.objNxMInfo.GenerateMID();
			
			if ( mid == '')
			{
				if ( this.versionNxMInfo >= 1.1 )
				{
					alert( "°í°´´ÔÀÇ PC È¯°æ¿¡¼­´Â ÁöÁ¤PC ÀÌ¿ëÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù." );
				}
				else
				{
					this.ErrorHandler();
				}
			}
			
			return mid;
		}
		catch( ex )
		{
			this.ErrorHandler();
		}
		return '';
	}
	
	this.GetComputerName = function GetComputerName()
	{
		this.InitMachineControl();
		
		try
		{
			var name = this.objNxMInfo.GetPCName();
			
			return name;
		}
		catch( ex )
		{
			this.ErrorHandler();
		}
		return '';
	}

	this.GxForceInstall = function NGM_GxForceInstall( game, arg, passport )
	{
		this.InitGameControl();
		
		try
		{
			var ret		= this.objNxGame.ForceInstall( String( game ), String( passport ), String( arg ) );

			if( 2 == ret )
			{
				this.ErrorHandler();
			}
			else if ( 0 != ret )
			{
				alert( "Cannot Launch NGM! error code=" + ret );
			}
		}
		catch( ex )
		{
			this.ErrorHandler();
		}

	}
	
	this.GxLaunchGame = function NGM_GxLaunchGame( game, arg, passport )
	{
		this.InitGameControl();
	
		try
		{
			var ret		= this.objNxGame.Launch( String( game ), String( passport ), String( arg ) );
	
			if( 2 == ret )
			{
				this.ErrorHandler();
			}
			else if ( 0 != ret )
			{
				alert( "Cannot Launch NGM! error code=" + ret );
			}
		}
		catch( ex )
		{
			this.ErrorHandler();
		}
	}
	
	this.WriteLogHandler = function NGM_WriteLogHandler( resultObject, responseXML )
	{
	}
	
	this.LaunchGameForGuestUser = function NGM_LaunchGameForGuestUser( game, arg )
	{
		var ngp	= this.GetCookie( "NGP" );
		this.GxLaunchGame(game, arg, ngp);	
	}
		
	this.LaunchGame = function NGM_LaunchGame( game, arg )
	{
		var npp	= this.GetCookie( "NPP" );
		this.GxLaunchGame(game, arg, npp);	
	}
	
	this.ForceInstall = function NGM_ForceInstall( game, arg )
	{
		var npp	= this.GetCookie( "NPP" );
		this.GxForceInstall(game, arg, npp);	
	}
	
	
	this.QxForceInstall = function NGM_QxForceInstall( game, arg )
	{
		var qpenc	= this.GetCookie( "QPENC" );
		this.GxForceInstall(game, arg, qpenc);	
	}
	
	this.QxLaunchGame = function NGM_QxLaunchGame( game, arg )
	{
		var qpenc	= this.GetCookie( "QPENC" );
		this.GxLaunchGame(game, arg, qpenc);	
	}
	
	
	this.MxForceInstall = function NGM_MxForceInstall( game, arg )
	{
		var msenc	= this.GetCookie( "MSGENC" );
		this.GxForceInstall(game, arg, msenc);
	}
	
	this.MxLaunchGame = function NGM_MxLaunchGame( game, arg1, arg2 )
	{
		var msenc		= this.GetCookie( "MSGENC" );
		var launchtype	= String( arg1 ).toLowerCase();
		var lastworld	= String( arg2 ).toLowerCase();
		
		if ( lastworld != null && lastworld != "" && lastworld != "undefined" )
		{
			msenc	= msenc + ":" + arg2;
		}
		if ( launchtype == "gameluanching" )
		{
			msenc	= "";
		}
		
		this.GxLaunchGame(game, arg1, msenc);
	}
	
	
	this.DownloadNGM = function NGM_DownloadNGM()
	{
		var DownloadURL = "http://platform.nexon.com/NGM/Bin/Setup.exe";
		if( Platform.IsTestPlatform() )
			DownloadURL = "http://platform.nexon.com/NGM/Bin/SetupT.exe";
		
		location.href = DownloadURL;	
	}
	
	this.GetCookie = function NGM_GetCookie( nameVal )
	{
		var numCookie = document.cookie.length;
		var oven = document.cookie.split( '; ' );
	
		for ( var i = 0; i < oven.length; i++ )
		{
			if ( oven[i].indexOf( '=' ) != -1 )
			{
				cookieName = oven[i].substring( 0, oven[i].indexOf( '=' ) );
			} else {
				cookieName = oven[i];
			}
	
			if ( cookieName == nameVal )
			{
				if ( oven[i].indexOf( '=' ) != -1 )
				{
					cookieVal = oven[i].substr( oven[i].indexOf( '=' ) + 1 );
				} else {
					cookieVal = '';
				}
				return cookieVal;
			}
		}
		return '';
	}
}

var NGM = new _NGM();