var editor;
var link_window;
var textarea;
var browser;

var iframeCSS = '<style type="text/css"> body{ margin:0px; padding:0px; font-family:Verdana; font-size:12px; color:#000; border:0px; }</style>';

var netscape = "Netscape";
var IE = "Microsoft Internet Explorer";

	function init()
	{
		browser = navigator.appName;

		textarea = document.getElementById("message");
		textarea.style.display = "none"; 
		document.getElementById("message_div").style.height = "140px";
		document.getElementById("rogerEditor").style.display = "inline";
		editor = document.getElementById("rogerEditor").contentWindow;
		
		//if (editor.body.contentEditable) { editor.body.contentEditable = true; } else { editor.designMode = "on"; }
		
			editor.document.designMode = "on";
			//editor.execCommand('useCSS', false, true);
			//editor.execCommand('styleWithCSS', false, true);
		
		
		document.getElementById("toolbar").style.display = "block"; 
		
		editor.document.open();
		editor.document.write(iframeCSS);
		editor.document.write(textarea.value);
		editor.document.close();

		try{editor.document.attachEvent('onkeyup',preSubmit);}
		catch(e){editor.document.addEventListener('keyup',preSubmit,false);}

		if(textarea.onkeyup != null)
		{
			try{editor.document.attachEvent('onkeyup',textarea.onkeyup);}
			catch(e){editor.document.addEventListener('keyup',textarea.onkeyup,false);}
		}
		
		try{editor.document.execCommand('styleWithCSS', false, false);}
		catch(e){}
	}
	
	function makeBold()
	{
		editor.document.execCommand('bold', false, null);
		editor.focus();
	}
	
	function makeItalic()
	{
		editor.document.execCommand('italic', false, null);
		editor.focus();
	}
	
	function makeUnderline()
	{
		editor.document.execCommand('underline', false, null);
		editor.focus();
	}
	
	function makeLink()
	{
		var url = prompt("Var god ange url","http://");
		if(url != null && url != "")
			editor.document.execCommand('CreateLink', false, url);
		editor.focus();
	}
	
	function unLink()
	{
		editor.document.execCommand('Unlink', false, null);
		editor.focus();
	}
	
	function preSubmit()
	{
		textarea.value = editor.document.body.innerHTML;
	}

	function show()
	{
		textarea.style.display = "block"; 
		document.getElementById("message_div").style.height = "250px";
		document.getElementById("rogerEditor").style.display = "block";
	}
