function add_field() {
 name_field=document.getElementById('name_field').innerHTML;
 value_field=document.getElementById('value_field').innerHTML;
 if (value_field=="") {
   document.getElementById('value_field').innerHTML='<input type="text" size="10" name="adr" />';
   document.getElementById('name_field').innerHTML='Комнат';
 }
 else {
   document.getElementById('value_field').innerHTML='';
   document.getElementById('name_field').innerHTML='';
 }
}

function del_unit(val) {
 document.getElementById('unit_'+val).innerHTML='';
 document.getElementById('main_form').submit();
}

function clearCurrentLink(){
 var x = window.location.href.split("&");
 for(var i=0;i<x.length;i++) {
  if (x[i]=="for=sale") {
   document.getElementById("rent_img").src="/files/images/spec_button/spec2.jpg";
   return 1;
  }
  if (x[i]=="for=rent") {
   document.getElementById("sale_img").src="/files/images/spec_button/spec1.jpg";
   return 1;
  }
  if (x[i]=="type=com") {
   if (document.getElementById("search_select")!=null) {
    document.getElementById("input_com_select").selected="selected";
    document.getElementById('value_field').innerHTML='';
    document.getElementById('name_field').innerHTML='';
   }
  }
  if (x[i]=="type=res") {
   if (document.getElementById("search_select")!=null) {
    document.getElementById("input_res_select").selected="selected";
    document.getElementById('value_field').innerHTML='<input type="text" size="10" name="adr" />';
    document.getElementById('name_field').innerHTML='Комнат';
   }
  }
 }
}

window.onload = clearCurrentLink; clearCurrentLink();

function OpenImagePopup(imgPath, title, alt) {
 var wc=parseInt((screen.availWidth)/2)
 var hc=parseInt((screen.availHeight)/2)
 var win = window.open('','preview','width=50,height=50, screenX='+wc+',screenY='+hc+',resizable=1,scrollbar=0,status=0');
 var winDoc = win.document;
 var content = '<html><head><title>'+title + '</title>' +'<style>body{overflow: hidden;margin:0;}img{border:0;}</style>'+'</head><body><a href="javascript:self.close()">' + '<img alt="' + alt + '" id="image" src="' + imgPath + '" /></a></body></html>'
 win.document.write(content);
 winDoc.body.onload = function() {
  var obj = winDoc.getElementById('image');
  var w = obj.width, h = obj.height;
  var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
  var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
  var top = (self.opera ? iHeight : screen.availHeight)/2 - h/2;
  win.resizeTo(w+10, h+26);
 }
 win.onload = winDoc.body.onload; // special for Mozilla
 win.document.close();
 win.focus();
}

