function pasteselection()
{
	var fr = document.getElementById('comment_text');
	var myselection = '';

	if ( window.getSelection )
	{
		myselection = window.getSelection();
	}
	else if ( document.selection )
	{
		myselection = document.selection.createRange().text;
	}
	else if ( document.getSelection )
	{
		myselection = document.getSelection();
	}
	if (fr)
	{
		fr.value += '[blockquote]'+myselection+'[/blockquote]\n';
		fr.focus();
	}

	return false;
}

function addname(name)
{
	if ($('#markItUp').length > 0)
	{
		$('#markItUp').val($('#markItUp').val() + '[b]'+name+'[/b] ');
		$('#addcommentform:hidden').slideDown('slow');
		BBreplace();
		fr.focus();
	}

	return false;
}

function ChangeRates(obj)
{
	if ($(obj).val() == 1) 
	{
		$("#server_rates").val(1);
		$("#server_rates").attr("readonly", true);
	}
	if ($(obj).val() == 2) 
	{
		$("#server_rates").attr("readonly", false);
	}

}


function delComment(commentid, serverowner, serverid)
{
	if (confirm('Действительно удалить?'))
	{
		$("#comment_"+commentid).load("/delcomment/"+commentid+"/"+serverowner+"/"+serverid+"/");
		$("#comment_"+commentid).remove();
	}
	return false;
}


function show_hide(){
	h = $('#login_frm').attr('height');
	$('#fpw_frm').attr('height:' + h);
	$('#login_frm').slideToggle('slow');
	$('#fpw_frm').slideToggle('slow');	
}

function ShowHideDiv(obj, self){
	if ($(obj+":visible").length > 0)
		$(self).css( "background-position", "-740px" );
	else
		$(self).css( "background-position", "0px" );
	$(obj).slideToggle('fast');
	return false;
}

function ShowHideComment(obj, self){
	if ($(obj+":visible").length > 0)
		$(self).html( "Показать комментарий" );
	else
		$(self).html( "Скрыть комментарий"  );
	$(obj).slideToggle('fast');
	return false;
}

function ShowHideCommentForm(obj, self){
	if ($(obj+":visible").length > 0)
		$(self).html( "<span>Добавить комментарий</span>" );
	else
		$(self).html( "<span>Скрыть форму</span>"  );
	$(obj).slideToggle('normal');
	return false;
}

/* server quality */
function SelectRating(obj, rate, zone) {
	$("#quality_rating #q_zone_" + zone + " span").removeClass("selected");

	if (zone == 0){
		if (rate == 0) text = "<div style='color: red'><strong>Ужасный сервер</strong>полное разочарование</div>";
		if (rate == 1) text = "<div style='color: red'><strong>Плохой сервер</strong>не очень удачный выбор</div>";
		if (rate == 2) text = "<div style='color: gray'><strong>Обычный сервер</strong>не хуже, не лучше других</div>";
		if (rate == 3) text = "<div style='color: green'><strong>Хороший сервер</strong>вполне достойный выбор</div>";
		if (rate == 4) text = "<div style='color: green'><strong>Отличный сервер</strong>всем рекомендую</div>";
		$("#quality_comment").html(text);
		$("#quality_rating span").removeClass("selected");
		$("#other_qulity .slevel_" + rate).addClass("selected");
		$("#quality_frm input").val(rate);
	}else{
		$("#quality_frm input[@name=q_parm_"+ zone +"]").val(rate);
	}
	$(obj).addClass("selected");
}
/* server counter codes*/
function SelectCounter(obj) {
	$("#counter_selector LI > IMG").removeClass("selected");
	$(obj).addClass("selected");
	$("#counter_selector div.descr").html($(obj).parent().children("span.title").html());
	$("#counter_selector TEXTAREA").val($(obj).parent().children("span.code").html());
	$("#counter_selector TEXTAREA").show();
	$("#counter_selector TEXTAREA").select();
}

function ShowWidget(obj) {
	$("body").append($("#widget").html());
}

function statusbar_close()
{
	$.get("/personal/panel/hide/");
	$("#statusbar").hide();
	$.jGrowl('<p>Панель отключена.</p><p>Вы можете повторно активировать панель администрирования в <a href="/personal/">личном кабинете</a>.<p>', { header: 'Информация',  life: 10000, theme: 'infobox'});
}

function statusbar_show(obj)
{
	$.get("/personal/panel/show/");
	$("#statusbar").show();
	$(obj).remove();
}

