// JavaScript Document

function errorClose()
{
	document.getElementById("error").style.display = 'none';
}

function ajaxCall(action, module, post) {
	if (post.indexOf('token=') == -1)
	{
		post += '&token='+$('#token').val();
	}
	
	var tmp = $.ajax({
			type: "POST",
			url: "http://"+window.location.hostname+"/ajax/"+action+"/module:"+module+"/",
			dataType: "html",
			data: post,
			processData: false,
			async: false
		}).responseText;
	
	return tmp;
}

function loadModuleAdmin(action, module, posts)
{
	if(posts == undefined) {  posts = "";	}

	var result = ajaxCall(action, module, posts);
	if(result != 'fail') {
		$('#mainAdminControl').html(result);
	}
}

function initializeModuleAdmin(action, module, posts)
{
	var width = $(document).width();
	$('#mainMask').css('width', width);

	var height = $(document).height();
	$('#mainMask').css('height', height);
	
	$('#mainMask').click(function() {
		windowCancel();
	});

	loadModuleAdmin(action, module, posts);
	
	$('#mainMask').fadeTo(500,0.6);
	$('#mainMask').fadeIn(500, function() {
		if($(window).height() > $('#mainContentEditor').height()) {
			$('#mainContentEditor').css('top', ( $(window).height() - $('#mainContentEditor').height() ) / 2 + $(window).scrollTop() + 'px');
		} else {
			$('#mainContentEditor').css('top', '50px');	
		}
		$('#mainContentEditor').css('left', ( $(window).width() - $('#mainContentEditor').width() ) / 2 + $(window).scrollLeft() + 'px');
		$('#mainContentEditor').fadeIn(300);	
	});
}

function hideAdminMenu() {
	if(showAdminBtns) {
		showAdminBtns = false;
		$('.minimizeAdminMenus').hide();
		$('.expandAdminMenus').show();
	} else {
		showAdminBtns = true;
		$('.minimizeAdminMenus').show();
		$('.expandAdminMenus').hide();
	}
}

function showAdminMenu(obj, over) {
	if(showAdminBtns) {
		if(over)
			$(obj).children('.toolbar').show();
		else
			$(obj).children('.toolbar').hide();
	}
}