                                                                                                         
var font_size = 11;
var font_original = 11;
var min_font = 9;
var max_font = 18;

var appNs=navigator.appVersion;
var ns4=(appNs.indexOf("4.77") != -1)||(appNs.indexOf("4.8") != -1);

function artTxt(txFg){
if (!ns4&&!txFg)document.write("<style>.txt{text-align:left;margin-right:118px;}</style>");
}

function saveFontSize(){
	var expire = new Date ();
   	expire.setTime (expire.getTime() + (6000 * 24 * 3600000)); //expires in 6 days from users clock
   	expire = expire.toGMTString();
	document.cookie="font_size="+font_size+"; expires="+expire;
}
	


function loadFontSize(){

  tempArray = document.cookie.split(";");		
  for (tA = 0; tA < tempArray.length; tA++){
	if (tempArray[tA].indexOf('font_size') > -1){
 	  fontValue = tempArray[tA].split("=");
	  font_size = parseInt(fontValue[1]);
	}
  }

}


function setFontSize(){
	
  loadFontSize()
  obj = document.getElementById("info");
  obj.style.fontSize = font_size+"px";

}


function plus (){
  obj = document.getElementById("info");
  font_size = obj.style.fontSize;
  font_size = parseInt(font_size);
  
  if (font_size < max_font)  font_size = font_size + 1;
  
  obj.style.fontSize = font_size+"px";
  saveFontSize();
}



function minus (){
  obj = document.getElementById("info");
  font_size = obj.style.fontSize;
  font_size = parseInt(font_size);

  if (font_size > min_font)  font_size = font_size - 1;

  obj.style.fontSize = font_size+"px";
  saveFontSize()
}



function normal (){
  obj = document.getElementById("info");
  font_size = font_original;
  obj.style.fontSize = font_size+"px";
  saveFontSize()
}

window.onload=new Function("setFontSize(); tabview_initialize('TabView'); ");

/* addEvent: simplified event attachment */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

/* window 'load' attachment */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* grab Elements from the DOM by className */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* toggle an element's display */
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

/* insert an element after a particular node */
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/* Array prototype, matches value in array: returns bool */
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

/* get, set, and delete cookies */
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
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";
}

function getEventSrc(e) {
	if (!e) e = window.event;

	if (e.originalTarget)
	return e.originalTarget;
	else if (e.srcElement)
	return e.srcElement;
}
/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = { 
	xCord : 0,				// @Number: x pixel value of current cursor position
	yCord : 0,				// @Number: y pixel value of current cursor position
	tipElements : ['a','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,			// @Element: That of which you're hovering over
	tip : Object,			// @Element: The actual toolTip itself
	active : 0,				// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				addEvent(current[j],'mouseover',this.tipOver);
				addEvent(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",500);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			var host = location.hostname.toString();
			var pattern = new RegExp("(http://?)"+host,"gi");
			var fullPath = anch.href.toString();
			var path = fullPath.replace(pattern,'');
			addy = (path.length > 25 ? path.toString().substring(0,25)+"..." : path);
			var access = ( anch.accessKey ? " ["+anch.accessKey+"]" : "" );
		} else {
			addy = anch.firstChild.nodeValue;
		}
		this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',pageLoader);

//Редактор
function smiles(usmivka){
	document.getElementById("emoticon").value = document.getElementById("emoticon").value + usmivka;
}
function linkkk(){
	var ime = prompt ("Въведе име на връзката", "тук");
	if(ime){
		var address = prompt ("Въведете път до връзката", "тук");
		if(address){
			document.getElementById("emoticon").value = document.getElementById("emoticon").value + "[a href=\"" + address + "\"]" + ime + "[/a]";
		}
	}
}
function imgbtn(){
	var alt = prompt ("Въведе име на картинката", "тук");
	if(alt){
		var address = prompt ("Въведете път до картинката", "тук");
		if(address){
			document.getElementById("emoticon").value = document.getElementById("emoticon").value + "[img src=\"" + address + "\" alt=\"" + alt + "\" /]";
		}
	}
}
var imageTag = false;
var theSelection = false;

var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

bbcode = new Array();
bbtags = new Array('[strong]','[/strong]','[em]','[/em]','[underline]','[/underline]','[p]','[/p]','[br /]','','[h1]','[/h1]','[h2]','[/h2]','[h3]','[/h3]','[pre]','[/pre]','[a href=""]','[/a]');
imageTag = false;

function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function textfont(bbopen, bbclose) {
	var txtarea = document.getElementById('emoticon');

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}


function textstyle(bbnumber) {
	var txtarea = document.getElementById('emoticon');

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) {
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.getElementById("post").add' + butnumber + '.value');
			eval('document.getElementById("post").add' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false;
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}

	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.getElementById("post").add' + butnumber + '.value');
				eval('document.getElementById("post").add' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else {

		/*if (imageTag && (bbnumber != 14)) {
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;
			document.getElementById("post").add14.value = "h3";
			imageTag = false;
		}*/

		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1;
		arraypush(bbcode,bbnumber+1);
		eval('document.getElementById("post").add'+bbnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

function mozWrap(txtarea, bbopen, bbclose)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + bbopen + s2 + bbclose + s3;
	return;
}

document.write('<script src="design/js/lib/prototype.js" type="text/javascript"></script><script src="design/js/src/scriptaculous.js" type="text/javascript"></script> <script src="design/js/src/unittest.js" type="text/javascript"></script>');

function smiles(usmivka){
   	  document.getElementById("emoticon").value = document.getElementById("emoticon").value + usmivka;
	}
function vote(rate){
	if (rate == "0") document.getElementById("vote").style.background = "url(design/img/vote/rate" + rate + ".gif)";  else 
		document.getElementById("vote").style.background = "url(design/img/vote/rate" + rate + ".gif)";
	}
function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Ограничение: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
function izgled(){
	var htmlkod, csskod, pagetitle
	htmlkod = document.redaktor.htmlcode.value;
	csskod = document.redaktor.csscode.value;
	document.write('<html>\n<head>\n<title>CSS Самоучител редактор</title>\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />\n<style type="text/css">\n<!--\n', csskod, '\n-->\n</style></head>\n<body>\n<a href="javascript:print()">Принтирай</a>&nbsp;<a href="editor.php">Назад</a><br />\n', htmlkod, '\n</body>\n</html>');
}
function source(){
var htmlkod, csskod, pagetitle
	htmlkod = document.redaktor.htmlcode.value;
	csskod = document.redaktor.csscode.value;
	pagetitle = "";
	document.write('<html>\n<head>\n<title>source</title>\n</head>\n<body>\n<form name="test1">\n<textarea name="select1" cols="50" rows="10" onFocus="this.select()">', '<html>\n<head>\n<title>', pagetitle, '</title>\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />\n<style type="text/css">\n<!--\n', csskod, '\n-->\n</style>\n</head>\n<body>\n', htmlkod, '\n</body>\n</html>','\n</textarea>\n</form>\n</body>\n</html>');
}
function novo(){
	var answer=confirm("Изтриване на всичко. Сигурни ли сте?")
			if(answer)
				{
					window.location= "editor_new.php";
				}
}
function change(){
	document.getElementById('save').value ="Запази*"
}
// An array of colours that will be applied to h2 tags.
var h2Cols = ['#FFFFFF', '#DDDDDD', '#BBBBBB', '#999999', '#777777', '#555555'];

// Main script.
var h2Arr = [];
function h2Setup()
{
 h2Arr = document.getElementsByTagName('h2');
 for (var h = 0; h < h2Arr.length; h++)
 {
  var h2 = h2Arr[h], text = h2.firstChild.nodeValue;
  h2.removeChild(h2.firstChild);
  h2.animNodes = [];
  for (var i = 0; i < text.length; i++)
  {
   var span = document.createElement('span');
   span.appendChild(document.createTextNode(text.substring(i, i+1)));
   h2.appendChild(span);
   h2.animNodes[h2.animNodes.length] = span;
  }
  h2.animCount = 0;
  h2.animTimer = setInterval('h2Anim(' + h + ')', 50);
 }
};
function h2Anim(h)
{
 var h2 = h2Arr[h], c = h2.animCount++, noAnim = 1;
 for (var i = 0; i < h2.animNodes.length; i++)
 {
  var s = h2.animNodes[i], frac = Math.max(0, Math.min(1, (c-i)/5)),
   marg = document.all && !window.opera ? 'marginRight' : 'marginLeft';
  if (s.animDone) continue;
  noAnim = 0;
  s.style.color = h2Cols[Math.floor(frac * 0.99999 * h2Cols.length)];
  if (frac == 1)
  {
   s.style[marg] = '0';
   s.animDone = 1;
  }
  else s.style[marg] = 3.6*(1-frac) + 'px';
 }
 if (noAnim) clearInterval(h2.animTimer);
 h2.style.visibility = 'inherit';
};

if (document.documentElement)
{
 // Hide h2 elements for animation and trigger show on load.
 //document.write('<style type="text/css"> h2 { visibility: hidden } </style>');
 var h2aOL = window.onload;
 window.onload = function()
 {
  if (h2aOL) h2aOL();
  h2Setup();
 }
}
function tabview_aux(TabViewId, id)
{
  var TabView = document.getElementById(TabViewId);

  // ----- Tabs -----

  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs" ) Tabs = Tabs.nextSibling;

  var Tab = Tabs.firstChild;
  var i   = 0;

  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href      = "javascript:tabview_switch('"+TabViewId+"', "+i+");";
      Tab.className = (i == id) ? "Active" : "";
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  // ----- Pages -----

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;

  var Page = Pages.firstChild;
  var i    = 0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight-2)+"px";
      Page.style.overflow = "auto";
      Page.style.display  = (i == id) ? 'block' : 'none';
    }
  }
  while (Page = Page.nextSibling);
}

// ----- Functions -------------------------------------------------------------

function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }

function tabview_initialize(TabViewId) { tabview_aux(TabViewId,  1); }