// JavaScript Document
//============================obsługa administratorów=========================
var admins = new Admins(reviewCallback);

//============================obsługa programu================================
function standard_admins_perform(result){
	hideloading();
	if (result == '0') showadmins(order, search_);
	else alertmsg(result);
}
function showadmins(ord, ser, ret){
	if (action != admins_action) {
		action = admins_action;
		resetvariables();
	}
	else {
		order = ord;
		search_ = ser;
	}
	action = admins_action;
	showloading();
	admins.showadmins(order, search_, ret);
}
function jmpshowadmins(jmp, ord, ser, ret){
	order = ord;
	search_ = ser;
	action = admins_action;
	showloading();
	admins.jmpshowadmins(jmp, order, search_, ret);
}
function showadmins_find(){
	showadmins(order, $('search_us').value);
}
function addadmins(ret){
	showloading();
	admins.addadmins(ret);
}
function doaddadmins(form){
	message = '';
	infomsg(message);
	if (!validatemail($('email').value)){
		alertmsg('Niepoprawny format adresu e-mail');
		$('email').focus();
		return;
	}
	showloading();
	var payload = getPayload(form);
	if ($('check_static')) payload = checkcheckbox(payload);
	admins.doaddadmins(payload);
}
function lockadmins(id){
	showloading();
	admins.lockadmins(id);
}
function unlockadmins(id){
	showloading();
	admins.unlockadmins(id);
}
function editadmins(id, stat, ret){
	showloading();
	admins_stat = stat;
	admins.editadmins(id, stat, ret);
}
function doeditadmins(form){
	message = '';
	infomsg(message);
	if (!validatemail($('email').value)){
		alertmsg('Niepoprawny format adresu e-mail');
		$('email').focus();
		return;
	}
	showloading();
	var payload = getPayload(form);
	if ($('check_static')) payload = checkcheckbox(payload);
	admins.doeditadmins(payload);
}
function checkcheckbox(payload){
	if ($('check_static') && $('check_static').checked) payload['check_static'] = 'checked';
	else if ($('check_static')) payload['check_static'] = '';
	if ($('check_news') && $('check_news').checked) payload['check_news'] = 'checked';
	else if ($('check_news')) payload['check_news'] = '';
	if ($('check_ads') && $('check_ads').checked) payload['check_ads'] = 'checked';
	else if ($('check_ads')) payload['check_ads'] = '';
	if ($('check_kurs') && $('check_kurs').checked) payload['check_kurs'] = 'checked';
	else if ($('check_kurs')) payload['check_kurs'] = '';
	if ($('check_gals') && $('check_gals').checked) payload['check_gals'] = 'checked';
	else if ($('check_gals')) payload['check_gals'] = '';
	if ($('check_down') && $('check_down').checked) payload['check_down'] = 'checked';
	else if ($('check_down')) payload['check_down'] = '';
	if ($('check_wstaw') && $('check_wstaw').checked) payload['check_wstaw'] = 'checked';
	else if ($('check_wstaw')) payload['check_wstaw'] = '';
	if ($('check_dwstaw') && $('check_dwstaw').checked) payload['check_dwstaw'] = 'checked';
	else if ($('check_dwstaw')) payload['check_dwstaw'] = '';
	if ($('check_menu') && $('check_menu').checked) payload['check_menu'] = 'checked';
	else if ($('check_menu')) payload['check_menu'] = '';
	if ($('check_nag') && $('check_nag').checked) payload['check_nag'] = 'checked';
	else if ($('check_nag')) payload['check_nag'] = '';
	if ($('check_newsl') && $('check_newsl').checked) payload['check_newsl'] = 'checked';
	else if ($('check_newsl')) payload['check_newsl'] = '';
	if ($('check_subs') && $('check_subs').checked) payload['check_subs'] = 'checked';
	else if ($('check_subs')) payload['check_subs'] = '';
	if ($('check_peop') && $('check_peop').checked) payload['check_peop'] = 'checked';
	else if ($('check_peop')) payload['check_peop'] = '';
	if ($('check_res') && $('check_res').checked) payload['check_res'] = 'checked';
	else if ($('check_res')) payload['check_res'] = '';
	if ($('check_set') && $('check_set').checked) payload['check_set'] = 'checked';
	else if ($('check_set')) payload['check_set'] = '';
	if ($('check_scr') && $('check_scr').checked) payload['check_scr'] = 'checked';
	else if ($('check_scr')) payload['check_scr'] = '';
	if ($('check_lang') && $('check_lang').checked) payload['check_lang'] = 'checked';
	else if ($('check_lang')) payload['check_lang'] = '';
	return payload;
}
function remadmins(id){
	var answer = confirm("Na pewno chcesz usunąć administratora?");
	if (answer){
		showloading();
		admins.remadmins(id);
	}
}
