﻿//2009-02 通过玩玩下载游戏资源的接口脚本
// com object
var  wwcom = null;

function CreateIEObject() 
{
    if (wwcom == null) 
    {
        try 
        {
            wwcom = new ActiveXObject("wwcom.WanWanCom");
            return true;
        }
        catch (e) 
        {
            return false;
        }
    }
    else
    {
        return true;
    }
}


// checked if wanwan is setup
function CheckWanwanSetup()
{
    if (wwcom == null) 
    {
        try 
        {
            wwcom = new ActiveXObject("wwcom.WanWanCom");
            return true;
        }
        catch (e) 
        {
            return false;
        }
    }
    else
    {
        return true;
    }
}
 
// down wanwan
function DownLoadWanwan()
{
    document.location = 'http://wanwan.131.com/download/131wanwan_net.exe';
}
 
// load installed games
function GetInstalledGameList()
{
    if (!CheckWanwanSetup())
     {
        return null;
    }
 
    try
    {
        var list = wwcom.GetInstalledGameList(0);
        if (list == '')
        {
            return null;
        }
        else
        {
            return list.split('|');
        }
    }
    catch(e)
    {
        return null;
    }
}
 

// check if game is setup
function CheckGameSetup(gameID)
{
    var installList = GetInstalledGameList();
    if (installList == null)
    {
        return false;
    }
 
    try
    {
        for(var i = 0, j = installList.length; i < j; i++)
        {
            if (installList[i] == gameID)
            {
                return true;
            }
        }
  
        return false;
    }
    catch(e)
    {
        return false;
    }
}
 
// download game and auto setup
function AddDownloadTask(id, ed2kUrl)
{
    if (!CheckWanwanSetup())
    {
        if (confirm('对不起，此链接需要安装131玩玩才能正常下载，请您安装后重试。'))
        {
            DownLoadWanwan();
        }
        return;
    }
    try
    {
        wwcom.AddDownloadTask(id, ed2kUrl);
    }
    catch(e)
    {
    }
}

// only down the file
function DownloadFile(ed2kUrl)
{
	if (!CheckWanwanSetup())
    {
        if (confirm('对不起，此链接需要安装131玩玩才能正常下载，请您安装后重试。'))
        {
            DownLoadWanwan();
        }
        return;
    }
	
    try
    {
        wwcom.DownloadFile(ed2kUrl, 0);
    }
    catch(e)
    {
    	if(confirm('您的玩玩版本不是最新。是否现在就启动玩玩升级？'))
    	{
    		RunWanwan();
    	}
    }
}
 
// run game
function RunGame(id)
{
    try
    {
        wwcom.RunGame(id);
    }
    catch(e)
    {}
}

function SkipLable(index)
{
    try
    {
        return webobj.SkipLable(index);
    }
    catch(e){}
}

function RunWanwan()
{
	SkipLable(1);
}