
function update_rent_table( buildings ){
  var div = rent_table_div();
  room_num = 1;
  if (buildings[0].rooms == "0"){
    div.innerHTML = empty_rent_table();
    return;
  }

  rent_table_html = rent_table_header();
  buildings.sort( building_comparator );
  for(i = 0; i < buildings.length ;i++){
    var b = buildings[i];
    if ( buildings[i].rooms.length == 1){
      rent_table_html = rent_table_html + rent_table_entry( b, b.rooms[0], room_num, false );
      room_num++;
    } else {
      for(j = 0; j < b.rooms.length ;j++){
        rent_table_html = rent_table_html + rent_table_entry( b, b.rooms[j], room_num, true );
        room_num++;
      }
    }
  }
  rent_table_html = rent_table_html + rent_table_footer();
  div.innerHTML = rent_table_html;
  return rent_table_html;
}


function empty_rent_table(){
    return '<div class="googlemap_list_box_t"><table class="googlemap_list" cellpadding="0" cellspacing="1" border="0"><tr><th class="title">物件名</th><th>賃料1</th><th>賃料2</th></tr></table></div><div class="googlemap_list_box"><table class="googlemap_list" cellpadding="0" cellspacing="1" border="0"><tr class="x"><td class="f11" width="300px">物件はありません</font></td><tr></table></div></div>';
}

function rent_table_header(){
    return '          <div id="RoomList">'+
    '            <h2 class="TitleRoomList"><img src="/bman3/img/search/img_map_subtitle_room.gif" alt="おすすめ物件一覧" /></h2>'+
    '            <ul>';
}

function rent_table_entry( b, r, room_num, is_grouped ){
  var css = ( room_num % 2 == 1 ? 'x' : 'o');
  var room_id = ( is_grouped ? b.rooms[0].id : r.id );
  var set_center_flag = ( is_grouped ? 1 : 0);
  
  return '              <li class="w">'+
    '                <dl>'+
    '                  <dt>'+
    '                    <a href="javascript:setcenter_no_search(' + (parseFloat(b.x)+0.0000016) + ',' + (parseFloat(b.y)+0.0016) + ',' + b.building_id + ',' + set_center_flag + ');">' + r.name + '</a>'+
    '                    <span>' + r.address + r.house_number + '</span>'+
    '                  </dt>'+
    '                  <dd class="TypeA">'+
    '                    ' + r.rent_per_day + '円/日<br />'+
    ( (r.rent_per_some_name == null) ? "" :  
     '                    ' + r.rent_per_some + '' + r.rent_per_some_name )+
    '                  </dd>'+
    '                  <dd class="TypeB">'+
    '                    ' + r.rent_per_day2 + '円/日<br />'+
    ( (r.rent_per_some_name2 == null) ? "" :  
     '                    ' + r.rent_per_some2 + '' + r.rent_per_some_name2 )+
    '                  </dd>'+
    '                </dl>'+
    '              </li>';
}

function rent_table_footer(){
  return '            </ul>'+
    '          </div>'+
    '        </div>';

}

function rent_table_div(){
  return document.getElementById('bman3_rent_table');
}


