var xmlHttp;
var map;
var flat_id;
var message ;
var messageid ;
var flat ;
var flon ;
var marker;
var innerHTML;
function showMap(SMD,Scity,Sdis,SHtype,Smina,Smaxa,Sstartime,Sdeptime,Sminp,Smaxp,keyword)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("您的浏览器不支持AJAX！");
  return;
  } 
var url="/gethotel.asp";
url=url+"?MD="+SMD;
url=url+"&dis="+Sdis;
url=url+"&city="+Scity;
url=url+"&htype="+SHtype;
url=url+"&mina="+Smina;
url=url+"&maxa="+Smaxa;
url=url+"&startime="+Sstartime;
url=url+"&deptime="+Sdeptime;
url=url+"&minp="+Sminp;
url=url+"&maxp="+Smaxp;
url=url+"&key="+keyword;
url=url+"&sid="+Math.random();
//alert(url);
xmlHttp.onreadystatechange=getLocationsAndMapCallback;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function getLocationsAndMapCallback() {
// state == 4 is when the response is complete
if (xmlHttp.readyState == 4) {              
  // Deserialize the JSON response (eval() command)
  // This creates an array of location objects. 
  var response = eval("("+xmlHttp.responseText+")");
  // generate HTML listing the locations and update  
  //   the page DOM so the user will see the HTML
  var div = document.getElementById('map_list');         

  document.getElementById("map_list").innerHTML   =   "";
  if (response.locations.location.length==0)
  {
	  document.getElementById("map_list").innerHTML   =   "No result";
  }
  for(i=0;i < response.locations.location.length; i++) {
	  if (i==0)
	  {
		  messageid  =  response.locations.location[i]["id"];
		  flat = response.locations.location[i]["latitude"];
		  flon = response.locations.location[i]["longitude"];
	  }else{
		  messageid  = messageid +","+ response.locations.location[i]["id"];
	  }	
  }
	message = messageid.split(",");//
if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
    map.setCenter(new GLatLng(flat,flon), 13);
  
    // 在给定点创建标记
    // 点击标记时会隐藏它
 //alert(document.getElementById("deptime").value);
  var innerHTML ="";
  for(i=0;i < response.locations.location.length; i++) {
        var flat_id = response.locations.location[i].id;
        var flat_name = response.locations.location[i].flat_name;
        var longitude = response.locations.location[i].longitude;
        var latitude = response.locations.location[i].latitude;
        var imgscr	 = response.locations.location[i].photo;
        innerHTML += "<div class=\"box\"><a href=\"/flat/show_flat.asp?id=" + flat_id + "\" target='_blank'><img  width=117 height=94  src=\"" + imgscr + "\"></a><p><a href=\"/flat/show_flat.asp?id=" + flat_id + "\" target='_blank' >" + flat_name + "</a></p></div>";
		var marker = createBridgeMarker(flat_id, flat_name,latitude, longitude,imgscr);
	    map.addOverlay(marker);
		}
		document.getElementById("map_list").innerHTML   =   innerHTML;
	  } // end  for loop
	} // end   if (state == 4)
} // end   function
    


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

