function OpenWindow (theURL,winName,features)
{
  window.open (theURL,winName,features);
}
function PreLoad (s)
{
  var I = new Image ();
  I.src = s;
}
function SwitchMode (Lay)
{
  if ( document.getElementById(Lay).style.display == 'none' )
    document.getElementById(Lay).style.display = 'block';
  else
    document.getElementById(Lay).style.display = 'none';
}

function SwitchVisible (Lay)
{
  if ( document.getElementById(Lay).style.visibility == 'hidden' )
    document.getElementById(Lay).style.visibility = 'visible';
  else
    document.getElementById(Lay).style.visibility = 'hidden';
}
function Popup (Pars)  
{
  var V = Pars.split (',');
  var theURL = '', winName = '', features = new Array ();
  var Width = 0, Height = 0;
  for ( i = 0; i < V.length; i++ )
  {
    var V1 = V[i].split ('=');
    if ( V1[0] == 'url' )
      theURL = V[i].replace (/url=/, '');
    else
      if ( V1[0] == 'winname' )
        winName = V[i].replace (/winname=/, '');
      else
      {
        if ( V1[0] == 'width' )
          Width = V1[1];
        if ( V1[0] == 'height' )
          Height = V1[1];
        features.push (V[i]);
      }
  }
  var Left = (window.screen.availWidth - Width) / 2;
  var Top = (window.screen.availHeight - Height) / 2;
  features.push ('left=' + Left);
  features.push ('top=' + Top);
  window.open (theURL, winName, features.join(','));
}                                     

function URLEncode (Text1)
{
        var SAFECHARS = "0123456789" +                                  
                                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                                        "abcdefghijklmnopqrstuvwxyz" +
                                        "-_.!~*'()";                            
        var HEX = "0123456789ABCDEF";

        var plaintext = Text1;
        var encoded = "";
        for (var i = 0; i < plaintext.length; i++ ) {
                var ch = plaintext.charAt(i);
            if (ch == " ") {
                    encoded += "+";                             
                } else if (SAFECHARS.indexOf(ch) != -1) {
                    encoded += ch;
                } else {
                    var charCode = ch.charCodeAt(0);
                        if (charCode > 255) {
                                encoded += "+";
                        } else {
                                encoded += "%";
                                encoded += HEX.charAt((charCode >> 4) & 0xF);
                                encoded += HEX.charAt(charCode & 0xF);
                        }
                }
        } // for

        return Text1;
};

function Rand ()
{
  return Math.round (Math.random () * 12345678); 
}

function MakeFavorite (Obj, URL) 
{
  Obj.style.behavior = 'url(#default#homepage)';
  Obj.setHomePage (URL);
  // example: MakeFavorite (this, 'http://www.site.com');
}

function LastUpdate(){
	
	var MonthArray = new Array("января", "февраля", "марта","апреля", "мая", "июня","июля", "августа", "сентября","октября", "ноября", "декабря");
	
	var today = new Date();
	
	var year = today.getYear();
	
	if(year<1000) year+=1900;
	
	var todayStr = today.getDate() + " " + MonthArray[today.getMonth()]+ " " + year + " г.";
	
	document.write(todayStr);

	var V = new Array ();
	date=document.lastModified;
	date2=date.split(' ');
	V=date2[1].split(':');
	document.write('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Сайт обновлен в '+V[0]+':'+V[1]+'&nbsp;<span style="padding:3px 4px;background-color:#EDF2FA;color:red;white-space:nowrap;"><strong>Тестовый режим</strong></span>');
}

var LastLayer,LayType;

function ShowSubMenu(lay,type){
	LayType=type;
	if(lay){
		if(LastLayer){
			document.getElementById("subnav"+LastLayer).style.display = 'none';
		}
		LastLayer=lay;
		document.getElementById("subnav"+lay).style.display = 'block';
		if(LayType==2){
			if(lay!="2"){
			ww=document.getElementById("mainnav"+lay).clientWidth-document.getElementById("mainnav2"+lay).clientWidth;
			w=event.clientX-event.offsetX-ww/2-6;
			if(w<100){w=10+marginI;}
			document.getElementById("subnav"+lay).style.left=w;
			}else{
				ww=document.getElementById("mainnav"+lay).clientWidth-document.getElementById("mainnav2"+lay).clientWidth;
				w=event.clientX-event.offsetX-ww/2-6;
				if(marginI<60){
				w2=document.body.clientWidth-document.getElementById("subnav"+lay).clientWidth-10-marginI;
				}else{
				w2=document.body.clientWidth-document.getElementById("subnav"+lay).clientWidth-4-marginI;
				}
				if(w>w2){w=w2;}
				document.getElementById("subnav"+lay).style.left=w2;
			}
		}
	}
}

function HideSubMenu(type){
	LayType=type;
	setTimeout("HideSubMenu2()",200);
}

function HideSubMenu2(){
	if(LayType==2){
		if(LastLayer){
			document.getElementById("subnav"+LastLayer).style.display = 'none';
			LastLayer="";
		}
	}
}