var current;

function showItem(obj,interractive)
{
// markItem(obj);
 if(!interractive)
	return;
 if(current != null)
	current.style.visibility = 'hidden';
 current = document.getElementById( obj.id + '_' );

 if(current != null)
 {
  current.style.visibility = 'visible';
  current.style.zIndex = obj.parentNode.style.zIndex + 1;
  current.style.left = (200 + obj.offsetLeft) + 'px';
 }
}

function hideItem(obj)
{
 if(obj != null) obj.style.visibility = 'hidden';
// unmarkItem(obj.parentNode);
}

function markItem(obj)
{
 if(obj != null)
 {
//  obj.style.background = 'RGB(128,128,128)';
  obj.firstChild.style.color = 'RGB(255,168,0)';
//  obj.style.border = '1px solid RGB(204,58,59)';
 }
}

function unmarkItem(obj)
{
 if(obj != null)
 {
//  obj.style.background = 'URL(/images/filler-menu.png)';
  obj.firstChild.style.color = 'RGB(1,51,112)';
//  obj.style.border = '1px solid RGB(185,206,235)';
 }
}

function hideAll()
{
 if(current != null) current.style.visibility = 'hidden';
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}

function addLink(from,to)
{
 selector = document.getElementById(from);
 content = document.getElementById(to);

 if( (content != null)&&(selector != null) )
 {
	 if(content.selectionStart < content.selectionEnd )
	 {
		value_pre	= content.value.substr( 0, content.selectionStart );
		value_selected	= content.value.substr( content.selectionStart, content.selectionEnd-content.selectionStart );
		value_past	= content.value.substr( content.selectionEnd, content.textLength-content.selectionEnd );
	 }
	 else
	 {
		value_pre	= content.value.substr( 0, content.selectionEnd );
		value_selected	= content.value.substr( content.selectionEnd, content.selectionStart-content.selectionEnd );
		value_past	= content.value.substr( content.selectionStart, content.textLength-content.selectionStart );
	 }

	 value  = '<a style="color: rgb(0, 81, 151);" href="/?page=' + selector.options[selector.selectedIndex].value + '" title="' + selector.options[selector.selectedIndex].text + '">';
	 if( value_selected.length == 0 )
		value += selector.options[selector.selectedIndex].text;
	 else
		value += value_selected;

	 value += '<'+'/a'+'>';

	 content.value = value_pre + value + value_past;
 }
}

function addLinkFile( from, to )
{
 selector = document.getElementById(from);
 content = document.getElementById(to);

 if( (content != null)&&(selector != null) )
 {
	 if(content.selectionStart < content.selectionEnd )
	 {
		value_pre	= content.value.substr( 0, content.selectionStart );
		value_selected	= content.value.substr( content.selectionStart, content.selectionEnd-content.selectionStart );
		value_past	= content.value.substr( content.selectionEnd, content.textLength-content.selectionEnd );
	 }
	 else
	 {
		value_pre	= content.value.substr( 0, content.selectionEnd );
		value_selected	= content.value.substr( content.selectionEnd, content.selectionStart-content.selectionEnd );
		value_past	= content.value.substr( content.selectionStart, content.textLength-content.selectionStart );
	 }

	 value  = '<a style="color: rgb(0, 81, 151);" href="/files/?file=' + selector.options[selector.selectedIndex].value + '" title="' + selector.options[selector.selectedIndex].text + '">';
	 if( value_selected.length == 0 )
		value += selector.options[selector.selectedIndex].text;
	 else
		value += value_selected;

	 value += '<'+'/a'+'>';

	 content.value = value_pre + value + value_past;
 }
}

function addImage( obj, to )
{
 selector = document.getElementById(obj);
 content = document.getElementById(to);

 if(selector.value == -1)
 {
	alert('Сначала выберите картинку. Картинка не должна быть пустой.');
	return false;
 }
 content.value += '<img src="/images/' + selector.options[selector.selectedIndex].label + '" alt="">';
 return true;
}

function changeImage(obj)
{
 image = document.getElementById('p' + obj.id);
 if( image != null ) image.src = '/images/?w=150&imgID=' + obj.options[obj.selectedIndex].value;
}

