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 checkform(f)
{
	var errMSG = "";
		// цикл ниже перебирает все элементы в объекте f, переданном в качестве параметра функции, в данном случае - наша форма.
	for (var i = 0; i<f.elements.length; i++)
	{
		if (null!=f.elements[i].getAttribute("required"))			// если текущий элемент имеет атрибут required т.е. обязательный для заполнения
		{
			if (isEmpty(f.elements[i].value)) // проверяем, заполнен ли он в форме и если он пустой
			{
				errMSG += "  " + f.elements[i].id + "\n";			// формируем сообщение об ошибке, перечисляя  незаполненные поля
				if ("" != errMSG)		//если сообщение об ошибке не пусто, выводим его, и возвращаем false
				{
					alert("Не заполнены обязательные поля:\n" + errMSG);
					return false;
				}
			}
		}
	}
}

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();
		}
	}
}

var px = '';
if(isMozilla) {
	px = 'px';
}
function res() {
	var obj = layer('tb_td');
	document.getElementById('menu').style.left=obj.getAbsoluteLeft()+px;
	//document.getElementById('menu_h1').style.left=obj.getAbsoluteLeft()+px;
	//document.getElementById('menu_h2').style.left=obj.getAbsoluteLeft()+px;
	document.getElementById('searchblock').style.left=obj.getAbsoluteLeft()+obj.getWidth()-255+px;
	document.getElementById('map').style.left=obj.getAbsoluteLeft()+obj.getWidth()-125+px;
	/*
	if(isMozilla) {
		document.getElementById('stolswf').style.margin="-3px -1px -4px 0px";
		document.getElementById('map').style.top="559px";
		document.getElementById('searchblock').style.top="567px";
	}
	*/
	if (getWindowWidth() < 900)
	{
		document.getElementById('window_right').style.width = '330px';
	} else {
		document.getElementById('window_right').style.width = '391px';
	}
	document.body.style.visibility="visible";
	endTIME();
}

function pict(e) {
	var tb = document.getElementById('tb').style.backgroundImage;
	if (browser.isOpera)
	{
		var bg = 'url(\"'+tb.substr(5, tb.length - 11)+".jpg\")";
	} else {
		var bg = 'url(\"'+tb.substr(4, tb.length - 9)+".jpg\")";
	}
	document.getElementById('tb').style.backgroundImage = bg;
}

function time(e) {
	window.setTimeout('res()', 300);
}

addHandler(window, 'load', time);
addHandler(window, 'load', pict);
addHandler(window, 'resize', time);


function photo1(text) {
	var preview = window.open('','popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=690,height=530,screenX=150,screenY=150,top=150,left=150')
	preview.document.clear();
	preview.document.writeln("<html><head></head><body style='margin: 0;'>");
	preview.document.writeln("<img src='img/trans.gif' border='0' id='phpt' style='z-index: 100; border: 1px solid black; cursor: pointer; cursor: hand; width: 670px; height: 510px;' onclick='window.close();' alt='Закрыть фото' title='Закрыть фото'/>");
	preview.document.writeln("</body></html>");
	var obj=preview.document.getElementById('phpt');
	obj.style.background='url(\''+text+'\') 50% 50% no-repeat white';
	preview.focus();
	preview.document.close();
}


function splink(url) {
	if(isMozilla) {
		var aspan = document.getElementsByName('splink');
	} else {
		var aspan = document.all.tags('span');
	}
	for(i=0; i<aspan.length; i++) {
		var URL = aspan[i].getAttribute('url');
		if (URL) {
			var Text = aspan[i].innerHTML;
			aspan[i].innerHTML = '<a href="'+URL+'">'+Text+'</a>';
		}
	}
}
