// equivalent of PHP urlencode
function urlencode( str )
{
	var ret = str;
	if(typeof str == 'string')
	{
	     ret = ret.toString();
    	ret = encodeURIComponent(ret);
    	ret = ret.replace(/%20/g, '+');
	}
	return ret;
}
// equivalent of PHP urldecode
function urldecode( str )
{
	var ret = str;
	if(typeof str == 'string')
	{
	    ret = ret.replace(/\+/g, '%20');
	    ret = decodeURIComponent(ret);
	    ret = ret.toString();
	}
	return ret;
}

// get FCK content
function GetFCKContent(id)
{
	var content = FCKeditorAPI.GetInstance(id).GetXHTML(); // retrieve the fck field
	$(id).value = content; // this reassigns the value from the fck instance back to the hidden field so you can call data:$(\'myform\') in the ajax

	// sometimes the function mysteriously returns null, try again
	if(content === null)
	{
		return GetFCKContent(id);
	}
	else
	{
		// escape because it is used in the AJAX POST parameters.
		return urlencode(content);
	}
}
// set FCK editor content
function setFCKContent(id, value)
{
	FCKeditorAPI.GetInstance(id).SetHTML(value);
}
function displayMenu(parent, name)
{
	if(typeof menu_parent != 'undefined' && menu_parent == parent)
	{
		hideMenu();
	}
	else
	{
		hideMenu();

		menu_element = document.getElementById(name);
		menu_parent = parent;

		flipButton(parent);

		var element = menu_element;

		if(element.style.display != 'block')
		{
			element.style.display = 'block';
		}
		else
		{
			element.style.display = 'none';
		}
	}
}

function hideMenu(){

		if(typeof menu_parent != 'undefined'){
			flipButton(menu_parent);}

		if(typeof menu_element != 'undefined' && menu_element.style){
			menu_element.style.display = 'none';}

		menu_parent = '';
		menu_element = '';}

function flipButton(button){

	if(button.className == 'Button'){
		button.className = 'ActiveButton';}
	else if(button.className == 'ActiveButton'){
		button.className = 'Button';}}

function openPopup(url, name, width, height){

	window.open(url, name, 'scrollbars,width='+width+',height='+height);}

function showWaitBox(type){

	var type;

	document.getElementById('WaitBox').style.display = 'block';

	if(type == 'ModulePage'){
		document.getElementById('FadeBoxModulePage').style.display = 'block';}
	else if(type == 'EditPage'){
		document.getElementById('FadeBoxEditPage').style.display = 'block';}}