browser = navigator.userAgent.toLowerCase();
isDOM = document.getElementById?true:false; //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+) 
isOpera = isOpera5 = window.opera && isDOM;
isOpera6 = isOpera && window.print;
isOpera7 = isOpera && document.readyState;
isMSIE = isIE = document.all && document.all.item && !isOpera; //Microsoft Internet Explorer 4+ 
isStrict = document.compatMode=="CSS1Compat";
isNN = isNC = navigator.appName=="Netscape";
isNN4 = isNC4 = isNN && !isDOM;
isNN6 = isNN && isDOM; //Mozilla или Netscape 6.* 
isKHTML = isSafari = (browser.match(/applewebkit/)!=null);
isMozilla = isDOM && (browser.match(/gecko/)!=null);
isMac = (browser.match(/mac/)!=null);

function isDefined() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function isStr() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}
function isNum() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='number') return false;}
  return true;
}
function isDigit(keyCode){
	return ((keyCode>=48 && keyCode<=57) || (keyCode>=96 && keyCode<=105));
}
function isControl(keyCode){
	return ((',35,36,37,38,39,40,8,9,46,').indexOf(','+keyCode+',')>-1);
}
function checkOnInt(val){
	return (((',35,36,37,39,8,9,46,').indexOf(','+val+',')>-1) || (val>=48 && val<=57) || (val>=96 && val<=105));
}
function checkOnFloat(val){
	return (((',35,36,37,39,8,9,46,190,191,').indexOf(','+val+',')>-1) || (val>=48 && val<=57) || (val>=96 && val<=105));
}



function word_case(num, word1, word2, word3){
	if((num%100>4) && (num%100<21)) return word3;
	if(num%10==1) return word1;
	if((num%10>1) && (num%10<5)) return word2;
	return word3;
}
	
function dhtmlLoadScript(url){
	var e = document.createElement("script");
	e.src = url;
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
}
function dhtmlLoadStyle(url){
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = url;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
}

function createScript(scriptSrc){
	var span = document.createElement('SPAN');
	span.style.display = 'none';
	document.body.insertBefore(span, document.body.lastChild);
	span.innerHTML = 'IEtxt.<s'+'cript></' + 'script>';
	setTimeout(function() {
	   var s = span.getElementsByTagName('script')[0];
	   s.language = 'JavaScript';
	   if (s.setAttribute) s.setAttribute('src', scriptSrc); else s.src = scriptSrc;
	}, 10);
}

function range(start, end){
	var res = new Array();
	for(var i=start;i<=end;i++)
		res[res.length]=i;
	return res;
}

function open_html(url, wwidth, wheight){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=yes'+win_coords);
		w.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		var w = window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no,scrollbars=yes'+win_coords);
	}
	return w;
}
function open_photo(url, wwidth, wheight){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=no'+win_coords);
		w.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		var w = window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no,scrollbars=no'+win_coords);
	}
	return w;
}
function switchBlockDisplay(ind) {
	var isTR = /^\s*<td/i.test(document.getElementById(ind).innerHTML);
	if (isDOM || isMSIE) {
		eval("var currElement = (isDOM)? document.getElementById('"+ind+"') : document.all['"+ind+"'];");
		if(currElement) currElement.style.display = (currElement.style.display == '')? 'none' : ((currElement.style.display == 'none')? ((isTR && isMozilla)?'table-row':'block') : 'none');
	}
}
function showBlock(ind) {
	if (isDOM || isMSIE) {
		eval("var currElement = (isDOM)? document.getElementById('"+ind+"') : document.all['"+ind+"'];");
		if(currElement) currElement.style.display = 'block';
	}
}
function hideBlock(ind) {
	if (isDOM || isMSIE) {
		eval("var currElement = (isDOM)? document.getElementById('"+ind+"') : document.all['"+ind+"'];");
		if(currElement) currElement.style.display = 'none';
	}
}
function setLayerItem(ind, item){
	if (isDOM || isMSIE) {
		eval("var currElement = (isDOM)? document.getElementById('"+ind+"') : document.all['"+ind+"'];");
		if(currElement) currElement.innerHTML = item;
	}
}
function fillContainerBy(url, cont_name, waitStr, noalert){
	if(!noalert) waitAlert(waitStr?waitStr:unlanguage('Подождите, осуществляется загрузка...###Loading. Please wait...'));
	if(!cont_name || cont_name=='') cont_name='container';
	if(!window.frames[cont_name]){
		var iframe = document.createElement('IFRAME');
		iframe.id = cont_name;
		iframe.name = cont_name;
		iframe.style.display = 'none';
		document.body.appendChild(iframe);
	}
	if(window.frames[cont_name])
		window.frames[cont_name].location.replace(url);
	return false;
}
function maximize(url){
	var screen_w = screen.width;
	var screen_h = screen.height;
	if(document.all){
		var w = window.open('','','left=0,top=0,width=screen_w,height=screen_h,scrollbars=yes,fullscreen=yes');
		w.location = url;
	}else{
		window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=yes,directories=no,resizable=no,screenX=0,screenY=0');
	}
}
function drawFlash(src,w,h,ID,bgcolor,wmode,vars, adds){
	src = src+'?'+Math.random();
	var str = '<object ' +
		'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" ' +
		((w && w!='')?'width="'+w+'" ':'') +
		((h && h!='')?'height="'+h+'" ':'') +
		'bgcolor="'+bgcolor+'" ' +
		'id="'+ID+'" ' +
		'align="" ' +
		adds +'>' +
		'<param name=movie value="'+src+'" />' +
		'<param name=quality value="high" />' +
		'<param name=wmode value="'+wmode+'" />' +
		'<param name=WMODE value="'+wmode+'" />' +
		'<param name=swLiveConnect value="true" />' +
		'<param name=allowScriptAccess value="always" />'+
		'<param name=menu value="false" />' +
		'<param name=FlashVars value="'+vars+'" />' +
		'<embed ' +
		'src="'+src+'" ' +
		'menu="false" ' +
		'quality="high" ' +
		'bgcolor="'+bgcolor+'" ' +
		'wmode="'+wmode+'" ' +
		'WMODE="'+wmode+'" ' +
		((w && w!='')?'width="'+w+'" ':'') +
		((h && h!='')?'height="'+h+'" ':'') +
		'name="'+ID+'" ' +
		'align="" ' +
		'swLiveConnect="true" ' +
		'allowScriptAccess="always" '+
		'FlashVars="'+vars+'" ' +
		'type="application/x-shockwave-flash" ' +
		'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
		'</embed>' +
		'</object>';
	return str;
}
function hideFlashes(){
	var objs = xGetElementsByTagName('OBJECT', document);
	for(var i=0; i<objs.length; i++){
		objs[i].old_visibility = ((xVisibility(objs[i]) && xVisibility(objs[i])!='')?xVisibility(objs[i]):'visible');
		xHide(objs[i]);
	}
}
function revertFlashes(){
	var objs = xGetElementsByTagName('OBJECT', document);
	for(var i=0; i<objs.length; i++){
		if(objs[i].old_visibility)
			xVisibility(objs[i], objs[i].old_visibility);
	}
}
function collect_IDs(obj, ID, direct) {
	var listvar = obj.value;
	switch(direct){
		case(true):{
			listvar = listvar+((listvar=='')?'':',')+ID;
			break;
		}
		case(false):{
			var listvar2 = ','+listvar+',';
			var pattern = ','+ID+',';
			eval('listvar = listvar2.replace(/'+pattern.replace(/\//g, '\\\/')+'/g,",").replace(/^,/,"").replace(/,$/,"");');
			break;
		}
	}
	obj.value = listvar;
}
function insertInTextarea(form, field, text) {
	var obj = form[field];
	obj.focus();
	if(document.selection){
		var sel = document.selection.createRange();
		sel.text= text;
	} else {
		var start=obj.selectionStart;
		var end=obj.selectionEnd;
		var txt=obj.value;
		var len=txt.length;
		obj.value=txt.substring(0, start) + 
			text + 
			txt.substring(end, len);
	}
	/*
	var flag = form[field].createTextRange && form[field].caretPos;
	if (flag) {
		var caretPos = form[field].caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	} else {
		form[field].value  += text;
	}
	*/
	form[field].focus();
}
function TagInsert(form, field, Tag, Tag2){
	var obj = form[field];
	obj.focus();
	if(document.selection){
		var sel = document.selection.createRange();
		sel.text= Tag+sel.text+Tag2;
	} else {
		var start=obj.selectionStart;
		var end=obj.selectionEnd;
		var text=obj.value;
		var len=text.length;
		obj.value=text.substring(0, start) + Tag + 
			text.substring(start, end) + Tag2 +
			text.substring(end, len);
	}
}
function is_f() {
	this.n=(document.layers)?true:false;
	this.o=(navigator.userAgent.indexOf('Opera')!=-1)?true:false;
	this.i=(document.all&&(!this.o))?true:false;
	this.d=(document.getElementById)?true:false;
}
var is=new is_f();
function setVisibility(e, v) {
	if(is.n) e.visibility = ((v)?'show':'hide');
	else if(e.style) e.style.visibility = ((v)?'visible':'hidden');
}
function moveLayer(e,x,y) {
	if(is.n) e.moveTo(x,y);
	else if(is.i) {
		e.style.pixelLeft=x;
		e.style.pixelTop=y;
	} else {
		e.style.left=x;
		e.style.top=y;
	}
}
function browseObjProps(obj_str){
	var with_values = 1;
	eval('var obj = '+obj_str+';');
	var arr = obj_str.replace(/\[/g, '.[').split('.');
	var rExp = /(innerHTML|outerHTML|innerText|outerText|file.+|mimeType|\d+)/;
	var rExp2 = /(innerHTML|outerHTML|innerText|outerText)/;
	obj_str2 = '';
	res_str = '';
	for(var i=1;i<=arr.length;i++){
		obj_str2 += arr[i-1]+(arr[i]?(arr[i].match(/\[/)?'':'.'):'.');
		res_str += ((i<arr.length)?'<a href=./index.htm onClick=\'browseObjProps("'+obj_str2.replace(/'/g, '&#039;').replace(/\.$/, '')+'"); return false\'>':'')+arr[i-1]+((i<arr.length)?'</a>'+(arr[i].match(/\[/)?' ':'. '):'');
	}
	var isArray = (obj.length && obj.length>0);
	var isArray = (obj.constructor && obj.constructor==Array);
	var s = '<img src=' + htmlrootpath + '/images/trans.gif width=500 height=1><br /><i>'+res_str.replace(/\. $/, '')+':</i> '+(with_values?'=<a href=./index.htm style=\'color:#000000\' onClick="alert('+obj_str+'); return false">&lt;value></a>':'')+'<br /><br />';
	var debug = 0;
	/*
	for(n in obj) if(!n.match(rExp)) {if(debug){eval('alert(\''+n+': \')'); eval('alert(obj.'+n+')');} eval('val = obj.'+n); eval('s += (\''+val+'\'.match(/\\[object/)?\'<a href=./index.htm onClick=\\\'browseObjProps("'+obj_str.replace(/'/g, '&#039;')+'.'+n+'"); return false\\\'>\'+n+\'</a>\':n)+(with_values?\'=\':\'\')+\',  \';');}
	*/
	if(isArray)
		for(var i=0; i<obj.length; i++) 
			eval('s += \'<a href=./index.htm onClick=\\\'browseObjProps("'+obj_str.replace(/'/g, '&#039;')+'['+i+']"); return false\\\'>[\'+i+\']</a>\'+(with_values?\'=<a href=./index.htm style=\\\'color:#000000\\\' onClick=\\\'alert('+obj_str.replace(/'/g, '&#039;')+'['+i+']); return false\\\'>&lt;value></a>\':\'\')+\',  \';');
	else
		for(n in obj) if(!n.match(rExp)) {if(debug){eval('alert(\''+n+': \')'); eval('alert(obj.'+n+')');} eval('val = obj.'+n); eval('s += \'<a href=./index.htm onClick=\\\'browseObjProps("'+obj_str.replace(/'/g, '&#039;')+'.'+n+'"); return false\\\'>\'+n+\'</a>\'+(with_values?\'=<a href=./index.htm style=\\\'color:#000000\\\' onClick=\\\'alert('+obj_str.replace(/'/g, '&#039;')+'.'+n+'); return false\\\'>&lt;value></a>\':\'\')+\',  \';');}
	/*
	for(n in obj) 
		eval('s += \'<a href=./index.htm onClick=\\\'alert('+obj_str.replace(/'/g, '&#039;')+'.'+n+'); return false\\\'>&lt;value></a>,  \';');
	*/
	showAlert(s);
}
function getActualCSSValue(oElement,strProperty){
	if(oElement){
		if(oElement.currentStyle){
			// это MSIE
			// у нас есть прекрасное свойство currentStyle
			// но сначала надо преобразовать имя свойства из css в ява-скрипт
			// т.е. не "font-size", а "fontSize"
	
			strProperty=strProperty.replace(/-\w/g,
				function($1){return $1.toUpperCase().substr(1)}
			);
			return oElement.currentStyle[strProperty];
		}
		if(navigator.userAgent.match(/AppleWebKit/)){
			return ''; // ... с презрением к Сафари и KHTML
		}
		if(document.defaultView){
			// это Gecko
			// используем загадочный, слабо документированный
			// но тем не менее работающий объект defaultView
	
			return document.defaultView.getComputedStyle(oElement,'').getPropertyValue(strProperty);
		}
		// ни рыба, ни мясо
		// до свидания
		throw "Obsolete browser";
	}
}

function getActualCSSValue(oElement, strProperty){
	if(oElement){
		if(oElement.currentStyle){
			strProperty=strProperty.replace(/-\w/g,
				function($1){return $1.toUpperCase().substr(1)}
			);
			return oElement.currentStyle[strProperty];
		}
		if(isKHTML){
			// добавить условие выбора - className или cssText
			eval('rExp = /\.'+oElement.className+'/;');
			var val = '';
			for(var i=1; i<=document.styleSheets.length; i++)
				for(var j=1; j<=document.styleSheets[i-1].cssRules.length; j++)
					if(document.styleSheets[i-1].cssRules[j-1].selectorText.match(rExp))
						val = document.styleSheets[i-1].cssRules[j-1].style[strProperty];

			return val;
		}
		if(document.defaultView){
			strProperty=strProperty.replace(/-\w/g,
				function($1){return $1.toUpperCase().substr(1)}
			);
			var val = '';
			eval('var rExp = /\.'+oElement.className+'/;');
			for(var i=1; i<=document.styleSheets.length; i++)
				for(var j=1; j<=document.styleSheets[i-1].cssRules.length; j++)
					if(document.styleSheets[i-1].cssRules[j-1].selectorText.match(rExp))
						val = document.styleSheets[i-1].cssRules[j-1].style[strProperty];

			return val;
			
			// return document.defaultView.getComputedStyle(oElement,'').getPropertyValue(strProperty);
		}
	}
}

function stopBubble(e){
	if(isMac) return false;
	if(!isMozilla) 
		window.event.cancelBubble=true;
	else 
		e.stopPropagation();
}


function switchAdminConsole(action){
	if(action==0){
		document.getElementById('admin_console').style.display = 'none';
		if(isMSIE) document.getElementById('admin_console_block_png').style.display = 'none';
	} else {
		switchBlockDisplay('admin_console');
		if(isMSIE) switchBlockDisplay('admin_console_block_png');
	}
	document.getElementById('admConsoleTbl').className = (((document.getElementById('admin_console').style.display=='none') || (action==0))?'xp_style_dis':'xp_style_act');
}

function main_menu_act(id, act){
	var tree_id = id.replace(/_\d+$/, '');
	if(isDefined(tree[tree_id])){
		if(isDefined(tree[tree_id].bghover))
			var bgcolor = (act?tree[tree_id].bghover:tree[tree_id].bgdis);
			if(tree[tree_id].isMainMenu) {
				document.getElementById('m'+id+'td_l').style.backgroundColor = 
				document.getElementById('m'+id+'td_r').style.backgroundColor = bgcolor;
			}
			document.getElementById('m'+id+'td_i').style.backgroundColor = bgcolor;
		if(isDefined(tree[tree_id].texthover))
			document.getElementById('a'+id).style.color = (act?tree[tree_id].texthover:tree[tree_id].textdis);
	}
}

function unlanguage(txt){
	var arr = txt.split('###');
	return (arr.length>=language)?arr[language]:txt;
}

function needAuth(){
	showAlert(''+
		unlanguage('Данная функция доступна только авторизованным пользователям###This function is accessible to authorized users only')+
		'<br /><br />'+
		bullet()+
		'<a href=./ onclick=\'showLogin(); return false\'>'+unlanguage('Вход###Log in')+'<'+'/a><br />'+
		bullet()+
		'<a href='+htmlrootpath+'/registration/index.htm>'+unlanguage('Регистрация###Registration')+'<'+'/a>'+
	'');
	return false;
}


var admConsoleInterv;
var macstyleInterv;
adminConsoleHideTimeout = macstyleHideTimeout = 100;

var adminConsoleWidth;
var adminConsoleHeight;

var firstMovingNode = 0;
var mn_sect_groupsID1;
var mn_ind1;
var mn_url1;
var mn_parent1;
var mn_deep1;
var tNode = new Array();
var sect_groupsID = 0;

var tree = new Array();

var recycleBin = null;

if(isMozilla && !isMSIE) {event = null;}

var frmOnSubmit;
var nonCompleteAuthor = new Function('alert(\'Необходимо завершить процесс ввода автора проверкой.\'); return false');
var nonCompleteKeywords = new Function('alert(\'Необходимо завершить процесс изменения ключевых слов проверкой.\'); return false');

function cross_PNG_background(name, src, adds, sizingMethod){
	if(isMSIE)
		return name+' {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+htmlrootpath+src+'\', sizingMethod=\''+(isDefined(sizingMethod)?sizingMethod:'crop')+'\');white-space:nowrap;'+(isDefined(adds)?adds:'')+'} ';
	else if(isDOM)
		return name+' {background-image:url('+htmlrootpath+src+');white-space:nowrap;'+(isDefined(adds)?adds:'')+'} ';
}

var liveSearchReq = false;

function save_user_setting(name, value, redirect_url){
	/*
	// $htmlrootpath/pagegen.php3?action=change_options&get_user_option[textareamode]=".($type=='htmltextarea'?'buttonstextarea':'htmltextarea')."
	if(window.XMLHttpRequest){
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject){
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(redirect_url!='')
		liveSearchReq.onreadystatechange = new Function(
			"if(liveSearchReq.readyState == 4){"+
				"document.location.href = '"+redirect_url+"';"+
			"}"
		);
	liveSearchReq.open('GET', htmlrootpath+'/system/container_actions.php3?action=saveSetting&name='+name+'&value='+value);
	liveSearchReq.send(null);
	*/
	xajax__respondent('saveUserSetting', name, value, redirect_url);
}

/* =============================
    ДОПОЛНИТЕЛЬНЫЕ СТИЛИ
============================= */

if(document.all && !window.opera) {
	if (/MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32") {
		document.write("<style type=\"text/css\">"+
		"#admin_console_block_png {width:100%;filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+htmlrootpath+"/images/dark_glass.png', sizingMethod='crop');white-space:nowrap;margin:0px 0px 3px 0px;} "+
		"</style>");
	}
} else if (document.getElementById) {
	document.write("<style type=\"text/css\">"+
		"#admin_console_block {background-image:url("+htmlrootpath+"/images/dark_glass.png);white-space:nowrap;margin:0px 0px 3px 0px;}"+
		"</style>");
}

document.write("<style type=\"text/css\">"+
".xp_style_dis td.l		{background:url("+htmlrootpath+"/images/xp-style-bar/dis_left.gif) no-repeat right top;}"+
".xp_style_act_hov td.l	{background:url("+htmlrootpath+"/images/xp-style-bar/act_hov_left.gif) no-repeat right top;}"+
".xp_style_dis_hov td.l	{background:url("+htmlrootpath+"/images/xp-style-bar/dis_hov_left.gif) no-repeat right top;}"+
".xp_style_act td.l		{background:url("+htmlrootpath+"/images/xp-style-bar/act_left.gif) no-repeat right top;}"+
".xp_style_dis td.r		{background:url("+htmlrootpath+"/images/xp-style-bar/dis_right.gif) no-repeat left top;}"+
".xp_style_act_hov td.r	{background:url("+htmlrootpath+"/images/xp-style-bar/act_hov_right.gif) no-repeat left top;}"+
".xp_style_dis_hov td.r	{background:url("+htmlrootpath+"/images/xp-style-bar/dis_hov_right.gif) no-repeat left top;}"+
".xp_style_act td.r		{background:url("+htmlrootpath+"/images/xp-style-bar/act_right.gif) no-repeat left top;}"+
".xp_style_dis td.i		{background:url("+htmlrootpath+"/images/xp-style-bar/dis_bg.gif) repeat-x left top;}"+
".xp_style_act_hov td.i	{background:url("+htmlrootpath+"/images/xp-style-bar/act_hov_bg.gif) repeat-x left top;color:#FFFFFF;}"+
".xp_style_dis_hov td.i	{background:url("+htmlrootpath+"/images/xp-style-bar/dis_hov_bg.gif) repeat-x left top;}"+
".xp_style_act td.i		{background:url("+htmlrootpath+"/images/xp-style-bar/act_bg.gif) repeat-x left top;color:#FFFFFF;}"+

(!isMozilla?"img {behavior: url('"+htmlrootpath+"/pngbehavior.htc'); vertical-align:middle}":"")+
"</style>");
