
///////////////////////////////////////////////////////////////////////////////////////////////////
// Main functions
///////////////////////////////////////////////////////////////////////////////////////////////////

function $(id) {
	return document.getElementById(id);
}

function serviceField(field_name) {
	var panel = document.getElementById(field_name).style;
	if (panel.display == "none")
		panel.display = "";
	else
		panel.display = "none";
}

function sendToIframe(href) {
	$("service_iframe").src = href;

	return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// More user information
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
function showUserInfo(event, user_id) {
	var user_info = $("userinfo_" + user_id);
	var x_pos = 10 + event.clientX + document.body.scrollLeft;
	var y_pos = 10 + event.clientY + document.body.scrollTop;
	user_info.style.left = x_pos + "px";
	user_info.style.top = y_pos + "px";
	user_info.style.display = "";
}

function hideUserInfo(user_id) {
	$("userinfo_" + user_id).style.display = "none";
}
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flood
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function flood(post_id, sid, short) {
	site_url = $("_site_url").value;
	$("service_iframe").src = site_url + "flood.php?flood=" + post_id + (short ? "&allmenu":"") + "&sid=" + sid;
	window.location = "#" + post_id;

	// close rating's starts
	user_id = $("user_id_" + post_id).value;
	if ($("full_stars_" + user_id + "_" + post_id))
		$("full_stars_" + user_id + "_" + post_id).style.display = "none";
}

function hideFlood(post_id) {
	site_url = $("_site_url").value;
	$("service_iframe").src = site_url + "flood.php?flood=" + post_id + "&flood_mode=hide";
}

function showFlood(post_id, short) {
	site_url = $("_site_url").value;
	$("service_iframe").src = site_url + "flood.php?flood=" + post_id + "&flood_mode=show" + (short ? "&allmenu":"");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Delete post
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function deletePost(post_id, url) {
	if (confirm("Вы действительно хотите удалить этот пост?")) {
		if ($("selete_post_reason").value = prompt("Какова причина удаления (указывать не обязательно):", "")) {
			form = $("delete_post_form");
			form.action = url;
			form.submit();
			window.location = "#" + post_id;

			// close rating's starts
			user_id = $("user_id_" + post_id).value;
			if ($("full_stars_" + user_id + "_" + post_id))
				$("full_stars_" + user_id + "_" + post_id).style.display = "none";

			// close rating's starts
			$("post_" + post_id).innerHTML = "";
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// Popup user information
///////////////////////////////////////////////////////////////////////////////////////////////////

var event_user_info_x;
var event_user_info_y;
var user_info_array = new Array();
var user_info_load = false;
var user_info_use = false;
var user_info_last = false;

var user_info_timeout = 2000;
var user_info_width = 300;
var user_info_height = 200;
var user_info_div = "user_info";
var service_iframe_div = "service_iframe";
var user_info_ajax_url = "/ajax/getuserinfo.php";

function showUserInfo(event, user_id, info_id) {
	if (!user_id || info_id == "")
		return false;

	if (info_id == user_info_use)
		return false;

	// Check for strip mach upload
	if (user_info_load && user_info_load == info_id)
		return false;
	else
		user_info_load = info_id;

	// Get coords
        event_user_info_x = event.clientX;
        event_user_info_y = event.clientY;

        // Check is send query or display have result
	if (!user_info_array[info_id])
		document.getElementById(service_iframe_div).src = user_info_ajax_url + "?user_id=" + user_id + "&info_id=" + info_id;
	else
		showUserInfoByIframe(info_id);

	return true;
}

function showUserInfoByIframe(info_id, info) {
	// Get object of DIV with user information
        var div_info = $(user_info_div);

        // Check is add new user information or use old
        if (info) {
        	div_info.innerHTML = info;
        	user_info_array[info_id] = info;
        } else if (user_info_array[info_id]) {
        	div_info.innerHTML = user_info_array[info_id];
        } else {
		user_info_load = false;
        	return false;
        }

        // Set use user information
        user_info_last = user_info_use = info_id;

        // Get coords
	var client_width = document.body.clientWidth;
	var client_height = document.body.clientHeight;
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
        var x_pos = 10 + event_user_info_x + scrollLeft;
	var y_pos = 10 + event_user_info_y + scrollTop;

        // Move DIV, if his go over
	if (client_width < (x_pos + user_info_width))
		x_pos -= user_info_width;
		
	// Set coords for DIV
	div_info.style.left = x_pos + "px";
	div_info.style.top = y_pos + "px";
	
        // Set width for DIV
        div_info.style.width = user_info_width + "px";

        // Display DIV
        div_info.style.display = "";

        // Set time out for check (hide DIV or not)
        show_time = setInterval("hideUserInfo()", user_info_timeout);

	// If user's information already loaded, then set null global variable
	if (user_info_load == info_id)
		user_info_load = false;
}

function hideUserInfo() {
	// Check is DIV used still
	if (user_info_use)
		return false;

	// Hide user information from page
	$(user_info_div).style.display = "none";

	// If time out is exist then close them
        if (show_time)
		clearInterval(show_time);

	return true;
}

function getLastUserInfo() {
	user_info_use = user_info_last;
}

function outFromUserInfoTarget() {
	user_info_use = false;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////