var d = document;
var w = window;

function wpopup(url,h,w,features,center,n)
{
	if (center==1)
	{
		ytop=Math.floor((screen.height-h)/2);
		ftop = "top="+ytop;
		left=Math.floor((screen.width-w)/2);
		fleft = "left="+left;
	}
	feat="";
	if (ftop || fleft)
	{
		feat=ftop+","+fleft+",";
	}
	feat+="height="+h+",width="+w;
	feat+=(features!="")?(","+features):"";
	window.open(url,(!n)?"newwin":n,feat);
}

function isEmpty(str)
{
	for (var i = 0; i < str.length; i++)
	if (" " != str.charAt(i))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function show(id)
{
	if (document.getElementById('block_'+id).style.display=="")
	{
		document.getElementById('block_'+id).style.display="none";
		document.getElementById('img_'+id).src="img/btn_down.gif";
		setCookie('block_'+id,'close');
	} else {
		document.getElementById('block_'+id).style.display="";
		document.getElementById('img_'+id).src="img/btn_up.gif";
		setCookie('block_'+id,'open');
	}
}

function checkBlock(id)
{
	var open=getCookie('block_'+id);
	if (!open) {
		return;
	}
	if (open=='open') {
		document.getElementById('block_'+id).style.display="";
		document.getElementById('img_'+id).src="img/btn_up.gif";
	} else {
		document.getElementById('block_'+id).style.display="none";
		document.getElementById('img_'+id).src="img/btn_down.gif";
	}
}

function mailto(name, domain)
{
	document.write('<a href="mailto:'+name+'@'+domain+'" class="link1">'+name+'@'+domain+'</a>');
}

function rsize() {
	for(i=1; i<=maxid; i++) {
		var menu = layer('popupmenu_' + i);
		if(menu.exists()) {
			var mainmenu = layer('mainmenu_' + i);
			if(mainmenu.exists()) {
				if(mainmenu.getWidth() + 5 > menu.getWidth()) {
					if(isMozilla) {
						menu.style.width = mainmenu.getWidth() - 5 + 'px';
					} else {
						menu.style.width = mainmenu.getWidth() - 5;
					}
				}
				if(getDocumentWidth() > (mainmenu.getAbsoluteLeft() + menu.getWidth())) {
					menu.setLeft(mainmenu.getAbsoluteLeft());
				} else {
					menu.setLeft(getDocumentWidth() - menu.getWidth());
				}
			}
		}
	}
	hideAll();
}

function show(id) {
	hideAll();
	var menu = layer('popupmenu_' + id);
	if(menu.exists()) {
		menu.show();
	}
}

function hideAll() {
	for(i=1; i<=maxid; i++) {
		var menu = layer('popupmenu_' + i);
		if(menu.exists()) {
			menu.hide();
		}
	}
}

function HomePage(ob) {
	if (isOpera) {
		alert("Чтобы добавить в избранное, нажмите Cnrtl+F12 и в открывшемся окне кнопку «Использовать текущую»")
	} else if (isMozilla) {
		alert("Измените домашнюю страницу вручную. Firefox не поддерживает изменение домашней страницы через скрипт.");
	} else if (isMSIE) {
		ob.style.behavior='url(#default#homepage)';
		ob.setHomePage(document.location.href)
	} else {
		alert("Измените домашнюю страницу вручную. Ваш броузер не поддерживает изменение домашней страницы через скрипт.");
	};
	return false;
}

function addBookmark(url, title) {
	if (!url) {
		var url = location.href;
	}
	if (!title) {
		var mt = document.getElementsByTagName('meta');
		var descr=mt['Description'].content;
		if (descr == '') {
			var title = document.title;
		}
	}
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
		//Gecko
		window.sidebar.addPanel (title, url, "");
	} else if (typeof window.external == "object") {
		//IE4+
		window.external.AddFavorite(url, title);
	} else if (window.opera && document.createElement) {
		//Opera7+
		var a = document.createElement('A');
		if (!a) {
			//IF Opera 6
			alert("Чтобы добавить в избранное, нажмите Cnrtl+D");
			return false; 
		}
		a.setAttribute('rel','sidebar');
		a.setAttribute('href',url);
		a.setAttribute('title',title);
		a.click();
	} else {
		alert("Добавьте, пожалуйста, сайт в избранное вручную. Скрипт не сработал.");
		return false;
	}
	return true; 
}

function map() {
	var map = window.open("/map.html", "MAP", "width=600px, height=400px, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes")
}

function video(vid) {
	if (!vid) { vid = "video.html" };
	var w = 580;
	var h = 450;
	var feat = "width=" + w + "px, height=" + h + "px,";
	//feat += "top=" + Math.floor((screen.height-h)-30) + ", ";
	feat += "top=30,";
	feat += "left=" + Math.floor((screen.width-w)-30) + ", ";
	feat += "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no";
	var map = window.open("/" + vid, "Video", feat)
}
function prn() {
	var hr = d.location.href;
	var symb = (hr.indexOf('?')>0)?'&':'?';
	var url = hr+symb+'prn=print';
	var map = window.open(url, "print", "width=700px, height=500px, toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes")
	map.onload = function() {
		var a_s = map.document.getElementsByTagName("a");
		for (var i=0, len=a_s.length; i<len; i++) {
			var hrm = map.document.location.href;
			var symb = (hrm.indexOf('?')>0)?'&':'?';
			//a_s[i].removeAttribute("href");
			a_s[i].href = a_s[i].href+symb+'prn=print';
		}
	}
}


function go(url) {
	if (window.opener) {
		window.close()
		window.opener.location.href = url;
	} else {
		parent.window.document.getElementById('okno').style.display='none';
		parent.window.location.href = url;
	}
}

function alt_title() {
	var imgs = d.getElementsByTagName("IMG");
	for (var i=0, len=imgs.length; i<len; i++) {
		imgs[i].title = imgs[i].alt;
	}			
}
