// These functions instantiate the applet object for Java games.

var popcap_tag_container_begin = '';
var popcap_tag  = '';
var popcap_tag_container_end = '';
popcap_isJava = true;
if (popcap_external_ads) popcap_internal_ads = true;

/* PluginDetect v0.1.9 by Eric Gerds */
// usage: 
// PluginDetect.isMinVersion('Java', '1.2'); 
// PluginDetect.isMinVersion('Flash', '9'); 
// returns 1 on success, -1 on fail. 
var PluginDetect={minIEver:5.5,getNum:function(A){if(!A){return null}var m=/[\d][\d\.\_,-]*/.exec(A);return m?m[0].replace(/[\.\_-]/g,","):null},hasMimeType:function(_3){var s,t,z,M=_3.constructor==String?[_3]:_3;for(z=0;z<M.length;z++){s=navigator.mimeTypes[M[z]];if(s&&s.enabledPlugin){t=s.enabledPlugin;if(t.name||t.description){return s}}}return null},findNavPlugin:function(N,_6){var _7=N.constructor==String?N:N.join(".*"),numS=_6===false?"":"\\d";var i,re=new RegExp(_7+".*"+numS+"|"+numS+".*"+_7,"i");var _9=navigator.plugins;for(i=0;i<_9.length;i++){if(re.test(_9[i].description)||re.test(_9[i].name)){return _9[i]}}return null},getAXO:function(_a){var _b,e;try{_b=new ActiveXObject(_a);return _b}catch(e){}return null},num:function(A){return (typeof A!="string"?false:(/\d/).test(A))},compareNums:function(_d,_e){if(!this.num(_d)||!this.num(_e)){return 0}var m1=_d.split(","),m2=_e.split(","),x,p=parseInt;for(x=0;x<Math.min(m1.length,m2.length);x++){if(p(m1[x],10)>p(m2[x],10)){return 1}if(p(m1[x],10)<p(m2[x],10)){return -1}}return 0},formatNum:function(num){if(!this.num(num)){return null}var n=num.replace(/[\.\_]/g,","),i;n=n.split(",").concat(["0","0","0","0"]);return n.slice(0,4).join(",")},initScript:function(){var $=this,IE;$.isIE=(/*@cc_on!@*/false);$.IEver=-1;if($.isIE){var IE=(/msie\s*\d\.{0,1}\d*/i).exec(navigator.userAgent),progid,x;if(IE){$.IEver=parseFloat((/\d.{0,1}\d*/i).exec(IE[0]),10)}progid=["ShockwaveFlash.ShockwaveFlash","Msxml2.XMLHTTP","Microsoft.XMLDOM","Msxml2.DOMDocument","TDCCtl.TDCCtl","Shell.UIHelper","Scripting.Dictionary"];$.ActiveXEnabled=false;for(x=0;x<progid.length;x++){if($.getAXO(progid[x])){$.ActiveXEnabled=true;break}}};if($.ActiveXEnabled&&$.IEver>=$.minIEver){$.head=typeof document.getElementsByTagName!="undefined"?document.getElementsByTagName("head")[0]:null;var T=document.createElement("script");T.setAttribute("type","text/vbscript");var Y=["<!"+"--","function PluginDetect1(c)","on error resume next","PluginDetect1=false","dim head, r","set head=PluginDetect.head","set r=head.firstChild","if TypeName(r)=\"HTMLObjectElement\" then","r.setAttribute \"classid\", c","if not TypeName(r.getAttribute(\"object\")) = \"Nothing\" then","PluginDetect1=true","if r.getAttribute(\"readyState\")<4 then","r.clearAttributes()","head.removeChild(r)","end if","else r.clearAttributes()","head.removeChild(r)","end if","end if","r=\"Nothing\"","head=\"Nothing\"","end function","--"+">"];T.setAttribute("text",Y.join("\n"));if($.head.firstChild){$.head.insertBefore(T,$.head.firstChild)}else{$.head.appendChild(T)}$.vbscript=false;var e;$.head.insertBefore(document.createElement("object"),$.head.firstChild);try{if(PluginDetect1("")===false){$.vbscript=true}}catch(e){}}},init:function(_17){var $=this,IE,p;_17=_17.toLowerCase().replace(/\s/g,"");p=$.plugin=$[_17];if(!p){return -3}if(typeof p.minversion=="undefined"){p.minversion={}}if(typeof p.version=="undefined"){p.version=null}if(typeof p.installed=="undefined"){p.installed=null}$.garbage=false;if($.isIE&&!$.ActiveXEnabled){return -2}return 1},isMinVersion:function(_19,_1a){var $=PluginDetect,i=$.init(_19);if(i<0){return i}if(!$.num(_1a)){return -3}var p=$.plugin,m=p.minversion;_1a=$.formatNum(_1a);if(typeof m["a"+_1a]=="undefined"){if(p.installed==null&&p.getCodeBaseVersion&&$.IEver>=p.minIEver){var tmp,x;for(x in m){tmp=$.compareNums(_1a,x.substring(1,x.length));if(m[x]==1&&tmp<=0){return 1}if(m[x]==-1&&tmp>=0){return -1}}m["a"+_1a]=$.isActiveXObject(_1a)?1:-1}else{if(p.installed==null){p.getVersion()}if(p.installed==-1){m["a"+_1a]=-1}else{if(p.version==null){m["a"+_1a]=0}else{m["a"+_1a]=($.compareNums(p.version,_1a)>=0?1:-1)}}}}$.cleanup();return m["a"+_1a];return -3},getVersion:function(_1e){return null},cleanup:function(){var $=this;if($.garbage&&typeof window.CollectGarbage!="undefined"){window.CollectGarbage()}},isActiveXObject:function(_22){var $=this,result,s="<object width=\"1\" height=\"1\" "+"style=\"display:none\" "+$.plugin.getCodeBaseVersion(_22)+">"+$.plugin.HTML+"</object>";$.head.insertBefore(document.createElement("object"),$.head.firstChild);$.head.firstChild.outerHTML=s;result=$.vbscript?PluginDetect1($.plugin.classID):$.detect($.plugin.classID);return result},detect:function(_24){var $=this,result;$.head.firstChild.setAttribute("classid",_24);result=$.head.firstChild.getAttribute("object")?true:false;if(!result||$.head.firstChild.getAttribute("readyState")<4){$.head.firstChild.clearAttributes();$.head.removeChild($.head.firstChild);$.garbage=true}return result},search:function(){},dummy1:0};PluginDetect.initScript();PluginDetect.java={mimeType:"application/x-java-applet",classID:"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",JavaVersions:["1.7.0.15","1.6.0.15","1.5.0.14","1.4.2.13","1.3.1.18"],searchJava:function(M){if(!M){return null}var G,e,x3,x4;var AXO=ActiveXObject;var T=M.split("."),J="JavaPlugin."+T[0]+T[1],v=T[0]+"."+T[1]+".";for(x3=T[2];x3>=0;x3--){for(x4=T[3];x4>=0;x4--){G=x4<10?"0"+x4:x4;try{new AXO(J+x3+"_"+G);return v+x3+"_"+G}catch(e){}}if(J+x3=="JavaPlugin.131"){return null}try{new AXO(J+x3);return v+x3}catch(e){}}return null},minIEver:5.5,HTML:"<param name=\"code\" value=\"A14999.class\" />",getCodeBaseVersion:function(v){var r=this.getDigits(v),$=PluginDetect;if($.compareNums(v,"1,4,1,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]}else{if($.compareNums(v,"1,5,0,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]+"0"}else{v=Math.round((parseFloat(r[0]+"."+r[1],10)-1.5)*10+5)+","+r[2]+","+r[3]+"0"+",0"}}return "codebase=\"#version="+v+"\""},digits:[1,9,32,32],getDigits:function(n){/([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)/.test(n);return [RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4]},hasRun:false,value:null,queryJavaHandler:function(){var $=PluginDetect.java,j=window.java,e;$.hasRun=true;try{if(typeof j.lang!="undefined"&&typeof j.lang.System!="undefined"){$.value=j.lang.System.getProperty("java.version")+" "}}catch(e){}},queryJava:function(){var $=PluginDetect,t=this,nua=navigator.userAgent,e;if(typeof window.java!="undefined"&&window.navigator.javaEnabled()){if(/gecko/i.test(nua)){if($.hasMimeType("application/x-java-vm")){try{var div=document.createElement("div"),evObj=document.createEvent("HTMLEvents");evObj.initEvent("focus",false,true);div.addEventListener("focus",t.queryJavaHandler,false);div.dispatchEvent(evObj)}catch(e){}if(!t.hasRun){t.queryJavaHandler()}}}else{if(/opera.9\.(0|1)/i.test(nua)&&/mac/i.test(nua)){return null}t.queryJavaHandler()}}return t.value},getVersion:function(){var _3a=null,$=PluginDetect;if(!$.isIE){var p1,p,mt;p=$.findNavPlugin(["Java","Plug-in"]);mt=$.hasMimeType(this.mimeType);if(p){p1=$.getNum(p.description)}if(p1&&mt&&navigator.javaEnabled()){_3a=p1}if(!_3a){p=this.queryJava();if(p){_3a=p}}this.installed=-1;if(_3a){this.installed=1}else{if(mt&&navigator.javaEnabled()){if(/macintosh/i.test(navigator.userAgent)&&/safari/i.test(navigator.userAgent)){this.installed=0}}}}else{var x,tmp=null;if($.IEver>=this.minIEver){_3a=$.search();this.installed=_3a?1:-1}else{for(x=0;x<this.JavaVersions.length;x++){tmp=this.searchJava(this.JavaVersions[x]);if(tmp){_3a=tmp;break}}this.installed=_3a?1:($.getAXO("JavaPlugin")?0:-1)}}this.version=$.formatNum($.getNum(_3a))}};PluginDetect.flash={mimeType:["application/x-shockwave-flash","application/futuresplash"],progID:"ShockwaveFlash.ShockwaveFlash",classID:"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000",getVersion:function(){var _3f=function(A){if(!A){return null}var m=/[\d][\d\,\.\s]*[rRdD]{0,1}[\d\,]*/.exec(A);return m?m[0].replace(/[rRdD\.]/g,",").replace(/\s/g,""):null};var p,$=PluginDetect,e,i,version=null,AXO=null,majV=null;if(!$.isIE){p=$.findNavPlugin("Flash");if(p&&p.description&&$.hasMimeType(this.mimeType)){version=_3f(p.description)}}else{for(i=15;i>2;i--){AXO=$.getAXO(this.progID+"."+i);if(AXO){majV=i.toString();break}}if(majV=="6"){try{AXO.AllowScriptAccess="always"}catch(e){return "6,0,21,0"}}try{version=_3f(AXO.GetVariable("$version"))}catch(e){}if(!version&&majV){version=majV}}this.installed=version?1:-1;this.version=$.formatNum(version)}};

function WriteDoc()
{	
    for (var a = 0; a < arguments.length; a++)
		popcap_tag += arguments[a];
}

function WriteParam(key,val)
{
	WriteDoc('<param name="', key, '" value="', val, '">\n');
}

function CreateGameTags()
{
	popcap_tag_container_begin = '<div id="gamediv">\n';

	WriteDoc('<applet\n');
	WriteDoc('code=',popcap_applet_class,'\n');
	WriteDoc('id=GameObject\n');
	WriteDoc('name=GameObject\n');
	WriteDoc('width=', popcap_app_width, '\n');
	WriteDoc('height=', popcap_app_height, '\n');
	WriteDoc('archive=', popcap_applet_jar, '\n');
	//CUSTOMIZED: enable full path to webgame files
	if (popcap_applet_codebase) {
		WriteDoc('codebase=', popcap_applet_codebase, '\n');
	}
	WriteDoc('viewastext mayscript\n');
	WriteDoc('>\n');

	WriteParam('cabbase',popcap_applet_cab);
	WriteParam('JSNotify','ReceiveNotification');
	WriteParam('bgcolor','CCFFFF');
	WriteParam('NoErrorPage','1');

	for (var i=0; i<popcap_applet_hosts.length; i++)
		WriteParam('host' + (i+1), popcap_applet_hosts[i]);

	WriteParam('hosterr',popcap_applet_hosterr);
	WriteParam('hosterrhash',popcap_applet_hosterrhash);	

	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);
	}

	if (popcap_internal_ads)
	{
		popcap_params.push('ShowAds');
		popcap_paramvals.push('true');

		popcap_params.push('adUrl');
		popcap_paramvals.push(popcap_upsellURL);
	}

	for (var i=0; i < popcap_params.length; i++)
		WriteParam(popcap_params[i],popcap_paramvals[i]);


	WriteDoc('</applet>\n');
	
	popcap_tag_container_end = '</div>\n';
	
	//CUSTOMIZED: 
	//firefox needs tags written after preroll runs/fails in ad.js
	//ie writes tag to trigger install prompts
	document.write(popcap_tag_container_begin);
	if (!popcap_runPreroll || (popcap_isIE && navigator.userAgent.indexOf('MSIE 7') == -1)) document.write(popcap_tag); //see ad.js "show the game" for special popcap_runPreroll = true handling
	document.write(popcap_tag_container_end);
}

function ReloadPlugin()
{
	if (!popcap_isIE) navigator.plugins.refresh(true);
	window.location.reload(false);
}

function CheckForJava()
{
	var java_installed = false;
	if (popcap_isIE) 
	{
		try 
		{
			//var axo = new ActiveXObject('JavaWebStart.isInstalled');
			if (PluginDetect.isMinVersion('Java', '1.2') != -1)
			{
				$("#plugin_dialog_java").hide();
				scroll(0,0);
				java_installed = true;
			}
			else
			{
				//no java detection for win98/ME users, assume they have java
				//otherwise show install dialog
				if (navigator.userAgent.indexOf('Windows 98') == -1)
				{
					$("#plugin_dialog_java").slideDown("slow");
					scroll(0,0);
				}
				else {
					java_installed = true;
				}
			}
		}
		catch (e)
		{
			//no java detection for win98/ME users, assume they have java
			//otherwise show install dialog
			if (navigator.userAgent.indexOf('Windows 98') == -1)
			{
				$("#plugin_dialog_java").slideDown("slow");
				scroll(0,0);
			}
		}
		CreateGameTags();
		if (popcap_runPreroll) thisObject('gamediv').style.visibility = 'hidden';
	}
	else
	{
		if ($.plugdetect('java') || $.browser.safari || ($.browser.opera && navigator.javaEnabled())) {
			java_installed = true; 
		}
		else if ($.platform.mac) {
			$("#plugin_dialog_mac").slideDown("slow");
			scroll(0,0);
		}
		else
		{
			$("#plugin_dialog_java").slideDown("slow");
			scroll(0,0);
		}
			
		CreateGameTags();
		if (popcap_runPreroll) thisObject('gamediv').style.visibility = 'hidden';
	}
	return java_installed;
}

java_installed = CheckForJava();