function findPos(id,elw,elh,no_handlers){__id=((typeof id=='string')?id:"txt_block")
var elem=$id(__id);var d_height
var d_width
try{if(document.body.clientHeight){d_height=document.body.clientHeight
d_width=document.body.clientWidth}else{d_height=document.body.offsetHeight
d_width=document.body.offsetWidth}}catch(e){}
if(!elw&&!elh){elw=800
elh=550}
show('overgray');gray=$id('overgray');gray.style.top=document.body.scrollTop+"px"
show(elem);document.body.className='gray_body'
document.body.style.overflow="hidden"
if(d_height<elh){elem.style.height=d_height+'px'
d_height=document.body.scrollTop;}else{d_height=((d_height-elh)/2)+document.body.scrollTop;elem.style.height=elh+'px'}
d_width=(d_width-elw)/2
elem.style.display="block"
elem.style.top=d_height+"px"
elem.style.left=d_width+"px"
if(!no_handlers){window.onscroll=function(){findPos(id,elw,elh);}
window.onresize=function(){findPos(id,elw,elh);}}}
function sendMetroRequest(e){$('#metro').hide();if(typeof window.load_metro!=='object'){window.load_metro={};}
var tid=(e.tagName=='SELECT')?e.options[e.selectedIndex].value:parseInt(e);if(window.towns_with_metro&&typeof window.towns_with_metro[tid]=='undefined'){if(window.load_metro.request){window.load_metro.request.abort();}
fillMetro('','metro_box');return false;}
var ajaxSettings={};ajaxSettings.global=false;ajaxSettings.cache=true;ajaxSettings.ifModified=true;$('#loadin').show();$.ajaxSetup(ajaxSettings);if(window.load_metro.request){window.load_metro.request.abort();}
window.load_metro.request=$.get('/js/request/metro.php?town='+tid,function(text){fillMetro(text,'metro_box');});}
function fillMetro(text,id){$('#loadin').hide();if(typeof MetroMap!=='undefined'){MetroMap.destroy();}
if(text!=""){$('#metro').show();show(id);text=eval('('+text+')');if(text.coordinates){window.coordinates=eval('('+text.coordinates+')');window.time_to_show_metro=false;}
if(text.text){$('#'+id).html(text.text);if($.browser.mozilla)
$('#'+id).toggle().toggle();}
if(typeof text.hasMap!='undefined'){if(text.hasMap==false){hide('watch_map');}else{show('watch_map');}}}else{$id(id).innerHTML="";hide("metro");hide(id);}}
function getIEVersionNumber(){var ua=navigator.userAgent;var offcet=ua.indexOf("MSIE ");if(offcet==-1){return false;}else{var num=parseFloat(ua.substring(offcet+5,ua.indexOf(";",offcet)));return(num<7);}}
TWindow=function(){this.is_ie=getIEVersionNumber()}
TWindow.prototype.unload=function(){this.unloaded=true;window.__id=null;window.onscroll=null;window.onresize=null;hide(this.id);hide('overgray');document.body.className=''
document.body.style.overflow="auto";if(this.is_ie){els=document.getElementsByTagName('SELECT')
for(i=0;i<=els.length;i++){show(els[i])}}
return false;}
TWindow.prototype.init=function(id,elw,elh){this.unloaded=false;this.id=id
this.el=$id(this.id)
if(!$id('closeit')){if(typeof window.metro_simple!='undefined'){this.el.style.paddingTop='15px';this.el.style.zIndex='150'}
ell=this.el;ell.innerHTML+='<div class="closeit"><a id="closeit" onClick="return TWindow.getInstance().unload();" href="#"><b>Закрыть окно [X]</b></a></div>';}
$id(this.id).style.width=elw+'px'
$id(this.id).style.height=elh+'px'
findPos(this.id,elw,elh)
findPos(this.id,elw,elh)
show(this.id)
if(this.is_ie){els=document.getElementsByTagName('SELECT')
for(i=0;i<=els.length;i++){hide(els[i])}}}
TWindow.getInstance=function(){if(!TWindow.instance){TWindow.instance=new TWindow();}
return TWindow.instance;}
