﻿
var aLang = new Array();

var oImg = new Image();
oImg.src = "";

function onLoad()
{
}

function popupWindow(sUrl, iWidth, iHeight, sFrameName)
{
	if (!sFrameName) sFrameName = "";

	scrollBarsShow = "0";
	if (window.screen.height<iHeight) 
	{
		iHeight = window.screen.height - 40;
		scrollBarsShow = "1";
	}
	if (window.screen.width<iWidth)
	{
		iWidth = window.screen.width - 10;
		scrollBarsShow = "1";
	}

	var topPosition  = (window.screen.height-30-iHeight)/2;
	var leftPosition = (window.screen.width-iWidth)/2

	return window.open(sUrl, sFrameName, "top="+topPosition+",left="+leftPosition+",menubar=0,scrollbars="+scrollBarsShow+",resizable=0,width="+iWidth+",height="+iHeight);
}

function displayWindowImg(sPath, iWidth, iHeight, sTitle)
{
	var oImgWin = popupWindow("", iWidth, iHeight);

	oImgWin.document.write ("<html><head><title>"+sTitle+"</title></head>");
	oImgWin.document.write ("<body style='margin-left:0;margin-top:0;margin-rigth:0;'>");
	oImgWin.document.write ("<img border='0' src='"+sPath+"' />");
	oImgWin.document.write ("<!-- null, null , null , null, null, null , null , null, null, null , null , null, null, null , null , null, null, null , null , null  -->");
	oImgWin.document.write ("</body></html>");
	return oImgWin;
}

function displayWindowImgSize(sUrl, sTitle)
{
	return displayWindowImgSize(sUrl, sTitle, 0);
}

function displayWindowImgSize(sUrl, sTitle, iTry)
{
	if ((!iTry) || (iTry == '')) iTry = 0;
	if (iTry < 600)
	{
		oImg.src = sUrl;
		if (oImg.complete)
		{
			var ua = navigator.userAgent;
			var iHeightAdd = 8;
			if ((navigator.appName == "Microsoft Internet Explorer") || (ua.indexOf('Opera') != -1)) iHeightAdd = 0;
		
			var win = displayWindowImg(sUrl, oImg.width, oImg.height+iHeightAdd, sTitle);
			oImg = new Image();
			oImg.src = "";
			return true
		} 
		else
		{
			setTimeout("displayWindowImgSize('"+ sUrl +"', '"+ sTitle +"', "+ (++iTry) +")", 1000);
		}
		return false;
	}
	alert(aLang['ErrorImageLoad']);
	return false;
}


function isDigit( e )
{
	e = e || event ;
	var iCode = ( e.keyCode || e.charCode ) ;
	var res = (
			( iCode >= 48 && iCode <= 57 )		// Numbers
			|| (iCode >= 37 && iCode <= 40)		// Arrows
			|| iCode == 8		// Backspace
			|| iCode == 46		// Delete
		) ;
	return res;
}

function IsSummerTime(date)    // проверям, является ли date летним
{
    var march = new Date( Date.UTC( date.getUTCFullYear(), 2, 31 ) );  // исходим от 31 марта 
    var begin_st = new Date( Date.UTC( date.getUTCFullYear(), 2, 31 - march.getUTCDay() ) ); // и получаем его последнее восресенье.

    var oct  = new Date( Date.UTC( date.getUTCFullYear(), 9, 31 ) ); // тоже самое с октябрём
    var end_st = new Date( Date.UTC( date.getUTCFullYear(), 9, 31 - oct.getUTCDay() ) );

    if ((date >= begin_st) && (date < end_st)) return 1; // смотрим, лежит ли date между ними
    else return 0;
}

function getBounds(element)
{
	if (!element) return false;
  var left = element.offsetLeft ? element.offsetLeft : 0;
  var top = element.offsetTop ? element.offsetTop : 0;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft;
    top += parent.offsetTop;
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function HideSelects(oSubMenu, bVisible)
{
	if ((oSubMenu) && (oSubMenu.className.search(/submenu_level2/) >= 0) && (isIElte7))
	{
		var selectList = document.getElementsByTagName("SELECT");
		for (var i = 0; i < selectList.length; i++)
		{
			if (bVisible)
				selectList[i].style.visibility = 'hidden';
			else
				selectList[i].style.visibility = 'visible';
		}
	}
}

function ControlPositon(oMenuElement, oSubMenu)
{
	if (oSubMenu) oSubMenu.style.top = oSubMenu.style.top;
	
	var oSubMenuBounds = getBounds(oSubMenu);
	var oMenuElementBounds = getBounds(oMenuElement);

	if ((oSubMenu) && (oSubMenuBounds.height > 200))
	{
		HideSelects(oSubMenu, true);
	}

	var iWindowWidth = (window.innerWidth)?window.innerWidth:
		((document.all)?document.body.offsetWidth:null);
		
	var iWindowHeight = (window.innerHeight)?window.innerHeight:
		((document.all)?document.body.offsetHeight:null);

	if (oSubMenuBounds.left > 700)
	{
		if (oSubMenuBounds.left + oSubMenuBounds.width > iWindowWidth - 10) 
		{
			oSubMenu.style.left = -Math.abs(oMenuElementBounds.width - oSubMenuBounds.width);
		}
	}

	if (oSubMenuBounds.top > 410)
	{
		if (oSubMenuBounds.top + oSubMenuBounds.height > iWindowHeight - 20) 
		{
			var iTop = -Math.abs(oSubMenuBounds.top + oSubMenuBounds.height - iWindowHeight + 20);
			if ((oSubMenuBounds.top + iTop) <= 60) iTop += Math.abs(oSubMenuBounds.top + iTop - 60); 
			oSubMenu.style.top = iTop;
		}
	}
}

var openMenu2, openMenu3;

function ShowSubmenu(oMenuElementId, bVisible)
{
	oMenuElement = document.getElementById(oMenuElementId);
	
	if (!oMenuElement) return;
	
	if ((oMenuElement.open != undefined) && (oMenuElement.open == bVisible)) return;
	
	if ((!bVisible) && (!oMenuElement.closeaction)) return;
	
	var oSubMenu = document.getElementById('submenu_' + oMenuElementId);
	var oMenuActionLabel = document.getElementById('menu_act_' + oMenuElementId);
	
	if (oMenuActionLabel) oMenuActionLabel.style.backgroundColor = bVisible ? '#0e457d' : '';
	if (oSubMenu) 
	{
		if (!bVisible)
		{
			if (openMenu2 == oMenuElementId) openMenu2 = null;
			if (openMenu3 == oMenuElementId) openMenu3 = null;
			HideSelects(oSubMenu, false);
		}

		oMenuElement.open = bVisible;
		oSubMenu.style.display = bVisible ? '' : 'none';
		
		if (bVisible)
		{
			if (oSubMenu.className.search(/submenu_level2/) >= 0) 
			{
				if (openMenu2 != oMenuElementId) 
				{
					CloseSubmenuForcibly(openMenu2);
					CloseSubmenuForcibly(openMenu3);
				}
				openMenu2 = oMenuElementId;
			}
			else
			{
				if (openMenu3 != oMenuElementId) 
				{
					CloseSubmenuForcibly(openMenu3);
				}
				openMenu3 = oMenuElementId;
			}
			ControlPositon(oMenuElement, oSubMenu);
		}
	}
}

function OpenSubmenu(oMenuElement)
{
	oMenuElement.closeaction = false;
	ShowSubmenu(oMenuElement.id, true);
}

function CloseSubmenu(oMenuElement)
{
	oMenuElement.closeaction = true;
	window.setTimeout("ShowSubmenu('" + oMenuElement.id + "', false)", 5);
}

function CloseSubmenuForcibly(oMenuElementId)
{
	if (oMenuElementId)
	{
		oMenuElement = document.getElementById(oMenuElementId);
		oMenuElement.closeaction = true;
		ShowSubmenu(oMenuElementId, false);
	}
}

function SendVote(formId)
{
	popupWindow('', 600, 300, 'voteres');
	var formVote = document.getElementById(formId);
	formVote.target = 'voteres';
	formVote.submit();
	return true;
}

function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null ) node = document;
	if ( tag == null ) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	pattern.compile("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) 
	{
		if ( pattern.test(els[i].className) ) 
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else 
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function loadFlash(objectId, url, width, height)
{
	var so = new SWFObject(url,"f"+objectId,width,height,"7");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write(objectId);
}

function ClearTarifForm()
{
	var oTarifForm = document.getElementById('tarif_filtr_form');
	var oInputList = oTarifForm.getElementsByTagName('INPUT');
	for (var key in oInputList)
	{
		if (oInputList[key].type == 'text') oInputList[key].value = '';
	}
  		
	var oSelectList = oTarifForm.getElementsByTagName('SELECT');
	for (var key in oSelectList)
	{
		if (oSelectList[key].id)
		{
			if (oSelectList[key].id.search(/_usl$/i) >= 0) oSelectList[key].value = -1;
			else if (oSelectList[key].id != 'result_rows') oSelectList[key].value = '';
		}
	}
  		
	var oMembersList = document.getElementById('members').options;
	for (var key in oMembersList)
	{
		if (key == 0) oMembersList[key].selected = true;
		else oMembersList[key].selected = false;
	}
}

function getBodyScrollTop()
{
	return self.pageYOffset || 
		(document.documentElement && document.documentElement.scrollTop) || 
		(document.body && document.body.scrollTop);
}

function ShowRatingCharDesc(e, id, visible)
{
	e = e || event;
	var oDivDesc = document.getElementById(id);
	if (oDivDesc)
	{
		oDivDesc.style.display = visible ? '' : 'none';
	}
}