/*function suchen(){
var suchbegriff = new Array('lorem','Elite','einn','Mittelpunkt','Personal','Sozialdienst','Tapetenwechsel');
var suchID = new Array('59','32','31','19','7','21','37')

for(i=0;i<suchbegriff.length;i++){
var suche = new RegExp(suchbegriff[i],'gi')
var bodytext = document.getElementById('contentbody').innerHTML
var hyperlink = suchID[i]
document.getElementById('contentbody').innerHTML = bodytext.replace(suche, "<a href='incl_glossar.php?ID="+hyperlink+"' target='glossar' class='glossarlink'>"+suchbegriff[i]+"</a>");}
}*/

/*
Text marker code 
Ashok Hariharan
*/


/*helper function , just does search & replace */



function replaceMe(str, phrase, chg) {
var pattern = new RegExp (phrase ,'g');
return str.replace( pattern, chg);
}


/*helper function , gets innerHtml of a layer */
/*code ripped from ppk : http://xs4all.nsl/~ppk/js/ */
function getLayerHtml(id)
{
	var inHtml = new String('');
	if (document.getElementById)
	{
		x = document.getElementById(id);
		inHtml = x.innerHTML;
	}
	else
	 if (document.all)
	{
		x = document.all[id];
		inHtml = x.innerHTML;
	}
	return inHtml;
}

/*helper function , sets the innerHtml of a layer */
/*code ripped from ppk : http://xs4all.nsl/~ppk/js/ */
function setLayerHtml(text,id)
{
	if (document.getElementById)
	{
		elemObj = document.getElementById(id);
		elemObj.innerHTML = text;
	}
	else if (document.all)
	{
		elemObj = document.all[id];
		elemObj.innerHTML = text;
	}
	/*
	this is ns4 compatible code ...
	*/
	/*
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>;';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
	*/
}

/*main marker function*/
function markText(txtKeyword, inputHtml, txtId) 
{
           var re; 						/*regex object*/
           var varMatches; 					/*matches array*/
           var outHtml; 					/*output html*/
           var replaceText;
          // replaceText = '<span style="background-color:yellow;color:red;font-weight:bold;">'+txtKeyword+ '</span>';
		  replaceText = '<a href="glossarDet.aspx?gid='+txtId+'" target="glossar" class="glossar" onclick="showGlossar();">'+txtKeyword+ '</a>';
	   re=new RegExp("(\<[^>][^<]*\>)([^<]*)","g");	/*create non-greedy regex match*/	   

	   /*
	   note : 
	   in 99% of cases <[^>]*\>)([^<]*) 
	   should also work , i did have the rare case where some invisible 
	   characters caused this to crap out ....
	   */

	   outHtml=new String('');				/*init html string*/
	   while ((varMatches = re.exec(inputHtml)) != null)		/*exec sequentially to apply span tags*/
	   {
		 outHtml+=varMatches[1]; 	/*html tag part*/
		 outHtml+=replaceMe(varMatches[2], txtKeyword, replaceText); 
	   }
	   return outHtml;
}


function main(elm)
{
	/*we have successfully parsed out the url now pass it to the highlight func.*/
	var inHtml;
	var outHtml;
	/*get the innerHtml content from within the div*/
	inHtml = '<em></em>'+getLayerHtml(elm);		
	for(i=0;i<glossar.length;i++){
			hiliteText = glossar[i]["keyword"];
			hiliteTextId = glossar[i]["id"];
		
			if (hiliteText.length != 0)
			{
				/*run the hilite function to hilite stuff*/
				inHtml = markText(hiliteText, inHtml, hiliteTextId);
				/*write the hilited stuff back to the div*/
			}
	}
	setLayerHtml(inHtml,elm);

}

function suchen(elm)
{

	if(elm){
		/*1 - we parse out the hilite= querystring value */
		main(elm);
		return;
	}
}

var ie = (document.all) ? true : false;
if(!ie) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getPosXY;
function getPosXY(e) {
    x = (ie) ? event.clientX + document.body.scrollLeft +10: e.pageX +10;
    y = (ie) ? event.clientY + document.body.scrollTop -80  : e.pageY - 80 ;

    if(x < 0) { x = 0; }
    if(y < 0) { y = 0; } 

}

var opacity;

function showGlossar(){

		if(ie){
			h = document.body.offsetHeight;
		}else{
			h = window.innerHeight;
		}
		//alert(h);
		
opacity = 100;
document.getElementById("multiboxblockglossar").style.display = "block";
ie ? document.getElementById("multiboxblockglossar").filters.alpha.opacity = opacity : document.getElementById("multiboxblockglossar").style.MozOpacity=opacity/100;
document.getElementById("multiboxblockglossar").style.position = "absolute";
document.getElementById("multiboxblockglossar").style.top = y ;
document.getElementById("multiboxblockglossar").style.left = x;
}

function startHideGlossar(){
//aktiv = window.setTimeout(function(){hideGlossar();}, 5);
hideGlossar()
}

function hideGlossar(){
/*if(opacity <= 0){
	window.clearTimeout(aktiv)
}else{
	opacity = opacity - 2;
	//document.getElementById("multiboxblockglossar").style.display = "none";
	ie ? document.getElementById("multiboxblockglossar").filters.alpha.opacity = opacity : document.getElementById("multiboxblockglossar").style.MozOpacity=opacity/100;
	aktiv = window.setTimeout(function(){hideGlossar();}, 5)};*/
	document.getElementById("multiboxblockglossar").style.display = "none";
}


