<div class="buttons">
	<a href="/admin/create/member" class="addbutton add-big">Új tag hozzáadása</a>
	<a href="/admin/parents" class="addbutton add-big">Szülők</a>
	<a href="/admin/shirts" class="addbutton add-big">Pólók</a>
	<a href="/admin/cities" class="addbutton add-big">Települések</a>
	<a href="/admin/schools" class="addbutton add-big">Iskolák</a>
	<a href="/admin/regions" class="addbutton add-big">Diákolimpia körzetek</a>
	<a href="/admin/user_groups" class="addbutton add-big">Csoportok</a>
	<a href="/admin/milestones" class="addbutton add-big">Játékos profil feltöltése</a>
</div>



<div class="user_filter">
	<input name="uk_filter_name" id="uk_filter_name" placeholder="Keresés..." autofocus>
	<select name="is_active" id="is_active">
		<option value="1">Aktív tagok</option>
		<option value="0">Passzív tagok</option>
		<option value="3">Minden tag</option>
	</select>
</div>



<div class="list" id="user_list">


</div>

<script>

var Timer;

$( document ).ready(function() {
    $("#is_active").trigger("change");
    $("#uk_filter_name").focus();
});


$("#is_active").change(search);
$("#uk_filter_name").keyup(function() {
	document.getElementById('user_list').innerHTML = 'Betöltés...';
	clearTimeout(Timer);
	Timer = window.setTimeout(search, 1000);

});


function open_kid_menu(uk_id) {
	$("#kid_menu_"+uk_id).slideToggle();
	if (!$("#kid_"+uk_id).hasClass('active_kid')) {
		$("#kid_"+uk_id).addClass('active_kid');
		$("#kid_"+uk_id).removeClass('list_item');
	}
	else {
		$("#kid_"+uk_id).removeClass('active_kid');
		$("#kid_"+uk_id).addClass('list_item');
	}

}

function open_deposit(user_id) {
	$("#"+user_id).submit();
}

function open_preview(user_id) {
	window.open("/preview/diary/"+user_id, '_blank');
}

function open_datasheet(user_id) {
	location.href = "/admin/members/"+user_id;
}

function open_previous_deposits(user_id) {
	location.href = "/admin/view_deposit/"+user_id;
}

function open_logins(user_id) {
	$("#login_"+user_id).submit();
}

function search() {
	document.getElementById('user_list').innerHTML = 'Betöltés...';
	$("#is_active").prop("disabled",true);
	$.post("/_ajax/get_user_list.php",
	{
		uk_filter_name: $("#uk_filter_name").val(),
	    is_active: $("#is_active").val()

	},
	function(data, status){
    	var pdata = JSON.parse(data);
    	var content = '';
    	for (var i=0; i<pdata.length; ++i) {
    		//console.log(pdata[i]['uk_id']);
    		//add_list_item(pdata[i]['uk_id'],pdata[i]['uk_name']);
    		content +=
			'\
			<form id="'+pdata[i]['uk_id']+'" class="user_mod_form" method="post" action="/admin/create/money_deposit">\
				<input type="hidden" name="mod_user_kid_uk_id" value="'+pdata[i]['uk_id']+'">\
			</form>\
			<form id="login_'+pdata[i]['uk_id']+'" class="user_mod_form" method="post" action="/admin/log/1">\
				<input type="hidden" name="login_kid" value="'+pdata[i]['uk_id']+'">\
			</form>\
			<div class="list_item clickable" id="kid_'+pdata[i]['uk_id']+'" onclick="open_kid_menu('+pdata[i]['uk_id']+')">\
				<img src="/_image/shuttlecock.png">\
					'+pdata[i]['uk_name']+'\
			</div>\
			<div class="kid_menu" id="kid_menu_'+pdata[i]['uk_id']+'">\
				<div class="kid_submenu" onclick="open_datasheet('+pdata[i]['uk_id']+')">\
			  		<span>Adatlap</span>\
			  		<img src="/_image/contact.png">\
		  		</div>\
		  		<div class="kid_submenu" onclick="open_deposit('+pdata[i]['uk_id']+')">\
			  		<span>Új befizetés</span>\
			  		<img src="/_image/deposit.png">\
		  		</div>\
		  		<div class="kid_submenu" onclick="open_previous_deposits('+pdata[i]['uk_id']+')">\
			  		<span>Korábbi befizetések</span>\
			  		<img src="/_image/stat.png">\
		  		</div>\
		  		<div class="kid_submenu" onclick="open_logins('+pdata[i]['uk_id']+')">\
			  		<span>Belépések</span>\
			  		<img src="/_image/login.png">\
		  		</div>\
			  	<div class="kid_submenu" onclick="open_preview('+pdata[i]['uk_id']+')">\
			  		<span>Szülői előnézet</span>\
			  		<img src="/_image/preview.png">\
		  		</div>\
			</div>\
			'
    	}
		document.getElementById('user_list').innerHTML = content;
		$("#is_active").prop("disabled",false);
	});
}

</script>
