function getUrlParams(url = location.search){
	var regex = /[?&]([^=#]+)=([^&#]*)/g, params = {}, match;
	while(match = regex.exec(url)) {
		params[match[1]] = match[2];
	}
	return params;
}

$(document).ready(function(){
	$.ajaxSetup({ cache: false });
});

$(document).on("click", "#ajax_next_page", function(e){
	e.preventDefault();
	
	
	//el = $(this).closest("td").find("input:first-child");
	data = {};
	data['action'] = "get_post_next_page";
	data['page'] = $(this).attr('page');
	
	$.ajax({
		url: "/ajax.php",
		type: "POST",
		data: data,
		dataType: 'json',
		success: function(data) {
			if( data.status == 'ok' ){
				$("#ajax_next_page").attr('page', parseInt($("#ajax_next_page").attr('page')) + 1);
				if( !data.button_more ){
					$("#bl_next_page").hide();
				}
				$("#bl_next_page").before(data.content);
			}
		}
	});
});
$(document).on("click", "#ajax_next_page_search", function(e){
	e.preventDefault();
	
	
	//el = $(this).closest("td").find("input:first-child");
	data = {};
	data['action'] = "get_post_next_page_search";
	data['page'] = $(this).attr('page');
	data['q'] = decodeURI(getUrlParams()['q']);
	
	$.ajax({
		url: "/ajax.php",
		type: "POST",
		data: data,
		dataType: 'json',
		success: function(data) {
			if( data.status == 'ok' ){
				$("#ajax_next_page_search").attr('page', parseInt($("#ajax_next_page_search").attr('page')) + 1);
				if( !data.button_more ){
					$("#bl_next_page").hide();
				}
				$("#bl_next_page").before(data.content);
			}
		}
	});
});
$(document).on("click", "#ajax_next_page_categ", function(e){
	e.preventDefault();
	
	
	//el = $(this).closest("td").find("input:first-child");
	data = {};
	data['action'] = "get_post_next_page_categ";
	data['page'] = $(this).attr('page');
	data['categ'] = $(this).attr('categ');
	
	$.ajax({
		url: "/ajax.php",
		type: "POST",
		data: data,
		dataType: 'json',
		success: function(data) {
			if( data.status == 'ok' ){
				$("#ajax_next_page_categ").attr('page', parseInt($("#ajax_next_page_categ").attr('page')) + 1);
				if( !data.button_more ){
					$("#bl_next_page").hide();
				}
				$("#bl_next_page").before(data.content);
			}
		}
	});
});