/*
function setIframeSrc(el,src) {
   if ( -1 == navigator.userAgent.indexOf("MSIE") ) { el.src = src; }
  else {    el.location = src;  }
}

var iframes = document.getElementsByTagName("iframe"); 
for (var i = 0; i < iframes.length; i++) { 
    var iframe=iframes[i]; 
	setTimeout(function(){setIframeSrc(iframe,iframe.getAttribute("src"))},500);
}
*/
/*
function setimgsrc(el,src){
//console.log(el.src);
setTimeout(function(){ 
	el.src=src; 
 	},1500);
}

var images = document.getElementsByTagName("img"); 
for (var i = 0; i < images.length; i++) { 
    var image=images[i];
//setTimeout(function(){ 	//image.src=image.getAttribute("src");  	},500);
 setimgsrc(image,image.src);
 //  (function(value) {       return function() {  console.log(value);    }     })(image.src);
		
		
}
*/

(function(){

// glocal variables
var window    = this, 
    instances = {},
    winH;

// cross browser event handling
function addEvent( el, type, fn ) {
  if ( window.addEventListener ) {
    el.addEventListener( type, fn, false );
  } else if ( window.attachEvent ) {
    el.attachEvent( "on" + type, fn );
  } else {
    var old = el["on" + type];
    el["on" + type] = function() { old(); fn(); };
  }
}

// cross browser event handling
function removeEvent( el, type, fn ) {
  if ( window.removeEventListener ) {
    el.removeEventListener( type, fn, false );
  } else if ( window.attachEvent ) {
    el.detachEvent( "on" + type, fn );
  }
}

// cross browser window height
function getWindowHeight() {
  if ( window.innerHeight ) {
    winH = window.innerHeight;
  } else if ( document.documentElement.clientHeight ) {
    winH = document.documentElement.clientHeight;
  } else if ( document.body && document.body.clientHeight ) {
    winH = document.body.clientHeight;
  } else {        // fallback:
    winH = 10000; // just load all the images
  }
  return winH;
}

// getBoundingClientRect alternative
function findPos(obj) {
  var top  = 0;
  if (obj && obj.offsetParent) {
    do {
      top += obj.offsetTop || 0;
      top -= obj.scrollTop || 0;
    } while (obj = obj.offsetParent); // 
    return { "top" : top };
  }
}

// top position of an element
var getTopPos = (function() {
  var dummy = document.createElement("div");
  if ( dummy.getBoundingClientRect ) {
    return function( el ) { 
      return el.$$top || el.getBoundingClientRect().top;
    };
  } else {
    return function( el ) { 
      return el.$$top || findPos( el ).top;
    };
  }
})();

// sorts images by their vertical positions
function img_sort( a, b ) {
  return getTopPos( a ) - getTopPos( b );
}

// let's just provide some interface 
// for the outside world
var LazyImg = function( target, offset ) {

  var imgs,    // images array (ordered)
      last,    // last visible image (index)
      id,      // id of the target element
      self;    // this instance

  offset = offset || 200; // for prefetching

  if ( !target ) {
    target = document;
    id = "$document";
  } else if ( typeof target === "string" ) {
    id = target;
    target = document.getElementById( target );
  } else {
    id = target.id || "$undefined";
  }

  // return if this instance already exists
  if ( instances[id] ) {
    return instances[id];
  }

  // or make a new instance
  self = instances[id] = {

    // init & reset
    init: function() {
      imgs = null;
      last = 0;
      addEvent( window, "scroll", self.fetchImages );
      self.fetchImages();
      return this;
    },

    destroy: function() { 
      removeEvent( window, "scroll", self.fetchImages );
      delete instances[id];
    },

    // fetches images, starting at last (index)
    fetchImages: function() {

      var img, temp, len, i;

      // still trying to get the target
      target = target || document.getElementById( id );

      // if it's the first time
      // initialize images array
      if ( !imgs && target ) {

        temp = target.getElementsByTagName( "img" ); 

        if ( temp.length ) {
          imgs = [];
          len  = temp.length;
        } else return;

        // fill the array for sorting
        for ( i = 0; i < len; i++ ) {
          img = temp[i];
          if ( img.nodeType === 1 && img.getAttribute("thumb") ) {

              // store them and cache current
              // positions for faster sorting
              img.$$top = getTopPos( img );
              imgs.push( img );
          }
        }
        imgs.sort( img_sort );
      }

      // loop through the images
      while ( imgs[last] ) {

        img = imgs[last];

        // delete cached position
        if ( img.$$top ) img.$$top = null;

        // check if the img is above the fold
        if ( getTopPos( img ) < winH + offset )  {

          // then change the src 
          img.src = img.getAttribute("thumb");
          last++;
        }
        else return;
      }

      // we've fetched the last image -> finished
      if ( last && last === imgs.length )  {
        self.destroy();
      }
    }  
  };
  return self.init();
};

// initialize
getWindowHeight();
addEvent( window, "load",   LazyImg().fetchImages );
addEvent( window, "resize", getWindowHeight       ); 
LazyImg();

window.LazyImg = LazyImg;

}());


var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};


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 "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function checkCookie()
{
popup=getCookie('popup');
if (popup!=null && popup!="") { }
else {
document.getElementById("bd").onclick=function() {
if (popup!=null && popup!="") { }
else {
window.open("http://otgovori.royalsbg.com/","_blank","toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1");
//window.open("http://92.247.254.112/new/chat/?lang=bg","_blank","toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1");
self.focus();
popup=1;
setCookie('popup',popup,1); 
}
};
}
}


function createElement(nodeName, name) {
  var node;
  try {
    node = createElementMsie(nodeName, name);
    createElement = createElementMsie;
  } catch (e) {
    node = createElementStandard(nodeName, name);
    createElement = createElementStandard;
  }
  return node;
}

/**
 * Code required by Internet Explorer when creating a new DOM node with the
 * name attribute set.
 */
function createElementMsie(nodeName, name) {
  return document.createElement("<"+nodeName+" name="+name+">");
}

/**
 * Code required by all other browsers that support web standards.
 */
function createElementStandard(nodeName, name) {
  var node = document.createElement(nodeName); node.name = name;
  return node;
}

function isEmailAddr(str){return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);}

function toggleNext(el) {
 var next=el.nextSibling;
 while(next.nodeType != 1) next=next.nextSibling;
 next.style.display=((next.style.display=="none") ? "block" : "none");
}
  
function toggleNextById(el) {
 var ccn="clicker", clicker=document.getElementById(el);
 clicker.className+=" "+ccn;
 clicker.onclick=function() {
 this.childNodes[1].innerHTML=((this.childNodes[1].innerHTML=="+") ? "-" : "+");
 toggleNext(this);
 };
 toggleNext(clicker);
}

/*
function reply(attach_to,to_comment) {
//fadeX('accessbox',1,250,50);
goto_url(attach_to.id);
}
*/

function get(obj) {
if(obj.comment.value=='' || obj.comment.value == obj.comment.defaultValue){obj.comment.style.border="1px solid red";return false;}	

if(!document.getElementById('top_buttons')){
if(obj.email_input.value=='' || obj.email_input.value == obj.email_input.defaultValue || !isEmailAddr(obj.email_input.value) ){ obj.email_input.style.border="1px solid red";return false;}	
}

var poststr = "comment=" + encodeURI( obj.comment.value ) +
"&art_id=" + encodeURI( obj.art_id.value ) +
"&email=" + encodeURI( obj.email_input.value ) +
"&comment_id=" + encodeURI( obj.comment_id.value  );
makePOSTRequest('post_comment.php', poststr, obj.id);
//document.getElementById("myform").style.display="none";
document.getElementsByTagName("body").item(0).style.cursor="auto";

 }
 

function getWindowHeight() {
  var body  = document.body;
  var docEl = document.documentElement;
  return window.innerHeight || 
         (docEl && docEl.clientHeight) ||
         (body  && body.clientHeight)  || 
         0;
}
  
var getScrollRoot = (function() {
  var SCROLL_ROOT;
  return function() {
    if (!SCROLL_ROOT) {
      var bodyScrollTop  = document.body.scrollTop;
      var docElScrollTop = document.documentElement.scrollTop;
      window.scrollBy(0, 1);
      if (document.body.scrollTop != bodyScrollTop)
        (SCROLL_ROOT = document.body);
      else 
        (SCROLL_ROOT = document.documentElement);
      window.scrollBy(0, -1);
    }
    return SCROLL_ROOT;
  };
})();

function interpolate(source,target,pos) { return (source+(target-source)*pos); }
function easing(pos) { return (-Math.cos(pos*Math.PI)/2) + 0.5; }

function scrollToAnim(targetTop, duration) {
  duration || (duration = 1000);
  var start    = +new Date,
      finish   = start + duration,
      startTop = getScrollRoot().scrollTop,
      interval = setInterval(function(){
        var now = +new Date, 
            pos = (now>finish) ? 1 : (now-start)/duration;
        var y = interpolate(startTop, targetTop, easing(pos)) >> 0;
        window.scrollTo(0, y);
        if(now > finish) { 
          clearInterval(interval);
        }
      }, 10);
}  
  
function scrollElemToCenter(id, duration) {
  var el = document.getElementById(id);
  var winHeight = getWindowHeight();
  var offsetTop = el.offsetTop;
  if (offsetTop > winHeight) { 
    var y = offsetTop - (winHeight-el.offsetHeight)/2;
    scrollToAnim(y, duration);
  }
} 
 
 


function render_reply(article_id) {
var attach_to = document.getElementById("comment_form");
if(!attach_to) return false;
var form = createElement("form", "myform"+article_id); form.onsubmit="return false"; form.id="myform"+article_id; form.method="post";
var heading = createElement("p");  heading.className="comments_header";
var heading_text="Вашият коментар"; heading.appendChild(document.createTextNode(heading_text));
var name_label = createElement("label"); name_label.htmlFor="email_input"; name_label.style.display="inline"; var name_label_text="Email адрес"; name_label.appendChild(document.createTextNode(name_label_text));

var email_input = createElement("input", "email_input"); email_input.type="text"; email_input.id="email_input"; 
//email_input.value=name_label_text; email_input.defaultValue=name_label_text;
//email_input.onfocus=function() { if (email_input.value == email_input.defaultValue) { email_input.value = ''; } };
//email_input.onblur=function() { if (email_input.value == '') { email_input.value = email_input.defaultValue; } }; 

email_input.onfocus=function() { if (this.value == this.defaultValue) { this.value = ''; } }
email_input.onblur=function() { if (this.value == '') { this.value = this.defaultValue; } }
email_input.onclick=function() { if (this.value == this.defaultValue) { this.value = ''; } email_input.style.color="#000000"; email_input.focus();};

var keyboard_span = createElement("span"); keyboard_span.id="langLink";   keyboard_span.title="DEFAULT";
var comment_label = createElement("label"); comment_label.htmlFor="comment"; var c_label_text="Вашият коментар:";
comment_label.appendChild(document.createTextNode(c_label_text)); comment_label.style.display="block"; comment_label.style.color="black";

var comment = createElement("textarea", "comment"); comment.rows=7; comment.cols=7; comment.id="comment"; comment.className="DEFAULT";
comment.style.color='#999999'; 
//comment.defaultValue=c_label_text; comment.value=c_label_text;
//comment.onfocus=function() { if (comment.value == comment.defaultValue) { comment.value = ''; } };
//comment.onblur=function() { if (comment.value == '') { comment.value = comment.defaultValue; } }; 
comment.onclick=function() {comment.style.color='#000000';   comment.focus();};

comment.onblur=function() {this.value=rtrim(this.value); if (this.value == '') { this.value = this.defaultValue; } }



var comment_id = createElement("input", "comment_id"); comment_id.type="hidden";comment_id.id="comment_id"; comment_id.value=0;
var art_id = createElement("input", "art_id"); art_id.type="hidden";art_id.id="art_id"; art_id.value=article_id;
var submit_btn = createElement("input", "the_submit"); submit_btn.type="submit"; submit_btn.id="submit"; submit_btn.value="Добави";
submit_btn.onclick=function() {
if(comment.value=='' || comment.value == comment.defaultValue){comment.style.border="1px solid red";return false;}
else {comment.style.border="1px solid #A7A6AA";}
if(email_input.value=='' || email_input.value == email_input.defaultValue || !isEmailAddr(email_input.value)){email_input.style.border="1px solid red";  email_input.value = email_input.defaultValue; return false;}	
else {get(this.parentNode);}
return false;
};
//form.appendChild(heading); ; //form.appendChild(keyboard_span); 
form.appendChild(email_input); form.appendChild(name_label); 
//form.appendChild(comment_label);
form.appendChild(comment);
form.appendChild(art_id); form.appendChild(comment_id); form.appendChild(submit_btn);

var reply_place = createElement("div"); reply_place.appendChild(form);
attach_to.appendChild(reply_place);
}


function reply(attach_to,to_comment) {
if (document.getElementById(to_comment+'_reply')) {
if(jscss('check_any',attach_to,'on'))
{
var el_to_remove=document.getElementById(to_comment+'_reply'); el_to_remove.parentNode.removeChild(el_to_remove);  
attach_to.style.border="2px outset #777788";
jscss('remove',attach_to,'on');
return;
}
}




jscss('add',attach_to,'on');
attach_to.style.border="none";

var html_br1 = createElement("br"), html_br2 = createElement("br");
var form = createElement("form", "myform"+to_comment); form.onsubmit="return false"; form.id="myform"+to_comment; form.method="post";

var name_label = createElement("label"); name_label.htmlFor="email_input"; var name_label_text="email:";
name_label.appendChild(document.createTextNode(name_label_text));
var email_input = createElement("input", "email_input"); email_input.type="text"; email_input.id="email_input"; email_input.value=name_label_text; email_input.defaultValue=name_label_text;

email_input.onfocus=function() { if (email_input.value == email_input.defaultValue) { email_input.value = ''; } };
email_input.onblur=function() { if (email_input.value == '') { email_input.value = email_input.defaultValue; } }; 
email_input.onclick=function() {email_input.style.color="#000000"; email_input.focus();};

var keyboard_span = createElement("span"); keyboard_span.id="langLink";   keyboard_span.title="DEFAULT";
var comment_label = createElement("label");
comment_label.htmlFor="comment"; var c_label_text="";
if (to_comment==0) {c_label_text="Вашият отговор...";} else {c_label_text="Вашият отговор...";}
comment_label.appendChild(document.createTextNode(c_label_text)); comment_label.style.display="block";

var comment = createElement("textarea", "comment"); comment.rows=7; comment.id="comment"; comment.className="DEFAULT"; comment.style.color="#999999"; comment.defaultValue=c_label_text; comment.value=c_label_text;

comment.onfocus=function() { if (comment.value == comment.defaultValue) { comment.value = ''; } };
comment.onblur=function() { if (comment.value == '') { comment.value = comment.defaultValue; } }; 
comment.onclick=function() {comment.style.color="#000000"; comment.focus();};

var comment_id = createElement("input", "comment_id"); comment_id.type="hidden";comment_id.id="comment_id"; comment_id.value=to_comment;
var art_id = createElement("input", "art_id"); art_id.type="hidden";art_id.id="art_id"; art_id.value=document.getElementById("article_id").value;
var submit_btn = createElement("input", "the_submit"); submit_btn.type="submit"; submit_btn.id="submit"; submit_btn.value="Добави";
submit_btn.onclick=function() {get(this.parentNode);return false;};

//form.appendChild(name_label);
form.appendChild(email_input); form.appendChild(html_br1); form.appendChild(keyboard_span);
//form.appendChild(comment_label);
form.appendChild(comment); form.appendChild(html_br2); form.appendChild(art_id); 
form.appendChild(comment_id); form.appendChild(submit_btn);

var reply_place = createElement("div"); reply_place.id=to_comment+"_reply";
reply_place.appendChild(form);
attach_to.parentNode.appendChild(reply_place);
scrollElemToCenter(to_comment+'_reply');
/*enable focus*/
//comment.focus();
/*
if (!document.getElementById("keyboard")) {
//load the keyboard language
var e = document.createElement("script");
e.id="keyboard";
e.src = "keyboard.js";
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e); 
} else { 
cTranslator.onLoad(); }
*/
}


function add_reply_buttons() {
if (document.getElementById("comments")) {
var comments=getElementsByClassName("user_comment"),
 sub_comments=getElementsByClassName("user_sub_comment"),
 reply_place=comments.concat(sub_comments),
 reply_element = createElement("span"); reply_element.className="options on"; reply_element.innerHTML="&lArr;отговори";

 
for (var i = 0, length=reply_place.length; i < length; i++) {
		reply_element.id=reply_place[i].id;		
				
		var reply_el=reply_element.cloneNode(true);
		reply_el.onclick=function() { reply(this,this.id); };
		//reply_place[i].appendChild(reply_element);
		//reply_place[i].onmouseover=function(){ jscss('add',this,'active'); jscss('swap',this.lastChild,'options off','options on');  }
		//reply_place[i].onmouseout=function(){	jscss('remove',this,'active');	jscss('swap',this.lastChild,'options on','options off');	}
		reply_place[i].insertBefore(reply_el,reply_place[i].children[0]);
		//reply_place[i].onmouseover=function(){ jscss('add',this,'active'); jscss('swap',this.children[0],'options off','options on');  }
		//reply_place[i].onmouseout=function(){	jscss('remove',this,'active');	jscss('swap',this.children[0],'options on','options off');	}
			}	
}
}


function recommend(comment_id){
var rec_id=comment_id.slice(3), post_str='comment_id=' +rec_id;
makePOSTRequest('recommend.php',post_str,comment_id);
document.getElementById(comment_id).style.display='none'; 
}


function add_recommend_buttons() {
//add recommend buttons
if (document.getElementById("comments")) {
var comments=getElementsByClassName("user_comment"); 
var sub_comments=getElementsByClassName("user_sub_comment"); 
var recommend_place=comments.concat(sub_comments); 
var recommend_element = createElement("p"); recommend_element.className="partner_link off"; recommend_element.innerHTML="препоръчай&uArr;";
for (var i = 0, length=recommend_place.length; i < length; i++) {
var rec_element=recommend_element.cloneNode(true);
rec_element.id="rec"+recommend_place[i].id;
rec_element.onclick=function() { recommend(this.id);	};
recommend_place[i].appendChild(rec_element);
//recommend_place[i].insertBefore(recommend_element,recommend_place[i].children[0]);
		recommend_place[i].onmouseover=function(){ jscss('add',this,'active'); jscss('swap',this.lastChild,'partner_link off','partner_link on');  };
		recommend_place[i].onmouseout=function(){	jscss('remove',this,'active');	jscss('swap',this.lastChild,'partner_link on','partner_link off');	};
		}		
}
}

function subscribe(genre,info_genre,article_id){
var attach_to=document.getElementById('subscribe');
if (attach_to) {
attach_to.innerHTML='<form style="clear:both; float:left; wwidth:250px;" action="mailinglist.php" method="post"><fieldset><label for="email"><strong>Безплатен абонамент за нови статии на тема: '+ genre +'</strong><br />Въведете e-мейл адреса си:</label><input onclick="this.focus();" id="email" name="email" size="45"  style="width: 162px;" type="text" /> <input name="genre" id ="genre" type="hidden" value="'+ info_genre +'" /><input name="article_id" id ="article_id" type="hidden" value="'+article_id+'" /><input type="submit" value="Абонирам се!" /></fieldset></form>';
}
}


function jscss(a,o,c1,c2)
{
  switch (a){
    case 'swap':  o.className=!jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);   break;
    case 'add':   if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}  break;
    case 'remove':  var rep=o.className.match(' '+c1)?' '+c1:c1; o.className=o.className.replace(rep,'');  break;
    case 'check':   return new RegExp('\\b'+c1+'\\b').test(o.className);   break;
	case 'check_any':    return new RegExp('(^|\\s+)' + c1 + '(\\s+|$)').test(o.className); break;
  }
}

function close(cl) {	
	var re = new RegExp("(^| )" + cl + "( |$)");
	var el = document.all ? document.all : document.getElementsByTagName("body")[0].getElementsByTagName("*"); // fix for IE5.x
	for (var i = 0; i < el.length; i++) {
	if (el[i].className && el[i].className.match(re)) {
	if (el[i].nextSibling)		{
		var tohide=el[i].nextSibling; 	while(tohide.nodeType!=1)  {  tohide=tohide.nextSibling;	}  
		el[i].tohide=tohide; //store the inner div
//close the opened content
jscss('swap',el[i].tohide,'open','close');
	}
//remove state open from title
jscss('remove',el[i],'open');
	}
	}
}
										 
function init(cl) {
	var re = new RegExp("(^| )" + cl + "( |$)");
	var el = document.all ? document.all : document.getElementsByTagName("body")[0].getElementsByTagName("*"); // fix for IE5.x
	for (var i = 0; i < el.length; i++) {
if (el[i].className && el[i].className.match(re)) {

//find the next div
var tohide=el[i].nextSibling; while(tohide.nodeType!=1)  {  tohide=tohide.nextSibling;	}  
el[i].tohide=tohide; //store the inner div

//hide all closed content divs
if(!jscss('check',el[i],'open')) { jscss('add',el[i].tohide,'close'); }

el[i].onclick = function () {

//find the content div
var tohide=this.nextSibling; while(tohide.nodeType!=1)  {  tohide=tohide.nextSibling;	}  
this.tohide=tohide; //store the inner div
	
if (jscss('check',this.tohide,'close')) {
close("open");
	
//set title to open
jscss('add',this,'open');

//open the content
jscss('swap',this.tohide,'close', 'open');
										}  
															 };
}
}
}	

var http_request = false;

function alertContents(response,ret_el) {  document.getElementById(ret_el).innerHTML = response;  }

function makePOSTRequest(url, parameters, ret_el, callback_function) { 
var def=0;
if (typeof callback_function == 'undefined' ) {callback_function = alertContents; } else {def=1;}

var http_request = false, activex_ids = ['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP' ];

if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml');  }
  } else if (window.ActiveXObject) { // IE6 and older
    for (i = 0; i < activex_ids.length; i++) {
      try {  http_request = new ActiveXObject(activex_ids[i]); } catch (e) {}
    }
  }

if (!http_request) {  alert('Нужно е да си обновите браузъра!');  return false; }
var return_el=document.getElementById(ret_el);if(return_el!==null){
//return_el.innerHTML="<img alt='Зареждане' src='/images/loading.gif' />Моля изчакайте...";
}
document.getElementsByTagName("body").item(0).style.cursor="wait";

http_request.onreadystatechange = function() {
if (http_request.readyState !== 4) {  return;  }
if (http_request.status !== 200) { alert('Има проблем при изпращането на заявката. Моля пробвайте отново.');    return;   }
document.getElementsByTagName("body").item(0).style.cursor="auto"; 
//var response = http_request.responseText; if ( def == 0 ) {response = http_request.responseText;} else { response = http_request.responseXML; }
var response = (def==0) ? http_request.responseText: http_request.responseXML;
//setTimeout(function(){ callback_function(response,ret_el)},1000);
callback_function(response,ret_el);
return; 
}; 
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Charset", "windows-1251");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

 
function rateit(article_id, action){
makePOSTRequest('rate.php', 'article_id=' +article_id+'&action='+action, 'rateplus');
document.getElementById('rateplus').style.display='none'; 
document.getElementById('rateminus').style.display='none'; 
document.getElementsByTagName("body").item(0).style.cursor="auto";
}


function myUnobtrusiveBehavior() {
//anti spam
if (document.getElementById("chk")) {
document.getElementById("chk").style.display="none";
document.getElementById("chk2").style.display="none";
}

/*
var page_content = document.getElementById("bd");
if (page_content) {
page_content.onmousedown = function () { return false;};
page_content.onselectstart = function () {return false;};
document.onmousedown=function(){return false;};
//my_onkeydown_handler(event); 
}
*/
//if (document.getElementById("subscribe")) { 
subscribe(); 
//}

//enable forms
var focused=false;
var formInputs = document.getElementsByTagName("input");
	for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        if (theInput.type == 'text' || theInput.type == 'password' ) {  
		theInput.onmousedown=function () {	 this.focus();	};
} 
}

//rules  
if(document.getElementById("rules_link")) {toggleNextById('rules_link');}

//Navigation
if (document.getElementsByTagName) {init("menu_title");}

//check links
var elmnts=getElementsByClassName("partner_link");
if (elmnts) {
for (var i = 0, length=elmnts.length; i < length; i++) {
elmnts[i].onclick=function() {
window.location=this.title;
};
}
}

var elmnts=getElementsByClassName("answer_link");
if (elmnts) {
for (var i = 0, length=elmnts.length; i < length; i++) {
elmnts[i].onclick=function() {
//window.location=this.title;
window.open(this.title,"_blank","width=1024,height=768,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes"); 
};
}
}

//reply buttons
add_reply_buttons();

//recommend_buttons
add_recommend_buttons();

//disable redirect to woman
//checkCookie();

/*
var element = document.getElementById('read_time');
if (element) {
element.parentNode.removeChild(element);
var nextSibling = document.getElementById('subscribe');
document.getElementById('fb-root').parentNode.insertBefore(element,nextSibling);
}
*/

}

myUnobtrusiveBehavior();

function navigate(start) {
var poststr = "article_id=" + encodeURI(document.getElementById("article_id").value) + "&start=" + encodeURI(start);
makePOSTRequest("list_comments.php", poststr, "comments_place");
}

function track()
{
var poststr = "track_str=" + encodeURI(document.getElementById("sbi").value);
makePOSTRequest("decode.php", poststr, "sbi");
setTimeout('document.getElementById(\"srch\").submit()', 3000);
//document.getElementById("srch").submit();
}

function goto_url(url)
{
//document.getElementById('access_join').title+="&fragment="+url;
//document.getElementById('access_register').title+="&fragment="+url;
var art_id=document.getElementById("article_id").value;
self.location="index.php?mode=login_forms&ref=article-"+art_id+".html&fragment="+url;
}
