currentContent = null;
currentImageGallery = null;

function RichtextBox_InsertImage(url, align, title)
{
	if(currentContent)
	{
		RichtextBox_InsertAtSelection(currentContent.contentWindow, '<img src="' + url + '" align="' + align + '" title="' + title + '" alt="' + title + '" class="cssImage" hspace="5" vspace="5" border="0"/>');
		if(currentImageGallery) currentImageGallery.style.display = 'none';
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if(obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if(obj.y) curtop += obj.y;
	return curtop;
}

function RichtextBox_Hide(objid)
{
	var obj = document.getElementById(objid);
	obj.style.display = 'none';
}

function RichtextBox_Show(objid)
{
	var obj = document.getElementById(objid);
	obj.style.display = 'block';
}

function RichtextBox_Toggle(objid, posx, posy)
{
	var obj = document.getElementById(objid);
	if(obj.style.display == 'block')
	{
		obj.style.display = 'none';
	}
	else
	{
		obj.style.top = posy + 16 + 'px';
		obj.style.left = posx + 16 + 'px';
		obj.style.display = 'block';
	}
}

function RichtextBox_InsertAtSelection(win, content)
{
	win.focus();
	if(document.all)
	{
		var range = win.document.selection.createRange();
		range.pasteHTML(content);
		range.collapse(false);
		range.select();
	}
	else
	{
		win.document.execCommand('insertHTML', false, content);
	}
}

function RichtextBox_ToolbarClick(caller, action)
{
	switch(action)
	{
		case 'createlink':
			var szURL = prompt("Voer een link in a.u.b.", "http://");
			if((szURL != null) && (szURL != ""))
			{
				document.getElementById(caller + '_edit').contentWindow.document.execCommand("CreateLink",false,szURL);
			}
			break;
		case 'createimage':
			imagePath = currentImage;
			if((imagePath != null) && (imagePath != ""))
			{
				document.getElementById(caller + '_edit').contentWindow.document.execCommand('InsertImage', false, imagePath);
			}
			break;
		default:
			document.getElementById(caller + '_edit').contentWindow.document.execCommand(action, false, null);
			break;
	}
}

function RichtextBox_Construct(caller)
{
	if(document.all)
	{
		rte = frames[caller + "_edit"].document;
		rte.open();
		rte.write(document.getElementById(caller).value.replace('&quot;', '"'));
		rte.close();
		rte.designMode = "on";
	}
	else
	{
		document.getElementById(caller + "_edit").contentDocument.designMode = "on";
		rte = document.getElementById(caller + "_edit").contentWindow.document;
		rte.open();
		rte.write(document.getElementById(caller).value.replace('&quot;', '"'));
		rte.close();
	}
}

function RichtextBox_Update(caller)
{
	if(document.all)
	{
		document.getElementById(caller).value = frames[caller + "_edit"].document.body.innerHTML.replace('&lt;', '<').replace('&gt;', '>');
	}
	else
	{
		document.getElementById(caller).value = document.getElementById(caller + "_edit").contentWindow.document.body.innerHTML.replace('&lt;', '<').replace('&gt;', '>')
	}
}
