
function showMessage (t,msg) {
	// t is msg type 0 = success, 1= info, 2. err
	
	var newm = dojo.byId('message');
	
	if (t == 0) {
		newm.style.color = "green"
	}
	if (t == 1) {
		newm.style.color = "#999999"
	}
	if (t == 2) {
		newm.style.color = "red"
	}	
	showMe(newm);
	newm.innerHTML = msg;
	//x = setTimeout(newm.innerHTML = "&nbsp;", 10000);
	
}

function showBlank(obj) {
	var tobj = dojo.byId(obj);
	obj.innerHTML = "&nbsp;";
	dojo.fx.html.fadeShow(tobj,600);
}

function showMe(obj) {
	var tobj = dojo.byId(obj);
	dojo.fx.html.fadeShow(tobj,600);	
}

function hideMe(obj) {
	var tobj = dojo.byId(obj);
	dojo.fx.html.fadeHide(tobj,600);
}

function isTinyMCEInstance() {
	/*  Added 0.5.22 (again!)  */
	/*
		NOT USED as of 0.5.3...
		
		Code from TinyMCE.
		Since couldnt find a method to call in
		the TinyMCE code, I copied a small portion
		of another method.
		
		Return true if a TinyMCE object exists.
	*/
	for (var n in tinyMCE.instances) {
		var inst = tinyMCE.instances[n];
		if (tinyMCE.isInstance(inst)) {
			//alert("yes");
			return true;
		} else {
			//alert("no");
			return false;
		}
	}
}


function addEditor() {
	tinyMCE.execCommand("mceAddEditor", true, "ta");
}


function removeEditor() {
	tinyMCE.execCommand("mceRemoveEditor", false, "ta");	
}

function getPageSrc() {
	//at this point, only one editor
	// but will need to change eventually
	var x = Trim(tinyMCE.getContent());	
	return x;	
}

function setPageSrc(userte,str) {
	//at this point, only one editor
	// but will need to change eventually
	var editor_on = dojo.byId('editor_on');
	
	if (userte == true) {
		if (editor_on.value == true) {
			var x = tinyMCE.setContent(str);
		} else {
			addEditor();
			var x = tinyMCE.setContent(str);
		}
		editor_on.value == true;
	} else {
		if (editor_on.value == true) {
			removeEditor();
		}
		var x = dojo.byId('ta').value = str;
		editor_on.value = false;	
	}	
	return true;	
}

function toggleEditor(userte) {
	/*  Added 0.5.22 (again!)  */
	
	if (isTinyMCEInstance()) {
		removeEditor();
		dojo.byId("btnrte").value = "Code Off";
	} else {
		addEditor();
		startEditor();
		dojo.byId("btnrte").value = "Code";
	}
	
/*	var editor_on = dojo.byId('editor_on');
	if (userte == 0) {
		removeEditor();
		editor_on.value = false;
	} else {
		if (editor_on.value == false) {
			//only run editor if already off
			addEditor();
		}
		editor_on.value = true;	
	}*/
	
}

function spacesToHyphens(str) {
	//make str lower case, trimmed, and hyphenated
	var str = dojo.string.trim(str);
	var str = str.toLowerCase();
	//match spaces only : return str.replace(/\s/g, "-");
	// this grabs anything that is "non-word" chars
	var str = str.replace(/[^\w]/g, "-");
	var str = str.replace(/-{2,}/g, "-");
	var str = dojo.string.trim(str.replace(/-$/, " "));
	
	//double check no ?
	var str = dojo.string.trim(str.replace(/\?$/, " "));
	
	return str;
}


function toggleFullRTE() {
	//if (isTinyMCEInstance()) {

removeEditor();
	if (!isTinyMCEInstance()) {
		var stylesheet = fbsiteroot() + "/editor_styles.css";
		var adv_styles = "Header 1=fontSize7;Header 2=fontSize6;Header 3=fontSize5;" + 
		"Text -3=textSize1;Text -2=textSize2;Text -1=textSize3;Text Norm=textSize4;" + 
		"Text +1=textSize5;Text +2=textSize6;Text +3=textSize7;"
		
		tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			plugins : "table, advimage, advlink, advhr, preview, zoom, flash, searchreplace, contextmenu, paste, fullscreen, noneditable, layer, style",
			entity_encoding : "numeric",
			content_css : stylesheet ,
			theme_advanced_buttons1_add : "separator, removeformat",
			theme_advanced_buttons2 : "forecolor,backcolor, bullist,numlist,undo,redo,separator, pastetext, pasteword,separator, link, unlink,separator,flash, image, advhr, separator, insertlayer, absolute, styleprops, charmap",
			theme_advanced_buttons3 : "tablecontrols, separator, preview, fullscreen, code",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			theme_advanced_styles : adv_styles,
			theme_advanced_resize_horizontal : true,
			theme_advanced_resizing : true,
			inline_styles : true,
			convert_fonts_to_spans : true,
			apply_source_formatting : true
		});
	}
}

function startEditor () {
	var stylesheet = fbsiteroot() + "/editor_styles.css";
	var adv_styles = "Header 1=fontSize7;Header 2=fontSize6;Header 3=fontSize5;" + 
	"Text -3=textSize1;Text -2=textSize2;Text -1=textSize3;Text Norm=textSize4;" + 
	"Text +1=textSize5;Text +2=textSize6;Text +3=textSize7;"
		tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			plugins : "table, advimage, advlink, advhr, preview, zoom, flash, searchreplace, contextmenu, paste, fullscreen, noneditable, layer, style",
			entity_encoding : "numeric",
			content_css : stylesheet ,
			theme_advanced_buttons1_add : "separator, removeformat",
			theme_advanced_buttons2 : "forecolor,backcolor, bullist,numlist,undo,redo,separator, pastetext, pasteword,separator, link, unlink,separator,flash, image, advhr, separator, insertlayer, absolute, styleprops, charmap",
			theme_advanced_buttons3 : "tablecontrols, separator, preview, fullscreen, code",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			theme_advanced_styles : adv_styles,
			theme_advanced_resize_horizontal : true,
			theme_advanced_resizing : true,
			inline_styles : true,
			convert_fonts_to_spans : true,
			apply_source_formatting : true
		});
/*	tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			plugins : "advimage, advlink, preview, contextmenu, paste, fullscreen",
			entity_encoding : "numeric",
			content_css : stylesheet ,
			theme_advanced_buttons1_add : "separator, removeformat",
			theme_advanced_buttons2 : "forecolor,backcolor, bullist,numlist,undo,redo,separator, pastetext, pasteword,separator, link, unlink,separator, image, separator, preview, fullscreen, separator, charmap",
			theme_advanced_buttons3 : "",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			theme_advanced_styles : adv_styles,
			theme_advanced_resize_horizontal : true,
			theme_advanced_resizing : true,
			inline_styles : true,
			convert_fonts_to_spans : true,
			apply_source_formatting : true
		});*/
		/*plugins : "table, advimage, advlink, preview, zoom, flash, searchreplace, contextmenu, paste, fullscreen",
		theme_advanced_buttons2: "forecolor,backcolor, bullist, numlist, undo, redo, pastetext, pasteword, separator, search, replace ,link, unlink",
		theme_advanced_buttons3 : "tablecontrols,separator,flash,image,preview,fullscreen,code,removeformat",*/
}

function startSimpleEditor () {
		var stylesheet = fbsiteroot() + "/fbscripts/fbsite_editor_styles.css";
		tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			entity_encoding : "numeric",
			content_css : stylesheet ,
			theme_advanced_buttons2 : "bullist,numlist,undo,redo,link,unlink,separator,removeformat",
			theme_advanced_buttons3 : "",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			theme_advanced_styles : "Header 1=fontSize7;Header 2=fontSize6;Header 3=fontSize5",
			theme_advanced_resize_horizontal : true,
			theme_advanced_resizing : true
		});
}

function startFullEditor () {
	var stylesheet = fbsiteroot() + "/editor_styles.css";
	var adv_styles = "Header 1=fontSize7;Header 2=fontSize6;Header 3=fontSize5;" + 
	"Text -3=textSize1;Text -2=textSize2;Text -1=textSize3;Text Norm=textSize4;" + 
	"Text +1=textSize5;Text +2=textSize6;Text +3=textSize7;"
	
	tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			plugins : "table, advimage, advlink, advhr, preview, zoom, flash, searchreplace, contextmenu, paste, fullscreen, noneditable, layer, style",
			entity_encoding : "numeric",
			content_css : stylesheet ,
			theme_advanced_buttons1_add : "separator, removeformat",
			theme_advanced_buttons2 : "forecolor,backcolor, bullist,numlist,undo,redo,separator, pastetext, pasteword,separator, link, unlink,separator,flash, image, advhr, separator, insertlayer, absolute, styleprops, charmap",
			theme_advanced_buttons3 : "tablecontrols, separator, preview, fullscreen, code",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			theme_advanced_styles : adv_styles,
			theme_advanced_resize_horizontal : true,
			theme_advanced_resizing : true,
			inline_styles : true,
			convert_fonts_to_spans : true,
			apply_source_formatting : true
		});
		/*plugins : "table, advimage, advlink, preview, zoom, flash, searchreplace, contextmenu, paste, fullscreen",
		theme_advanced_buttons2: "forecolor,backcolor, bullist, numlist, undo, redo, pastetext, pasteword, separator, search, replace ,link, unlink",
		theme_advanced_buttons3 : "tablecontrols,separator,flash,image,preview,fullscreen,code,removeformat",*/
}

function noeditorzz() {
/*tinyMCE.init({
			mode : "exact",
			elements : "ta",
			theme : "advanced",
			plugins : "advhr,flash,searchreplace,fullscreen,zoom,advimage",
			entity_encoding : "numeric",
			content_css : "fbsite_editor_styles.css",
			theme_advanced_buttons2 : "forecolor,backcolor, bullist,numlist,undo,redo,link,unlink,separator,search,replace,flash,advhr,image,code,fullscreen,removeformat",
			theme_advanced_buttons3 : "",
			entities : '60,lt,62,gt,38,amp,59,37,39,34,quote,96',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_styles : "Header 1=fontSize7;Header 2=fontSize6;Header 3=fontSize5",
			onchange_callback : "showMessage(2,'Your data was changed. Do not forget to save!')"
		});*/	
}