//для реплики в профиле
function ChangeDisplay(id)
{
	var item = document.getElementById(id).style.display;
	switch (item)
	{
		case "none" : document.getElementById(id).style.display = ""; document.getElementById("2").style.display = "none"; break;
		default : document.getElementById(id).style.display = "none"; document.getElementById("2").style.display = ""; break;
	}
}
//для реплики в профиле

//для отзывов в последних заметках
function ChangeDisplayResponse(id,id2,id3)
{
	var item = document.getElementById(id).style.display;
	switch (item)
	{
		case "none" : document.getElementById(id).style.display = ""; document.getElementById(id2).style.display = "none"; document.getElementById(id3).style.display = ""; break;
		default : document.getElementById(id).style.display = "none"; document.getElementById(id2).style.display = ""; document.getElementById(id3).style.display = "none"; break;
	}
}
//для отзывов в последних заметках

//создаём ajax-объект
function createRequestObject() {
	try { return new XMLHttpRequest() }
	catch(e) {
		try { return new ActiveXObject('Msxml2.XMLHTTP') }
		catch(e) {
			try { return new ActiveXObject('Microsoft.XMLHTTP') }
			catch(e) { return null; }
		}
	}
}
//создаём ajax-объект

//выводим содержимое
function showContent(link,id_content,id_loading,id_team,id_user) {

var cont = document.getElementById(id_content);
var loading = document.getElementById(id_loading);

cont.innerHTML = loading.innerHTML;

var http = createRequestObject();
	if( http ) {
	http.open('get', link);
    http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		http.onreadystatechange = function () {
			if(http.readyState == 4) {
			cont.innerHTML = http.responseText;
            updAJAXChatOnline(id_team,id_user);
			}
		}
	http.send(null);
	}
    else {
	document.location.reload();
	}
}
//выводим содержимое

///////////////////////////
//функция вывода листинга//
///////////////////////////
function ShowListing (type,page,id,user) {

var comments = document.getElementById('listing');
var comments_loading = document.getElementById('listing_loading');

comments.innerHTML = comments_loading.innerHTML;

var http = createRequestObject();
http.open('get', '/listing.php' + '?type=' + escape(type) + '&page=' + escape(page) + '&id=' + escape(id) + '&user=' + escape(user));
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    http.onreadystatechange = function () {
        if(http.readyState == 4) {
        comments.innerHTML = http.responseText;
        }
    }
http.send(null);
}

////////////////////////////////
//функция отправки уведомления//
////////////////////////////////
function SendNotification (type,id1,id2) {

var http = createRequestObject();
http.open('get', '/notification.php' + '?type=' + escape(type) + '&id1=' + escape(id1) + '&id2=' + escape(id2));
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	http.onreadystatechange = function () {
	    if(http.readyState == 4) {
	    }
	}
http.send(null);
}

//////////////////////////////////
//функция добавления комментария//
//////////////////////////////////
function AddComment (id,post,author) {

var text = document.getElementById('text_form').value;

var comment_loading = document.getElementById('comment_loading');
comment_loading.style.display = "";

var http = createRequestObject();
http.open('get', '/add_comment.php' + '?id=' + (id) + '&author=' + (author) + '&text=' + escape(text) + '&post=' + (post));
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	http.onreadystatechange = function () {
	    if(http.readyState == 4) {
	    var comment_loading = document.getElementById('comment_loading');
		comment_loading.style.display = "none";
        	if(http.responseText == 'Error') {}
            else {
            document.getElementById('text_form').value = "";
	        ShowListing(1,1,post,author);
	        CountComments(2,post);
	        CountUserComments(3,author);
        	}
	    }
	}
http.send(null);

}

/////////////////////////////////
//функция подсчёта комментариев//
/////////////////////////////////
function CountComments (id,post) {

var count_comments = document.getElementById('count_comments');

var http = createRequestObject();
http.open('get', 'add_comment.php' + '?id=' + (id) + '&post=' + (post));
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    http.onreadystatechange = function () {
        if(http.readyState == 4) {
        count_comments.innerHTML = http.responseText;
        }
    }
http.send(null);
}

/////////////////////////////////////////
//функция подсчёта комментариев у юзера//
/////////////////////////////////////////
function CountUserComments (id,user) {

var count_user_comments = document.getElementById('count_user_comments');

var http = createRequestObject();
http.open('get', 'add_comment.php' + '?id=' + (id) + '&user=' + (user));
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    http.onreadystatechange = function () {
        if(http.readyState == 4) {
        count_user_comments.innerHTML = http.responseText;
        }
    }
http.send(null);
}