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

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

/**
 * 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 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");
		});
	});
}

/**
 * Silde open and close submenus
 * @param menu_id
 * @return
 */
function show_navigation_submenu(menu_id) {
	//hide_navigation_submenus();
	
	$("#" + menu_id).css("display", "block");
}

function hide_navigation_submenus() {
	$(".menu-item-content").slideUp("fast");
}

/**
 * Silde open and close submenus
 * @param menu_id
 * @param menu_type
 * @return
 */
function toggle_navigation_submenu(menu_id) {
	$(".menu-item-submenu-wrapper").css("display", "none");
	
	//dehighlight the menu items
	$(".menu-item-highlight").attr('class', 'menu-item-name');
	
	if(menu_id > 0) {
		//show the submenu div
		submenu_div_id = "#menu-item-" + menu_id + "-submenu";
		$(submenu_div_id).css("display", "block");
		
		//keep the top menu item highlighted
		$("#menu-item-span-" + menu_id).attr('class', 'menu-item-highlight');
	}
}

var timeoutID = null;
function hide_navigation_submenu(menu_id) {
	timeoutID = setTimeout("hide_navigation_submenu_test(" + menu_id + ")", 500);
}

function hide_navigation_submenu_test (menu_id) {
	$(".menu-item-submenu-wrapper").css("display", "none");
	
	$('#menu-item-span-' + menu_id).attr('class', 'menu-item-name');
}

function reset_navigation_submenu_timer () {
	clearTimeout(timeoutID);
	timeoutID = null;
}

/**
 * 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 'forgot_password':
			form_id = 'forgot-password-form';
		break;
		
		case 'contact/post_contactEmail':
			form_id = "contact-form";
		break;
		
		case 'domain_search':
			form_id = "domain_search-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.TYPE) {
				case 'MESSAGE':
					placeholder_id = "message-row";
				break;
				
				case 'CONTENT':
					placeholder_id = "content";
				break;
			}
			
			//hide the error message and set the new error message
			//then show the message block
			event_showLoadedAjaxContent(placeholder_id, output_data.OUTPUT);
		});
	}
}

/**
 * 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");
	});
}

/**
 * Silde open and close submenus
 * @param menu_id
 * @param menu_type
 * @return
 */
function toggle_menu_table_expand(menu_id) {
	$(".admin-menu-table-data-submenus").fadeOut("fast");
	
	if(menu_id > 0) {
		menu_id = "#admin-menu-table-data-submenus-" + menu_id;
		
		$(menu_id).slideDown("fast");
	}
}

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

function hideErrorMessage() {
	$('#message-row').hide();
}
