
var _posx, _posy;
var _posdi = 15;
var _pinned = new Array();
var _dynShow = new Array();
var _dynZ = 1001;

function isIE() {

	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);

}

function init() {
	if (window.captureEvents) {
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = getXY;
}

function getXY(e) {

	if (document.addEventListener) {
		_posx = e.clientX + window.pageXOffset;
		_posy = e.clientY + window.pageYOffset;
	}
	else if (window.opera) {
		_posx = e.clientX + window.pageXOffset;
		_posy = e.clientY + window.pageYOffset;
	}
	else if (window.event) {
	
		if (document.compatMode && document.compatMode!= 'BackCompat') {
			_posx = event.clientX + document.documentElement.scrollLeft;
			_posy = event.clientY + document.documentElement.scrollTop;
		}
		else {
			_posx = event.clientX + document.body.scrollLeft;
			_posy = event.clientY + document.body.scrollYop;
		}	
	}
}

function createTip(id, width, height, dpl) {

   var tipDiv = document.createElement('span');
   tipDiv.setAttribute('id', id);

   tipDiv.className = "tooltip";	

	document.body.appendChild(tipDiv);
	
   if (width) 
	   tipDiv.style.width = width+"px";
   
   if (height) 
	   tipDiv.style.height = height+"px";
		   
	tipDiv.style.left = _posx+_posdi+"px";	   
	tipDiv.style.top = _posy+_posdi+"px";
   
	if (dpl)
		tipDiv.style.display = dpl;
}

function removeTip(id) {

	var t = document.getElementById(id);
	var p = t.parentNode;
	p.removeChild(t);

}

function moveTip(id) {

	if (_pinned[id])
		return;

	var tip = document.getElementById(id);
	
	tip.style.top = _posy+_posdi+"px";
	tip.style.left = _posx+_posdi+"px";

}

function showTip(id, txt, w, h) {

	if (_pinned[id])
		return;
	
	if (!document.getElementById(id))
		createTip(id, w, h);
		
	var tip = document.getElementById(id);
	
	tip.style.display = "block";
	if (txt)
		tip.innerHTML = txt;
	
	if (w)
		tip.style.width = w+"px";
	if (h)
		tip.style.height = h+"px";
		
	moveTip(id);

}

function hideTip(id) {

	if (_pinned[id])
		return;

	var tip = document.getElementById(id);
	
	tip.style.display = "none";

}

function spinTip(id) {

	if (_pinned[id])
		_pinned[id] = false;
	else
		pinTip(id);
		
}

function pinTip(id) {

	if (!document.getElementById(id))
		return;

	_pinned[id] = false;
	if (!document.getElementById(id+"_close")) {
		if (isIE()) {
			document.getElementById(id).style.display = 'block';
			document.getElementById(id).style.width = document.getElementById(id).offsetWidth-10+"px";
		}
		document.getElementById(id).innerHTML = "<span id='"+id+"_close' style='float: right; margin-left: 5px;'><a href='javascript:;' onclick='unpinTip(\""+id+"\")'><img src='/Templates/"+_tpDir+"/Images/del.gif' alt='Close' title='Close window' /></a><br /></span>"+document.getElementById(id).innerHTML;
	}
	moveTip(id);
	_pinned[id] = true;
	
}

function editTip(id, txt) {

	if (!document.getElementById(id))
		return;
		
	var tip = document.getElementById(id);

	if (txt)
		tip.innerHTML = txt;	

}

function unpinTip(id) {

	_pinned[id] = false;
	hideTip(id);

}

function createDyn(id, width, height, dpl) {

	var dynDiv = document.createElement('span');
	dynDiv.setAttribute('id', id);

	dynDiv.className = "dynMenu";	

	document.body.appendChild(dynDiv);
	
	if (width) 
	   dynDiv.style.width = width+"px";
   
	if (height) 
	   dynDiv.style.height = height+"px";
		
	dynDiv.style.left = _posx+_posdi+"px";	   
	dynDiv.style.top = _posy+_posdi+"px";
	
	_dynZ++;
	dynDiv.style.zIndex = _dynZ;
   
	if (dpl)
		dynDiv.style.display = dpl;
		
}

function showDyn(id, txt, w, h) {
	
	if (!document.getElementById(id))
		createDyn(id, w, h);
		
	var dyn = document.getElementById(id);
	
	dyn.style.display = "block";
	if (txt)
		dyn.innerHTML = txt;
	
	if (w)
		dyn.style.width = w+"px";
	if (h)
		dyn.style.height = h+"px";
		
	dyn.style.left = _posx+_posdi+"px";	   
	dyn.style.top = _posy+_posdi+"px";
	
	_dynZ++;
	dyn.style.zIndex = _dynZ;
	
	_dynShow[id] = true;

}

function switchDyn(id, txt, w, h, dpl) {

	if (!document.getElementById(id))
		createDyn(id, w, h, dpl);
		
	var dyn = document.getElementById(id);
		
	if (_dynShow[id])
		hideDyn(id);
	else 
		showDyn(id, txt, w, h);

}

function hideDyn(id) {

	var dyn = document.getElementById(id);
	
	dyn.style.display = "none";
	_dynShow[id] = false;

}
	
