/**
 *
 * Script Name: Write Image Tag
 * The script is take from http://www.alexking.org
 * The copyright is belong to http://www.alexking.org
 *
 */

// eric 2006.02.23
function writeImgTag2( html, text, editor ) {
	if (editor == null) {
		writeImgTag(text);
	} else {
		editor.insertHTML(html);
	}
}

function writeImgTag( tag )
{
	//var myField = document.NewComment.commentText;
	var myField = document.getElementById( "commentText" );
	if(myField==null){	
		myField = document.getElementById( "postExtendedText" );
	}


	tag = ' ' + tag + ' ';
	
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = tag;
		myField.focus();
	}
	else if (myField.selectionStart || myField.selectionStart == '0') {

		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var cursorPos = endPos;
		myField.value = myField.value.substring(0, startPos)
					  + tag
					  + myField.value.substring(endPos, myField.value.length);
		cursorPos += tag.length;
		myField.focus();
		myField.selectionStart = cursorPos;
		myField.selectionEnd = cursorPos;
	}
	else {
		myField.value += tag;
		myField.focus();
	}
}
