// JavaScript Document

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

function ajaxCall(post, refreshOnSuccess) {
	if (post.indexOf('token=') == -1) {
		post += '&token='+jQuery('#token').val();
	}

	var tmp = jQuery.ajax({
			type: "POST",
			url: protocol+window.location.hostname+"/ajax.html",
			dataType: "html",
			data: post,
			processData: false,
			async: false
		}).responseText;
	
	if (refreshOnSuccess) {
		if (tmp == 1) {
			window.location.reload();
		} else {
			reportError(tmp);
		}
	} else {
		return tmp;
	}
}

function loadModuleAdmin(posts) {
	if(posts == undefined) {  posts = "";	}
	
	var result = ajaxCall(posts);
	if(result != 'fail') {
		jQuery('#mainAdminControl').html(result);
	}
}

function initializeModuleAdmin(posts) {
	$('#mainContentEditor').css('width', '70%');
	$('#mainContentEditor').css('height', '70%');
	$('#mainContentEditor').css('top', '15%');
	$('#mainContentEditor').css('left', '15%');
	
	jQuery('#mainMask').click(function() {
		window.location.reload();
	});

	loadModule(posts);
	
	jQuery('#mainMask').fadeTo(500,0.6);
	jQuery('#mainMask').fadeIn(500, function() {
		
		/*if(jQuery(document).height() > jQuery('#mainContentEditorContent').height()) {
			jQuery('#mainContentEditor').css('top', ( jQuery(document).height() - jQuery('#mainContentEditor').height() ) / 2 + jQuery(document).scrollTop() + 'px');
		} else {
			jQuery('#mainContentEditor').css('top', '50px');	
		}*/
		jQuery('#mainContentEditor').fadeIn(300);	
	});
}

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

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

jQuery(document).ready( function() {
	jQuery("a[@rel='external']").click(function(){return !window.open(this.href);});
});
