var isIE = (document.all) ? true:false;
var helpLayerId = 'helplayer'

//ReplaceAll functie:
function replaceAll(checkMe,toberep,repwith)
{
  var temp = checkMe;
  var i = temp.indexOf(toberep);
  while(i > -1)
  {
    temp = temp.replace(toberep, repwith);
    i = temp.indexOf(toberep, i + repwith.length + 1);
  }
  return temp;
}

function showTitle(obj)
{
	var pos = getPos(obj);
	var helpLayer = getObject(helpLayerId);	
	if(helpLayer!=undefined)
	{
		helpLayer.innerHTML = formatInhoud(obj.title);
		obj.title = '';	
		helpLayer.style.left =(pos.x+20)+'px';
		helpLayer.style.top =(pos.y+20)+'px';
		helpLayer.style.display = 'block';
		helpLayer.style.visibility = 'visible';
		//wrapIframeAroundMe(helpLayer);
	}
	return true;
}
function getObject(id)
{
	return document.getElementById(id);
}
function hideTitle(obj)
{
	var helpLayer = getObject(helpLayerId);
	obj.title = getObject(helpLayerId).innerHTML;
	helpLayer.style.visibility = 'hidden';
	helpLayer.style.display = 'none';	
	//unwrapIframe();
	return true;
}
function formatInhoud(inhoud)
{
  var newInh = inhoud;
  newInh = replaceAll(newInh,'[k]','<h3>');
  newInh = replaceAll(newInh,'[/k]','</h3>');
  newInh = replaceAll(newInh,'[enter]','<br />');
	return newInh;
}

function addTitleSpans()
{
	var elements=document.getElementsByTagName('*');
	for(var i=0; i<elements.length;i++)
	{
		if ( elements[i].tagName == 'DIV' || elements[i].tagName == 'LABEL' )
	  {
  		if(elements[i].title && elements[i].title.length>0)
  		{
  			elements[i].className+=' help';
  			elements[i].onmouseover=function(){
  		  	showTitle(this);
  		  	var url = '';
  		  	if (this.href)
  		  	{
  		  	  url = replaceAll(this.href, '\'', '|');
  		  	  url = replaceAll(url, '|', '\\\'');  		  	  
  		  	}          
  	  	}
  	  	elements[i].onmouseout=function(){
  	  		hideTitle(this);
  	  	}
  		}
	  }
	}
}


function getPos(theObj)
{
  x = y = 0;
    //de style wissels zijn uitgezet, want dan verliest Mozilla de selectedText in de ubb editor.
  	//var oldstyle = theObj.style.display;	
  	//theObj.style.display = 'block';	  
  h = theObj.offsetHeight;
  w = theObj.offsetWidth;
		//theObj.style.display = oldstyle;
  while(theObj){
    x += theObj.offsetLeft;
    y += theObj.offsetTop;
    theObj = theObj.offsetParent;
  }
 return {height:h,width:w,x:x,y:y}
}
