/* JavaScript file */

var oldregion=0;

if (window.screen.width>900) {var mode=1;} else {var mode=0;}

function adv(){
		if (screen.width<=800) {
			document.write ('<div align="left" style="margin-left:50px;"><a href="http://www.adv.ru" target="_blank"><img src="/images/internal/adv.gif" border="0" alt="сделано в ADV"/></a></div>')
			
		}
		if (screen.width>=1024) {
			document.write ('<!--<div align="left" style="margin-left:100px;">--><a href="http://www.adv.ru" target="_blank"><img src="/images/internal/adv.gif" border="0" align="right" alt="сделано в ADV"/></a><!--</div>-->')
		}
	}

function wfloat (target,size) {
var wWidth=400;
var wHeight=316;
var cWidth=window.screen.width;
var cHeight=window.screen.height;
if(cHeight && cWidth){
	var leftOffset=Math.ceil((cWidth-wWidth)/2);
	var topOffset=Math.ceil((cHeight-wHeight)/2);
	var size = size || 'width=678,height=590';
	var target = target || 'wfloat';
	openwnd ('',target,'width='+wWidth+',height='+wHeight+'location=no,toolbar=no,resizable=no,menubar=no,status=no,scrollbars=no,top='+topOffset+',left='+leftOffset);
 }
return false;
}

// mozg

function ShowThis(divid) {document.getElementById(divid).style.display="block";}
function HideThis(divid) {document.getElementById(divid).style.display="none";}

function Show(divid) {
	if (document.getElementById(divid).style.display=="none") {
		document.getElementById(divid).style.display="block";
	} else {
		document.getElementById(divid).style.display="none";
	}
}

function showRegion(id) {
	if (oldregion!=id) hideRegion(oldregion);
	if (id!=0)ShowThis('region'+id);
	oldregion=id;
}
function hideRegion(id) {
	if (id!=0) HideThis('region'+id);
}

function directShow (id)
{
	var i = 1;
	while (document.getElementById('info'+i) != null && document.getElementById('info'+i))
	{
		if (id == i)
		{ 
			//ShowThis('block'+i);
			ShowThis('arr'+i);
			ShowThis('act'+i);
			ShowThis('info'+i);
			//document.getElementById('title'+i).style.display = "bold";
		}
		else
		{
			//HideLayer('block'+i);
			HideThis('arr'+i);
			HideThis('act'+i);
			HideThis('info'+i);
			//document.getElementById('title'+i).style.display = "normal";
		}
		i++;
	}
}

function ShowMag(id) {
//alert (id);
directShow(id);
//ShowThis('arr'+id);
//ShowThis('act'+id);
//ShowThis('info'+id);
}
function HideMag(id) {
HideThis('arr'+id);
HideThis('act'+id);
HideThis('info'+id);
}


/*
function showZone (objid){
	if (current_zone) hideLayer(current_zone)
	current_zone = 'zone'+objid
	showLayer(current_zone)
}

function showCity (id){
	if (current_city) hideLayer(current_city)
	current_city = 'city'+objid
	showLayer(current_city)
}

function showLayer(divid) {
	//alert(divid);
	var obj = document.getElementById(divid)
// mozilla ? 
	obj.style.visibility = 'visible'
}

function hideLayer(divid) {
	var obj = document.getElementById(divid)
// mozilla ? 
	obj.style.visibility = 'hidden'
}*/


function Citate(title, name)
	{
		if(document.all.atestlink)
		{
			document.all.atestlink.focus();
		}
		else
		{
			var	cite_open='<CITE>';
			var	cite_close='</CITE>';
	
			var pref_open=title + ' написал(а): ' + cite_open;
			var pref_close=cite_close + '\n\n';
	
			var o=document.all.bbsm_description;
	
			if(document.getSelection)
			{
				var selection=document.getSelection();
			}
			else
			{
				var selection=document.selection.createRange().text;
			}
	
			if(selection!='') o.value=pref_open + selection + pref_close + o.value;
			else
			{
				o.value=pref_open + document.all["mes_" + name].innerText + pref_close + o.value;
			}
	
			o.focus();
		}
	}

function check_email(s)
{ flag=true;
	if (window.RegExp) {
		st="a";ex=new RegExp(st);
		if (st.match(ex)) {
			r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			r2=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
			b=(!r1.test(s)&&r2.test(s));
		} else { flag=false; }
	} else { flag=false; }
	if(!flag) b=(s.indexOf("@")>0&&s.indexOf(".")>0&&s!=""&&s!="Please, enter your e-mail");
	return (b);
}
function f(param) { param.focus();param.select(); }
function check(email)
{	if(val(email)) return true;
		else return false;
}
function val(param)
{	s=param.value;
	if(check_email(s)) { return true;
	} else {
		alert("Please, enter a valid e-mail address.");
		f(param);return false; }
}

function photo (url) {
	wnd = null;
	var url = url || '';
	var alt = alt || '';
	var width = width || 600;
	var height = height || 400;
	var size = 'width='+width+',height='+height;
	wnd = window.openwnd (url,'wfloat',size+'toolbar=no,menubar=no,scrollbars=no,status=no,resizable=no');
	wnd.document.open();
	wnd.document.write("<html><head><script>function resize(){");
	wnd.document.write("self.resizeTo (photo.width,photo.height); } onload=resize;");
	wnd.document.write("</script><title>Увеличенное изображение</title></head><body bottommargin=0 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src='"+url+"' alt='"+alt+"' border='0' vspace='0' hspace='0' id='photo'/><body></html>");
  wnd.document.close();
  
return false;
}

function show_img(a,name) 
{
	if (document.getElementById(name).src){
		document.getElementById(name).src = a;
	}
	
}


function validate_form(kanom) {
	if (!check_empty(document.form.kanom.value))
	{
		alert('Вы не ввели идентификационный номер!');
		return false;
	}
}

function check_empty(text) {
	return (text.length > 0);
}

function ShowHide(divid) {

                var d = document.getElementById("blockcity");
					var dc = d.getElementsByTagName("div");
					for (var i=0; i<dc.length; i++) {
						dc[i].style.display = "none";
					}
					document.getElementById(divid).style.display = "block";
}

var _cache = {};

function switchField(t, id) {
	var o = null;

	if( _cache[id] ) {
		o = _cache[id];
	} else {
		//o = document.getElementById(id);
		o = document.forms[0][id];
		o = o.parentNode;

		_cache[id] = o;
	}

	if( !o ) {
		return;
	}

	/*
	if( o.className.length ) {
		o.className = '';
	}
	*/

	o.style.display = ( t.checked ) ? '' : 'none';
}

function hideField(t, id) {
	var o = null;

	if( _cache[id] ) {
		o = _cache[id];
	} else {
		//o = document.getElementById(id);
		o = document.forms[0][id];
		o = o.parentNode;

		_cache[id] = o;
	}

	if( !o ) {
		return;
	}

	o.style.display = 'none'
}
