﻿//NGMModuleInfo.js
var NGMModuleInfo = '<?xml version="1.0"?><NGMModule><NGMDll host="ngm.nexon.net/ngm/NGM/Bin/NGMDll.dll" crc="570864249" /><GameData><combatarms_us gamecode="33563143" crc="0" /></GameData></NGMModule>';

//npf_ngm.js
function _NGM() {
    this.strGameAXName = "NXCOM.NxGameControl.US.2";
    this.strGameFPName = "application/x-npnxgame-us"
    this.objNxGame = null;
    this.versionNxGame = 0;

    this.strNxMInfoAXName = "NXCOM.NxMachineControl.US.1";
    this.strNxMInfoFPName = "application/x-npnxminfo-us"
    this.objNxMInfo = null;
    this.versionNxMInfo = 0;

    this.strServerHost = "ngm.nexon.net/ngm/NGM/Bin/NGMDll.dll";
    this.strNGMDllCRC = "";
    this.strGameDatas = "";

    this.strInstallPage = "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() {
        alert("NGM Not Installed");
    }

    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 {
            return this.objNxMInfo.GenerateMID();
        }
        catch (ex) {
            this.ErrorHandler();
        }
    }

    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.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.DownloadNGM = function NGM_DownloadNGM() {
        var DownloadURL = "http://ngm.nexon.net/ngm/NGM/Bin/Setup.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();

