// feddback. подставляет готовые темы для письма
function copyS(subj)
{
	document.forms['feedback'].elements['subject'].value = subj;
	return(false);
}

// Цитировать выделенный текст
function postQuote(commentarea,alertmsg) {
	var posttext = '';
	if (window.getSelection){
		posttext = window.getSelection();
	}
	else if (document.getSelection){
		posttext = document.getSelection();
	}
	else if (document.selection){
		posttext = document.selection.createRange().text;
	}
	else {
		return true;
	}
	
	if (posttext==''){
		alert(alertmsg);
		return true;
	} else {
		var quote='[quote]'+posttext+'[/quote]\n';
		var comment=document.getElementById(commentarea);
		addQuote(comment,quote);
	}
	
	return false;
}

// Добавить выделенный текст в форму
function addQuote(comment,quote){
	if (document.selection) {
		comment.focus();
		sel = document.selection.createRange();
		sel.text = quote;
		comment.focus();
	}
	else if (comment.selectionStart || comment.selectionStart == '0') {
		var startPos = comment.selectionStart;
		var endPos = comment.selectionEnd;
		var cursorPos = endPos;
		var scrollTop = comment.scrollTop;
		if (startPos != endPos) {
			comment.value = comment.value.substring(0, startPos)
			              + quote
			              + comment.value.substring(endPos, comment.value.length);
			cursorPos = startPos + quote.length
		}
		else {
			comment.value = comment.value.substring(0, startPos) 
				              + quote
				              + comment.value.substring(endPos, comment.value.length);
			cursorPos = startPos + quote.length;
		}
		comment.focus();
		comment.selectionStart = cursorPos;
		comment.selectionEnd = cursorPos;
		comment.scrollTop = scrollTop;
	}
	else {
		comment.value += quote;
	}
}

// добавить в избранное
function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( window.opera && window.print ) {
		var t = document.createElement('a');
		t.setAttribute('rel', 'sidebar');
		t.setAttribute('href', url);
		t.setAttribute('title', title);
		t.click();
	} else if( document.all ) {  
		window.external.AddFavorite( url, title);  
	}
}

// счётчик символов
function countLength(elem,max,min)
{
	var length = max - elem.value.length;

	length--;
	if (length < 0 ) {length =0;}
	
	document.getElementById(elem.name+'_status').innerHTML = '('+length+')';
}

// Показать и скрыть блок
function show_and_hidden_block(show_block,hidden_block)
{
	document.getElementById(show_block).style.display = 'block';
	document.getElementById(hidden_block).style.display = 'none';
}