
function _gel(a){return document.getElementById?document.getElementById(a):(document.all?document.all[a]:null);}
function appl(a,b){return function(){return a[b].apply(a,arguments);}}
var UTIL = {
	isIE:(navigator.appName=='Microsoft Internet Explorer'),
	trim:function(t){return t.replace(/^\s+|\s+$/g,'');},
	hide:function(obj){obj.style.display='none';},
	show:function(obj,m){if(typeof(m)=='undefined')m='block';if(m=='table-row'&&this.isIE)m='block'; obj.style.display=m;},
	inArray:function(elem, array){for(var i=array.length - 1;i>=0;--i)if(array[i]===elem)return i;return -1;/* Use === because on IE, window == document*/},
	getOffset:function(a,b){var c=0;while(a!=null){c+=a['offset'+(b?'Left':'Top')];a=a.offsetParent;}return c;},
	addClass:function(elem,names){var a=names.split(/\s+/);for(var i=a.length-1;i>=0;--i)if(this.inArray(elem.className.split(/\s+/),a[i])==-1)elem.className+=(elem.className?' ':'')+a[i];},
	delClass:function(elem,names){var a=names.split(/\s+/);var b=elem.className.split(/\s+/);for(var i=b.length-1;i>=0;--i)if(this.inArray(b[i],a)!=-1)b[i]='';elem.className=b.join(' ');}
}
function changeMmItem(obj, cond)
{
	obj.style.backgroundImage = cond?"url(/images/mmbgrd_a.gif)":"url(/images/mmbgrd.gif)";
	return true;
}
function changeBgrd(obj, cond)
{
	obj.className = obj.firstChild.className = cond?'mm-a':'mm';
	return false;
}
function clickMm(obj)
{
	location = obj.firstChild.href;
	return true;
}
function changeImg(obj, name)
{
	var path = obj.src;
	var idx = path.lastIndexOf('/');
	path = (idx>=0)?path.substr(0,idx+1):'';
	obj.src = path + name;
	return false;
}
function winOpen(src)
{
	var width = parseInt(screen.width/2);
	var height = parseInt(screen.height/2);
	var x = parseInt(width/2);
	var y = parseInt(height/2);
	win = window.open(src,'New','width='+width+',height='+height+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars');
	return false;
}
function ExpCol(obj)
{
	var element = document.getElementById(obj);
	if (element != null) element.className = element.className == "vaca col" ? "vaca exp": "vaca col";
	return false;
}
function addFavorite(url, title)
{
	if (!url) url = location.href;
	if (!title) title = document.title;
  
	//Gecko
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel(title, url, "");
	//IE4+
	else if (typeof window.external == "object") window.external.AddFavorite(url, title);
	//Opera7+
	else if (window.opera && document.createElement)
	{
		var a = document.createElement('A');
		if (!a) return false; //IF Opera 6
		a.setAttribute('rel','sidebar');
		a.setAttribute('href',url);
		a.setAttribute('title',title);
		a.click();
	}
	else return false;
	return true;
}
function previewImage(url,width,height,title)
{
	height+=64;width+=64;
	var w=window.open(url,'prv','width='+width+',height='+height+',top='+(screen.height/2-height/2)+',left='+(screen.width/2-width/2)+',location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,directories=0,hotkeys=0');
	setTimeout(function(){w.document.body.style.padding='32px';w.document.body.style.margin='0px';if(typeof(title)!='undefined')w.document.title=title;},0);
	w.focus();
}

function ajax_init_object(){var A=null;if(typeof(XMLHttpRequest)!='undefined')A=new XMLHttpRequest();else if(typeof(ActiveXObject)!='undefined'){var msxmlhttp=new Array('Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.5.0');for(var i=msxmlhttp.length-1;!A&&i>=0;i--){try{A=new ActiveXObject(msxmlhttp[i]);}catch(e){A=null;}}}return A;}
function ajax_do_call(uri,method,args,func_name,params,btext){var x,post_data;if(typeof(method)=='undefined'||method=='')method='GET';if(method=='GET'){if(args){if(uri.indexOf('?')!=-1)uri+='&';else uri+='?';uri+=escape(args);}post_data=null;}else if(method=='POST')post_data=args;x=ajax_init_object();if(x==null)return false;else{x.open(method,uri,true);if(method == 'POST'){x.setRequestHeader('Method','POST '+uri+' HTTP/1.1');x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}x.onreadystatechange=function(){if(x.readyState!=4)return;if(x.status==200){var a=btext?x.responseText:x.responseXML;if(a!=null){try{if(func_name)func_name(a,params);}catch(e){;}}}}}x.send(post_data);delete x;return true;}
function ajax_post(uri,post_data,func,params,btext){ajax_do_call(uri,'POST',post_data,func,params,(typeof(btext)!='undefined'&&btext));}
function ajax_get(uri,func,params,btext){ajax_do_call(uri,'GET','',func,params,(typeof(btext)!='undefined'&&btext));}
function ajax_get_resp(uri,method,args){var ret=null;var x=ajax_init_object();if(x==null)return false;else{x.open(method,uri,false);if(method=="POST"){x.setRequestHeader("Method","POST "+uri+" HTTP/1.1");x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}x.send(args);ret=x.responseXML;delete x;}return ret;}

function insPrice()
{
	var target = document.getElementById('widget');
	if (target)
	{
		var newNode = document.createElement('div');
		newNode.className = 'widget';
		newNode.innerHTML = '<div class="widget_head">Это важно:</div>';
		newNode.innerHTML += '<div><a href="/about/software/cons/?utm_campaign=java_experiment;utm_source=consultant.popular;utm_medium=top_txt;utm_content=doc_from_system">Данный документ взят из системы КонсультантПлюс (см. описание)<\/a><hr class="divthick"\/><\/div>';
		newNode.innerHTML += '<div><a href="/about/purchase/price/?utm_campaign=java_experiment;utm_source=consultant.popular;utm_medium=top_txt;utm_content=how_to_buy">Купить систему КонсультантПлюс<\/a><hr class="divthick"\/><\/div>';
		newNode.innerHTML += '<div><a href="/about/purchase/demo/show/?utm_campaign=java_experiment;utm_source=consultant.popular;utm_medium=top_txt;utm_content=order_demo">Заказать бесплатную демонстрацию системы КонсультантПлюс<\/a><\/div>';
		target.parentNode.replaceChild(newNode,target);
		newNode = null;
	}
}

function insWidget(v)
{
	var newNode = document.createElement('div');
	newNode.className = 'widget';
	var nodes = v.getElementsByTagName('item');
	newNode.innerHTML = '<div class="widget_head">Это актуально:</div>';
	var len = nodes.length;
	for (var i = 0; i < len; i++)
		newNode.innerHTML += '<div><a href="' + nodes[i].getAttribute('link') + '">' + nodes[i].getAttribute('title') + '&nbsp;&raquo;&raquo;&raquo;<\/a><\/div>';
	var target = document.getElementById('widget');
	if (target)
	{
		target.parentNode.replaceChild(newNode,target);
	}
	else
	{
		target = document.getElementById('top');
		if (target)
		{
			while (target.tagName != 'H1')
				target = target.nextSibling;
			target.parentNode.insertBefore(newNode, target.nextSibling);
		}
	}
	newNode = null;
}
function insDbs(v)
{
	var nodes = v.getElementsByTagName('item');
	var len = nodes.length;
	if (len)
	{
		var newNode = document.createElement('div');
		newNode.className = 'dbs';
		newNode.innerHTML = '';
		for (var i = 0; i < len; i++)
			newNode.innerHTML += '<div>' + getNodeValue(nodes[i]) + '<\/div>';
		var target = document.getElementById('dbs');
		if (target)
			target.parentNode.replaceChild(newNode,target);
		else
		{
			target = document.getElementById('content');
			if (target)
				target.insertBefore(newNode, target.childNodes[0]);
		}
		if (navigator.userAgent.indexOf('MSIE ') != -1)
		{
			var el = document.getElementById('footer');
			el.style.top = el.offsetTop + newNode.offsetHeight + 8 + 'px';
		}
		newNode = null;
	}
}
function getNodeValue(node) { return (node.text != undefined) ? node.text : node.textContent; }
function insAdvert(v)
{
	var nodes = v.getElementsByTagName('item');
	if (nodes.length)
	{
		var target = document.getElementById('advert');
		if (target) target.innerHTML = getNodeValue(nodes[0]);
	}
}

function getCookie(name)
{
	var arg = name + '=';
	var alen = arg.length;
	var clen = document.cookie.length;
	var pos = sep = 0;
	var bFind = false;
	while (!bFind)
	{
		pos = document.cookie.indexOf(arg,pos);
		if (pos == -1)
			break;
		else
		{
			var ch = pos ? document.cookie.charAt(pos-1) : ';';
			if (ch == ';' || ch == ' ' || ch == '\n')
			{
				pos += alen;
				sep = document.cookie.indexOf(';', pos);
				if (sep == -1) sep = clen;
				return document.cookie.substr(pos, sep-pos);
			}
		}
	}
	return null;
}

function setCookie(name,val,expire,path,domain,secure)
{
	document.cookie = name + '=' + escape(val) +
		( (expire) ? '; expires=' + expire.toGMString() : '' ) +
		( (path) ? '; path=' + path : '' ) +
		( (domain) ? '; domain=' + domain : '' ) +
		( (secure) ? '; secure' : '' );
}

function closeTopBanner()
{
	var el = document.getElementById('top_banner');
	if (el)
		el.parentNode.removeChild(el);
	setCookie('top_banner','closed',0,'/');
}
/* suggest */
function selectItem(li, input){var e = document.createElement('INPUT');e.name='sgst';e.type='hidden';e.value='1';input.form.appendChild(e);input.form.submit();}
function formatItem(row){return row[0];}
window.onload = function()
{
	var adds_dir = '/adds/';
	if (document.getElementById('dbs'))
		if (location.pathname == '/' || location.pathname == '/online/' || location.pathname == '/online/lastdocs/')
			ajax_get(adds_dir + 'online.js', insDbs);

	if (_gel('widget'))
	{
		var re = /\/law\/review\//
		var re2 = /\/law\/review\/lawmaking\/(dd|sw)/
		var re3 = /\/law\/review\/ess\//
		if (re.test(location.pathname) && !re2.test(location.pathname) && !re3.test(location.pathname))
			ajax_get(adds_dir + 'widget.js?f=actual;t=x;rand', insWidget);
		else
		{
			re = /\/popular\/.+\//
			if (re.test(location.pathname))
				insPrice();
		}
	}

	if (_gel('advert'))
		ajax_get(adds_dir + 'advert.js', insAdvert);

	if (typeof(_autocomplete) != 'undefined')
	{
		var e = _gel('srchtxt');
		if(e) _autocomplete('/search/suggest/', e, {delay:500,minChars:2,cacheLength:10,onItemSelect:selectItem,formatItem:formatItem});
//		if(!UTIL.isIE)
		{
			e = _gel('srchtp');
			if(e) _autocomplete('/search/suggest/', e, {delay:500,minChars:2,cacheLength:10,onItemSelect:selectItem,formatItem:formatItem});
		}
	}
		

/* TOP BANNER */
/*
	if (getCookie('top_banner') == null)
	{
		var min_width = 623;
		var top_banner = document.createElement('DIV');
		top_banner.style.position = 'absolute';
		top_banner.id = 'top_banner';

		top_banner.style.top = '-50px';
		top_banner.style.height = '40px';
		top_banner.style.left = '205px';
		if (UTIL.isIE && (window.location.pathname != '/'))
			top_banner.style.left = '171px';

		var width = document.body.clientWidth - 239;
		top_banner.style.width =  (width>min_width?width:min_width)+'px';

		top_banner.style.backgroundColor = '#fff';
//		top_banner.style.backgroundImage = 'url(/images/back_tb.png)';

		var rand = (Math.floor(Math.random()*1024)+1);
		top_banner.innerHTML = '<table height="40" width="100%" cellspacing="0" cellpadding="0" border="0" style="border:1px solid #f90;"><col><col width="15%"><tr><td align="center"><div style="width:600px;" align="left"><img src="\/images\/logoprof40.gif" width="96" height="40" alt="ico" title="" style="float:left;padding-right:8px;"\/><div id="top_banner_frame_1" style="font-size:12px;text-align:right;padding-top:8px;font-weight:bold;"><a href="http:\/\/prof.consultant.ru\/?utm_campaign=prof;utm_source=consultant.top.all;utm_medium=banner;utm_term=7days" class="top_banner" style="color:#f90;">Новая разработка КонсультантПлюс Технология ПРОФ.<br/>Легко искать, удобно работать!<\/a><\/div><\/td><td valign="bottom" align="right"><a href="javascript:closeTopBanner()"><img src="\/images\/close_tb.gif" width="50" height="12" border="0" alt="Закрыть" title="Закрыть баннер" style="padding-right:3px;"\/><\/a><\/td><\/tr><\/table>';
//		top_banner.innerHTML = '<table height="40" width="100%" cellspacing="0" cellpadding="0" border="0"><col><col width="15%"><tr><td align="center"><div style="width:600px;" align="left"><img src="\/images\/ico_tb.gif" width="100" height="40" alt="ico" title="" style="float:left;padding-right:8px;"\/><div id="top_banner_frame_1" style="font-size:12px;text-align:right;padding-top:8px;font-weight:bold;"><a href="\/comment\/?ref=topb" class="top_banner">Обзор изменений налогового законодательства 2008 года - уже в системе!<\/a><\/div><div id="top_banner_frame_2" style="font-size:12px;text-align:right;padding-top:8px;display:none;font-weight:bold;"><a href="\/comment\/?ref=topb" class="top_banner">Обзор изменений налогового законодательства 2008 года - уже в системе!<\/a><\/div><\/td><td valign="bottom" align="right"><a href="javascript:closeTopBanner()"><img src="\/images\/close_tb.gif" width="50" height="12" border="0" alt="Закрыть" title="Закрыть баннер" style="padding-right:3px;"\/><\/a><\/td><\/tr><\/table>';
//		top_banner.innerHTML = '<table height="40" width="100%" cellspacing="0" cellpadding="0" border="0"><col><col width="15%"><tr><td align="center"><div style="width:700px;" align="left"><div id="top_banner_frame_1" style="font-size:12px;text-align:left;font-weight:bold;"><a href="http:\/\/forum.consultant.ru\/viewtopic.php?id=15044" class="top_banner">Конференция на форуме &quot;Сохранение трудового коллектива в условиях кризиса: правовые вопросы&quot;.<br\/>Задайте свой вопрос до 1 февраля<\/a><\/div><\/td><td valign="bottom" align="right"><a href="javascript:closeTopBanner()"><img src="\/images\/close_tb.gif" width="50" height="12" border="0" alt="Закрыть" title="Закрыть баннер" style="padding-right:3px;"\/><\/a><\/td><\/tr><\/table>';
		var parent = document.getElementById('all');
		if (!parent)
			parent = document.getElementById('header');
		parent.appendChild(top_banner);

		setTimeout('showBanner()', bannerSpeed) ;
		window.onresize = function()
		{
			var width = document.body.clientWidth - 239;
			top_banner.style.width = (width>min_width?width:min_width)+'px';
		}
	}
*/
/* END TOP BANNER */
}

var stepCounter = 1;
var stepMaximum = 60;
var bannerSpeed = 1;
var bAnim = 0;
function showBanner()
{
	if((obj = document.getElementById('top_banner')) )
	{
		if (stepCounter<stepMaximum)
		{
			stepCounter++;
			obj.style.top = (stepCounter - 50) + 'px';
			setTimeout('showBanner()', bannerSpeed) ;
		}
		else if (bAnim)
			setTimeout('animBanner()', 3000) ;
	}
}

var frame=1;
function animBanner()
{
	if (frame == 1)
	{
		var obj = document.getElementById('top_banner_frame_2');
		obj.style.display = 'none';
		obj = document.getElementById('top_banner_frame_1');
		obj.style.display = 'block';
		frame = 2;
	}
	else
	{
		var obj = document.getElementById('top_banner_frame_1');
		obj.style.display = 'none';
		obj = document.getElementById('top_banner_frame_2');
		obj.style.display = 'block';
		frame = 1;
	}
	setTimeout('animBanner()', 3000) ;
}

