var common_backend_url = '/ajax/ajax_backend.js.php';
var debug_level = 'dev';

function ajax_action(action, param) {
	param['action'] = action;
	var backend_url = param['backend_url'] || common_backend_url;
	$.ajax({
		type: "POST",
		url: backend_url,
		data: param,
   		success: function(response) {
  			var dest = $("dest", response).text();
  			var htmldata = $("htmldata", response).text();
 			$dest_obj = gebi(dest);
			if ($dest_obj) $dest_obj.innerHTML = htmldata;
 		},
		complete: function(XML, status) {
  		}
 	});
}
function debug_message(message) {
	if (!message) return;
	if (debug_level == 'dev') alert(message);
	var obj = $("#debug").text(message);
}
function ajax_response(response) {
	var $obj = gebi(response.dest_obj_id);
	if ($obj) $obj.innerHTML = response.html;
}

/********************/


/* рейтинги объектов */
function vote(object_class, object_id, vote, dest_obj_id) {
	ajax_action('vote', {'object_class': object_class, 'object_id': object_id, 'vote': vote, 'dest_obj_id' : dest_obj_id, 'response_func': 'ajax_response'});
}

/* голосования */
function polling_answer(polling_id, answer_id, dest_obj_id) {
	ajax_action('polling_answer_2', {'polling_id': polling_id, 'answer_id': answer_id, 'dest_obj_id' : dest_obj_id, 'response_func': 'ajax_response'});
}

function polling_display(polling_id, view, dest_obj_id) {
	ajax_action('polling_display', {'polling_id': polling_id, 'view': view, 'dest_obj_id' : dest_obj_id, 'response_func': 'ajax_response'});
}
