if ((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1)){
	bw_type = "ie";
}else if (navigator.appName.indexOf("Netscape") != -1){
	bw_type = "nn";
	if (parseInt(navigator.appVersion) >= 5){
		bw_type += "6";
	}
}else if (navigator.userAgent.indexOf("Opera") != -1){
	bw_type = "op";
}else{
	bw_type="other";
}


function wopen(_wurl,_wn,_ww,_wh,_wscrl){
 if(screen.width){
  wpos_x = (screen.width-_ww)/2;
  if (wpos_x < 0){ wpos_x = 0;}
  wpos_y = (screen.height-_wh)/2;
  if (wpos_y < 0){ wpos_y = 0;}
 }else{
  wpos_x = 0;
  wpos_y = 0;
 }
 if(_wn==""){ _wn = "w_test";}
 wind_desc = window.open(_wurl,_wn,"alwaysRaised=0,top="+wpos_y+",left="+wpos_x+",height="+_wh+",width="+_ww+",menubar=0,resizable=0,scrollbars="+_wscrl+",status=0");
 wind_desc.focus();
 return wind_desc;
}

function printw(){
	PW1=wopen("print.php?up="+window.location,"PrnWind",950,600,0,1,1);
}


function imgw(iurl,ix,iy){
	PW2=wopen("img.html?i="+iurl,"ImgWind",ix,iy,0);
}


var Sb = new Object();
Sb.isDOM=(document.getElementById)?true:false;
Sb.isIE=(document.all)?true:false;
Sb.isOP=(window.opera)?true:false;
Sb.isNS4=(document.layers)?true:false;
Sb.xOfs = 0;
Sb.yOfs = 1;
Sb.NS4_notice = "Для корректного отображения сайта,\nВаш браузер должен быть совместим с\nMozilla 1.x/IExploer 5.x/Opera 7.x";
Sb.L1_Color = "";
Sb.L1_Color_Over = "";
Sb.L1_BgColor = "";
Sb.L1_BgColor_Over = "#C4D2FC";
Sb.L2_Color = "";
Sb.L2_Color_Over = "";
Sb.L2_BgColor = "";
Sb.L2_BgColor_Over = "#C4D2FC";
Sb.c_idPref = "mc";
Sb.l_idPref = "ml";
Sb.delay = 800;
//items: i1, i1_1, i1_1_2, ...
Sb.M_items = new Object();
//vars:
//[0] - width
//[1] - height
//[2] - x
//[3] - y
//[4] - level
Sb.activeItem = null;
Sb.interval = null;


if(Sb.isDOM) Sb.getObj = function(id)
{
	return document.getElementById(id)||null;
}
else if(Sb.isIE) Sb.getObj = function(id)
{
	return document.all[id]||null;
}
else if(Sb.isNS4) Sb.getObj = function(id)
{
	return document.layers[id]||null;
}

Sb.splitName = function(str)
{
	if("string"==typeof(str))
	{
		var r = str.split("_");
	}
	else
	{
		var r = new Array();
		r[0] = str;
	}
	return r;
}

Sb.print_r = function(n)
{
	var r = "";
	var t = typeof(n);
	r+="typeof: "+t+"\n";
	if(t=="object")
	{
		r+="Properties:\n";
		for (var i in n) {
			r+=i+"="+n[i]+"\n";
		}
	}
	r+="Value:\n"+n;
	if(arguments.length>1)
	{
		if(arguments[1])
		{
			return r;
		}
		else
		{
			Sb.TestAlert_content = r;
			Sb.TestAlertWindow = window.open("","AlertWindow","resizable,scrollbars,height=300,width=400");
			setTimeout("Sb.WriteAlertWindow()", 50);
		}
	}
	else
	{
		alert(r);
	}
}

Sb.WriteAlertWindow = function()
{
	Sb.TestAlertWindow.document.write("<html><head><title>Information</title></head><body style=\"padding:5px;margin:0px;font:12px Arial\"><pre>"+Sb.TestAlert_content+"</pre></body></html>");
	Sb.TestAlertWindow.document.close();
}

Sb.getObjWidth = function(id)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	if(obj.clientWidth)
	{
		return obj.clientWidth;
	}
	else if(obj.style.width)
	{
		return obj.style.width;
	}
	//todo
}

Sb.getObjHeight = function(id)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	if(obj.clientHeight)
	{
		return obj.clientHeight;
	}
	else if(obj.style.height)
	{
		return obj.style.height;
	}
	//todo
}

Sb.getObjLeft = function(id)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	if(obj.offsetParent)
	{
		x = obj.offsetLeft;
		t = obj.offsetParent;
		while (t != null)
		{
			x += t.offsetLeft;
			t = t.offsetParent;
		}
    return x;
	}
	else if(obj.style.left)
	{
		return obj.style.left;
	}
	//todo
}

Sb.getObjTop = function(id)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	if(obj.offsetParent)
	{
		y = obj.offsetTop;
		t = obj.offsetParent;
		while (t != null)
		{
			y += t.offsetTop;
			t = t.offsetParent;
		}
    return y;
	}
	else if(obj.style.top)
	{
		return obj.style.top;
	}
	//todo
}

Sb.ObjSetVis = function(id, state)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	obj.style.visibility = state?"visible":"hidden";
}

Sb.ObjSetPos = function(id, x, y)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	obj.style.left = x+"px";
	obj.style.top = y+"px";
}

Sb.ObjSetWidth = function(id, w)
{
	obj=Sb.getObj(id);
	if(obj==null) return null;
	//alert("set w "+w+" for "+id);
	obj.style.width = w;
}

Sb.ObjSetColor = function(id, color)
{
	obj=Sb.getObj(id);
	if(obj!=null)
	{
		obj.style.color = color;
		return true;
	}
	return false;
}

Sb.ObjSetBgColor = function(id, color)
{
	obj=Sb.getObj(id);
	if(obj!=null)
	{
		obj.style.backgroundColor = color;
		return true;
	}
	return false;
}

Sb.getItem = function(path)
{
	return eval("Sb.M_items.i"+path);
}

Sb.ChangeItemVis = function(id,mode)
{
	var t_id="";
	var isThrow=true;
	var item=null;
	var i=1;
	while(isThrow)
	{
		t_id=id+"_"+i;
		eval("item=Sb.M_items.i"+t_id);
		if("undefined"!=typeof(item) && item!=null)
		{
			Sb.ObjSetVis(Sb.c_idPref+t_id, mode);
		}
		else
		{
			isThrow=false;
		}
		i++;
	}
}

Sb.ChangeVis = function(id,mode)
{
	eval("var item = Sb.M_items.i"+id);
	if("undefined"!=typeof(item) && item!=null)
	{
		var id_arr=Sb.splitName(id);
		var i=0;
		var t_id="";
		var isThrow=true;
		var subitem=null;
		for(i=0;i<id_arr.length;i++)
		{
			if(i>0)	t_id+="_";
			t_id+=id_arr[i];
			Sb.ChangeItemVis(t_id, mode);
		}
	}
}

Sb.M_ov = function()
{
	if(arguments.length>0)
	{
		var this_id = arguments[0];
		eval("var item=Sb.M_items.i"+this_id);
		if(item[4]>1)
		{
			Sb.ObjSetBgColor(Sb.c_idPref+this_id, Sb.L2_BgColor_Over);
		}
		else
		{
			Sb.ObjSetBgColor(Sb.c_idPref+this_id, Sb.L1_BgColor_Over);
		}
		if(Sb.activeItem && Sb.activeItem!=this_id) Sb.ChangeVis(Sb.activeItem, false);
		clearTimeout(Sb.interval);
		Sb.ChangeVis(this_id, true);
		Sb.activeItem = this_id;
	}
}

Sb.M_ou = function()
{
	if(arguments.length>0)
	{
		var this_id = arguments[0];
		eval("var item=Sb.M_items.i"+this_id);
		if(item[4]>1)
		{
			Sb.ObjSetBgColor(Sb.c_idPref+this_id, Sb.L2_BgColor);
		}
		else
		{
			Sb.ObjSetBgColor(Sb.c_idPref+this_id, Sb.L1_BgColor);
		}
		Sb.interval = setTimeout("Sb.ChangeVis(Sb.activeItem, false)", Sb.delay);
	}
}

Sb.M_cl = function(arg)
{
}

/*
mc1
mc2
	mc2_1
		mc2_1_1
		mc2_1_2
	mc2_2
	mc2_3
mc3
mc4
mc5
...
*/
Sb.initItem = function(parent_id)
{
	var isThrow=true;
	var i=1;
	//TODO
	//цыкл while, определение наибольшей ширины и количества элементов
	var maxW=0;
	while(isThrow)
	{
		if(parent_id==0)
			var this_id = i;
		else
			var this_id = parent_id+"_"+i;
		var obj=Sb.getObj(Sb.c_idPref+this_id);
		if(obj!=null)
		{
			var t=Sb.splitName(this_id);
			if(t.length>1)
				var level = t.length;
			else
				var level = 1;
			if(level>1)
			{
				eval("var W="+(parseInt(Sb.getObjWidth(Sb.c_idPref+this_id))+2));
				if(W>maxW){
					maxW = W;
					//alert("maxW found "+maxW+" in "+this_id);
				}
			}
		}
		else
			isThrow=false;
		i++;
	}
	//цыкл for по определенному кол-ву элементов, установка значений, установка наибольшей ширины
	var ix = i-2;
	//alert(ix+"\n"+parent_id);
	if(ix>0)
	{
		for(i=1;i<=ix;i++)
		{
			if(parent_id==0)
				var this_id = i;
			else
				var this_id = parent_id+"_"+i;
			if(level==1)
				eval("var maxW="+Sb.getObjWidth(Sb.c_idPref+this_id));
			eval("Sb.M_items.i"+this_id+"=new Array()");
			eval("Sb.M_items.i"+this_id+"[0]="+maxW);
			eval("Sb.M_items.i"+this_id+"[1]="+Sb.getObjHeight(Sb.c_idPref+this_id));
			if(parent_id==0)
			{
				if(i>1)
					eval("var dX=Sb.M_items.i"+(i-1)+"[2]+Sb.M_items.i"+(i-1)+"[0]+Sb.xOfs");
				else
					var dX = Sb.x;
				var dY = Sb.y;
			}
			else
			{
				eval("var parent_level=Sb.M_items.i"+parent_id+"[4]");
				if(level>2)
					eval("var dXofs=Sb.M_items.i"+parent_id+"[0]+Sb.xOfs");
				else
					var dXofs = 0;
				eval("var dX=Sb.M_items.i"+parent_id+"[2]+dXofs");
				if(level==2)
				{
					if(i==1)
						eval("var dY=Sb.M_items.i"+parent_id+"[3]+Sb.M_items.i"+parent_id+"[1]+Sb.yOfs");
					else
						eval("var dY=Sb.M_items.i"+parent_id+"_"+(i-1)+"[3]+Sb.M_items.i"+parent_id+"_"+(i-1)+"[1]+Sb.yOfs");
				}
				else
				{
					if(i==1)
						eval("var dY=Sb.M_items.i"+parent_id+"[3]");
					else
						eval("var dY=Sb.M_items.i"+parent_id+"_"+(i-1)+"[3]+Sb.M_items.i"+parent_id+"_"+(i-1)+"[1]+Sb.yOfs");
				}
			}
			eval("Sb.M_items.i"+this_id+"[2]="+dX);
			eval("Sb.M_items.i"+this_id+"[3]="+dY);
			eval("Sb.M_items.i"+this_id+"[4]="+level);
			Sb.ObjSetPos(Sb.c_idPref+this_id, dX, dY);
			if(level>1)
				Sb.ObjSetWidth(Sb.c_idPref+this_id, maxW);
			if(level==1) Sb.ObjSetVis(Sb.c_idPref+this_id, true);
			Sb.initItem(this_id);
		}
	}
}

Sb.init = function()
{
	if(Sb.isNS4) alert(Sb.NS4_notice);
	var x = Sb.getObjLeft(Sb.c_idPref+"0");
	Sb.x = (x)?x:0;
	var y = Sb.getObjTop(Sb.c_idPref+"0");
	Sb.y = (y)?y:0;
	Sb.initItem(0);
}

Sb.ToTop = function()
{
	window.scrollTo(0,0);
}

Sb.wopen = function(url, name, w, h, is_scrloll)
{
	if(screen.width)
	{
		var wpos_x = (screen.width-w)/2;
		if (wpos_x < 0){ wpos_x = 0;}
		var wpos_y = (screen.height-h)/2;
		if (wpos_y < 0){ wpos_y = 0;}
	}else{
		var wpos_x = 0;
		var wpos_y = 0;
	}
	if(name==""){
		name = "w_test";
	}
	is_scroll = (is_scroll)?1:0;
	Sb.wopen_id = window.open(url,name,"alwaysRaised=0,top="+wpos_y+",left="+wpos_x+",height="+h+",width="+w+",menubar=0,resizable=0,scrollbars="+is_scrloll+",status=0");
	Sb.wopen_id.focus();
	return Sb.wopen_id;
}
window.onload=Sb.init;

Sb.print = function()
{
	window.open("http://"+"cfkls:cthdbc@"+document.domain+"/print.php?Url="+escape(window.location));
	//alert("http://"+"cfkls:cthdbc@"+document.domain+"/print.php?Url="+escape(window.location));
}

function wopen(url,winid, w, h, toolbar, scroll, resizable)
{
	var w_url = (url=="")?"about:blank":url;
	var w_n = (winid==null)?"W_TEST":winid;
  var rw = 0, rh = 0;
  if(navigator.userAgent.indexOf("Opera")!=-1)
  {
	  if(typeof(window.innerWidth) == 'number'){
	    rw = window.innerWidth;
	    rh = window.innerHeight;
	  }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
	    rw = document.documentElement.clientWidth;
	    rh = document.documentElement.clientHeight;
	  }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
	    rw = document.body.clientWidth;
	    rh = document.body.clientHeight;
	  }
  }else{
	  if(screen.width&&screen.height)
		{
			rw = screen.width;
			rh = screen.height;
		}
  }
  var w_x = Math.round((rw-w)/2);
  if (w_x < 0){ w_x = 0;}
  var w_y = Math.round((rh-h)/2);
	if (w_y < 0){ w_y = 0;}
	var w_scr = (scroll)?1:0;
	var w_tlb = (toolbar)?1:0;
	var w_res = (resizable)?1:0;
	window.open(w_url,w_n,"alwaysRaised=0,left="+w_x+",top="+w_y+",height="+h+",width="+w+",menubar=0,toolbar="+w_tlb+",resizable="+w_res+",scrollbars="+w_scr+",status=0");
}