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);
}
function isControl(keyCode){
	return ((',35,36,37,39,8,9,46,').indexOf(','+keyCode+',')>-1);
}
function checkOnInt(val){
	return (((',35,36,37,39,8,46,').indexOf(','+val+',')>-1) || (val>=48 && val<=57) || (val>=96 && val<=105));
}
function checkOnFloat(val){
	return (((',35,36,37,39,8,46,190,191,').indexOf(','+val+',')>-1) || (val>=48 && val<=57) || (val>=96 && val<=105));
}



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 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=swLiveConnect value="true">' +
		'<param name=menu value="false">' +
		'<param name=FlashVars value="'+vars+'">' +
		'<embed ' +
		'src="'+src+'" ' +
		'menu="false" ' +
		'quality="high" ' +
		'bgcolor="'+bgcolor+'" ' +
		'wmode="'+wmode+'" ' +
		((w && w!='')?'width="'+w+'" ':'') +
		((h && h!='')?'height="'+h+'" ':'') +
		'name="'+ID+'" ' +
		'align="" ' +
		'swLiveConnect="true" ' +
		'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+'/g,",").replace(/^,/,"").replace(/,$/,"");');
			break;
		}
	}
	obj.value = listvar;
}

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;
}
function checkAuth(){
	if(document.getElementById('authFormLogin') && document.getElementById('authFormPassword')){
		var ref = document.location.href.replace(/http:\/\//, '').replace(/[^\/]+/, '');
		var s = '';
		if(document.getElementById('authFormLogin').value=='')
			s += '<li>'+unlanguage('поле <b>Логин<' + '/b> пустое###field <b>Login<' + '/b> is empty')+'.';
		else
			if(document.getElementById('authFormLogin').value.match(/\\W/g)!=null)
				s += '<li>'+unlanguage('недопустимые символы в поле <b>Логин<' + '/b>###incorrect chars in <b>Login<' + '/b>')+'.';
		if(document.getElementById('authFormPassword').value=='')
			s += '<li>'+unlanguage('поле <b>Пароль<' + '/b> пустое###field <b>Password<' + '/b> is empty')+'.';
		if(s!=''){
			showAlert(unlanguage('ошибка:###error:')+'<ul>'+s+'</ul>');
			return false;
		}
		document.auth.submit();
		return false;
	} else {
		showAlert(unlanguage('Системная ошибка. Обратитесь к разработчикам сайта.###System error. Mail to site administrator.'));
		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();

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:'')+'} ';
}


/* =============================
    ДОПОЛНИТЕЛЬНЫЕ СТИЛИ
============================= */

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;}"+
(isMSIE?"img {behavior: url('"+htmlrootpath+"/pngbehavior.htc'); vertical-align:middle}":"")+
"</style>");
