function reloadchcks(elname, frmname) {
	if (!frmname) frmname = "def1";
	
	var p = document.forms[frmname].elements[elname];
	
	if (p.checked) {
			document.getElementById('divtype_1').style.display="";
	}
	if (!p.checked) {
		document.getElementById('divtype_1').style.display="none";
			
	}		
}

function galPicNextImg(p) {
	var hold = document.getElementById('nextBut');
	if(hold) {
		document.location.href= hold.href;
	} 
	
	return false;
}


function hideGalPic(n) {
	if (document.getElementById) {
		document.getElementById('picNoScript_' + n).style.display = 'none';
	}
}

function doNext() {
	if(currentPic < (NUM_PICS)) {
		document.getElementById(NDIV).style.textDecoration='none';
		document.getElementById(NDIV).style.color='';
	} else {
		document.getElementById(NDIV).style.color=DISABLECOLOR;
		document.getElementById(NDIV).style.textDecoration='line-through';
	}
}

function doBack(){
	if(currentPic > 1) {
		document.getElementById(BDIV).style.textDecoration='none';
		document.getElementById(BDIV).style.color='';
	} else {
		document.getElementById(BDIV).style.color=DISABLECOLOR;
		document.getElementById(BDIV).style.textDecoration='line-through';
	}
}



function showDiv(nDiv) {	
	for(var i = 1; i <= NUM_PICS; i++) {
		
		if (NUM_PICS > 1) {
			document.getElementById(LINKID_PREF + i).style.background= unselectedColor;
			document.getElementById(LINKID_PREF + i).style.color= currentPicColor;
		}
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			node.style.visibility='visible';
			currentPic = i;
			document.getElementById(LINKID_PREF + currentPic).style.background= currentPicColor;
			document.getElementById(LINKID_PREF + currentPic).style.color= unselectedColor;
		} else if(node) {
			node.style.display='none';
			node.style.visibility='hidden';
		}
	}
	doBack();
	doNext();
}

function showRelDiv(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			node.style.visibility='visible';
			currentPic = i;
		} else if(node) {
			node.style.display='none';
			node.style.visibility='hidden';
		}
	}
	doBack();
	doNext();		
}

function showDivPrev() {
	if(currentPic > 1) {
		if (!RelGall) {
			showDiv(currentPic - 1);
		} else {
			showRelDiv(currentPic - 1);
		}
	}
}

function showDivNext() {
	if(currentPic < NUM_PICS) {
		if (!RelGall) {
			showDiv(currentPic + 1);
		} else {
			showRelDiv(currentPic + 1);
		}				
	}
}


function GallInit(galpic) {
	var i;

	for (i = 1; i < 20; i ++) {
		if (document.getElementById(NAV_DIV + i)) {
			document.getElementById(NAV_DIV + i).style.display='block';
		}
	}
	if (!galpic) {
		showDiv(1);
	} else {
		showDiv(galpic);
	}
}


//~ function GallInit() {
	//~ showDiv(1);
	//~ document.getElementById(NAV_DIV).style.display='block';
	//~ document.getElementById(NAV_DIV).style.visibility='visible';
//~ }


function RelGallInit() {
	showRelDiv(1);
	document.getElementById(NAV_DIV).style.display='block';
	document.getElementById(NAV_DIV).style.visibility='visible';
}


function openw(url, title, options) {
	var newwin = window.open(url, title, options);
	newwin.focus();
}

function showNextFileForm() {
	var form = document.forms['def1'];
	var currfiles = form.numfiles.value;
	var nextfileind = currfiles*1 + 1;
	var nextfile = document.getElementById('file' + nextfileind + 'cont');
	nextfile.style.display = 'block';
	form.numfiles.value = currfiles*1 + 1;
	return true;
}

var kumulatsize = 0;
function resize(oper) {
	var elem = document.getElementById("ourStoryContent");
	if (oper == '+' && kumulatsize < 5) kumulatsize = kumulatsize + 1;
	if (oper == '-' && kumulatsize > -5) kumulatsize = kumulatsize - 1;
	
	elem.className = 'fontSize' + kumulatsize;
}

function vbaneri2(section, htmlstart, htmlend) {
	if (typeof(banners) == 'undefined') return false;
	if (!banners[section]) return false;
	if (showban1==1) {
		document.write(htmlstart);
		vbaneriw(section);
		document.write(htmlend);
	}
}

function setClass( hEl, sClass ) {
	hEl.className = sClass
}

function rate(r, t, i, s) {
	if (!r) return;			// nepodaden rating
	if (t && !i) return;	// type = 1 (msg) i nqma podadeno msgid
	var form;
	var contid;
	if (t) {	// forum msg
		form = document.forms['voteform_' + i];
		contid = 'ratemsg' + i;
	} else {	// story
		form = document.forms['voteform'];
		contid = 'recomend';
	}
		
	var fotoblog = jQuery('.foto-path').length > 0 ? 1 : 0;
	var tema = jQuery('.temaActive').length > 0 ? 1 : 0;
	var debat = jQuery('.debatePath').length > 0 ? 1 : 0;

	var http_request = getxmlhttp();
	if (!http_request) { 
		form.submit();
		return true;
	}
	http_request.open('GET', '/voteform2.php?storyid=' + s + '&type='+ t + '&itemid=' + i +'&rating=' + r +'&fotoblog=' + fotoblog + '&tema=' + tema + '&debat=' + debat, true);
	http_request.onreadystatechange = function() { voteformload(http_request, contid); };
	http_request.send(null);
}

function fptopkareChageShow(p) {
	if (p == 0) return false;

	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, 'tlT' + opt + 'content'); };
	
	var f = document.forms['filter'];
	var opt = f.elements['topfilter'].value;
	if (!opt) return;
	
	var contents = document.getElementById('best').childNodes;
	for (var i = 0; i < contents.length; i ++) {
		if (contents[i].nodeName.toUpperCase() == 'DIV') {
			contents[i].style.display = 'none';
			if (contents[i].id == ('tlT' + opt + 'content')) {
				contents[i].style.display = '';
				http_request.open('GET', './?cache=no&ajaxobj=' + contents[i].className.substring(3), true);
				http_request.send(null);
			}
		}
	}
	
}

function showBizkit(p) {
	var mShowMe;
	var mHideMe;
	
	if(p == 1) {
		mShowMe = document.getElementById('bizkit1');
		mHideMe = document.getElementById('bizkit2');
		document.getElementById('BizkitBG').style.fontWeight = 'bold';
		document.getElementById('BizkitEU').style.fontWeight = 'normal';
	} else {
		mShowMe = document.getElementById('bizkit2');
		mHideMe = document.getElementById('bizkit1');
		document.getElementById('BizkitBG').style.fontWeight = 'normal';
		document.getElementById('BizkitEU').style.fontWeight = 'bold';
	}
	
	mShowMe.style.display = 'block';
	mHideMe.style.display = 'none';
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else 
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

// anketata

function genrandom(i) {
	return Math.floor(Math.random()*i+1)
}

function anketatest() {
	return;
	var CVal = readCookie('anketa1');
	var cdays = 1;
	if (CVal) return;
	if(genrandom(10) == 10) {
		if (confirm('Желаете ли да участвате в анкета на KARIERI.bg?')) {
			cdays = 300;
			window.open('/anketa/');
		}
	}
	createCookie('anketa1', '1', cdays);
}

function anketapopup() {
	var cdays = 1;
	var CVal = readCookie('anketa22');
	if (CVal) return;
	if (genrandom(3) == 3) {
		w = window.open("/anketa1/start.html", "anketa", "width=790,height=500,scrollbars=1,resizable=1,status=0,toolbar=0,location=0,menubar=0,directories=0");
	}
	createCookie('anketa22', '1', cdays);
}

function anketaok(p) {
	return;
	cdays = 300;
	createCookie('anketa1', '1', cdays);
	window.open(p, 'anketareal', 'width=1024,height=700,scrollbars=1,resizable=1,status=1,toolbar=1,location=1,menubar=1,directories=1');
	window.close();
	return false;
}

function anketacancel() {
	window.close();
}

function anketaBarPopup() {
	var endDate = new Date();
	var startDate = new Date();
	var today = new Date();
	
	startDate.setFullYear(2010,11,20);
	endDate.setFullYear(2010,11,24);
	
	if(today >= startDate && today < endDate) {
		var cdays = 356;
		var CVal = readCookie('anketabar63');
		if (CVal) return false;
		if(genrandom(10) == 10) {
			w = window.open("http://www.dnevnik.bg/anketa_bar/", "anketa", "width=600,height=300,scrollbars=1,resizable=1,status=0,toolbar=0,location=0,menubar=0,directories=0");
		}
		createCookie('anketabar63', '1', cdays);
	}
}

anketaBarPopup();

// novini ot dnevnik

function dnevnikChageTab(t) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, t.id + 'content'); };

	var tabs = t.parentNode.getElementsByTagName('a');
	for (var i = 0; i < tabs.length; i ++) {
		tabs[i].className = '';
		if (tabs[i].id == t.id) {
			tabs[i].className = 'filterMenuActive';
		} else {
			tabs[i].className = '';
		}
	}
	var contents = document.getElementById('maindiv').childNodes;
	for (var i = 0; i < contents.length; i ++) {
		if (contents[i].nodeName.toUpperCase() == 'DIV') {
			contents[i].style.display = 'none';
			if (contents[i].id == (t.id + 'content')) {
				contents[i].style.display = '';
				
				http_request.open('GET', './?ajaxobj=' + contents[i].className.substring(3), true);
				http_request.send(null);
			}
		}
	}
}



//~ function dnevnikChageTab(t) {
	//~ t.blur();
	//~ var http_request = getxmlhttp();
	//~ if (!http_request) return true;
	
	//~ http_request.onreadystatechange = function() { hndsubmit(http_request, t.id + 'content'); };

	//~ var tabs = t.parentNode.parentNode.parentNode.getElementsByTagName('span');
	//~ for (var i = 0; i < tabs.length; i ++) {
		//~ tabs[i].className = '';
		//~ if (tabs[i].id == t.id) {
			//~ tabs[i].className = 'sel';
		//~ }
	//~ }
	//~ var contents = document.getElementById('tfMainDiv').childNodes;
	//~ for (var i = 0; i < contents.length; i ++) {
		//~ if (contents[i].nodeName.toUpperCase() == 'DIV') {
			//~ contents[i].style.display = 'none';
			//~ if (contents[i].id == (t.id + 'content')) {
				//~ contents[i].style.display = '';

				//~ http_request.open('GET', './?ajaxobj=' + contents[i].className.substring(3), true);
				//~ http_request.send(null);
			//~ }
		//~ }
	//~ }
//~ }

//menudropdown


function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

/* [MODIFIED] This code commented out, not needed for activate/deactivate
   on mouseover.

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element that was clicked on.

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  // If the active button was clicked on, exit.

  if (el == activeButton)
    return;

  // If the element is not part of a menu, reset and clear the active
  // button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

[END MODIFIED] */

function buttonClick(event, menuId) {

  var button;

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.

  button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;

  // Exit if this button is the currently active one.

  if (button == activeButton)
    return false;

  // [END MODIFIED]

  // Reset the currently active button, if any.

  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {

  var button;

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Activates this button's menu if no other is currently active.

  if (activeButton == null) {
    buttonClick(event, menuId);
    return;
  }

  // [END MODIFIED]

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

  button.className += " menuButtonActive";

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button) + (button.offsetWidth - button.menu.offsetWidth);
  y = getPageOffsetTop(button) + button.offsetHeight;

  // For IE, adjust position.

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";

  // For IE; size, position and show the menu's IFRAME as well.

  if (button.menu.iframeEl != null)
  {
    button.menu.iframeEl.style.left = button.menu.style.left;
    button.menu.iframeEl.style.top  = button.menu.style.top;
    button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
    button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
    button.menu.iframeEl.style.display = "";
  }
  
  button.menu.style.visibility = "visible";
}

function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuButtonActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";

    // For IE, hide menu's IFRAME as well.

    if (button.menu.iframeEl != null)
      button.menu.iframeEl.style.display = "none";
  }
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {

  var item, menu, x, y;

  // Find the target item element and its parent menu element.

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  // Close any active sub menu and mark this one as active.

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  // Highlight the item element.

  item.className += " menuItemHighlight";

  // Initialize the sub menu, if not already done.

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the sub menu, if not already done.

  if (item.subMenu.onmouseout == null)
    item.subMenu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Get position for submenu based on the menu item.

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isIE) {
    maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
      (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
      (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  if (browser.isOP) {
    maxX = document.documentElement.scrollLeft + window.innerWidth;
    maxY = document.documentElement.scrollTop  + window.innerHeight;
  }
  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  // Position and show the sub menu.

  item.subMenu.style.left       = x + "px";
  item.subMenu.style.top        = y + "px";
  item.subMenu.style.visibility = "visible";

  // For IE; size, position and display the menu's IFRAME as well.

  if (item.subMenu.iframeEl != null)
  {
    item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
    item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
    item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth + "px";
    item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
    item.subMenu.iframeEl.style.display = "";
  }

  // Stop the event from bubbling.

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";

    // For IE, hide the sub menu's IFRAME as well.

    if (menu.activeItem.subMenu.iframeEl != null)
      menu.activeItem.subMenu.iframeEl.style.display = "none";

    menu.activeItem.subMenu = null;
  }

  // Deactivate the active menu item.

  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

// [MODIFIED] Added for activate/deactivate on mouseover. Handler for mouseout
// event on buttons and menus.

function buttonOrMenuMouseout(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element the mouse is moving to.

  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
      el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // If the element is not part of a menu, reset the active button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

// [END MODIFIED]

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  // For items with arrows, add padding to item text to make the
  // arrows flush right.

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null) {
      textEl.style.paddingRight = (itemWidth 
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
      // For Opera, remove the negative right margin to fix a display bug.
      if (browser.isOP)
        arrowEl.style.marginRight = "0px";
    }
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // Fix the IE display problem (SELECT elements and other windowed controls
  // overlaying the menu) by adding an IFRAME under the menu.

  //~ if (browser.isIE) {
    var iframeEl = document.createElement("IFRAME");
    iframeEl.frameBorder = 0;
    iframeEl.src = "javascript:;";
    iframeEl.style.display = "none";
    iframeEl.style.position = "absolute";
    iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
    menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
  //~ }

  // Mark menu as initialized.

  menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}


function vbaneritxtcapital(section,prefixhtml,suffixhtml,prefixelem,suffixelem) {
	var ret = '';
	for(i in section) {
		if (showban1==1 && banners[section[i]]) {
			ret += prefixelem + singleBanner(banners[section[i]][0], banners[section[i]][8], banners[section[i]][2], banners[section[i]][3], banners[section[i]][1], banners[section[i]][4], banners[section[i]][5], banners[section[i]][6], banners[section[i]][7], banners[section[i]][9], banners[section[i]][10]) + suffixelem;
			
			var http = false;

			if (navigator.appName == "Microsoft Internet Explorer") {
			  http = new ActiveXObject("Microsoft.XMLHTTP");
			} else {
			  http = new XMLHttpRequest();
			}
			
			var banurl = 'http://' + document.domain + '/lib/banlog.php?type=ban&posid=' + banners[section[i]]['posid'] + '&banid=' + banners[section[i]]['banid'] + '&banorderposid=' + banners[section[i]]['banorderposid'] + '&ipcountry=' + ipcountry + '&ipcity=' + ipcity;

			http.open("GET", banurl);
			http.onreadystatechange = function() {
			  if(http.readyState == 4) {
			  }
			}
			http.send(null);
		}
	}
	
	if(ret) {
		document.write(prefixhtml);
		document.write(ret);
		document.write(suffixhtml);
	}
}

function voteForMsg(msgid, vote, commentHolderId) {
	var intvote;
	var http_request = getxmlhttp();
	if (!http_request) return true;
	if (!msgid || !vote) return false;
	
	if(vote == '+') {
		intvote = 'u';
	} else if(vote == '-') {
		intvote = 'd';
	} else if(vote == '!') {
		intvote = 'r';
	} else {
		return false;
	}
	
	if (vote == '+' || vote == '-') {
		jQuery('#msgid' + msgid + ' .votePlus, #msgid' + msgid + ' .voteMinus').hide();
		jQuery('#msgid' + msgid + ' .votesWait').show();
	} else if(vote == '!') {
		jQuery('#report_' + msgid + ' a').hide();
	}

	http_request.onreadystatechange = function() { 
		voteForMsgResponse(http_request,msgid, commentHolderId, intvote);
	};
	
	http_request.open('GET', '/voteform.php?msg=' + msgid + '&vote=' + intvote, true);
	http_request.send(null);
	return false;
}

function voteForMsgResponse(p, msgid, commentHolderId, reported) {
	if (p.readyState != 4 || p.status != 200) {
		return false;
	}
	
	var rateHolder, split, plus, minus, html = '';
	
	if (reported == 'r') {
		rateHolder = document.getElementById('report_' + msgid);
		rateHolder.innerHTML = '<em>Коментарът бе докладван на модераторите.</em>';
	} else {
		rateHolder = document.getElementById('rate_' + msgid),
		split = p.responseText.split("/");
		
		if ((typeof(split[0]) != "undefined") && (typeof(split[1]) != "undefined")) {
			plus = Math.round((split[1]*1 + split[0]*1) / 2);
			minus = Math.round((split[1] - split[0]) / 2);
			
			html = '<span>Оценка<br />';
			if (minus > 0) {
				html += '<strong class="negative">-' + minus + '</strong>';
			}
			if (plus > 0) {
				html += ' <strong class="positive">+' + plus + '</strong>';
			}
			html += '</span>';
			
			rateHolder.innerHTML = html;
		}
		jQuery('#msgid' + msgid + ' .votesWait').hide();
	}
	
	return false;
}

function setVisibility(id, visibility) {
	document.getElementById(id).style.display = visibility;
}

function buzzdashvote(pformname) {
	var bbpansid;
	
	var pfrm = document.forms[pformname];
	
	if (!pfrm) return false;
	var els = pfrm.elements["anketaans[]"];
	
	if (!els) return false;
	for (var i = 0; i < els.length; i++) {
		if (els[i].checked) {
			bbpansid = els[i].attributes['bbpansid'];
			if (!bbpansid) {
				return false;
			}
		}
	}
	
	if (!bbpansid) return false;
	if (!bbpansid.value) return false;
	
	var vals = bbpansid.value.split('_');
	if (!vals || !vals[0] || !vals[1]) return false;
	jQuery(document.body).append('<iframe src="http://www.buzzdash.bg/vote/?BB_id=' + vals[0] + '&BBO_id=' + vals[1] + '" border="0" frameborder="0" width="1" height="1"></iframe>');
	
	return true;
}

function loadlateTrigger(context) {
	var items = $(context).find('.loadlate');
	
	if (items.length && typeof items.appear == 'function') {
		items.show().appear(function() {
			var loadlate = $(this).attr('loadlate');

			if (loadlate) {
				$(this).attr('src', loadlate);
				$(this).removeAttr('loadlate');
			}
		});
		items.removeClass('hidden');
	}
}

jQuery(document).ready(function() {
	// lazy load
	(function($) {
		loadlateTrigger(document);
	})(jQuery);
	
	$('.nclMultimediaHold').children('ul').find('a').on('click', function() {
		var itemName = $(this).data('rel');
		
		if (typeof itemName != 'undefined') {		
			$('.multimediaHolder').load('?ajaxobj=' + itemName, function() {
				var arrows = $(this).parent().parent().find('.arrws').find('a');
				
				$(this).css('margin-left', 0);
				$(arrows[0]).addClass('rightArrw').removeClass('rightArrwOff');
				$(arrows[1]).addClass('leftArrwOff').removeClass('leftArrw');
				
				loadlateTrigger($('.nclMultimediaHold'));
			}); 
			$(this).parent().parent().find('a.active').removeClass('active'); 
			$(this).addClass('active'); 
		}
		
		return false;
	});		
	
	jQuery(".blogyear a").click(function () {
		jQuery(".blogyear" + jQuery(this).text()).toggle();	
    });    

	var userAgent = navigator.userAgent.toLowerCase();
	jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
	var version = 0;
	if(jQuery.browser.chrome){
		userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
		userAgent = userAgent.substring(0,userAgent.indexOf('.'));
		version = userAgent;
		jQuery.browser.safari = false;
		showToolbar();
	}

	var bigGalleryStory = jQuery('.gallShow');
	if(bigGalleryStory.length) { //koda da se izpulnqva samo ako ima takuv div
		jQuery('#msg').focus(function(e) {
			if(typeof(galKeyPressHandler) == 'function') {
				jQuery(document).unbind('keyup', galKeyPressHandler);
			}
		});
		
		jQuery('#msg').change(function(e) {
			if(typeof(galKeyPressHandler) == 'function') {
				jQuery(document).unbind('keyup', galKeyPressHandler);
			}
		});
		
		jQuery('#msg').blur(function(e) {
			jQuery(document).bind('keyup', galKeyPressHandler);
		});
		
		function galKeyPressHandler(e) {
			if(e.keyCode == 39) { //next ->
				var nextlnk = jQuery('.wrapMImage:visible .rightNav a');
				if(nextlnk.length) {
					nextlnk.click();
				}
			} else if(e.keyCode == 37) { //prev <-
				var prevlnk = jQuery('.wrapMImage:visible .leftNav a');
				if(prevlnk.length) {
					prevlnk.click();
				}
			} else {
				return false;
			}
		};
		
		jQuery(document).bind('keyup',galKeyPressHandler);
	}

	jQuery("a[rel*='lightbox[roadtrip]']").lightBox({
		txtImage: 'Снимка',
		txtOf: 'от',
		imageLoading: 'lib/lightbox2.04/images/loading.gif',
		imageBtnClose: 'lib/lightbox2.04/images/closelabel.gif',
		imageBtnPrev: 'lib/lightbox2.04/images/prevlabel.gif',
		imageBtnNext: 'lib/lightbox2.04/images/nextlabel.gif'
	});

	jQuery('.accentMenu li').hover(
		function(){
			jQuery('.accentContentNew').stop(true, true);
			jQuery('.accentMenu li').removeClass("active");
			jQuery(this).addClass("active");
			jQuery('#accentStory').append(jQuery(this).attr('content'));
			jQuery('.accentContentNew').fadeIn(500, function () {
				jQuery('.accentContentActive').remove();
				jQuery('.accentContentNew').addClass('accentContentActive');
				jQuery('.accentContentActive').removeClass('accentContentNew');
			});
		}, function(){
	});
	
	jQuery('.sectionMenuRight li').hover(
		function(){
			jQuery('.accentContentNew').stop(true, true);
			jQuery('.sectionMenuRight li').removeClass("sectionMenuActive");
			jQuery(this).addClass("sectionMenuActive");
			jQuery('#accentStory').append(jQuery(this).attr('content'));
			jQuery('.accentContentNew').fadeIn(500, function () {
				jQuery('.accentContentActive').remove();
				jQuery('.accentContentNew').addClass('accentContentActive');
				jQuery('.accentContentActive').removeClass('accentContentNew');
			});
		}, function(){
	});
	
	jQuery('#blogCalendar a').click(
		function(){
			jQuery(this).parent().siblings('li').removeClass('today'); 
			jQuery(this).parent().addClass('today');
		}
	);
	
	//~ jQuery('.filterMenu a').click(
		//~ function(){
			//~ jQuery('#filter').load('./?ajaxobj=' + (jQuery(this).attr('ajaxobj'))); 
			//~ jQuery(this).parent().siblings().children('a .filterMenuActive').removeClass('filterMenuActive'); 
			//~ jQuery(this).parent().children().addClass('filterMenuActive');
		//~ }
	//~ );
	
	jQuery('.buttresOff').click (
		function(){
			jQuery.get('/ajaxpoll.php?formname=anketa&type=1&posid=' + jQuery(this).attr('posid') + '&pollid=' + jQuery(this).attr('pollid') + '&pollpage=&anketaans[]=' + jQuery(this).attr('ansid') + '&votenow=1', null, function(data, textstatus){
				jQuery('.content #pollres').html(data);
			});
			jQuery('.showResults a, .showResults i').hide();
		}
	);
	
	jQuery('.answer a').click (
		function(){
			jQuery.get('/ajaxpoll.php?formname=anketa&type=1&posid=' + jQuery(this).attr('posid') + '&pollid=' + jQuery(this).attr('pollid') + '&pollpage=&anketaans[]=' + jQuery(this).attr('ansid') + '&votenow=1', null, function(data, textstatus){
				jQuery('.content #pollres').html(data);
			});
			jQuery('.showResults a, .showResults i').hide();
		}
	);
	
	jQuery('.answer a').hover (
		function(){
			jQuery(this).parent().siblings().addClass('buttresOffactive');
			jQuery(this).parent().siblings().removeClass('buttresOff');
		},
		function(){
			jQuery(this).parent().siblings().removeClass('buttresOffactive');
			jQuery(this).parent().siblings().addClass('buttresOff');
		}
	);
	
	jQuery('.showResults a').click (
		function(){
			jQuery.get('/ajaxpoll.php?formname=anketa&type=1&pollid=' + jQuery(this).attr('pollid') + '&viewtype=резултати', null, function(data, textstatus){
				jQuery('.content #pollres').html(data);
			});
			jQuery('.showResults').hide();
			jQuery('.pollBack').show();
		}
	);
	
	jQuery('.pollBack a').click (
		function(){
			jQuery.get('/ajaxpoll.php?type=1&formname=anketa&pollid='+ jQuery(this).attr('pollid') + '&posid='+ jQuery(this).attr('posid') + '', null, function(data, textstatus){
				jQuery('.content #pollres').html(data);
				jQuery('.buttresOff').click (
					function(){
						jQuery.get('/ajaxpoll.php?formname=anketa&type=1&posid=' + jQuery(this).attr('posid') + '&pollid=' + jQuery(this).attr('pollid') + '&pollpage=&anketaans[]=' + jQuery(this).attr('ansid') + '&votenow=1', null, function(data, textstatus){
							jQuery('.content #pollres').html(data);
						});
					}
				);
	
				jQuery('.answer a').click (
					function(){
						jQuery.get('/ajaxpoll.php?formname=anketa&type=1&posid=' + jQuery(this).attr('posid') + '&pollid=' + jQuery(this).attr('pollid') + '&pollpage=&anketaans[]=' + jQuery(this).attr('ansid') + '&votenow=1', null, function(data, textstatus){
							jQuery('.content #pollres').html(data);
						});
					}
				);
			});	
				
			jQuery('.pollBack').hide();
			jQuery('.showResults').show();
		}
	);
	
	
	jQuery('.grafikNaviHeader a').click(
		function(){
			jQuery(this).parent().siblings().children('a').removeClass('active'); 
			jQuery(this).parent().children().addClass('active');
		}
	);
	
	jQuery('.grafikNaviFooter a').click(
		function(){
			jQuery(this).parent().siblings().children('a').removeClass('active'); 
			jQuery(this).parent().children().addClass('active');
		}
	);
	
	jQuery('.expand a').click (
		function(){
			jQuery(this).parent().parent().hide().siblings('.expandable').show();
		}
	);
	
	jQuery('.expandContent a').click (
		function(){
			jQuery(this).parent().hide().siblings('.expandable').show();
			//~ jQuery(this).parent().parent().parent().parent().parent().parent().parent().css('float', 'none');
			//~ jQuery(this).parent().parent().parent().parent().parent().parent().parent().addClass('iemargin');

		}
	);
	
	jQuery('.shrink a').click (
		function(){			
			jQuery(this).parent().parent().parent().hide().siblings().show();
			jQuery(this).parent().parent().parent().siblings().children('.expand').show();
			jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().css('float', 'left');
			jQuery(this).parent().parent().parent().parent().parent().parent().parent().css('float', 'left');
			jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().removeClass('iemargin');
		}
	);
	
	jQuery('.shrinkvideo a').click (
		function(){			
			jQuery(this).parent().parent().parent().siblings().show().siblings('.expandable').hide();
		}
	);
	
	jQuery('.fSize').click(function() {
		var txtHolder = jQuery('#ourStoryContent'); 
		if(txtHolder.hasClass('fontSize0')) {
			txtHolder.removeClass('fontSize0').addClass('fontSize5 lineHeight1_3');
			jQuery(this).removeClass('txtBig').addClass('txtMini');
			jQuery(this).children('a').attr('title', 'Намаляване на шрифта');
			createCookie('fontSize',1);
		} else {
			txtHolder.removeClass('fontSize5 lineHeight1_3').addClass('fontSize0');
			jQuery(this).removeClass('txtMini').addClass('txtBig');
			jQuery(this).children('a').attr('title', 'Увеличаване на шрифта');
			createCookie('fontSize',0);
		}
		
		return false;
	});
	
	jQuery('.filterLightPhoto a').click(
		function(){
			jQuery(this).parent().siblings().children('a').removeClass('activePhoto'); 
			jQuery(this).parent().children().addClass('activePhoto');
			jQuery('.lightPhotoProp p').html(jQuery(this).attr('alt'));
		}
	);
	
	jQuery('.innerK1').click(function() {
		jQuery('html,body').animate({scrollTop: jQuery('#k1').offset().top},500);
		return false;
	});
	
	jQuery('.dosieP').live('click', function() {
		jQuery('html,body').animate({scrollTop: jQuery('.galMenu').offset().top},700);
	});
	
	jQuery('.innerK2').click(function() {
		jQuery('html,body').animate({scrollTop: jQuery('#k2').offset().top},500);
		return false;
	});
	
	jQuery('.innerK3').click(function() {
		jQuery('html,body').animate({scrollTop: jQuery('#k3').offset().top},500);
		return false;
	});
	
	jQuery('.innerLight').click(function() {
		jQuery('html,body').animate({scrollTop: jQuery('#LIGHT').offset().top},500);
		return false;
	});
	
	jQuery('.modLnk a').click(function(){
		jQuery('html,body').animate({scrollTop: jQuery('#mod').offset().top},500);
		return false;
	});
	
	jQuery('.proLnk a').click(function(){
		jQuery('html,body').animate({scrollTop: jQuery('#pro').offset().top},500);
		return false;
	});
	
	jQuery('.conLnk a').click(function(){
		jQuery('html,body').animate({scrollTop: jQuery('#con').offset().top},500);
		return false;
	});
	
	jQuery('.morebrowse').click(function() {
		jQuery('html,body').animate({scrollTop: jQuery('#clndrbox').offset().top},500);
		return false;
	});
	
	jQuery("#cmntsbscr").click(function () {
		if (jQuery('input[name=cmntsbscr]:checked').val() == 1) {
		//zapisva
			jQuery.get('/forumalerts.php?itemid=' + jQuery(this).attr('itemid') + '&uid=' + jQuery(this).attr('uid') + '&a=1', null, function(data, textstatus){
				jQuery('#cmntsbscrtxt').html(data);
			});
		} else {
		//otpisva
			jQuery.get('/forumalerts.php?itemid=' + jQuery(this).attr('itemid') + '&uid=' + jQuery(this).attr('uid') + '&a=0', null, function(data, textstatus){
				jQuery('#cmntsbscrtxt').html(data);
			});
		}	
	});
	
	jQuery("#debatsbscr").click(function () {
		if (jQuery('input[name=debatsbscr]:checked').val() == 1) {
			if(!jQuery(this).attr('uid')){ //proverka dali e registriran potrebitel
				jQuery('.debSubscr p').html('За да се абонирате за известия за дебатите, моля <a title="влезте в профила си" href="javascript:openloginthickbox();">влезте в профила си</a> или се <a title="Регистрация" href="javascript:openregthickbox();">регистрирайте</a>');
			}else {
				//zapisva
				jQuery.get('/debatialerts.php?itemid=' + jQuery(this).attr('itemid') + '&uid=' + jQuery(this).attr('uid') + '&a=1', null, function(data, textstatus){
					jQuery('.debSubscr p').html(data);
				});
			}
		}else {
		//otpisva
			if(!jQuery(this).attr('uid')){ //proverka dali e registriran potrebitel
				jQuery('.debSubscr p').html('За да се абонирате за известия за дебатите, моля <a title="влезте в профила си" href="javascript:openloginthickbox();">влезте в профила си</a> или се <a title="Регистрация" href="javascript:openregthickbox();">регистрирайте</a>');
			}else {
				jQuery.get('/debatialerts.php?itemid=' + jQuery(this).attr('itemid') + '&uid=' + jQuery(this).attr('uid') + '&a=0', null, function(data, textstatus){
					jQuery('.debSubscr p').html(data);
				});
			}	
		}	
	});
	
	
	if ((jQuery('input[name=debatsbscr]:checked').val() == 1) && !jQuery('input[name=debatsbscr]').attr('uid')) {
		jQuery('input[name=debatsbscr]').attr('checked', false);
	}

	loadFilterComments();
	
	
	var commentForm = jQuery('#forumPost');
	if(commentForm.length) {
		commentForm.submit(function() {
			if((forumSpamTest(jQuery('#forumPost #msg').val(), false) || (forumSpamTest(jQuery('#forumPost #author').val(), true)) ) && !jQuery('#captcha').val()) {
				
				if(!jQuery('.captchaHolder #captchaInp').length) {
					jQuery('.captchaHolder').html('<div class="captcha"><div id="captchaInp" style="width: 461px; display: block; overflow: hidden; margin-bottom: -35px; _height: 70px; _margin-bottom: 0;">				<span class="L" style="overflow: hidden; line-height: auto; height: auto;">					<img src="/frmcaptcha.php" id="cappic" /><br/>					<a title="Генериране на нов код" href="javascript: void(0);" onclick="return reloadCaptcha();">Генериране на нов код</a>				</span>				<div class="captchaInpDiv">				<label>Моля, въведете кода от изображението в полето по-долу, за да докажете, че не сте спам-робот.</label>					<input type="text" name="captcha" id="captcha">				</div>			</div></div>');
				}
				return false;
			}
			jQuery('.capSendBut').hide(); 
			jQuery('.thanksSubmit').show();
		});
	}
	
	loadFontSize();
	
	jQuery('.linkDosieWrapper').hover(
		function(){
			jQuery(this).children('.linkDosieBox').css({
				'display': 'block'
			});
		},
		function(){
			jQuery(this).children('.linkDosieBox').css({
				'display': 'none'
			}); 
		}
		
	);
		
	$('.tools .recomend .otherInFavList').live('click', function() {
		$(this).next('.recommendUserList').show();
		$(this).hide();
		return false;
	});
	
	
	if ($('.nclPaperClndr').length) {
		
		$.get('/lib/checkcaldates.php?pari=' + jQuery('#isPariCal').html(), function(data) {
			var dateArr = data.split(',')
			limit = (jQuery(dateArr).size());
			for(i=0; i<limit; i++) {
				dateArr[i] = new Date(dateArr[i]).toString();
			}
			$('#monthsArr').html(dateArr.toString());
		});
		
		var startDate =  '10/10/2011';
		if(jQuery('#isPariCal').html()){
			var startDate =  '01/01/2010';
		}
		
		var currentTime = new Date(),
		datePickerParams = {
			'createButton': false, 
			'horizontalOffset': 0,
			'verticalOffset': 0, 
			'startDate': startDate,
			renderCallback:function($td, thisDate, month, year) {
				dateArr = $('#monthsArr').html();
				dateArr = dateArr.split(',')
				if ($.inArray(thisDate.toString(), dateArr) > -1) {
					$td.removeClass('disabled');
				}
				if (thisDate.isWeekend() || ($.inArray(thisDate.toString(), dateArr) == -1)) {
					$td.addClass('disabled');
				}
			}
		};
			
		if (typeof currentTime.asString == 'function') {
			if(jQuery('#isPariCal').html()){
				datePickerParams.endDate = '28/10/2011';
			}else {
				datePickerParams.endDate = currentTime.asString();
			}
			
		}
		
		
		$('.nclPaperClndr').datePicker(datePickerParams)
			.bind('mouseenter', function() {
				var calendar = $(this);
				calendar.dpDisplay();
				
				if (window.location.search) {
					hashes = window.location.search.slice(window.location.search.indexOf('?') + 1).split('&');
					for (var i = 0; i < hashes.length; i++) {
						hash = hashes[i].split('=');
						if (hash[0] == 'd') {
							calendar.dpSetSelected(hash[1], true, true, false);
							break;
						}
					}
				}

				this.blur();
				
				return false;
			})

			
			
			.bind('dateSelected', function(e, selectedDate, $td) {
				var hashes, filter = '';
				
				if (window.location.search) {
					hashes = window.location.search.slice(window.location.search.indexOf('?') + 1).split('&');
					for (var i = 0; i < hashes.length; i++) {
						hash = hashes[i].split('=');
						if (hash[0] == 'f') {
							filter = 'f=' + hash[1] + '&';
						}
					}
				}
				
				if(jQuery('#isPariCal').html()){
					window.location.href = 'http://' + window.location.host + '/vestnikut/?' + filter + 'issuedate=' + selectedDate.asString() + '&pari=1';
				}else {
					window.location.href = 'http://' + window.location.host + '/vestnikut/?' + filter + 'issuedate=' + selectedDate.asString();
				}
				
			});
			
			$('.nclPaperClndr').datePicker(datePickerParams).bind('dpMonthChanged',	function(event, displayedMonth, displayedYear)
				{
					$.get('/lib/checkcaldates.php?pari=' + jQuery('#isPariCal').html(), {month: displayedMonth + 1, year:displayedYear}, function(data) {
						var dateArr = data.split(',')
						limit = (jQuery(dateArr).size());
						for(i=0; i<limit; i++) {
							dateArr[i] = new Date(dateArr[i]).toString();
						}
						$('#monthsArr').html(dateArr.toString());
						$('.nclPaperClndr').dpDisplay();
					});
				}
			)
			
	}
	
	$('body').mousemove(function(e1) {
		cursorPointer = {
			x: e1.pageX,
			y: e1.pageY
		};
	});

	$('.nclHeadNavMain .nclNavOpen a, .nclAccentTitleRow a, .moreContent a, .nclSubNews a').each(function() {
		$(this).attr('href', this + '?ref=upmenu');
	});
	
	$('#bodywrapper .akcentwrapper a').each(function() {
		href = $(this).attr('href');
		href = href.replace('?ref=upmenu', '');
		$(this).attr('href', href + '?ref=akcentmenu');
	});
	
	

	$('.liMenu').hover(
		function(e){
			var el = this,
				o = $(this).offset(),
				elem = {
					top: o.top,
					left: o.left,
					bottom: o.top + $(this).height(),
					right: o.left + $(this).width()
				};
				
			setTimeout(function() {
				var id = $(el).attr('id');
				
				if (cursorPointer.y >= elem.top && cursorPointer.y <= elem.bottom && cursorPointer.x >= elem.left && cursorPointer.x <= elem.right) {
					if (id == 'clrvestnikut' || id == 'active-clrvestnikut') {
						$(el).children('.nclNavOpen').html($('#akcentclrvestnikut').clone());
						
					} else if (id == 'clrinteractive' || id == 'active-clrinteractive') {
						$(el).children('.nclNavOpen').html($('#akcentclrinteractive').html());
						
					} else if(!($(el).children('.nclNavOpen').children('.nclRowHolder').children('.moreContent').html())) {
						$(el).children('.nclNavOpen').children('.nclRowHolder').children('.moreContent').html($('#dummyLayers').find('#akcent' + $(el).attr('id') + '').children('.akcent').html());
						$(el).children('.nclNavOpen').children('.nclRowHolder').children('.moreContent').html($('#dummyLayers').find('#akcent' + ($(el).attr('id') + '').replace('active-', '')).children('.akcent').html());
					}
					$(el).children('.nclNavOpen').show();
					$(el).children('.link').addClass('active');					
				}
			}, 200);
			
		}, function(){
			var el = this;
			
			setTimeout(function() {
				$(el).children('.nclNavOpen').hide();
				$(el).children('.link').removeClass('active');
			}, 200);
		}
	);		
	
	if (!jQuery('#lastCover').siblings('.date').html()){
		jQuery('#dailyNavDate').html(jQuery('#firstCover').siblings('.date').html());
	}else {
		jQuery('#dailyNavDate').html(jQuery('#firstCover').siblings('.date').html() + ' - ' + jQuery('#lastCover').siblings('.date').html());
	}

	$('#akcentclrvestnikut .leftArrw, #clrvestnikut .leftArrw').live('click', function() {
		var cont = $(this).parents('.nclCont'), 
			prev;
		
		if (cont.length) {
			prev = cont.prev('.nclCont');
			
			if (prev.length) {
				cont.hide();
				prev.show();
			}
		}
		
		return false;
	});
	$('#akcentclrvestnikut .leftArrwOff, #clrvestnikut .leftArrwOff').live('click', function() {
		return false;
	});
	$('#akcentclrvestnikut .rightArrw, #clrvestnikut .rightArrw').live('click', function() {
		var cont = $(this).parents('.nclCont'), 
			next;
		
		if (cont.length) {
			next = cont.next('.nclCont');
			
			if (next.length) {
				cont.hide();
				next.show();
			}
		}
		
		return false;
	});
	$('#akcentclrvestnikut .rightArrwOff, #clrvestnikut .rightArrwOff').live('click', function() {
		return false;
	});
	
	//slider daily arc 
	$('.nclArchDaily a.leftArrwBig, .nclArchDaily a.rightArrwBig').click(function() {
		var items = $('.dailyCoversHolder .dailyIssue').length,
			newleft, fin = false;
		if (items > 5) {
			if ($(this).hasClass('leftArrwBig')) { // nazad v tozi sluchai
				newleft = parseInt($('.dailyCoversHolder').css('margin-right'));
				if (newleft == 0) {
					newleft = (-1) * (parseInt($('.dailyCoversHolder').css('margin-right')) + 5*160);
				}else {
					newleft = -((items - 5) * 160);
				}
				newleftVal = newleft;
				newleft = newleft + 'px';
				
				$(".dailyCoversHolder").animate({
					marginRight: newleft
				}, 300, function() {
					
				if (newleftVal < ((-1) * (parseInt($('.dailyCoversHolder').css('margin-right')) + 5*160))){
					$('.nclArchDaily a.rightArrwBig').show();
				}
				
				if (newleftVal == -((items - 5) * 160)){
					$('.nclArchDaily a.leftArrwBig').hide();
				}
				
					
				});
			
			} else if ($(this).hasClass('rightArrwBig')) {
				newleft = parseInt($('.dailyCoversHolder').css('margin-right'));
				if (newleft == -((items - 5) * 160)) {
					newleft = parseInt($('.dailyCoversHolder').css('margin-right')) + 5*160;
					if (newleft == 0) {
						$('.nclArchDaily a.rightArrwBig').hide();
						$('.nclArchDaily a.leftArrwBig').show();
					}	
					//~ }else {
						//~ newleft = parseInt($('.dailyCoversHolder').css('margin-right')) + 5*160;
						//~ $('.nclArchDaily a.lightArrwBig').show();
					//~ }	
				}
				
				newleft = newleft + 'px';
				
				$('.dailyCoversHolder').animate({
					marginRight: newleft
				}, 300, function() {

				});
			}
		}
		
		return false;
	});
	
	$('.nclTopNews.fpage').each(function() {
		var cont = this,
			ban = $('.bann300x250 .bannLabel', cont).next(),
			paidAdv;
		
		if (ban.length && ban.height() > 250) {
			$('.paidAdvert', cont).remove();
		}
	});
	
	if ($('#specialIssueDoc').length) {
		if(!jQuery('.id').data('lguserid')){
			jQuery('#specialIssueDoc a').click(function(){
				tb_show('','/login2download.php?showform=login&modal=true&width=420&height=460','null');
				return false;
			});
		}

	}
	
});


function filterLoad(obj, holder, p) {
	jQuery(holder).load('./?ajaxobj=' + obj);
	jQuery(p).parent().siblings().children('a.filterMenuActive').removeClass('filterMenuActive'); 
	jQuery(p).parent().children().addClass('filterMenuActive');
	createCookie('CapitalFilterTabObj',obj,0);	
	return false;
}

function fpageFilterLoad(obj, holder, p, period) {
	
	jQuery(holder).load('/?ajaxobj=' + obj + '&period=' + period);
 
	$('.nclFilter li').each(function() {
		if ($(this).data('type') == obj) {
			$('span', $(this)).show();
			$('a', $(this)).hide();
			$(this).addClass('activeChoice');
		} else {
			$(this).removeClass('activeChoice');
			$('span', $(this)).hide();
			$('a', $(this)).show();
		}
	});
 
	createCookie('CapitalFilterTabObj',obj,0); 
	return false;
}

function filterLoadPage(obj, holder, p, period) {
	jQuery(holder).load('./?ajaxobj=' + obj + '&period=' + period);
	jQuery(p).parent().siblings().children('a.filterMenuActive').removeClass('filterMenuActive'); 
	jQuery(p).parent().children().addClass('filterMenuActive');
	createCookie('CapitalStoryTabObj',obj,0);	
	return false;
}

function replyTo(postNum, postAuthor) {
	var curVal = jQuery('#msg').val();
	var repStr;
	if(curVal.length > 0) {
		repStr = curVal + '\nДо коментар [#' + postNum + '] от "' + postAuthor + '":\n\n';
	} else {
		repStr = 'До коментар [#' + postNum + '] от "' + postAuthor + '":\n\n';
	}
	jQuery('#msg').val(repStr).focus();
	jQuery('html,body').animate({scrollTop: jQuery('#addcomment').offset().top},500);
	return false;
}


function getTdContent (){	

}

function toggle(id) {
	var hold = document.getElementById(id);
	if(hold.style.display == 'block') {
		hold.style.display = 'none';
	} else if(hold.style.display == 'none') {
		hold.style.display = 'block';
	}
	
	return false;
}

function toggle2a(id) {
	jQuery('#'+id).stop(true,true);
	if(document.getElementById(id).style.display == 'none') {
		jQuery('#'+id+'nav').css({
			'display': 'block'
		});
		jQuery('#'+id).css({
			marginLeft: "320px",
			'display': 'block'
		});
		jQuery('#'+id).animate({
			marginLeft: "0px"
		}, 500, 'swing', function (e) {
			jQuery(this).css({
				'display': 'block'
			});
		});
	} else {
		jQuery('#'+id+'nav').css({
			'display': 'none'
		});
		jQuery('#'+id).css({
			marginLeft: "0px"
		});
		jQuery('#'+id).animate({
			marginLeft: "-320px"
		}, 500, 'swing', function (e) {
			jQuery(this).css({
				'display': 'none'
			});
		});
	}
	return false;
}

function toggle2(id) {
	jQuery('#'+id).stop(true,true);
	if(document.getElementById(id).style.display == 'none') {
		jQuery('#'+id+'nav').css({
			'display': 'block'
		});
		jQuery('#'+id).css({
			marginLeft: "-320px",
			'display': 'block'
		});
		jQuery('#'+id).animate({
			marginLeft: "0px"
		}, 500, 'swing', function () {
			jQuery(this).css({
				'display': 'block'
			});
		});
	} else {
		jQuery('#'+id+'nav').css({
			'display': 'none'
		});
		jQuery('#'+id).css({
			marginLeft: "0px"
		});
		jQuery('#'+id).animate({
			marginLeft: "320px"
		}, 500, 'swing', function () {
			jQuery(this).css({
				'display': 'none'
			});
		});
	}
	return false;
}

function setGraphIndex(holderId, idx, period, dataStore, w, h, dataType) {
	if(!idx) {
		idx = 'dn20';
	}
	if(!period) {
		period = '1d';
	}

	
	if(!w) {
		w = 300;
	}
	
	if(!h) {
		h = 250;
	}
	
	if(dataType) {
		varType = 'c';
	} else {
		varType = 'i';
	}
	
	var flashvars = {
		dataFeederURL: escape('/biznes/flashgraph.php?' + varType + '=' + idx + '&p=' + period)
	};
	
	swfobject.embedSWF('/biznes/graphs.swf', holderId, w, h, '9.0.0', null, flashvars);
	dataStore.activeIdxGraph = idx;
	dataStore.activeIdxPeriod = period;
	
	return false;
}


function calendarChangeMonth(m,y,rn) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, 'clndrbox'); };

	http_request.open('GET', './?ajaxobj=calendar&m=' + m + '&y=' + y + '&rubrikaname=' + rn, true);
	http_request.send(null);
	return false;
}

function uraganCal(rubrname) {
	var month = document.getElementById('calm');
	var year = document.getElementById('caly');
	
	calendarChangeMonth(month.value,year.value,rubrname);
	return false;
}

function debVote(pollid, ansid) {
	if(pollid && ansid) {
		jQuery.get('/ajaxpoll.php', { 'type': 3, 'formname': 'anketa', 'pollid': pollid, 'anketaans': ansid, 'votenow': 1 },
		  function(data){
			jQuery('.debVoteHldr').html(data);
		  });
	}
	return false;
}



function filterComments() {
	var cVal = readCookie('capitalForumFilter');

	if (jQuery('#forumFilter option:selected').val() == 1) {
		jQuery('.singleComment').show();
		jQuery('#commentpreviewbox').hide();
		jQuery('#commentpreviewtitle').hide();
	}
	if (jQuery('#forumFilter option:selected').val() == 2) {
		jQuery('.singleComment').hide();
		jQuery('.singleComment1').hide();
		jQuery('.singleCommentBlue').show();
		jQuery('#commentpreviewbox').hide();
		jQuery('#commentpreviewtitle').hide();
	}
	if (jQuery('#forumFilter option:selected').val() == 3) {
		jQuery('.singleComment').show();
		jQuery('.singleComment1').hide();
		jQuery('.singleCommentBlue').show();
		jQuery('#commentpreviewbox').hide();
		jQuery('#commentpreviewtitle').hide();
	}
	if (jQuery('#forumFilter option:selected').val() == 4) {
		jQuery('.singleComment').hide();
		jQuery('#commentpreviewbox').hide();
		jQuery('#commentpreviewtitle').hide();
	}
	
	if (jQuery('#forumFilter option:selected').val()) {
		createCookie('capitalForumFilter',jQuery('#forumFilter option:selected').val(),1);
	}
}

function loadFilterComments(){
	var cVal = readCookie('capitalForumFilter');
	if (cVal) {
		jQuery('#forumFilter').val(cVal);
		filterComments();
	}
}

function deleteComment(postNum, msgId) {
	var answer = confirm("Наистина ли желаете да изтриете този коментар? ")
	if (answer){
		jQuery.get('/decomments.php?msgid=' + msgId + '', null, function(data, textstatus){
		jQuery('#comment-' + postNum + ' .rightCol').html(data);
		
			});
	}
}

function modAction(id) {
	var actionStr = '';
	var action = jQuery('#candp' + id).val();
	if(action != '') {
		var customtxt = '';
		if(action == 15) {
			customtxt = prompt('Моля въведете името на фирмата');
			if(customtxt == '' || customtxt == null) {
				jQuery('#msg'+id).html('Грешка! Невалидно име.').show();
				setTimeout( 'hideMsg('+ id +');', 5000); 
				return false;
			}
			customtxt = '&custext=' + escape(customtxt);
		}
		
		
		//~ if(topic) {
			//~ actionStr = '&action='+action+'&topic=1' + customtxt;
		//~ } else {
			actionStr = '&action='+action + customtxt;
		//~ }
	}
	
	//~ jQuery('#msg'+id).load('modAct.php?msgid='+id+actionStr,null,function (responseText, textStatus, XMLHttpRequest) {
		//~ jQuery('#msg'+id).show();
		//~ setTimeout( 'hideMsg('+ id +');', 5000); 
	//~ });
	
	 window.open('http://cms.economedia.bg/forums/search/singleModAct.php?msgid=' + id+actionStr + '', null, function(data, textstatus){
		jQuery('cmntTxt').html(data);
	
	});
	
	
	return false;
}

function reloadCaptcha() {
	var img = document.getElementById('cappic');
	img.src = '/frmcaptcha.php?rld=' + Math.random();
	return false;
}


function forumSpamTest(strVal, skipCyrTest) {
	var ret 
	ret = false;
	
	if(strVal) {
		if(strVal.search(/https?:\/\/|www\.\w+/i) !== -1) {
			ret = true;
		} else if(!skipCyrTest && (strVal.search(/[а-я]/i) == -1)) {
			ret = true;
		} else if(strVal.search(/[ёыэ]/i) !== -1) {
			ret = true;
		}
	}
	
	return ret;
}

function scrollPic(pId, light){
	
	if(jQuery('#brandLinkBlock').length) {
		var scrollTo = '#brandLinkBlock';
	} else if(light == 'light') {
		var scrollTo = '.lightTools';
	} else {
		var scrollTo = '.gallInside';
	}
	
	jQuery('html,body').animate({scrollTop: jQuery(scrollTo).offset().top},500);
	return false;
}


function gpush(category, action, label, value) {
	if (_gaq) {
		_gaq.push(['_trackEvent', category, action, label, value]);
	}
	return true;
}

function showpollvoteform(pollid, type) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	if (!pollid || !type) return false;

	http_request.onreadystatechange = function() { 
		if(http_request.readyState != 4 || http_request.status != 200) {
			return false;
		}

		if(typeof(http_request.responseText) == 'undefined') {
			return false;
		}

		document.getElementById('recomend').innerHTML = http_request.responseText;
	};

	http_request.open('GET', '/voteform.php?pollid=' + pollid + '&type=' + type, true);
	http_request.send(null);
	return false;
}

function loadFontSize(){
	var cVal = readCookie('fontSize');
	var txtHolder = jQuery('#ourStoryContent');
	if (cVal == 1) {
		txtHolder.removeClass('fontSize0').addClass('fontSize5 lineHeight1_3');
		jQuery(this).removeClass('txtBig').addClass('txtMini');
		jQuery(this).children('a').attr('title', 'Намаляване на шрифта');
	} else {
		txtHolder.removeClass('fontSize5 lineHeight1_3').addClass('fontSize0');
		jQuery(this).removeClass('txtMini').addClass('txtBig');
		jQuery(this).children('a').attr('title', 'Увеличаване на шрифта');
	}
}

function showToolbar() {
	jQuery('#ext_toolbar').css({backgroundImage: "url('/i/6/ext/chromegradient.png')", fontFamily: 'Georgia, "Times New Roman", Times, serif', fontSize: '14px', color: '#333', borderBottom: '1px solid #CCC', height: "37px"});	
	jQuery('#ext_toolbar').append('<div id="ext_toolbar_close"><span style="display:none;">Затваряне</span></div>');
	jQuery('#ext_toolbar').append('<div id="ext_toolbar_install"><span style="display:none;">Инсталиране</span></div>');
	jQuery('#ext_toolbar').append('<div id="ext_toolbar_text">Опитайте <span id="ext_toolbar_link">приставката на Капитал за Google Chrome</span>. С нея получавате известия за избрани от вас новини от Капитал директно в браузъра. </div>');
	jQuery('#ext_toolbar_link').css({textDecoration:"underline", color: "#0066CC", cursor:"pointer"});
	jQuery('#ext_toolbar_text').css({padding: "11px 10px 10px 38px", background: "url('/i/6/ext/chromeicon.png') no-repeat 5px 5px", overflow:"hidden", whiteSpace:"nowrap", "-webkit-user-select":"none", cursor: "default"});
	jQuery('#ext_toolbar_close').css({float:"right", background: "url('/i/6/ext/chromeclose.png') no-repeat", width:"10px", height:"10px", margin: "14px 10px 0 0", cursor:"pointer"});
	jQuery('#ext_toolbar_install').css({float:"right", background: "url('/i/6/ext/chromeinstall.png') no-repeat", width:"102px", height:"26px", margin: "6px 10px 0 0", cursor:"pointer"});
	
	if(toolbarConfig.slide) {
		jQuery('#ext_toolbar').hide().slideDown('fast');
	}
	
	jQuery('#ext_toolbar_close').click(closeToolbar);
	jQuery('#ext_toolbar_install').click(openExtension);
	jQuery('#ext_toolbar_link').click(openExtension); 
	
	jQuery("embed").attr("wmode", "opaque");
	jQuery(window).resize(flow); 
	jQuery(window).scroll(move);
	move();
}

function closeToolbar() {
	jQuery('#ext_toolbar').slideUp('fast');
	
	if ('localStorage' in window && window['localStorage'] !== null) {
		localStorage[toolbarConfig.hide] = true;
	}
	//createCookie('cptext1', '1', 365);
	
	var date = new Date();
	date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
	var expires = "; expires=" + date.toGMTString();
	
	document.cookie = 'cptext1' + "=" + '1' + expires + "; path=/" + ";domain=.capital.bg";
}

function openExtension() {
	closeToolbar();
	window.open(toolbarConfig.link);
}

function flow() {
	jQuery('#ext_toolbar_text').width(jQuery(window).width() - 185);
	jQuery("#ext_toolbar").css({width:jQuery(window).width()});
}

function move() {
	if(jQuery(window).scrollTop() <= 1) {
		jQuery("#ext_toolbar").css({position:"relative", top: 0});
	}
	else {
		jQuery("#ext_toolbar").css({position:"absolute", top: jQuery(window).scrollTop()+"px", width:jQuery(window).width(), zIndex:"100000"});
	}
	flow();
}

function getNextCovers(){	
	$.get("arccovers.php", {pubdate: jQuery('#lastCover').html(), move: 'fw'}, function(data){
		$('.dailyCovers').html(data);
	});
}

function getPrevCovers(){
	$.get("arccovers.php", {pubdate: jQuery('#firstCover').html(), move: 'bw'}, function(data){
		$('.dailyCovers').html(data);
	});
}

function toggle6a(id) {
	jQuery('#'+id).stop(true,true);
	if(document.getElementById(id).style.display == 'none') {
		jQuery('#'+id+'nav').css({
			'display': 'block'
		});
		jQuery('#'+id).css({
			marginLeft: "470px",
			'display': 'block'
		});
		jQuery('#'+id).animate({
			marginLeft: "0px"
		}, 500, 'swing', function (e) {
			jQuery(this).css({
				'display': 'block'
			});
		});
	} else {
		jQuery('#'+id+'nav').css({
			'display': 'none'
		});
		jQuery('#'+id).css({
			marginLeft: "0px"
		});
		jQuery('#'+id).animate({
			marginLeft: "-470px"
		}, 500, 'swing', function (e) {
			jQuery(this).css({
				'display': 'none'
			});
		});
	}
	return false;
}

function toggle6(id) {
	jQuery('#'+id).stop(true,true);
	if(document.getElementById(id).style.display == 'none') {
		jQuery('#'+id+'nav').css({
			'display': 'block'
		});
		jQuery('#'+id).css({
			marginLeft: "-470px",
			'display': 'block'
		});
		jQuery('#'+id).animate({
			marginLeft: "0px"
		}, 500, 'swing', function () {
			jQuery(this).css({
				'display': 'block'
			});
		});
	} else {
		jQuery('#'+id+'nav').css({
			'display': 'none'
		});
		jQuery('#'+id).css({
			marginLeft: "0px"
		});
		jQuery('#'+id).animate({
			marginLeft: "470px"
		}, 500, 'swing', function () {
			jQuery(this).css({
				'display': 'none'
			});
		});
	}
	return false;
}

function slideboxes(element, elementStyle, itemsLimit, holderName, itemName, itemWidth){
	var items = $(element).parents('.nclRowHolder').find('.' + itemName).length;
	var newleft, newleftVal, fin = false;
	
	if (items > itemsLimit) {
		if (elementStyle == 'leftArrw' && !(parseInt($(element).parents('.nclRowHolder').find('.'+holderName+'').css('margin-left')) % itemWidth)) {
			newleft = parseInt($(element).parents('.nclRowHolder').find('.'+holderName+'').css('margin-left')) + itemsLimit*itemWidth;
			if (newleft > 0) {
				newleft = 0;
				fin = true;
			}
			newleftVal = newleft;
			newleft = newleft + 'px';
			
			$(element).parents('.nclRowHolder').find('.'+holderName+'').animate({
				marginLeft: newleft
			}, 300, function() {
				var newbottom = (-1) * parseInt(parseInt(newleft) / itemWidth) + 1*1;
				
				if (newleftVal < (((items-itemsLimit)*itemWidth))){
					$(element).siblings().addClass('rightArrw');
					$(element).siblings().removeClass('rightArrwOff');
				}
				
				if (newleftVal >= 0){
					$(element).addClass('leftArrwOff');
					$(element).removeClass('leftArrw');
				}
				
				$('.topicInfo li.ctr').text(newbottom + '-' + (newbottom + itemsLimit*1) + ' / ' + items);
			});
		
		} else if (elementStyle == 'rightArrw' && !(parseInt($(element).parents('.nclRowHolder').find('.'+holderName+'').css('margin-left')) % itemWidth)) {
			newleft = parseInt($(element).parents('.nclRowHolder').find('.'+holderName+'').css('margin-left')) - itemsLimit*itemWidth;
			if (newleft < -((items - itemsLimit) * itemWidth)) {
				newleft = -((items - itemsLimit) * itemWidth);
				fin = true;
			}
			newleftVal = newleft;
			newleft = newleft + 'px';
			
			$(element).parents('.nclRowHolder').find('.'+holderName+'').animate({
				marginLeft: newleft
			}, 300, function() {
				var newbottom = (-1) * parseInt(parseInt(newleft) / itemWidth) + 1*1;
				
				$(element).siblings().addClass('leftArrw');
				$(element).siblings().removeClass('leftArrwOff');
				
				if (newleftVal == (-((items-itemsLimit)*itemWidth))){
					$(element).addClass('rightArrwOff');
					$(element).removeClass('rightArrw');
				}
				
				$('.topicInfo li.ctr').text(newbottom + '-' + (newbottom + itemsLimit*1) + ' / ' + items);
			});
		}
		return false;
	}
}

function fpageFilterMenuLoad(obj, holder, period){
	jQuery(holder).load('./?ajaxobj=' + obj +'&period=' + period);
	
	if (readCookie('CapitalFilterTabObj') == 'cheteno' && obj == '24hours'){
		createCookie('CapitalFilterTabObj','cheteno',0);
	}
	return false;
}

