

addData = function (PlaceOn,ControlID) 
{

    // lets Create The Main Div 
    this.placeEl = Ext.get(PlaceOn);
    if (ControlID) 
        this.mainDivId = Ext.id();
    else
        this.mainDivId = ControlID;
        
    this.mainDiv = this.CreateDiv('x-adddata',document.body);
    
    
    
    var mytitle =this.CreateDiv('x-adddata-title',this.mainDiv);
    
    //if(iever == 6)
   // {
        //this.mainDiv.dom.style.width="780px";
        //mytitle.dom.style.width="780px";
    //}
    
    this.closeEl = this.CreateDiv('closeme',mytitle);
    this.closeEl.dom.innerHTML="X";
    this.closeEl.addListener('mousedown',this.hide,this);
    
    this.CreateDiv('title-text',mytitle).dom.innerHTML="פירוט נכסים";
    
    this.mainDiv.dom.id = this.mainDivId;
    
   // Draw List
    this.listContainerDiv = this.CreateDiv('x-adddata-listcontainer',this.mainDiv);
    
    
        this.listHeaderDiv = this.CreateDiv('x-adddata-listcontainer-header',this.listContainerDiv);
        
        this.listHeaderDiv.dom.innerHTML = "<span>רשימת דירות</span>";
        
        //this.CreateDiv('assets-list-title',this.listHeaderDiv).dom.innerHTML = "שכונה &nbsp &nbsp מס' חד' &nbsp &nbsp מחיר";
        
        this.listDiv = this.CreateDiv('x-adddata-listcontainer-list',this.listContainerDiv);
        
        this.listDivBox = this.listDiv.getBox();
        
        this.listUL = this.CreateDiv('ulDiv',this.listDiv);
        
        this.listLIs = [];
        
    this.listItemWidth = this.listDiv.dom.clientWidth - 1; // set the client width for that element for l8r use
    
    
    
    
    
    
   // Draw Main Section
   
   
   
    this.rightSection =  this.CreateDiv('x-adddata-rightsection',this.mainDiv);
    // adding top menu
    this.maininfotopRow = this.CreateDiv('x-adddata-maininfo-toprow',this.rightSection);
    
    
    this.maininfotopRow.dom.style.display="none";
        // top menu options
        
        
        
        //this.maininfotopRowMyAssetList = this.CreateDiv('x-adddata-maininfo-toprow-item',this.maininfotopRow);
        //this.maininfotopRowMyAssetList.dom.innerHTML = "הוסף לרשימת הנכסים שלי";
//        this.maininfotopRowMyAssetList.on('click',mam.addRemoveAsset,mam);
        //this.maininfotopRowMyAssetList.dom.id = "listAddToMyAssets";
        
        
        
        this.maininfottopRowSep = this.CreateDiv('x-adddata-maininfo-toprow-item-sep', this.maininfotopRow );
        this.maininfottopRowSep.dom.innerHTML = "&nbsp";
        
        //this.maininfotopRowSmartAgent = this.CreateDiv('x-adddata-maininfo-toprow-item',this.maininfotopRow);
        //this.maininfotopRowSmartAgent.dom.innerHTML = "הפעל סוכן חכם";
        
        //this.maininfottopRowSep = this.CreateDiv('x-adddata-maininfo-toprow-item-sep', this.maininfotopRow );
        //this.maininfottopRowSep.dom.innerHTML = "&nbsp";
        
        this.maininfotopRowPriceHistory = this.CreateDiv('x-adddata-maininfo-toprow-item',this.maininfotopRow);
        this.maininfotopRowPriceHistory.dom.innerHTML = "הסטורית מחירים באיזור";
        
        this.maininfottopRowSep = this.CreateDiv('x-adddata-maininfo-toprow-item-sep', this.maininfotopRow );
        this.maininfottopRowSep.dom.innerHTML = "&nbsp";
        
        
        //this.maininfotopRowPrint = this.CreateDiv('x-adddata-maininfo-toprow-item',this.maininfotopRow);
        //this.maininfotopRowPrint.dom.innerHTML = "תצוגת הדפסה";
        //this.maininfotopRowPrint.on('click',this.printAdd,this);
        
        
    // create structor for detail section
    this.detailBox = this.CreateDiv('x-adddata-all-details-box',this.rightSection);
    
    
    
    /* create inlage pic container */
    
    this.largPic = this.CreateDiv('largpic', Ext.getBody());
    var t1 = this.CreateDiv('title',this.largPic);
    this.largPicCloseBtn = this.CreateDiv('larg-pic-close', t1);
        this.largPicCloseBtn.dom.innerHTML="X";
        this.largPicCloseBtn.on('click',this.hideLargPic,this);
    this.CreateDiv('txt', t1).dom.innerHTML = "תצוגת תמונה"
    
    this.largPicNavBar = this.CreateDiv('larg-pic-nav-bar', this.largPic);
    this.largImgNavBack = this.CreateDiv('larg-pic-nav-bar-btn', this.largPicNavBar);
    this.largImgNavNext = this.CreateDiv('larg-pic-nav-bar-btn', this.largPicNavBar);
                
                
                
                
                this.largImgNavNext.on("click",this.LargPicChange,this);
                this.largImgNavNext.dom.id="LargPicUp";
                this.largImgNavBack.on("click",this.LargPicChange,this);
                this.largImgNavBack.dom.id="LargPicDown";
            //this.picBarNav.dom.innerHTML="1 / 3";
            this.picBarMagnifay =this.CreateDiv('magnifay',this.picBar);
        
        
        //create area pic and info
        this.areaPicAndInfo =this.CreateDiv('x-adddata-area-pic-and-info',this.detailBox);
         this.areaPic = this.CreateDiv('area-pic',this.areaPicAndInfo);
         this.areaPic.dom.id = "areaSmallMap";
         this.areaPichomeIcon = this.CreateDiv('areaPichomeIcon',this.areaPic);
         this.areaPichomeIcon.dom.id = "areaPichomeIcon";
         this.infoTree = this.CreateDiv('area-info-tree',this.areaPicAndInfo);
    
    
    // create place form banner 
    this.infoBanner = this.CreateDiv('adddata-info-banner',this.detailBox);
    
    
    
    this.myBox = this.mainDiv.getBox();
    this.fixLocation();
    this.visible = false;
    //this.hide();
    this.mainDiv.toggleClass('x-adddata-hide');  
    
    this.createReportForm();
    

};


addData.prototype = 
{
mainDiv: null,
listContainerDiv: null,
listHeaderDiv: null,
listDiv: null,
listDivBox: null,
listFillerLi: null,
rightSection: null,
middleSection: null,
mainInfoDiv: null,
mainInfoCloseDiv: null,
mainInfoDataDiv: null,
mainInfoLeftCol: null,
mainInfoPicDiv: null,
mainInfoLinkDiv: null,
mainInfoButtonsDiv: null,
btnAddToList: null,
btnHunter: null,
bannerDiv: null,
priceChangeDiv: null,
distanceDiv: null,
mainDivId : null,
placeEl: null,
listItemWidth: null,
closeEl: null,
listUL: null,
listLIs: null,
visible: null,
mm: null, // Markers Manager
rowIndex: null,
selectedLi: null,
myBox: null,
maininfottopRowSep : null,
maininfotopRowSmartAgent : null,
maininfotopRowPriceHistory : null,
maininfotopRowPrint : null,
script : 'json/json.aspx?action=getAreaInfo&',
//picurl : "http://192.118.97.206/zazim/img.img?AddId=",
picurl : hosturl+"zazim/img.img?AddId=",


createReportForm : function()
{
    if(!this.reportForm)
    {
        this.reportForm = new createForm({width:330,height:370,title:'דיווח שגיאות',analyticsname:'report_asset_error'});
        this.reportForm.parent = this;
        this.reportForm.is_valid_email = function(email)
        {
            return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);    
        };
        this.submit = function()
        {
            var data = this.getFormValsObj();
            var msg= "";
            
            if(data.name == "")
            {
                if(msg != "") msg+="\n";
                msg+="חובה להזין את שם המדווח";
            }
            if(data.email == "")
            {
                if(msg != "") msg+="\n";
                msg+="חובה להזין כתובת מייל";
            }
            else
            {
                if(!this.is_valid_email(data.email))
                {
                    if(msg != "") msg+="\n";
                    msg+="כתובת המייל שהוזנה אינה חוקית";
                }
                
            }
            if(data.type == "")
            {
                if(msg != "") msg+="\n";
                msg+="חובה לציין את סוג הדיווח";
            }
            if(data.type == "else" && (data.msg =="" || data.msg.length < 10 ))
            {
                if(msg != "") msg+="\n";
                msg+="בדיווח אחר ישל למלא את סוג הבעיה";
            }
            if(msg != "")
            {
                alert(msg);
            }
            else
            {
                this.parent.sendReport();
            }
            
            
        };
        var msg= "אנו באתר זזים עושים את מיטב המאמצים על מנת <br>" +
        "להציג את המידע העדכני והמדויק ביותר.<br>"+
        "במידה ומצאתם שגיאה במידע המוצג באתר <br>"+
        "אנא דווחו לנו על ידי מילוי הטופס המצורף.<br>"+
        "אנו נעשה את מיטב המאמצים על מנת לטפל בבעיה. <br>"+
        "בתודה על שיתוף הפעולה<br>"+
        "צוות אתר זזים.";
        this.reportForm.addDiv({style:"reportFormMsg",text:msg});
        
        
        this.reportForm.addDiv({style:"reportFormText",text:"* שם הפונה:"});
        this.reportForm.addField({style:"reportFormData",type:'text',value:'' ,name:'name',width:180});
        this.reportForm.addDiv({style:"reportFormText",text:"* כתובת מייל:"});
        this.reportForm.addField({style:"reportFormData",type:'text',value:'' ,name:'email',width:180});
        this.reportForm.addDiv({style:"reportFormText",text:"טלפון:"});
        this.reportForm.addField({style:"reportFormData",type:'text',value:'' ,name:'phone',width:180});
        
        this.reportForm.addDiv({style:"reportFormText",text:"* סוג הבעיה:"});
        this.reportForm.addField({style:"reportFormData",type:'select',value:'' ,name:'type',width:180});
        
        
        this.reportForm.addDiv({style:"reportFormText",text:"תיאור הבעיה:"});
        this.reportForm.addField({style:"reportFormData",type:'textarea' , name:'msg', height:80,width:175});
        
        this.reportForm.fieldArray.type.addOption('','בחר',true);
        this.reportForm.fieldArray.type.addOption('location','ממוקם לא נכון במפה');
        this.reportForm.fieldArray.type.addOption('details','חסרים פרטים');
        this.reportForm.fieldArray.type.addOption('contact','פרטי התקשרות חסרים / שגויים');
        this.reportForm.fieldArray.type.addOption('old','מודעה לא רלוונטית');
        this.reportForm.fieldArray.type.addOption('else','אחר פרט');
        var btnsdiv =this.reportForm.addDiv({style:'reportFormbtns'});
        this.reportForm.addBtn({width:170,target:btnsdiv,text:'דווח'}).on('click',this.submit,this.reportForm);
        
        
    }
},
sendReport : function()
{
    
    this.reportForm.form.dom.style.zIndex = this.reportForm.form.dom.style.zIndex -1;
    var data = this.reportForm.getFormVals() + "|add_id(" +  this.selectedLi.row[this.rowIndex['id']] + ")";
    data = data.replace(/,/g,"_psik").replace(/"/g,"_merca").replace(/'/g,"_geresh");
    
    Ext.Ajax.request({
            url :hosturl + "contact/sendmsg.aspx?",
            success : function(ans){
                var rez = eval(ans.responseText);
                if(rez[0]== false)
                {
                    
                    alert(rez[1]);
                    this.reportForm.form.dom.style.zIndex = this.reportForm.form.dom.style.zIndex +1;
                    this.reportForm.hide();
                }
                else
                {
                    alert('מספר הפנייה שלך הוא: \n ' + rez[1] + '\n צוות אתר זזים' );
                    this.reportForm.form.dom.style.zIndex = this.reportForm.form.dom.style.zIndex +1;
                    this.reportForm.hide();
                }
                
            },
            failure :function(){alert('חיבור לשרת נכשל אנא בדוק את חיבור האינטרנט');this.reportForm.form.dom.style.zIndex = this.reportForm.form.dom.style.zIndex +1;this.reportForm.hide();},
            params :{data:data},
            scope : this
        });
  
},
fixLocation: function ()
    {
        var locBox = this.placeEl.getBox();
        
        // Lets Compute The Location
        var top = Math.round(locBox.y + locBox.height/2 - this.myBox.height/2);
        var left = Math.round(locBox.x + locBox.width/2 - this.myBox.width/2);
        
        
        this.mainDiv.dom.style.top = top + 'px';
        this.mainDiv.dom.style.left = left + 'px';
        
        
    },
    CreateDiv: function (inClass,appendTo)
    {
        var Div =  Ext.get(document.createElement('DIV'));
        Div.dom.id = Ext.id();
        Div.toggleClass(inClass);  
        if (appendTo) Div.appendTo(appendTo);
       
        
        return Div;
    },
    AddsCount: function (No,Count,Type)
    {
        //this.listHeaderDiv.dom.innerHTML = "<span>" + Type + " "+ No +" מתוך "+ Count +"</span>";
    },
    hide: function ()
    {
        
     if (this.visible)
     {
     //alert('hide');
     
     if(openFormList.length != 0)
        {
            for(var i=0; i<openFormList.length ; i++)
            {
                if(openFormList[i] == this)
                {
                    openFormList.splice(i,1);
                }
            }
        }
     
     bmanager.remove(this.constBanner);
     this.hideLargPic();
     if(Ext.get('contactDetails') != null)
                {
                    this.contactDetails.dom.style.display='none';
                    this.contactDetails.dom.innerHTML = "";
                }
     this.mainDiv.fadeOut({
            endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
            easing: 'easeOut',
            duration: .5,
            remove: false,
            useDisplay: true
        });
        this.clearLis();
      //  this.mainDiv.toggleClass('x-adddata-hide');  
        this.visible = false;
     }
     if(this.blockdiv)
        this.blockdiv.dom.style.display="none";
    },
    show: function ()
    {
      
      
     if (!this.visible)
     {
        //alert('show');  
        
        if(!this.blockdiv)
        {
            this.blockdiv = Ext.get(document.createElement('div'));
            this.blockdiv.dom.style.width = Ext.getBody().getWidth() + "px";
            this.blockdiv.dom.style.height =   "2000px";
            this.blockdiv.dom.style.position = "absolute";
            this.blockdiv.dom.style.top=0;
            this.blockdiv.dom.style.left=0;
            this.blockdiv.dom.style.backgroundColor = "gray";
            var val=4;
            this.blockdiv.dom.style.MozOpacity = val;
            this.blockdiv.dom.style.opacity = val/10;
            this.blockdiv.dom.style.filter = 'alpha(opacity=' + val*10 + ')';
            this.blockdiv.appendTo(Ext.getBody());
            this.blockdiv.dom.style.display="none";
            this.blockdiv.dom.style.zIndex =10000;
            
        }
        
        this.fixLocation();     
        //this.mainDiv.toggleClass('x-adddata-hide'); 
        this.mainDiv.fadeIn();
        //this.mainDiv.toggleClass('x-adddata-hide');  
        this.visible = true;
        this.blockdiv.dom.style.display="block";
        this.mainDiv.dom.style.zIndex =10001;
        openFormList[openFormList.length] = this;
        this.mainDiv.dom.focus();
     }
    },
    clearLis: function ()
    {
    if(this.bannerList)
    {
        for(var i=0;i<this.bannerList.length;i++)
        {
            bmanager.remove(this.bannerList[i]);
            this.bannerList[i] = null;
        }
        this.bannerList = new Array();
    }
    if ( this.listFillerLi)
    {
            this.listFillerLi.dom.innerHTML = '';
            this.listFillerLi.remove();
            this.listFillerLi = null;
    }
    this.selectedLi = null;
        for (var i = 0; i < this.listLIs.length; i++)
        {
            this.listLIs[i].removeAllListeners();
            this.listLIs[this.listLIs.length - 1].row = null;
            this.listLIs[i].dom.innerHTML = '';
            this.listLIs[i].remove();
            this.listLIs[i] = null;
        }
        this.listLIs = null;
        this.listLIs = [];
    },
    enlist: function (MarkerId,selectId,rows,_rowIndex)
    {
        
        
        if(!rows)
        {
            var rows = map.getHousesMarkerData(MarkerId);
        }
        if(_rowIndex)
        {
            this.rowIndex = _rowIndex;
        }
        else
        {
            this.rowIndex = mm.rowIndex;
        }
        
        this.clearLis();
        
        var selectIndex = 0; // var to hold wich index will go first
        //
        var counter = -1;
        
        
        if(!this.selectListTemplate)
            {
                this.selectListTemplate = new Ext.Template(
                    '<div class="Divli">',
                    '<div class="Street"> {street} </div>',
                    '<div class="Rooms"> {rooms} חד\'  </div>',
                    '<div class="Price"> {price} </div>',
                    '<div class="{avg}" > </div>',
                    '</div>'
                );
                this.selectListTemplate = this.selectListTemplate.compile();
            }
        for (var i = rows.length-1; i >= 0; i--)
        {
            counter++;
            if (selectId && selectId == rows[i][this.rowIndex['id']]) selectIndex = counter;
            
            if(counter % addDataliList == 0 )
            {
                if(!this.bannerList) this.bannerList = [];
                // change number to add banners  0= no banners
                if(this.bannerList.length <0)
                {
                    this.bannerList[this.bannerList.length] = bmanager.add('13303','128','30',this.listUL);
                }

            }
            
            var OrigPrice = rows[i][this.rowIndex['ShekelRent']];
            if (OrigPrice < 1000000)
            {
                OrigPrice =  roundNumber(OrigPrice/1000,2) + "K" + " ₪";
            }
            else
            {
                OrigPrice =  roundNumber(OrigPrice/1000000,2) + "M"+ " ₪";
            }
            var arrow = "";
            
            if(!isNaN(rows[i][this.rowIndex['vPriceAvg']]))
            {
                if(rows[i][this.rowIndex['ShekelRent']]*1 > 100)
                {
                    if (rows[i][this.rowIndex['ShekelRent']] > rows[i][this.rowIndex['vPriceAvg']]*1  ) 
                     arrow = "Up";
                    else if (rows[i][this.rowIndex['ShekelRent']] < rows[i][this.rowIndex['vPriceAvg']]*1   ) 
                        arrow = "Down";
                }
                
                if( rows[i][this.rowIndex['vPriceAvg']]*1  == 0 )
                    arrow = "";
            }
            var li=this.selectListTemplate.append(this.listUL,{street:rows[i][this.rowIndex['vStreet']],rooms:rows[i][this.rowIndex['RoomNumber']],price:OrigPrice,avg:arrow});
            li = Ext.get(li);
            li.addListener('mousedown',this.select,this,{li: li});
            this.listLIs[this.listLIs.length] = li;
            this.listLIs[this.listLIs.length - 1].row = rows[i];
            
        }
       this.select(null,null,{li: this.listLIs[selectIndex]},true);
       // fill another empty li so the height of the list will be right
       if ((rows.length < 2 ? 2 : rows.length ) * 29 < this.listDivBox.height)
       {
        /*
           this.listFillerLi = Ext.get(document.createElement('LI'));
           this.listFillerLi.toggleClass('Divli');
           this.listFillerLi.toggleClass('PlaceHolder');
           this.listFillerLi.dom.style.height = (this.listDivBox.height - rows.length * 29 )  + 'px';
           this.listFillerLi.appendTo(this.listUL);
           */
       }
       else
       { // lets just add a double end, so we can compansate for the selected effect
       /*
          this.listFillerLi = Ext.get(document.createElement('LI'));
          this.listFillerLi.toggleClass('Divli');
          this.listFillerLi.toggleClass('PlaceHolder');
          this.listFillerLi.dom.style.height = (2 * 29 )  + 'px';
          this.listFillerLi.appendTo(this.listUL);
          */
       }
        this.AddsCount(1,rows.length,rows[0][this.rowIndex['AssetType']]);
        this.show();
        
    },
    select: function (p1,p2,p3,noAmin)
    {
        
        
        pageTracker._trackPageview("/display_add" ); 
        //this.infoBanner//13308 
        
        if(!this.displaytemplate)
        {
            this.displaytemplate = new Ext.Template(
                      ' <div class="assets-detail-box"> ',
                      '  <div class="asset-detail" id="asset-detail-ancor"> ',
                      '    <div style="width:180px; float:right; height:240px;"> ',
                      '      <div class="orange-text"> פרטי נכס</div> ',
                      '      <div class="text-title" style="font-weight:bold;"> מחיר:</div> <div class="{price_color}"> {price} ₪  </div> ',
                      '      <div class="text-title" style="visibility:{showavgprice};font-weight:bold;"> מחיר ממוצע:</div> <div class="text-data" style="visibility:{showavgprice};font-weight:bold;font-size:14px;"> {avg_price} </div> ',
                      '      <div class="text-title"> נכס:</div> <div class="text-data"> {type} </div> ',
                      '      <div class="text-title" style="height:43px"> מיקום:</div> <div class="text-data" style="height:43px;overflow:hidden;"> <acronym title="{location}"> {location} </acronym>   </div> ',
                      '      <div class="text-title"> שטח:</div> <div class="text-data">{size} </div> ',
                      '      <div class="text-title"> חדרים:</div> <div class="text-data"> {rooms}</div> ',
                      '      <div class="text-title"> קומה:</div> <div class="text-data">{floor} </div> ',
                      '      <div class="text-title"> תאריך כניסה:</div> <div class="text-data">{date} </div> ',
                      '      <div class="text-title" style="font-weight:bold;"> תאריך עדכון:</div> <div class="text-data" style="font-weight:bold;"> {update}</div> ',
                      '    </div> ',
                      '    <div style=" width:125px; float:right; height:240px;">',
                      '      <img  id="assetPicBox" src=""/>',
                      '       <div class="magnifay" id="asset_show_larg_pic_txt"> לחץ להגדלה </div>',
                      '       <div class="contact-detail-link" id="showContactDetail" > פרטי התקשרות </div>',
                      '       <div class="contact-detail" id="contactDetail">',
                      '        איש קשר: {contactname} <br>',
                      '         {contactphone}  ',
                      '       </div>',
                      '    </div>',
                      '    <div style="width:180px; float:right; height:110px;">',
                      '      <div class="orange-text" style="width:100%;"> פרטים נוספים</div>',
                      '         <div class="{elevaitor}"> מעלית </div>',
                      '         <div class="{aircon}"> מיזוג </div>',
                      '         <div class="{parking}"> חניה </div>',
                      '         <div class="{bars}"> סורגים </div>',
                      '         <div class="{furni}"> ריהוט </div>',
                      '    </div> ',
                      '    <div style="width:120px; float:right; height:110px;">',
                      '    <div class="orange-text" style="width:100%;"> &nbsp</div>',
                      '         <div class="{teras}"> מרפסת </div>',
                      '         <div class="{refurb}"> משופצת </div>',
                      '         <div class="{arbitration}"> תיווך/יזמות/אחר </div>',
                      '         <div class="{partners}"> מתאים לשותפים </div>',
                      '         <div class="{hac}"> גישה לנכים </div>',
                      '    </div>',
                      '    <div style="width:100%; float:right; height:30px; overflow:hidden;" title="{description}">',
                      '      {description}',
                      '    </div>',
                      '  </div> ',
                      '  <div class="asset-map-and-distance">',
                      '      <div class="orange-text"> מפה ומרחקים</div>',
                      '      <div class="minimap" id="minimap">  </div>',
                      '     <div class="orange-text" style="font-weight:bold;"> מרחקים </div> ',
                      '     <div class="distances-div">',
                      '       <div id="אנטנות סלולריות" > <img src="addData/images/antenagray.png"/> <div>אנטנות <br> סלולריות </div> </div>',
                      '       <div id="בתי ספר"> <img src="addData/images/schoolgray.png"/> <div> בתי ספר </div> </div>',
                      '       <div id="חניונים"> <img src="addData/images/parkinggray.png"/> <div> חניונים </div> </div>',
                      '       <div id="סופר/מרכז מסחרי"> <img src="addData/images/supergray.png"/> <div> סופר <br> מרכז מסחרי </div> </div>',
                      '       <div id="בית מרקחת"> <img src="addData/images/pharmacygray.png"/> <div>בתי <br> מרקחת </div> </div>',
                      '       <div id="קופות חולים"> <img src="addData/images/kopatholimgray.png"/> <div> קופות <br> חולים </div> </div>',
                      '       <div id="תחנות דלק"> <img src="addData/images/gasgray.png"/> <div> תחנת דלק </div> </div>',
                      '       <div id="תחנת רכבת"> <img src="addData/images/traingray.png"/> <div> רכבת  </div> </div>',
                      '       <div id="חופי רחצה"> <img src="addData/images/beachgray.png"/> <div> חופי רחצה </div> </div>',
                      '       <div id="בריכה/קאנטרי"> <img src="addData/images/poolgray.png"/> <div> בריכות  </div> </div>',
                      '       <div id="גנים"> <img src="addData/images/tempelgray.png"/> <div> גנים/פארקים  </div> </div>',
                      '       <div id="מועדונים"> <img src="addData/images/clubgray.png"/> <div> מועדונים  </div> </div>',
                      '     </div>',
                      '  </div>',
                      '  <div class="assetDisplayBtns" id="assetDisplayBtns">',
                      '       <div class="btnaprint"  id="printadd"> תצוגת הדפסה </div>',
                      '       <div class="btnadd"  id="addremovemyassets"> הוסף לנכסים שלי </div><div class="btnsep"> </div>',
                      '       <div class="btnhistory"  id="pricehistory"> הסטורית מחירים </div><div class="btnsep"> </div>',
                      '       <div class="btnareprot"  id="reporterror"> דווח על מודעה שגויה </div> <div class="btnsep"> </div>',
                      '   </div>',
                      '</div>'

            );
            
            this.displaytemplate = this.displaytemplate.compile();
        }
        
        if (p3.li != this.selectedLi)
        {
            if (this.selectedLi) this.selectedLi.toggleClass('selected');
            this.selectedLi = p3.li;
            this.selectedLi.toggleClass('selected');
            // Fix scroll position so it wont look wierd
         
            var selectedPos = this.selectedLi.getBox().y - this.listDiv.getBox().y;
            if (selectedPos < 2* 29)
            {
                this.listDiv.scroll("b",selectedPos - 2 * 29,true);
            }
            else if (selectedPos > 8 * 29)
            {
                this.listDiv.scroll("b",(selectedPos - 7 * 29),true);
            }
            // set the options
            
            // changed by gilad 
            
            // add marking from header
            ////listAddToMyAssets
            
            
            
            
            
            this.infoTree.dom.style.display = 'block'; 
            // hide contact details 
                if(Ext.get('contactDetails') != null)
                {
                    this.contactDetails.dom.style.display='none';
                    this.contactDetails.dom.innerHTML = "";
                }
                
            // hide larg pic
                this.hideLargPic();
            // adding adress
            var addressText = "";
            var lastUpdate = "";
            
            
            /* start creating new object with display data for template */
            
            var dispobj = {};
            function ev(name,value)
            {
                value = value.replace(/"/g,'');
                value = value.replace(/'/g,'');
                value = value.replace(/\n/g,'');
                value = value.replace(/\r/g,'');
                var str1 = "dispobj." + name + "='" + value + "';";
                //str1 = str1;
                eval(str1);
            }
            
            
            
            
            if(!isNaN( this.selectedLi.row[this.rowIndex['vAge']]))
            {
                if( ( this.selectedLi.row[this.rowIndex['vAge']] *1 ) > 0  )
                {
                    lastUpdate = "לפני  " + (this.selectedLi.row[this.rowIndex['vAge']] *1) + " ימים";
                }
                else if( ( this.selectedLi.row[this.rowIndex['vAge']]*1 ) == 0  )
                {
                    lastUpdate = " בשעה האחרונה" 
                }
                else
                {
                    lastUpdate = "לפני  " + (this.selectedLi.row[this.rowIndex['vAge']] *-1) + " שעות";
                }
            }
           
            
            ev('update',lastUpdate);
            
            var addTypeText;
            //this.selectedLi.row[this.rowIndex.vAddType]
            if(this.selectedLi.row[this.rowIndex.vAddType] == 'rent')
            {
                addTypeText = 'השכרה';
            }
            else if(this.selectedLi.row[this.rowIndex.vAddType] == 'sale')
            {
                addTypeText = 'מכירה';
            }
            else if(this.selectedLi.row[this.rowIndex.vAddType] == 'partners')
            {
                addTypeText = 'שותפים';
            }
            else if(this.selectedLi.row[this.rowIndex.vAddType] == 'commercial')
            {
                addTypeText = 'עיסקי';
            }
            else if(this.selectedLi.row[this.rowIndex.vAddType] == 'exchange')
            {
                addTypeText = 'החלפה';
            }
            
            addressText +=this.selectedLi.row[this.rowIndex['AssetType']]+ '(' + addTypeText + ')';
            
            ev('type',addressText);
            
            
            var loc = this.selectedLi.row[this.rowIndex['city']] + '&nbsp' + this.selectedLi.row[this.rowIndex['Street']];
            if(loc.length > 125 )
            {
                loc = '<acronym title="'+loc+'"> '+loc.substr(0,18)+'... </acronym>';
            }
            
            ev('location', loc);
            ev('rooms',this.selectedLi.row[this.rowIndex['RoomNumber']]);
            ev('size',this.selectedLi.row[this.rowIndex['Size']].replace(/ /g,"").replace(/-/g,"") == '' ? 'לא צויין' : this.selectedLi.row[this.rowIndex['Size']] + " מ\"ר ");
            ev('floor',this.selectedLi.row[this.rowIndex['Floor']]);
            
            // adding apt properties
            
            var aptPropertis = new Array();
//            debugger;
            if (this.selectedLi.row[this.rowIndex['Elevator_value']] == 'true'){aptPropertis[0] = 'yes';}else{aptPropertis[0] = 'no';} ; //מעלית
            if (this.selectedLi.row[this.rowIndex['AirCond_value']] == "true" ){aptPropertis[1] = 'yes';}else{aptPropertis[1] = 'no';} ; //מיזוג
            if (this.selectedLi.row[this.rowIndex['Parking_value']] == "true" ){aptPropertis[2] = 'yes';}else{aptPropertis[2] = 'no';} ; //חניה
            if (this.selectedLi.row[this.rowIndex['Bars_value']] == 'true'){aptPropertis[3] = 'yes';}else{aptPropertis[3] = 'no';} ; //סורגים
            if (this.selectedLi.row[this.rowIndex['Furnished_value']] == 'true' ){aptPropertis[4] = 'yes';}else{aptPropertis[4] = 'no';} ; //ריהוט
            if (this.selectedLi.row[this.rowIndex['GoodForPartners_value']] == 'true'){aptPropertis[5] = 'yes';}else{aptPropertis[5] = 'no';} ; //מתאים לשותפים
            if (this.selectedLi.row[this.rowIndex['HandicapAccess_value']] == 'true'){aptPropertis[6] = 'yes';}else{aptPropertis[6] = 'no';} ; //גישה לנכים
            if (this.selectedLi.row[this.rowIndex['Refurbished_value']] == 'true'){aptPropertis[7] = 'yes';}else{aptPropertis[7] = 'no';} ; //משופצת
            if (this.selectedLi.row[this.rowIndex['VernadaNo_value']] == 'true'){aptPropertis[8] = 'yes';}else{aptPropertis[8] = 'no';} ; //מרפסת
            if (this.selectedLi.row[this.rowIndex['vTivuch']] == 'true'){aptPropertis[9] = 'yes';}else{aptPropertis[9] = 'no';} ; //מתיווח
            
            
            
            
            ev('elevaitor',aptPropertis[0]);
            ev('aircon',aptPropertis[1]);
            ev('parking',aptPropertis[2]);
            ev('bars',aptPropertis[3]);
            ev('furni',aptPropertis[4]);
            ev('teras',aptPropertis[8]);
            ev('refurb',aptPropertis[7]);
            ev('arbitration',aptPropertis[9]);
            ev('partners',aptPropertis[5]);
            ev('hac',aptPropertis[6]);
            
            
            
            
            

            
            // add price and link to other price list
            
            var priceClass = ""
            
            // test price -- Start
            if( isNaN(this.selectedLi.row[this.rowIndex['vPriceAvg']])) 
            {
                priceClass = "Price-black";
            }
            else
            {
                if (this.selectedLi.row[this.rowIndex['ShekelRent']] > this.selectedLi.row[this.rowIndex['vPriceAvg']] *1   ) 
                 priceClass = "Price-red";
                else if (this.selectedLi.row[this.rowIndex['ShekelRent']] < this.selectedLi.row[this.rowIndex['vPriceAvg']] *1   ) 
                    priceClass = "Price-green";
                    
                if( this.selectedLi.row[this.rowIndex['vPriceAvg']] *1  == 0 ||  this.selectedLi.row[this.rowIndex['ShekelRent']] *1 <100 )
                    priceClass = "Price-black";
            }
            
            var pricetxt = "<SPAN class='"+ priceClass  +"'>" +  ((this.selectedLi.row[this.rowIndex['ShekelRent']]*1) < 100 ? 'מחיר לא צויין' : "₪ " +   Ext.util.Format.usMoney(  this.selectedLi.row[this.rowIndex['ShekelRent']])).replace('$','').replace('.00','')  + "</SPAN>" ;
            if(!isNaN(this.selectedLi.row[this.rowIndex['vPriceAvg']])) 
            {   
                pricetxt+= "<DIV style=\"diriction:rtl;\">"  + ( (this.selectedLi.row[this.rowIndex['vPriceAvg']]*1) == 0 ? "" :(  "מחיר ממוצע לאיזור " + "₪ " +   Ext.util.Format.usMoney(  this.selectedLi.row[this.rowIndex['vPriceAvg']])).replace('$','').replace('.00','')   ) + "</DIV>"
            }
            ev('price',((this.selectedLi.row[this.rowIndex['ShekelRent']]*1) < 100 ? 'מחיר לא צויין' : " " +   Ext.util.Format.usMoney(  this.selectedLi.row[this.rowIndex['ShekelRent']])).replace('$','').replace('.00',''));
            ev('price_color',priceClass);
            
            if( isNaN(this.selectedLi.row[this.rowIndex['vPriceAvg']])) 
                ev('showavgprice','hidden');
            else if((this.selectedLi.row[this.rowIndex['vPriceAvg']]*1) == 0)
                ev('showavgprice','hidden');
            else
            {
                ev('showavgprice','block');
                ev('avg_price',Ext.util.Format.usMoney(this.selectedLi.row[this.rowIndex['vPriceAvg']]).replace('$','').replace('.00',''));
            }
            ev('date',this.selectedLi.row[this.rowIndex["EntryWhen"]]);
    
            ev('contactname' , (this.selectedLi.row[this.rowIndex['Contact']] =="" ? 'לא צויין' :this.selectedLi.row[this.rowIndex['Contact']] ) );
            var pnumbers = "";
            if(this.selectedLi.row[this.rowIndex.PhoneA] != "")
            {
                pnumbers = this.selectedLi.row[this.rowIndex.PhoneA];
            }
            if(this.selectedLi.row[this.rowIndex.PhoneB] != "")
            {
                if(pnumbers.length != 0) pnumbers+="<br>";
                pnumbers+= this.selectedLi.row[this.rowIndex.PhoneB];
            }
            ev('contactphone', pnumbers);
            
            
            // get area pic and clear old markers
                //var picurl = "http://192.118.97.206/Zazim/wms.wms?AssetX="+this.selectedLi.row[this.rowIndex['x']]+"&AssetY="+this.selectedLi.row[this.rowIndex['y']];
                
            // get apt area info from server
            //this.selectedLi.row[this.rowIndex['px']]
            
            
            /* test */
            
            if(this.selectedLi.row[this.rowIndex.description] )
            {   
                //debugger;
                ev('description', this.selectedLi.row[this.rowIndex.description]);
                
            }
            
            
            this.detailBox.dom.innerHTML = "";
            this.displaytemplate.append(this.detailBox,dispobj);
            var picurl = hosturl+"Zazim/wms.wms?AssetX="+this.selectedLi.row[this.rowIndex['x']]+"&AssetY="+this.selectedLi.row[this.rowIndex['y']];
            this.getAptPic(picurl);
            
            this.areaPichomeIcon = this.CreateDiv('areaPichomeIcon',Ext.get('minimap'));
            this.areaPichomeIcon.dom.id = "areaPichomeIcon";
            this.picBox =Ext.get('assetPicBox');
            
            
            var url = this.script + 'input=' +this.selectedLi.row[this.rowIndex['id']];
            
            var req = new treeAjax();
            this.curretAssetX = this.selectedLi.row[this.rowIndex['x']]*1;
            this.curretAssetY = this.selectedLi.row[this.rowIndex['y']]*1;
            var onSuccessFunc=function (list){this.fillAreaInfoTree(list);}
            var onErrorFunc=function (error){}
            
            /* get distance data*/
            req.makeRequest( url, "get", this.createDelegate(this,this.fillAreaInfoTree),this.createDelegate(this, onErrorFunc) );
           
           Ext.get('showContactDetail').on('click',function(){
           pageTracker._trackPageview("/show_phone_number"); 
           Ext.get('showContactDetail').dom.className = Ext.get('contactDetail').dom.className;
           Ext.get('showContactDetail').dom.innerHTML = Ext.get('contactDetail').dom.innerHTML;
            //.display="none";
           Ext.get('showContactDetail').dom.style.display="block";  
           }); 
            
            
            this.maininfotopRowPrint = Ext.get('printadd');
            this.maininfotopRowPrint.on('click',this.printAdd,this);
            
            
            
            Ext.get('reporterror').on('click',this.reportForm.show,this.reportForm);
            this.maininfotopRowMyAssetList = Ext.get('addremovemyassets');
            this.maininfotopRowMyAssetList.on('click',mam.addRemoveAsset,mam);
            if(mam.getAssetList().indexOf(this.selectedLi.row[this.rowIndex['id']] + "|") != -1)
            {
                this.maininfotopRowMyAssetList.dom.innerHTML = "הסר מהנכסים שלי";
                this.maininfotopRowMyAssetList.dom.className="btnaremove";
            }
            else
            {
                this.maininfotopRowMyAssetList.dom.innerHTML = "הוסף לנכסים שלי";
                this.maininfotopRowMyAssetList.dom.className="btnadd";
            }
            
            this.maininfotopRowMyAssetList.dom.id = 'display'+ this.selectedLi.row[this.rowIndex['id']];
            
            this.detailBox.slideIn('t', { duration: 0.4 ,callback:function(){
            if(this.constBanner)
            {
                bmanager.remove(this.constBanner);
            }
            this.constBanner = bmanager.add('13308','470','63',this.infoBanner);
            },scope:this});
            //this.infoTree
            
            // add pic_manager
         
         
            if(this.selectedLi.row[this.rowIndex['vPicCount']] == 0 || this.selectedLi.row[this.rowIndex['vPicCount']] == null )
            {
                Ext.get('asset_show_larg_pic_txt').dom.innerHTML = "לא נמצאו תמונות";
            }
            else
            {
                Ext.get('asset_show_larg_pic_txt').on("click",this.showLargPic,this);
                this.picBox.on("click",this.showLargPic,this);
                this.largImgNavBack.dom.innerHTML = "◄1";
                this.largImgNavNext.dom.innerHTML = " / " + this.selectedLi.row[this.rowIndex['vPicCount']] + "►";
                
                
            }
            
            this.currentDisplayedPicture = 1;
            // http://192.118.97.206/zazim/img.img?AddId=1069762&ImageNo=5&Width=143&Height=108
            //this.picurl + 
            //
            
            this.picBox.dom.src = this.picurl + this.selectedLi.row[this.rowIndex['id']] + "&ImageNo=" + this.currentDisplayedPicture + "&Width=110&Height=80" ;
            
        }
        
    },
    printAdd : function()
    {
        
        print.add([{data:this.selectedLi.row,index:this.rowIndex}])
        
    },
    showLargPic : function(evt)
    {
        
        //picChange
        var width = 350;
        var height = 300;
        
        if(this.selectedLi.row[this.rowIndex['vPicCount']] == 0 || this.selectedLi.row[this.rowIndex['vPicCount']] == null ) return;
        
        //this.largPic
        if(this.largPic.dom.style.display == "block")
        {
            this.largPic.dom.style.display='none'; 
        }
        else
        {
            if(this.largPic.dom.style.backgroundImage != "url('"+ this.picurl + this.selectedLi.row[this.rowIndex['id']] + "&ImageNo=" + this.currentDisplayedPicture + "&Width="+ width +"&Height="+ height  +"')")
                this.largPic.dom.style.backgroundImage ="url('"+ this.picurl + this.selectedLi.row[this.rowIndex['id']] + "&ImageNo=" + this.currentDisplayedPicture + "&Width="+ width +"&Height=" + height   +"')";
                

            this.largPic.dom.style.left = evt.getPoint().x +5 + "px";
            this.largPic.dom.style.top = evt.getPoint().y  + "px";
            this.largPic.dom.style.display = "block";
            
            this.largPic.fadeIn();
        }
        
        
        
    },
    moveLargPic : function(evt)
    {
        return;
        this.largPic.dom.style.left = evt.getPoint().x +5 + "px";
        this.largPic.dom.style.top = evt.getPoint().y -150 + "px";
        
    },
    hideLargPic : function()
    {
        //if(this.selectedLi.row[this.rowIndex['vPicCount']] ==0) return;
        //this.largPic.dom.style.display='none'; 
        
        this.largPic.fadeOut({
            endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
            easing: 'easeOut',
            duration: .5,
            remove: false,
            useDisplay: true
        });
    },
    
    LargPicChange : function(evt,src)
    {
        
        if(this.selectedLi.row[this.rowIndex['vPicCount']] ==0) return;
        
        var width = 350;
        var height = 300;
        
        if(src.id == "LargPicUp")
        {
          if(  this.currentDisplayedPicture == this.selectedLi.row[this.rowIndex['vPicCount']])
          {
            this.currentDisplayedPicture = 1;
          }
          else
          {
            this.currentDisplayedPicture++;
          }
        }
        else
        {
          if(  this.currentDisplayedPicture == 1)
          {
            this.currentDisplayedPicture = this.selectedLi.row[this.rowIndex['vPicCount']];
          }
          else
          {
            this.currentDisplayedPicture--;
          }
        }
        
        this.largImgNavBack.dom.innerHTML = "◄" + this.currentDisplayedPicture;
        
        //this.currentPicNum.dom.innerHTML = "◄" + this.currentDisplayedPicture;
        
        this.picBox.dom.src =this.picurl + this.selectedLi.row[this.rowIndex['id']] + "&ImageNo=" + this.currentDisplayedPicture + "&Width=110&Height=80";
        this.largPic.dom.style.backgroundImage ="url('"+ this.picurl + this.selectedLi.row[this.rowIndex['id']] + "&ImageNo=" + this.currentDisplayedPicture + "&Width="+ width +"&Height=" + height   +"')";
        
    },
    createDelegate : function(instance, method) {
		return function() {
			return method.apply(instance, arguments);
		}
	},
    getAptPic : function(url)
    {
        
        var parent = document.getElementById('picholder');
        document.getElementById('picholder').style.backgroundImage ="url('"+ url +"')";
        
        //var smallMap = Ext.get('areaSmallMap');
        var smallMap = Ext.get('minimap');
        smallMap.dom.style.backgroundImage ="url('"+ url +"')";
        return;
    },
    
    testMarkerProxy : function(div,txt)
    {
        if(!this.markerArray)return;
        if(this.markerArray.length == 0 ) return;
        var difnum = 30;
        
        var divy = (div.dom.style.top.toString().replace(/px/,"") *1);
        var divx = (div.dom.style.left.toString().replace(/px/,"") *1);
        for(var i=0; i <this.markerArray.length -1;i++)
        {
            var markerpic = Ext.get(this.markerArray[i]+"_marker");
            var oldy = (markerpic.dom.style.top.toString().replace(/px/,"") *1);
            var oldx = (markerpic.dom.style.left.toString().replace(/px/,"") *1);
            
            if( divx -difnum <= oldx && divx +difnum >= oldx)
            {
                if( divy -difnum <= oldy && divy +difnum >= oldy)
                {
                    var markertxt = Ext.get(this.markerArray[i]+"_marker_text");
                    if(markertxt.dom.innerHTML.substr(0,markertxt.dom.innerHTML.indexOf("(")) == txt.dom.innerHTML.substr(0,txt.dom.innerHTML.indexOf("(")))
                    {
                        //alert("same");
                        div.dom.innerHTML = "";
                        div.remove();
                        div=null;
                        txt.dom.innerHTML = "";
                        txt.remove();
                        txt= null;
                        this.markerArray.splice(this.markerArray.length-1,1);
                        return false;
                    }
                    else
                    {
                        var x = (divx + oldx) /2;
                        var y = (divy + oldy) /2;
                        markerpic.dom.style.top = y + "px";
                        markerpic.dom.style.left = x + "px";
                        if(markertxt.dom.innerHTML.indexOf(txt.dom.innerHTML) != -1 )
                            markertxt.dom.innerHTML = markertxt.dom.innerHTML + "<br>" + txt.dom.innerHTML;
                        div.dom.innerHTML = "";
                        div.remove();
                        div=null;
                        txt.dom.innerHTML = "";
                        txt.remove();
                        txt= null;
                        this.markerArray.splice(this.markerArray.length-1,1);
                        return false;
                        //alert("dif");
                    }
                    
                }
            }
        }
            return true;
    },
    createItemMarker : function(id,type,x,y,pic)
    {
        if(!this.markerArray)
        {
            this.markerArray = new Array();
        }
        
        this.markerArray[this.markerArray.length] = id;
    
    
        var displayWidth = 512;
        var displayHeight = 512;
        var textWidth = 100;
        
        //asset_display_sep
        
        var mapdiv= Ext.get('picholder');
        //mapdiv.dom.style.top = Ext.get('asset_display_sep').getBox().y - 55 +"px";
        mapdiv.dom.style.top = Ext.getBody().getScroll().top *1 + 40 + "px";
        mapdiv.dom.style.left = Ext.get('asset-detail-ancor').getBox().x +5 +"px";
        mapdiv.dom.style.width = displayWidth + "px";
        mapdiv.dom.style.height = displayHeight + "px";
        mapdiv.dom.style.display='block';
        mapdiv.dom.style.zIndex = "999999";
        
        //mapdiv.fadeIn();
        
        // create red dot
        var Div =  Ext.get(document.createElement('DIV'));
        Div.dom.id = id + "_marker";
        var TopLeftX = this.curretAssetX-1000;
        var TopLeftY = this.curretAssetY+1000;
        var WIDTH_METER = 2000;
        var PIXEL_PER_METER = 512/2000;
        Div.dom.className = "marker-bullet";
        Div.dom.style.backgroundImage = "url("+ pic + ")";
        Div.dom.style.position="absolute";
        var container = Ext.get('picholder').getBox();
        var markerx = ( ((x - TopLeftX)*PIXEL_PER_METER)*1  - 7);
        var markery = (((TopLeftY - y)*PIXEL_PER_METER)*1 -7);
        
        //debugger;
        if(markerx -10 <= 0) markerx = markerx+10;
        if(markerx +10 >= container.width) markerx = markerx-10;
        
        if(markery -10 <= 0) markery = markery+10;
        if(markery +20 >= container.height) markery = markery-15;
        
        Div.dom.style.left =  markerx +"px";
        Div.dom.style.top = markery  +"px";
        Div.dom.style.zIndex = "1000000";
        
        
        
        
        // create text node
        var Text =  Ext.get(document.createElement('DIV'));
        Text.dom.id = id + "_marker_text";
        Text.dom.style.width = textWidth + "px";
        Text.dom.className = "marker-text";
        Text.dom.innerHTML = type;
        Text.dom.style.position="absolute";
        
        // test text position
        
        var textx=0;
        var texty= markery + 17;
        if( markerx + ((textWidth/2)*1) < displayWidth )
        {
          textx = markerx - ((textWidth/2)*1);
          
        }
        else
        {
            textx = markerx - ((textWidth/2)*1);
            //textx = displayWidth - ((textWidth/2)*1) - 4;
        }
        if( markerx - ((textWidth/2)*1) < 0  )
        {
            //textx = 2;
        }
        
        
        
        Text.dom.style.top = texty + "px";
        Text.dom.style.left = textx + "px";
        
        
        
        if(this.testMarkerProxy(Div,Text))
        {
            Div.appendTo(Ext.get('picholder'));
            Text.appendTo(Ext.get('picholder'));
        }
        
        
        
        //Div.dom.innerHTML = type;
        
        //xadddatapriceandpics
        
    },
    removeTreeMarkers : function()
    {
        if(!this.markerArray) return;
        for(var i=0; i<this.markerArray.length;i++)
        {
            var markerpic = Ext.get(this.markerArray[i]+"_marker");
            var markertxt = Ext.get(this.markerArray[i]+"_marker_text");
            
            markerpic.dom.innerHTML = "";
            markerpic.remove();
            markerpic=null;
            markertxt.dom.innerHTML = "";
            markertxt.remove();
            markertxt = null;
            
        }
        this.markerArray=null;
        var mapdiv= Ext.get('picholder');        
        mapdiv.dom.style.display='none';
    },
    removeItemMarker : function(id)
    {
        var mapdiv= Ext.get('picholder');        
        mapdiv.dom.style.display='none';
        
        this.removeTreeMarkers();
        /*
        var t = Ext.get(id+"_marker");
        
        t.dom.innerHTML = '';
            t.remove();
            t = null;
            
        t = Ext.get(id+"_marker_text");
            t.remove();
            t = null;
          */  
        return;
    },
    fillAreaInfoTree : function(list,assetx,assety)
    {
        //debugger;
        
        if(this.tree)
        {
            
            this.tree.clearTreeFromContainer();
        }
        
        var items = eval(list.responseText);
        
        
        for(var i=0; i<items.length;i++)
        {
            if(items[i].type == "תיכונים")
                items[i].type= "בתי ספר";
        }
        
        var mytree = new tree('infotree','טבלת מרחקים');
        var currentDistance =0;
        var currentCategory = "";
        var subtree=null;
        var itemName= "";
        var writeDistance = 0;
        var xy="";
        if(items.length ==0) return;
        for(var i=0; i<items.length;i++)
        {
            xy=items[i].x + "," + items[i].y;
            writeDistance = items[i].distance;
            if(writeDistance.toString().indexOf(".") != -1)
                    {
                        writeDistance = writeDistance.toString().substr(0,writeDistance.toString().indexOf("."));
                    }
            itemName = (items[i].name =="" ? "ללא שם." :items[i].name )+ ' (' + writeDistance + ' מ)';
            if (itemName.length > 19)
            {
                itemName = '<acronym title="' + itemName + '">' + itemName.toString().substr(0,15) + "..." + '</acronym>';
            }
            if(items[i].type != currentCategory )
            {
                
                if(subtree != null)
                {
                    if(currentDistance.toString().indexOf(".") != -1)
                    {
                        currentDistance = currentDistance.toString().substr(0,currentDistance.toString().indexOf("."));
                    }
                    subtree.titleName += "(" + (currentDistance * 1 )  + " מ)";
                }
                
                
                if(!mytree.subtreebyname) mytree.subtreebyname = [];
                if(mytree.subtreebyname[items[i].type] == null)
                {   
                    subtree =  mytree.addSubTree('tree_'+i, items[i].type );
                    mytree.subtreebyname[items[i].type] = subtree;
                    try
                    {
                        Ext.get(items[i].type).first().on('mouseover',subtree.mouseover,subtree);
                        Ext.get(items[i].type).first().on('mouseout',subtree.mouseout,subtree);
                        
                        Ext.get(items[i].type).first().dom.src = Ext.get(items[i].type).first().dom.src.toString().replace(/gray/g,"");
                        Ext.get(items[i].type).first().dom.style.cursor = "pointer";
                        subtree.markerpic = Ext.get(items[i].type).first().dom.src;
                    }
                    catch(ex)
                    {
                        
                    }
                }
                else
                {
                    subtree = mytree.subtreebyname[items[i].type];
                }
                
                
                    
                currentCategory = items[i].type;
                var item = subtree.addItem(i,itemName,xy );
                item.orgtext = (items[i].name =="" ? "ללא שם." :items[i].name )+ ' (' + writeDistance + ' מ)';
                //this.createItemMarker(i,items[i].type,items[i].x,items[i].y);
                
                //subtree.addItem(i,items[i].name + '( ' + (items[i].distance*1) + ' מטר )' );
                currentDistance = items[i].distance * 1;
            }
            else
            {
                if(currentDistance > items[i].distance *1  )
                {
                    currentDistance = items[i].distance *1 ;
                }
                
                var item =subtree.addItem(i,itemName,xy );
                item.orgtext = (items[i].name =="" ? "ללא שם." :items[i].name )+ '(' + writeDistance + ' מ)';
                //this.createItemMarker(i,items[i].type,items[i].x,items[i].y);
            }
        }
        
        if(currentDistance.toString().indexOf(".") != -1)
                    {
                        currentDistance = currentDistance.toString().substr(0,currentDistance.toString().indexOf("."));
                    }
        subtree.titleName += " ( " + (currentDistance * 1 )  + " )";
        //this.infoTree.dom.innerHTML="";
        mytree.drow('',true,this.infoTree.dom);
        this.infoTree.dom.style.display = 'block';
        
        this.tree = mytree;
        mytree.itemEnter = this.createDelegate(this,this.showMarkerOnMap);
        mytree.itemLeave = this.createDelegate(this,this.hideMarkerOnMap);
        mytree.treeEnter = this.createDelegate(this,this.showMarkersOnMap);
        mytree.treeLeave = this.createDelegate(this,this.hideMarkersOnMap);
    },
        showMarkerOnMap : function(item,pic,b,c)
        {
            
            this.createItemMarker(item.id,item.orgtext,item.value.split(",")[0],item.value.split(",")[1],pic);
        },
        hideMarkerOnMap : function(item)
        {
            this.removeTreeMarkers();
            
            
        },
        showMarkersOnMap : function(root)
        {
            
            if(root.type == "tree") return;
            this.hideMarkersOnMap();
            for(var i=0;i<root.items.length;i++)
            {
                if(root.items[i].type != "subtree")
                    this.showMarkerOnMap(root.items[i],root.markerpic);
            }
            
        },
        hideMarkersOnMap : function(root)
        {
            this.removeTreeMarkers();
        },
        reShowPrice: function()
        {
            this.priceChangeDiv.toggleClass('x-adddata-hide');
            this.distanceDiv.toggleClass('x-adddata-hide'); 
        },
        ShowHideContactDetail : function()
        {   
            if(Ext.get('contactDetails') == null)
            {
                this.contactDetails = this.CreateDiv('contact-details',Ext.getBody());
                this.contactDetails.dom.id = "contactDetails";
            }
            if(this.contactDetails.dom.innerHTML == "")
            {
            
                this.contactDetails.dom.style.top =  this.contactAptLink.getBox().y + 12 + "px";
                this.contactDetails.dom.style.left =  this.contactAptLink.getBox().x + "px";
                var text = "<DIV> איש קשר : " + this.selectedLi.row[this.rowIndex['Contact']] + " </DIV>";
                text+="<DIV> טלפון : " + this.selectedLi.row[this.rowIndex['PhoneA']] + 
                (this.selectedLi.row[this.rowIndex['PhoneB']] !=''? ("," + this.selectedLi.row[this.rowIndex['PhoneB']]) :'')+
                " </DIV>";
                this.contactDetails.dom.innerHTML = text;
                //this.rowIndex['PhoneA']
                //this.selectedLi.row[this.rowIndex['Contact']]
                
                this.contactDetails.dom.style.display='block';
            }
            else
            {
                this.contactDetails.dom.innerHTML = "";
                this.contactDetails.dom.style.display='none';
            }
        }
};

// AJAX PROTOTYPE _____________________________________________



treeAjax = function ()
{
	this.req = {};
	this.isIE = false;
}



treeAjax.prototype.makeRequest = function (url, meth, onComp, onErr)
{
	
	if (meth != "POST")
		meth = "GET";
	
	this.onComplete = onComp;
	this.onError = onErr;
	
	var pointer = this;
	
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest)
	{
		this.req = new XMLHttpRequest();
		this.req.onreadystatechange = function () { pointer.processReqChange() };
		this.req.open("GET", url, true); //
		this.req.send(null);
	// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
		if (this.req)
		{
			this.req.onreadystatechange = function () { pointer.processReqChange() };
			this.req.open(meth, url, true);
			this.req.send();
		}
	}
}


treeAjax.prototype.processReqChange = function()
{
	
	// only if req shows "loaded"
	if (this.req.readyState == 4) {
		// only if "OK"
		if (this.req.status == 200)
		{
			this.onComplete( this.req );
		} else {
			this.onError( this.req.status );
		}
	}
}




