
var MOSSBASIC = {
	theme : "advanced",
	theme_advanced_resizing : true,
	theme_advanced_path : false,
	plugins : "advlink,directionality",
		theme_advanced_buttons1 : "fontselect,fontsizeselect,formatselect,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,numlist,bullist,link,unlink,|,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],kbd,code"
};																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																			  
var MOSSFULL = {
	theme : "advanced",
	theme_advanced_resizing : true,
	theme_advanced_path : false,
	plugins : "table,advimage,advlink,searchreplace,contextmenu,directionality,xhtmlxtras",
		theme_advanced_buttons1 : "cut,copy,paste,removeformat,|,search,replace,|,undo,redo,|,tablecontrols,|,link,unlink,|,forecolor,backcolor",
		theme_advanced_buttons2 : "fontselect,fontsizeselect,formatselect,|,bold,italic,underline,|,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,|,numlist,bullist,blockquote,cite,abbr,acronym,|,code",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],kbd,code"
};
	
var head = document.getElementsByTagName("head")[0]
script = document.createElement('script');
script.id = 'tinymceScript';
script.type = 'text/javascript';
head.appendChild(script);
script.src = '/_layouts/1033/tinymce3/jscripts/tiny_mce/tiny_mce.js';

function ctv_enableTinyMce() {
	if(getCookie('ctvPortalTinyMCESafariDisable')){
		return;
	}
			
	var rx = /RTE_ConvertTextAreaToRichEdit\("(\w+)"/;
	var as = document.getElementsByTagName("script");
	var enableForPage = false;
	for (i = 0; i < as.length; i++) {
		var st = as[i].text;
		if (rx.test(st)) {
			var ctlid = rx.exec(st)[1];
			if(tinymce.isWebKit && !enableForPage){
					if(!confirm('TinyMCE support for Safari is experimental. Would you like to load it?\n\nClicking cancel will prevent this dialog from appearing for the rest of your SharePoint session.')){
						setCookie('ctvPortalTinyMCESafariDisable', true); //set a cookie to not load tinymce for this session
					return;
		 		}else{
				 	enableForPage = true;
				}
			}
			if (st.indexOf('FullHtml') >= 0){
				tinyMCE.init(MOSSFULL);
			}else{
				tinyMCE.init(MOSSBASIC);
			}
			tinyMCE.execCommand("mceAddControl", false, ctlid);
		}
	}
}
_spBodyOnLoadFunctionNames.push('ctv_enableTinyMce');
		
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}