// pour IE4 qui ne connait pas la fonction document.getElementById
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

function img_jp2k(SourceFile, PictWidth, PictHeight,isHTM,isJPEG,coefiframe)
{

	var navName;
	var sourceJPG;

	//document.write ("fichier source=" + SourceFile);
	document.open();

	//sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
	if (jpg==1){
		sourceJPG = SourceFile.racine() + "/"+ SourceFile.name() + ".jpg";
	}else{

		//sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
		//cas du jp2: verifier si le plugin est installé ou pas
		sourceJPG = SourceFile.racine() + "/"+ SourceFile.name() + ".jp2";

		//TEST INSTALL PLUGIN
		mimetype = navigator.mimeTypes["image/jp2"];

		if (mimetype){
		
			plugin = mimetype.enabledPlugin;

			if (! plugin){//si pas de plugin
	
				sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
			}
		}else{	

			//si pas de plugin
			sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
		}
		//FIN TEST
	}//fin if jpg==1

	if (jpg==1)
	{

		document.write("<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>");
		return 0;
	}	

	nav = navigator.appName;

	if (navigator.userAgent.indexOf("Opera") != -1)
	{
		// Opera browser detected
		nav = "Opera Browser";
	}


	if ( nav == "Microsoft Internet Explorer"){
//document.write("here="+sourceJPG);	
//document.write("here SourceFile="+SourceFile);				
//document.write("IE" + sourceJPG);
//alert("isHTM=" + isHTM);
		if ((isJPEG) || ((isJPEG==-1)&& (isHTM==-1))){

			document.write("<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
			<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
			<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
			<param name='SRC' value='" + SourceFile + "'>\
			<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "' id='AutoNumber1' height='" + PictHeight + "'>\
		  	<tr>\
	    	<td width='" + PictWidth + "'>\
	      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
			</td>\
			<td>\
			</tr>\
			</table></object>");
		}else if (isHTM){

			//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
			//sourceHTML= sourceJPG.replace(".jpg",".html");	
			sourceHTML= sourceJPG.replace(".jpg",".htm");	

//alert("sourceHTML=" + sourceHTML);
			if (coefiframe==0){
				coefiframe=1;
			}

			document.write("<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
			<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
			<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
			<param name='SRC' value='" + SourceFile + "'>\
			<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
			</IFRAME>\
			</object>");

		}		
		
	}else{//cas de mozilla ou safari
	

//alert("plateforme=" + navigator.platform);
		//test si on est sous win32 ou mac os
		if (navigator.platform=="Win32"){
	
			mimetype = navigator.mimeTypes["image/jp2"];
		
			if (mimetype){
				plugin = mimetype.enabledPlugin;
				if (plugin){
					// Yes, so can we display with a plug-in?   
		  			document.write("<embed type='image/j2c' src='" + SourceFile + "' width='" + PictWidth + "' height='" + PictHeight + "' PLUGINSPAGE='http://www.mobilier-design-mdba.fr/plugin/download.php?file=setup_moz_plugin.exe' ></embed>");
		  		}else{   		
					if (isJPEG){//ajout aurelie pour le cas MAC qui ne sait pas afficher les jpg				
						document.write("<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>");				
					}else if (isHTM){
						//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
						//sourceHTML= sourceJPG.replace(".jpg",".html");	
						sourceHTML= sourceJPG.replace(".jpg",".htm");	
						if (coefiframe==0){
							coefiframe=1;
						}
						document.write("<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
						</IFRAME>");					
					}				
				}
			}else{   			
				//document.write("<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>");
				//	document.write("existe html="+isHTM);
				//document.write("<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>");
				if (isJPEG){//ajout aurelie pour le cas MAC qui ne sait pas afficher les jpg
					document.write("<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>");					
				}else if (isHTM){
					//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
					//sourceHTML= sourceJPG.replace(".jpg",".html");	
					sourceHTML= sourceJPG.replace(".jpg",".htm");	
					if (coefiframe==0){
						coefiframe=1;
					}
					document.write("<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
					</IFRAME>");
				}				
			}
		}else{//fin test de plateforme
			// si on est sou MAC OS même comportement que IE? voir si ça marche.....
//alert("MAC OS");
			/*if ((isJPEG) || ((isJPEG==-1)&& (isHTM==-1))){
				document.write("<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
				<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
				<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
				<param name='SRC' value='" + SourceFile + "'>\
				<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "' id='AutoNumber1' height='" + PictHeight + "'>\
			  	<tr>\
		    	<td width='" + PictWidth + "'>\
		      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
				</td>\
				<td>\
				</tr>\
				</table></object>");
			}else if (isHTM){*/
			    //alert("sourcejpg");
				//sous safari on affiche directement du HTML, sans passer par jp2 ni jpg
				//le .htm doit se trouver dans le repert du menu
				if (coefiframe==0){
					coefiframe=1;
				}
				//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
				sourceHTML= sourceJPG.replace(".jp2",".jpg");	
				//sourceHTML= sourceHTML.replace(".jpg",".html");	
				sourceHTML= sourceHTML.replace(".jpg",".htm");	
				//prob d'adresse relative avec safari: il ne trouve pas le fichier: files/menus/menu/laser0017.html
				//essai en mettant http://82.127.122.158/mdba/
				sourceHTML="http://82.127.122.158/mdba/" + sourceHTML
				//alert("sourceHTML=" + sourceHTML);
				/*document.write("<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
				<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
				<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
				<param name='SRC' value='" + SourceFile + "'>\
				<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
				</IFRAME>\
				</object>");*/
				document.write("<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
				</IFRAME>");
			//}
		}
	}


	document.close();
}

function get_htmljp2k( SourceFile, PictWidth, PictHeight)
{

	var navName;
	var sourceJPG;
	var html;
//modif aurelie le 10/11/2006: enlver le /jpg/ vu que l'on a dejà renseigné cette partie dans le cas de jpg
//document.write(SourceFile.racine().search("/jpg"));
//document.write("jpg="+jpg);
//on recherche le repert "/jpg" dans SourceFile.racine
//if (SourceFile.racine().search("/jpg")>0)

	if (jpg==1){

		sourceJPG = SourceFile.racine() + "/"+ SourceFile.name() + ".jpg";
		//	document.write("LAAAA");
	}else{
		//sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
		//cas du jp2
		sourceJPG = SourceFile.racine() + "/"+ SourceFile.name() + ".jp2";
		//document.write("LAAAA");
		//TEST INSTALL PLUGIN
		mimetype = navigator.mimeTypes["image/jp2"];
	
		if (mimetype){
			plugin = mimetype.enabledPlugin;
			if (! plugin){//si pas de plugin
				sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
			}
		}else{	//si pas de plugin
			sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";
		}
	}
	//	sourceJPG = SourceFile.racine() + "/jpg/"+ SourceFile.name() + ".jpg";


	if (jpg==1){

		html="<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>";
		return html;
	}
	/*
	document.write(navigator.appName);
	document.write(navigator.appVersion.charAt(0));
	document.write("<p></p>");
	document.write(navigator.userAgent);
	*/

	nav = navigator.appName;

	if (navigator.userAgent.indexOf("Opera") != -1) 
	{
		// Opera browser detected
		nav = "Opera Browser";
	}


	if ( nav == "Microsoft Internet Explorer")
	{
		//modif aurelie
		//affiche les images déroulantes si le format est JP2
		/*if (jpg==1){
			//affiche les images déroulantes si le format est JPEG
			html= "<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "'  height='" + PictHeight + "'>\
		  	<tr>\
	    	<td width='" + PictWidth + "'>\
	      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
	    	</td>\
		  	</tr>\
			</table>";
		}else{
			html="<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
			<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
			<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
			<param name='SRC' value='" + SourceFile + "'>\
			<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "' id='AutoNumber1' height='" + PictHeight + "'>\
		  	<tr>\
	    	<td width='" + PictWidth + "'>\
	      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
	    	</td>\
		  	</tr>\
			</table></object>";
		}*/
		if ((isJPEG) || ((isJPEG==-1)&& (isHTM==-1))){

			html="<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
			<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
			<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
			<param name='SRC' value='" + SourceFile + "'>\
			<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "' id='AutoNumber1' height='" + PictHeight + "'>\
		  	<tr>\
	    	<td width='" + PictWidth + "'>\
	      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
			</td>\
			<td>\
			</tr>\
			</table></object>";
		}else if (isHTM){
			//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
			//sourceHTML= sourceJPG.replace(".jpg",".html");	
			sourceHTML= sourceJPG.replace(".jpg",".htm");	

			if (coefiframe==0){
				coefiframe=1;
			}

			html="<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
			<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
			<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
			<param name='SRC' value='" + SourceFile + "'>\
			<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
			</IFRAME>\
			</object>";
		}		

		
	}else{

	if (navigator.platform=="Win32"){
		mimetype = navigator.mimeTypes["image/jp2"];
		
		if (mimetype)
		{
			plugin = mimetype.enabledPlugin;
			if (plugin) 
			{
				// Yes, so can we display with a plug-in?   
	  			html="<embed type='image/j2c' src='" + SourceFile + "' width='" + PictWidth + "' height='" + PictHeight + "' PLUGINSPAGE='http://www.mobilier-design-mdba.fr/plugin/download.php?file=setup_moz_plugin.exe' ></embed>";
	  		}
	  		else
	  		{   
				
				//html="<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>";
				if (isJPEG)//ajout aurelie pour le cas MAC qui ne sait pas afficher les jpg
				{
					html="<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>";
				}else if (isHTM){
						//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
						//sourceHTML= sourceJPG.replace(".jpg",".html");	
						sourceHTML= sourceJPG.replace(".jpg",".htm");	
						//document.write("Mozilla ou MAC test=" + sourceHTML);
						//window.open(sourceHTML,'_self');
						if (coefiframe==0){
							coefiframe=1;
						}
						html="<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
						</IFRAME>";	
				}
					
			}
		}
		else
	 	{   			
			//html="<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>";

			if (isJPEG)//ajout aurelie pour le cas MAC qui ne sait pas afficher les jpg
				{
					html="<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>";
				}else if (isHTM){
					//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
					//sourceHTML= sourceJPG.replace(".jpg",".html");	
					sourceHTML= sourceJPG.replace(".jpg",".htm");	
					//document.write("Mozilla ou MAC test=" + sourceHTML);
					//window.open(sourceHTML,'_self');
					if (coefiframe==0){
						coefiframe=1;
					}
					html="<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
					</IFRAME>";
				}
		}
	}else{//cas MAC OS
	// si on est sou MAC OS même comportement que IE? voir si ça marche.....
			//alert("MAC OS");
			/*if ((isJPEG) || ((isJPEG==-1)&& (isHTM==-1))){
				html="<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
				<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
				<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
				<param name='SRC' value='" + SourceFile + "'>\
				<table border='0' cellpadding='0' cellspacing='0' width='" + PictWidth + "' id='AutoNumber1' height='" + PictHeight + "'>\
			  	<tr>\
		    	<td width='" + PictWidth + "'>\
		      	<img src='" + sourceJPG +"' width='" + PictWidth + "px' height='" + PictHeight + "'px>\
				</td>\
				<td>\
				</tr>\
				</table></object>";
			}else if (isHTM){*/
				if (coefiframe==0){
					coefiframe=1;
				}
				//M. Liberas propose que les pages soient en HTM et pas en HTML pour différencier des commentaires
				//sourceHTML= sourceJPG.replace(".jpg",".html");	
				sourceHTML= sourceJPG.replace(".jpg",".htm");	
				/*html="<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + PictWidth + "' height='" + PictHeight + "'>\
				<param name='_ExtentX' value='" + PictWidth * 10 + "'>\
				<param name='_ExtentY' value='" + PictHeight * 10 + "'>\
				<param name='SRC' value='" + SourceFile + "'>\
				<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
				</IFRAME>\
				</object>";*/
				html="<IFRAME NAME='name_iframe' src='" + sourceHTML + "' HEIGHT='" + PictHeight*coefiframe + "' width='" + PictWidth*coefiframe + "'>\
				</IFRAME>";
			//}
		}
	}

	return html;
}
/*
function if_notJp2K()
{
	
	mimetype = navigator.mimeTypes["image/jp2"];
	
	if (mimetype)
	{
		plugin = mimetype.enabledPlugin;
		if (! plugin)
		{
			dl_plugin();
		}
	}
	else
	{
		dl_plugin();
	}
}*/

function notjp2k_affiche(text)
{
	
	mimetype = navigator.mimeTypes["image/jp2"];
	
	if (mimetype)
	{
		plugin = mimetype.enabledPlugin;
		if (! plugin)
		{
			document.write(text);
		}
	}
	else
	{
		document.write(text);
	}
}

/*function dl_plugin()
{
	nav = navigator.appName;
		if ( nav == "Microsoft Internet Explorer") 
		{
			document.write("<object classid='clsid:73BF7099-EC98-42A0-86F6-B3B3092EDD96' id='MMJ2KAX1' width='" + 150 + "' height='" + 150 + "'>\
			<param name='_ExtentX' value='" + 150 * 10 + "'>\
			<param name='_ExtentY' value='" + 150 * 10 + "'>\
			<param name='SRC' value='_blank.jp2'>\
			<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='" + 150 + "' id='AutoNumber1' height='" + 150 + "'>\
		  	<tr>\
		    	<td width='" + 150 + "'> \
		      	<p align='center'> Le Plugin Internet Explorer JPEG2000 n'est pas installé. </p>\
		      	<p align='center'> Cliquez <a href='http://www.mobilier-design-mdba.fr/plugin/download.php?file=MMJP2KAX.exe'>ici</a> \
		      	pour le télécharger. </p>\
		      	<p align='center'> Executez le et actualisez la page. </p>\
		    	</td>\
		  	</tr>\
			</table></object>");
		}
		else 
		{
		document.write("\
			<p align='center'> Le Plugin Internet Mozilla/Netscape JPEG2000 n'est pas installé. </p>\
			<p align='center'> Cliquez <a href='http://www.mobilier-design-mdba.fr/plugin/download.php?file=setup_moz_plugin.exe'>ici</a> \
			pour le télécharger </p>\
			<p align='center'> Puis fermez votre navigateur, installez le Plugin et réouvrez le navigateur pour afficher la page</p>");
		
		}
}*/

function switchJpg()
{

	if (jpg==1)
	{
		er = new RegExp("true");
		for (var i = 0 ; i < document.links.length; ++i)
		{
			document.links[i].href = document.links[i].href.replace(er,"false");
		}
		jpg=false;
		document.getElementById('mainFrame').src = document.getElementById('mainFrame').src.replace(er,"false");
	}
	else
	{
		er = new RegExp("false");
		for (var i = 0 ; i < document.links.length; ++i)
		{
			document.links[i].href = document.links[i].href.replace(er,"true");
		}
		jpg=true;
		document.getElementById('mainFrame').src = document.getElementById('mainFrame').src.replace(er,"true");
	}
}

String.prototype.racine = function()
{
	i=this.length;
	while (this.charAt(i)!='/' && i>=0)
	{
		i=i-1;
	}
	return this.substr(0,i);
}

String.prototype.name = function() {
	i=this.length;
	while (this.charAt(i)!='/' && i>=0)
	{
		i=i-1;
	}
	return this.substr(i+1,this.length-i-5);
}
