function getHeight()
{
  var h = 600;
  if (window.innerHeight)
  {
    h = window.innerHeight;
  } 
  else if (document.body.clientHeight) h = document.body.clientHeight;
  return h;
}
function check_height()
{
  var h = getHeight();
  if (h>550)
  {
    document.write('<style type="text/css">#main {top:'+Math.ceil((h-550)/2)+'px; position:absolute; }</style>');
  }
}
function openPreview(src, w, h)
{
  tmpWindow = window.open("", "_popup", "width="+w+",height="+h+",status=no,toolbar=no,menubar=no");
  tmpWindow.document.open();  
  tmpWindow.document.write('<html><head><title>Агентство недвижимости "Теремки"</title></head><body style="background:#FFFFFF; margin:0px; padding:0px;"><img src=' + src + ' border="0" /></body></html>');
  tmpWindow.document.close();
}
function getPos(el)
{
  var r = { x: el.offsetLeft, y: el.offsetTop };
  if (el.offsetParent)
  {
    var tmp = getPos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}
var imgPos = null;
var last_info = null;
function fetch_info(id)
{
  div = document.getElementById('main_info');
  if (last_info) document.getElementById('info' + last_info).style.display = 'none';
  last_info = id;
  document.getElementById('info' + last_info).style.display = '';
  try {
  imgPos = getPos(document.getElementById('map'));
  div.style.left = (imgPos.x + 100) + 'px';
  div.style.top = (imgPos.y + 20) + 'px';
  }
  catch (e) {}
  div.style.display = '';

}
function close_info()
{
  div = document.getElementById('main_info');
  if (last_info) document.getElementById('info' + last_info).style.display = 'none';
  last_info = null;
  div.style.display = 'none';
}
function checkForm(frm, arr, txter)
{
  el = null;
  err = '';
  if (!txter) txter = 'Please fill in required fields';
  for(i in arr)
  {
    switch(frm.elements[i].type)
    {
      case 'text':
      case 'password':
        if (frm.elements[i].value == '')
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
    	break;
      case 'select-one':
        if (frm.elements[i].selectedIndex == 0)
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
    	break;
    }
  }
  if (err == '') return true;
  else
  {
    el.focus();
    alert(txter + ":\n-----------------------------------\n" + err + "-----------------------------------");
    return false;
  }
}
var home_fm_st = false;
function home_sf(el)
{
  home_fm_st = (el.options[el.selectedIndex].value == 1 || el.options[el.selectedIndex].value == 4);
  for(i=1; i<3; i++)
  {
  	document.getElementById('sf_tr_' + i).style.display = home_fm_st ? '' : 'none';
  	document.getElementById('sfa_tr_' + i).style.display = home_fm_st ? 'none' : '';
  }
  el.form.adv_ignore.value = home_fm_st ? '' : 'id_region2';
}
function home_sf_check(frm)
{
  focus_el = null;
  if (frm.id_operation.selectedIndex == 0)
  {
  	focus_el = frm.id_operation;
  }
  if (frm.id_category.selectedIndex == 0)
  {
  	focus_el = frm.id_category;
  }
  if (focus_el)
  {
    focus_el.focus();
    alert('Пожалуйста выберите операцию и тип недвижимости');
    return false;
  }
  return true;
  
}
function td_over(id)
{
  if (!cur_id || cur_id != id)
  {
    if (cur_id) 
    {
      document.getElementById('td_'+cur_id).className='mn_back';
      if (el = document.getElementById('sub_'+cur_id)) el.style.display = 'none';
    }
    document.getElementById('td_'+id).className='mn_active';
    if (el = document.getElementById('sub_'+id)) el.style.display = '';
    cur_id = id;
  }
  if (window.tm1) clearTimeout(window.tm1);
  window.tm1 = setTimeout('td_default()', 2000);
}
function td_default()
{
  if (cur_id && def_id && cur_id == def_id) return;
  if (cur_id)
  {
    document.getElementById('td_'+cur_id).className='mn_back';
    if (el = document.getElementById('sub_'+cur_id)) el.style.display = 'none';
  }
  if (def_id)
  {
    document.getElementById('td_'+def_id).className='mn_active';
    if (el = document.getElementById('sub_'+def_id)) el.style.display = '';
  }
}