/*
Copyright (c) 2007, PMP Concept
version: 1
*/

/*****************************************************************************
 *
 * 								Classe pmpMsgBox
 *
 *	Fonction : 	affichage d'une boite de dialogue
 *
 *  Paramètres
 *		- message	 	: (string) le texte de la boite de dialogue
 *		- type		 	: (string) le type de la boite de dialogue, facultatif
 *  	- titre			: (string) le titre de la boite de dialogue
 *		- icone		 	: (string) l'url de l'icone de la boite de dialogue, facultatif
 *
*****************************************************************************/

PMP.util.pmpMsgBox = function(message, type, titre, icone) 
{
	this.typeArray = new Array("information", "question", "avertissement", "erreur", "confirmation");

	this.message = message;
	this.type = PMP.common.isString(type)  && this.typeArray.join(",").search(type) >= 0 ? type : "information";
	this.titre = PMP.common.isString(titre) ? titre : type;
	this.icone = icone;

	this.popup = new Popup();
	//document.write('<div id="popup_layer"><div id="overlay" class="overlay"></div><div id="lightbox"><div id="outerImageContainer"></div></div></div>')
	
	// ajout de la fenetre dans la liste des fenetres du document
	if( PMP.common.isUndefined(document.fenetres) )
		document.fenetres = new Array();
	
	this.index = document.fenetres.length;
	document.fenetres[this.index] = this;
	
	this.template =	'<div id="fenetre" class="fenetre">'
				  +		'<div id="titlebar"><div id="icon"></div><div id="titre">' + this.titre + '</div></div>'
				  +		'<div id="messagearea">'
				  +			'<div id="message" class="' + this.type + '">' + this.message + '</div>'
				  +		'</div>'
				  +		'<div id="buttonsbar">'
				   //+			'<input type="image" id="bouton_close" class="button" alt="Fermer" onclick="document.fenetres['+this.index+'].hide();" />'
				  +			'<span id="bouton_close" class="button" onclick="document.fenetres['+this.index+'].hide();">Fermer</span>'
				  +		'</div>'
				  +	'</div>';
	
	this.popup.addContent(this.template);
	this.show();
	this.dragdrop = new PMP.util.pmpDragDrop("outerImageContainer", "titlebar");
}


PMP.util.pmpMsgBox.prototype = {
	
	 setTitre : function(titre) {
		this.titre = titre;
	},

	getTitre : function() {
		return this.titre;
	},

	show : function() {
		this.popup.show();
		
		this.bouton_close = document.getElementById("bouton_close");
		if( this.bouton_close )
		{
			/*var me = this;
			this.bouton_close.onkeypress = function (evt)
			{
				var code;
	
				var pmpEvt = new PMP.util.pmpEvent();
				pmpEvt.getEvent(evt);
		
				if (pmpEvt.event.keyCode) code = pmpEvt.event.keyCode;
				else if (pmpEvt.event.which) code = pmpEvt.event.which;
				
				if( code == 13 || code == 27 )
				{
					me.hide();
					pmpEvt.cancelEvent();
				}
			}
			this.bouton_close.focus();
			*/
			
			this.keypress = document.onkeypress;
			var me = this;
			document.onkeypress = function (evt)
			{
				var code;
	
				var pmpEvt = new PMP.util.pmpEvent();
				pmpEvt.getEvent(evt);
		
				if (pmpEvt.event.keyCode) code = pmpEvt.event.keyCode;
				else if (pmpEvt.event.which) code = pmpEvt.event.which;
				
				if( code == 13 || code == 27 )
				{
					me.hide();
					pmpEvt.cancelEvent();
				}
			}
			
		}
	},

	hide : function() {
		document.onkeypress = this.keypress;
		this.popup.hide();
	}

}
