var admin_active_tab = "desktop";
var original_sidebar_height = 641;

/**
* Fade in the error message when there is one
**/

function goToHomepage()
{
	window.location.href = "http://www.floorball-stimulo.be";
}

function openWindow(action, title)
{
	window.open(action, title);
}

function showErrorMessage()
{
	if($('#message-blok').html() != "")
	{
		$('#message-blok').fadeIn("slow");
	}
}

function initSidebarHeight(reset)
{
	var sidebar_height = "";
	var content_height = $("#content").height();
	
	if(reset == true)
	{
		sidebar_height = original_sidebar_height;
	}
	else
	{
		var right_sidebar_height = $("#right-sidebar").height();
		var left_sidebar_height = $("#left-sidebar").height();
		
		sidebar_height = left_sidebar_height;
		
		if(right_sidebar_height > left_sidebar_height)
		{
			sidebar_height = right_sidebar_height;
		}
	}
	
	if(content_height > sidebar_height)
	{
		sidebar_height = content_height;
	}
	
	$("#left-sidebar").css("height", sidebar_height + "px");
	$("#right-sidebar").css("height", sidebar_height + "px");
}

/**
 * Show the password field and hide the dummy password field
 */
function showPasswordField()
{
	//hide the dummy field
	$('#login-password-dummy').css('display', 'none');
	
	//show the real password field
	$('#login-password').css('display', 'block');
	$('#login-password').focus();
}

/**
 * Show the dummy password field and hide the password field
 */
function showPasswordDummyField()
{
	var temp_password = $('#login-password').val();
	
	if(temp_password == '')
	{
		//hide the real password field
		$('#login-password').css('display', 'none');
		
		//show the dummy field
		$('#login-password-dummy').css('display', 'block');
	}
}

/**
 * Show the default username in the username field
 */
function showDefaultUsername()
{
	var default_username = 'Gebruikersnaam...';
	var temp_username = $('#login-username').val();
	
	//if the user didn't fill in the username, then show the default text again
	if(temp_username == '')
	{
		$('#login-username').val(default_username);
		$('#login-username').css('color', '#999999');
	}
}

/**
 * Clear the default username in the username field
 */
function clearUsernameField()
{
	var default_username = 'Gebruikersnaam...';
	var temp_username = $('#login-username').val();
	
	//if the username is the default username, then clear the text
	if(temp_username == default_username)
	{
		$('#login-username').val('');
		$('#login-username').css('color', '#000000');
		$('#login-username').focus();
	}
}

/**
 * Hide a certain div
 * 
 * @param id
 */
function hideDiv(id)
{
	var element_id = "#" + id;
	$(element_id).fadeOut("slow");
}

/**
 * Show a certain div
 * 
 * @param id
 */
function showDiv(id)
{
	var element_id = "#" + id;
	$(element_id).fadeIn("slow");
}

function show_node_image_upload_form()
{
	$('#upload-node-image-placeholder').fadeOut("slow", function()
	{
		$('#product-gallery-upload-form-placeholder').fadeIn("slow");
	});
	
}

/**
 * Remove the currency sign from the string
 **/
function removeCurrencySign(valuta_string)
{
	//split the string
	var valuta_array = valuta_string.split(" ");
	
	//return only the decimal part of the string
	var valuta_decimal = valuta_array[1];
	valuta_decimal = replaceChar(valuta_decimal, ',', '.');

	return valuta_decimal;
}

/**
 * Add the currency sign to the value
 **/
function addCurrencySign(value)
{
	value = Math.round(value*100)/100;
	value = value.toString();
	value = replaceChar(value, '.', ',');
	value_length = value.length;
	
	if(value.indexOf(',') == -1)
	{
		value = value + ',00';
	}
	else
	{
		if(value.indexOf(',') > (value_length - 3))
		{
			value = value + '0';
		}
	}
	
	value = '€ ' + value;
	return value;
}

/**
 * Replace all characters in the string
 **/
function replaceChar(string, char_to_replace, replace_with_char)
{
	var string_array = string.split(char_to_replace);
	
	var array_length = string_array.length;
	var result_string = '';
	
	for(i=0; i<array_length; i++)
	{
		result_string += string_array[i];
		
		if(i < (array_length - 1))
		{
			result_string += replace_with_char;
		}
	}
	
	return result_string;
}

/**
 * Check if an element with a certain id exists on this page
 * 
 * @return boolean
 */
function checkElementExistsById(element_id)
{
	var exists = false;
	
	if($("#" + element_id).length > 0)
	{
		exists = true;
	}
	
	return exists;
}

function event_onmouseoverMenu(id)
{
	var menuID = '#' + id;
	var menuLinkID = menuID + ' a';
	$(menuID).css("background-image","url(img/button_hover_bg.jpg)");
	$(menuID).css("cursor","pointer");
	$(menuLinkID).css("color","#f550a6");
}

function event_onmouseoutMenu(id)
{
	var menuID = '#' + id;
	var menuLinkID = menuID + ' a';
	$(menuID).css("background-image","url(img/button_bg.jpg)");
	$(menuLinkID).css("color","#FFFFFF");
}

function event_onclickMenu(url)
{
	window.location.href = url;
}

/**
 * Admin actions in the admin overview lists
 * 
 * @param type
 * @param action
 * @param item_id
 * @return
 */
function adminAction(type, action, item_id)
{
	var go = false;
	
	if(action == "delete")
	{
		deleteConfirm = confirm("Bent u zeker dat u " + type + " " + item_id + " wil verwijderen?");
		
		if (deleteConfirm != 0)
		{
			go = true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		go = true;
	}
	
	//only when we can make the call to the server, we check the type of call to define the action
	if(go)
	{
		switch(type)
		{
			case 'node':
				ajaxAdminNode(item_id, action);
			break;
			
			case 'sponsor':
				ajaxAdminSponsor(item_id, action);
			break;
			
			case 'forum':
				ajaxAdminForum(item_id, action);
			break;
			
			case 'topic':
				ajaxAdminTopic(item_id, action);
			break;
			
			case 'news':
				ajaxAdminNews(item_id, action);
			break;
			
			case 'user':
				ajaxAdminUser(item_id, action);
			break;
			
			case 'category':
				ajaxAdminCategory(item_id, action);
			break;
			
			case 'activity':
				ajaxAdminActivity(item_id, action);
			break;
			
			case 'training':
				ajaxAdminTraining(item_id, action);
			break;
			
			case 'download':
				ajaxAdminDownload(item_id, action);
			break;
			
			case 'link':
				ajaxAdminLink(item_id, action);
			break;
		}
	}
}

/**
 * Gallery actions in the admin overview lists
 * 
 * @param type
 * @param action
 * @param item_id
 * @param img_id
 * @return
 */
function galleryAction(type, action, item_id, img_id)
{
	var go = false;
	
	if(action == "delete")
	{
		deleteConfirm = confirm("Bent u zeker dat u " + type + " afbeelding " + img_id + " wil verwijderen?");
		
		if (deleteConfirm != 0)
		{
			go = true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		go = true;
	}
	
	//only when we can make the call to the server, we check the type of call to define the action
	if(go)
	{
		switch(type)
		{
			case 'node':
				ajaxAdminNodeGallery(item_id, img_id, action);
			break;
			
			case 'sponsor':
				ajaxAdminSponsorGallery(item_id, img_id ,action);
			break;
		}
	}
}

function onlyNumbers(value)
{
	//if the field is empty then enter 0 as marge
	if(value == "")
	{
		return false;
	}
	
	/*//replace a ' with a .
	if(value.indexOf(",") != -1)
	{
		value = replaceChar(value, ',', '.');
	}
	
	//check the length of the value
	if(value != '0')
	{
		var error = false;
		if(value.length > 6)
		{
			var decimal_position = value.indexOf(".");
			
			if(decimal_position == -1 || decimal_position > 6)
			{
				error = true;
			}
		}
		
		if(error)
		{
			alert("Het getal mag maximaal 6 cijfers met 2 decimalen bevatten.");
			return false;
		}
	}*/

	//only numbers are allowed
	if(isNaN(value))
	{
		alert("Enkel getallen zijn toegelaten.");
		return false;
	}
}

function showImage(src)
{
	$("#node-image-gallery-loader img").fadeOut("slow", function()
	{
		$("#node-image-gallery-loader img").attr("src", src);
		$("#node-image-gallery-loader img").load(function()
		{
			$("#node-image-gallery-loader img").fadeIn("slow");
		});
	});
}

function moveOptions(srcSel, targetSel, loc)
{
	//loop through options until we do not have any more selected options
	while(srcSel.selectedIndex != -1)
	{
	    //figure out our current selection
	    var indx = srcSel.selectedIndex;
	    
		//make a copy of the option
	    var cpy = srcSel.options[indx].cloneNode(true);
	    
		//remove the option from the list
	    srcSel.options[indx] = null;
	   
	    //determine if we have any options
	    var len = targetSel.options.length;
	   
	    //If we have no options we can append it
	    if(len===0)
		{
	      targetSel.appendChild(cpy);
	    }
	    else
		{
	        //determine if we add to the top or bottom of the list
	        //Append either at the last child, or at index zero
	        var locOpt = (loc !== "top")? targetSel.options[len-1].nextSibling : 
	                                      targetSel.options[0];
	        //Insert our coned copy of the option we removed
	        targetSel.insertBefore(cpy, locOpt);
	    }
	}
}

function moveAllOptions( srcSel, targetSel, loc )
{
	//Check to see if our select is multiple        
	var isMulti = true;
	if(!srcSel.multiple)
	{
	    //if not, set it to multiple to make selection easier
	    isMulti = false;
	    srcSel.multiple = true;
	}
	
	//loop through our options and select it
	var opts = srcSel.options;
	for(var i=opts.length-1;i>=0;i--)
	{
	    opts[i].selected = true;
	}
	
	//Call our move method
	moveOptions(srcSel, targetSel, loc);
	
	//If the select element was not multiple, reset it back
	if(!isMulti)
	{
	    srcSel.multiple = false;
	}
}

/**
 * Perform a search action on the site using ajax to search in the database
 * @return
 */
function ajaxSearch()
{ 
	var search_val = $("#searchform-box").val();
	
	var type = 'search';
	
	$.post(type, {type: type, search_term : search_val}, function(data)
	{
		if (data.length > 0)
		{ 
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the menu with ajax calls to refresh the content
 * @param menu_id
 * @param menu_type
 * @return
 */
function ajaxMenu(menu_id, menu_type)
{ 
	var type = "menu";
	
	$.get(type, {type: type, cid : menu_id, mode: 'content'}, function(data)
	{
		toggle_navigation_submenu(menu_id, menu_type);
		
		if(data.length > 0)
		{
			$("#content").html(data);
			
			initSidebarHeight(true);
		}
	});
}

/**
 * AJAX Browse the node items with ajax calls to refresh the content
 * @param nid
 * @return
 */
function ajaxNode(nid)
{ 
	var type = "node";
	
	$.get(type, {type: type, nid : nid, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the sponsor items with ajax calls to refresh the content
 * @param sid
 * @return
 */
function ajaxSponsor(sid)
{ 
	var type = "sponsor";
	
	$.get(type, {type: type, sid : sid, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Return the Sponsor images into a grid
 * @param sid
 * @return
 */
function ajaxSponsors()
{ 
	var type = "sponsors";
	
	$.get(type, {type: type, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the news items with ajax calls to refresh the content
 * @param news_id
 * @return
 */
function ajaxNews(news_id)
{ 
	var type = "news";
	
	$.get(type, {type: type, newsid : news_id, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse to an overview page of all the active news items
 * @return
 */
function ajaxNewsOverview()
{
	var type = "news_all";
	
	$.get(type, {type: type, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the activity items with ajax calls to refresh the content
 * @param activity_id
 * @return
 */
function ajaxActivity(activity_id)
{
	var type = "activity";
	
	$.get(type, {type: type, activityid : activity_id, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse to an overview page of all the active activity items
 * @return
 */
function ajaxActivitiesOverview()
{
	var type = "activities_all";
	
	$.get(type, {type: type, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Get the content of the activity date options
 * @return
 */
function ajaxReccuringActivity()
{
	//get the value of the checkbox
	var checkbox_value = $('#recurring-activity-checkbox:checked').val();
	
	if(checkbox_value == 'on')
	{
		checkbox_value = 'recurring';
	}
	else
	{
		checkbox_value = 'single';
	}
	
	var type = "admin_recurring_activity";
	
	$.get(type, {type: type, action: checkbox_value, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#activities-edit-date-placeholder").html(data); 
		} 
	});
}

var activity_exception = 2;

/**
 * AJAX Get the content of the activity exception part
 * @return
 */
function ajaxExceptionActivity()
{
	var type = "admin_exception_activity";
	
	$.get(type, {type: type, action: activity_exception, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#activities-exception-placeholder").append(data);
			
			//set the number of exceptions on the activity form
			activity_exception++;
		} 
	});
}

/**
 * AJAX Browse the calendar with ajax calls to refresh the content
 * @param month
 * @param year
 * @param tid
 * @return
 */
function ajaxCalendar(month, year, tid)
{
	var type = 'kalender';
	
	$.get(type, {type: type, page: month, year: year, tid: tid, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{ 
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the forum with ajax calls to refresh the content
 * @param forum_id
 * @return
 */
function ajaxForum(forum_id)
{ 
	var type = "forum";
	
	$.get(type, {type: type, fid: forum_id, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * AJAX Browse the topics with ajax calls to refresh the content
 * @param topic_id
 * @return
 */
function ajaxTopic(topic_id)
{ 
	var type = "topic";
	
	$.get(type, {type: type, tid: topic_id, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * Silde open and close submenus
 * @param menu_id
 * @param menu_type
 * @return
 */
function toggle_navigation_submenu(menu_id, menu_type)
{
	switch(menu_type)
	{
		case 'submenu':
			extra = 'sub-';
			
			$(".block-content-sub-submenu-placeholder").slideUp("slow");
		break;
		
		case 'sub-submenu':
			
		break;
	
		default:
			extra = '';
			
			$(".block-content-sub-submenu-placeholder").slideUp("slow");
		break;
	}
	
	if(menu_type == 'main')
	{
		$(".block-content-submenu-placeholder").slideUp("slow", function()
		{
			initSidebarHeight(false);
		});
	}
	
	menu_id = "#" + extra + "submenu-placeholder-" + menu_id;
	
	$(menu_id).slideDown("slow", function()
	{
		initSidebarHeight(false);
	});
}

/**
 * Toggle the calendar tooltip on or off
 * @param id
 * @return
 */
function toggle_calendar_tooltip(id)
{
	$('.calendar-day-tooltip').fadeOut("slow");
	
	$('#' + id).slideDown('slow');
}

/**
 * load new data, returned from an ajax call into a placeholder
 * @param placeholder_id
 * @param data
 * @return
 */
function event_showLoadedAjaxContent(placeholder_id, data)
{
	//fade out the old content and fade in the new content
	$("#" + placeholder_id).fadeOut("fast", function()
	{
		$("#" + placeholder_id).html(data);
		$("#" + placeholder_id).fadeIn("fast");
	});
	
	initSidebarHeight(true);
}

/**
 * When an ajaxAdminCall is loaded successfully, then show the data
 * @param data
 * @return
 */
function event_on_ajaxAdminCall_Success(data)
{
	var admin_placeholder_id = 'admin-content-placeholder';
	
	//fade out the old content and fade in the new content
	event_showLoadedAjaxContent(admin_placeholder_id, data);
}

/**
 * AJAX When the admin clicks an item in the control panel
 * @param type
 * @return
 */
function ajaxAdminCall(type)
{
	$.get(type, {type: type, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin user actions
 * @param type
 * @param loginname
 * @param action
 * @return
 */
function ajaxAdminUser(loginname, action)
{
	var type = 'admin_user_action';
	
	$.get(type, {type: type, loginname : loginname, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin news actions
 * @param newsid
 * @param action
 * @return
 */
function ajaxAdminNews(newsid, action)
{
	var type = 'admin_news_action';
	
	$.get(type, {type: type, newsid : newsid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin activity actions
 * @param activity_id
 * @param action
 * @return
 */
function ajaxAdminActivity(activity_id, action)
{
	var type = 'admin_activity_action';
	
	$.get(type, {type: type, activityid : activity_id, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin node actions
 * @param nid
 * @param action
 * @return
 */
function ajaxAdminNode(nid, action)
{
	var type = 'admin_node_action';
	
	$.get(type, {type: type, nid : nid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin node gallery actions
 * @param nid
 * @param img_id
 * @param action
 * @return
 */
function ajaxAdminNodeGallery(nid, img_id, action)
{
	var type = 'admin_node_gallery_action';
	
	$.get(type, {type: type, nid : nid, imageid: img_id, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin forum actions
 * @param fid
 * @param action
 * @return
 */
function ajaxAdminForum(fid, action)
{
	var type = 'admin_forum_action';
	
	$.get(type, {type: type, fid : fid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin topic actions
 * @param tid
 * @param action
 * @return
 */
function ajaxAdminTopic(tid, action)
{
	var type = 'admin_topic_action';
	
	$.get(type, {type: type, tid : tid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin sponsor actions
 * @param sid
 * @param action
 * @return
 */
function ajaxAdminSponsor(sid, action)
{
	var type = 'admin_sponsor_action';
	
	$.get(type, {type: type, sid : sid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin sponsor gallery actions
 * @param sid
 * @param img_id
 * @param action
 * @return
 */
function ajaxAdminSponsorGallery(sid, img_id, action)
{
	var type = 'admin_sponsor_gallery_action';
	
	$.get(type, {type: type, sid : sid, imageid: img_id, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin download actions
 * @param downloadid
 * @param action
 * @return
 */
function ajaxAdminDownload(downloadid, action)
{
	var type = 'admin_download_action';
	
	$.get(type, {type: type, downloadid : downloadid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}

/**
 * AJAX Admin link actions
 * @param linkid
 * @param action
 * @return
 */
function ajaxAdminLink(linkid, action)
{
	var type = 'admin_link_action';
	
	$.get(type, {type: type, downloadid : linkid, action : action, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//show the new data
			event_on_ajaxAdminCall_Success(data);
		} 
	});
}


/**
 * Post of an admin form
 * @param type
 * @return
 */
function ajaxAdminPost(type)
{
	var form_id = '';
	var fields = '';
	var placeholder_id = '';
	
	switch(type)
	{
		case 'user_admin':
			form_id = "admin-user-form";
		break;
		
		case 'category_admin':
			form_id = "admin-category-form";
		break;
		
		case 'product_admin':
			form_id = "admin-product-form";
		break;
		
		case 'news_admin':
			form_id = "admin-news-form";
		break;
		
		case 'node_admin':
			form_id = "admin-node-form";
		break;
		
		case 'node_images_admin':
			form_id = "admin-node-images-form";
		break;
		
		case 'upload_image':
			form_id = "admin-upload-form";
		break;
		
		case 'sponsor_admin':
			form_id = "admin-sponsor-form";
		break;
		
		case 'permission_admin':
			form_id = "admin-permission-form";
		break;
		
		case 'module_admin':
			form_id = "admin-module-form";
		break;
		
		case 'help_email':
			form_id = "admin-help-form";
		break;
		
		case 'homepage_admin':
			form_id = "admin-homepage-form";
		break;
		
		case 'forum_admin':
			form_id = 'admin-forum-form';
		break;
		
		case 'topic_admin':
			form_id = 'admin-topic-form';
		break;
		
		case 'activities_admin':
			form_id = 'admin-activities-form';
		break;
		
		case 'link_admin':
			form_id = "admin-link-form";
		break;
	}
	
	if(form_id != "")
	{
		fields = $("#" + form_id).serialize();
	}

	if(fields != "")
	{
		$.post(type, {type: type, data: fields, mode : "content"}, function(data)
		{
			var output_data = eval( "(" + data + ")" );	
			
			switch(output_data.STATUS)
			{
				case 'ERROR':
					placeholder_id = "message-row";
					
					if(checkElementExistsById(placeholder_id) == true)
					{
						//hide the error message and set the new error message
						//then show the message block
						event_showLoadedAjaxContent(placeholder_id, output_data.OUTPUT);
					}
				break;
				
				case 'SUCCESS':
					placeholder_id = "admin-content-placeholder";
					
					//hide the error message and set the new error message
					//then show the message block
					event_showLoadedAjaxContent(placeholder_id, output_data.OUTPUT);
				break;
			}
		});
	}
}

/**
 * Post of a frontend form
 * @param type
 * @return
 */
function ajaxFrontendPost(type)
{
	var form_id = '';
	var fields = '';
	var placeholder_id = '';
	
	switch(type)
	{
		case 'user_edit':
			form_id = "user-edit-form";
		break;
		
		case 'category_admin':
			form_id = "admin-category-form";
		break;
		
		case 'product_admin':
			form_id = "admin-product-form";
		break;
		
		case 'calendar':
			form_id = "calendar-select-form";
		break;
		
		case 'topic_post':
			form_id = 'topic-post-form';
		break;
		
		case 'topic_add':
			form_id = 'topic-add-form';
		break;
		
		case 'forgot_password':
			form_id = 'forgot-password-form';
		break;
		
		case 'contact_email':
		case 'sponsor_info':
			form_id = "contact-form";
		break;
	}
	
	if(form_id != "")
	{
		fields = $("#" + form_id).serialize();
	}

	if(fields != "")
	{
		$.post(type, {type: type, data: fields, mode : "content"}, function(data)
		{
			var output_data = eval( "(" + data + ")" );	
			
			switch(output_data.STATUS)
			{
				case 'ERROR':
					placeholder_id = "message-row";
					
					//hide the error message and set the new error message
					//then show the message block
					event_showLoadedAjaxContent(placeholder_id, output_data.OUTPUT);
				break;
				
				case 'SUCCESS':
					placeholder_id = "content";
					
					//hide the error message and set the new error message
					//then show the message block
					event_showLoadedAjaxContent(placeholder_id, output_data.OUTPUT);
				break;
			}
		});
	}
}

/**
 * AJAX Get the user profile
 * @return
 */
function ajaxProfile(type)
{
	$.get(type, {type: type, mode: 'content'}, function(data)
	{
		if (data.length > 0)
		{
			$("#content").html(data); 
		} 
	});
}

/**
 * change the bg of a tab when the user hovers it with the mouse
 * @param tab_id
 * @return
 */
function controlPanelTabHover(tab_id)
{
	//leave all the tabs
	$('.control-panel-tabs-list-item').css('background-image', 'url(./img/tab_bg.png)');
	
	//change the bg of the tab that needs to be hovered
	$('#' + tab_id).css('background-image', 'url(./img/tab_bg_hover.png)');
}

/**
 * change the bg of a tab when it is left with the mouse
 * @param tab_id
 * @return
 */
function controlPanelTabLeave(tab_id)
{
	var temp_tab = 'control-panel-tabs-list-item-' + admin_active_tab;
	
	if(tab_id != temp_tab)
	{
		$('#' + tab_id).css('background-image', 'url(./img/tab_bg.png)');
	}
	
	//activate the active tab again
	controlPanelTabHover(temp_tab);
}

/**
 * AJAX When the admin clicks a tab in the control panel
 * @param type
 * @return
 */
function ajaxAdminControlPanelTab(type, panel)
{
	$.get(type, {type: type, panel: panel, mode : "content"}, function(data)
	{
		if (data.length > 0)
		{
			//set the active tab variable
			admin_active_tab = panel;
			
			//activate the tab
			controlPanelTabHover('control-panel-tabs-list-item-' + panel);
			
			//fade out the old content and fade in the new content
			event_showLoadedAjaxContent('control-panel-blok', data);
		} 
	});
}

/**
 * Toggle the topic post form
 * @return
 */
function toggleTopicPostForm()
{
	if($('#forum-topic-message-placeholder').css("display") == "block")
	{
		//show the reaction placeholder
		$('#forum-topic-message-placeholder').fadeOut("slow", function()
		{
			$('#forum-topic-reaction-placeholder').fadeIn("slow");
		});
	}
	else
	{
		//show the message placeholder
		$('#forum-topic-reaction-placeholder').fadeOut("slow", function()
		{
			$('#forum-topic-message-placeholder').fadeIn("slow");
			
			$('#forum-topic-message-placeholder').focus();
		});
	}
}

/**
 * Toggle the topic add form
 * @return
 */
function toggleTopicAddForm()
{
	if($('#forum-topic-add-form-placeholder').css("display") == "block")
	{
		//show the add placeholder
		$('#forum-topic-add-form-placeholder').fadeOut("slow", function()
		{
			$('#forum-topic-add-placeholder').fadeIn("slow");
		});
	}
	else
	{
		//show the add-form placeholder
		$('#forum-topic-add-placeholder').fadeOut("slow", function()
		{
			$('#forum-topic-add-form-placeholder').fadeIn("slow");
			
			$('#forum-topic-add-form-placeholder').focus();
		});
	}
}

function forum_quote_on_topic_message(placeholder_id, quote_on_user)
{
	var editor_id = 'topic-message-textarea';
	
	var value = '<div style="line-height: 16px;background-color: #AAAAAA;"><p class="quote-topic-post-field">Quote op <b>' + quote_on_user + '</b>:<br/>';
	value += $('#' + placeholder_id).html();
	value += '</p></div><br/>';
	
	if($('#forum-topic-message-placeholder').css("display") != "block")
	{
		toggleTopicPostForm();
	}
	
	set_fckeditor_value(editor_id, value);
}

/**
 * Get the value of a certain FCKEditor instance
 * 
 * @param editor_id
 * @return
 */
function get_fckeditor_value(editor_id)
{
	var oEditor = FCKeditorAPI.GetInstance(editor_id);
	
	return oEditor.GetXHTML(true);
}

/**
 * Set the value of a certain FCKEditor instance
 * 
 * @param editor_id
 * @param value
 * @return
 */
function set_fckeditor_value(editor_id, value)
{
	var oEditor = FCKeditorAPI.GetInstance(editor_id);
	
	oEditor.SetHTML(value);
}