var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers


function popup(url,w,h,sb)
{

	atr = '';
	atr = atr + 'toolbar=no,';
	if (sb)
	{
		atr = atr + 'scrollbars=no,';
	}
	else
	{
		atr = atr + 'scrollbars=yes,';
	}
	atr = atr + 'location=no,';
	atr = atr + 'statusbar=no,';
	atr = atr + 'menubar=no,';
	atr = atr + 'resizable=no,';
	atr = atr + 'status=no,';
	atr = atr + 'toolbar=no,';
	atr = atr + 'menubar=no,';
	if (w) {
	atr = atr + 'width='+w+',';
	atr = atr + 'height='+h+',';
	}
	else{
	atr = atr + 'width=700,';
	atr = atr + 'height=700,';
	}
	atr = atr + ' left='+String((screen.width-w)/2)+', top='+String((screen.height-h)/2);
	new_window=window.open(url,'_blank',atr);
	new_window.focus();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function isValidEmail(emailStr) {
	// checks if the e-mail address is valid
//	was
//	var emailPat = /^(\".*\"|[A-Za-z0-9]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;		//	"
	var emailPat = /^(\".*\"|[A-Za-z0-9\.\-_]*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z\-_]*(\.[A-Za-z\-_]*)+)$/;		//	"
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {
		//alert("Your email address seems incorrect.  Please try again (check the '@' and '.'s in the email address)");
		return false;
	}
	return true;
}




function get_radio_value(object_name)	{
//	достает значение radiobutton'a,  если не выбрано - вернет undefined
	tmp_value = 'undefined';
	my_object=MM_findObj(object_name);
	num = my_object.length;
	for( var i = 0; i < num; i++ ) {
		if( my_object[ i ].checked == '1' ) {
			tmp_value = my_object[ i ].value;
		}
	}
return(tmp_value);
}


function NumbersOnly() {
	if (window.event) code=event.keyCode;
	else code=event.charCode;
	//else code= e.which;
	//alert(e.which);	
	//if (event.keyCode<48||event.keyCode>57) return false;
	if ((code<48||code>57)&&(code!=46)) return false;
	else return true;
}



function update_journal(object_name){
//	function for subscribe for impressmedia
	value1 = MM_findObj(object_name).checked;
	if (value1)	value2=false; else value2=true;
	//	window.alert(object_name);
	//	window.alert(value);

	MM_findObj(object_name+'_month').disabled = value2;
	MM_findObj(object_name+'_year').disabled = value2;
	MM_findObj(object_name+'_period').disabled = value2;

	num = MM_findObj(object_name+'_count').value;
	for (i=1; i<=num; i++ )	{
		MM_findObj(object_name+'_special['+i+']').disabled = value2;
	//	window.alert(MM_findObj(object_name+'_special['+i+']').checked);
	}
}




function show_nl(news_id)	{
	tmpobj = MM_findObj('ndata_'+news_id);
	if (tmpobj != null)	tmpobj.style.display=	'inline';
	
	tmpobj = MM_findObj('hide_'+news_id);
	if (tmpobj != null)	tmpobj.style.display	=	'inline';
	
	tmpobj = MM_findObj('more_'+news_id);
	if (tmpobj != null)	tmpobj.style.display	=	'none';
}

function hide_nl(news_id)	{
	tmpobj = MM_findObj('ndata_'+news_id);
	if (tmpobj != null)	tmpobj.style.display=	'none';

	tmpobj = MM_findObj('hide_'+news_id);
	if (tmpobj != null)	tmpobj.style.display	=	'none';

	tmpobj = MM_findObj('more_'+news_id);
	if (tmpobj != null)	tmpobj.style.display	=	'inline';
}



function metro (action, show_name, checkbox_name, text_name)	{
	if (action == 'show') {
		tmpobj = MM_findObj(show_name);
		if (tmpobj != null)	tmpobj.style.display=	'inline';
	}
	
	if (action == 'hide') {
		tmpobj = MM_findObj(show_name);
		if (tmpobj != null)	tmpobj.style.display=	'none';
		////	+ вывести список выбранных станций в div id="station_text"

		tmpobj = MM_findObj(checkbox_name);
		if (tmpobj != null)	{
			total = tmpobj.length;
			display = '';
			for( var i = 0; i < total; i++ ) {
				if( tmpobj[ i ].checked == true ) {
					display = display + ', ' + tmpobj[ i ].title;
				}
			}
			display = display.substring(2);
			if (display=='') display='не указано';
			tmpobj = MM_findObj(text_name);
			if (tmpobj != null)	tmpobj.innerHTML = display;
		}
	}
}




function okrug (action)	{
	if (action == 'show') {
		tmpobj = MM_findObj('okrug');
		if (tmpobj != null)	tmpobj.style.display=	'inline';
	}
	
	if (action == 'hide') {
		tmpobj = MM_findObj('okrug');
		if (tmpobj != null)	tmpobj.style.display=	'none';
	}
}


function photogalleries (action)	{
	if (action == 'show') {
		tmpobj = MM_findObj('photogalleries');
		if (tmpobj != null)	tmpobj.style.display=	'inline';
	}
	
	if (action == 'hide') {
		tmpobj = MM_findObj('photogalleries');
		if (tmpobj != null)	tmpobj.style.display=	'none';
	}
}


function img_popup(img)	{
	atr = '';
	atr = atr + 'scrollbars=no,';
	atr = atr + 'location=no,';
	atr = atr + 'statusbar=yes,';
	atr = atr + 'menubar=no,';
	atr = atr + 'status=yes,';
	atr = atr + 'toolbar=no,';
	atr = atr + 'resizable=no,';
	atr = atr + 'width=300,';
	atr = atr + 'height=300,';
	atr = atr + ' left=150, top=150';

	html = '<html><head><title></title></head><body style="margin:0 0 0 0;" bgcolor="#FFFFFF"><script>function fit_img(w,h,img){ window.resizeTo(w+10,h+49);window.status=" ";}</script><div id="r1"><img src="'+img+'" alt="закрыть окно" border=0 onClick="window.close(self)" style="cursor:hand;" id="img" onload="fit_img(this.width, this.height, this);"></div></body></html>';

	win=window.open('','',atr);
	win.document.write(html);
	win.focus();
	return(false);
}


function img_popup_scroll(img)	{
	atr = '';
	atr = atr + 'scrollbars=yes,';
	atr = atr + 'location=no,';
	atr = atr + 'statusbar=yes,';
	atr = atr + 'menubar=no,';
	atr = atr + 'status=yes,';
	atr = atr + 'toolbar=no,';
	atr = atr + 'resizable=no,';
	atr = atr + 'width=300,';
	atr = atr + 'height=300,';
	atr = atr + ' left=150, top=150';

	html = '<html><head><title></title></head><body style="margin:0 0 0 0;" bgcolor="#FFFFFF"><script>function fit_img(w,h,img){ window.resizeTo(w+10,h+49);window.status=" ";}</script><div id="r1"><img src="'+img+'" alt="закрыть окно" border=0 onClick="window.close(self)" style="cursor:hand;" id="img" onload="fit_img(this.width, this.height, this);"></div></body></html>';

	win=window.open('','',atr);
	win.document.write(html);
	win.focus();
	return(false);
}

function write_flash(file, width, height, url) {
	var str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="'+width+'" height="'+height+'">';
	str+='<param name="quality" value="high">';
	str+='<param name="wmode" value="opaque">';
	str+='<param name="Movie" value="'+file+'">';
	str+='<param name="Src" value="'+file+'">';
	str+='<param name="AllowNetworking" value="all">';
	str+='<param name="AllowFullScreen" value="false">';
	str+='<embed src="'+file+'" menu="false" width="'+width+'" height="'+height+'" align="center" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="opaque"></embed>';
	str+='</object>';
	document.write(str);
}

function catchKey(event) {
	if(window.event)
			event=window.event;
	if(event.ctrlKey && event.keyCode==13 || event.keyCode==10) {
			if(document.getSelection || document.selection.createRange().text){
				 if(document.getSelection && !document.getSelection().length) return;
					window.open("/mistake/","SendMistake","width=450,height=350,top=300,left=450");
			}
	}
}


function nz_rotate(el_array, time, curr){
	// сколько всего
	total = el_array.length;

	//	счетчик
	if (curr == undefined) {
		curr=total-1;
	}

	// текущий делаем невидимым
	myobj = MM_findObj(el_array[curr]);
	if (myobj != null)	myobj.style.display	=	'none';

	// увеличиваем счетчик
	curr  = curr + 1;
	// корректировка счетчика
	if (curr >= total)	curr = 0;

	//	показываем следующий
	myobj = MM_findObj(el_array[curr]);
	if (myobj != null)	myobj.style.display	=	'inline';

	//	зацикливаем
	setTimeout(function(){nz_rotate(el_array, time, curr)}, time);
}


function Checkbox_To_Div(checkbox_id, div_id) {
	tmpobj = MM_findObj(checkbox_id);
	if (tmpobj != null)	{
		total = tmpobj.length;
		display = '';
		for( var i = 0; i < total; i++ ) {
			if( tmpobj[ i ].checked == true ) {
				display = display + ', ' + tmpobj[ i ].title;
			}
		}
		display = display.substring(2);
		if (display=='') display='не указано';
		tmpobj = MM_findObj(div_id);
		if (tmpobj != null)	tmpobj.innerHTML = display;
	}
}


function Checkbox_Init(checkbox_id, value_txt) {
	if (value_txt=='') return;
	
	ids = value_txt.split(',');
	num = ids.length;
	
	tmpobj = MM_findObj(checkbox_id);
	if (tmpobj != null)	{
		total = tmpobj.length;
		display = '';
		for( var i = 0; i < total; i++ ) {
			
			for(j=0; j<num; j++) {
				val = tmpobj[i].value;
				if (val==ids[j])	{
					tmpobj[ i ].checked = true;
				}
			}
		}
	}
}


