
function toggleVisible(el)
{
	if ( el.hasClass("visible") )
		el.removeClass("visible");
	else 
		el.addClass('visible');
}

/*  Attaches the event listeners so the menu shows when the right menu is clicked.
 * Gets done whenever the #mr cell (right-menu container) is ready.
 */
new YAHOO.util.Element("mr").on("contentReady", function()
{	
	var links = YAHOO.util.Selector.query(".menuLink");
	YAHOO.util.Event.on(links, "click", function(ev)
	{
		toggleVisible( new YAHOO.util.Element("menu") );
		YAHOO.util.Event.stopEvent( ev );
	});
});

if (!!document.all)
{
	YAHOO.util.Event.on(window, "load", function(){
		if ( window.FCKeditorAPI != undefined )
		{
			FCKeditorAPI.GetInstance("bodyText").Events.AttachEvent("OnPaste", 
				function(fck){
					var data = fck.GetClipboardHTML();
					data = (data+"").replace("\r", "");
					data = (data+"").replace(/<BR>/gi, "\n");
					data = (data+"").replace(/<.*?>/gi, "");
					data = (data+"").replace("&nbsp;\n", "");
					data = cleanHtml(data);
					fck.InsertHtml( data );
					
					var html = fck.GetHTML();
					html = html.replace("<p>&nbsp;</p>", "");
					fck.SetHTML(html);
					
					return false;
				});
		}
	});
}

/* This inserts p-tags at linebreaks.
 */
function cleanHtml( text )
{
	var strArray = new Array();
	
	var closeState = 0 ;
	var insertedPs = false;
	var blockStartTag = "<p>" ;
	var blockEndTag = "</p>" ;
	
	
	for ( var i = 0 ; i < text.length ; i++ )
	{
		var c = text.charAt( i ) ;
		if ( c == '\r' )
			continue ;

		if ( c != '\n' )
		{
			strArray.push( c ) ;
			continue ;
		}

		// Now we have encountered a line break.
		// Check if the next character is also a line break.
		
		strArray.push( blockEndTag ) ;
		strArray.push( blockStartTag ) ;
		insertedPs = true;
		closeState = 1 ;
	}
	
	if ( insertedPs )
		return "<p>"+strArray.join( "" )+"</p>";
	else
		return strArray.join( "" );
}


String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function clone(o)
{
	var obj = {};
	for ( f in o )
	{
		obj[f] = o[f];
	}
	return obj;
}

