/* Функції сайта Леся Українка :*/
function PseudoClick(Name) {
var	F = GetCookie(Name);
	if (F == 1) {
		var P = document.getElementById(Name);
		if (P)
			P.click();
	}
} // PseudoClick

function ToggleBlockNote(Sender) {
var ID = Sender.id;
var IDNote = ID + 'Div';
var Elem = document.getElementById(IDNote);
	if (Elem != null) {
  var ToggleOn = Elem.style.display;
	if (ToggleOn == 'none')
		Elem.style.display = 'block'
	else
	  Elem.style.display = 'none';
	}
} // ToggleBlockNote

function ToggleInlineNote(Sender, HTML, CSS) {
var ID = Sender.id;
var IDNote = ID + 'Note';
var Pr = Sender.parentNode;
var Elem = document.getElementById(IDNote);
	if (Elem == null) {
  	var Dsc = document.createElement('span');
		Dsc.setAttribute('id', IDNote);
		Dsc.style.cssText = CSS;
		Pr.insertBefore(Dsc, Sender.nextSibling);
		Elem = document.getElementById(IDNote);
		Elem.innerHTML = HTML;
	}
	else {
		Pr.removeChild(Elem);
	}
} // ToggleInlineNote

function ToggleNote(Sender, HTML) {
	ToggleInlineNote(Sender, HTML, 'color: #006600');
} // ToggleNote

function ToggleStyle(Sender) {
var i, oRule;
var StyleName = Sender.name;
var oStyleSheet = document.styleSheets[1];
	oRule = null;
	for (i=0; i < oStyleSheet.rules.length; i++) {
  	if (StyleName == oStyleSheet.rules[i].selectorText)
  		oRule = oStyleSheet.rules[i];
  }
  if (oRule != null) {
	  if (Sender.checked) {
			switch (oRule.selectorText) {
		  	case '.Hint' :
		    	oRule.style.cssText = 'color: #990000';
		      break;
		  	case '.AnchorHidden' :
		    	oRule.style.cssText = 'background: #CCCCCC';
		      break;
		  	case '.Joke' :
		    	oRule.style.cssText = 'background: #CCFFCC';
		      break;
		  	case 'A.Link' :
		    	oRule.style.cssText = 'color: #0000FF; text-decoration: underline';
		      break;
		  }
      SetCookie(StyleName, 1);
	  }
	  else {
    	switch (oRule.selectorText) {
      	case '.Hint' :
        	oRule.style.cssText = 'color: #000000';
          break;
      	case '.AnchorHidden' :
        	oRule.style.cssText = 'color: #000000';
          break;
      	case '.Joke' :
        	oRule.style.cssText = 'color: #000000';
          break;
      	case 'A.Link' :
        	oRule.style.cssText = 'color: #000000; text-decoration: none';
          break;
      }
      DeleteCookie(StyleName, '/', "");
	  }
  }
} // ToggleStyle

function ToggleVisibility(Item) {
var x, i, ToggleOn;
	x = document.getElementById(Item);
	ToggleOn = x.checked;
var aDivs = document.body.getElementsByTagName("div");
	for (i=0; i<aDivs.length; i++) {
		x = aDivs[i];
		if (x.className == Item) {
			if (ToggleOn)
				x.style.display = 'block'
			else
			  x.style.display = 'none';
		}
	}
} // ToggleVisibility

function VarText(Item) {
var x, y, i, S;
var aDivs = document.body.getElementsByTagName("div");
	for (i=0; i<aDivs.length; i++) {
		x = aDivs[i];
		S = x.className;
		if (S.indexOf('Var') == 0) {
			if (Item == 'Canonic')
			  x.style.display = 'none'
			else {
				if (S == Item) {
					x.style.display = 'block'}
				else
					x.style.display = 'none';
			}
		}
	}
} // VarText

function VarTextAdd(Item) {
	var x;
//	x = document.all['AddCanonic'];
	x = document.getElementById('AddCanonic');
	if (Item == 'Canonic')
		x.style.display = 'block'
	else
		x.style.display = 'none';
	VarText(Item);
} // VarTextAdd

function VarTextAdd2(Item) {
var x, i, S;
var aDivs = document.body.getElementsByTagName("div");
	for (i=0; i<aDivs.length; i++) {
		x = aDivs[i];
		S = x.id;
		if (S.indexOf('AddCanonic') == 0) {
			if (Item == 'Canonic')
				x.style.display = 'block'
			else
				x.style.display = 'none';
			}
		}
		VarText(Item);
} // VarTextAdd2

/* Управління Cookie */
function GetCookie(c_name) {
if (document.cookie.length > 0) {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) {
    c_start=c_start + c_name.length + 1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1)
			c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
  }
}
return "";
} // getCookie

function SetCookie(c_name, value) {
	document.cookie = c_name + "=" + escape(value) + "; path=/";
} // setCookie

function DeleteCookie( name, path, domain ) {
if ( GetCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
} // DeleteCookie

/* Закладки */
function AddBookmark(url, title) {
// http://www.tigir.com/addbookmark.htm
  if (!url) url = location.href;
  if (!title) title = document.title;

  //Gecko
//  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
  if (window.sidebar)
  	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;
} // AddBookmark

function CopyToClipboard(text) {
  if (window.clipboardData) {
  	window.clipboardData.setData('text', text);
  }
  else {
		var clipboarddiv=document.getElementById('divclipboardswf');
    if(clipboarddiv==null) {
      clipboarddiv=document.createElement('div');
      clipboarddiv.setAttribute("name", "divclipboardswf");
      clipboarddiv.setAttribute("id", "divclipboardswf");
      document.body.appendChild(clipboarddiv);
    }
    clipboarddiv.innerHTML='<embed src="http://' + document.location.hostname + '/files/common/swf/clipboard.swf" FlashVars="clipboard='+
encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	}
  return false;
} // CopyToClipboard

function BmkP(Elt) {
// DisplayBmkPanel
var X = Elt.id;
	if (document.getElementById(X + 'BmkPanel'))
		return false;
var A, B, C, D, D2;
	switch (CurrentLang) {
		case 'uk' :
			A = 'Номер рядка (уступа)';
			B = 'Копіювати URL рядка (уступа) в буфер обміну';
			C = 'Встановити закладку на цей рядок (уступ)';
			D = 'К';
			D2 = 'З';
			break;

		case 'ru' :
			A = 'Номер строки (абзаца)';
			B = 'Копировать URL строки (абзаца) в буфер обмена';
			C = 'Установить закладку на эту строку (абзац)';
			D = 'К';
			D2 = 'З';
			break;

		default:
			A = 'Line (paragraph) number';
			B = 'Copy this line (paragraph) URL to clipboard';
			C = 'Bookmark this line (paragraph)';
			D = 'C';
			D2 = 'B';
	}
var Y = ' <span id="' + X + 'BmkPanel" style="white-space: nowrap">';
	Y = Y + '</span>';
	Y = Y + '<span title="' + A + '">(' + X.substr(4) + ')</span> ';
var U = GetBaseURL();
	Y = Y + '<a title="' + B + '" href="#' + X + '" onclick="CopyToClipboard(\'' + U + '#' + X + '\'); return false;">' + D + '</a> ';
	A = document.title + ', ' + X;
	Y = Y + '<a title="' + C + '" href="#' + X + '" onclick="AddBookmark(\'' + U + '#' + X + '\', \'' + A + '\'); return false;">' + D2 + '</a>';
	Elt.innerHTML = Elt.innerHTML + Y;
	return false;
} // BmkP

/* Плаваюча панель */
var FloatPanelActive = 0;
var FloatPanelPosition = 4;

function DisplayFloatPanel(Position) {
var FP = document.getElementById('FloatPanel');
	if (!FP)
  	return;
  if (!Position)
   	Position = Math.abs(FloatPanelPosition);
	switch (Position) {
  	case -1:
    	FloatPanelPosition = -FloatPanelPosition;
    	FP.style.display = 'none';
      break;
    case 1:
    	FP.style.display = 'block';
      FloatPanelPosition = 1;
      FP.style.bottom = 'auto';
      FP.style.right = 'auto';
      FP.style.left = '30px';
      FP.style.top = '30px';
      break;
    case 2:
    	FP.style.display = 'block';
      FloatPanelPosition = 2;
      FP.style.bottom = 'auto';
      FP.style.right = '30px';
      FP.style.left = 'auto';
      FP.style.top = '30px';
      break;
    case 3:
    	FP.style.display = 'block';
      FloatPanelPosition = 3;
      FP.style.bottom = '30px';
      FP.style.right = '30px';
      FP.style.left = 'auto';
      FP.style.top = 'auto';
      break;
    case 4:
    	FP.style.display = 'block';
      FloatPanelPosition = 4;
      FP.style.bottom = '30px';
      FP.style.right = 'auto';
      FP.style.left = '30px';
      FP.style.top = 'auto';
      break;
  }
  SetCookie('FPPos', FloatPanelPosition);
} // DisplayFloatPanel

function GetBaseURL() {
var U = document.URL;
var P = U.indexOf('#');
	if (P >= 0)
		U = U.substr(0, P);
	return U;
} // GetBaseURL

var FPBStyle = 'inline';

function InitFloatPanel() {
	if (!FloatPanelActive)
		return;
var FPB = document.getElementById('FPanelBtn');
	if (FPB)
		FPB.style.display = FPBStyle;

var FPP = GetCookie('FPPos');
  if (FPP == '')
  	FPP = 4;
  else
  	FPP = parseInt(FPP);
  if (FPP > 0)
	  DisplayFloatPanel(FPP);
	else {
		FloatPanelPosition = Math.abs(FPP);
		DisplayFloatPanel(-1);
	}
	PseudoClick('Hint');
	PseudoClick('AnchorHidden');
	PseudoClick('Link');
	PseudoClick('Joke');
} // InitFloatPanel

DoLoadFunc = InitFloatPanel;
