/*
This is the Octoshape Auto-Launcher JavaScript file. Version OCTO-2011004270
*/


var octopv_manualInstallerWin=null;
var octopv_manualInstallerOSX=null;
var octopv_manualInstallerDef=null;


function octopv_ConstructUtil(){
	this.ua = navigator.userAgent.toLowerCase();
	
	this.setTimeoutFunctionObject = new Object();
	this.setTimeoutFunctionObjectCount=0;
	
	
	this.setTimeoutFunction=function(millis, func){
		this.setTimeoutFunctionObjectCount++;
		var name = "name"+this.setTimeoutFunctionObjectCount;
		this.setTimeoutFunctionObject[name] = function(){
			func();
		};
		setTimeout("octoUtil.setTimeoutFunctionObject."+name+"();",millis);
	};
	
	this.getOctoVersion=function(){  
		
		return octopv_version;  
	};

	this.qsmap=null;
	this.getQueryStringValue=function(name,defaultValue){
		if(this.qsmap==null){
			this.qsmap = new Object();
			this.size = 0;
			var qs = window.location.search;
			if(qs.length>1){
				qs = qs.substring(1);
				var arr = qs.split('&');
				var i=0;
				for(;i<arr.length;i++){
					var v = arr[i]; 
					if(v.length>0){
						this.size++;
						if(v.indexOf("=")== -1){
							this.qsmap[v] = "";
						}else{
							var a = v.split('=',2);
							this.qsmap[a[0]] = a[1];
						}
					}
				}
			}
		}
		if(typeof(this.qsmap[name])=='undefined'){
			return defaultValue;
		}else{
			return this.qsmap[name];
		}
	};
	
	this.isQueryStringValue=function(name, value){
		var qsvar = this.getQueryStringValue(name, 'not'+value);
		return (qsvar==value);
	};
	
	this.isOSX=function(){
		return this.ua.indexOf("mac os x") != -1;
	};

	this.isOSX106=function(){
		return this.ua.indexOf("mac os x 10_6") != -1 || this.ua.indexOf("mac os x 10.6") != -1;
	};

	this.isWindows=function(){
		return this.ua.indexOf("windows") != -1;
	};

	this.isSafari=function(){
		return this.ua.indexOf("applewebkit") != -1;
	};

	this.isFirefox=function(){
		return this.ua.indexOf("firefox") != -1;
	};

	this.isFirefox3=function(){
		return this.ua.indexOf("firefox/3") != -1;
	};

	this.isIE=function(){
		return this.ua.indexOf("msie") != -1;
	};

	this.isIE6=function(){
		return this.ua.indexOf("msie 6.0") != -1;
	};

	this.isOpera=function(){
		return this.ua.indexOf("opera") != -1;
	};

	this.isVista=function(){
		return this.ua.indexOf("windows nt 6.0") != -1;
	};

	this.isXP=function(){
		return (this.ua.indexOf("windows nt 5.1") != -1 || this.ua.indexOf("windows nt 5.2") != -1);
	};
	
	
	this.randomString=function(numChars){
		var r = "";
		var nc = numChars;
		while(nc>0){
			var n = nc>10?10:nc;
			var num = Math.pow(36,n);
			r+=(Math.floor(Math.random()*num)).toString(36);
			nc-=n;
		}
		return r;
	};

	
	this.flashOk=function(){
		var flash = navigator.plugins['Shockwave Flash'];
		if(flash){
			var v = parseInt( flash.description.replace( /^[^\d]*/, '' ));
			return v>=9;
		}else if (octoUtil.isIE() && octoUtil.isWindows()){
			try {
				
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				var version = axo.GetVariable("$version");
				
				var str = version.split(" ")[1];  
				var major = str.split(",")[0];    
				return parseFloat(major) >= 9;
			} catch (e) {
				return false;
			}
		}
		return false;
	};
	
	this.getSwfObject=function(swfname){
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[swfname];
		}else{
			return document[swfname];
		}
	};


	this.convertToNumber=function(reply, def){
		var intReply=def;
		if(typeof reply == 'number'){
			intReply=reply;
		}else{
			var parsed=parseInt(reply);
			if(!isNaN(parsed)){
				intReply=parsed;
			}
		}
		return intReply;
	};
	
	this.insertInvisibleIframe=function(source){
		var iframe = document.createElement("iframe");
		iframe.setAttribute("width", 0);
		iframe.setAttribute("height", 0);
		iframe.setAttribute("src", source);
		iframe.style.display = "none";
		document.body.insertBefore(iframe,document.body.firstChild);
	};
	
	this.mime_plugin_is=function(mimeID, pluginName){
		if(navigator && navigator.mimeTypes && navigator.mimeTypes.length){
			var mime =  navigator.mimeTypes[mimeID];
			if(mime){
				var text  = mime.enabledPlugin.name.toLowerCase();
				return (text.indexOf(pluginName.toLowerCase()) >=0);
			}
		}
		return false;
	};
	
	this.has_mime=function(mimeID){
		if(navigator && navigator.mimeTypes && navigator.mimeTypes.length){
			var mime =  navigator.mimeTypes[mimeID];
			if(mime && mime.enabledPlugin){
				return true;
			}
		}
		return false;
	};
	
	this.writeToDiv=function(indiv, html, logTag, create, noStyle){
		try{
			if( typeof(create)=='boolean' &&  create) {
				if(typeof(noStyle)=='boolean' && noStyle){
					octoUtil.createNewDiv2(indiv);
				}else{
					octoUtil.createNewDiv(indiv);
				}
			}
		 	var div = null;
		 	if(indiv!=null){
		 		div = document.getElementById(indiv);
		 		if(div==null){
		 			octolog.info("div "+indiv+" does not exist.",logTag);
		 			return false;
		 		}
		 	}
		 	if(indiv==null){
		 		document.write(html);
		 	}else{
		 		div.innerHTML=html;
		 	}
		 	octolog.info("inserted HTML into div "+indiv,logTag);
		 	return true;
		}catch(ex){ 
			octolog.warning('JavaScript error for div '+indiv+': '+ex.message,logTag);
			return false;
		}
	};

		
	this.createNewDiv2=function(idName){
		var elem = document.getElementById(idName);
		if(elem==null){
			var oDiv = document.createElement("div");
			oDiv.id=idName;
			document.body.insertBefore(oDiv,document.body.firstChild);
			return true;
		}else{
			return false;
		}
	};

	this.createNewDiv=function(idName){
		try{
			var elem = document.getElementById(idName);
			if(elem==null){
				var oDiv = document.createElement("div");
				oDiv.id=idName;
				oDiv.style.height = "0px"; 
				oDiv.style.width = "1px"; 
				document.body.insertBefore(oDiv,document.body.firstChild);
				return true;
			}else{
				return false;
			}
		}catch(ex){ 
			octolog.warning('JavaScript error: '+ex.message,'createNewDiv');
			return false;
		}
	};
	
	
	
	this.writeInNewDiv=function(html, logTag,width, height){
		try{
			var oDiv = document.createElement("div");
			var id = octopv_getJsUniqueId();
			oDiv.id=id;
			if(octoUtil.isFirefox() || octoUtil.isSafari()){
				oDiv.style.height = "0px"; 
			}
			if((typeof(width)=='number') && (typeof(height)=='number') && width>=0 && height>=0){
				oDiv.style.height = height+"px"; 
				oDiv.style.width = width+"px"; 
			}
			document.body.insertBefore(oDiv,document.body.firstChild);
			return octoUtil.writeToDiv(id, html,logTag);
		}catch(ex){
			return false;
		}
	};
	
	this.getFirstOfType=function(type){
		var i=1;
		for(;i<arguments.length;i++){
			if(typeof(arguments[i])==type){
				return arguments[i];
			}
		}
		return null;
	};

	
}
var octoUtil = new octopv_ConstructUtil();



function octopv_ConstructConfig(){
	
	this.ID_FLASH_BP="fbp";
	this.ID_BROWSER_PLUGIN="bp";
	this.ID_JSHTTP="jshttp";
	this.ID_LAUNCH_APPLET="applaunch";
	this.ID_TEST_APPLET="apptest";
	this.ID_FLASH_EULA="feula";
	this.ID_PRELOAD_APPLET="appload";
	this.ID_INSTALL_APPLET="appinstall";
	this.ID_CAB_INTALL="cabinstall";
	this.ID_SIGNED_APPLET="signedapplet";
	this.ID_LOGGING="jslog";
	this.ID_STAT="stat";
	this._logTag="octoConfig";
	
	this._disables=new Object();
	this._paths=new Object();
	this._codePaths=new Object();
	 
	this.basePath='';  	 
	 
	this.variant=null;		 
	this.usingEulaInPlayer=false;	 
	this.appletDisplayName=null; 
	this.showEulaOnManualInstall=false;
	this.eulaKeepAliveInterim=5000;
	this.statDelayed=false; 
	
	
	this.setBasePath=function(path){
		if( path=='' || path.charAt(path.length-1)=='/'){
			this.basePath=path;
		}else{
			this.basePath=path+'/';
		}
	};
	
	this.setFile=function(item, file, platform1){
		var platform = octoUtil.getFirstOfType('string',platform1,'');
		if(platform.indexOf('win')!=-1){
			this._paths[item+'_win']=file;
		}else if(platform.indexOf('osx')!=-1){
			this._paths[item+'_mac']=file;
		}else{
			this._paths[item]=file;
		}
	};

	this.setCode=function(item, code, platform1){
		var platform = octoUtil.getFirstOfType('string',platform1,'');
		if(platform.indexOf('win')!=-1){
			this._codePaths[item+'_win']=code;
		}else if(platform.indexOf('osx')!=-1){
			this._codePaths[item+'_mac']=code;
		}else{
			this._codePaths[item]=code;
		}
	};

	this.getCodePath=function(item){
		var code = null;
		if(octoUtil.isOSX()){
			code = this._codePaths[item+'_mac'];
		}else if(octoUtil.isWindows()){
			code = this._codePaths[item+'_win'];
		}
		if(typeof(code)=='undefined' || code==null){
			code = this._codePaths[item];
		}
		if(typeof(code)=='undefined'){
			return null;
		}
		return code;
	}

	this.getPath=function(item){
		if(this.hasDisabled(item)) return null;
		var file = null;
		if(octoUtil.isOSX()){
			file = this._paths[item+'_mac'];
		}else if(octoUtil.isWindows()){
			file = this._paths[item+'_win'];
		}
		if(typeof(file)=='undefined' || file==null){
			file = this._paths[item];
		}
		if(typeof(file)=='undefined'){
			return null;
		}
		return this.basePath+octopv_folder+'/'+file;
	};
	
	 
	this.disable=function(item){
		this._disables[item] = true;
	};
	
	
	this.disableApplets=function(){
		this.disable(this.INSTALL_APPLET);
		this.disable(this.LAUNCH_APPLET);
		this.disable(this.PRELOAD_APPLET);
		this.disable(this.TEST_APPLET);
	};
	
	this.hasDisabled=function(item){
		return (typeof(this._disables[item])=='boolean') && this._disables[item];
	};
	
	
	this.loopDisables=function(callbackFunction){
		for (var e in this._disables){ 
			callbackFunction(e+"",this._disables[e]);
		}
	};
	
}
var octoConfig=new octopv_ConstructConfig();




function octopv_ConstructErrorCodes(){
	this.CODE_USER_DECLINED = 			1;
	this.CODE_USER_SHOULD_REFRESH = 	2;
	this.CODE_USER_SHOULD_REINSTALL = 	3;
	this.CODE_USER_SHOULD_INSTALL = 	4;
	this.CODE_USER_SHOULD_LAUNCH = 		5;
	this.CODE_UNKNOWN_STATUS = 			6;
	this.CODE_ERROR = 					9;
	
	this.FLASH_EULA_REJECT = 		1100;
	this.INSTALL_APPLET_EULA_REJECT=1101;	

	this.LAUNCH_APPLET_SECURITY=	1110;
	this.INSTALL_APPLET_SECURITY= 	1111;

	this.LAUNCH_APPLET_AFTER_INSTALL=1200;
	this.BP_AFTER_INSTALL=			1201;
	
	
	this.NO_BROWSER_PLUGIN=			1490;
	this.LAUNCH_APPLET_NO_PLUGIN=	1491;
	this.PLUGIN_ANSWER_BP_NOT_FOUND=1492;
	
	this.FLASH_BP_NOT_LAUNCHED=     1500;	
	this.CAB_AFTER_INSTALL=			1501;
	this.BROWSER_PLUGIN_NO_METHOD=	1502;
	
	this.LAUNCH_APPLET_TIMEOUT=		1600;	
	this.PRELOAD_APPLET_TIMEOUT=	1601;	
	this.JS_ABORTED=				1602;
	this.JSHTTP_CONNECT=			1603;
	this.JSHTTP_CONNECT_TIMEOUT=	1604;
	this.JSHTTP_CONNECT_EX=			1605;
	this.JSHTTP_NOT_XML=			1606;
	this.JSHTTP_XML=				1607;
	this.JSHTTP_TIMEOUT=			1608;
	this.FLASH_BP_TIMEOUT=			1609;
	this.FLASH_BP_UNKNOWN=			1610;
	this.FLASH_BP_NO_CALLBACK=		1611;
	this.BP_ONLY_ON_WIN_AND_MAC=	1612;
	this.TEST_APPLET_ERROR=			1613;
	
	this.LAUNCH_APPLET_NOT_ON_MAC=	1620;
	this.LAUNCH_APPLET_NO_COOKIE=	1621;
	this.FLASH_BP_NO_OR_OLD_FLASH= 	1622;
	this.JSHTTP_IMPOSSIBLE= 		1623;
	this.TEST_APPLET_NOT_ON_THIS_OS=1624;
	this.JAVA_NOT_ENABLED=			1625;
	this.CAB_ONLY_ON_WIN_IE=		1626;
	this.CAB_NOT_ON_VISTA=			1627;
	this.INSTALL_APPLET_OLD_MAC=	1628;
	this.INSTALL_APPLET_VISTA_OLD_JAVA=1629;
	this.LAUNCH_APPLET_REPLY=		1630;
	this.LAUNCH_APPLET_WRITE=		1631;
	this.INSTALL_APPLET_JS=			1632;
	this.INSTALL_APPLET_NO_FILE= 	1633;		
	this.INSTALL_APPLET_EXECUTION= 	1634;
	this.INSTALL_APPLET_UNKNOWN= 	1635;
	this.CAB_READY_STATE=			1636; 
	this.PROTOCAL_LAUNCH_AFTER=		1637; 
	this.PROTOCAL_LAUNCH_ERROR=		1638; 
	this.LAUNCH_APPLET_JAVASCRIPT=	1639;
	this.LAUNCH_APPLET_DISABLED=	1640;
	this.APPLETS_DISABLED=			1641;
	this.CAB_DISABLED=				1642;
	this.BP_DISABLED=				1643;
	this.BP_NOT_IN_OPERA=			1644;
	this.FLASH_BP_DISABLED=			1645;
	this.FLASH_BP_DIV_ERROR=		1646;
	
	this.JS=						1900;
	this.JSHTTP_UNKNOWN=			1901;
	this.LAUNCH_APPLET_UNKNOWN = 	1902;
	this.LAUNCH_APPLET_NOT_READY=	1903;
	this.PRELOAD_APPLET_INSERT=		1905;
	this.WRAP_ERROR=				1906;

	this.PRELOAD_APPLET_OK=			1910;	
	this.FLASH_EULA_ACCEPT= 		1911;	
	this.INSTALL_APPLET_OK= 		1912;	
	this.TEST_APPLET_OK=			1913;	
	this.FLASH_EULA_NO_FLASH = 		1914;
	this.FLASH_EULA_DISABLED = 		1915;
	this.FLASH_EULA_DIV_ERROR = 	1916;
	this.FLASH_EULA_INTERNAL_START_CALL= 1917;
	this.FLASH_EULA_INTERNAL_LOAD= 	  1918;
	this.FLASH_EULA_INTERNAL_IO_LOAD= 1919;
	
	this.FLASH_EULA_RETURN_REJECTED= 1920; 
	this.FLASH_EULA_RETURN_GENERIC_ERR= 1921;
	this.FLASH_EULA_RETURN_WRITE_FAILED= 1922;
	
	this.FLASH_EULA_INTERNAL_JS_ERROR= 1930;
	this.PATH_NOT_SET= 1931;
	this.LAUNCH_UNKNOWN = 1932;
	
	  
	this.STAGE_RUNNING =					1990;
	this.STAGE_NOT_WRITTEN_TO_PAGE = 		1992;
	this.STAGE_WAITING_FOR_INIT_CALL= 		1993;
	this.STAGE_WAITING_FOR_FINISH_CALL = 	1994;
	this.STAGE_NOT_SET= 					1999;	

	this.isStage=function(err){
		return (1990 <= err && err <= 1999);
	};

	this.getCode=function(err){
		if(err==0) return 0;
		if(err>=1700) return this.CODE_ERROR;
		if(err>=1600) return this.CODE_UNKNOWN_STATUS;
		if(err>=1500) return this.CODE_USER_SHOULD_LAUNCH;
		if(err>=1400) return this.CODE_USER_SHOULD_INSTALL;
		if(err>=1300) return this.CODE_USER_SHOULD_REINSTALL;
		if(err>=1200) return this.CODE_USER_SHOULD_REFRESH;
		if(err>=1100) return this.CODE_USER_DECLINED;
		return this.CODE_ERROR;
	};
	
	
	this.isLessOrEqual=function(err1,err2){
		var e1 = Math.abs(err1)-(Math.abs(err1)%100);
		var e2 = Math.abs(err2)-(Math.abs(err2)%100);
		return (e1<=e2);
	};
	
	this.print=function(err){
		var f = "";
		var e = " ("+err+")";
		switch(err){
		case 0: 							return "Success";
		case this.JS:						return "JavaScript error"+e;
		case this.JS_ABORTED:				return "JavaScript Aborted"+e;
		case this.WRAP_ERROR:				return "Plugin launch attempt wrap init"+e;
		case this.JSHTTP_CONNECT: return "JavaScript-HTTP error on connect (Plugin not running)"+e;
		case this.JSHTTP_CONNECT_TIMEOUT: 	return "JavaScript-HTTP connect time-out reached"+e;
		case this.JSHTTP_CONNECT_EX:		return "JavaScript-HTTP exception while connecting"+e;
		case this.JSHTTP_NOT_XML: 	return "JavaScript-HTTP plugin did not reply with xml doc"+e;
		case this.JSHTTP_XML: return "JavaScript-HTTP plugin replied with incorrect base node tag"+e;
		case this.JSHTTP_TIMEOUT: 			return "JavaScript-HTTP master time-out reached"+e;
		case this.JSHTTP_UNKNOWN: 			return "JavaScript-HTTP unknown error"+e;
		case this.JSHTTP_IMPOSSIBLE:		return "JavaScript-HTTP can not be used"+e;
		case this.FLASH_EULA_NO_FLASH:		return "Flash Eula impossible since we have no flash"+e;
		case this.FLASH_EULA_DISABLED:		return "Flash Eula is disabled"+e;
		case this.FLASH_EULA_DIV_ERROR:		return "Flash Eula could not make div"+e;
		case this.TEST_APPLET_ERROR:		return "Test applet error"+e;
		case this.FLASH_BP_NO_OR_OLD_FLASH:	return "Flash-bp impos. since no or old flash"+e;
		case this.FLASH_BP_DISABLED:		return "Flash-bp is disabled"+e;
		case this.FLASH_BP_DIV_ERROR:		return "Flash-bp div insert error"+e;
		case this.FLASH_BP_TIMEOUT:			return "Flash-bp time-out reached"+e;
		case this.FLASH_BP_NOT_LAUNCHED:return "Flash-bp could not reach plug-in, but it is installed"+e;
		case this.FLASH_BP_UNKNOWN:			return "Flash-bp could not reach plug-in"+e;
		case this.FLASH_BP_NO_CALLBACK:		return "Flash-bp had no callback function"+e;		
		case this.BP_ONLY_ON_WIN_AND_MAC:	return "Browser plugin only on win and mac"+e;
		case this.BP_DISABLED:				return "Browser plugin is disabled"+e;
		case this.BP_NOT_IN_OPERA:			return "Browser plugin can not be used in Opera"+e;
		case this.INSTALL_APPLET_OLD_MAC:	return "No applet install since to old mac os"+e;
		case this.INSTALL_APPLET_VISTA_OLD_JAVA:return "No applet install since Vista + old java"+e;
		case this.PRELOAD_APPLET_INSERT:return "Preload applet could not be inserted to the page"+e;
		case this.TEST_APPLET_NOT_ON_THIS_OS:return "Test applet could not be used on this os"+e;
		case this.APPLETS_DISABLED:			return "All applets are disabled"+e;
		case this.PRELOAD_APPLET_TIMEOUT:	return "Preload applet timeout"+e;
		case this.PRELOAD_APPLET_OK:		return "Preload applet success"+e;
		case this.TEST_APPLET_OK:			return "Test applet success"+e;
		case this.FLASH_EULA_ACCEPT:		return "Flash EULA accepted"+e;
		case this.LAUNCH_APPLET_TIMEOUT: 	return "Launch applet timeout reached"+e;
		case this.LAUNCH_APPLET_REPLY: 		return "Launch applet reply error"+e;
		case this.LAUNCH_APPLET_SECURITY:	return "Launch applet not trusted by user"+e;
		case this.LAUNCH_APPLET_WRITE: 		return "Launch applet disk write error"+e;
		case this.LAUNCH_APPLET_NOT_ON_MAC:	return "Launch applet does not exist on mac"+e;
		case this.LAUNCH_APPLET_DISABLED:	return "Launch applet is disabled"+e;
		case this.LAUNCH_APPLET_NO_COOKIE:	return "Launch applet had no cookie"+e;
		case this.LAUNCH_APPLET_NOT_READY:	return "Launch applet is not ready"+e;
		case this.LAUNCH_APPLET_UNKNOWN: 	return "Launch applet unknown error"+e;
		case this.LAUNCH_APPLET_JAVASCRIPT:	return "Launch applet javascript error"+e;
		case this.NO_BROWSER_PLUGIN:		return "Could not find browser plug-in"+e;
		case this.BROWSER_PLUGIN_NO_METHOD:return "Browser plugin is missing a method definition"+e;
		case this.LAUNCH_APPLET_NO_PLUGIN:	return "Launch applet did not find plugin"+e;
		case this.PLUGIN_ANSWER_BP_NOT_FOUND:return "Browser plugin could not find octo-plugin"+e;
		case this.JAVA_NOT_ENABLED:			return "Java disabled in browser"+e;
		case this.LAUNCH_APPLET_AFTER_INSTALL:return "Launch applet did not work after applet install"+e;
		case this.BP_AFTER_INSTALL:	return "Browser plugin did not work after applet install"+e;
		case this.CAB_ONLY_ON_WIN_IE:		return "Cab install can only be done on win+ie"+e;
		case this.CAB_DISABLED:				return "Cab install has been disabled"+e;
		case this.CAB_NOT_ON_VISTA:			return "Cab install can not be done on Vista"+e;
		case this.CAB_AFTER_INSTALL:		return "Cab has run"+e;
		case this.CAB_READY_STATE:			return "Cab ready state not defined"+e;
		case this.PROTOCAL_LAUNCH_AFTER:	return "Protocol launch has run"+e; 
		case this.PROTOCAL_LAUNCH_ERROR:	return "Protocol launch error"+e; 
		case this.FLASH_EULA_REJECT:		return "Flash EULA rejected"+e;
		case this.INSTALL_APPLET_JS:		return "Install applet JavaScript error"+e;
		case this.INSTALL_APPLET_UNKNOWN:	return "Install applet unknown error"+e;
		case this.INSTALL_APPLET_EXECUTION:	return "Install applet execution error"+e;
		case this.INSTALL_APPLET_NO_FILE:	return "Install applet no file error"+e;
		case this.INSTALL_APPLET_SECURITY:	return "Install applet not trusted by user"+e;
		case this.INSTALL_APPLET_EULA_REJECT:return "Install applet EULA rejected"+e;
		case this.STAGE_NOT_SET:					return "JS value is not set."+e;
		
		case this.FLASH_EULA_INTERNAL_JS_ERROR: return "JS-Exeption when calling asosa to show internal eula"+e;
		case this.FLASH_EULA_INTERNAL_LOAD:return "Error when asosa showed internal eula"+e;
		case this.FLASH_EULA_INTERNAL_IO_LOAD:return "IOError when asosa showed internal eula"+e;
		case this.FLASH_EULA_INTERNAL_START_CALL:return "Error when asosa called start on internal eula"+e;
		
		case this.FLASH_EULA_RETURN_REJECTED:return "Flash EULA returned rejected"+e;
		case this.FLASH_EULA_RETURN_GENERIC_ERR:return "Flash EULA generic internal error"+e;
		case this.FLASH_EULA_RETURN_WRITE_FAILED:return "Flash EULA internal error: write failed"+e;
		
		case 1321: f="Applet-"; 
		case 1301: return f+"BP could not find octoshape folder in reg-db"+e;
		case 1322: f="Applet-";
		case 1302: return f+"BP could not find keys in octoshape folder in reg-db"+e;
		case 1323: f="Applet-";
		case 1303: return f+"BP octoshape program is placed on a too long path name"+e;
		case 1324: f="Applet-";
		case 1304: return f+"BP could not launch octoshape program"+e;
		case 1325: f="Applet-";
		case 1305: return f+"BP could not find octoshape program on disk"+e;
		case 1311: 	return "Mac-BP. Launch services could not find octoshape app"+e;
		case 1312: 	return "Mac-BP. Launch services could not open the octoshape app"+e; 
		case 1313:	return "Mac-BP. Error sending apple event to octoshape app"+e; 
		case 1314: 	return "Mac-BP. Error in apple event reply from octoshape app"+e;
		}
		
		return "unknown"+e;
	};


	
	this.isBrowserPluginError = function(err){
		var e = Math.abs(err);
		return (1300 <= e && e < 1330);
	};
	
	this.convertBpError=function(err, isFromWinApplet){
		var e = Math.abs(err);
		if(isFromWinApplet){
			e += 20;
		}
		return 1300+e;
	};
	
	this.isLaunchStopError=function(err){
		return (err==0)||(Math.abs(err)<400);
	};
}
var octoErrors = new octopv_ConstructErrorCodes();



function octopv_ConstructLaunchKinds(){
	this.START_UP=			1;
	this.GET_CONNECT_URL=	2;
	this.CONVERT_LINK=		3;
	this.GET_STRING=		4;
	this.GET_SUA_VERSION=	5;
	
	this.toString=function(kind){
		switch(kind){
		case this.START_UP:			return "Start up";
		case this.GET_CONNECT_URL:	return "Connect url";
		case this.CONVERT_LINK:		return "Convert link";
		case this.GET_STRING:		return "Get option";
		case this.GET_SUA_VERSION:	return "Get sua version";
		default: return "unknown";
		}
	};
}
var octoLaunchKinds = new octopv_ConstructLaunchKinds();




var octopv_abortAutoLaunch=false;

function octoGetManualInstallLink(){
	if(octoUtil.isOSX()&& octopv_manualInstallerOSX!=null){
		return octoConfig.basePath+octopv_folder+'/'+octopv_manualInstallerOSX;
	}else if(octoUtil.isWindows()&& octopv_manualInstallerWin!=null){
		return octoConfig.basePath+octopv_folder+'/'+octopv_manualInstallerWin;
	}else{
		return octopv_manualInstallerDef;
	}
}



function octoAbortAutoLaunch(){
	octolog.info('Aborting auto-launch');
	octopv_abortAutoLaunch=true;
	
	octopv_pluginLauncherApplet.resetAll(); 
};


function octoManualLaunch(){
	octolog.info('Doing protocol launch');
	octopv_launchByProtocol();
};


function octoGetPluginStatus(functionInt, tryAutoInstall, messageFunction){
	var obj = new octopv_ConstructPluginLaunch(octoLaunchKinds.START_UP, 
			functionInt,null,messageFunction);
	obj.setDoAutoInstall(tryAutoInstall);
	obj.start();
};


function octoGetConnectUrl(functionIntString, tryAutoInstall, messageFunction){
	var obj = new octopv_ConstructPluginLaunch(octoLaunchKinds.GET_CONNECT_URL, 
			functionIntString,null,messageFunction);
	obj.setDoAutoInstall(tryAutoInstall);
	obj.start();
};


function octoGetPlayLink(octolink, functionIntString, tryAutoInstall, messageFunction){
	var obj = new octopv_ConstructPluginLaunch(octoLaunchKinds.CONVERT_LINK, 
			functionIntString, octolink,messageFunction);
	obj.setDoAutoInstall(tryAutoInstall);
	obj.start();
};


function octoGetStringOption(option,functionIntString, tryAutoInstall, messageFunction){
	var obj = new octopv_ConstructPluginLaunch(octoLaunchKinds.GET_STRING, 
			functionIntString, option, messageFunction);
	obj.setDoAutoInstall(tryAutoInstall);
	obj.start();
};


function octoGetSuaVersion(functionIntString, tryAutoInstall, messageFunction){
	var obj = new octopv_ConstructPluginLaunch(octoLaunchKinds.GET_SUA_VERSION, 
			functionIntString,null,messageFunction);
	obj.setDoAutoInstall(tryAutoInstall);
	obj.start();
};



function octopv_ConstructPluginLaunch(replyKind, replyFunction1, arg, messageFunction){
	this.doAutoInstall = false;

	this._replyFunctionParameterNum = replyKind==octoLaunchKinds.START_UP?1:2;
	this._kind = replyKind;
	this._arg = arg;
	this._stat=null;
	this._flashEula=null;
	this._installStarted=false;
	this._isFinished=false;
	this._repliedState=octoErrors.STAGE_NOT_SET;
	this._repliedString="";
	this._leastError=octoErrors.STAGE_NOT_SET;
	var top=this;
	 
	this.setDoAutoInstall=function(useIt){
		this.doAutoInstall = (typeof(useIt)=='boolean' && useIt);
	};

	this.setUseLaunchStat=function(playerId, instanceId, statTimeout){
		this._stat = new octopv_ConstructLaunchStatistics(playerId, instanceId, this._kind+"", 
				this.doAutoInstall, statTimeout); 
	};
	
	this.setUseExternalEula=function(eulaObject){
		this._flashEula = new ConstructWrap(eulaObject);
	};
	
	
	
	
	function messageBack(id,proceeding){
		if(typeof(messageFunction)=='function'){
			messageFunction(id,proceeding);
		}
	}
	
	
	function logApart(str, tag){
		if(str == null){
			if(octolog.shouldDoInfo){
				var str2="";
				var i = 10;
				for(;i>0;i--){ str2+="**********"; }
				octolog.event(' '+str2+' ',tag);
			}
		}else{
			if(octolog.shouldDoInfo){
				var s = '';
				var len = ((90-str.length)-1)/2;
				while(len>0){
					s += '.';
					len--;
				}
				octolog.event(' *****'+s+str+s+(str.length%2==0?'':'.')+'***** ',tag);
			}else{
				octolog.event(str,tag);
			}
		}
	}

	
	function replyFunction(theIntState1, theStringReply){
		if(octopv_abortAutoLaunch) return;
		if(top._flashEula!=null){
			if(octoConfig.showEulaOnManualInstall && theIntState1!=0 && !top._flashEula.isClosed()){
				
				octolog.info('We show the eula before returning on maunal install');
				top._flashEula.start(function(eulaReply){
					
					octolog.info('The eula was run before manual install.');
					replyFunction();
				});
				return;
			}
			if(top._flashEula.isClosed() && theIntState1==0){
				 
				octolog.info('Cleaning up after flash eula'); 
				top._flashEula.content.cleanup();
			}
		}
		
		var theIntState = octoUtil.getFirstOfType('number',theIntState1,top._leastError);
		if(top._installStarted && theIntState==0){
			octopv_settings.updateCounter('installdone');
		}
		if(top._stat!=null){
			octolog.info('calling close on this._stat ... ');
			top._stat.close(theIntState);
		}else{
			octolog.info('Stat was null.');
		}
		top._repliedState=theIntState;
		top._repliedString=theStringReply;
		messageBack("",true);
		octolog.info('String reply: '+theStringReply);
		var str = 'Final status: '+octoErrors.print(theIntState);
		logApart(str,'replyFunction');
		logApart(null,'replyFunction');
		
		if(this._replyFunctionParameterNum==1){
			replyFunction1(theIntState);	
		}else{
			replyFunction1(theIntState, theStringReply);	
		}
		this._isFinished=true;
	}
	
	
	function ConstructWrap(parent){
		this.content=parent;
		this.running=false;
		this.exitState=octoErrors.WRAP_ERROR; 
		this._hasRun=false;
		this._statAttId="";
		this._runId=octoUtil.getFirstOfType('string',this.content.attemptId,'wrap');
		this._logTag = octoUtil.getFirstOfType('string',this.content._logTag,'wrap-'+this._runId);
		
		this.isClosed=function(){
			var isRunOnce = typeof(this.content.runonce)=='boolean' && this.content.runonce;
			var hasExit = this.exitState!=octoErrors.WRAP_ERROR;
			return (isRunOnce && this._hasRun && hasExit);
		};
		
		this.start=function(onError){
			if(this.running){
				octolog.info('ERROR?: calling start on running run-obj',this._logTag);
				return;	
			}
			this._globalHold = this._runId+octopv_getJsUniqueId();
			top[this._globalHold]=function(err){
				if(octoErrors.isLaunchStopError(err)){
					octolog.info('Not calling next procedure since we have stop error','next');
					replyFunction(err);
				}else{
					octolog.info('Calling next procedure after timeout','next');
					onError(err);
				}
			};
			if(this.isClosed()){
				octolog.info('calling start on closed run-obj',this._logTag);
				setTimeout('window.'+top.myGlobalName+'.'+this._globalHold+'('+this.exitState+');',100);
				return;	
			}
			this.running=true;
			logApart('OPENING '+this._runId,this._logTag);
			if(top._stat!=null){
				this._statAttId=top._stat.beginAttempt(this._runId);
			}
			messageBack(this._runId,true);
			var me = this;
			this.content.start(function(err){
				if(me._close(err,onError)){
					setTimeout('window.'+top.myGlobalName+'.'+me._globalHold+'('+err+');',100);
				}
			}, function(str){
				if(me._close(0,replyFunction)){
					replyFunction(0,str);
				}
			},function(proceeding){
				if(top._stat!=null){
					top._stat.updateAttempt(me._statAttId);
				}
				messageBack(me._runId,proceeding);
			});
		};
		
		this._close=function(state, func){
			if(!this.running){
				octolog.info('ERROR?: calling close on not running run-obj',this._logTag);
				return false;
			}
			if(typeof(func)!='function'){
				octolog.info('ERROR: reply function('+state+') is '+typeof(func),this._logTag);
				return false;
			}
			var str='CLOSING '+this._runId+': '+octoErrors.print(state);
			if(octoErrors.isLessOrEqual(state, top._leastError)){
				
				octolog.info('Setting least error to '+octoErrors.print(state),this._logTag);
				top._leastError=state;
			}
			
			logApart(str,this._logTag);
			this._hasRun=true;
			this.exitState=state;
			this.running=false;
			if(top._stat!=null){
				top._stat.endAttempt(state,this._statAttId);
			}
			return true;
		};
	}
	
	
	function runInstallByApplet(eula, tApp, pApp, iApp, lApp){
		var logTag='super-app-install';
		
		function proceed(err){
			octolog.info('Proceed after eula or test/preload called ... ',logTag);
			if(eula.isClosed() && tApp.isClosed() && !pApp.running){
				if(eula.exitState == octoErrors.FLASH_EULA_REJECT){
					
					octolog.info('Not proceeding since eula was rejected',logTag);
				}else if(tApp.exitState != octoErrors.TEST_APPLET_OK){
					
					replyFunction();
				}else if(!pApp.isClosed()){
					
					pApp.start(function(errLoad){
						octolog.info('Preload ok?: '+octoErrors.print(errLoad),logTag);
						proceed(errLoad);
					});
				}else if(pApp.isClosed() && pApp.exitState == octoErrors.PRELOAD_APPLET_OK){
					
					iApp.start(function(errApp){
						
						if(errApp==octoErrors.INSTALL_APPLET_OK){
							if(lApp.content.canAnswer()==0){
								
								lApp.start(function(errLApp){ 
									
									
									replyFunction(octoErrors.LAUNCH_APPLET_AFTER_INSTALL);
								});
							}else{ 
								var bp = new ConstructWrap(new octopv_ConstructBP(top._kind,top._arg));
								bp.start(function(errBp){ 
									
									replyFunction(octoErrors.BP_AFTER_INSTALL);
								});
							}
						}else{ 
							
							replyFunction(errApp); 
						}
					}); 
				}else if(pApp.isClosed()){
					
					replyFunction();
				}
			}
		}
		
		tApp.start(function(errTest){
			octolog.info('Test app ok?: '+octoErrors.print(errTest),logTag);
			proceed(errTest);
		});
		
		eula.start(function(err1){
			octolog.info('Eula answer ok?: '+octoErrors.print(err1),logTag);
			if(err1==octoErrors.FLASH_EULA_REJECT){
				replyFunction(err1);
			}else{
				proceed(err1);
			}
		});
	}

	
	
	this.start=function(){
		var str = 'Auto-Launch ('+octoLaunchKinds.toString(this._kind)+') called. '+
			'Auto-install: '+this.doAutoInstall;
		logApart(null,'start');
		logApart(str,'start');
		octolog.info('Eula on maunal install: '+octoConfig.showEulaOnManualInstall,'start');
		window.octopv_abortAutoLaunch=false;
		if(this._stat!=null) this._stat.open();
		
		
		var appletTest = new ConstructWrap(new octopv_ConstructAppletTest(8000));
		var jshttp=new ConstructWrap(new octopv_ConstructJsHttp(6498,8247,2000,this._kind));
		var fbp=new ConstructWrap(new octopv_ConstructPortFlash(6498, 8247,this._kind)); 
		var bp=new ConstructWrap(new octopv_ConstructBP(this._kind,this._arg));
		var lApp = new ConstructWrap(new octopv_ConstructAppletLaunch(top._kind,top._arg));

		if(this._flashEula==null){
			this._flashEula = new ConstructWrap(new octopv_ConstructShowEula());
		}
		
		var runAll;
		if(jshttp.content.canAnswer()==0){	
			
			runAll=new octopv_ContructRunAll(jshttp,bp);
		}else{	
			
			runAll=new octopv_ContructRunAll(bp,fbp);
		}
		runAll.start(function(firstErr){
			appletTest.start(function(errTapp){
				
				if(errTapp==octoErrors.TEST_APPLET_OK){
					
					octolog.debug("calling start on lApp");
					lApp.start(function(errLapp){ 
						octolog.debug("After run lApp: "+errLapp);
						if(!top.doAutoInstall){ 
							if(lApp.content.canAnswer()==0){ 
								replyFunction(errLapp);	
							}else{ 
								replyFunction(); 
							}
						}else{	
							
							var preload = new octopv_ConstructPreloadInstallApplet(appletTest.content, 20000);
							var install = new octopv_ConstructInstallApplet(top._kind);
							runInstallByApplet(top._flashEula, appletTest, new ConstructWrap(preload),
									new ConstructWrap(install),lApp);
						}
					});
				}else{ 
					if(!top.doAutoInstall){ 
						replyFunction(); 
					}else{ 
						
						var cab = new ConstructWrap(new octopv_ConstructCabInstall(3000,top._flashEula));
						cab.start(function(errCab){
							if(errCab==octoErrors.CAB_AFTER_INSTALL){
								
								var toRun;
								if(jshttp.content.canAnswer()==0){  
									toRun = new octopv_ContructRunAll(jshttp,bp);
								}else{ 
									toRun = new octopv_ContructRunAll(bp,fbp);
								}
								toRun.start(replyFunction);
							}else{ 
								replyFunction(); 
							}
						});
					}
				}
			});
		});
	}
	this.myGlobalName = "octopv_launch"+octopv_getJsUniqueId(); 
	window[this.myGlobalName] = this;
}

function octopv_ContructRunAll(){
	this.arr=new Array(arguments.length);
	for(var i=0;i<this.arr.length;i++){
		this.arr[i] = arguments[i];
	}
	this.start=function(endFunction){
		this._run(0,endFunction);
	};
	var me=this;
	this._run=function(i,endFunction){
		var toRun = this.arr[i];
		toRun.start(function(err){
			var i2=i+1;
			if(i2<me.arr.length){
				me._run(i+1,endFunction);
			}else{
				endFunction(err);
			}
		});
	};
};



function octoAsOsaCreateLaunch(swfname, replyName, messageName){
	var asosa=octoUtil.getSwfObject(swfname);
   	if(typeof(asosa)=='undefined'){
		octolog.error('ERROR!: could not get a hold of asosa swf: '+swfname);
		return "";
   	}
	
	var obj = new octopv_ConstructPluginLaunch(2, function(intStatus, stringReply){
		var funcName = replyName+obj.myGlobalName;
		asosa[funcName](intStatus,stringReply);
	},null,
	function(message,progressed){
		if(typeof(message)=="string"){
			try{
				var funcName = messageName+obj.myGlobalName;
				asosa[funcName](message,progressed);
			}catch(ex){
				octolog.warning('Could not call message function on asosa: '+ex);
			}
		}
	});
	obj.asosa=asosa;
	return obj.myGlobalName;
}

function octopv_getLaunchObject(id){
	if(typeof(window[id])=='object'){
		return window[id];
	}else{
		octolog.warning('Could not get handle on asosa object: '+id);
		return null;
	}
}


function octoOsaSetInstall(id,doInstall){
	var launch = octopv_getLaunchObject(id);
	if(launch!=null){
		launch.setDoAutoInstall(doInstall);
	}
}

function octoOsaSetStat(id,statTimeout,playerId,instanceId){
	var launch = octopv_getLaunchObject(id);
	if(launch!=null){
		octolog.info('Using launch stat ('+playerId+') since it was set from osa.');
		launch.setUseLaunchStat(playerId, instanceId, statTimeout); 
	}
}


function octoOsaSetEula(id){
	if(octoConfig.usingEulaInPlayer){
		var launch = octopv_getLaunchObject(id);
		if(launch!=null){
			var eulaStartName = "octopv_eulaStart"+id;
			var obj = new octopv_ConstructShowEula(function(){
				try{
					var launch1 = octopv_getLaunchObject(id);
					if(octoConfig.hasDisabled(octoConfig.ID_FLASH_EULA)){
						return octoErrors.FLASH_EULA_DISABLED;
					}
					var path = octoConfig.getPath(octoConfig.ID_FLASH_EULA);
					if(path==null){
						return octoErrors.PATH_NOT_SET;
					}
					launch1.asosa[eulaStartName](path, obj.callbackFuncName,
							obj.keepAliveFuncName,obj.keepAliveInterim,obj.clickToTextFuncName);
				}catch(ex){
					octolog.warning('Could not call eula start '+eulaStartName+' function on asosa: '+ex);
					return octoErrors.FLASH_EULA_INTERNAL_JS_ERROR;
				}
				return 0;
			});
			launch.setUseExternalEula(obj);
			return eulaStartName;
		}
	}
	return "";
}

function octoOsaStartDelayed(id){
	octolog.debug("setting osa start delayed for "+id, "OsaStart");
	setTimeout("octoOsaStart('"+id+"');",100);
}

function octoOsaStart(id){
	var launch = octopv_getLaunchObject(id);
	if(launch!=null){
		octolog.debug("osa start called for "+id, "OsaStart");
		launch.start();
	}
}

 
function octoOsaGetResult(id){
	var launch = octopv_getLaunchObject(id);
	if(launch==null){
		return octoErrors.LAUNCH_UNKNOWN;
	}else if(!launch._isFinished){
		return octoErrors.STAGE_RUNNING;
	}else{
		return launch._repliedState;
	}
}


function octoOsaGetStringResult(id){
	var launch = octopv_getLaunchObject(id);
	if(launch!=null && launch._isFinished){
		return launch._repliedString;
	}else{
		return "";
	}
}






function octopv_ConstructCookieSettings(){
	this._logTag='Settings';
	this._getCookie=function(name){
		var cs = document.cookie.split(';');
		for(var i=0;i < cs.length;i++) {
			var c = cs[i];
			
			while (c.charAt(0)==' '){
				c = c.substring(1,c.length);
			}
			if (c.indexOf(name) == 0) {
				
				var kv = c.split('=');
				if(kv.length >= 1&&kv[0]==name){
					if(kv.length==2){
						return kv[1];
					}else{
						return "";
					}
				}
			}
		}
		return null;
	};

	this._hasCookie=function(name){
		var cs = document.cookie.split(';');
		for(var i=0;i < cs.length;i++) {
			var c = cs[i];
			while (c.charAt(0)==' '){
				c = c.substring(1,c.length);
			}
			if (c.indexOf(name) == 0) {
				return true;
			}
		}
		return false;
	};

	this.getStatId=function(){
		var id = this._getCookie("octowebstatid");
		if(id==null||id==""){
			id=octoUtil.randomString(20);
		}
		var age = 365*24*60*60; 
		document.cookie = "octowebstatid="+id+"; max-age="+age+"; path=/";
		return id;
	};
	
	this.launchMethodOk=function(id){
		return this._hasCookie("octoweb"+id+"=true");
	};
	
	this.setLaunchMethodOk=function(id){
		octolog.info('Setting cookie for: '+id+' ',this._logTag);
		var age = 31*24*60*60; 
		document.cookie = "octoweb"+id+"=true; max-age="+age+"; path=/";
	};
	
	this.updateCounter=function(name){
		var cookieName = "octocounter"+name;
		var count = this.getCounter(name);
		count++;
		var age=365*24*60*60;
		document.cookie = cookieName+"="+count+"; max-age="+age+"; path=/";
	};
	
	this.getCounter=function(name){
		var cookieName = "octocounter"+name;
		var count = 0;
		if(this._hasCookie(cookieName)){
			try{
				count = parseInt(this._getCookie(cookieName));
			}catch(ex){
				octolog.warning('Error getting cookie: '+ex,this._logTag);
			}
		}
		return count;
	};
	
	this.getAll=function(){
		var arr = new Array();
		var cs = document.cookie.split(';');
		for(var i=0;i < cs.length;i++) {
			var c = cs[i];
			
			while (c.charAt(0)==' '){
				c = c.substring(1,c.length);
			}
			if (c.indexOf('octo') == 0) {
				arr.push(c);
			}
		}
		return arr;
	};
	
	this.clear=function(){
		var cs = document.cookie.split(';');
		for(var i=0;i < cs.length;i++) {
			var c = cs[i];
			
			while (c.charAt(0)==' '){
				c = c.substring(1,c.length);
			}
			if (c.indexOf('octo') == 0 && c.indexOf('octowebstat')==-1) {
				document.cookie = c+"; max-age=0; path=/";
			}
		}
	};
}
window.octopv_settings=new octopv_ConstructCookieSettings();



function octopv_ConstructDirectStat(){
	this._logTag="octostat";
	this._obj=null;
	this._listeners=new Array();
	this.randomId=octoUtil.randomString(10); 
	
	this._state=-1;
	
	this.ready=function(reply){
		switch(this._state){
		case -1: 
			this._listeners.push(reply);
			this._insert();
			return; 
		case 1: 
			this._listeners.push(reply);	
			return; 
		default: 
			reply(this._state); 			
			return; 
		}
	};	

	var arr = this._listeners;
	this._callListeners=function(){
	this._listeners=new Array();
	for(var i=0; i<arr.length; i++){
			arr[i](this._state);
		}
	};	

	this.openSession=function(strXmlString,keepAlive){
		try{
			var statId = this._obj.openSessionStr(strXmlString,keepAlive);
			return statId;
		}catch(ex){
			octolog.warning("Exception while calling open: "+ex,this._logTag);
			return null;
		}
	};
	
	
	this.finishedSession=function(strXmlString){
		try{
			this._obj.finishedSessionStr(strXmlString);
		}catch(ex){
			octolog.warning("Exception while calling finished: "+ex,this._logTag);
		}
	};	
	
	this.updateSession=function(statIdString, strXmlString){
		try{
			this._obj.updateSessionStr(statIdString, strXmlString);
		}catch(ex){
			octolog.warning("Exception while calling update: "+ex,this._logTag);
		}
	};	
	
	this.closeSession=function(statIdString, strXmlString){
		try{
			this._obj.closeSessionStr(statIdString, strXmlString);
		}catch(ex){
			octolog.warning("Exception while calling close: "+ex,this._logTag);
		}
	};

	this._initTimoutReached=function(){
		if(this._state==1){
			this._state = -2; 
			octolog.info('Timeout has been reached and we had no answer from flash',this._logTag);
			this._callListeners();
		}else{
			octolog.info('(Timeout has been reached, but we already replied)',this._logTag);
		}
	}

	this._initFromFlash=function(swfname){
		octolog.info('init-function called',this._logTag);
		var oldState = this._state;
		this._state = 0;
		this._obj=octoUtil.getSwfObject(swfname);
    	if(oldState==-2){
			octolog.info("Init called after timeout was reached.",this._logTag);
    	}else{
			this._callListeners();
    	}
	}
	
	this._insert=function(){
		this._state = 1; 
		var myId="octopv_directStatId";
		var jslog=octolog.isShowing();
		var debug=false;
		
		var timeoutfunctionName=myId+'timeout';
		var initfunctionName=myId+'init';
		var flashName=myId+'name';
		var path = octoConfig.getPath(octoConfig.ID_STAT); 
		if(path==null){
			this._state = -4; 
			this._callListeners();
			return;
		}
		var flashVars = 'init='+initfunctionName+'&debug='+debug+'&jslog='+jslog;
		
	  	var html  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	   	html += ' id="'+flashName+'" ';
	    if(debug){
		   	html += ' width="800" height="200"';
	    }else{
		   	html += ' width="0" height="0"';
	    }
	    html += ' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">';
	    html += ' <param name="movie" value="'+path+'" />';
	    html += ' <param name="FlashVars" value="'+flashVars+'" />';
	    html += ' <param name="wmode" value="transparent" />';
	    html += ' <param name="AllowScriptAccess" value="always" />';
	    html += ' <embed src="'+path+'"';
	    if(debug){
		    html += ' width="800" height="200"';
	    }else{
		    html += ' width="1" height="1"';
	    }
	    html += ' name="'+flashName+'"';
	    html += ' AllowScriptAccess="always"';
	    html += ' FlashVars="'+flashVars+'"';
	    html += ' play="true" loop="false" wmode="transparent"';
	    html += ' type="application/x-shockwave-flash" ';
	    html += ' pluginspage="http://www.adobe.com/go/getflashplayer">';
	    html += ' </embed></object>';
	    
		octolog.info('Inserts flash helper from '+path,this._logTag);
		
		window[initfunctionName]=function(swfname){
			octopv_directStatObject._initFromFlash(swfname);
		};
		var w = debug?800:-1;
		var h = debug?200:-1;
		if(octoUtil.writeInNewDiv(html,this._logTag,w,h)){
			
			window[timeoutfunctionName]=function flashStat_timeout2(){
				octopv_directStatObject._initTimoutReached();
			};
			setTimeout("window."+timeoutfunctionName+"();",4500);
	    }else{
			octolog.info('Could not write to div',this._logTag);
			this._state = -3; 
			this._callListeners();
	    }
	};
}
var octopv_directStatObject=new octopv_ConstructDirectStat();

function octopv_ConstructLaunchStatistics(playerId, instanceId, replyKind, useInstall, timeout){
	this._logTag="octostat";
	this._enabled=true;
	this._statTimeout=timeout;
	this._playerId=playerId;
	this._instanceId=instanceId;
	this._statId=null;
	this._begin=0;
	this._end=0;
	this._result=-9999;
	this._attempts = new Array();
	this._reply = replyKind;
	this._install=useInstall;
	this._cookieid = octopv_settings.getStatId();
	this._delayed=octoConfig.statDelayed; 
	
	this._toXml=function(){
		var xml = '<autolaunch ';
		xml+='reply="'+this._reply+'" ';
		if(this._install){
			var vari = octoConfig.variant;
			if(vari==null || vari==""){
				vari='octoshape';
			}
			xml+='install="'+vari+'" ';
		}
		if(this._playerId){
			xml+='playerid="'+this._playerId+'" ';
		}
		if(this._instanceId){
			xml+='instanceid="'+this._instanceId+'" ';
		}
		xml+='version="2" ';
		xml+='jsid="'+octopv_directStatObject.randomId+'" ';
		
		xml+='cookieid="'+this._cookieid+'" ';
		xml+='useragent="'+navigator.userAgent+'" ';
		xml+='octoversion="'+octoUtil.getOctoVersion()+'" ';
		if(octolog.isShowing()){
			xml+='debug="true" ';
		}
		xml+='numinstalls="'+octopv_settings.getCounter('installdone')+'" ';
		var texteulas =octopv_settings.getCounter('texteulaclicked');
		if(texteulas>0){
			xml+='numtexteula="'+texteulas+'" '; 
		}		
		
		xml+='domain="'+document.domain+'" ';
		
		
		xml+='begin="'+this._begin+'" ';
		if(this._end>0){
			xml+='end="'+this._end+'" result="'+this._result+'" ';
		}
		xml+=' >';
		var ai=0;
		for (;ai<this._attempts.length;ai++){
			xml+=this._attempts[ai].toXml();
		}
		xml += '</autolaunch>';
		return xml;
	};

	
	this.open=function(){
		if(this._end>0){
			octolog.warning("ERROR: opening closed stat session: "+this._statId,this._logTag);
			return;
		}
		if(this._begin>0){
			octolog.warning("ERROR: opening opened stat session: "+this._statId,this._logTag);
			return;
		}
		this._begin=new Date().getTime();
		this._updateStat();
	};
	
	
	this.beginAttempt=function(name){
		if(this._end>0){
			octolog.warning("ERROR: begin attempt on closed stat session: "+this._statId,this._logTag);
			return "";
		}else{
			var att = new ConstructAttempt(name, this._logTag);
			var newLen = this._attempts.push(att);
			this._updateStat(false);
			return (newLen-1);
		}
	};

	
	this.updateAttempt=function(attId){
		if(this._end>0){
			octolog.warning("ERROR: update attempt on closed stat session: "+this._statId,this._logTag);
		}else{
			var att = this._attempts[attId];
			if(typeof(att)=='object' && typeof(att.end)=='function'){
				att.update(); 
				this._updateStat(false);
			}
		}
	};

	
	
	this.endAttempt=function(intResult, attId){
		if(this._end>0){
			octolog.warning("ERROR: end attempt on closed stat session: "+this._statId,this._logTag);
		}else{
			var att = this._attempts[attId];
			if(typeof(att)=='object' && typeof(att.end)=='function'){
				att.end(intResult);
				this._updateStat(false);
			}
		}
	};
	
	
	this.close=function(intResult){
		if(this._end>0){
			octolog.warning("ERROR:Closing already closed stat session: "+this._statId,this._logTag);
		}else{
			this._end=new Date().getTime();
			this._result=intResult;
			this._updateStat(false);
		}
	};
	
	this.flush=function(){
		if(this._delayed){
			this._updateStat(true);
		}
	};
	
	this._updateStat=function(force){
		if(this._delayed && !force){
			octolog.debug('Stat is delayed.',this._logTag);
		}else if(this._enabled){
			if(this._statId==null){
				
				var me = this;
				octopv_directStatObject.ready(function(status){
					if(status==0){
						octolog.info('Stat is ready, now to call open session.',me._logTag);
						var xml = me._toXml();
						if(me._end>0){
							octopv_directStatObject.finishedSession(xml);
						}else{
							me._statId=octopv_directStatObject.openSession(xml,me._statTimeout);
							if(me._statId==-1){
								octolog.info('Stat open returned -1. Disabling stat.',me._logTag);
								me._enabled=false;
							}
						}
					}else{
						octolog.info('Stat error: '+status,me._logTag);
						me._enabled=false;
					}
				});
			}else{
				
				if(this._end>0){
					octopv_directStatObject.closeSession(this._statId, this._toXml());
				}else{
					octopv_directStatObject.updateSession(this._statId, this._toXml());
				}
			}
		}else{
			octolog.debug("Not updating since stat is disabled. open:"+this._statId,this._logTag); 
		}
	};
	
	function ConstructAttempt(name1,logTag){
		this._logTag=logTag;
		this._name = name1;
		this._begin = new Date().getTime();
		this._update = 0;
		this._end = 0;
		this._result = -1; 

		this.update=function(){
			if(this._end>0){
				octolog.warning("ERROR: update attempt on already ended att ",this._logTag);
			}else{
				this._update = new Date().getTime();
			}
		}

		this.end=function(intResult){
			if(this._end>0){
				octolog.warning("ERROR: end attempt on already ended att ",this._logTag);
			}else{
				this._end=new Date().getTime();
				this._result=intResult;
			}
		}
		
		this.toXml=function(){
			var xml = '<attempt name="'+this._name+'" begin="'+this._begin+'" ';
			if(this._end>0){
				xml+='end="'+this._end+'" result="'+this._result+'" ';
			}
			if(this._update>0){
				xml+='update="'+this._update+'" ';
			}
			xml+=' /> ';
			return xml;
		};
	}
}



function octopv_ConstructBP(replyKind, strArg){
	this._replyKind=replyKind;
	this._strArg=strArg;
	this.attemptId=octoConfig.ID_BROWSER_PLUGIN;
	this._logTag=this.attemptId;
	
	this.canAnswer=function(){
		if(octoConfig.hasDisabled(this.attemptId)){
			return window.octoErrors.BP_DISABLED;
		}else if(octoUtil.isWindows() || octoUtil.isOSX()){
			if(octoUtil.isOpera()){
				return window.octoErrors.BP_NOT_IN_OPERA;
			}else{
				return 0;
			}
		}else{
			return window.octoErrors.BP_ONLY_ON_WIN_AND_MAC;
		}
	};
	var me=this;
	this.start=function(onError, onSuccses){
		var can = this.canAnswer();
		if(can!=0){
			onError(can);
			return;
		}
		octopv_bp._logTag=this._logTag;
		octopv_bp.makePluginReady(function(result){
			if(result==0){
				octopv_settings.setLaunchMethodOk(me.attemptId);
				switch(me._replyKind){
				case octoLaunchKinds.START_UP: onSuccses(0); break;
				case octoLaunchKinds.GET_CONNECT_URL: 
					var xml = octopv_bp.plugin.getString('xmlbound');
					onSuccses(xml); 
					break;
				case octoLaunchKinds.CONVERT_LINK: 	
					var playlink = octopv_bp.plugin.getLink(me._strArg,false);
					octolog.info('Got play link from browser plugin: '+playlink+'.',me._logTag);
					onSuccses(playlink); 
					break;
				case octoLaunchKinds.GET_STRING: 
					onSuccses(octopv_bp.plugin.getString(me._strArg)); 
					break;
				case octoLaunchKinds.GET_SUA_VERSION:
					var xml = octopv_bp.plugin.getString('suaversion');
					onSuccses(xml); 
					break;
				}
			}else{
				if(result == octoErrors.NO_BROWSER_PLUGIN){
					var browserNotIE=navigator.userAgent.toLowerCase().indexOf("msie") == -1;
					var hasCookie=octopv_settings.launchMethodOk(me.attemptId);
					var logStr='We trust this answer? cookie:'+hasCookie+' / non-ie:'+browserNotIE;
					octolog.info('Not found ('+result+'). '+logStr,me._logTag);
					onError(result);
				}else{
					onError(result);
				}
			}
		});
	};	
}


function octopv_ConstructBrowserPlugin(){
	this.plugin = null;
	this._replyFunction = function(){};
	this._logTag=null;
	
	this._setPlugin = function BPsetPlugin(plug){
		this.plugin=plug;
		this._readyRepeat();
	};
	
	this._convertPluginError=function(error){
		if(error==-1) return octoErrors.PLUGIN_ANSWER_BP_NOT_FOUND;
		if(octoUtil.isOSX()){
			octolog.warning('Error from mac osx browser plugin: '+error,this._logTag);
			var bpErrorPlus = Math.floor((-error)/100000);
			var macErrorPlus = (-error)%(bpErrorPlus*10000);
			octolog.info('Mac osx error code: '+(-macErrorPlus),this._logTag);
			return octoErrors.convertBpError(bpErrorPlus, false);
		}else{
			return octoErrors.convertBpError(error, false);
		}
	};
	
	this._readyRepeat=function(){
		try {
			var result = this.plugin.getStatus(true);
			switch (result){
		 		case 1:
					
					setTimeout("octopv_bp._readyRepeat();",1000);
					return;
				case 2:
					
					this._replyFunction(0); 
					return;
		 		default:
					this._replyFunction(this._convertPluginError(result)); 
		 			return;
			}
		}catch (exception) {
			octolog.warning('octopv_bp._readyRepeat exception '+exception,this._logTag);
			this._replyFunction(this._convertPluginError(-6)); 
		}
	}
	
	this._check=function(octoobject){
		if (octoobject==null || typeof(octoobject) == "undefined"){
			octolog.info('Octoobject('+octoobject+'): is typeof undefined',this._logTag);
			return octoErrors.NO_BROWSER_PLUGIN;
		}
		if (typeof(octoobject.getStatus) == "undefined") {
			octolog.warning('Octoobject('+octoobject+'): has no getStatus method',this._logTag);
			return octoErrors.BROWSER_PLUGIN_NO_METHOD;	
		}
		return 0;
	}
	
	this._mimeType=function BPMimetype() {
		var octomime = "application/x-octoshapeplugin-client";
		octolog.info("Trying to get browser plugin by mime type: "+octomime,this._logTag);
						
		if (navigator && navigator.mimeTypes && navigator.mimeTypes.length > 0) {
			var mimetype = navigator.mimeTypes[octomime];
			
			if (!mimetype && (navigator.plugins)) {
				octolog.info("Refreshing plugins",this._logTag);
				navigator.plugins.refresh(false);
				mimetype = navigator.mimeTypes[octomime];
			}

			if (!mimetype) {
				octomime = octomime.toLowerCase();
				mimetype = navigator.mimeTypes[octomime];
			}
			
			if (mimetype) {
				var name = 'octoshapeclientobject';
				var octoshape = document.getElementById(name);
				if (!octoshape) {
					octolog.info("We have no "+name+" object",this._logTag);
					var html = "";
					if(octoUtil.isOSX()){
						html = '<embed id="'+name+'" type="'+octomime+'" hidden="true"></embed>';
					}else{
						var style = 'height:0px; width:1px; visibility:hidden;';
						html = '<object id="'+name+'" type="'+octomime+'" style="'+style+'" />';
						
					}
					octoUtil.writeInNewDiv(html,this._logTag);
					octoshape = document.getElementById(name);
				}
				octolog.info("Have inserted html mime type object, now checking object. ",this._logTag);
				if (this._check(octoshape)==0) {
					octolog.info("Client loaded using mimeTypes:" + octomime,this._logTag);
					this._setPlugin(octoshape);
					return true;
				}else{
					octolog.info("Mime type "+octomime+" not known. Inserted object:"+octoshape,this._logTag);
					octolog.info("We try to wait 1 second ... ",this._logTag);
					
					octopv_setTimeoutFunction(1000, function(){
						octolog.info("After waiting 1 second for browser plugin",octopv_bp._logTag);
						var octoDims = document.getElementById('octoshapeclientobject');
						if (octoDims==null || typeof(octoDims) == "undefined"){
							octopv_bp._replyFunction(octoErrors.NO_BROWSER_PLUGIN);
						}
						if (typeof(octoDims.getStatus) == "undefined") {
							octopv_bp._replyFunction(octoErrors.BROWSER_PLUGIN_NO_METHOD);
						}
						octolog.info("Browser plugin ok after wait",octopv_bp._logTag);
						octopv_bp._setPlugin(octoDims);
					});
					return true;
				}
			} 
		}
		return false;
	};
	
	
	this._getBp=function BPGet(){
		
		var errorCode = octoErrors.NO_BROWSER_PLUGIN;
		try {
			if (window.ActiveXObject) {
				try {
					var octoshape = new ActiveXObject("octoshapeplugin.client");
					errorCode = this._check(octoshape);
					if(errorCode==0){ 
						octolog.info("Client loaded using ActiveXObject",this._logTag);
						this._setPlugin(octoshape)
						return; 
					}
				} catch(exception) {}
			}
		
			if (window.GeckoActiveXObject) {
				try {
					var octoshape = new GeckoActiveXObject("octoshapeplugin.client");
					errorCode = this._check(octoshape);
					if(errorCode==0){ 
						octolog.info("Client loaded using GeckoActiveXObject",this._logTag);
						this._setPlugin(octoshape)
						return;
					}
				} catch(exception) {}
			}
			
			
			if (false && navigator && navigator.plugins && navigator.plugins.length > 0) {
				var octoshape = navigator.plugins["application/x-octoshapeplugin.client"];
				errorCode = this._check(octoshape);
				if(errorCode==0){ 
					octolog.info("Client loaded using navigator.plugins",this._logTag);
					this._setPlugin(octoshape)
					return;
				}
			}
		
			if(navigator && navigator.mimeTypes && navigator.mimeTypes.length > 0) {
				if(this._mimeType()) return;
			}
		} catch (exception) {
			if(this._mimeType()) return;
		}
		
		octolog.info("Client loading failed all together.",this._logTag);
		this._replyFunction(errorCode);
	};
	
	
	this.makePluginReady=function(replyFunction){
		this._replyFunction = replyFunction;
		if(this._check(this.plugin)==0){
			this._readyRepeat();
		}else{
			this._getBp();
		}
	};
}


var octopv_bp = new octopv_ConstructBrowserPlugin();



window.octopv_preloadAppletCount=0;
window.octopv_preloadAppletReplies=new Object();
function octopv_initAppletInited(callbackId, major,minor,micro,osVersion){
	octolog.info("got applet reply for "+callbackId);
	if(arguments.length>=4){
		octolog.info('System info: java version 1.'+major+'.'+minor+'_'+micro);
	}
	octopv_preloadAppletReplies[callbackId](major,minor,micro,osVersion);
}


function octopv_preloadApplet(replyFunction, timeoutMillis, logTag1, archive1){
	var answered=false;
	var logTag=octoUtil.getFirstOfType('string',logTag1,'app-preload');
	var name = 'func'+window.octopv_preloadAppletCount;
	var reply = 'window.octopv_preloadAppletReplies.'+name+'();';
	window.octopv_preloadAppletReplies[name]=function(major,minor,micro,osVersion){
		if(answered){
			octolog.info("got applet reply from "+name+" but we have already answered!",logTag);
		}else{
			octolog.info("got applet reply from "+name,logTag);
			answered=true;
			replyFunction(0,major,minor,micro,osVersion);
		}
	};
	var div = 'octopv_preloadApplet'+window.octopv_preloadAppletCount;
	window.octopv_preloadAppletCount++;
	var html='';
	
	var initcode=octoConfig.getCodePath(octoConfig.ID_TEST_APPLET); 
	var initjar=octoConfig.getPath(octoConfig.ID_TEST_APPLET);
	
	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1){
		
		octolog.info("generating test applet ie tag",logTag);
		html += '<OBJECT ';
		html += 'NAME="'+name+'" ';
		html += 'ID="'+name+'" ';
	  	html += 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
		html += 'width="1" height="1"> ';
		html += '<PARAM NAME="code" value="'+initcode+'" /> ';
		if(typeof(archive1)=='string'){
			html += '<PARAM NAME="archive" VALUE="'+initjar+','+archive1+'">';
		}else{
			html += '<PARAM NAME="archive" VALUE="'+initjar+'" />';
		}
	  	html += '<PARAM NAME="mayscript" VALUE="true" />';
	  	html += '<PARAM NAME="callbackstring" VALUE="'+name+'" />';
		html += '</OBJECT> ';
	}else{
		
		octolog.info("generating test applet non-ie tag",logTag);
		html += '<applet code="'+initcode+'" '; 
		html += 'width="1" height="1" ';
		if(typeof(archive1)=='string'){
			html+='archive="'+initjar+','+archive1+'" ';
		}else{
			html+='archive="'+initjar+'" ';
		}
        html += 'scriptable="true" ';
        html += 'mayscript="true" ';
		html += 'callbackstring="'+name+'" ';
		html += '>';
		
		html += '<PARAM name="callbackstring" value="'+name+'">';	
		html += '</applet>';
	}
	var timeoutName=name+'timeout'; 
	var timeout = 'window.octopv_preloadAppletReplies.'+timeoutName+'();';
	window.octopv_preloadAppletReplies[timeoutName]=function(){
		if(answered){
			octolog.info("(Reached timeout for "+name+" but we have already answered)",logTag);
		}else{
			octolog.info("Reached timeout for "+name,logTag);
			answered=true;
			replyFunction(octoErrors.PRELOAD_APPLET_TIMEOUT);
		}
	};
	octolog.info("Writing test applet tag to page: "+initjar,logTag);
	if(octoUtil.writeToDiv(div, html, logTag,true)){
		if(answered){
			octolog.info("Not setting timeout since we already have answered",logTag);
		}else{
			octolog.info("Setting timeout to "+timeoutMillis,logTag);
			setTimeout(timeout,timeoutMillis);
		}
	}else{
		replyFunction(octoErrors.PRELOAD_APPLET_INSERT); 
	}
}

function octopv_ConstructAppletTest(timeoutMillis){
	this.major=-1;
	this.minor=-1;
	this.micro=-1;
	this.runonce=true;
	this.osVersion="";
	this._timeoutMillis=timeoutMillis;
	this.attemptId=octoConfig.ID_TEST_APPLET;
	this._logTag=this.attemptId;
	
	
	this.canAnswer=function(){
		if(octoConfig.hasDisabled(this.attemptId)){
			octolog.info("All applets are disabled!",this._logTag);
			return octoErrors.APPLETS_DISABLED;
		}else if(octoUtil.isWindows() || octoUtil.isOSX()){
			if(!navigator.javaEnabled()){
				if(octoUtil.isWindows() && octoUtil.isFirefox()){
					octolog.info("Java disabled, but user-conf is win+fx, so we try anyway.",
							this._logTag);
				 	return 0;
				}else{
					octolog.info("Applet launch impossible. java disabled:"+navigator.javaEnabled(),
							this._logTag);
				 	return octoErrors.JAVA_NOT_ENABLED; 
				}
			}
			return 0;
		}else{
			
			octolog.info("Can not do applet launch or install since OS is not windows or mac os x",
					this._logTag);
			return octoErrors.TEST_APPLET_NOT_ON_THIS_OS;
		}
	};
	var me=this;
	this.start=function(onFinish){
		var can = this.canAnswer();
		if(can!=0){
			onFinish(can);
			return;
		}
		octopv_preloadApplet(function(ok,major,minor,micro,osVersion){
			if(ok==0){
				me.major=major;
				me.minor=minor;
				me.micro=micro;
				me.osVersion=osVersion;
				onFinish(octoErrors.TEST_APPLET_OK);
			}else{
				onFinish(ok);
			}
		},this._timeoutMillis,this._logTag);
	};
}

function octopv_ConstructPreloadInstallApplet(appTest,timeoutMillis){
	this._appTest=appTest;
	this._timeoutMillis=timeoutMillis;
	this.runonce=true;
	this.attemptId=octoConfig.ID_PRELOAD_APPLET;
	this._logTag=this.attemptId;
	
	this.canAnswer=function preloadInstallAppletCan(){
		
		var appTestCan = this._appTest.canAnswer();
		if(appTestCan!=0){
			return appTestCan;
		}
		var userAgent = navigator.userAgent.toLowerCase();
		  
		if(octoUtil.isOSX()){
			
			function hasVersion(str){ return (appTest.osVersion.indexOf(str) != -1); }
			 
			if(hasVersion("10.0")||hasVersion("10.1")||hasVersion("10.2")||hasVersion("10.3")){
				 
				return octoErrors.INSTALL_APPLET_OLD_MAC; 
			}
		
		}else if(octoUtil.isIE() && octoUtil.isVista()){
			 
			if(this._appTest.major < 6 || (this._appTest.major==6 && 
					this._appTest.minor==0 && this._appTest.micro < 8)){
				
				octolog.info("no applet install since: vista + ie + java<=1.6.0_07: "+
						major+"/"+minor+"/"+micro,this._logTag);
				return octoErrors.INSTALL_APPLET_VISTA_OLD_JAVA; 
			}
		}
		
		return 0;
	};
	var me=this;
	this.start=function(onFinish){
		var can=this.canAnswer();
		if(can!=0){
			onFinish(can);
			return;
		}
		octopv_preloadApplet(function(ok){
			var exit = ok==0?octoErrors.PRELOAD_APPLET_OK:ok;
			onFinish(exit);
		},this._timeoutMillis,this._logTag,octoConfig.getPath(octoConfig.ID_INSTALL_APPLET)); 
	};
}



function octopv_ConstuctLauncherApplet(){
	
	this.status=octoErrors.STAGE_NOT_WRITTEN_TO_PAGE;
	
	this.name = 'octopv_pluginLauncherAppletApplet';
	this._readyFunction=null;
	this._readyFunctionNew=false;
	this._logTag=null;
	
	
	this.start=function(functInt){
		octolog.debug('Starting Launch-applet.',this._logTag);
		if(!octoErrors.isStage(this.status)){
			
			octolog.debug('Launch-applet is in some error state: '+this.status,this._logTag);
			functInt(this.status);
		}else if(this.status==0){
			
			octolog.debug('Launch-applet is ready .',this._logTag);
			this._readyFunction=functInt;
			this._readyFunctionNew=true;
			this._startupPlugin();
		}else{
			
			octolog.debug('Launch-applet is running. status is '+this.status,this._logTag);
			this._readyFunction=functInt;
			this._readyFunctionNew=true;
			
			if(this.status==octoErrors.STAGE_NOT_WRITTEN_TO_PAGE){	
				if(!this._insert()){
					this.status=octoErrors.LAUNCH_APPLET_JAVASCRIPT;
					this._readyFunctionNew=false;
					functInt(this.status);
				}
			}
		}
	};
	
	this._startupPlugin=function(){
		if(this.status==0){
			octolog.info('Looping for plugin startup.',this._logTag);
			this._loopCount=0;
			this._loopForPlugin();
		}else if(octoErrors.isStage(this.status)){
			octolog.info('Waiting for launch applet init.',this._logTag);
		}else{
			octolog.info('Replying applet error.',this._logTag);
			if(this._readyFunction!=null && this._readyFunctionNew){
				this._readyFunctionNew=false;
				this._readyFunction(this.status);
			}
		}
	};

	this._loopCount=0;
	this._loopForPlugin=function(){
		this._loopCount++;
		var os = this.getStatus(this._loopCount==1);
		if(os==0 ||os==1){
			setTimeout("window.octopv_pluginLauncherApplet._loopForPlugin();",1000);
		}else{
			if(this._readyFunction!=null && this._readyFunctionNew){
				this._readyFunctionNew=false;
				if(os==2){
					this._readyFunction(0);
				}else{
					
					if(os==-1){
						
						this._readyFunction(octoErrors.LAUNCH_APPLET_NO_PLUGIN);
					}else{
						this._readyFunction(octoErrors.convertBpError(os, true));
					}
				}
			}
		}
	};
	
	this.resetAll=function(){
		this._readyFunctionNew=false;
	};

	this._appletReady=function(reply){
		var init = octoUtil.convertToNumber(reply, octoErrors.LAUNCH_APPLET_REPLY);
		octolog.info('Launcher applet inited with '+init+'. Status is '+this.status,this._logTag);
		if(init>0){
			this.status=octoErrors.STAGE_WAITING_FOR_FINISH_CALL; 
		}else{
			if(init==0){
				this.status=0;
			}else if(init==-2){
				this.status=octoErrors.LAUNCH_APPLET_WRITE;
			}else if(init==-3){
				this.status=octoErrors.LAUNCH_APPLET_SECURITY;
			}else{
				this.status=octoErrors.LAUNCH_APPLET_UNKNOWN; 
			}
			
			setTimeout("octopv_pluginLauncherApplet._startupPlugin();",500);
		}
	};
	
	this._insert=function(){
		octolog.info('Inserting launch-applet');
		try{
			this.status=octoErrors.STAGE_WAITING_FOR_INIT_CALL;
			var html='';
			
			var mainClass = octoConfig.getCodePath(octoConfig.ID_LAUNCH_APPLET);
			var jarFile = octoConfig.getPath(octoConfig.ID_LAUNCH_APPLET);
			if(jarFile==null){
				octolog.warning('Applet path not set. launcher '+jarFile, this._logTag);
				return false;
			}
			if(navigator.userAgent.toLowerCase().indexOf("msie") != -1){
				
				html += '<OBJECT ';
				html += 'NAME="'+this.name+'" ';
				html += 'ID="'+this.name+'" ';
			  	html += 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
				html += 'width="1" height="1"> ';
				html += '<PARAM NAME="code" value="'+mainClass+'" /> ';
				html += '<PARAM NAME="archive" VALUE="'+jarFile+'" />';
			  	html += '<PARAM NAME="mayscript" VALUE="true" />';
			  	html += '<PARAM NAME="scriptable" VALUE="true" />';
			  	html += '<PARAM NAME="callbackstring" VALUE="launcher" />';
			  	html += '<PARAM NAME="initfunction" VALUE="octopv_pluginLauncherAppletInited" />';
			  	html += '<PARAM NAME="NAME" VALUE="'+octoConfig.appletDisplayName+'">';
			  	html += octolog.appletDebugParams(true);
				html += '</OBJECT> ';
			}else{
				
				html += '<embed code="'+mainClass+'" '; 
				html += 'width="1" height="1" type="application/x-java-applet;version=1.1" ';
				html += 'pluginspage="http://java.sun.com/javase/downloads/" ';
		        html += 'id="'+this.name+'" ';
				html += 'NAME="'+octoConfig.appletDisplayName+'" ';
				html += 'archive="'+jarFile+'" ';
		        html += 'scriptable="true" ';
		        html += 'mayscript="true" ';
				html += 'callbackstring="launcher" ';
			  	html += 'initfunction="octopv_pluginLauncherAppletInited" ';
			  	html += octolog.appletDebugParams(false);
				html += '/>';
			}
			if(!octoUtil.writeToDiv('octopv_pluginLauncherAppletDiv', html, this._logTag,true)){
				return false;
			}
			return true;
		
		}catch(ex){ 
			octolog.warning('JavaScript error: '+ex.message,this._logTag);
			return false;
		}
	}
		
	this.getPlayLink=function(octolink){
		if(this.status!=0) return "";
		return document[this.name].getLink(octolink, false);
	};

	this.getStringOption=function(option){
		if(this.status!=0) return "";
		return document[this.name].getString(option);
	};

	this.getStatus=function(startup){
		try{
			if(octoErrors.isStage(this.status)){
				return octoErrors.LAUNCH_APPLET_NOT_READY;
			}else if (this.status!=0){
				return this.status;
			}else{
				var reply = document[this.name].getStatus(startup);
				octolog.info('stat: '+this.status+'. Reply from getStatus('+typeof(reply)+'): '+reply,
					this._logTag);
				return reply;
			}
		}catch(ex){ 
			octolog.warning('JavaScript error: '+ex.message,this._logTag);
			return octoErrors.JS;
		}
	};
}
var octopv_pluginLauncherApplet=new octopv_ConstuctLauncherApplet();


function octopv_pluginLauncherAppletInited(reply){
	octopv_pluginLauncherApplet._appletReady(reply);
}

function octopv_ConstructAppletLaunch(replyKind, strArg){
	this._replyKind=replyKind;
	this._strArg=strArg;
	this.attemptId=octoConfig.ID_LAUNCH_APPLET;
	this._logTag=this.attemptId;
	
	this.canAnswer=function(){
		if(octoConfig.hasDisabled(this.attemptId)){
			octolog.info("AppletLaunch is disabled!",this._logTag);
			return octoErrors.LAUNCH_APPLET_DISABLED;
		}else if(octoUtil.isOSX()){
			octolog.info('can not use applet launch since we are on mac os.',this._logTag);
			return octoErrors.LAUNCH_APPLET_NOT_ON_MAC;
		}else if(octopv_settings.launchMethodOk(octoConfig.ID_SIGNED_APPLET)){
			octolog.debug('can use applet launch since we have cookie',this._logTag);
			return 0;
		}else{
			octolog.info('can not use applet launch since there is no cookie',this._logTag);
			return octoErrors.LAUNCH_APPLET_NO_COOKIE;
		}
	};
	
	var me=this;
	this.start=function(onError, onSuccess){
		octolog.debug('applet launch start called ',this._logTag);
		var can = this.canAnswer();
		if(can!=0){
			onError(can);
			return;
		}
		octopv_pluginLauncherApplet._logTag=this._logTag;
		octolog.debug('applet launch calling sub 1',this._logTag);
		octopv_pluginLauncherApplet.start(function(status){
			if(status==0){
				
				octopv_settings.setLaunchMethodOk(octoConfig.ID_SIGNED_APPLET);
				switch(me._replyKind){
				case octoLaunchKinds.START_UP: 
					onSuccess(); 
					break;
				case octoLaunchKinds.GET_CONNECT_URL: 
					var xml = octopv_pluginLauncherApplet.getStringOption('xmlbound');
					onSuccess(xml); 
					break;
				case octoLaunchKinds.CONVERT_LINK: 
					onSuccess(octopv_pluginLauncherApplet.getPlayLink(me._strArg)); 
					break;
				case octoLaunchKinds.GET_STRING: 
					onSuccess(octopv_pluginLauncherApplet.getStringOption(me._strArg)); 
					break;
				case octoLaunchKinds.GET_SUA_VERSION: 
					var xml = octopv_pluginLauncherApplet.getStringOption('suaversion');
					onSuccess(xml); 
					break;
				}
			}else{
				
				onError(status);
			}
		});
		octolog.debug('applet launch after calling sub 1',this._logTag);
	};
}




function octopv_ConstructJsHttp(port1a, port2a, timeout, replyKind){ 
	this._portArr=new Array();
	this._portCount=-1;
	this._timeout=timeout;
	this._replyKind=replyKind;
	this.attemptId=octoConfig.ID_JSHTTP;
	this._logTag=this.attemptId;

	if(typeof(port1a)!='undefined'){
		this._portArr.push(port1a);
	}

	if(typeof(port2a)!='undefined'){
		this._portArr.push(port2a);
	}
	
	this.canAnswer = function(){
		if(window.XDomainRequest){
			switch(this._replyKind){
				case octoLaunchKinds.START_UP:  		return 0;
				case octoLaunchKinds.GET_CONNECT_URL: 	return 0;
				case octoLaunchKinds.GET_SUA_VERSION:	return 0;
			}
		}
		return octoErrors.JSHTTP_IMPOSSIBLE;
	};

	this.start=function(onError,onSuccess){
		if (this.canAnswer(this._replyKind)!=0){
			onError(octoErrors.JSHTTP_IMPOSSIBLE); 
			return;
		}
		this._portCount=-1;
		this._run(octoErrors.JSHTTP_IMPOSSIBLE, onError,onSuccess);
	}
	
	this._run=function(err, onError, onSuccess){
		this._portCount++;
		if(this._portCount>=this._portArr.length){
			onError(err);
		}else{
			var ipport = '127.0.0.1:'+(this._portArr[this._portCount]);
			var me = this;
			this._tryPort(ipport, this._replyKind, function(err){
				me._run(err, onError,onSuccess);
			},onSuccess,this._logTag);
		}
	};
	
	this._tryPort=function(ipport, replyKind, onError, onSuccess, logTag){
		octolog.info('Trying ip+port: '+ipport,this._logTag);
		var finished=false;
		try{
			
			octolog.info('Making XDomainRequest object ... ',logTag);
			var xdr=new XDomainRequest(); 
			if(!xdr){
				octolog.info('Could not make object.',logTag);
				onError(octoErrors.JSHTTP_IMPOSSIBLE); 
				return;
			}
			xdr.onload=function(){
				octolog.info('onload called',logTag);
				var reply = octoErrors.JSHTTP_UNKNOWN;
				var version = "";
				try {
					var xmlDoc=new ActiveXObject('Microsoft.XMLDOM');
					xmlDoc.async='false';
					var text = xdr.responseText;
					xmlDoc.loadXML(text);
					if(xmlDoc.documentElement.tagName=='octoshapesua'){
						reply = 0;
						version = xmlDoc.documentElement.getAttribute('version');
					}else{
						reply = octoErrors.JSHTTP_XML;
					}
					octolog.info('version: '+version,logTag);
					octolog.info('reply was: '+text,logTag);
				}catch(e){
					octolog.warning('Err '+e.name+': '+e.message,logTag);
					reply = octoErrors.JSHTTP_NOT_XML;
				}
				finished=true;
				
				switch(replyKind){
				case octoLaunchKinds.START_UP: 
					onSuccess();
					break;
				case octoLaunchKinds.GET_CONNECT_URL: 
					onSuccess(ipport);
					break;
				case octoLaunchKinds.GET_SUA_VERSION:	
					onSuccess(version);
					break;
				default:
					octolog.warning('ERROR: (jshttp) unknown reply kind was: '+replyKind,logTag);
				}
			};
			xdr.onerror = function(){
				octolog.info('onerror called: '+typeof(onError),logTag);
				finished=true;
				onError(octoErrors.JSHTTP_CONNECT);
			};
	        xdr.ontimeout = function(){
				octolog.info('ontimeout called',logTag);
				finished=true;
				onError(octoErrors.JSHTTP_CONNECT_TIMEOUT);
			};
	  		xdr.timeout = this._timeout;
	  		var req = 'http://'+ipport+'/octoshapeprobe.xml';
	  		
	  		xdr.open('POST', req);
			
			octopv_setTimeoutFunction(this._timeout+1500, function(){
				if(finished){
					octolog.info('We reached javascript timeout, but have already answered.',logTag);
				}else{
					finished=true;
					onError(octoErrors.JSHTTP_TIMEOUT);
				}
			});
	  		var randomStr = 'random'+(Math.floor(Math.random()*100000));
			octolog.info('Sending request: '+req+' post: '+randomStr,logTag);
			xdr.send(randomStr);
		}catch(ex){
			octolog.warning('Caught exception: '+ex,logTag);
			finished=true;
			onError(octoErrors.JSHTTP_CONNECT_EX);
		}
	}
}




window.octopv_counter=0;
function octopv_getJsUniqueId(){
	window.octopv_counter++;
	return ('id'+window.octopv_counter);
};

function octopv_ConstructPortFlash(port1,port2, replyKind){
	this._replyKind=replyKind;
	this._port1=port1;
	this._port2=port2;
	this.attemptId=octoConfig.ID_FLASH_BP;
	this._logTag=this.attemptId;

	
	this.canAnswer=function(){
		if(octoConfig.hasDisabled(this.attemptId)){
			return octoErrors.FLASH_BP_DISABLED;
		}else if(octoUtil.flashOk()){
			switch(this._replyKind){
				case octoLaunchKinds.START_UP:  		return 0;
				case octoLaunchKinds.GET_CONNECT_URL: return 0;
			}
		}
		return octoErrors.FLASH_BP_NO_OR_OLD_FLASH;
	};
	var me=this;
	this.start=function(onError, onSuccess){
		var can = this.canAnswer();
		if(can!=0){
			onError(can);
			return;
		}
		octopv_FlashBP(function(status,portReply){
			octolog.info('reply from octopv_FlashBP:'+portReply,me._logTag);
			if(status==0){
				if(me._replyKind==octoLaunchKinds.START_UP){
					onSuccess();
				}else if(me._replyKind==octoLaunchKinds.GET_CONNECT_URL){
					onSuccess('127.0.0.1:'+portReply);
				}
			}else{
				onError(status);
			}
		},this._logTag,this._port1,this._port2); 
	};
}


function octopv_FlashBP(replyfunc, logTag1){

	if(!octoUtil.flashOk()){
		replyfunc(octoErrors.FLASH_BP_NO_OR_OLD_FLASH); 
	};

	var myId=octopv_getJsUniqueId();
	
	var replyfunctionName='octopv_flashOctoIsRunningTester_reply'+myId;
	var timeoutfunctionName='octopv_flashOctoIsRunningTester_timeout'+myId;
	var initfunctionName='octopv_flashOctoIsRunningTester_init'+myId;
	var flashName='octopv_flash_bp'+myId;
	var logTag = octoUtil.getFirstOfType('string',logTag1,'FlashBP');
	var path = octoConfig.getPath(octoConfig.ID_FLASH_BP);

	if(path==null){
		octolog.info('Flash bp path not set.',logTag);
		replyfunc(octoErrors.PATH_NOT_SET); 
	}

  	var html  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
   	html += ' id="'+flashName+'" width="0" height="0"';
    html += ' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">';
    html += ' <param name="movie" value="'+path+'" />';
    html += ' <param name="FlashVars" value="init='+initfunctionName+'" />';
    html += ' <param name="wmode" value="transparent" />';
    html += ' <param name="AllowScriptAccess" value="always" />';
    html += ' <embed src="'+path+'"';
    html += ' width="1" height="1" name="'+flashName+'"';
    html += ' AllowScriptAccess="always"';
    html += ' FlashVars="init='+initfunctionName+'"';
    html += ' play="true" loop="false" wmode="transparent"';
    html += ' type="application/x-shockwave-flash" ';
    html += ' pluginspage="http://www.adobe.com/go/getflashplayer">';
    html += ' </embed></object>';

	octolog.info('Inserts flash helper from '+path,logTag);
	
	var portsArr = new Array();
	var debugStr = '';
	for(var i=1; i<arguments.length; i++){
		if(typeof(arguments[i])=='number'){
			portsArr.push(arguments[i]);
		}
	}
	
	for(var i=0; i<portsArr.length; i++){
        debugStr+=(portsArr[i]+',');
	}
	octolog.info('Ports to check ('+portsArr.length+'): '+debugStr,logTag);
	
	window[initfunctionName]=function(swfname){
		octolog.info('init-function called',logTag);
		var dims=octoUtil.getSwfObject(swfname);
		window[timeoutfunctionName]=function(){
			octolog.info('(Timeout has been reached, but we already replied)',logTag);
		};
		octolog.info('Calling flash bp: '+dims,logTag);
		window[replyfunctionName]=function(intResult){
			if(intResult==-1){
				replyfunc(octoErrors.FLASH_BP_UNKNOWN);
			}else if(intResult==0){
				octolog.info('Installed but not launched reply from flash!',logTag);
				replyfunc(octoErrors.FLASH_BP_NOT_LAUNCHED);
			}else{
				replyfunc(0,intResult);
			}
		};
		
		try{
	   		dims.octopvAS_beginCheck(replyfunctionName,2000,portsArr);
    	}catch(ex){
			octolog.warning('ex:'+ex,logTag);
			octolog.info('try to wait 1 second and then try again ...',logTag);
			octopv_setTimeoutFunction(1000, function(){
				try{
					octolog.info('After wait of 1 second.',logTag);
			   		dims.octopvAS_beginCheck(replyfunctionName,2000,portsArr);
		    	}catch(ex){
					octolog.info('After wait of 1 second we still got ex!:'+ex,logTag);
		    		replyfunc(octoErrors.FLASH_BP_NO_CALLBACK);
		    	}
			});
    	}
	};
    if(octoUtil.writeInNewDiv(html,logTag)){
		
		window[timeoutfunctionName]=function(){
			octolog.info('Timeout has been reached and we had no answer from flash -- ',logTag);
			window[initfunctionName]=function(){
				octolog.info('Flash answer was inited after timeout. ',logTag);
			};
			window[replyfunctionName]=function(intResult){
				octolog.info('Flash answer got after timeout: '+intResult,logTag);
			};
			replyfunc(octoErrors.FLASH_BP_TIMEOUT);
		};
		setTimeout("window."+timeoutfunctionName+"();",4500);
    }else{
		octolog.info('Could not write to div octopv_flashOctoIsRunningTesterDiv',logTag);
		replyfunc(octoErrors.FLASH_BP_DIV_ERROR); 
    }
}





function octopv_forceSuaUpdateIfNeeded(updatelink, okSuaVersion, replyFunction){
	octolog.info("Function called. updatelink: "+updatelink+" sua:"+okSuaVersion);
	
	octoGetSuaVersion(function(intStatus, stringVersion){
		if(intStatus==0){
			var ver = stringVersion;
			var doUpdate = false;
	   		if (ver.Length == okSuaVersion.Length) {
			    	doUpdate = ver < okSuaVersion; 
		    } else {
    			doUpdate = ver.Length < okSuaVersion.Length;
    		}
    		if(doUpdate){
    			octolog.info("Doing sua update. Current ver is "+ver+", marker is "+okSuaVersion);
    			octoGetPlayLink(updatelink, function(intStatus2,playlink){
    				if(intStatus2<0){
    					replyFunction(intStatus2);
    				}else{
    					
						octoUtil.insertInvisibleIframe(playlink);
						window.octopv_forceSuaUpdateIfNeededLoopReply=replyFunction;
						setTimeout("octopv_forceSuaUpdateIfNeededLoop();",3000);
    				}
    			}, false);
    		}else{
				replyFunction(0);
    		}
		}else{
			replyFunction(intStatus);
		}
	}, false);
}

window.octopv_forceSuaUpdateIfNeededLoopReply=null;
function octopv_forceSuaUpdateIfNeededLoop(){
	octolog.info("calling after wait.");
	octoGetPluginStatus(function(intStatus){
		if(intStatus<0){
			octopv_forceSuaUpdateIfNeededLoopReply(intStatus);
		}else{
			octopv_forceSuaUpdateIfNeededLoopReply(1);
		}
	}, false);
}





function octopv_launchByProtocol(callback,timeout){
	try{
		var name = "octopv_launchByProtocolFrame";
		var e = document.getElementById(name);
		if(e==null){
			e = document.createElement("iframe");
			e.id=name;
			e.name=name;
			e.width=0;
			e.height=0;
			e.style.display = "none";
			e.src="OCTOSHAPE:";
			document.body.insertBefore(e,document.body.firstChild);
		}else{
			e.src="OCTOSHAPE:";
		}
		if(typeof(callback)=='function'){
			var to = (typeof(timeout)=='number')?timeout:3000;
			octolog.info("After launch by protocol we wait for "+to+" milli-secs before returning");
			octopv_setTimeoutFunction(to, function(){
				callback(octoErrors.PROTOCAL_LAUNCH_AFTER);
			});
		}
	}catch(ex){
		octolog.warning("Exception "+ex);
		if(typeof(callback)=='function'){
			callback(octoErrors.PROTOCAL_LAUNCH_ERROR);
		}
	}
}





function octopv_ConstructAppletInstall(){
	this._logTag=null;
	this.installCompleted=null;
	this.installCompletedNew=false;
	this.progress=function(str){};
	this.waitFinishedCount=0;

	this.appletCallback=function(result){
		octolog.info("applet finished install (1): "+result,this._logTag);
		var status=octoErrors.INSTALL_APPLET_JS;
		var res = 0;
		try{
			status = parseInt(result);
			if(status>=0){
				octopv_settings.setLaunchMethodOk(octoConfig.ID_SIGNED_APPLET);
				res=status;
				status=0;
			}else{
				switch(status){
					case -5: status=octoErrors.INSTALL_APPLET_EXECUTION; 	break;
					case -4: status=octoErrors.INSTALL_APPLET_NO_FILE;		break;
					case -3: status=octoErrors.INSTALL_APPLET_SECURITY;		break;
					case -2: status=octoErrors.INSTALL_APPLET_EULA_REJECT;	break;
					default: status=octoErrors.INSTALL_APPLET_UNKNOWN;		break;
				}
			}
			octolog.info("applet install result converted to: "+status,this._logTag);
		}catch(ex){ 
			octolog.warning('JavaScript error (result was '+status+': '+ex.message,this._logTag);
		}
		if(this.installCompleted!=null && this.installCompletedNew){
			this.installCompletedNew=false;
			octolog.info("calling install completed with status: "+status,this._logTag);
			this.installCompleted(status,res);
		}else{
			var logStr = "Got reply from applet, but could not call onComplete. ";
			octolog.info(logStr+"Type: "+typeof(this.installCompleted)+" New:"+this.installCompletedNew,
					this._logTag);
		}
	};

	
	this.doInstall=function(indiv, onComplete, progressFunction){
		if(typeof(onComplete)=='function'){
			this.installCompleted=onComplete;
			this.installCompletedNew=true;
		}
		
		if(typeof(progressFunction) == 'function'){
			this.progress=progressFunction;
		}else{
			this.progress=function(str){};
		}
		var html='';
		var installJar = octoConfig.getPath(octoConfig.ID_INSTALL_APPLET);
		var installCode = octoConfig.getCodePath(octoConfig.ID_INSTALL_APPLET);
		
		if(navigator.userAgent.toLowerCase().indexOf("msie") != -1){
			
			html += '<OBJECT NAME="octopv_applet"';
		  	html += 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
			html += 'width="1" height="1"> ';
			html += '<PARAM NAME="code" value="'+installCode+'"> ';
			html += '<PARAM NAME="archive" VALUE="'+installJar+'">';
		  	html += '<PARAM NAME="mayscript" VALUE="true">';
		  	html += '<PARAM NAME="NAME" VALUE="'+octoConfig.appletDisplayName+'">';
		  	if(arguments.length == 4){
				html += '<PARAM name="'+param1+'" VALUE="'+value1+'"/>';
			}
		  	html += octolog.appletDebugParams(true);
			html += '</OBJECT> ';
		}else{
			
			html += '<embed code="'+installCode+'" '; 
			html += 'NAME="'+octoConfig.appletDisplayName+'" ';
			html += 'width="1" height="1" type="application/x-java-applet;version=1.1" ';
			html += 'pluginspage="http://java.sun.com/javase/downloads/" ';
			html += 'archive="'+installJar+'" ';
	        html += 'scriptable="true" ';
	        html += 'mayscript="true" ';
			html += 'callbackstring="install" ';
		  	html += octolog.appletDebugParams(false);
			html += '/>';
		}
		octolog.info("inserting install-jar from: "+installJar,this._logTag);
		octoUtil.writeToDiv(indiv, html,this._logTag);
	}
}

var octopv_AppletInstallObject = new octopv_ConstructAppletInstall();



function octopv_appletProgress(message){
	octolog.info("applet install progress: "+message+"", arguments.callee);
	octopv_AppletInstallObject.progress(message);
}


function octopv_installAppletFinishedInstall(result){
	octopv_AppletInstallObject.appletCallback(result);
};

function octopv_ConstructInstallApplet(replyKind){
	this._replyKind=replyKind;
	this.attemptId=octoConfig.ID_INSTALL_APPLET;
	this._logTag=this.attemptId;
	this.canAnswer=function(){
		return 0;
	};
	var me=this;
	this.start=function(onError,onSucces){
		var div3="octopv_appletDiv3";
		octoUtil.createNewDiv(div3);
		octopv_AppletInstallObject._logTag=this._logTag;
		octopv_AppletInstallObject.doInstall(div3, function(status,port){
			octolog.info('applet install answer: '+status,me._logTag);
			if(octopv_abortAutoLaunch){
				octolog.info('NB: octopv_abortAutoLaunch false after applet install run',me._logTag);
			}
			if(status!=0){
				onError(status);
			}else{
				octopv_settings.setLaunchMethodOk(octoConfig.ID_SIGNED_APPLET);
				if(octoLaunchKinds.START_UP==me._replyKind){
					onSucces();
				}else if(octoLaunchKinds.GET_CONNECT_URL==me._replyKind && port>0){
					onSucces('127.0.0.1:'+port);
				}else{
					onError(octoErrors.INSTALL_APPLET_OK);
				}
			}
		}, function(str){
			octolog.info('Installing: '+str,me._logTag);
		});
	};
}



function octopv_ConstructShowEula(callToShowFunction){
	this.runonce = true;
	this.attemptId=octoConfig.ID_FLASH_EULA;
	this._logTag=this.attemptId;
	
	this.uniqueId=octopv_getJsUniqueId(); 
	this._containerid="octopv_topEulaDiv"+this.uniqueId;
	this._callbackToShowFunction = octoUtil.getFirstOfType('function',callToShowFunction);
	
	
	this.callbackFuncName = "octopv_feula_cb"+this.uniqueId;
	this.keepAliveFuncName = "octopv_feula_ka"+this.uniqueId;
	this.clickToTextFuncName = "octopv_feula_ctt"+this.uniqueId;

	this._swfName = 'octopveula';
	this._inserted=false;
	
	this.canAnswer=function(){
		if(octoConfig.hasDisabled(this.attemptId)) return octoErrors.FLASH_EULA_DISABLED;
		if(octoUtil.flashOk()) return 0;
		return octoErrors.FLASH_EULA_NO_FLASH;
	};
	
	this._insert=function(){
		var container = document.getElementById(this._containerid);
		octolog.info('getting container div: '+(container!=null),this._logTag);
		if(container==null){
			container=document.createElement("div");
			container.id=this._containerid;
			container.style.position='absolute';
			container.style.zIndex='9999';
			container.style.width='100%';
			container.style.height='100%';
			container.style.top='0px';
			container.style.left='0px';
			document.body.insertBefore(container,document.body.firstChild);
			octolog.info('after insert of container div: '+(container!=null),this._logTag);
		}
		if(container == null){
			return octoErrors.FLASH_EULA_NO_FLASH;
		}

		var flashVars = 'containerId='+this._containerid;
		flashVars+='&callbackFunc='+this.callbackFuncName;
		flashVars+='&clickToTextEulaFunc='+this.clickToTextFuncName;
		flashVars+='&keepAliveFunc='+this.keepAliveFuncName;
		flashVars+='&keepAliveIterim='+octoConfig.eulaKeepAliveInterim;
		
		var path = octoConfig.getPath(octoConfig.ID_FLASH_EULA);
		if(path==null){
			return octoErrors.PATH_NOT_SET;
		}

	  	var html  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	    html += ' id="'+this._swfName+'" width="100%" height="100%"';
	    html += ' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">';
	    html += ' <param name="movie" value="'+path+'" />';
	    html += ' <param name="wmode" value="transparent" />';
	    html += ' <param name="AllowScriptAccess" value="always" />';
	    html += ' <param name="FlashVars" value="'+flashVars+'" />';
	    
	    html += ' <embed src="'+path+'"';
	    html += ' width="100%" height="100%" name="'+this._swfName+'"';
	    html += ' AllowScriptAccess="always"';
	    html += ' play="true" loop="false" wmode="transparent"';
	    html += ' type="application/x-shockwave-flash" FlashVars="'+flashVars+'"';
	    html += ' pluginspage="http://www.adobe.com/go/getflashplayer">';
	    html += ' </embed></object>';

		octolog.info('Showing eula from:' +path,this._logTag);
	    container.innerHTML = html;
	    return 0;
	}
	
	var me=this;
	
	this.start=function(onFinish, paramNotUsed, onUpdate){
		var can = this.canAnswer();
		if(can!=0){
			onFinish(can);
			return;
		}
		
		window[this.callbackFuncName]=function(status){
			octolog.info('Reply from Eula: '+octoErrors.print(status),me._logTag);
			switch(status){
			case 0: onFinish(octoErrors.FLASH_EULA_ACCEPT); break;
			case octoErrors.FLASH_EULA_RETURN_REJECTED: onFinish(octoErrors.FLASH_EULA_REJECT);	break;
			default: onFinish(status);
			}
		};
		
		
		window.octopve_callbackFunc = window[this.callbackFuncName];
		
		window[this.keepAliveFuncName]=function(){
			octolog.info('Got keep alive from flash-eula.',me._logTag);
			onUpdate(false);
		};

		window[this.clickToTextFuncName]=function(){
			octolog.info('User clicked to see eula text.',me._logTag);
			octopv_settings.updateCounter('texteulaclicked');
		};
		if(this._callbackToShowFunction==null){
			can = this._insert();
		}else{
			can = this._callbackToShowFunction();
		}
		if(can==0 || typeof(can)=='undefined'){
			this._inserted=true;
		}else{
			onFinish(can);
		}
	};
	
	this.cleanup=function(){
		if(!this._inserted){
			octolog.info('No cleanup since not inserted.',this._logTag);
			return;
		}
		if(this._callbackToShowFunction!=null){
			octolog.info('No cleanup in JavaScript since eula not inserted from here.',this._logTag);
			return;
		}
		var swf=octoUtil.getSwfObject(this._swfName);
		if(swf){
			try{
				octolog.info('Calling deleteCookie() on feula',this._logTag);
				swf.deleteCookie();
				octolog.info('Cleanup done. ',this._logTag);
			}catch(ex){
				octolog.warning('No cleanup since error when calling swf function: '+ex,this._logTag);
			}
		}else{
			octolog.info('No cleanup since we could not get handle on swf.',this._logTag);
		}
	};
}






var octopvCAB_topobject = new Object();
octopvCAB_topobject.onComplete=null;
octopvCAB_topobject.timeout=0;

function octopv_doCabInstall(indiv, timeout, onComplete, logTag){
	var file = octoConfig.getPath(octoConfig.ID_CAB_INTALL);
	if(file==null){
		octolog.info("Not inserting cab file, since it was not set. ",logTag);
		onComplete(octoErrors.PATH_NOT_SET);
		return;
	}
	octopvCAB_topobject.onComplete = onComplete;
	octopvCAB_topobject.timeout=timeout;
	var html = '<OBJECT onreadystatechange="javascript:octopv_cabReadychange();"';
	html += ' CODEBASE="'+file+'#version=1.0.0.0"';
	html += ' id="OctoshapeCabInstaller" CLASSID="CLSID:7D4733C0-C43B-4A81-AF43-F9B20D1F8348"';
	html += ' width="0" height="0" >';
	html += '</OBJECT>';
	octolog.info("Inserting cab file from "+file,logTag);
	octoUtil.writeToDiv(indiv, html,logTag);
}

function octopv_cabReadychange(dontWait){
	try{
		var state = document.all["OctoshapeCabInstaller"].readyState;
		octolog.info("Ready state changed to "+state);
		if(state==4){
			if(octopvCAB_topobject.onComplete!=null){
				setTimeout("octopvCAB_topobject.onComplete(0);",octopvCAB_topobject.timeout);
			}
		}
	}catch(ex){
		if(typeof dontWait == 'boolean' && !dontWait){
			octolog.info("Ready state not defined: "+ex);
			
			if(octopvCAB_topobject.onComplete!=null){
				octopvCAB_topobject.onComplete(octoErrors.CAB_READY_STATE);
			}
		}else{
			octolog.info("Ready state not defined: "+ex+" trying to wait a little ... ");
			setTimeout("octopv_cabReadychange(true);",500);
		}
	}
}

function octopv_ConstructCabInstall(timeout, eula){
	this._timeout=timeout;
	this._eula=eula;
	this.attemptId=octoConfig.ID_CAB_INTALL;
	this._logTag=this.attemptId;
	this.canAnswer=function cabInstallCan(){
		if(octoConfig.hasDisabled(this.attemptId)){
			octolog.info("Can not do cab install since it it disabled.",this._logTag);
			return octoErrors.CAB_DISABLED;
		}
		if(!octoUtil.isWindows()){
			
			octolog.info("Can not do cab install since OS is not windows.",this._logTag);
			return octoErrors.CAB_ONLY_ON_WIN_IE;
		}
		if(!octoUtil.isIE()){
			
			octolog.info("Can not do cab install since browser is not ie.",this._logTag);
			return octoErrors.CAB_ONLY_ON_WIN_IE;
		}
		
		if(octoUtil.isVista()){
			
			octolog.info("Can not do cab install since we are on vista. ",this._logTag);
			
			return octoErrors.CAB_NOT_ON_VISTA; 
		}
		return 0;
	};
	var me=this;
	this.start=function(onFinish){
		var can = this.canAnswer();
		if(can!=0){
			onFinish(can);
			return;
		}
		var divCab="octopv_topCabDiv";
		octoUtil.createNewDiv2(divCab);
		this._eula.start(function(err1){
			if(err1!=octoErrors.FLASH_EULA_REJECT){
				octopv_doCabInstall(divCab, me._timeout, function(err){
					
					if(err==0){
						octolog.info('Cab finished, but was it successful?.',me._logTag);
						onFinish(octoErrors.CAB_AFTER_INSTALL);
					}else{
						onFinish(err);
					}
				},this._logTag);
			}else{
				onFinish(err1);
			}
		});
	};
}



function octopv_logInitFromQueryString(){
	octolog.info('onload window event','initlog');
	octolog.info(null);
}


function octopv_ConstructDebug(){
	this._debugDivID="octopv_logDiv";
	this._arr=new Array();
	this._errors=new Array();
	var qscookieclear = octoUtil.isQueryStringValue('octoshapecookieclear','true');
	this._debugSize = octoUtil.getQueryStringValue('octoshapelogsize',null); 
	var debugType = octoUtil.getQueryStringValue('octoshapelog','nolog');
	
	this.shouldLog=false;
	this.shouldDoEvent=false;
	this.shouldDoInfo=false;
	this.shouldDoDebug=false;
	switch(debugType){
	case "debug":
		this.shouldDoDebug=true;
	case "info":
		this.shouldDoInfo=true;
	case "event":
		this.shouldDoEvent=true;
		this.shouldLog=true;
	default:
	}
	
	this._extraSettings = new Object();
	this._doOutput=true;
	this._initMillis=new Date().getTime();
	
	this.init=function(){
		if(this.shouldLog){
			if(typeof (window.addEventListener) != 'undefined'){
				window.addEventListener("load", octopv_logInitFromQueryString, false);
			}else if (typeof (document.addEventListener) != 'undefined'){
				document.addEventListener("load", octopv_logInitFromQueryString, false);
			}else if(typeof (window.attachEvent) != 'undefined'){
				window.attachEvent("onload", octopv_logInitFromQueryString, false);
			}else{
				var alertStr = 'Octoshape js debug could not set eventlistener\n';
				alert(alertStr+'Your query-string has octoshapejsdebug=true set');
			}
		}
		if(qscookieclear){
			octopv_settings.clear();
		}
	}
	
	this.addTopSetting=function(name,value){
		this._extraSettings[name] = value;
	}
	
	
	this._getFunctionName=function(func, anonymous){
		var funcStr = func.toString();
		var a1 = funcStr.toLowerCase().indexOf('function');
		var b1 = funcStr.indexOf("(");
		var a=a1==0?8:0;
		var b=b1>0?b1:funcStr.length;
		funcStr = funcStr.substring(a,b);
		funcStr = funcStr.replace(/ /, "");
		if(funcStr.length==0){
			if(typeof(anonymous)=='undefined'){
				funcStr="anonymous";
			}else{
				funcStr=anonymous;
			}
		}else{
			var a2 = funcStr.lastIndexOf('_');
			if(a2>0){
				funcStr = funcStr.substring(a2+1);
			}
		}
		return funcStr;
	};
	
	this.debug=function(str, debugName){
		if(this.shouldDoDebug){
			this._log(str,debugName, 'orange');
		}
	};
	
	this.info=function(str, debugName){
		if(this.shouldDoInfo){
			this._log(str,debugName, 'black');
		}
	};
	
	this.event=function(str, debugName){
		if(this.shouldDoEvent){
			this._log(str,debugName,'blue');
		}
	};
	
	
	this.warning=function(str, debugName){
		if(this.shouldDoInfo){
			this._log(str,debugName,'red');
		}
	};

	this.error=function(str, debugName){
		this._errors.push(this._getLineLog('',debugName,str));
		this.warning('Setting error: '+str, debugName);
	};
	
	this.isEnabled=function(){
		return this.shouldLog && !octoConfig.hasDisabled(octoConfig.ID_LOGGING);
	}

	this.isShowing=function(){
		return (this._getDiv()!=null);
	}

	
	this._getDiv=function(){
		if(!this.isEnabled()) return false;
		var	div = document.getElementById(this._debugDivID);
		if(div){
			return div;
		}
		
		if((!div) && this.shouldLog){
			
			var oDiv = document.createElement("div");
			oDiv.id=this._debugDivID;
			oDiv.style.backgroundColor = "white";
			if(this._debugSize!=null){
				var pi = parseInt(this._debugSize);
				if(!isNaN(pi)){
					oDiv.style.height=pi+"px";
					oDiv.style.overflow="auto";
				}
			}
			document.body.appendChild(oDiv);
			return oDiv;
		} 
		return null;
	}

	this.appletDebugParams=function(paramParams){
		if(this.isShowing()){
			if(paramParams){
				return '<param name="display" value="debug_console_div"/>';
			}else{
				return 'display="debug_console_div" ';
			}
		}else{
			 return '';
		}
	}

	this._hasProperty=function(obj, element){
		for (var i in obj){ 
			if(obj[i].toLowerCase() == element.toLowerCase()){
				return true;
			}
		}
		return false;
	}

	this.logObjectProperty=function(objectName, obj, prop){
		this.log("Object "+objectName+" has property "+prop+": "+this._hasProperty(obj, prop), 
				"JS-Object");
	}

	this.logObject=function(message, obj){
		var result = "[";
		var delim = "";
		for (var i in obj){ 
			result += (delim + i);
			delim = ",";
		}
		result+="]";
		this.log(message+": "+result, "JS-Object");
	};

	this._getLineLog=function(str1,str2,str3,color){
		if(typeof(color)=='string'){
			return this._getLine('color:'+color+';', str1, str2, str3);
		}else{
			return this._getLine(null, str1, str2, str3);
		}
	}

	this._getLineTop=function(str2,str3){
		return this._getLine(null, '', str2, str3);
	}

	this._getLine=function(style,str1,str2,str3){
		var str3b = str3;
		str3b = str3b.replace(/</g, "&lt;");
		str3b = str3b.replace(/>/g, "&gt;");
		var styleStr = style!=null?' STYLE="'+style+'" ':"";
		return ('<TR '+styleStr+'><TD ALIGN="right">'+str1+'<TD>'+str2+'<TD>|<TD colspan=2>'+str3b+'</TR>');
	}
	
	
	this._log = function(str, debugName, color){
		if(!this.isEnabled()) return false;
		try{
			var name = null;
			if(typeof(debugName)=='string'){
				name = debugName;
			}
			if(name==null){
				var func = arguments.callee.caller.caller;
				if(typeof(func)=='function'){
					name = this._getFunctionName(func,null);
				}
			}
			if(name==null){
				name = 'unknown';
			}
			var millis = (new Date().getTime()) - this._initMillis;
			if(str!=null){
				this._arr.push(this._getLineLog(millis,name,str,color));
			}
			if(!this._doOutput) return false;
			var	div = this._getDiv();
			if(div){
				this._doOutput=false;
				var font = 'font-family:monospace; font-size:9pt; ';
				var color = 'background-color:white; color:black; ';
				var theString = '<div STYLE="'+color+font+'"><table>';

				theString+=("<TR STYLE=\"background-color:#B0B0B0; font-weight: bold;\">");
				theString+=("<TD colspan=5>OCTOSHAPE JAVASCRIPT DEBUG OUTPUT</TR>");
				
				theString+=this._getLine('background-color:#D8D8D8;',false,'','SETTINGS','');
				theString+=this._getLineTop('version', 'Octoshape JavaScript version: '+octoUtil.getOctoVersion());
				
				theString+=this._getLineTop('user-agent',navigator.userAgent);

				if(octoConfig.usingEulaInPlayer){
					theString+=this._getLineTop('eula','EULA is shown inside the player. ');
				}else{
					theString+=this._getLineTop('eula',
							'EULA is shown in full window (outside player).');
				}

				for (var e in this._extraSettings){ 
					theString+=this._getLineTop(e,this._extraSettings[e]);
				}
				
				theString+=this._getLineTop('path','Using the base path: '+octoConfig.basePath);

				var me=this;
				octoConfig.loopDisables(function(id,disabled){
					theString+=me._getLineTop('disabled',id+' is disabled: '+disabled);
				});
				
				var cookieArr = octopv_settings.getAll();
				for(var i3=0;i3<cookieArr.length;i3++){
					theString+=this._getLineTop('cookies','Cookie setting: '+cookieArr[i3]);
				}

				if(this._errors.length>0){
					theString+=this._getLine('background-color:#FF9999;',false,'','CONFIGURATION ERRORS','size: '+this._errors.length);
					for(var i=0;i<this._errors.length;i++){
						theString+=this._errors[i];
					}
				}
				
				theString+=this._getLine('background-color:#D8D8D8;',false,'','LOGS','size: '+this._arr.length);
				for(var i=0;i<this._arr.length;i++){
					theString+=this._arr[i];
				}
				theString+="</table></div>";
				div.innerHTML = theString;
				this._doOutput=true;
				return true;
			}
		}catch (exception) {}
		return false;
	};
}
var octolog = new octopv_ConstructDebug();
octolog.init();


function octopv_debug(str1,str2){
	octolog.debug(str1,str2);
}
function octopv_log(str1,str2){
	octolog.info(str1,str2);
}
function octopv_error(str1,str2){
	octolog.error(str1,str2);
}
function octopv_warning(str1,str2){
	octolog.warning(str1,str2);
}
function octopv_setting(str1,str2){
	octolog.addTopSetting(str1,str2);
}
function octopv_event(str1,str2){
	octolog.event(str1,str2);
} /* SET BY BUILD SYSTEM */
octoConfig.setBasePath('http://www.octoshape.com/autolaunchers/');
octoConfig.setFile(octoConfig.ID_INSTALL_APPLET,'octosetupOCTO-201-1004270-silent-osx.jar','osx');
octoConfig.setCode(octoConfig.ID_INSTALL_APPLET, 'octoshape.applets.OctoInstallAppletMac.class', 'osx');
octoConfig.setFile(octoConfig.ID_INSTALL_APPLET,'octosetupOCTO-201-1004270-silent-win32_i386_ansi.jar','win');
octoConfig.setCode(octoConfig.ID_INSTALL_APPLET, 'octoshape.applets.OctoInstallApplet.class', 'win');
octoConfig.setFile(octoConfig.ID_CAB_INTALL, 'octosetupOCTO-201-1004270-silent-win32_i386_ansi.cab','win');
octopv_manualInstallerWin='octosetupOCTO-201-1004270-win32_i386_ansi.exe';
octopv_manualInstallerOSX='octosetupOCTO-201-1004270-osx.dmg';
octopv_manualInstallerDef='http://www.octoshape.com/?page=get_octo&variant=OCTO';
octoConfig.setFile(octoConfig.ID_PRELOAD_APPLET,'octoinitapplet-0906170.jar');
octoConfig.setFile(octoConfig.ID_TEST_APPLET,'octoinitapplet-0906170.jar');
octoConfig.setCode(octoConfig.ID_PRELOAD_APPLET, 'octoshape.applets.init.OctoTestApplet');
octoConfig.setCode(octoConfig.ID_TEST_APPLET, 'octoshape.applets.init.OctoTestApplet');
octoConfig.setFile(octoConfig.ID_LAUNCH_APPLET,'octolauncherapplet-1004121.jar','win');
octoConfig.setCode(octoConfig.ID_LAUNCH_APPLET, 'octoshape.applets.OctoPluginLauncherApplet', 'win');
var octopv_version='OCTO-2011004270';
octoConfig.appletDisplayName='Octoshape Grid Delivery Enhancement';
octoConfig.setFile(octoConfig.ID_FLASH_EULA,'octoeula-OCTO-2011004270.swf');
octoConfig.usingEulaInPlayer=true;
octoConfig.showEulaOnManualInstall=true;
octoConfig.setFile(octoConfig.ID_FLASH_BP,'octofbpMain-1004270.swf');
octoConfig.disable(octoConfig.ID_STAT);
var octopv_folder='OctoAutoLaunch-OCTO-2011004270';
function octopv_isInited(){  return octopv_version; };
var octopv_asosaEntryObj = octoUtil.getSwfObject(window.octopv_asosaEntry);
if(typeof(octopv_asosaEntryObj)!='undefined') octopv_asosaEntryObj.javaScriptLoaded();
