var placeTarget      = '';
var placeTarTrue     = 0;
var placeTempTarTrue = 0;
var placeCntSelect   = 0;
var al               = 1;

function chowmenu(obj){ document.getElementById(obj).className="smenuv"
 if(document.getElementById("f"+obj)) document.getElementById("f"+obj).className="iframemenuv2";
 if(document.getElementById("player1")) document.getElementById("player1").className="m_videoin_off";
}
function hidmenu(obj){ document.getElementById(obj).className="smenuh"
 if(document.getElementById("f"+obj)) document.getElementById("f"+obj).className="iframemenuv1";
 if(document.getElementById("player1")) document.getElementById("player1").className="m_videoin";
}

function winlogopen(){ document.getElementById('winlogin').className="winlogin"}
function winlogclose(){ document.getElementById('winlogin').className="hidden"}

function ch_color(obj,cl){
  if(cl!='')
   obj.className=cl;
  else
   obj.className='tpl_realty_tractive';
}

function chowobj(obj){
 if( document.getElementById(obj).className=="visible" ) hidobj(obj);
 else document.getElementById(obj).className="visible";
}
function hidobj(obj){ document.getElementById(obj).className="hidden";  }
function replaceString(oldS,newS,fullS) {
 for (var i=0; i<fullS.length; i++) {
  if (fullS.substring(i,i+oldS.length) == oldS) {
   fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
  }
 }
 return fullS;
}
function changeCurrency(obj) {
 document.cookie = "Currency="+obj.value+"; path=/";
}
function openWind(url,x,y){
 var wnd = window.open(url,'','toolbar=0, resizable=1, width='+x+', height='+y);
}
function openObject(url,type,firm,card){
 if(al)
  document.location.href = url + 'realty/object/type,'+ type +'/firm'+ firm +'/id'+ card +'.php';
 al = 1;
}

function pl_submit(t){
 var warnning = "";
 if(document.placeLocator.plid_ploc.value == ""){ warnning = "<li>Не выбрана область</li>";}
 if(document.placeLocator.pl_type.value == "" && document.placeLocator.pl_alltype.value == ""){ warnning = warnning+ "<li>Не выбран тип недвижимости</li>";}
 if(document.placeLocator.pl_usl.value == "" && document.placeLocator.pl_alltype.value == ""){ warnning = warnning+ "<li>Не выбрано условие</li>";}
 if(document.placeLocator.pl_type.value == "newbuilding" && document.placeLocator.pl_usl.value == "rent" ){ warnning = warnning+ "<li>Поиск по данному запросу не доступен</li>";}
 if(warnning == "") document.placeLocator.submit();
 else message(warnning);
}

var DIV = null;
function message(warnning){
 if(DIV==null) var element = document.createElement("DIV");
 else var element = DIV;
 element.id = "flyover";
 element.className = "flydiv";
 element.style.visibility = "visible";
 element.innerHTML = "<!--[if lt IE 7]><iframe frameborder=\"0\" class=\"flyframe\"></iframe><![endif]-->"
  +"<div class=\"flyover\"><div class=\"warning\"><b>Предупреждение:</b><br/><ul>"+ warnning +"</ul></div>"
  +"<div class=\"flyover_close\"><a href=\"javascript: flyoverout('flyover');\">закрыть</a></div></div>";
 DIV = document.body.appendChild(element);
 setTimeout ("flyoverout('flyover')", 7000);
}
function flyoverout(obj){ document.getElementById(obj).innerHTML = ""; hidobj(obj); }

// -- поиск локатор ---------------------------------------------------------------
function elemColorOver(element){
 element.firstChild.style.backgroundColor='#e7e7e7';
 element.style.cursor = 'pointer';
}
function elemColorOut(element){
 element.firstChild.style.backgroundColor='transparent';
}
function openPlace(id, ploc, img1, img2){
 var disp = document.getElementById("d"+ploc+"_"+id);
 var elem = document.getElementById("u"+ploc+"_"+id);
 var mass = disp.className.split(" ");
 var clas = mass[0];
 var cl2  = ''; if(mass[1]) cl2 = " "+mass[1];
 if(clas == "dtree_box"){
  disp.className="dtree_boxopen"+cl2;
  elem.style.backgroundImage='url(/images/dtree/'+img2+')';
 }else{
  disp.className="dtree_box"+cl2;
  elem.style.backgroundImage='url(/images/dtree/'+img1+')';
 }
}
function getPlace( ploc, id, name, element, img1, img2 ){
 var act = document.getElementById("dtree_"+ploc+"_active").value;
 var img = document.getElementById("dtree_"+ploc+"_img").value;

 if(act!=''){
  document.getElementById(act).style.backgroundImage = 'url(/images/dtree/'+img+')';
 }
 placeTarget = ploc;
 element.style.backgroundImage='url(/images/dtree/'+img2+')';
 document.getElementById("dtree_"+ploc+"_active").value = element.id ;
 document.getElementById("dtree_"+ploc+"_img").value = img1;
 name = replaceString("область","обл.", name);
 name = replaceString("руспублика","респ.", name);
 document.getElementById("pl_"+ploc).innerHTML = "<nobr>"+name+"</nobr>";
 document.getElementById("plid_"+ploc).value = id;
 setTimeout('hidobj("obl_'+ploc+'")',300);

 var url       = '/ajax/place_locator.php';
 var strParams = 'id='+id+'&ploc='+ploc;
 var loader1   = new
 net.ContentLoader(url,FillRaion,null,"POST",strParams);
}

function getPlace2( ploc, id, name, element, img1, img2 ){
 var act = document.getElementById("dtree_"+ploc+"_active").value;
 var img = document.getElementById("dtree_"+ploc+"_img").value;
 if(act!=''){
  document.getElementById(act).style.backgroundImage = 'url(/images/dtree/'+img+')';
 }
 element.style.backgroundImage='url(/images/dtree/'+img2+')';
 document.getElementById("dtree_"+ploc+"_active").value = element.id ;
 document.getElementById("dtree_"+ploc+"_img").value = img1;
 name = replaceString("область","обл.", name);
 name = replaceString("республика","респ.", name);
 document.getElementById("pl_"+ploc).innerHTML = "<nobr>"+name+"</nobr>";
 document.getElementById("plid_"+ploc).value = id;
 setTimeout('hidobj("obl_'+ploc+'")',300);

 if(placeTarTrue > 0){
   placeTempTarTrue = 1;
   placeTarget   = ploc;
   var url       = '/ajax/place_locator.php';
   var strParams = 'id='+id+'&ploc='+ploc;
   var loader1   = new
   net.ContentLoader(url,FillRaion,null,"POST",strParams);
 }

}

function FillRaion(){
 var xmlDoc  = this.req.responseXML;
 var xRows   = xmlDoc.getElementsByTagName('entry');

 if(placeTempTarTrue==1){
  for(var i=0;i<placeCntSelect;i++){
   _FillRaion(xmlDoc, xRows, i+1);
  }
  placeTempTarTrue = 0;
 } else { _FillRaion(xmlDoc, xRows, ''); }
}

function _FillRaion(xmlDoc, xRows, dEnd){
 var objDDL = document.getElementById('plRaion_'+placeTarget+dEnd);
 objDDL.options.length = 0;
 for(var i=0;i<xRows.length;i++){
  var theText  = xRows[i].getElementsByTagName('optionText').item(0).firstChild.nodeValue;
  var theValue = xRows[i].getElementsByTagName('optionValue').item(0).firstChild.nodeValue;
  var option   = new Option(theText,theValue);
  objDDL.options.add(option,objDDL.options.length);
 }

}

function dTree(objName){
 this.config = {
  name : null,
  proc : ''
 }
 this.obj       = objName;
 this.nodes     = [];
 this.root      = new dTree_node(-1);
}
function dTree_node(id, id_parent, name, active){
 this.id        = id;
 this.id_parent = id_parent;
 this.name      = name;
 this.active    = active;
}
dTree.prototype.toString = function() {
 var str = '<input type="hidden" id="dtree_'+this.config.name+'_active" value="">'
         + '<input type="hidden" id="dtree_'+this.config.name+'_img" value="">';
 if (document.getElementById) {str=str+this.addNode(1);}
 str = str+ '';
 return str;
}
dTree.prototype.add   = function(id, id_parent, name, active){
 this.nodes[this.nodes.length] = new dTree_node(id, id_parent, name, active);
}
dTree.prototype.addNode   = function(id_parent){
 var str  = ''; var strn = ''; var cls   = ''; var cls2 = '';
 var plus = ''; var mins = ''; var dline = ''; var dbox = '';
 for (var n=0; n<this.nodes.length; n++) {
  if(this.nodes[n].id_parent == id_parent){
   cls   = 'dtree_closeb'; plus  = 'plusbottom.gif'; mins  = 'minusbottom.gif';
   cls2  = 'dtree_joinb';  plus2 = 'joinbottom.gif'; mins2 = 'joinredbottom.gif';
   dline = ''; dbox  = 'dtree_box';
   if(this.nodes[n].active) {
    cls   = 'dtree_openb'; cls2  = 'dtree_ojoinb';
    dbox = 'dtree_boxopen'; plus2 = 'joingetpbottom.gif';};
   for(var j=n+1; j<this.nodes.length; j++){
    if(this.nodes[j].id_parent == id_parent){
     cls   = 'dtree_close'; plus = 'plus.gif'; mins = 'minus.gif';
     cls2  = 'dtree_join'; plus2 = 'join.gif'; mins2 = 'joinred.gif';
     dline = ' dline'; dbox  = 'dtree_box';
     if(this.nodes[n].active) { cls   = 'dtree_open'; cls2  = 'dtree_ojoin';
      dbox = 'dtree_boxopen'; plus2 = 'joingetp.gif';}
     break;
    }
   }
   strn = this.addNode(this.nodes[n].id);
   if(strn == ''){
    str = str + '<div class = "'+cls2+'" id="u'+this.config.name+'_'
    + this.nodes[n].id+'" onmouseover="elemColorOver(this)" onmouseout="elemColorOut(this)" onclick="getPlace'+ this.config.proc +'(\''+this.config.name+'\', \''
    + this.nodes[n].id+'\' , \''+this.nodes[n].name+'\' , this, \''+plus2+'\', \''+mins2+'\')"'
    + '>'
    + '<span>'+this.nodes[n].name+'</span></div>';
   }else{
    strn = '<div class="'+dbox+dline+'" id="d'+this.config.name+'_'+ this.nodes[n].id +'">'+strn+'</div>';
    str = str + '<div class="'+cls+'" id="u'+this.config.name+'_'
    + this.nodes[n].id
    + '" onmouseover="elemColorOver(this)" onmouseout="elemColorOut(this)" onclick="openPlace('
    + this.nodes[n].id+', \''+this.config.name+'\', \''+plus+'\', \''+mins+'\')"><span>'
    + this.nodes[n].name+'</span></div>'+strn;
   }
  }
 }
 return str;
}
dTree.prototype.open   = function(id){
}
// -- конец поиск локатор ---------------------------------------------------------

