var winWait = 0;
var winClose = false;
var nCount = 0;
var checkLoaded = -1;
var maxTries = 1;
var tryInterval = 5000;
// 0 : Applet lanc?e OK
// 1 : Applet lanc?e avec une mauvaise version
// 2 : Applet lanc?e sans droit d'ex?cution d'applet sign?e
// 3 : Applet non lanc?e (?tat initial)
var appletStatus = 3;

function OpenWaitWindow ()
{
/*
    if( winClose == false )
    {
        winParams = "toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=0, copyhistory=0, menuBar=0, width=500, height=130";
        winWait = window.open( "/attente.html", "attente", winParams );
        window.status = "Chargement en cours...";
    }
 */
}

function CloseWaitWindow ()
{
/*
    if( winWait != 0 )
    {
        winWait.close();
        window.status = "Fin du chargement.";
    }

    winClose = true;
    */
}

function signalAppletStarted(newAppletStatus)
{
	appletStatus = newAppletStatus;
	if (appletStatus != 0)
	{
		openWithoutChecking(appletStatus);
	}
	else
	{
		successOpen();
	}
}

function successOpen()
{
	top.data.document.formdata.nothing.value="0";
	if ( !(top.milieu.up.openSommaire === undefined) ) {top.milieu.up.openSommaire();}
}

function CheckAdSignerOpened()
{
	var localadsigner = null;
//alert("appletStatus "+appletStatus);
// Les navigateurs Mozilla sous Mac ne permettent pas l'appel javascript -> java. 
// On consid?re que l'applet s'est lanc?e. 
// Le lien manuel permettra d'ouvrir le texte si l'applet ne s'ouvre pas.

// 0 : Applet lanc?e OK
// 1 : Applet lanc?e avec une mauvaise version
// 2 : Applet lanc?e sans droit d'ex?cution d'applet sign?e
// 3 : Applet non lanc?e (?tat initial)
	if (appletStatus != 3)
	{
		return true;
	}

//	if (navigator.platform == 'MacPPC')
//	{
//		return true;
//}
	nCount++;
	window.onerror = restartCheckAdSignerOpened;
	
	/*if( document.adsigner )
    	localadsigner = document.adsigner;
    	
	else if( adsigner )
    	localadsigner = adsigner;
	else if( document.applets && document.applets.length > 0 && document.applets[0] )
    	localadsigner = document.applets[0];*/
	
	if (localadsigner)
	{
		checkLoaded = localadsigner.checkLoaded();

		if (checkLoaded != 0)
		{
			openWithoutChecking(checkLoaded);
		}
    }
    else if( nCount <= maxTries )
    {
//alert (1);    	// Une erreur, pas de cr?ation de l ?l?ment Java
    	window.setTimeout('CheckAdSignerOpened()',tryInterval);
    }
    else
	{
//alert (2);
		openWithoutChecking(3);
	}
	return true;
}

function restartCheckAdSignerOpened()
{
	if( nCount < maxTries )
    {
//    alert (3);
    	// Une erreur, pas de cr?ation de l ?l?ment Java
    	window.setTimeout('CheckAdSignerOpened()',tryInterval);
    }
    else
	{
//	alert (4);
		openWithoutChecking(3);
	}
	return true;
}

function openWithoutChecking(checkLoaded)
{
	top.data.document.formdata.vTryApplet.value="0";
	top.data.document.formdata.vTryActiveX.value="0";
	top.data.document.formdata.nothing.value="1";
	
	top.milieu.cont.milieu.displayFailureImage();
    
	var url = "getpdf.php?fic="+fic;
	//alert(url);
	//window.open(url, "_blank");
	// Cas o? l'applet n'a pas la bonne version
//	if (checkLoaded == 1)
//	{
//		window.open(djo_aide_wrongversion, "aide", windowProperties);
//	}
	// Cas o? l'applet s'ex?cute mais sans droit d'applet sign?e
//	else if (checkLoaded == 2)
//	{
//		window.open(djo_aide_nopermissions, "aide", windowProperties);
//	}
	// Cas o? l'applet n'est pas lanc?e
//	else if (checkLoaded == 3)
//	{
//		window.open(djo_aide, "aide", windowProperties);
//	}
	
    return true;
	
}
