//*********************************
// Tips Library
// author iGate Global Solutions
//
//
//
//*********************************

// 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></title>");
if (styleSheet)
{
	my_window.document.write("<link href='" + styleSheet + "' rel='stylesheet' type='text/css'>");
}
my_window.document.write("</head><body style='padding:5px;font-family:arial;font-size:12px;'>");

my_window.document.write("<div class=hintTitle>" + tts.title + "</div>");
my_window.document.write("<p align='right'><a href='javascript:window.close();'></a><hr width='100%' heigth='1'></p>");
my_window.document.write("<div class=hintContent>" + tts.content + "</div>");

my_window.document.write("<hr width='100%' heigth='1'><div align='right' style='margin-right:10px;position:relative;'><a  href='javascript:window.close();' class='smartnotice'>" + closeTranslation + "</a></div></body></html>");


my_window.document.close();
}





