//
//
//		LIVINGACTOR INSTALL FOR NETSCAPE LIBRARY VERSION 1.6.1.0
//
//				copyrights La Cantoche Production
//					all rights reserved
//
//
//


var SpionTimeDiff = 0;
var xpiUrl = "http://localhost/testnewinstall/LA-mozactivex-ff-10.xpi";
if(NAV6)//Moz_InitLA_Auto
{
	try{
			version = window.document.LIVINGACTORPLUGIN.Version;
			if(DEBUGMODE){ alert("Moz_InitLA_Auto : version="+version+">=LA_PluginVersion="+LA_PluginVersion);}
			if(version >= LA_PluginVersion) {
				if(window.document.LIVINGACTORPLUGIN.ClientData("IsReloading") == "True") {
					alert("reloading");
					LA_ACTOR_URL = window.document.LIVINGACTORPLUGIN.ClientData("ActorURL");
					LA_UserDefined = window.document.LIVINGACTORPLUGIN.ClientData("UserValue");
					LA_GenericPlugin = window.document.LIVINGACTORPLUGIN;
					ActorLoading();
				}
			}
	}
	catch(e){
		//alert("Erreur"+e);
		if(DEBUGMODE){ alert("Moz_InitLA_Auto:no activex"+e);}
	}
}

function Moz_CheckPlugin(){
if(DEBUGMODE){ alert("Moz_CheckPlugin:enter");}

	navigator.plugins.refresh(true)	;
	if( navigator.mimeTypes["application/x-oleobject"])
	{
		if(DEBUGMODE){ alert("Moz_CheckPlugin:found the firefox plugin");}
		return 1;
	}
	else
	{
		if(DEBUGMODE){ alert("Moz_CheckPlugin:didnt find the firefox plugin");}
		return 0;
	}
}

function Moz_CheckActiveX(){
if(DEBUGMODE){ alert("Moz_CheckActiveX:enter");}
	try {
		version = window.document.LIVINGACTORPLUGIN.Version;
	    }
	    catch(e){
		    if(DEBUGMODE){ alert("Moz_CheckActiveX:didnt find LA activex");}
		    return ERRNOINST;
	    }
	    try{
		if(DEBUGMODE){ alert("Moz_CheckActiveX: version="+version);}
		if(version >= LA_PluginVersion){
			LA_GenericPlugin = window.document.LIVINGACTORPLUGIN;
			return ERRNO;
		}
		else{
			if(DEBUGMODE) alert("Moz_CheckActiveX: QUIT");
			window.document.LIVINGACTORPLUGIN.LoadActor("fake.liv");
			window.document.LIVINGACTORPLUGIN.Quit();
			return ERRUP;
		}
	    }
	    catch(e){ // this catch is here cause when we quit, the plugin doesnt like it.
		    return ERRUP;
	    }
}

function Moz_installPlugin() {
	xpi={'Mozilla Firefox 1.0 ActiveX Plug-in':xpiUrl};
	InstallTrigger.install(xpi); 
} 

/*function Moz_DownloadActiveXInstaller(){
	if(DEBUGMODE){ alert("Moz_DownloadActiveXInstaller:enter");}	
	var range = document.createRange();
	if (range.createContextualFragment) {
	   range.selectNodeContents(document.body);
	   var docFrag = range.createContextualFragment("<Object type='application/x-oleobject' ClassID='CLSID:DF4F4ED9-420B-4F40-AEE6-A620460306E7' ID='AX_INSTALLER'  Width=0 Height=0  > </Object>");
	   document.body.appendChild(docFrag);
	   //IncSpionTimer(); //we start our timer to watch the diff beetween now and a possible error in Moz_LoopWaitingInstallerReady
	}
		Moz_LoopWaitingInstallerReady();
}*/

function Moz_LoopWaitingInstallerReady(){
	try {
		if(DEBUGMODE){ alert("Moz_DownloadActiveXInstaller:enter");}	
		var range = document.createRange();
		if (range.createContextualFragment) {
		   range.selectNodeContents(document.body);
		   var docFrag = range.createContextualFragment("<Object type='application/x-oleobject' ClassID='CLSID:DF4F4ED9-420B-4F40-AEE6-A620460306E7' ID='AX_INSTALLER'  Width=0 Height=0  > </Object>");
		   document.body.appendChild(docFrag);
		   //IncSpionTimer(); //we start our timer to watch the diff beetween now and a possible error in Moz_LoopWaitingInstallerReady
		}
		error = document.AX_INSTALLER.Error;
		//if(DEBUGMODELOOP){ alert( "Moz_LoopWaitingInstallerReady: error =" +document.AX_INSTALLER.Error);}
		if(DEBUGMODELOOP) alert("Moz_LoopWaitingInstallerReady: error="+error);
		
		if (error==undefined){
			if(DEBUGMODELOOP){ alert( "Moz_LoopWaitingInstallerReady: error  is undefined" );}
			//if(SpionTimeDiff<10){
				// we went allmost immediatly here, so the user didnt have time to say no.. we must don't have right
				//if(DEBUGMODE){ alert( "Moz_LoopWaitingInstallerReady: the installation couldnt be processed. we are sorry");}
			ShowDiv();
			//}
			/*else {
				if(DEBUGMODE){ alert( "Moz_LoopWaitingInstallerReady: user say no.");}
				// we spent time before comming here... so there's chance than the user said no.	
			}*/
		}
		
		else if(error==0){
			document.AX_INSTALLER.Install();
			Moz_LoopWaitingLAActiveXReady();
		}
		/*else if(error>=0){
			if(DEBUGMODELOOP){ alert( "Moz_LoopWaitingInstallerReady: error =" +document.AX_INSTALLER.Error);}
			setTimeout("Moz_LoopWaitingInstallerReady()",300);
		}*/
		
	}
	catch(e){
		alert("we had a problem to register our installer, sorry");
		//setTimeout("Moz_LoopWaitingInstallerReady()",300);
	}	
}

function Moz_LoopWaitingLAActiveXReady(){
	ready=document.AX_INSTALLER.HasFinished;
	if(DEBUGMODELOOP){ alert( "Moz_LoopWaitingLAActiveXReady:" +ready);}
	if(ready) {
		try{
				var range = document.createRange();
				if (range.createContextualFragment) {
				   range.selectNodeContents(document.body);
				   var docFrag = range.createContextualFragment("<Object type='application/x-oleobject' ClassID='CLSID:B8A23E08-0B26-4348-AA96-33395A51DDD9'  ID='AX_PLUGIN'  Width=0 Height=0  > </Object>");
				   document.body.appendChild(docFrag);
				}
				document.AX_PLUGIN.ClientData("IsReloading") = "True" ;
				document.AX_PLUGIN.ClientData("ActorURL") = LA_ACTOR_URL ;
				document.AX_PLUGIN.ClientData("UserValue") = LA_UserDefined ;
				top.document.location.href = top.document.location;
		}
		catch(e){
			if(DEBUGMODELOOP){ alert( "Moz_LoopWaitingLAActiveXReady: pb with creation of activex AFTER installation");}
			//ManageError(E_CANNOT_FIND_PLUGIN_VERSION_REQUESTED);
		}
	}
	else{
		setTimeout("Moz_LoopWaitingLAActiveXReady()",300);
	}
}

/*function IncSpionTimer(){
	SpionTimeDiff+= 1;
	if(SpionTimeDiff<100){
		setTimeout("IncSpionTimer()",500);
	}
}*/

