<!--
var isIE  = (document.all) ? true : false;
var editor_focus = false;
var save_draft_timer;
var palette_mode;

function set_editor() {
	var source = '<style> P { margin: 2px 0 2px 0;} BODY { padding:5px;}</style>';
	htmleditor.document.designMode = 'On';
	htmleditor.document.open('text/html');
	htmleditor.document.write(source);
	htmleditor.document.close();
	htmleditor.document.body.style.fontSize = '13px';
	htmleditor.document.body.style.color = '#404040';
	htmleditor.document.body.style.fontFamily= 'MS P Gothic, arial';
	var innerBody = htmleditor.document.body;
	innerBody.onblur = function() { save_pos(); }
	innerBody.onfocus = function() { save_pos(); editor_focus = true; }
	innerBody.onkeypress = function() { onkeypress_html_body(); }
	//set_body();
	// htmleditor.focus();
}

function save_pos() {
	try { htmleditor.document.currentPos =  htmleditor.document.selection.createRange().duplicate(); }
	catch(e) { }
}

function onclick_editor_com(com) {
	htmleditor.document.execCommand(com, false, null);
	htmleditor.focus();
}

function onclick_editor_font(com, obj) {
       htmleditor.document.execCommand(com, null, obj.value);
	htmleditor.focus();
}

function display_palette() {
	document.getElementById('editor_palette').style.display = 'block';
}

function ck_color(color) {
	htmleditor.focus();
	if (palette_mode == '1') {
		htmleditor.document.execCommand('ForeColor', false, color);
	} else {
	       if (isIE){
			htmleditor.document.execCommand('BackColor', null, color );
		}else{
			htmleditor.document.execCommand('hilitecolor', null, color );
		}
	}
	document.getElementById('editor_palette').style.display = 'none';
}

function set_emoticon(src) {
	if (isIE) {
		var sText = htmleditor.document.currentPos;
		if (!sText) return false;
		htmleditor.document.body.focus();
		sText.pasteHTML('<img src="'+src+'" align="absmiddle">');
		sText.select();
	} else {
		htmleditor.focus();
		htmleditor.document.execCommand('insertHTML', false, '<img src="'+src+'" align="absmiddle">');
		htmleditor.focus();
	}
}

function set_image(server, path, width, position, caption) {
	var position_str = '';
	switch (position) {
		case '1': position_str = 'left'; break;
		case '2': position_str = 'center'; break;
		case '3': position_str = 'right'; break;
	}
	if (isIE) {
        htmleditor.focus();
        htmleditor.document.execCommand('insertimage', false, '/' + path);
		
/*
	    var sText = lasttr;
		//var sText = htmleditor.document.currentPos;
		if (!sText) return false;
		htmleditor.document.body.focus();

		sText.pasteHTML(path);
		//alert(htmleditor.document.body.innerHTML);
		if(caption) {
			sText.pasteHTML('<div align="'+position_str+'"><img src="/'+path+'"><p style="text-align:center;">'+caption+'</p></div>');
		} else {
			sText.pasteHTML('<div align="'+position_str+'"><img src="/'+path+'"></div>');
		}
		
		sText.select();
*/
		htmleditor.focus();
		
	} else {
		htmleditor.focus();
		if(caption) {
			htmleditor.document.execCommand('insertHTML', false, '<div align="'+position_str+'"><img src="/'+path+'"><p style="text-align:center;">'+caption+'</p></div>');
		} else {
			htmleditor.document.execCommand('insertHTML', false, '<div align="'+position_str+'"><img src="/'+path+'"></div>');
		}
		htmleditor.focus();

	}
}
function onclick_attach_image() {
	window.open('/system/editor_add_image/','a_i','width=400,height=370');
	
}

function onclick_add_link() {
	window.open('/system/editor_add_link/','a_i','width=400,height=220');
}

function gotolink(urlto,optionStr) {
	if (isIE) {
		var sText = htmleditor.document.currentPos;
		if (!sText) return false;
		htmleditor.document.body.focus();
		sText.pasteHTML("<A href=\"" + urlto + "\" " + optionStr + ">" +  htmleditor.document.selection.createRange().text + "</A>");
		sText.select();
	} else {
		 
		 var range = document.getElementById('htmleditor').contentWindow.getSelection().getRangeAt(0) 

		htmleditor.focus();
		htmleditor.document.execCommand('insertHTML', false, "<A href=\"" + urlto + "\" " + optionStr + ">" + range.toString() + "</A>");
		htmleditor.focus();

	}
		 
		 
}

function onkeypress_html_body() {
	if (save_draft_timer) window.clearInterval(save_draft_timer);
	save_draft_timer = window.setInterval('save_draft()', 5000);
}

-->
