function FTB_Format(editor,htmlmode,format) {
	if (htmlmode) return; 
	editor.focus();
	editor.document.execCommand(format,'',null);
}
function FTB_Bold(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'bold'); 
}



function FTB_Italic(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'italic'); 
}
function FTB_Underline(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'underline'); 
}
function FTB_Strikethrough(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'strikethrough'); 
}
function FTB_Superscript(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'superscript'); 
}
function FTB_Subscript(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'subscript'); 
}
function FTB_RemoveFormat(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'removeFormat'); 
}
function FTB_JustifyLeft(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'justifyleft'); 
}
function FTB_JustifyRight(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'justifyright'); 
}
function FTB_JustifyCenter(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'justifycenter'); 
}
function FTB_JustifyFull(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'justifyfull'); 
}
function FTB_BulletedList(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'insertunorderedlist'); 
}
function FTB_NumberedList(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'insertorderedlist'); 
}
function FTB_Indent(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'indent'); 
}
function FTB_Outdent(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'outdent'); 
}
function FTB_Cut(editor,htmlmode) {
	editor.focus();
	editor.document.execCommand('cut','',null);
}
function FTB_Copy(editor,htmlmode) {
	editor.focus();
	editor.document.execCommand('copy','',null);
}
function FTB_Paste(editor,htmlmode) {
	editor.focus();
	editor.document.execCommand('paste','',null);
}

function FTB_insertcontentpager(editor,htmlmode){



editor.focus();
sel = editor.document.selection.createRange();
        
sel.pasteHTML('[GF2-NEXTPAGE]'); 


}


function FTB_Undo(editor,htmlmode) {
	editor.focus();
	editor.document.execCommand('undo','',null);
}
function FTB_Redo(editor,htmlmode) {
	editor.focus();
 	editor.document.execCommand('redo','',null);
}
function FTB_Delete(editor,htmlmode) {
	if (confirm('确实要删除编辑器中所有的文字和 HTML 代码吗？')) {	
		editor.document.body.innerHTML = '';
		editor.document.body.innerText = '';
	}
	editor.focus();
}
function FTB_CreateLink(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
    editor.document.execCommand('createlink','1',null);
}
function FTB_Unlink(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
    editor.document.execCommand('unlink','1',null);
}
function FTB_InsertImage(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'InsertFile.aspx?Tag=5';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:420px; dialogHeight:260px;help:0;status:0;resizeable:0;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}
function FTB_InsertFlash(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'InsertFile.aspx?Tag=2';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:420px; dialogHeight:260px;help:0;status:0;resizeable:0;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}
function FTB_InsertMedia(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'InsertFile.aspx?Tag=3';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:420px; dialogHeight:260px;help:0;status:0;resizeable:0;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}
function FTB_InsertReal(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'InsertFile.aspx?Tag=4';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:420px; dialogHeight:260px;help:0;status:0;resizeable:0;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}
function FTB_InsertMood(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'InsertFile.aspx?Tag=6';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:420px; dialogHeight:260px;help:0;status:0;resizeable:0;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}
function FTB_BatchUpload(editor,htmlmode) {
	if (htmlmode) return;
	editor.focus();
	var galleryscript = 'BatchUpload.aspx';
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:600px; dialogHeight:350px;help:0;status:0;resizeable:1;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		sel = editor.document.selection.createRange();
		sel.pasteHTML(imagestring);
	}
}

function insertCC(str)
{
    editor = txtContent_editor;
    editor.focus();
    sel = editor.document.selection.createRange();
	sel.pasteHTML(str);    
}

function FTB_InsertRule(editor,htmlmode) { 
	FTB_Format(editor,htmlmode,'inserthorizontalrule'); 
}
function FTB_InsertDate(editor,htmlmode) {
	editor.focus();
	var d = new Date();
	sel = editor.document.selection.createRange();
	sel.pasteHTML(d.toLocaleDateString());
}
function FTB_InsertTime(editor,htmlmode) {
	editor.focus();
	var d = new Date();
	sel = editor.document.selection.createRange();
	sel.pasteHTML(d.toLocaleTimeString());
}
function FTB_SetFontFace(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	editor.document.execCommand('fontname','',value);
}
function FTB_SetFontSize(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	editor.document.execCommand('fontsize','',value);


}
function FTB_SetFontForeColor(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	editor.document.execCommand('forecolor','',value);
}
function FTB_InsertSymbol(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	sel = editor.document.selection.createRange();
	sel.pasteHTML(value);
}

function FTB_CopyHtmlToHidden(editor,hiddenHtml,htmlmode) {
	if (htmlmode) {
		hiddenHtml.value = editor.document.body.innerText;  
	} else {
		hiddenHtml.value = editor.document.body.innerHTML;  
	}
	if (hiddenHtml.value == '<P>&nbsp;</P>') {
		hiddenHtml.value = '';
		editor.document.body.innerText = '';
		editor.document.body.innerHTML = '';
	}
}
function FTB_CheckTag(item,tagName) {
	if (item.tagName.search(tagName)!=-1) {
		return item;
	}
	if (item.tagName=='BODY') {
		return false;
	}
	item=item.parentElement;
	return FTB_CheckTag(item,tagName);
}
function FTB_CharBefore(sel) {
	if (sel.move('character',-1) == -1) {
		sel.expand('character');
		return sel.text;
	} else {
		return 'start';
	}
}
function FTB_CharAfter(sel) {
	var sel2 = sel;
	if (sel.expand('character')) {
		sel2.move('character',1);
		sel2.expand('character');
		return sel2.text;
	} else {
		return 'end';
	}
}
function FTB_CharBefore(r) {
	if (r.move('character',-1) == -1) {
		r.expand('character');
		return r.text;
	} else {
		return 'start';
	}
}
function FTB_CharAfter(r) {
	var r2 = r;
	if (r.expand('character')) {
		r2.move('character',1);
		r2.expand('character');
		return r2.text;
	} else {
		return 'end';
	}
}
function FTB_GetRangeReference(editor) {
	editor.focus();
	var objReference = null;
	var RangeType = editor.document.selection.type;
	var selectedRange = editor.document.selection.createRange();

	switch(RangeType) {
		case 'Control' :
			if (selectedRange.length > 0 )  {
				objReference = selectedRange.item(0);
			}
			break;

		case 'None' :
			objReference = selectedRange.parentElement();
			break;

		case 'Text' :
			objReference = selectedRange.parentElement();
			break;
	}
	return objReference
}
// ********************************************
// Style Functions
// ********************************************
function FTB_SetButtonStyle(buttonTD,style,checkstyle) {
	if (buttonTD == null) return;
	if (buttonTD.className != checkstyle)
		buttonTD.className = style;
}
function FTB_GetClassSubName(className) {
	underscore = className.indexOf("_");
	if (underscore < 0) return className;
	return className.substring(underscore+1);
}
function FTB_SetActiveTab(theTD,editorname) {
	parentTR = theTD.parentElement;
	selectedTab = 1;
	totalButtons = parentTR.cells.length-1;
	for (var i=1;i< totalButtons;i++) {
		parentTR.cells[i].className = editorname + "_TabOffRight";
		if (theTD == parentTR.cells[i]) { selectedTab = i; }

	}

	if (selectedTab==1) {
		parentTR.cells[0].className = editorname + "_StartTabOn";
	} else {
		parentTR.cells[0].className = editorname + "_StartTabOff";
		parentTR.cells[selectedTab-1].className = editorname + "_TabOffLeft";
	}

	theTD.className = editorname + "_TabOn";
}
