/*
 * Popup
 */

toutou.require("toutou.html.dom");
toutou.require("toutou.html.dnd");

if(typeof js == "undefined") {
	js = {};
	js.imgPath = "";
}

js.popup = new function(){
	
}

// param :
// title = nom affiché dans la barre de la fenetre popup
// contenu = contenu du message à afficher dans la fenetre
// bcolor = backgroundColor & borderColor de la fenetre
// tcolor = couleur du texte
// fondgris = true ou false pour afficher ou non un layer semi transparent sur le fond de page
js.popup.popup_window = function(title, contenu, bcolor, tcolor, fondgris, zone_bouton)
{	
	if (!zone_bouton){
		zone_bouton="<a href='#' onclick='js.popup.hidepopup();'><img src='imgT/btn_ok_gris_popup.gif' border='0'></a>"
	}
	//initialisation des DIV pour la fenetre popup
	var content_zone_erreurs = tt$("contenu_zone_erreurs");
	toutou.html.layout.extend(content_zone_erreurs);
	var zone_erreurs = tt$("zone_erreurs");
	toutou.html.layout.extend(zone_erreurs);
	var content_zone_bouton = tt$("btn_ok");
	content_zone_bouton.innerHTML=zone_bouton;
	
	
	//mise en place du contenu et des styles
	content_zone_erreurs.innerHTML = contenu;
	content_zone_erreurs.style.color = tcolor;
	
	zone_erreurs.style.backgroundColor = bcolor;
	zone_erreurs.style.borderColor = bcolor;

	position = toutou.html.layout.getScrollPosition();
	
	// init du div dragable
	var dragableDiv = tt$("zone_erreurs");
	dragableDiv.style.top = position.top + 15 + "px";
	var dragHandle = tt$("drag_zone_erreurs");
	dragHandle.innerHTML = "<div style='float:left;'>" + title + "</div><div style='float:right;'><a href='#' onclick='js.popup.hidepopup();'><img src='imgT/close_popup.gif' border='0'></a></div>";
	toutou.html.dnd.setDragable(dragableDiv, dragHandle);
	dragableDiv.tt_setDisplay("block");

	// mise en place du layout semi transparent en fond de page
	if (fondgris){
		//size = toutou.html.layout.getPageSize();
		var shadow = tt$("shadow");
		toutou.html.layout.extend(shadow);
		
		var documentSize = toutou.html.layout.getPageSize();
		var windowSize = toutou.html.layout.getWindowSize();
		var size = {
		width: Math.max(documentSize.width, windowSize.width),
		height: Math.max(documentSize.height, windowSize.height)
		}
	
		shadow.style.backgroundColor = "#000";
		shadow.style.width = size.width + "px";
		shadow.style.height = size.height + "px";
	
		shadow.tt_setDisplay("block");
		shadow.tt_setOpacity(50);
	}
	//shadow.style.backgroundColor = bcolor;
}

js.popup.hidepopup = function() {
	tt$("zone_erreurs").tt_setDisplay("none");
	tt$("shadow").tt_setDisplay("none");
}