var browser = '';
FtGetBrowser();
function FtSelection()
{
	if (browser == 'IE') {
	    parent.document.frames("FtEditorForm").focus();
		SELECTION = parent.document.frames("FtEditorForm").document.selection;
		RANGE = SELECTION.createRange();
		RANGE_TEXT = RANGE.text;
	} else {
		SELECTION = parent.document.getElementById("FtEditorForm").contentWindow.getSelection();
        RANGE = SELECTION.getRangeAt(0);
		RANGE_TEXT = RANGE.toString();
	}
}
//Íù¸¸±à¼­Æ÷ÖÐ²åÈë´úÂë
function FtInsertItem(insertNode)
{
	if (browser == 'IE') {
		if (SELECTION.type.toLowerCase() == 'control') {
			RANGE.item(0).outerHTML = insertNode.outerHTML;
		} else {
			RANGE.pasteHTML(insertNode.outerHTML);
		}
	} else {
        SELECTION.removeAllRanges();
		RANGE.deleteContents();
        var startRangeNode = RANGE.startContainer;
        var startRangeOffset = RANGE.startOffset;
        var newRange = parent.document.createRange();
		if (startRangeNode.nodeType == 3 && insertNode.nodeType == 3) {
            startRangeNode.insertData(startRangeOffset, insertNode.nodeValue);
            newRange.setEnd(startRangeNode, startRangeOffset + insertNode.length);
            newRange.setStart(startRangeNode, startRangeOffset + insertNode.length);
        } else {
            var afterNode;
            if (startRangeNode.nodeType == 3) {
                var textNode = startRangeNode;
                startRangeNode = textNode.parentNode;
                var text = textNode.nodeValue;
                var textBefore = text.substr(0, startRangeOffset);
                var textAfter = text.substr(startRangeOffset);
                var beforeNode = parent.document.createTextNode(textBefore);
                var afterNode = parent.document.createTextNode(textAfter);
                startRangeNode.insertBefore(afterNode, textNode);
                startRangeNode.insertBefore(insertNode, afterNode);
                startRangeNode.insertBefore(beforeNode, insertNode);
                startRangeNode.removeChild(textNode);
            } else {
				if (startRangeNode.tagName.toLowerCase() == 'html') {
					startRangeNode = startRangeNode.childNodes[0].nextSibling;
					afterNode = startRangeNode.childNodes[0];
				} else {
					afterNode = startRangeNode.childNodes[startRangeOffset];
				}
				startRangeNode.insertBefore(insertNode, afterNode);
            }
            newRange.setEnd(afterNode, 0);
            newRange.setStart(afterNode, 0);
        }
        SELECTION.addRange(newRange);
	}
}
function FtGetBrowser()
{
	var agentInfo = navigator.userAgent.toLowerCase();
	if (agentInfo.indexOf("msie") > -1) {
		var re = new RegExp("msie\\s?([\\d\\.]+)","ig");
		var arr = re.exec(agentInfo);
		if (parseInt(RegExp.$1) >= 5.5) {
			browser = 'IE';
		}
	} else if (agentInfo.indexOf("firefox") > -1) {
		browser = 'FF';
	} else if (agentInfo.indexOf("netscape") > -1) {
		var temp1 = agentInfo.split(' ');
		var temp2 = temp1[temp1.length-1].split('/');
		if (parseInt(temp2[1]) >= 7) {
			browser = 'NS';
		}
	} else if (agentInfo.indexOf("gecko") > -1) {
		browser = 'ML';
	} else if (agentInfo.indexOf("opera") > -1) {
		var temp1 = agentInfo.split(' ');
		var temp2 = temp1[0].split('/');
		if (parseInt(temp2[1]) >= 9) {
			browser = 'OPERA';
		}
	}
	return browser;
}