var editor;

function init()
{
	editor = document.getElementById("editor");
	editor.contentWindow.document.designMode = "On";
}

function command(command, value)
{
	editor.contentWindow.document.execCommand(command, false, value);
}

function NormalMode()
{
	editor.contentWindow.document.body.innerHTML = document.getElementById("code").value;
	document.getElementById("editor").style.display = "inline";
	document.getElementById("text").style.display = "none";
}

function CodeMode()
{
	document.getElementById("text").value = editor.contentWindow.document.body.innerHTML;
	document.getElementById("editor").style.display = "none";
	document.getElementById("text").style.display = "inline";
}

function setTextAreaFromIframeContent(textarea, iframe)
{
	textarea.value = iframe.contentWindow.document.body.innerHTML;
}

function addLink(url, editor_in)
{	
	editor = editor_in;
	command('CreateLink', url);
}

function addImage(url, editor_in)
{	
	editor = editor_in;
	command('insertimage', url);
	///editor.contentWindow.document.execCommand('insertimage', false, url + '"' + " id=image_1 border=0");
	///var image = editor.contentWindow.document.getElementById('image_1');
	///alert(image.width);
	//Item = new Object 
	//Item.A = '<img src='+url+'>';
	//editor.contentWindow.document.body.innerHTML = editor.contentWindow.document.body.innerHTML + Item.A;
	//alert(url);
}

function getEditorFromPopup()
{	
	return opener.document.getElementById("editor");
}

function setIframeContent(text, iframe)
{
	iframe.contentWindow.document.body.innerHTML = text;
}
