  function getXMLVar(xml_obj){
    result = "";
    if(xml_obj && xml_obj.firstChild){
      result = xml_obj.firstChild.data;
    }
    return result;
  }

  function getZoomLevel(){
    var zl = map_zoom_level;
    var czl = -1;
    var dwidth = Math.abs(map_left_top_x-map_right_bottom_x);
    var dheight = Math.abs(map_left_top_y-map_right_bottom_y);
    for(var i=0;i<zoom_properties.length;i++){
      if((zoom_properties[i][0]>=dwidth) && (zoom_properties[i][1]>=dheight)){
        czl = i;
      }
    }
    if(czl!=-1){
      zl = czl;
    }
    return zl;
  }

  function updateMap() {
    centered_zoom = true;
    map.clearOverlays();
    map.setCenter(new GLatLng(map_ctr_lat,map_ctr_lng), map_zoom_level);
    for (var i=0; i<listings_array.length; i++) {
      var lng = listings_array[i].lng;
      var lat = listings_array[i].lat;
      var point = new GLatLng(lat,lng);
      var marker = createMarker(point, i);
      map.addOverlay(marker);
    }
    dataRecievingMsg(false);
    centered_zoom = false;
  }

  function goLnav(direction){
    if(data_loading==false){
      page_current = page_current + direction;
      create_lnav();
      var url = url_get_list+"&xml=1&ndd=1&page="+direction;
      loadListData(url);
    }
  }

  function getIconID(pic_name){
    result = false;
    for(var i=0;i<icons_lib.length;i++){
      if(icons_lib[i].image.indexOf(pic_name)!=-1){
        result = i;
      }
    }
    return result;
  }

  function showListBlock(switcher){
    dataRecievingMsg(false);
    if(switcher==true){
      document.getElementById("show_list_box").style.display = "block";
      document.getElementById("show_list_box").style.visibility = "visible";
      document.getElementById("top_right_box").style.visibility = "visible";
      document.getElementById("top_right_box2").style.visibility = "visible";
      document.getElementById("top_right_box2").style.display = "block";
    } else {
      document.getElementById("show_list_box").style.display = "none";
      document.getElementById("show_list_box").style.visibility = "hidden";
      document.getElementById("top_right_box").style.visibility = "hidden";
      document.getElementById("top_right_box2").style.visibility = "hidden";
      document.getElementById("top_right_box2").style.display = "none";
    }
  }
  function showMapBlock(switcher){
    if(switcher==true){
      document.getElementById("map_under").style.display = "block";
      document.getElementById("show_map_box").style.visibility = "visible";
    } else {
      document.getElementById("show_map_box").style.visibility = "hidden";
      document.getElementById("map_under").style.display = "none";
    }
  }
  function showLoadingBlock(switcher){
    if(switcher==true){
      document.getElementById("show_loading").style.display = "block";
      document.getElementById("show_loading").style.visibility = "visible";
    } else {
      document.getElementById("show_loading").style.display = "none";
      document.getElementById("show_loading").style.visibility = "hidden";
    }
  }

  function loadListData(url){
    showListBlock(false);
    if(total_listings>0 || total_listings==-1){
      showLoadingBlock(true);
      AJAXUrlObj.set(url+additional_url_params,send_params);
//      prompt("aaa",url+additional_url_params+send_params);
//      loadData(url+additional_url_params);
      loadData(AJAXUrlObj);
    } else {
      updateList(true);
      showListBlock(true);
    }
  }

  function loadMapData(url){
    showMapBlock(false);
    showLoadingBlock(true);
    AJAXUrlObj.set(url+additional_url_params,send_params);
//    loadData(url+additional_url_params);
    loadData(AJAXUrlObj);
  }


  function getDisclaimers(listings_array){
    var ret = "";
    if(listings_array.length>0){
      var disclaimers = new Array();
      for (var i=0; i<listings_array.length; i++) {
        var lst = listings_array[i];
        if(lst.light_mls&&lst.light_mls!='false'){
          var disclaimer = lst.disclaimer;
          if(disclaimer&&!disclaimers[lst.mls]){
            disclaimers[lst.mls] = disclaimer;
          }
        }
      }
      for(mls in disclaimers) {
        if(disclaimers[mls]){
          ret += disclaimers[mls];
        }
      }
    }
    return ret;
  }

  function mapInfoBlock(type,lid){
    var ls = document.getElementById("map_info_block");
    if(type=="details"){
      is_ld_show = true;
      showMapInfo("details");
      if(lid>=0){
        ln = listings_array[lid];
        current_listing_details = ln;
        var details_link = "showDetails(current_listing_details);";
        var request_appointment_link = "showAppointment(current_listing_details);";
        var request_moreinfo_link = "showMoreInfo(current_listing_details);";
        var preparedStatus = "";
        if(ln.status=="Sold" && ln.lclass=="Residential Lease" && ln.mls=="MRIS"){
          preparedStatus = "Rented";
        }else{
          preparedStatus=ln.status;
        }
        var s = ""+
                "<table width='100%' height='380' cellpadding='0' cellspacing='0'><tr><td valign='top'>"+
                "<table width='100%' cellpadding='0' cellspacing='0'><tr><td bgcolor='#A5A2A5'>"+
                "<table width='131' height='99' cellpadding='0' cellspacing='1'>"+
                "<tr><td align='center' bgcolor='#FFFFFF'><a href='javascript:"+details_link+"'><img src='"+ln.photo+"' width='129' height='97' border='0' onError='this.src=\"http://isvr.net/empty_image.gif\"'/></a></td></tr>"+
                "</table>"+
                "</td></tr></table>"+
                "<table width='100%' cellpadding='0' cellspacing='4'>";
                if(ln.lclass!=""){
                  s += "<tr><td class='d' colspan='2'><b>"+ln.lclass+"<br></b></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.status!=""){
                  s += "<tr><td class='d' colspan='2' style='color:#ff0000'>"+preparedStatus+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.price!=""){
                  s += "<tr><td class='d' style='color:#707070'><b>Price:<br></b></td><td class='d' align='right'>"+ln.price+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.bedrooms!=""){
                  s += "<tr><td class='d' style='color:#707070'><b>Bd:<br></b></td><td class='d' align='right'>"+ln.bedrooms+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.bathrooms!=""){
                  s += "<tr><td class='d' style='color:#707070'><b>Bth:<br></b></td><td class='d' align='right'>"+ln.bathrooms+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.square_feet!=""){
                  s += "<tr><td class='d' style='color:#707070'><b>SqFt:<br></b></td><td class='d' align='right'>"+ln.square_feet+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.lot_size!=""){
                  s += "<tr><td class='d' style='color:#707070'><b>Lot:<br></b></td><td class='d' align='right'>"+ln.lot_size+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.full_location!=""){
                  s += "<tr><td colspan='2' class='d' style='color:#707070'><b>Address:<br></b></td></tr>"
                      +"<tr><td colspan='2' class='d'>"+ln.full_location+"<br></td></tr>"
                      +"<tr><td colspan='2' bgcolor='#c0c0c0'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>";
                }
                if(ln.company_name!="" && ln.mls != "SOCAL"){
                  if (ln.light_mls=='true') {
                    s += "<tr><td colspan='2' class='d' style='color:#707070'>Courtesy of "+ln.company_name+"<br></td></tr>";
                  } else {
                    s += "<tr><td colspan='2' class='d' style='color:#707070'>Presented by "+ln.company_name+"<br></td></tr>";
                  }
                }
                if(ln.mls=="REIL" && ln.status != "Pending do not show"){
                  s += "<tr><td colspan='2' align='center'><a href='#REIL_DISCLAIMER'><img src='http://isvr.net/BLE-logo-sm.gif' height='14' width='14' alt='' border='0'/></a></td></tr>";
                } else if (ln.mls=="MLSNI"){
                  s += "<tr><td colspan='2' align='center' bgcolor='#ffffff'><img src='http://isvr.net/MLSNI-logo-sm.gif' width='82' height='20' alt='' border='0' vspace='3'/></td></tr>";
                } else if (ln.mls=="MAXEBRDI"){
                  s += "<tr><td colspan='2' align='center'><a href='#MAXEBRDI_DISCLAIMER'><img src='http://isvr.net/logo_MAXEBRDIsm.gif' height='24' width='45' alt='' border='0'/></a></td></tr>";
                } else if (ln.light_mls=='true'&&ln.idx_icon!='') {
                  s += "<tr><td colspan='2' align='center'><a href='#"+ln.mls+"_DISCLAIMER'><img src='"+ln.idx_icon+"' alt='' border='0'/></a></td></tr>";
                }
           s += ""+
                "</td></tr>"+
                "<tr><td colspan='2' align='center'><a href='javascript:"+details_link+"'><img src='http://isvr.net/org_b_details.gif' width='123' height='22' alt='DETAILS' border='0'/></a></td></tr>"+
                "<tr><td colspan='2' align='center'><a href='javascript:"+request_appointment_link+"'><img src='http://isvr.net/org_b_app.gif' width='123' height='22' alt='Schedule Showing Appointment' border='0'/></a></td></tr>"+
                "<tr><td colspan='2' align='center'><a href='javascript:"+request_moreinfo_link+"'><img src='http://isvr.net/org_b_info.gif' width='123' height='22' alt='Request More Information' border='0'/></a></td></tr>"+
//                "<tr><td colspan='2' height='22' align='center' background='http://isvr.net/maps/bg_dis.gif' class='d'><a href='javascript:"+details_link+"' style='text-decoration:none;color:#FFFFFF;'>Statistic</a></td></tr>"+
                "</table>"+
                "</td></tr>"+
                "</table>";
      } else {
        var s = "<br/>Please click on a property icon to see the details.";
      }
    } else {
      is_ld_show = false;
      showMapInfo("stats");
      var s = ""+
              "<table width='100%' height='396' cellpadding='0' cellspacing='0'><tr><td valign='top'>"+
              "<table width='100%' cellpadding='8' cellspacing='0'><tr><td valign='top' class='d'>"+
              "<br/>"+
              "Total listings "+total_listings+"<span style='color:#ff0000;'>*</span><br/>"+
              "<br/>"+
              "First "+map_total_view+" shown on the map<br/>"+
              "<br/>"+
              total_in_boundaries+" fall into the map boundaries<br/>"+
              "<br/>"+
              "Zoom or move the map to see more properties<br/>"+
              "</td></tr></table>"+
              "</td></tr>"+
              "<tr>"+
              "  <td valign='bottom'>"+
              "    <table width='100%' cellpadding='0' cellspacing='0'>"+
              "    <tr bgcolor='#A5A2A5'><td><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
              "    <tr><td height='39' align='center' class='basicAsm' style='color:#404040;'>ROLLOVER HOME ICONS TO VIEW QUICK STATS</td></tr>"+
              "    <tr bgcolor='#A5A2A5'><td><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
              "    <tr><td height='39' align='center' class='basicAsm' style='color:#404040;'>CLICK ON A HOME ICON FOR DETAILS</td></tr>"+
              "    <tr bgcolor='#A5A2A5'><td><img src='http:/isvr.net/p.gif' width='1' height='1'/></td></tr>"+
              "    <tr><td><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
              "    <tr bgcolor='#A5A2A5'><td><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
              "    <tr>"+
              "      <td bgcolor='#D8D8D8' class='d' style='color:#404040;'>"+
              "        <img src='http://isvr.net/p.gif' width='1' height='5'/><br>"+
              "        <b>&#160;Legend:<br></b>"+
              "        <img src='http://isvr.net/p.gif' width='1' height='1'/><br>"+
              "        <img src='http://isvr.net/maps/map_legend.gif' width='131' height='48'/><br>"+
              "      </td>"+
              "    </tr>"+
              "    </table>"+
              "  </td>"+
              "</tr>"+
              "</table>";
    }
    ls.innerHTML = "";
    ls.innerHTML = s;
  }

  function onMapMove(who){
    if(map_change == true){
      debugJS("Map event "+who);
      var mbounds = map.getBounds();
      var url = url_get_map+"&xml=1&ndd=1&left="+mbounds.getSouthWest().lng()+"&right="+mbounds.getNorthEast().lng()+"&top="+mbounds.getNorthEast().lat()+"&bottom="+mbounds.getSouthWest().lat()+additional_url_params;
//      prompt("aaa",url);
      AJAXUrlObj.set(url,send_params);
//      loadData(url);
      loadData(AJAXUrlObj);
      map_change = false;
    }
  }

  function dataRecievingMsg(switcher){
    if(document.getElementById("map_loading")){
      if(switcher==true){
        document.getElementById("map_loading").style.display = "block";
        document.getElementById("map_loading").style.visibility = "visible";
      } else {
        document.getElementById("map_loading").style.display = "none";
        document.getElementById("map_loading").style.visibility = "hidden";
      }
    }
  }

  function getMousePos(e){
    oCanvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
    posX = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
    posY = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
  }

  function viewResults(status){
    if(data_loading==false){
      if(status=="Map"){
        init_map_data = false;
        var url = url_get_map+"&xml=1&ndd=1";
        document.getElementById("buttMap").className = "buttActive";
        document.getElementById("buttList").className = "butt";
        showListBlock(false);
        showMapBlock(true);
        show_type = "Map";
        showNotesBlock(true,show_type);
        loadMapData(url);
      }
      if(status=="List"){
        init_map_data = false;
        var url = url_get_list+"&xml=1&ndd=1&page="+page_current;
        document.getElementById("buttList").className = "buttActive";
        document.getElementById("buttMap").className = "butt";
        showMapBlock(false);
        showListBlock(true);
        show_type = "List";
        showNotesBlock(true,show_type);
        loadListData(url);
      }
    }
  }

  function showMapInfo(type){
    if(document.getElementById("buttStats") && document.getElementById("buttDetails")){
      if(type=="stats"){
        document.getElementById("buttStats").className = "sbuttActive";
        document.getElementById("buttDetails").className = "sbutt";
      }
      if(type=="details"){
        document.getElementById("buttDetails").className = "sbuttActive";
        document.getElementById("buttStats").className = "sbutt";
      }
    }
  }

  function showNotesBlock(switcher,status){
    var ls = document.getElementById("bottom_notes_text");
    var s = "";
    if(status=="Map"){
      s += getDisclaimers(listings_array);
      s += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td valign='top' class='d'>*</td><td valign='top' class='d'>Not all the properties can be mapped due to incomplete address.<br>Use \"Show results as a list\" to see all the properties.</td></tr></table>";
    }
    if(status=="List"){
//      s = "Information deemed reliable but not guaranteed to be accurate.";
    }
    ls.innerHTML = "";
    ls.innerHTML = s;
    if(switcher==true&&status=="Map"){
      document.getElementById("bottom_notes_block").style.display = "block";
      document.getElementById("bottom_notes_block").style.visibility = "visible";
    } else {
      document.getElementById("bottom_notes_block").style.display = "none";
      document.getElementById("bottom_notes_block").style.visibility = "hidden";
    }
  }

  function viewIpix(url) {
    var checkHTTP = url;
    if (checkHTTP.indexOf("http://")!=0 && checkHTTP.indexOf("https://")!=0){
      fileURL="http://" + url;
    } else {
      fileURL = url;
    }
    common_viewTour(fileURL);
  }
  
  function openUrl(url) {
    var bars = '';
    bars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=yes,scrollbars=yes,resizable=yes,width=640,height=700'    
    var newWin = open ('', '', bars);
    newWin.document.location.href = url;
    newWin.focus();
  }

  function showErrorMsg(error_msg){
/*    var results = "";
    for(var i=0;i<results_arr.length;i++){
      results += results_arr[i];
      if(i<results_arr.length-1){
        results += ", ";
      }
  }*/
    var ls = document.getElementById("list");    
    var s = ""+
            "<table width='100%' height='260' cellpadding='10' cellspacing='0' border='0'>"+
            "<form name='app_form'>"+
            "<tr>"+
            "  <td bgcolor='#ffffff' align='center'>"+
            "    <table cellpadding='4' cellspacing='2'>"+
            "    <tr><td colspan='2' height='22' class='basicVb' style='color:#ad0000;'>Error:<br><img src='http://isvr.net/p.gif' height='5' width='1'><br></td></tr>"+
            "    <tr><td colspan='2' class='d'>"+error_msg+"</td></tr>"+
            "    </table>"+
            "  </td>"+
            "</tr>"+
            "</form>"+
            "</table>";
    ls.innerHTML = "";
    ls.innerHTML = s;
    show_type = "";
    showLoadingBlock(false);
    showListBlock(true);
    document.getElementById("buttList").className = "butt";
    document.getElementById("top_right_box").style.visibility = "hidden";
    document.getElementById("top_right_box2").style.visibility = "hidden";
    document.getElementById("top_right_box2").style.display = "none";
  }