
function showLoading() {
	var loading = document.getElementById('HTML_AJAX_LOADING');
	loading.style.display = 'block';
}

function hideLoading() {

	var loading = document.getElementById('HTML_AJAX_LOADING');
	loading.style.display = 'none';

}

function ratingProgressHide() {

	var progress = document.getElementById('dynamic_stars_progress');
	progress.style.display = 'none';
	var stars = document.getElementById('dynamic_stars');
	stars.style.display = 'block';

}

function ratingProgressShow() {

	var progress = document.getElementById('dynamic_stars_progress');
	progress.style.display = 'block';
	var stars = document.getElementById('dynamic_stars');
	stars.style.display = 'none';

}

function showCarousel() {
	var loading = document.getElementById('ajax_loading_overlay');
	loading.style.display = 'block';

}

function hideCarousel() {
	var loading = document.getElementById('ajax_loading_overlay');
	loading.style.display = 'none';
}


function showBookingPage(d,m,y) {

	new Ajax.Updater('bookinglist', '/?section=bookings&module=booking&action=list&ajax=1&d='+d+'&m='+m+'&y='+y, {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete: hideLoading });

}

function articlePage(article_id,page_id) {

	new Ajax.Updater('articlebody', '/?section=articles&module=article&action=read&ajax=1&id='+article_id+'&page_id='+page_id, {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete: hideLoading });

}

function blaatOver(page_id) {

	var section = document.getElementById('helperform').section.value;
	var module = document.getElementById('helperform').module.value;
	var action = document.getElementById('helperform').action.value;
	var mode = document.getElementById('helperform').mode.value;
	var pattern = document.getElementById('helperform').pattern.value;

	new Ajax.Updater('resultset', '/?section='+section+'&module='+module+'&action='+action+'&pattern='+pattern+'&ajax=1&pageNum='+page_id, {asynchronous:true, evalScripts:true });

}

function toggleVisibility(target_id) {
	
	var box = document.getElementById(target_id).style.display;
	
	if (box == 'none') {
		document.getElementById(target_id).style.display = 'block';
		document.getElementById(target_id).focus();
	} else
		document.getElementById(target_id).style.display = 'none';
	
	
}

function pageComments(page_id) {

	var section = document.writeCommentForm.section.value;
	var module = document.writeCommentForm.module.value;
	var action = document.writeCommentForm.action.value;
	var id = document.writeCommentForm.id.value;

    new Ajax.Updater('basearea', '/?section='+section+'&module='+module+'&action='+action+'&op=pageComments&id='+id+'&pageNum='+page_id, {asynchronous:true, evalScripts:true });
	
}

function writeCommentHandler() {
	
	var section = document.writeCommentForm.section.value;
	var module = document.writeCommentForm.module.value;
	var action = document.writeCommentForm.action.value;
	var id = document.writeCommentForm.id.value;

	var body = escape(document.writeCommentForm.commentBody.value);

	new Ajax.Updater('basearea', '/?section='+section+'&module='+module+'&action='+action+'&op=writeComment&id='+id+'&body='+body, {asynchronous:true, evalScripts:true });
    
    return false;
	
}

function shout() {
	
	var body = escape(document.shouter.body.value);
	document.shouter.body.value = '';
	new Ajax.Updater('shoutbox', '/?section=welcome&module=shoutbox&action=small&op=shout&body='+body, {asynchronous:true, evalScripts:true });
    
    return false;
	
}

function shoutbox() {
	
	new Ajax.PeriodicalUpdater('shoutbox', '/?section=welcome&module=shoutbox', {asynchronous:true, evalScripts:true, frequency: 5, decay: 1 });
    
    return false;
	
}

function switchEventMode(mode, id) {
    new Ajax.Updater('basearea', '/?section=events&module=event&mode='+mode+'&op=switchMode&action=detail&id='+id, {asynchronous:true, evalScripts:true });
}

function switchGameMode(mode, id) {
    new Ajax.Updater('basearea', '/?section=games&module=game&mode='+mode+'&op=switchMode&action=detail&id='+id, {asynchronous:true, evalScripts:true });
}

function switchClanMode(mode, id) {
    new Ajax.Updater('basearea', '/?section=users&module=clan&mode='+mode+'&op=switchMode&action=detail&id='+id, {asynchronous:true, evalScripts:true });
}


function userPlayHandler(form) {
    
	var id = form.id.value;
	var flavor_id = form.flavor_id.value;
	var notice = escape(form.notice.value);

	new Ajax.Updater('flavors', '/?section=games&module=game&mode=flavors&action=detail&id='+id, {asynchronous:true, evalScripts:true });
	new Ajax.Updater('basearea', '/?section=games&module=game&op=addPlayer&mode=players&action=detail&id='+id+'&notice='+notice+'&flavor_id='+flavor_id, {asynchronous:true, evalScripts:true });

	return false;
}

function clanPlayHandler(form) {
    
	var id = form.id.value;
	var flavor_id = form.flavor_id.value;
	var clan_id = form.clan_id.value;
	var notice = escape(form.notice.value);

	new Ajax.Updater('flavors', '/?section=games&module=game&mode=flavors&action=detail&id='+id, {asynchronous:true, evalScripts:true });
	new Ajax.Updater('basearea', '/?section=games&module=game&op=addClan&mode=clans&action=detail&clan_id='+clan_id+'&id='+id+'&notice='+notice+'&flavor_id='+flavor_id, {asynchronous:true, evalScripts:true });

	return false;
}

function userNotPlayHandler(form_id) {
    
	var id = document.getElementById(form_id).id.value;
	var flavor_id = document.getElementById(form_id).flavor_id.value;

	new Ajax.Updater('flavors', '/?section=games&module=game&mode=flavors&action=detail&id='+id, {asynchronous:true, evalScripts:true });
	new Ajax.Updater('basearea', '/?section=games&module=game&op=delPlayer&mode=players&action=detail&id='+id+'&flavor_id='+flavor_id, {asynchronous:true, evalScripts:true });

}

function clanNotPlayHandler(form_id) {
    
	var id = document.getElementById(form_id).id.value;
	var flavor_id = document.getElementById(form_id).flavor_id.value;
	var clan_id = document.getElementById(form_id).clan_id.value;


	new Ajax.Updater('flavors', '/?section=games&module=game&mode=flavors&action=detail&id='+id, {asynchronous:true, evalScripts:true });
	new Ajax.Updater('basearea', '/?section=games&module=game&op=delClan&mode=clans&action=detail&clan_id='+clan_id+'&id='+id+'&flavor_id='+flavor_id, {asynchronous:true, evalScripts:true });

}


function addArticlePage(article_id) {

	new Ajax.Updater('articlepages', '/?section=articles&module=article&action=editor&op=addpage&ajax=1&id='+article_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});

}

function delArticlePage(article_id, page_id, page_title) {
    if (confirm('Do you really want to remove the page?\n' + page_title)) {
	new Ajax.Updater('articlepages', '/?section=articles&module=article&action=editor&op=delpage&ajax=1&id='+article_id+'&page_id='+page_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
    }
}

function delClan(clan_id) {
    if (confirm('Do you really want to delete this clan along with all comments?\n')) {
	window.location = '/?section=users&module=clan&action=delete&id='+clan_id;
    }
}

function clanAddMember() {

	var member_pattern = document.getElementById('member_adduser').member_pattern.value;
	var clan_id = document.getElementById('member_adduser').clan_id.value;

	new Ajax.Updater('clanmembers', '/?section=users&module=clan&action=editor&op=addmember&ajax=1&member_pattern='+member_pattern+'&id='+clan_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
    return false;
}

function clanSetMember() {

	var setrank = document.getElementById('member_adduser').setrank.value;
	var clan_id = document.getElementById('member_adduser').clan_id.value;

	new Ajax.Updater('clanmembers', '/?section=users&module=clan&action=editor&op=addmember&ajax=1&member_pattern='+member_pattern+'&id='+clan_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
    return false;
}

function clanDelMember(clan_id, user_id, username) {
    if (confirm('Do you really want to remove the member?\n' + username)) {
	   new Ajax.Updater('clanmembers', '/?section=users&module=clan&action=editor&op=delmember&ajax=1&memberid='+user_id+'&id='+clan_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
    }
}

function clanUpMember(clan_id, user_id) {
	   new Ajax.Updater('clanmembers', '/?section=users&module=clan&action=editor&op=upmember&ajax=1&memberid='+user_id+'&id='+clan_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
}

function clanDownMember(clan_id, user_id) {
	   new Ajax.Updater('clanmembers', '/?section=users&module=clan&action=editor&op=downmember&ajax=1&memberid='+user_id+'&id='+clan_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
}

function bookingRemove(booking_id) {
    if (confirm('Do you really want to remove the booking?\n')) {
	   new Ajax.Updater('bookinglist', '/?section=bookings&module=booking&action=list&op=delbooking&id='+booking_id, {asynchronous:true, evalScripts:true, onLoading: showCarousel, onComplete: hideCarousel});
    }
}


