TempCode = 548;

ActiveXVersion = "1,0,0,29"



function detectActiveXCTL()
{
  if (window.ActiveXObject) 
  {  
      var control = null;  
     try {  
          control = new ActiveXObject('ScriptableActiveX.CamSpaceActiveX.5');
      } catch (e) {  
	 //alert("nope, catch... ");
          return false;  
      }  
      if (control) {  
	 //alert("it exists");
          isInstalled = true;

		  control.FakeSocket="hello";
		  if (control.FakeSocket!="Hello to you too")
		  {
			return false;
		  }

		  
		  control.FakeSocket="getver";
		  ver = control.FakeSocket;
		  //alert(ver);
		  if (ver != ActiveXVersion)
		  {
			return false;
		  }
		  
	//	  alert(b);
	//alert("CamSpaceActiveX latest version is now installed, refreshing page...");
		  return true;
      }  
  } else {  
  return false;
      // Check navigator.plugins for "Shockwave for Director"  
  }
}


function install (aEvent)
{
 
  var params = {
    "Camspace": { URL: aEvent.currentTarget.href,
             IconURL: aEvent.currentTarget.getAttribute("iconURL"),
             Hash: aEvent.currentTarget.getAttribute("hash"),
             toString: function () { return this.URL; }
    }
  };
  InstallTrigger.install(params);
  return false;
}

function SetCamSpaceObjectSize(Width,Height)
{
	document.getElementById('CamSpaceOBJ').width = Width;
	document.getElementById('CamSpaceOBJ').height = Height;
};

function MessageCamSpaceActiveX(s)
{
	document.getElementById('CamSpaceOBJ').FakeSocket = s;
	return getElementById('CamSpaceOBJ').FakeSocket;
};

function SetCamSpaceGame(Game)
{
	MessageCamSpaceActiveX("game:"+Game);
};

function SetCamSpaceExtComponentSize(Width,Height)
{
	getElementById('CamSpaceOBJ').HaveExtComponent = 1;
	getElementById('CamSpaceOBJ').ExtComponentWidth = Width;
	getElementById('CamSpaceOBJ').ExtComponentHeight = Height;
	getElementById('CamSpaceFlash').width = Width;
	getElementById('CamSpaceFlash').height = Height;

}

function is_ie() 
{ 
	var ua = navigator.userAgent.toLowerCase();
	if ( ua.indexOf( "msie" ) != -1 )
		return true;
	return false;
}

	
function detectCamSpacePresence()
{
  if (!is_ie())
  {
	return (undefined !=  navigator.mimeTypes &&
			navigator.mimeTypes["application/x-camspace-file"] &&
			navigator.mimeTypes["application/x-camspace-file"].enabledPlugin);
			
  }
  else
  {
      return detectActiveXCTL();
  }	  
}
	
function CamSpaceCode(width, height, gameurl, themeurl,prerollurl) 
{ 
	var TableStart = 
			'<table cellpadding="0" cellspacing="0" border="0">\
		<tr valign="top">\
		<td>';

	var TableEnd = 
		'</td>\
		</tr>\
		<tr>\
		<td>\
		</td>\
		</tr>\
		</table>';

var s = '';
	if (is_ie())
	{
s = 		
		'<OBJECT ID="CamSpaceOBJ" CLASSID="CLSID:79DA2FED-7618-4a84-8E79-35FDC3CA61B5" CODEBASE="http://www.samsungmobile.co.il/touch/CamSpaceActiveX.cab#version='+ActiveXVersion+'"\
		 WIDTH="'+width+'" HEIGHT="'+height+'">\
		<PARAM NAME="TempCode" Value="'+TempCode+'">\
		 <PARAM NAME="DispMode" Value="0">\
		 <PARAM NAME="GameURL" Value="'+gameurl+'">\
		 <PARAM NAME="ThemeURL" Value="'+themeurl+'">\
		 <PARAM NAME="PrerollURL" Value="'+prerollurl+'">\
		</OBJECT>';
		}
		else
		{
			if (navigator.appName == "Netscape")
				{
					// detection for Netscape
					if (detectCamSpacePresence())
					{
						s = '<embed \
								id="CamSpaceOBJ"\
								TYPE="application/x-camspace-file"\
								ALIGN="baseline" BORDER="0"\
								PLUGINSPAGE="XPI_Insatll.htm"\
								WIDTH="'+width+'" HEIGHT="'+height+'" \
								ThemeURL="'+themeurl+'"\
								GameURL="'+gameurl+'"\
								PrerollURL="'+prerollurl+'"\
								DispMode="0"\
								TempCode="'+TempCode+'"\
						</embed>';
					}
					else
					{
				
						s = "<div style=\"position:relative;left:3%;background-color: #999;color: inherit;margin-left: 4px;margin-top: 60px;\">\
						     <div style=\"position:relative;top:0px;left:0px;height:200px;width:250x;background-color:#FFFFFF;text-align:center;border-style:outset;border-width:1px;border-color:#808080;padding:5px;\">\
						   <font style=\"border: solid 1x black;height:100%;vertical-align:center;font-size:16px;font-weight:bold\"><br><br>To view this page you have to install the Camspace Firefox plugin\
						   <br><br></font><a style=\"font-size:10pt;font-weight:bold;\"\
						   href=\"http://camdeveloper.com/CamSpaceFFPlugin.xpi\"\
						   iconURL=\"http://www.camspace.com/public/images/Application.png\"\
						   hash=\"sha1:4950c1e57eb16402df745563d846830788b3dc32\"\
						   type= \"application/x-xpinstall\"\
						   onclick=\"return install(event);\">\
								<img style=\"border:none\" src=\"Install_button.png\" />\
						   </a></div></div><br><br><br><br>";
					}
				}
		
		}
		return TableStart+s+TableEnd;
};
	
function CamSpaceFlashCode(flashwidth, flashheight, flashurl, csw, csh, camspaceurl, themeurl) 
{ 
		if (is_ie())
	{
var s = 
		'<table cellpadding="0" cellspacing="0" border="0">\
		<tr valign="top">\
		<td>\
		<embed id="CamSpaceFlash"\
			src="'+flashurl+'"\
			width="'+flashwidth+'"\
			height="'+flashheight+'"\
			allowscriptaccess="always"\
			allowfullscreen="false"\
			flashvars="quality=high"/>\
		</td>\
		<td>\
		<OBJECT ID="CamSpaceOBJ" CLASSID="CLSID:79DA2FED-7618-4a84-8E79-35FDC3CA61B5" CODEBASE="http://www.samsungmobile.co.il/touch/CamSpaceActiveX.cab#version='+ActiveXVersion+'"\
		WIDTH="'+csw+'" HEIGHT="'+csh+'">\
		<PARAM NAME="TempCode" Value="'+TempCode+'">\
		<PARAM NAME="DispMode" Value="0">\
		<PARAM NAME="GameURL" Value="'+camspaceurl+'">\
		<PARAM NAME="ThemeURL" Value="'+themeurl+'">\
		<PARAM NAME="HaveExtComponent" value="1">\
		<PARAM NAME="ExtComponentWidth" value="'+flashwidth+'">\
		<PARAM NAME="ExtComponentHeight" value="'+flashheight+'">\
		</OBJECT>\
		</td>\
		</tr>\
		</table>';
		return s;
		}
				var s = 
				'<table cellpadding="0" cellspacing="0" border="0">\
				<tr valign="top">\
				<td>\
				<object \
                id="CamSpaceOBJ"\
                TYPE="application/x-camspace-file"\
                ALIGN="baseline" BORDER="0"\
				WIDTH="'+csw+'" HEIGHT="'+csh+'" \
				param_ThemeURL="'+themeurl+'"\
				param_GameURL="'+camspaceurl+'"\
				param_DispMode="0"\
				param_TempCode="'+TempCode+'"\
				param_HaveExtComponent" value="1"\
				param_ExtComponentWidth" value="'+flashwidth+'"\
				param_ExtComponentHeight" value="'+flashheight+'"\
        </object>';
		return s;

		
};
