// JavaScript Document

window.onresize = message;
function message()
{
 if(document.getElementById('kontakts').style.display=='block')
  {
   document.getElementById('kontakts').style.left = ((getClientWidth() / 2 - 205) / (getClientWidth() / 100)) + '%'; 
   document.getElementById('kontakts').style.top = ((getClientHeight() / 2 - 155) / (getClientHeight() / 100)) + '%';
  } 
}


function getClientHeight()  
{  
 return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;  
}   

function getClientWidth()  
{  
 return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;  
}  

function getXmlHttp()
{
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}


function getOpacityProperty()
{
 if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
  return 'opacity';
 if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
  return 'MozOpacity';
 if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
  return 'KhtmlOpacity';
 if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
  return 'filter';
 return false; //нет прозрачности
}

function setElementOpacity(sElemId, nOpacity)
{
 var elem = 0;
 var i = 0;
 var opacityProp = getOpacityProperty();
 if (opacityProp == "filter") 
  nOpacity *= 100;
 elem =  document.getElementById(sElemId);
 if (!elem || !opacityProp) 
  return; 
 if (opacityProp == "filter")  // Internet Exploder 5.5+
  {
   var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
   if (oAlpha) 
    elem.style.filter = "alpha(opacity=" + nOpacity + ")"
   else 
    elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=" + nOpacity + ")"; 
  }
 else // Другие браузеры
  elem.style[opacityProp] = nOpacity;
}

 function DrawHead()
  {
   var I = 0;

   for (I = 100; I <= 108; I++)   
    setElementOpacity(I, 0.8);	
	
   for (I = 200; I <= 208; I++)   
    setElementOpacity(I, 0.8);	
	
   for (I = 300; I <= 308; I++)   
    setElementOpacity(I, 0.8);	
   
   for (I = 400; I <= 408; I++)   
    setElementOpacity(I, 0.8);	
	
   for (I = 500; I <= 508; I++)   
    setElementOpacity(I, 0.8);
 
   for (I = 403; I <= 405; I++)   
    document.getElementById(I).style.height = (document.getElementById(I).offsetHeight + document.getElementById('Informer').offsetHeight) +    'px';
	
   for (I = 406; I <= 408; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById('Informer').offsetHeight) +'px';

   if (document.getElementById(406).offsetTop >= document.getElementById(306).offsetTop) 
    for (I = 500; I <= 510; I++)
     document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById(406).offsetTop + 25) +'px';
   else
    for (I = 500; I <= 510; I++)
     document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById(306).offsetTop + 25) +'px';
	 

 DropDownMenu();
 document.getElementById("Loader").style.display='none';
 LeftPercent(); 
}

 function getBodyScrollTop()   
{ 
 return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body &&document.body.scrollTop);
}  
  
function mousePageXY(e)
{
  var x = 0, y = 0;
  if (!e) 
   e = window.event;
  if (e.pageX || e.pageY)
   {
    x = e.pageX;
    y = e.pageY;
   }
  else if (e.clientX || e.clientY)
   {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
   }
 return {"x":x, "y":y};
}  
  

function DrawDropMenu(Visible, iParent, ChildCount)	
{
 var mCur = mousePageXY(0);
 var I = 0;
 if (Visible=='True') 
  {	
   for (I = iParent; I < iParent + ChildCount; I++)
    {
	 setElementOpacity(I, 0.8);	
     document.getElementById(I).style.display="block";
	}
  }
 else
  {	  
   for (I = iParent; I < iParent + ChildCount; I++)
    {
     //Если курсор по оси Х меньше чем ширина элемента меню И
     if ((mCur.x < document.getElementById(I).offsetLeft + document.getElementById(I).width)&&
     //Если курсор по оси Х больше чем левый край элемента меню(т.е. по оси Х курсор в пределах меню) И
     (mCur.x > document.getElementById(I).offsetLeft)&&
     //Если курсор по оси Y больше чем верхняя точка элемента меню И
     (mCur.y > document.getElementById(I).offsetTop)&&
     //Если курсор по оси Y меньше чем нижняя точка элемента меню
     (mCur.y < document.getElementById(I).offsetTop + document.getElementById(I).height))
      {
       return(false);
      }
	}
   for (I = iParent + 1; I < iParent + ChildCount; I++)
    document.getElementById(I).style.display="none";
    setElementOpacity(iParent, 1);	
  }
}


function setCookie (name, value) 
{
 document.cookie = name + "=" + escape(value);
}

function getCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function DropDownMenu()
{
 var AVisibleMenu = []; 
 AVisibleMenu = getCookie("MenuIndex");
// alert(AVisibleMenu);
// alert(AVisibleMenu[0]);
 if (AVisibleMenu == null)
  return;
 if (AVisibleMenu[0] == "1")
  ShowLeftMenu(325, 315); 
 if (AVisibleMenu[2] == "1")
  ShowLeftMenu(326, 318);
 if (AVisibleMenu[4] == "1")
  ShowLeftMenu(327, 321);
 if (AVisibleMenu[6] == "1")
  ShowLeftMenu(328, 324);

 if (getCookie("VMenu") != 0)
  ShowVMenu();
 window.scrollTo(0, getCookie("dscroll"));
}

function ShowLeftMenu(MenuID, ButtonID)
{
 var I = 0;
 var Child = MenuID * 10;
 var Temp = 0;
 var AVisibleMenu = []; 

 if (document.getElementById(Child).style.display == 'none')
  {
   document.getElementById(Child).style.display = 'block';  
   
   for (I = MenuID + 1; I <= 328; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById(Child).offsetHeight) +'px'; 
  
   for (I = 303; I <= 305; I++)
    document.getElementById(I).style.height = (document.getElementById(I).offsetHeight + document.getElementById(Child).offsetHeight) +'px';
   for (I = 306; I <= 308; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById(Child).offsetHeight) +'px';
   
   for (I = ButtonID; I <= 323; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + document.getElementById(Child).offsetHeight) +'px';   
	
   for (I = 325; I <= 328; I++)
    {
	 Temp = I * 10;	
	 if (document.getElementById(Temp).style.display == 'block')
      document.getElementById(Temp).style.top	=  (document.getElementById(I).offsetTop + 30)	+ 'px';
	}
  }
 else
  { 
   for (I = MenuID + 1; I <= 328; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - document.getElementById(Child).offsetHeight) +'px'; 
  
   for (I = 303; I <= 305; I++)
    document.getElementById(I).style.height = (document.getElementById(I).offsetHeight - document.getElementById(Child).offsetHeight) +'px';
   for (I = 306; I <= 308; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - document.getElementById(Child).offsetHeight) +'px';
   
   for (I = ButtonID; I <= 323; I++)
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - document.getElementById(Child).offsetHeight) +'px';   

   document.getElementById(Child).style.display = 'none';  

   for (I = 325; I <= 328; I++)
    {
	 Temp = I * 10;	
	 if (document.getElementById(Temp).style.display == 'block')
      document.getElementById(Temp).style.top	=  (document.getElementById(I).offsetTop + 30) + 'px';
	}
  }
 if (document.getElementById(406).offsetTop >= document.getElementById(306).offsetTop) 
  Temp = 406
 else
  Temp = 306;
 for (I = 500; I <= 502; I++)
  document.getElementById(I).style.top = (document.getElementById(Temp).offsetTop + 30) +'px';
 for (I = 503; I <= 505; I++)
  document.getElementById(I).style.top = (document.getElementById(Temp).offsetTop + 50) +'px';	
 for (I = 506; I <= 508; I++)
  document.getElementById(I).style.top = (document.getElementById(Temp).offsetTop + 130) +'px';	
 document.getElementById(509).style.top = (document.getElementById(Temp).offsetTop + 70) +'px';	
 document.getElementById(510).style.top = (document.getElementById(Temp).offsetTop + 115) +'px';	 
   
 //Перебрать все номера меню, и создать массив - Index[видимый или нет]. Сохранить массив в кукисы.
 for (I = 325; I <= 328; I++)
  {
   Temp = I * 10;
   if (document.getElementById(Temp).style.display == 'none')    
    AVisibleMenu.push("0")
   else
    AVisibleMenu.push("1");
  }
 setCookie("MenuIndex", AVisibleMenu);
}


function ShowVMenu()
{
 var I = 0;	
 var Temp = 0;
 if (document.getElementById('Player').style.display == 'block')
  {
   document.getElementById(38).src = 'IMG/ArrowDown.png';
   document.getElementById(203).style.height = '50px';	
   document.getElementById(204).style.height = '50px';
   document.getElementById(205).style.height = '50px';	
 
   document.getElementById(206).style.top = '205px';	
   document.getElementById(207).style.top = '205px';	
   document.getElementById(208).style.top = '205px';	
   
   for (I = 300; I <= 323; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - 450) +'px';
   
   for (I = 400; I <= 408; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - 450) +'px';
	
   document.getElementById('Informer').style.top = document.getElementById(403).style.top;	
	
   for (I = 500; I <= 510; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop - 450) +'px';
	
   for (I = 325; I <= 328; I++)  	
    {
     Temp = I * 10;		
     document.getElementById(I).style.top = (document.getElementById(I).offsetTop - 450) + 'px';
     document.getElementById(Temp).style.top = (document.getElementById(I).offsetTop + 30) + 'px';
	}
    document.getElementById(324).style.top = (document.getElementById(324).offsetTop - 450) + 'px';//минус размер шрифта
    document.getElementById('Player').style.display = 'none';
    setCookie('VMenu', 0);
  }
 else
  {
   document.getElementById(38).src = 'IMG/ArrowUp.png';
   document.getElementById(203).style.height = '500px';	
   document.getElementById(204).style.height = '500px';
   document.getElementById(205).style.height = '500px';	
 
   document.getElementById(206).style.top = '655px';	
   document.getElementById(207).style.top = '655px';	
   document.getElementById(208).style.top = '655px';	 
   for (I = 300; I <= 323; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + 450) +'px';
   for (I = 400; I <= 408; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + 450) +'px';
   for (I = 500; I <= 510; I++)   
    document.getElementById(I).style.top = (document.getElementById(I).offsetTop + 450) +'px';	
	
   document.getElementById('Informer').style.top = document.getElementById(403).style.top;	
   	
   for (I = 325; I <= 328; I++) 
    {
     Temp = I * 10;	
     document.getElementById(I).style.top = (document.getElementById(I).offsetTop + 450) + 'px';//минус размер шрифта	    
     document.getElementById(Temp).style.top = (document.getElementById(I).offsetTop + 30) + 'px';	 
	}
   document.getElementById(324).style.top = (document.getElementById(324).offsetTop + 450) + 'px';//минус размер шрифта	
   document.getElementById('Informer').style.top = document.getElementById(403).style.top;
   document.getElementById('Player').style.display = 'block';
   setCookie('VMenu', 1);
  }
}

function UserExit()
{
 var req = getXmlHttp()  
 req.open('GET', 'forum/login.php?logout=true&sid='+getCookie("phpbb2mysql_sid"), true);
 req.send(null);  // отослать запрос
 setTimeout("reloadloc()",1500);
}

 function reloadloc()
 {
  window.location.reload();
 }

function DH()
{
 var ua = navigator.userAgent.toLowerCase(); 
 var isOpera = (ua.indexOf('opera')  > -1); 
 var isIE = (!isOpera && ua.indexOf('msie') > -1); 
	  
 return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight,     getViewportHeight()); 
	  
 function getViewportHeight() 
 { 
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight :  document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
 }
}

function Modal(Id)
{
 setElementOpacity("FonModal", 0.2);	
 document.getElementById("FonModal").style.height = DH() + 'px';
 document.getElementById("FonModal").style.left = '0px'; 

 document.getElementById(Id).style.left = ((screen.width / 2 - 205) / (screen.width / 100)) + '%';  
 document.getElementById(Id).style.top = ((screen.height / 2 - 155) / (screen.height / 100)) + '%'; 
 document.getElementById("FonModal").style.display = 'block';   
 document.getElementById(Id).style.display = 'block';

}

function CloseModal(Id)
{
 document.getElementById("FonModal").style.display = 'none'; 
 document.getElementById(Id).style.display = 'none'; 
}

function FormSubmit(FormName)
{
 document.forms(FormName).submit(); 
}
  
function LeftPercent()
{
 var I = 0;
 var Percent = 0;

 if (screen.width <= 1024) 
  {
   if (!document.all) 
   {  
    document.constructor.prototype.__defineGetter__('all', function() { return document.getElementsByTagName('*'); } );
    for (I = 0; I < document.getElementsByTagName('*').length - 1; I++) 	
     if (document.getElementsByTagName('*').item(I).className.indexOf('Standart') + 1)
      document.getElementsByTagName('*').item(I).style.left = Percent;
    return;	
   } 
   for (I = 0; I < document.all.length - 1; I++) 	
    if (document.all(I).style.left == '10%')
     document.all(I).style.left = '0%';
  }
	
 if (screen.width > 1024) 
  {
   Percent = (((screen.width - 990) / 2) / (screen.width / 100) - 1)+ '%'; 
   
   if (!document.all) 
    {  
     document.constructor.prototype.__defineGetter__('all', function() { return document.getElementsByTagName('*'); } );
     for (I = 0; I < document.getElementsByTagName('*').length - 1; I++) 	
      if (document.getElementsByTagName('*').item(I).className.indexOf('Standart') + 1)
       document.getElementsByTagName('*').item(I).style.left = Percent;
     return;	
    }     
   for (I = 0; I < document.all.length - 1; I++) 	
    if (document.all(I).style.left == '10%')
     document.all(I).style.left = Percent;
  }
}  

