/*
	- writer : ccs
	- modify : kkj 2008-08-05 
*/

var Domain_APP      = "http://app.joycity.com";
var Domain_APP_CDN  = "http://app-patch.jceworld.com/app-patch";

function isAbleActiveX(ModuleID)
{		
	var ModuleName, ModuleCLSID, ModuleVersion, DivModule;

	for(var i=0;i<arrModuleInfo.length;i++)
		if(arrModuleInfo[i].ModuleName == ModuleID)
		{
			ModuleName = arrModuleInfo[i].ModuleName;
			ModuleCLSID = arrModuleInfo[i].ModuleCLSID;
			ModuleVersion = arrModuleInfo[i].ModuleVersion;
			DivModule = "Div"+ModuleName;			
		}

	if (document.all.item(DivModule) == null)
	{
		var ModuleFolder = "cab";
		if(Domain_WWW != null)
		{
			if(Domain_WWW == "http://fs.paran.com")
				ModuleFolder = "cab_paran";					
		}
		document.body.insertAdjacentHTML("beforeEnd","<div id=\""+DivModule+"\"><object id='"+ModuleName+"' classid='CLSID:"+ModuleCLSID+"' width='0' height='0' CODEBASE='"+Domain_APP+"/_app/"+ModuleFolder+"/JCGameManager.cab#version="+ModuleVersion+"'></object></div>");
	}

	var bModuleAvailable = false;	

	if ( document.all.item(ModuleName) != null)
	{
		if (document.all.item(ModuleName).readyState == 4)
			if (document.all.item(ModuleName).object != null)
				bModuleAvailable = true;
	}
	if(!bModuleAvailable)
		return 0;
	else
		return 1;
}

function isInstalledActiveX(ModuleID)
{	
	var ObjectName;	
	if( ModuleID == "LauncherAX" )	ObjectName = "JCGameManager.Launcher";
	if( ModuleID == "SysInfoAX" )	ObjectName = "JCGameManager.SystemInfo";
	if( ModuleID == "BrowserAX" )	ObjectName = "JCGameManager.BrowserInfo";
				
	try {
		var obj = new ActiveXObject(ObjectName);
		if(obj) Installed = true;
		else 	Installed = false;
	} catch(ex) {
		Installed = false;
	}
	
	// return 
	if(Installed == true) 
		return 1;	
	else 
		return 0;
}

function ModuleInfo(ModuleName,ModuleFolder,ModuleFile,ModuleVersion,ModuleCLSID,ModuleLoad)
{	
	this.ModuleName = ModuleName;
	this.ModuleFolder = ModuleFolder;
	this.ModuleFile = ModuleFile;
	this.ModuleVersion = ModuleVersion;
	this.ModuleCLSID = ModuleCLSID;
	this.ModuleLoad = ModuleLoad;
}
var arrModuleInfo = new Array();
///////////////////////////Module Versions/////////////////////////
arrModuleInfo[0] = new ModuleInfo("SysInfoAX","cab","JCGameManager.cab","1,0,0,8","348CE212-36CE-4E40-9F56-3F0AFAF7BAE3","1");
arrModuleInfo[1] = new ModuleInfo("BrowserAX","cab","JCGameManager.cab","1,0,0,8","910074AB-A93A-4090-A5D4-53ADDE759880","1");
arrModuleInfo[2] = new ModuleInfo("JSImageEditorAX","ocx","JSImageEditorAX.ocx","1,0,0,13","C7D00E11-3F7C-4A53-A740-62F12E51C52D","1");
arrModuleInfo[3] = new ModuleInfo("FSGameLauncherModule","exe","FSGameLauncherModule.exe","2,0,0,14","","0");
arrModuleInfo[4] = new ModuleInfo("ANLauncherApp","exe","ANLauncherApp.exe","1,0,0,1","","0");
arrModuleInfo[5] = new ModuleInfo("HISGameLauncher","exe","HISGameLauncher.exe","2,0,0,4","","0");
arrModuleInfo[6] = new ModuleInfo("GXGameLauncher","exe","GXGameLauncher.exe","2,0,0,16","","0");
arrModuleInfo[7] = new ModuleInfo("libdfp","dll","libdfp.dll","1.0.2.2","","0");
arrModuleInfo[8] = new ModuleInfo("FSFGameLauncher","exe","FSFGameLauncher.exe","1,0,0,3","","0");
arrModuleInfo[9] = new ModuleInfo("FSMGameLauncher","exe","FSMGameLauncher.exe","1,0,0,3","","0");
arrModuleInfo[10] = new ModuleInfo("VSGameLauncher","exe","VSGameLauncher.exe","1,0,0,3","","0");
arrModuleInfo[11] = new ModuleInfo("JCGameLauncher","exe","JCGameLauncher.exe","1,1,0,19","","0");
arrModuleInfo[12] = new ModuleInfo("JCGameLauncherFS2","exe","JCGameLauncherFS2.exe","1,0,0,5","","0");
arrModuleInfo[13] = new ModuleInfo("TLGameLauncher","exe","TLGameLauncher.exe","1,1,0,19","","0");
///////////////////////////Module Versions/////////////////////////

function CheckModule(ModuleName)
{	
	var ModuleFolder,ModuleFile,ModuleVersion,ModuleCLSID,ModuleLoad;

	for(var i=0;i<arrModuleInfo.length;i++)
		if(arrModuleInfo[i].ModuleName == ModuleName)
		{
			ModuleFolder = arrModuleInfo[i].ModuleFolder;
			ModuleFile = arrModuleInfo[i].ModuleFile;
			ModuleVersion = arrModuleInfo[i].ModuleVersion;
			ModuleCLSID = arrModuleInfo[i].ModuleCLSID;
			ModuleLoad = arrModuleInfo[i].ModuleLoad;
		}
	var ret = JCGameManager.CheckModule(ModuleFile,ModuleVersion,Domain_APP+"/_app/"+ModuleFolder+"/");
	if(ret == 1)
	{
		if(ModuleLoad == "1")
		{
			load_control(ModuleName,ModuleCLSID);
			for(var k=0;k<1;k++)
			{
				if (eval(ModuleName+".object") == null)
				{
					JCGameManager.CheckModule(ModuleFile,ModuleVersion,Domain_APP+"/_app/"+ModuleFolder+"/");
					load_control(ModuleName,ModuleCLSID);
				}
			}
			if (eval(ModuleName+".object") == null)
			{
				ret = -11
			}
		}			
	}
	return ret;
}

function load_control(ModuleName,ModuleCLSID)
{
	var span_ctl = document.all.item(ModuleName+'_span');
	if (span_ctl == null) {
		document.body.insertAdjacentHTML("beforeEnd","<SPAN id='"+ModuleName+"_span'></span>");
		span_ctl = document.all.item(ModuleName+'_span');
	}
	span_ctl.innerHTML = "";
	var strObj = "<object id='"+ModuleName+"' classid='CLSID:"+ModuleCLSID+"' width='0' height='0'></object>";
	span_ctl.innerHTML = strObj;
}

function GetModuleInfo(ModuleName)
{
	var ModuleFolder,ModuleFile,ModuleVersion,ModuleCLSID,ModuleLoad;

	for(var i=0;i<arrModuleInfo.length;i++)
		if(arrModuleInfo[i].ModuleName == ModuleName)
		{
			ModuleFolder = arrModuleInfo[i].ModuleFolder;
			ModuleFile = arrModuleInfo[i].ModuleFile;
			ModuleVersion = arrModuleInfo[i].ModuleVersion;
			ModuleCLSID = arrModuleInfo[i].ModuleCLSID;
			ModuleLoad = arrModuleInfo[i].ModuleLoad;
		}
	var ret = ModuleFile +"$"+ ModuleVersion +"$"+ Domain_APP_CDN+"/_app/"+ModuleFolder+"/";
	return ret;
}

