// Lazy load
/*$(function() {          
  $("img").lazyload({
	 effect      : "fadeIn",
	failurelimit : 1000
  });
});
*/
//Statistic for first page spec offers
	// Spec-offers statistic : onload img
	$(function() {          
          var values = '';
		  $(".getStat").each(function(index) {
             if($(this).attr('param')!='')
			 {
			 	values = values + $(this).attr('param')+';';
			 }
          });
		  if(values!='') { wrDb(values,'/show/'); }
      });
	
	// Spec-offers statistic : onload img
	$(function() {          
          
		  $("li.getStat:[obj='oth']").click(function() {
			 if($(this).attr('param')!='')
			 {
				wrDb($(this).attr('param'),'/click/');
			 }
          });
		 
      });

function wrDb(str, action)
{
	$.ajax({
		url: "/spec_stat"+action,
		cache: false,
		type: "POST",
		data: "type="+str,
		success: function (data) {
			
		}
	});	
}


$(document).ready(function() {
    $("#menutop li:last").css({background:'none'});
    $("#userpanel li:last").css({background:'none'});
    $('#menutop ul').each(function(index) {
        $(this).children('li:last').css({background:'none'});
     });
    $("#menufooter ul li:last").addClass("lastli");
    $(".righthead ul li:last").addClass("lasthb");
    $("#menuside >  li:last").css({background:'none'});
    $('#menuside ul').each(function(index) {
        $(this).children('li:last').css({background:'none'});
     });
    



    // button hover
    $('button').hover(function(){
        $(this).addClass('buttonhover');
    },
    function(){
        $(this).removeClass('buttonhover');
    });
    // button click
    $('button').click(function(){
        $(this).addClass('buttonhover_click');
    },
    function(){
        $(this).removeClass('buttonhover_click');
    }); 
    // offers in head
    $('.hb5 li a').hover(function(){
        $(this).children('#popup').fadeIn(220);
    },
    function(){
        $(this).children('#popup').fadeOut(20);
    }); 
    
    // print page show image
    $('span.turn_on').click(function(){
        $(this).hide().siblings('.turn_off').show().parents('b').siblings('div.hide').show();
    });
    $('span.turn_off').click(function(){
        $(this).hide().siblings('.turn_on').show().parents('b').siblings('div.hide').hide();
    });

    // Regulate the input value: 'from - to' when 'focus - blur'
    $('input[type="text"]').focus(function() { 
            var value = $(this).attr('value');
            var defvalue = $(this).attr('defvalue');
            if(value == defvalue) $(this).attr('value','');
    }); 
    $('input[type="text"]').blur(function() {  
            var value = $(this).attr('value');
            var defvalue = $(this).attr('defvalue');
            if(value == '') $(this).attr('value',defvalue);
    });
    
    // Show|hide expand search on estate searching pages
    $('.expandsearch #expand').click(function() {
        $(this).next('#expandsearchtable').slideToggle(100).css({display:'block'});
    });
    
    // Show|hide tooltips on estate searching pages
    $('.tooltipshow').click(function() {
        $('li.tooltipcorner:visible').fadeOut(250).siblings('li.tooltipcontent').fadeOut(250);
        $(this).siblings('li.tooltipcorner').fadeIn(250).siblings('li.tooltipcontent').fadeIn(250);
    });
    $('.tooltipsclose').click(function() {
        $('li.tooltipcontent').fadeOut(250).siblings('li.tooltipcorner').fadeOut(250);;
    });
    
    $(document).click(function(event){      
		var target = $(event.target);
		if (target.parents("ul").children("li.tooltipcorner").length == 0) {    
		$('li.tooltipcontent').fadeOut(250).siblings('li.tooltipcorner').fadeOut(250);
		}
    });
    
    
    // estate offers change pics
    $('.estateoffer_photo > ul > li > img').click(function(){
        $('.estateoffer_photo_ship').hide();
        $(this).siblings('.estateoffer_photo_ship').show();
        $('.estateoffer_photo_main_pic').children('img').hide().attr({'src':$(this).attr('src'), 'pos':$(this).attr('pos')}).fadeIn(400);
    });
	
	// KONKURS //
	
	$('.voting_d > div.rubric_title').click(function(){
		 $(this).children('span').toggleClass('nodashed');
		 $(this).next('div').children('ul').slideToggle();
	 });
	
	$('.vote_button > li ').click(function(event){
		var cat = $(this).attr('cat');
		var pos = $(this).attr('pos');
	
		var o = getOffsetSum(this)
		var orect = getOffsetRect(this)
		
		event = event || window.event
		if ( event.pageX == null && event.clientX != null ) {
			var html = document.documentElement, body = document.body;
			event.pageX = event.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
			event.pageY = event.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
		}	
		
		$.ajax({
			url: "/doverie_potrebitelya/vote/",
			cache: false,
			type: "POST",
			data: "cat="+cat+"&pos="+pos,
			success: function (data) {
				if(data > 0) { 
					$('.vote_complete').css({'top':o.top, 'margin-left':'15px', 'margin-top':'3px'}).show().fadeIn(2000).fadeOut(3000);
					$("li:[cat='"+cat+"'] > button").fadeOut(200).text(''); 
				}
				
			}
		});	
	});


     // button hover
    $('.vote_button > li').hover(function(){
        if($(this).children('button').text()!='')
		{
			$(this).css({background:'#c4d7fd', cursor:'pointer'});
		}
    },
    function(){
        $(this).css({background:'#ffffff', cursor:'default'});;
    });

});


// Show's Google map on offer's page
function loadEstateMap(lat, lng) {
	if (GBrowserIsCompatible()) {
		
		var map = new GMap2(document.getElementById("map"));
		map.removeMapType(G_SATELLITE_MAP);
		point = new GLatLng(lat,lng);
		map.setCenter(point, 15);
		
        var customUI = map.getDefaultUI();
        customUI.maptypes.hybrid = false;
        customUI.zoom.scrollwheel = false;
        map.setUI(customUI);
		
		iconBlue = new GIcon();
		iconBlue.image = '/img/kpal.png';
		iconBlue.shadow = '/img/kpal_sh.png';
		iconBlue.iconSize = new GSize(27, 47);
		iconBlue.shadowSize = new GSize(52, 45);
		iconBlue.iconAnchor = new GPoint(14, 51);
		iconBlue.infoWindowAnchor = new GPoint(15, 1);
	
		marker = new GMarker(point, iconBlue);
		map.addOverlay(marker);
	
		var mapControl = new GMapTypeControl();
			
		
		map.addControl(mapControl);
   }
}


function showAdrCounter()
{
    var RndNum4NoCash = Math.round(Math.random() * 1000000000);
    var ar_Tail='unknown'; if (document.referrer) ar_Tail = escape(document.referrer);
    document.write('<sc' + 'ript language="JavaScript" type="text/javascript" src="http://ad.adriver.ru/cgi-bin/erle.cgi?sid=53412&target=blank&bt=16&pz=0&rnd=' + RndNum4NoCash + '&tail256=' + ar_Tail + '"><\/sc' + 'ript>');
}

function noerror_mail()
{
    var l;
    
    l = document.news_attach.user_email.value;
    
    if((l.indexOf('@', 0) == -1) || (l.indexOf('.', 0) == -1) || (l.length <= 4) || (l.indexOf(' ', 0) != -1))
    {
        alert("Поле 'E-mail' пустое или заполнено некорректно");
        return false;
    }
                    
    return true;
}

function ar_flver(){
 var d, n = navigator, m, f = 'Shockwave Flash';
 if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
 else if (window.ActiveXObject) { try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {}} 
 return d ? d.replace(/\D+/,'').split(/\D+/) : [0,0];
};

function showMailCounter()
{
<!--Rating@Mail.ru counter-->
d=document;var a='';a+=';r='+escape(d.referrer);js=10;
a+=';j='+navigator.javaEnabled();js=11;
s=screen;a+=';s='+s.width+'*'+s.height;
a+=';d='+(s.colorDepth?s.colorDepth:s.pixelDepth);js=12;
js=13;
d.write('<a href="http://top.mail.ru/jump?from=92695" target="_top">'+
'<img src="http://da.c6.b1.a0.top.mail.ru/counter?id=92695;t=132;js='+js+
a+';rand='+Math.random()+'" alt="" border="0" '+
'height="40" width="88" \/><\/a>');if(11<js)d.write('<'+'!-- ');

if(11<js)d.write('--'+'&#062');
<!--// Rating@Mail.ru counter-->
}

function showLiveInternetCounter()
{
    document.write("<a href='http://www.liveinternet.ru/click' "+
    "target=_blank><img src='//counter.yadro.ru/hit?t14.11;r"+
    escape(document.referrer)+((typeof(screen)=="undefined")?"":
    ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
    screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
    ";"+Math.random()+
    "' alt='' title='LiveInternet' "+
    "border='0' width='88' height='31'><\/a>")
}

function sortBy(field)
{
    if(field!=undefined)
    {
        $("form:[name='hids']").append('<input type="hidden" name="field" value="'+field+'"/>');
    }
}


/* ============= table hover ============== */


// Adriver Ajax code
function debug(){}

function adriver (ph, prm, defer) {  
    try {
        this.ph = ph; 
        this.prm = {};
        for (var i in this.defaults) this.prm[i] = this.defaults[i];
        for (var i in prm) this.prm[i] = prm[i];
        for (var i in this.prm) this.req += i + "=" + this.prm[i] + "&";
        if(!adriver.items){ 
            adriver.items = {};
            this.addHandlers();
            this.checkFlash();
        }
        this.p = document.getElementById(ph);
        this.p.adriver = this;
        adriver.items[ph] = this;
        defer || this.load(); 
    }catch(e){}
}

adriver.prototype.ver = "1.1";
adriver.prototype.flashVer = [0];
adriver.prototype.domReady = false;
adriver.prototype.handlers = [];
adriver.prototype.defaults = {tail256: (document.referrer ? escape(document.referrer) : 'unknown')};
adriver.prototype.h = document.getElementsByTagName("head").item(0);
adriver.prototype.req = "http://ad.adriver.ru/cgi-bin/erle.cgi?";

        
adriver.prototype.loadScript = function(req, m){ //m - flag. set when loading from mirror
try {
        m || (req += "ph=" + this.ph + "&rnd=" + Math.round(Math.random()*10000));
        var s = document.createElement("script");
        s.setAttribute("type", "text/javascript");
        s.setAttribute("charset", "windows-1251");
        s.setAttribute("src", req);
        this.s = s;
        this.h.insertBefore(s, this.h.firstChild); 
    }catch(e){}
}

adriver.prototype.detachScript = function (){ try{ this.h.removeChild(this.s) }catch(e){}}

adriver.prototype.load = function (){   try{ this.loadScript(this.req) }catch(e){}}

adriver.prototype.onDomReady = function (f) {try{ this.domReady ? f() : this.handlers.push(f) }catch(e){}}


/************ dom ready state check **********************/

adriver.prototype.runHandlers = function(old_handler){
    try {
        if (old_handler){old_handler() }
        if (!this.domReady){
            adriver.prototype.domReady = true;
            var f; while (f = this.handlers.shift()) f();
        }
    }catch(e){}
}

adriver.prototype.addHandlers = function(){
    try {
        var d = document, t = this, safariTimeout;

        if (/WebKit/i.test(navigator.userAgent)) {
            safariTimeout = setInterval(function(){if (/loaded|complete/.test(d.readyState)) {clearInterval(safariTimeout); t.runHandlers() }}, 100);
        } else if (d.addEventListener) {
            d.addEventListener("DOMContentLoaded", function(){t.runHandlers()}, false);
        } else if (d.all && !window.opera) {
            var s = d.createElement("script");
            s.setAttribute("type", "text/javascript");
            s.setAttribute("src", "");          
            s.setAttribute("defer", "true");
            s.onreadystatechange = function(){if (this.readyState == "complete") t.runHandlers()} 
            this.h.insertBefore(s, this.h.firstChild); 
        }
        var old_handler = window.onload;
        window.onload = function(){t.runHandlers(old_handler)};
    } catch (e){}
}


adriver.prototype.checkFlash = function(req){
    debug("checking flash");
    try {
        if (req) return (this.flashVer[0] >= req);

        var d, n = navigator, m, f = 'Shockwave Flash';
        if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
        else if (window.ActiveXObject) { debug ("activeX flash detect"); try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {debug ("error in activeX detection")}} 
        debug ("version obj: " + d);
        if (d) adriver.prototype.flashVer = d.replace(/\D+/,'').split(/\D+/);
    
        debug ("flash " + this.flashVer + " detected");
    } catch (e){}
    return false;
}

//============optional components=================//

adriver.prototype.setAnchor = function (){this.anchor = this.addDiv(this.p, {position:"relative"});}

adriver.prototype.addPanel = function (id, params, inner, holder){ 
    debug("add panel" + id);
    var panel = null;
    try {
        if (!this.panels){
            this.panels = {};
        }
        panel = this.addDiv(holder || this.anchor, params, inner)
        this.panels[id] = panel;
    }catch(e){}
    return panel;
}

adriver.prototype.addDiv = function (o, params, inner){
    var n = null;
    try {
        n = document.createElement("DIV");
        for (var i in params){ n.style[i] = params[i] } 
        if (inner) n.innerHTML = inner;
        o.insertBefore(n, o.firstChild); 
    }catch(e){}
    return n;
}

function adriver_dispatcher(ph, panel, command, arg){
    debug("dispatching " + command + ": " + arg + " to " + ph + "." + panel);
    try {
        var a = adriver.items[ph];
        if (a && a.dispatch) a.dispatch(panel, command, arg);
    } catch (e) {}
}

// End of Adriver Ajax code

// ***************** dither cjeck_all block *********** //
function gototheselectedsuperflats(printuri)
{
    if(document.checkeds.length == 0)
    {
        alert('Вы не выбрали ни одного варианта');
    }
    else
    {
        sendCheckeds();
        document.hids.target='_blank';
        document.hids.action = printuri;
        document.hids.submit()
    }
}


function DiTHER_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=DiTHER_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}

document.checkeds = new Array();

function testChecks()
{
    allchecked = true;
    for(i=0;i<document.allcheckeds.length;i++)
    {
        thisexist = false;
        for(i2=0;i2<document.checkeds.length;i2++)
        {
            if(document.checkeds[i2] == document.allcheckeds[i]) thisexist = true;
        }
        if(!thisexist) allchecked = false
    }
    if(allchecked)
    {
        if(DiTHER_findObj('topCheckAll')!=null) {DiTHER_findObj('topCheckAll').checked = true;}
        if(DiTHER_findObj('bottomCheckAll')!=null) {DiTHER_findObj('bottomCheckAll').checked = true;}
    } else {
            if(DiTHER_findObj('topCheckAll')!=null) {DiTHER_findObj('topCheckAll').checked = false;}
            if(DiTHER_findObj('bottomCheckAll')!=null) {DiTHER_findObj('bottomCheckAll').checked = false;}
        }
}

// adding previusly checks (from postdata) to checkeds
function addPrevCheckeds()
{
    document.checkeds = document.hids.checks.value.split(',');
    if(document.checkeds == '')
    {
        document.checkeds = new Array();
    }
}

// adds current id to ids array
function addChecked(cl)
{
    if(cl.checked)
    {
        document.checkeds.push(cl.name);
    }
    else
    {
        for(i=0;i<document.checkeds.length;i++)
        {
            if(document.checkeds[i] == cl.name)
            {
                document.checkeds.splice(i,1);
            }
        }
    }
    testChecks();
}

//set all checkeds to postdata in form
function sendCheckeds()
{
    document.hids.checks.value = document.checkeds;
}


function addAllCheckeds(cl)
{
    if(cl.checked)
    {
        for(i=0;i<document.allcheckeds.length;i++)
        {
            exist = false;
            for(i2=0;i2<document.checkeds.length;i2++)
            {
                if(document.checkeds[i2] == document.allcheckeds[i]) exist = true;
            }
            if(!exist) document.checkeds.push(document.allcheckeds[i]);

            DiTHER_findObj('ch'+document.allcheckeds[i]).checked = true;
        }
        testChecks();
    }
    else
    {
        for(i=0;i<document.allcheckeds.length;i++)
        {
            for(i2=0;i2<document.checkeds.length;i2++)
            {
                if(document.checkeds[i2] == document.allcheckeds[i])
                {
                    document.checkeds.splice(i2,1);
                }
            }
            DiTHER_findObj('ch'+document.allcheckeds[i]).checked = false;
        }
        testChecks();
    }
}

function str_replace ( search, replace, subject ) { // Replace all occurrences of the search string with the replacement string
    // 
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni

    if(!(replace instanceof Array)){
        replace=new Array(replace);
        if(search instanceof Array){//If search is an array and replace is a string, then this replacement string is used for every value of search
            while(search.length>replace.length){
                replace[replace.length]=replace[0];
            }
        }
    }

    if(!(search instanceof Array))search=new Array(search);
    while(search.length>replace.length){//If replace    has fewer values than search , then an empty string is used for the rest of replacement values
        replace[replace.length]='';
    }

    if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
        for(k in subject){
            subject[k]=str_replace(search,replace,subject[k]);
        }
        return subject;
    }

    if(search.length > 0)
    {
    for(var k=0; k<search.length; k++){
        if(subject != undefined)
        {
        var i = subject.indexOf(search[k]);
        while(i>-1){
            subject = subject.replace(search[k], replace[k]);
            i = subject.indexOf(search[k],i);
        }
        }
    }
    }

    return subject;

}
// Список операторов для оплаты через смс
function show_operators()
{  
    var head     = document.getElementById('sms_operator');
  for(i=0;i<jsonSMS.country[0].Operators.length; i++)
  {     
        var name = jsonSMS.country[0].Operators[i];
    if((typeof name.Numbers[7]) != "undefined" && (name.Name == 'МТС' || name.Name == 'Мегафон' || name.Name == 'TELE2' || name.Name == 'BEE LINE'))
        {
            
            for(k=0;k<name.Numbers.length; k++)
            {
                if(name.Numbers[k].Number == '9691')
                {
                    operatorList=document.createElement('span');
                    var cost = Math.round(name.Numbers[k].CostLocal*0.0118*100)/100;
                    operatorList.innerHTML = '<b> '+name.Name+'</b> - стоимость: <b>'+cost+'</b> руб.; ';
                    head.appendChild(operatorList)
                }
            }
            
        }
    }
}

// Список операторов для оплаты через смс
function show_operators_4445()
{
        var head     = document.getElementById('sms_operator');
  for(i=0;i<jsonSMS.country[0].Operators.length; i++)
  {
                var name = jsonSMS.country[0].Operators[i];
        if((typeof name.Numbers[7]) != "undefined" && (name.Name == 'МТС' || name.Name == 'Мегафон' || name.Name == 'TELE2' || name.Name == 'BEE LINE'))
                {

                        for(k=0;k<name.Numbers.length; k++)
                        {
                                if(name.Numbers[k].Number == '4445')
                                {
                                        operatorList=document.createElement('span');
                                        var cost = Math.round(name.Numbers[k].CostLocal*0.0118*100)/100;
                                        operatorList.innerHTML = '<b> '+name.Name+'</b> - стоимость: <b>'+cost+'</b> руб.; ';
                                        head.appendChild(operatorList)
                                }
                        }

                }
        }
}

function ar_flver(){
 var d, n = navigator, m, f = 'Shockwave Flash';
 if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
 else if (window.ActiveXObject) { try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {}} 
 return d ? d.replace(/\D+/,'').split(/\D+/) : [0,0];
};

function showimg(src,w,h,ptitle)
{
    cw = w+40;
    ch = h+40;
    newin = window.open("","viewimg", "dependent=yes,width="+cw+",height="+ch+",screenX=100,screenY=100, scrollbars=yes");

    newin.document.write("<html><head><title>"+ptitle+"</title></head><body><img src=\""+src+"\" width=\""+w+"\" height=\""+h+"\"/></body></html>");
    newin.document.close();
}
function createLink(link, display, style_class)
{
    var link_full = "<a href = '"+link+"' class = '"+style_class+"'>"+display+"</a>";
    document.getElementById('span_link').innerHTML = link_full;
}

function createLinkBlank(link, display, style_class)
{
    var link_full = "<a href = '"+link+"' class = '"+style_class+"' target='_blank'>"+display+"</a>";
    document.getElementById('span_link').innerHTML = link_full;
}

function createLinkBlankv1(link, display, style_class, pos)
{
    var link_full = "<a href = '"+link+"' class = '"+style_class+"' target='_blank'>"+display+"</a>";
    document.getElementById('span_link'+pos).innerHTML = link_full;
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

function pre_submit_v1()
{
	if(document.mainform.title_ru.value.length > 0 && document.mainform.code_auth.value.length > 0 && document.mainform.phone_1.value.length > 0 && document.mainform.pub_mail.value.length > 0)    	
	{
		if(checkerror(document.mainform.title_ru) && (document.mainform.code_auth.value == document.mainform.code.value) && checkerror(document.mainform.phone_1) && checkerror(document.mainform.pub_mail))
	    		document.mainform.submit();	
		else
	    		alert("Поля заполнены некорректно!");	    		
	}
    	else
    		alert("Все поля обязательны к заполнению!");
}    

function pre_submit()
{
	if(document.mainform.title_ru.value.length > 0 && document.mainform.addr.value.length > 0)    	
	{
		if(checkerror(document.mainform.title_ru) && checkerror(document.mainform.addr))
	    		document.mainform.submit();	
		else
	    		alert("Обязательные поля заполнены некорректно!");
	}
    	else
    		alert("Поля отмечанные звездочкой обязательны к заполнению!");
}


var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

	

function mover(num) {

	var head     = document.getElementById('on'+num);
	if(is_ie)
	{
		head.style.display = 'none';
		head.style.width = '0px';
		head.style.overflow = 'hidden';
	}
	else
	{
		head.setAttribute('style','display:none; width:0px; overflow:hidden');
	}

	var head1     = document.getElementById('off'+num);
	if(is_ie)
	{
		$('tr#off'+num).css({display:'block', clear:'left', width:'100%'});
	}
	else
	{
		head1.setAttribute('style','clear:left;');
	}

}

function mout(num)
{
	 var head     = document.getElementById('on'+num);
	
	if(is_ie)
	{
		head.style.display = 'block';	
	}
	else
	{
		head.setAttribute('style','clear:left;');
	}
	var head1     = document.getElementById('off'+num);
	if(is_ie)
	{
		head1.style.display = 'none';
		head1.style.width = '0px';
		head1.style.overflow = 'hidden';
	}
	else
	{
		head1.setAttribute('style','display:none; width:0px; overflow:hidden');
	}

}

    // Table hover
    $('.dtable tr').hover(function(){
        if($(this).attr('id')=='') $(this).children('td').addClass('bgblue');
    },
    function(){
        if($(this).attr('id')=='')$(this).children('td').removeClass('bgblue');
    });


function showMap(mmp,w,h,type)
{
	cw = w+20;
	ch = h+20;
	newin = window.open("","viewmap", "dependent=yes,width="+cw+",height="+ch+",screenX=100,screenY=100");

	if(type == 'photo')
	{
		titl = 'Просмотр фотографии';
	}
	else if(type == 'plan')
	{
		titl = 'Просмотр планировки';
	}
	else if(type == 'map')
	{
		titl = 'Просмотр карты';
	}

	newin.document.write("<html><head><title>"+titl+"</title></head><body><img src=\""+mmp+"\" width=\""+w+"\" height=\""+h+"\"/></body></html>");
}


function getOffset(elem) {
    if (elem.getBoundingClientRect) {
        // "правильный" вариант
        return getOffsetRect(elem)
    } else {
        // пусть работает хоть как-то
        return getOffsetSum(elem)
    }
}

function getOffsetSum(elem) {
    var top=0, left=0
    while(elem) {
        top = top + parseInt(elem.offsetTop)
        left = left + parseInt(elem.offsetLeft)
        elem = elem.offsetParent
    }

    return {top: top, left: left}
}

function getOffsetRect(elem) {
    // (1)
    var box = elem.getBoundingClientRect()

    // (2)
    var body = document.body
    var docElem = document.documentElement

    // (3)
    var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop
    var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft

    // (4)
    var clientTop = docElem.clientTop || body.clientTop || 0
    var clientLeft = docElem.clientLeft || body.clientLeft || 0

    // (5)
    var top  = box.top +  scrollTop - clientTop
    var left = box.left + scrollLeft - clientLeft

    return { top: Math.round(top), left: Math.round(left) }
}