// These functions instantiate the ActiveX object for ActiveX games.

var popcap_tag  = '';
popcap_isAX		= true;

function WriteDoc()
{	
    for (var a = 0; a < arguments.length; a++)
		popcap_tag += arguments[a];
}

function WriteParam(key,val)
{
	if (popcap_isIE) // Object
		WriteDoc('<PARAM name="', key, '" value="', val, '">\n');
	else		 // Embed
		WriteDoc(key, '="', val, '"\n');
}

function CreateGameTags()
{
	WriteDoc('<div ID="gamediv">\n');
	
	if (popcap_isIE) 
	{
		WriteDoc('<object\n');
		WriteDoc('id="GameObject"\n');
		WriteDoc('classid="clsid:DF780F87-FF2B-4DF8-92D0-73DB16A1543A"\n');
		WriteDoc('codebase="', popcap_loadercab_url, '"\n');		
		WriteDoc('width=', popcap_app_width, '\n');
		WriteDoc('height=', popcap_app_height, '\n');
		WriteDoc('>\n');
	}
	else
	{
		WriteDoc('<embed \n');
		WriteDoc('type="application/x-popcaploader;version=1.0.0.1"\n');
		WriteDoc('width=', popcap_app_width, '\n');
		WriteDoc('height=', popcap_app_height, '\n');
		WriteDoc('id="GameObject"\n');
	}

	WriteParam('numhosts',popcap_ax_hosts.length);
	
	for (var i=0; i < popcap_ax_hosts.length; i++)
	{
		WriteParam('host' + (i+1), popcap_ax_hosts[i]);
		WriteParam('hostsig' + (i+1), popcap_ax_hostsigs[i]);
	}

	WriteParam('gamename',popcap_gamename);
	WriteParam('partnername',popcap_partnername);
	WriteParam('displayname',popcap_displayname);
	WriteParam('gamecab',popcap_gamecab);

	if (popcap_logo_url != null)
		WriteParam('logocab',popcap_logo_url);
	
	if (popcap_cheats)
	{
		popcap_params.push('cheats');
		popcap_paramvals.push('true');
	}

	if (popcap_score_broadcast != 0)
	{
		popcap_params.push('pc_scorebroadcast');
		popcap_paramvals.push(popcap_score_broadcast);
	}

	popcap_params.push('ShowUpsell');
	
	if (!popcap_internal_ads) popcap_paramvals.push('false');
	else popcap_paramvals.push('true');
	
	if (popcap_enableZone || popcap_isZoneAPIonly)
	{
		popcap_params.push('ZoneScript');
		popcap_paramvals.push('true');
	}		
	
	if (popcap_params.length>0)
	{
		var params = '';
		
		for (var i=0; i < popcap_params.length; i++)
		{
			if (i!=0) params += ',';
		
			params += popcap_params[i];
		}

		WriteParam('params',params);
		
		for (var i=0; i < popcap_params.length; i++)
			WriteParam(popcap_params[i],popcap_paramvals[i]);
	}

	if (popcap_isIE)
	{
		WriteDoc('</object>\n');
		WriteDoc('<script for="GameObject" event="PopcapNotification(method,param)" language="JavaScript">\n');
		WriteDoc('ReceiveNotification(method,param);\n');
		WriteDoc('</scr','ipt>\n');
	}
	else
	{
		WriteDoc('>\n');
		WriteDoc('</embed>\n');
	}
	
	WriteDoc('</div>\n');

	document.write(popcap_tag);
}

function reloadPlugin()
{
	navigator.plugins.refresh(false);		
	window.location.href = window.location.href;
}

function CheckForNetscapePlugin()
{
	try
	{
		var pluginType = 'application/x-popcaploader;version=1.0.0.1';
		mimetype = navigator.mimeTypes[pluginType];
		
		if (!(mimetype && mimetype.enabledPlugin && mimetype.type==pluginType))
		{
			//document.write('<br>You need to get the PopCap Plugin to run this game.<br>');
			//document.write('Get the PopCap Plugin <a href="', popcap_plugin_url, '">here</a>!<br>');
			//document.write('After installing the plugin, launch the game <a href="javascript:;" onclick="reloadPlugin()">here</a>!<br>');
			document.write('<div style="color:red; margin-left:60px; text-align:left; margin-bottom:10px;">');
			document.write('<br>このゲームをプレイするにはプラグインが必要です。<br>');
			document.write('1. プラグインを<a href="', popcap_plugin_url, '">こちら</a>からダウンロードしてください。<br>');
			document.write('2. ダウンロードしたファイルをダブルクリックしてインストールしてください。<br>');
			document.write('3. インストールが完了したら<a href="javascript:;" onclick="reloadPlugin()">こちら</a>をクリックします。ゲームが表示されます。<br>');
			document.write('</div>');
		}
		else
		{
			CreateGameTags();
			
			if (popcap_runPreroll) thisObject('gamediv').style.visibility = 'hidden';
		}
	}
	catch (e)
	{
	}
}

if (popcap_isIE)
{
	CreateGameTags();
	
	if (popcap_runPreroll) thisObject('gamediv').style.visibility = 'hidden';
}
else CheckForNetscapePlugin();

function PopcapNotification_GameObject(method,param) 
{
	ReceiveNotification(method,param);
}

