// JavaScript Document
function switching(id) {
	jQuery('#' + id).slideToggle('fast', '');
}

function category_edit(catid) {
    document.getElementById('box2').style.display = 'block';
    $.ajax({
        url: 'ajax.php?a=category_edit&catid=' + catid,
        type: 'GET',
        dataType: 'php',
        timeout: 1000,
        success: function(response){
          $("#box2").html(response);
        }
    });
}

function category_delete(catid) {
    $.ajax({
        url: 'ajax.php?a=category_delete&catid=' + catid,
        type: 'GET',
        dataType: 'php',
        timeout: 1000,
        success: function(response){
          $("#text2").html(response);
        }
    });
    document.getElementById('catid_' + catid).style.display = 'none';
}

function updateSiteContent(nameOfTxt, cronjobFilename, cronjobGet) {
    window.open('../../includes/' + cronjobFilename + '.php?' + cronjobGet + '=' + nameOfTxt, '', 'width=800,height=640,resizable=yes');
}

function acceptValidation(id, key) {
	$('#regid_' + id).hide();
	$.ajax({
		url: 'ajax.php?a=acceptValidation&key=' + key,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function denyValidation(id, key) {
	$('#regid_' + id).hide();
	$.ajax({
		url: 'ajax.php?a=denyValidation&key=' + key,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function banPopup(account) {
	document.getElementById('banpopup').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=banpopup&account=' + account,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#banpopup").html(response);
		}
	});
}

function reqitmAccept(reqid) {
	document.getElementById('reqid_' + reqid + '_accept').style.display = 'none';
	document.getElementById('reqid_' + reqid + '_deny').style.display = 'none';
	document.getElementById('reqid_' + reqid + '_status').innerHTML = 'Closed';
	$.ajax({
		url: 'ajax.php?a=reqitmaccept&reqid=' + reqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
}

function reqitmDeny(reqid) {
	document.getElementById('reqid_' + reqid + '_accept').style.display = 'none';
	document.getElementById('reqid_' + reqid + '_deny').style.display = 'none';
	document.getElementById('reqid_' + reqid + '_status').innerHTML = 'Closed';
	$.ajax({
		url: 'ajax.php?a=reqitmdeny&reqid=' + reqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
}

function pscDone(pscid, account, worth) {
	document.getElementById('box').style.display = 'inline-block';
	document.getElementById('pscid_' + pscid + '_undone').innerHTML = '<img src="img/unbanned.png" />';
	document.getElementById('pscid_' + pscid + '_undone').href = 'javascript:pscUndone(' + pscid + ');';
	document.getElementById('pscid_' + pscid + '_undone').title = 'Status: Done<br/> (Set to \'\'undone\'\')';
	$.ajax({
		url: 'ajax.php?a=pscdone&id=' + pscid + '&account=' + account + '&points=' + worth,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function pscUndone(pscid, account, worth) {
	document.getElementById('box').style.display = 'inline-block';
	document.getElementById('pscid_' + pscid + '_done').innerHTML = '<img src="img/banned.png" />';
	document.getElementById('pscid_' + pscid + '_done').href = 'javascript:pscDone(' + pscid + ');';
	document.getElementById('pscid_' + pscid + '_done').title = 'Status: Undone<br/> (Set to \'\'done\'\')';
	$.ajax({
		url: 'ajax.php?a=pscundone&id=' + pscid + '&account=' + account + '&points=' + worth,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function psclogs_delete(pscid) {

	document.getElementById('pscid_' + pscid + '_delete').style.display = 'none';
	document.getElementById('pscid_' + pscid).style.textDecoration  = 'line-through';
	if(document.getElementById('pscid_' + pscid + '_done')) {
		document.getElementById('pscid_' + pscid + '_done').style.display = 'none';
	}
	if(document.getElementById('pscid_' + pscid + '_undone')) {
		document.getElementById('pscid_' + pscid + '_undone').style.display = 'none';
	}
	
	$.ajax({
		url: 'ajax.php?a=pscdelete&id=' + pscid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
}

function banned(account, banned) {
	$.ajax({
		url: 'ajax.php?a=banned&account=' + account + '&banned=' + banned,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
}

function gamemaster(account, gm) {
	$.ajax({
		url: 'ajax.php?a=gamemaster&account=' + account + '&gm=' + gm,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	if(gm == 'yes') {
		document.getElementById('gamemaster').onchange = 'gamemaster(\'' + account + '\', \'no\');';
	} else {
		document.getElementById('gamemaster').onchange = 'gamemaster(\'' + account + '\', \'yes\');';
	}
}

function faq_edit(faqid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=faq_edit&faqid=' + faqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function faq_delete(faqid) {
	$.ajax({
		url: 'ajax.php?a=faq_delete&faqid=' + faqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('faqid_' + faqid).style.display = 'none';
}

function faq_addform() {
	document.getElementById('faqaddform').style.display = 'block';
}

function rule_edit(faqid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=rule_edit&id=' + faqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function rule_delete(faqid) {
	$.ajax({
		url: 'ajax.php?a=rule_delete&id=' + faqid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('id_' + faqid).style.display = 'none';
}

function rule_addform() {
	document.getElementById('addruleform').style.display = 'block';
}

function usergroup_edit(gid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=usergroup_edit&gid=' + gid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function usergroup_delete(gid) {
	$.ajax({
		url: 'ajax.php?a=usergroup_delete&gid=' + gid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('gid_' + gid).style.display = 'none';
}

function usergroup_addform() {
	document.getElementById('usergroupaddform').style.display = 'block';
}

function banPage(page) {
	$.ajax({
		url: 'ajax.php?a=banlogs&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function reqitmPage(page) {
	$.ajax({
		url: 'ajax.php?a=reqitm&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function pscPage(page) {
	$.ajax({
		url: 'ajax.php?a=psclogs&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function donationPage(page) {
	$.ajax({
		url: 'ajax.php?a=donationlogs&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function giftPage(page) {
	$.ajax({
		url: 'ajax.php?a=giftlogs&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function buyPage(page) {
	$.ajax({
		url: 'ajax.php?a=buylogs&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function save_setting(type) {
	$.ajax({
		url: 'ajax.php?a=save_setting&type=' + type + '&new=' + $('#' + type + 'input').val(),
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $('#' + type + "_txt").html(response);
		}
	});
	$('#' + type + '_edit').html('<img src="img/edit.png" />');
	$('#' + type + '_edit').attr('title', 'Edit');
	$('#' + type + '_edit').attr('href', 'javascript:edit_setting(\'' + type + '\');');
}

function edit_setting(type) {
	$('#' + type + '_txt').html('<input type="text" id="' + type + 'input" value="' + document.getElementById(type + '_txt').innerHTML + '" style="width: 200px;" />');
	$('#' + type + '_edit').html('<img src="img/save.png" />');
	$('#' + type + '_edit').attr('title', 'Save');
	$('#' + type + '_edit').attr('href', 'javascript:save_setting(\'' + type + '\');');
}

function shopItemPage(page) {
	$.ajax({
		url: 'ajax.php?a=shopitempage&page=' + page,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#pageinc").html(response);
		}
	});
}

function shopitem_edit(mid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=shopitem_edit&mid=' + mid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function shopitem_delete(mid) {
	$.ajax({
		url: 'ajax.php?a=shopitem_delete&mid=' + mid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('mid_' + mid).style.display = 'none';
}

function shopitem_addform() {
	document.getElementById('shopitemaddform').style.display = 'block';
}

function shopcat_edit(mcatid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=shopcat_edit&mcatid=' + mcatid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function shopcat_delete(mcatid) {
	$.ajax({
		url: 'ajax.php?a=shopcat_delete&mcatid=' + mcatid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('mcatid_' + mcatid).style.display = 'none';
}

function edit_shopsetting(type) {
	document.getElementById(type + '_txt').innerHTML = '<input type="text" id="' + type + 'input" value="' + document.getElementById(type + '_txt').innerHTML + '" style="width: 100px;" />';
	document.getElementById(type + '_edit').innerHTML = '<img src="img/save.png" />';
	document.getElementById(type + '_edit').title = 'Save';
	document.getElementById(type + '_edit').href = 'javascript:save_shopsetting(\'' + type + '\');';
}

function save_shopsetting(type) {
	$.ajax({
		url: 'ajax.php?a=save_shopsetting&type=' + type + '&new=' + document.getElementById(type + 'input').value,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $('#' + type + "_txt").html(response);
		}
	});
	document.getElementById(type + '_edit').innerHTML = '<img src="img/edit.png" />';
	document.getElementById(type + '_edit').title = 'Edit';
	document.getElementById(type + '_edit').href = 'javascript:edit_mail(\'' + type + '\');';
}

function voteitm_addform() {
	document.getElementById('voteitmaddform').style.display = 'block';
}

function voteitm_edit(vid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=voteitm_edit&vid=' + vid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function voteitm_delete(vid) {
	$.ajax({
		url: 'ajax.php?a=voteitm_delete&vid=' + vid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('vid_' + vid).style.display = 'none';
}

function openNewCategoryMainForm() {
    document.getElementById('shopCategoryMain').style.display = 'block';
}
function editCategoryMain(catid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=editCategoryMain&mid=' + catid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}
function deleteCategoryMain(catid) {
	$.ajax({
		url: 'ajax.php?a=deleteCategoryMain&mid=' + catid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('maincat_' + catid).style.display = 'none';
}

function openNewCategorySubForm() {
    document.getElementById('shopCategorySub').style.display = 'block';
}
function editCategorySub(catid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=editCategorySub&sid=' + catid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}
function deleteCategorySub(catid) {
	$.ajax({
		url: 'ajax.php?a=deleteCategorySub&sid=' + catid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('subcat_' + catid).style.display = 'none';
}

function news_addform() {
	document.getElementById('newsaddform').style.display = 'block';
}

function category_addform() {
    document.getElementById('categoryaddform').style.display = 'block';
}

function news_edit(nid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=news_edit&nid=' + nid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function news_delete(nid) {
	$.ajax({
		url: 'ajax.php?a=news_delete&nid=' + nid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('nid_' + nid).style.display = 'none';
}

function download_addform() {
	document.getElementById('dladdform').style.display = 'block';
}

function download_edit(did) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=download_edit&did=' + did,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function download_delete(did) {
	$.ajax({
		url: 'ajax.php?a=download_delete&did=' + did,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('did_' + did).style.display = 'none';
}

function partner_addform() {
	document.getElementById('addform').style.display = 'block';
}

function partner_edit(pid) {
	document.getElementById('box').style.display = 'block';
	$.ajax({
		url: 'ajax.php?a=partner_edit&pid=' + pid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#box").html(response);
		}
	});
}

function partner_delete(pid) {
	$.ajax({
		url: 'ajax.php?a=partner_delete&pid=' + pid,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $("#text").html(response);
		}
	});
	document.getElementById('pid_' + pid).style.display = 'none';
}

function edit_mail(type) {
	document.getElementById(type + '_txt').innerHTML = '<input type="text" id="' + type + 'input" value="' + document.getElementById(type + '_txt').innerHTML + '" style="width: 200px;" />';
	document.getElementById(type + '_edit').innerHTML = '<img src="img/save.png" />';
	document.getElementById(type + '_edit').title = 'Save';
	document.getElementById(type + '_edit').href = 'javascript:save_mail(\'' + type + '\');';
}

function save_mail(type) {
	$.ajax({
		url: 'ajax.php?a=save_mail&type=' + type + '&new=' + document.getElementById(type + 'input').value,
		type: 'GET',
		dataType: 'php',
		timeout: 1000,
		success: function(response){
		  $('#' + type + "_txt").html(response);
		}
	});
	document.getElementById(type + '_edit').innerHTML = '<img src="img/edit.png" />';
	document.getElementById(type + '_edit').title = 'Edit';
	document.getElementById(type + '_edit').href = 'javascript:edit_mail(\'' + type + '\');';
}