//*********************************
// Tips Library
// author Guibert Jerome
//
//
//
//*********************************

// Constructor for Tip
function Tip(id, title, content)
{
	this.id = id;
	this.title = title;
	this.content = content;
}

// Constructor for tips
// element id for set tips position
function Tips(id)
{
	this.id = id;
	this.items = new Array();
	this.hideitem = null;
	this.defaultitem = null;
	this.add = tipsAdd;
	this.show = tipsShow;
	this.hide = tipsHide;
	this.init = tipsInit;
	this.setDefault = tipsSetDefault;
	this.isInit = false;
	this.count = tipsCount;
	this.redraw = tipsRedraw;
	this.showOnInit = null;
	this.gettip = tipsgettip;
}
// init tips
function tipsInit()
{
	// get x,y
	var el = layer_getElement(this.id);
	if (el == null) return;
	var	trueX = layer_getRealLeft(el);
	var trueY = layer_getRealTop(el);
	
	// creation layer
	for (var i=0; i < this.items.length; ++i)
	{
		var tts = this.items[i];
		var name = this.id + "_" + tts.id;
		var contenuHtml = "<div class=hintTitle>" + tts.title + "</div><div>&nbsp;</div><div class=hintContent>" + tts.content + "</div>";
		newLayer(name, "", "", contenuHtml);
		setzIndex(name,20);
		hideLayer(name);
		setPositionAbsolute(name);
		moveLayerTo(name,trueX,trueY);
	}
	this.isInit = true;
	if (this.showOnInit != null)
	{
		this.show(this.showOnInit);
	}
}

// count
function tipsCount()
{
	return this.items.length;
}
// add a tip
function tipsAdd(id, title, content)
{
	this.items[this.items.length] = new Tip(id, title, content);
}
// set default tip
function tipsSetDefault(tipID)
{
	this.defaultitem = tipID;
}
// show a tip
function tipsShow(tipID)
{
	if (this.isInit == false) 
	{
		this.showOnInit = tipID;
		return;
	}
	var tts = null;
	for (var i=0; i < this.items.length; ++i)
		if (this.items[i].id == tipID) {tts = this.items[i]; break;}
	if (tts == null) return;
	
	if (this.hideitem != null)
	{
		hideLayer(this.hideitem);
	}
	var name = this.id + "_" + tts.id;
	showLayer(name );
	this.hideitem = name;
	
}
// hide a tip
function tipsHide()
{
	if (this.hideitem != null)
	{
		hideLayer(this.hideitem);
		this.hideitem = null;
	}
	if (this.defaultitem != null)
	{
		this.show(this.defaultitem);
	}
}
// redraw
function tipsRedraw()
{
	
	if (this.hideitem != null)
	{
		hideLayer(this.hideitem);
	}

	var el = layer_getElement(this.id);
	if (el == null) return;
	var	trueX = layer_getRealLeft(el);
	var trueY = layer_getRealTop(el);
	
	for (var i=0; i < this.items.length; ++i)
	{
		var tts = this.items[i];
		var name = this.id + "_" + tts.id;
		moveLayerTo(name,trueX,trueY);
	}
	if (this.hideitem != null)
	{
		showLayer(this.hideitem);
	}
}

function tipsgettip(tipID)
{
	var tts = null;
	for (var i=0; i < this.items.length; ++i)
		if (this.items[i].id == tipID) {tts = this.items[i]; break;}
	return tts;
}

// ---------------------------------------------
// init system and usely function
var tips_container = null;

function initTip()
{
	if (tips_container == null)
	{
		tips_container = new Tips("imgtippos");
	}
	return tips_container;
}

function hideTip()
{
	if (tips_container == null) return;
	tips_container.hide();
}

function showTip(ID)
{
	if (tips_container == null) return;
	tips_container.show(ID);
}
function setDefaultTip(ID)
{
	if (tips_container == null) return;
		tips_container.setDefault(ID);
}
// used to show a persitent tip
function showDescription(ID)
{
	setDefaultTip(ID)
	showTip(ID);
}


function drawTips()
{
	var t = initTip();
	if (t != null)
	{
		if (t.isInit == false)
		{
			t.init();
		}
		else
		{
			t.redraw();
		}
	}
}

var my_window = null;
function showPopupDescription(styleSheet, ID, closeTranslation, width, height)
{
tts = tips_container.gettip(ID);

my_window= window.open ("",  "mywindow","scrollbars=yes, status=1, resizable=0, width=" + width + ",height=" + height);
my_window.document.write("<html><head><title>Mondial Assistance</title>");
my_window.document.write("<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
if (styleSheet)
{
	my_window.document.write("<link href='" + styleSheet + "' rel='stylesheet' type='text/css'></head>");
}
	my_window.document.write("<style>body { margin:0px; background-color:#FFFFFF; }</style>");
	my_window.document.write("<body bgcolor='#cccccc' marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>");

	my_window.document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
	my_window.document.write("<tr align='right' valign='top'><td>");
	my_window.document.write("<table cellpadding='0' cellspacing='0' border='0' cols='2' bgcolor='#FFFFFF' width='98%' >");

	my_window.document.write("<tr><td width='31%'></td><td width='68%' height='41' align='right'>");
	my_window.document.write("<div class='logo'></div></td>");
	my_window.document.write("</tr></table></td></tr><tr align='left' valign='top' bgcolor='#0099FF'>");
	my_window.document.write("<td>&nbsp;</td></tr><tr align='left' valign='top'><td>&nbsp;</td></tr>");
	my_window.document.write("<tr align='left' valign='top'><td>");
	
	
	my_window.document.write("<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td width='25'>");
	my_window.document.write("</td>");
	my_window.document.write("<td class='bodytextlink' align='left' valign='top' width='1107'>")
	my_window.document.write("" +  tts.content + "" );;
	my_window.document.write("</tr></table></td></tr><tr><td align='right'>");
	my_window.document.write("<table width='78%' cellpadding='0' cellspacing='0' border='0' align='right'>");
	my_window.document.write("<tr><td width='280'>");
	
	
	my_window.document.write("</td>");
	my_window.document.write("<td align='right' width='468'><p>&nbsp;</p></td>");
	my_window.document.write("<td width='129' align='right'>");
	my_window.document.write("<a href='javascript:window.close();' class='button1'>" + closeTranslation + "</a>&nbsp;&nbsp;</td>");
	my_window.document.write("</tr></table></td></tr></table>");

	my_window.document.write("</body></html>");
	my_window.document.close();
}



