var mouseX, mouseY, tooltipX, tooltipY, tooltip;

// IE kennt kein .indexOf()  :(
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for (var i=0; i<this.length; i++) {
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}
// -----------------------------------------------------------------------------
function cutCellContent(cell)
{
	innerSpan = cell.getElementsByTagName('span')[0];

	//alert('1');
	if (!innerSpan) { return; } // kein span in der Zelle vorhanden
	// um nicht jedes Element zuk�rzen mu� eine ID ins Span gelegt werden
	innerId = cell.getElementsByTagName('span')[0].id;
	//if (innerId) { return; }
	if (innerSpan.getElementsByTagName('*')[0]) { return; }		// HTML-Code in der Zelle
	if (innerSpan.offsetWidth +5 < cell.offsetWidth ) { return; }		// Inhalt passt in Zelle
	// Vollst�ndigen Inhalt sichern in angeh�ngtem span
	saveContent = document.createElement('span');
	saveContent.style.display = 'none';
	saveContent.innerHTML = innerSpan.innerHTML;
	cell.appendChild(saveContent);

	innerSpan.innerHTML = basicTrim(innerSpan.innerHTML);
	//innerSpan.innerHTML = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
	tmp = innerSpan.innerHTML;
	innerSpan.innerHTML = '';

	cellLength = parseInt(cell.offsetWidth*0.14);
	innerSpan.innerHTML = tmp.substr(0,cellLength);
	
	if (innerSpan.offsetWidth +25 > cell.offsetWidth){
		for(i = cellLength; i< 255; i++){
			if (innerSpan.offsetWidth +25 < cell.offsetWidth){
				break;
			}
			else{
				innerSpan.innerHTML = innerSpan.innerHTML.substr(0, innerSpan.innerHTML.length-1);
			}
		}
	}
	else{
		for(i = cellLength; i< 255; i++){
			if (innerSpan.offsetWidth +25> cell.offsetWidth){
				break;
			}
			else{
				innerSpan.innerHTML+=tmp.charAt(i);
			}
		}
	}



	//innerSpan.innerHTML = innerSpan.innerHTML.substr(0,cellLength);

	innerSpan.innerHTML = innerSpan.innerHTML.replace("&amp;","&");
	//innerSpan.innerHTML = innerSpan.innerHTML.replace("amp;","&");
	innerSpan.innerHTML += ' ... &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
}

function basicTrim (str) {
	return str.replace(/\s+$/,"").replace(/^\s+/,"");
}

// -----------------------------------------------------------------------------
function cutCellContents() {
	allElem = document.getElementsByTagName('*');
	for( var i = 0; i < allElem.length; i++) {
		//if (allElem[i].className == 'table_content') {
		if ((allElem[i].className.indexOf('table_content') >= 0) || (allElem[i].className.indexOf('tt_table_content') >= 0)) {
			cutCellContent(allElem[i]);
		}
	}
}
// -----------------------------------------------------------------------------
function ttInit()
{
	document.onmousemove = captureMousePos;
	tooltip = document.createElement('div');
	tooltip.className = 'table_tooltip';
	document.body.appendChild(tooltip);
	cutCellContents();
}
// -----------------------------------------------------------------------------
function ttShow(obj, text, x, y)
{
	if(!mouseX || !mouseY) return;

	if(tooltip.style.display != 'inline')
	{
		tooltip.style.display = 'inline';

		if(text) {
			tooltip.innerHTML = text.replace(/\r\n/g, '<br>');
		}
		else {
			if (textObj = obj.parentNode.getElementsByTagName('span')[1]) {
				tooltip.innerHTML = textObj.innerHTML.replace(/<q> ?<\/q>/gi, '<br>');
			}
			else {
				tooltip.innerHTML = obj.innerHTML.replace(/<q> ?<\/q>/gi, '<br>');
			}
		}

		if(!obj.onmouseout || obj.onmouseout.toString().indexOf('this.oldmouseout();') == -1)
		{
			obj.oldmouseout = obj.onmouseout;
			obj.onmouseout	= function() { tooltip.style.display = 'none'; if(this.oldmouseout) this.oldmouseout(); }
		}

		if(!(tooltipX = x)) tooltipX = 0;
		else if(x == -1) tooltipX -= tooltip.offsetWidth / 2;

		if(!(tooltipY = y)) tooltipY = 0;
		else if(y == -1) tooltipY -= tooltip.offsetHeight / 2;
	}

	tooltip.style.left = mouseX + tooltipX + 'px';
	tooltip.style.top	= mouseY + tooltipY + 'px';
}
// -----------------------------------------------------------------------------
function captureMousePos(Event)
{
	if(Event)
	{
		mouseX = Event.pageX + 16;
		mouseY = Event.pageY + 6;
	}
	else
	{
		Event = window.event;
		mouseX = Event.x + 6 + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : 0);
		mouseY = Event.y + 6 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : 0);
	}
}
