markerManager = function (dataTable) 
{
    
    this.dataTable = dataTable; // Html table to show adds data
    this.Data = [];
    
    // Lets Create The Row Templates
    // {invert}
    this.rowTemplate = new Ext.Template(
                  '<div class="row">',
                  '<div class="{invert}">',
                        '<div class="c-PDate" >{PDate}</div>',
                        '<div class="c-vPicCount"><img src="images/x-asset_list-camera.png" class="{vPicCount}" /></div>',
                        '<div class="c-Floor">{Floor}</div>',
                        '<div class="c-EntryWhen">{EntryWhen}</div>',
                        '<div class="c-RoomNumber">{RoomNumber}</div>',
                        '<div class="c-ShekelRent">{ShekelRent}</div>',
                        '<div class="c-Street">{Street}</div>',
                        '<div class="c-city">{city}</div>',
                        '<div class="c-AssetType">{AssetType}</div>',
                        '<div class="c-cBox"><input id="listchk{id}" type="checkbox" style="border:none;" onclick="mam.addRemoveAsset(this,event);" {checked}  /></div>',
                   '</div>',
                   '</div>'

    );
    this.rowTemplate = this.rowTemplate.compile();
    this.currentPage = 1;
    this.pageSize = 10;
    this.dataToShow = null;


    this.pageRows = [];
   
}


markerManager.prototype = 
{
    Data: null,
    ImgPath: null,
    prevRequests: null,
    rowIndex: null,
    // Table Stuff
    dataTable: null,
    rowTemplate: null,
    currentPage: null,
    pageSize: null,
    pageRows: null,
    dataToShow: null,
    
    
    
    drawPageOnChange: function()
    {
        var combo = Ext.get('pageSelector');
        var pageNo = combo.dom.options.selectedIndex + 1;
        
        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();
            }
        
        this.drawPage(pageNo);
             
    },
    drawPage: function (pageNo,Cols)
    {
        
        
            if(this.bannerList)
            {
                for(var i=0;i<this.bannerList.length;i++)
                {
                    bmanager.remove(this.bannerList[i],true);
                    this.bannerList[i] = null;
                }
                this.bannerList = new Array();
            }
           
            if (Cols) this.rowIndex = Cols;
            if (!this.rowIndex) return;
     
             var combo = Ext.get('pageSelector');
             combo.dom.onchange = null;
             combo.dom.options.length = 0;
              for (var i = this.pageSize; i <  map.getHousesCount() + this.pageSize; i += this.pageSize )
              {
                var el = document.createElement('option');
                el.value = i/this.pageSize;
                el.text = i/this.pageSize;
                combo.dom.options[ i/this.pageSize-1] = el;
              }
            if ( combo.dom.options.length == 1 || combo.dom.options.length == 0)
                Ext.get('x-asset_list-pageSelector').dom.style.display = 'none'
            else
                Ext.get('x-asset_list-pageSelector').dom.style.display = 'block';
          
            if ( map.getHousesCount() > 0)
            {
                if (pageNo)
                {
                    if (pageNo - 1 <= combo.dom.options.length)
                    {
                     this.currentPage = pageNo;
                    }
                    else
                    {
                     this.currentPage = 1;
                    }
                }
                else
                {
                    this.currentPage = 1;
                }
                if (combo.dom.options.length > 1) 
                {
                    combo.dom.options.selectedIndex = this.currentPage - 1;
                    combo.dom.onchange = this.drawPageOnChange.createDelegate(this);
                     
                }
            }
            for (var i = 0; i < this.pageRows.length; i++)
            {
                this.pageRows[i].rowId = null;
                this.pageRows[i].marker = null;
                this.pageRows[i].removeAllListeners();
                this.pageRows[i].remove();
                this.pageRows[i] = null;
                
            }
            this.pageRows = null;
            this.pageRows = [];
            //this.dataTable.dom.innerHTML = '';
            for (var i = (this.currentPage - 1) * this.pageSize; i < (this.currentPage) * this.pageSize && i <  map.getHousesCount(); i++)
            {
                
                if(i % assetsOnMapBanner == 0 )
                {
                    
                    if(!this.bannerList) this.bannerList = [];
                    if(this.bannerList.length <0)
                    {
                        this.bannerList[this.bannerList.length] = bmanager.add('13302','788','20',this.dataTable);
                    }

                }
                
                this.addRow(map.getHousesRow(i),i+1);
                
            }
            
            bmanager.removeHidden();

    },
    addRow: function (dataCell,index)
    {
    
          var tbl = this.dataTable.dom;
          if(dataCell == null) return;
          var _checked = "";
          if(mam.getAssetList() != null)
            if(mam.getAssetList() != "")
                if(mam.getAssetList().indexOf(dataCell[this.rowIndex['id']] + "|") != -1)
                    _checked = "checked";
          
          //debugger;
          var el = this.rowTemplate.append(this.dataTable,
              {
                invert : (index % 2 == 0) ? 'zeb' : 'row',
                AssetType: dataCell[this.rowIndex['AssetType']],
                city: dataCell[this.rowIndex['vCity']] ,
                Street: dataCell[this.rowIndex['vStreet']] ,
                "ShekelRent": dataCell[this.rowIndex['ShekelRent']] ,
                RoomNumber: dataCell[this.rowIndex['RoomNumber']] ,
                EntryWhen: dataCell[this.rowIndex['EntryWhen']] ,
                Floor: dataCell[this.rowIndex['Floor']] ,
                vPicCount: (dataCell[this.rowIndex['vPicCount']] == '0') ? 'hide' : '' ,
                PDate: dataCell[this.rowIndex['PDate']],
                id : dataCell[this.rowIndex['id']],
                checked : _checked
              });
              //alert(dataCell[this.rowIndex['pindex']]);
              
           el.pindex = dataCell[this.rowIndex['pindex']]; //pindex is marker index for some wierd reason
           el.rowId = dataCell[this.rowIndex['id']];
           Ext.get(el).addListener("mouseover", 
                        function(p1,p2,p3)
                                {
                                   map.HousesMarkerOver(this.pindex);
                                },
                        el);
            Ext.get(el).addListener("mouseout", 
                        function(p1,p2,p3)
                        {
                            map.HousesMarkerOut(this.pindex);
                        },
                        el);
                        
            Ext.get(el).addListener("mousedown", 
                        function(p1,p2,p3)
                        {
                            if(p2.tagName == "INPUT") return;
                            addsDataWindow.enlist(this.pindex,this.rowId);
                            //alert(this.pindex);
                        },
                        el);
                                            /*
            Ext.get(el).addListener("mousedown", 
                     el.marker.mouseDown.createDelegate(el.marker),
                     el.marker.icon.imageDiv.childNodes[0]);    */                       
           this.pageRows[this.pageRows.length] = Ext.get(el);
            

    },
    removeRow: function (dataCell)
    {
    
    }
}

