/* 
//
// Auteur : Aurélien BARRAU - QIO (ore@iqio.org)
// Date : 2004/08/23
// 
// Projet : WebCT95 
//
// Fichier : q_openImage.js
// Description : permet d'ouvrir une popup avec l'image.
//
 */

/*
*	@Description : Ouverture du popup.
*	@Param	:	- nomImage : nom de l'image, ou url
*				- titreHtml : titre de la fenetre (defaut: @ )
*/
function openImage(nomImage, titreHtml) 
{
	if ((nomImage == "")||(nomImage == " "))
	{
		alert(" Le nom du fichier n'est pas renseigné, ce dernier ne peut pas être ouvert. ");
		return false;
	}
	if (titreHtml == "")	titreHtml = "@"; 
	var imgWidth = 300;
	var	imgHeight = 100;
	var offset = 50;
	var argWin = "status=0,toolbar=0,titlebar=0,fullscreen=0,location=0,scrollbars=0,resizable=1";

	fenetre = window.open("","","width="+ imgWidth +",height="+ imgHeight +",left="+ ((screen.width - imgWidth)/2) +",top="+ ((screen.height - imgHeight)/2) +","+ argWin);
	var corps = ecriture_fichier(nomImage, titreHtml); 
	fenetre.document.open();
	fenetre.document.write(corps);
	fenetre.document.close();
}


/*
*	@Description : Ecrit le corps du fichier html dans le popup.
*	@Param	:	- nomImage : nom de l'image, ou url
*				- titreHtml : titre de la fenetre (defaut: @ )
*/
function ecriture_fichier(nomImage, titreHtml)
{
	var corpsPopup	= "<html> \n"
		corpsPopup += "<head> \n"
		corpsPopup += "	<title>"+ titreHtml +"</title> \n"
		corpsPopup += "</head> \n"

		corpsPopup += " <div id='divLoading' style='visibility:visible;position:absolute; top:0; left:0; width:300; height:100;'><table width='100%' height='100%' algin='center'><tr><td align='center' valign='middle' style='font-family:Verdana; font-size:12px; color:#E9110D;'> Image en cours de chargement ... </td></tr></table></div>\n"

		corpsPopup += "	<script language=\"javascript\" type=\"text/javascript\">  \n"
		corpsPopup += "	function checksize() {  \n"
		corpsPopup += "		if (document.images[0].complete) {  \n"
		corpsPopup += "			imgWidth = document.images[0].width + 10;  \n"
		corpsPopup += "			imgHeight = document.images[0].height + 30; \n"
		corpsPopup += "			window.moveTo(((screen.width - imgWidth) /2), ((screen.height - imgHeight) /2)); \n"
		corpsPopup += "			window.resizeTo(imgWidth, imgHeight);  \n"
		corpsPopup += "			divLoading.style.visibility = 'hidden'; \n"
		corpsPopup += "			window.focus();  \n"
		corpsPopup += "		} else { setTimeout('checksize()',250) }  \n"
		corpsPopup += "	} \n"
		corpsPopup += "</script> \n"
// -- pour fermer la fenetre automatiquement: onblur='window.close()' -- //
		corpsPopup += "<body onload='checksize()' onclick='window.close()' leftMargin='0' topMargin='0' marginwidth='0' marginheight='0' style='cursor:hand;'> \n"
		corpsPopup += " <table width='100%' height='100%' algin='center' border='0' cellspacing='0' cellpadding='0'><tr><td align='center' valign='middle' style='font-family:Verdana; font-size:12px; color:#E9110D;'><img src='"+ nomImage +"' border='0' alt='Cliquez sur la photo pour fermer la fenêtre.'></td></tr></table> \n"
		corpsPopup += "</body> \n"
		corpsPopup += "</html> \n";


		return corpsPopup;
}
