﻿
//实例化地图对象
var map;
var startlatlng;
var rectOverlay;
var rectBox;
var isBeginDraw=false;
var isDraw = false;
var mapoperatetype;
var markerList;
var hotelSet;
var infoWindowOffsetLeft = 240;
var infoWindowOffsetTop = 480;
var hotelmarkeroverlay;
var arrayMarker = new Array();

//加载地图
//<params>hasTools?:是否添加控制工具(true/false)</params>
//<params>isSetCenter?:是否设置地图中心(true/false)</params>
function load(hasTools,isSetCenter){
  var cityName = isSetCenter;
  
  if (isSetCenter){
    if (document.getElementById("CityName") != null &&
        document.getElementById("CityName").value != null &&
        document.getElementById("CityName").value != "")
    {
      cityName = document.getElementById("CityName").value;
    }else{
      cityName = "北京";
    }
  }
  
  map = new Map();
  map.load("map",cityName,hasTools);
  map.addListener(MapEvent.CLICK,onMapClick);
  map.addListener(MapEvent.MOUSEMOVE,onMapMouseMove);
  map.addListener(MapEvent.INFOWINDOWOPEN,onInfoWindowOpen);
}

//卸载地图
function unload(){
  if (map){
    map.unload();
  }
}

//设置繁体网地图Key
function setMapKeyOfBig5(){
  if (location.href.indexOf("big5.elong.com") > -1)
  {
    if (document.getElementById("maps_js") != null)
       document.getElementById("maps_js").src = "http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAAGStvxLW_DPTdcfPgL279exRxnnaWZekBftlqjhRhX8b_Rjr2RBTKjPoIf2W-CZkK1-PMbQ-MPYAIVQ";
  }
}

//注册地图API
function regMapApi(){
   if (typeof(language) != "undefined" && language == "en")
    document.write("<script src='http://ditu.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAZqr862R-vwRvAk2z9Fz0MBTUePom3BZIuI15Lb-l8AqgP_hU1RTKRygV84bt1u2cjJEr1YaLLpAvVw' type='text/javascript'></script>");
  else
    document.write("<script src='http://ditu.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAZqr862R-vwRvAk2z9Fz0MBTBvvqy1tEhAFkvYrLGdXIDdhuQ1RRT0GvPHHeA3kEs6zXaNMilGA9a0A' type='text/javascript'></script>");
}

//定位到城市
function moveToCity(cityName){
  if (cityName && cityName.length > 0){
    map.getLatLng(cityName,function(point){
      if (point){
        map.setCenter(point, 13);
      }
    });
  }
}

//添加一个酒店标注
function addHotelMarker(lat,lng,name){
  if (lat && lat != 0 && lng && lng != 0){
    var latlng = new LatLng(lat,lng);
    var imageurl = {url:"http://resource.elong.com/cn/hotels/images/hotel_map.gif",width:21,height:21};
    var marker = map.createLabeledMarker(latlng.toGLatLng(),true,imageurl,true,{id:0,title:name,clickable:false,draggable:false,labelText:name,labelOffset:new Size(5, -23)});
    
    map.setCenter(latlng,13);
    map.addOverlay(marker);
    
    //var point = map.fromLatLngToDivPixel(map.getCenter());
    //map.showTitle(new Point(point.x,point.y),name);
  }
}

//添加一个酒店标注  Add by AX
function addLabelMarker(lat,lng,name,price,imageNum,image,area,star,hotelID,areaLink,firstHotelNum)
{
  if (lat && lat != 0 && lng && lng != 0)
  {
    if(name.length>15)
    name=name.substring(0,15)+"…";
    var qi="<span style='font-size:12px;color:#707070;'>起</span>";
    if(price=="--")
    {
       price="特价";
       qi="";
    }
    else
        price="&yen;"+price;        
    if(area.length>6)
        area=area.substring(0,6)+"...";    
    if(star>9&&star<51)
        star= "<img src='http://resource.elong.com/cn/hotels/images/"+star+"x.gif' border='0' align='absmiddle' alt='' />";
    else
        star="";
    var imageurl = {url:"http://resource.elong.com/cn/hotels/images/h_"+imageNum+".gif",width:15,height:15};      
    var marker = map.createLabel(lat,lng,imageurl,true,true,
        "<div style='white-space:nowrap;background:#99CCFF;color: #001D75;border:1px #001D75 solid;font-weight:bolder;font-family:Arial;height:15px;width:40px;line-height:15px;font-size:12px;text-indent:2px;text-align:left;'>"+price+"</div>",
        0,-26,
        "<div style='background:white;width:240px;height:120px;border:1px #001D75 solid;font-size:12px;text-align:left;'> 	<div style='width:119px;text-align:left;float:left;height:17px;line-height:16px;font-weight:bolder;font-family:Arial;font-size:12px;background:#99CCFF;text-indent:4px;'>"+price+"</div><div style='width:116px !important;width:116px;float:right;height:14px !important;height:14px;line-height:16px;background:#99CCFF;;text-align:right;padding:2px 5px 0 0;'>"+star+"</div> 	<h2 style='width:230px;font-size:12px;font-family:宋体;text-align:left;font-weight:bolder;margin:3px;color:#c20001;padding-top:5px;clear:both;'><a href='http://www.elong.com/hotels/details.aspx?m=details&hotelid="+hotelID+"'>"+name+"</a></h2> 	<div style='width:240px;margin:0;padding:0;'> 		<div style='width:74px;float:left;margin-right:6px;'><a href='http://www.elong.com/hotels/details.aspx?m=Image&hotelid="+hotelID+"'><img src='"+image+"' border='0' style='width:70px;height:70px;margin:4px;' alt='' onError=javascript:{this.src='http://resource.elong.com/cn/hotels/images/no.jpg'} /></a></div> 		<div style='float:right;width:140px;margin-right:3px;'> 		<ul style='width:100%;margin:0 2px 0 0;padding:0;list-style:none;'> 			<li style='font-size:18px;color:#ce1f1a;font-family:Arial;font-weight:bolder;'>"+price+qi+"&nbsp;&nbsp;<input type='button' value='预订' onclick=\"window.location='http://www.elong.com/hotels/details.aspx?m=Details&hotelid="+hotelID+"';\" style='height:22px;line-height:18px;background:#31669c;color:white;font-weight:bolder;border-top:1px #CACACC solid;border-right:1px #006600 solid;border-bottom:1px #006600 solid;border-left:1px #CACACC solid;cursor:pointer;' /></li> 			<li style='width:100%;margin:0 2px 0 0;padding:3px 0;list-style:none;'>位置：<a href='http://www.elong.com/hotel/"+areaLink+"'>"+area+"</a></li> 			<li style='width:100%;margin:0 2px 0 0;padding:3px 0;list-style:none;'><a href='http://www.elong.com/hotels/details.aspx?m=Commentary&hotelid="+hotelID+"'>用户评论</a>　<a href='http://www.elong.com/hotels/details.aspx?m=Image&hotelid="+hotelID+"'>360度全景</a></li> 		</ul> 		</div> 	</div> </div>",
        false);
    //展开第一个酒店的toolTip
//    if(imageNum==Number(firstHotelNum)+1)
//        marker.tipDiv.style.visibility="visible";   
    map.addOverlay(marker);
  }
  arrayMarker.push(marker); 
}

function setCenterForMap()
{
    var level=13;var eastWestDistance=0;var southNorthDistance=0;
    //必须是两个点,计算东西距离
    if (east != west)
    {
        var temp0=new GLatLng((north + south) / 2,east);
        var temp1=new GLatLng((north + south) / 2,west);
        eastWestDistance=temp0.distanceFrom(temp1);
    }
    //计算南北距离
    if (north != south)
    {
        var temp2=new GLatLng(north,(east + west) / 2);
        var temp3=new GLatLng(south,(east + west) / 2);
        southNorthDistance=temp2.distanceFrom(temp3);
    }
    //计算缩放比例
    if(eastWestDistance!=0&&southNorthDistance!=0)
    {
        if(eastWestDistance<563/68*1000&&southNorthDistance<300/68*1000)
        {level=13;}
        else if(eastWestDistance<563/68*2*1000&&southNorthDistance<300/68*2*1000)
        {level=12;}
        else if(eastWestDistance<563/68/2*10000&&southNorthDistance<300/68/2*10000)
        {level=11;}
        else if(eastWestDistance<563/68*10000&&southNorthDistance<300/68*10000)
        {level=10;}
        else if(eastWestDistance<563/68*20000&&southNorthDistance<300/68*20000)
        {level=9;}
    }else{level=13;}
    //设置中心
//    alert('缩放级别:'+level);
    map.setCenter(new GLatLng((north + south) / 2,(east + west)/2),level);
}

//展开一个酒店标注,
//MarkerNum为要展开的酒店序号,从1开始的,所以要减一
function expandMarker(MarkerNum)
{
    for(var i=0; i<arrayMarker.length;i++)
    {
        if(arrayMarker[i]!=undefined)
        arrayMarker[i].tipDiv.style.visibility="hidden";
    }
    arrayMarker[MarkerNum-1].tipDiv.style.visibility="visible";
    map.setCenter(arrayMarker[MarkerNum-1].getPoint());
}


//打印地图
function printMap(mapID)
{
    if (window.print) 
    {   
        var markContent="";
        var i=0;
        //查看是否显示出了Tootip
        for(i=0; i<arrayMarker.length;i++)
        {
            if(arrayMarker[i]!=undefined)
            {
                if(arrayMarker[i].tipDiv.style.visibility=="visible")
                {
                    arrayMarker[i].tipDiv.style.visibility="hidden";
                    markContent=arrayMarker[i];
                    break;
                }
            }
        }
        var divMapContent = getObj(mapID).innerHTML;
        var marker1="";
        var logoTop="350px";
        if(markContent!="")
        {
            logoTop="500px";
            marker1='<img src="http://resource.elong.com/cn/hotels/images/h_'+(i+1)+'.gif" style="margin-top:300px;margin-left:7px;"/><br />'+'<div style="margin-bottom:5px;margin-left:7px; width:240px;border:1px #001d75 solid;clear:both;font-size:12px;>'+markContent.tipDiv.innerHTML+'</div>';
        }
         var body ='<div > '+
        ' <div style="float: left; width: 563px; position:absolute;">'+
        '     <div id="map" style="width: 563px; height: 300px;margin:0 0 5px 8px;position:absolute;">'+divMapContent+
        '     </div>'+
        ' </div>'+
        '<br clear="all" />'+
        marker1+
        '<div style="float:left;top:'+logoTop+';position:absolute;margin-left:7px; " > <img src="http://resource.elong.com/images/index_0601/cn/logo.gif" width="279" height="75" border="0" alt="艺龙旅行网" /><br/>'+
        '<div style="float:left;position:absolute;margin-top:5px;font-size:12px;">Copyright &copy; 1999-2010 elong, Inc, All Right Reserved.</div>'+
         ' </div>';
//      var pwin=window.open('','print_content');
      var pwin=window.open ('', 'print_map', 'height='+(screen.availHeight-30)+', width='+(screen.availWidth-10)+', top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
      pwin.document.open();
      pwin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"><head></head><body onload="window.print();">'+body+'</body></html>');
      pwin.document.close();
      setTimeout(function(){pwin.close();},1000);
    }

}

//后台生成的JSON对象添加标注
function addMarkers(){
  //后台生成的JSON对象
  var hotelInfoSet = hotelSet.hotelInfoSet;
  if (hotelInfoSet && hotelInfoSet.length > 0){
    markerList = new MarkerList();
    markerList.clear();
    
    for(var i=0;i < hotelInfoSet.length;i++){
      var hotel = hotelInfoSet[i];
      var point = new LatLng(hotel.latitude,hotel.longitude);
      var imageurl = "http://resource.elong.com/cn/hotels/images/h_" + (i+1) + ".gif";
      var linkurl = "<iframe src='" + getMapHotelInfoWindow() + "HotelId=" + hotel.hotelId + "' name='textFrame' scrolling='no' width='480' height='240' marginwidth='0' MARGINHEIGHT='0' frameborder='no'></iframe>";
      
      var marker = map.createMarker(point,hotel.hotelId,true,imageurl,false,{title:hotel.hotelName});
      marker.bindInfoWindowHtml(linkurl);
      markerList.add(marker);
    }
    
    //用标注管理器添加一组标注
    map.addMarkers(markerList.toGMarkerList(),0);
    map.refresh();
  }
}
//后台生成的JSON对象添加标注
function addHotelsListMarkers(){
  //后台生成的JSON对象
  if(hotelSet)
  {
      var hotelInfoSet = hotelSet.hotelInfoSet;
      
      if (hotelInfoSet && hotelInfoSet.length > 0){
        markerList = new MarkerList();
        var centerPoint;
        markerList.clear();
        var num=1;
        for(var i=0;i < hotelInfoSet.length;i++){
          var hotel = hotelInfoSet[i];
          if(hotel.latitude!=0&&hotel.longitude!=0)
          {
              var point = new LatLng(hotel.latitude,hotel.longitude);
              if(num==1)
              {
                centerPoint=point;
              }
                  var imageurl = "http://resource.elong.com/cn/hotels/images/h_" + (i+1) + ".gif";
              
              var marker = map.createMarker(point,hotel.hotelId,true,imageurl,false,{title:hotel.hotelName},markerclickcallback);
              markerList.add(marker);
              num++;
          }
          
        }
        
        //用标注管理器添加一组标注
        map.addMarkers(markerList.toGMarkerList(),0);
        map.refresh();
        if(centerPoint)
        {
            map.setCenter(centerPoint, 11);
        }
      }
  }
}
function markerclickcallback(id)
{
	mouseoverBgImage(id);
	scrolltohotel("i"+id);
	HighlightHotel(id);
}
function HighlightHotel(id)
{
	$("div[class^=ht_item]").each(function (i){
		$(this).attr("class","ht_item");
	});
	$("#i"+id).attr("class","ht_item on");
}
function getHotelLowPriceByHotelId(hotelid)
{
	var lowprice;
	var title;
	var language;
	$.each(hotelSet.hotelInfoSet, function(i,item){
		if(item.hotelId==hotelid)
		{
			lowprice =item.lowerprice;
			title=item.hotelTitle;
			language=item.language;
		}
	});
	return {l:lowprice,t:title,lan:language};//无价的时候需要怎么显示
}
//酒店对应的标识高亮显示
function mouseoverBgImage(hotelId)
{
	mouseoutBgImage(hotelId);
    if (markerList && markerList.count() > 0 && hotelId){
    var marker = markerList.getMarkerById(hotelId);
    if (marker){
       var itemindex=markerList.getItemIndex(hotelId);
       var imageurl=marker.getIcon().image;
       imageurl= imageurl.substring(0, imageurl.lastIndexOf('.gif'))+"_o.gif";//此图片需要业务给另外一套亮色图片在原有序号基础上加_g.gif命名
       var htindex = 0;
       if (itemindex != null && itemindex != "" && itemindex != "undefined") {
           htindex = parseInt(itemindex, 10) + 1;
       }
	   //浮动窗口样式及内容
		var labelclass="class";
		var windowhtml;
		windowhtml='<div style="width:157px;">'+
		'<div style="background:url(http://resource.elong.com/cn/hotels/images/mapbgtip.gif) right 0 repeat-y; overflow:hide;zoom:1;">'+
		'<div style="width:142px;background:#fff;border-top:#006b02 solid 2px;border-left:#006b02 solid 2px;border-right:#006b02 solid 2px;float:left;padding:5px;">'+
		'<ul>'+
		'<li style="font-weight:bold;"><a href=javascript:HotelDetails(' + hotelId + ',"rate","eLong","","_blank","'+htindex+'")  title="' + marker.getTitle() + '">' + getHotelLowPriceByHotelId(hotelId).t + '</a></li>';
		
		
		if(getHotelLowPriceByHotelId(hotelId).lan=="cn")
		{
			windowhtml=windowhtml+'<li><span style="color:#cf6600;font-weight:bold;">'+getHotelLowPriceByHotelId(hotelId).l+'</span>'+
			'<span style="color:#999999;margin-left:3px;">起</span></li>';
		}
		else{
			windowhtml=windowhtml+'<li><span style="color:#999999;margin-left:3px;">From </span><span style="color:#cf6600;font-weight:bold;">'+getHotelLowPriceByHotelId(hotelId).l+'</span>'+
			'</li>';
		}
		windowhtml=windowhtml+
		'</ul>'+
		'</div>'+
		'</div>'+
		'<div style="clear:both;height:0px;line-height:0px;margin:0 auto;font-size:1px;"></div>'+
		'<div style="background:url(http://resource.elong.com/cn/hotels/images/mapbg.gif) no-repeat;width:157px;height:8px;"></div>'+
		'</div>';
	  
	   
       hotelmarkeroverlay = map.createLabeledMarker(marker.getPoint().toGLatLng(),true,imageurl,false,{id:0,title:'',clickable:false,draggable:false,labelText:windowhtml,labelOffset:new Size(-80, -80),labelClass:labelclass});//
    
       map.addOverlay(hotelmarkeroverlay);
       
       if(marker.getPoint())
       {
            map.setCenter(marker.getPoint());
       }
    }
  }
}
//鼠标移出时酒店对应酒店还原显示
function mouseoutBgImage(hotelId)
{
     if (markerList && markerList.count() > 0 && hotelId){
    var marker = markerList.getMarkerById(hotelId);
  
    if(hotelmarkeroverlay)
    {
        map.removeOverlay(hotelmarkeroverlay);
    }
  }
}
function scrolltohotel(id)
{
	var scr=$(document).scrollTop()||$(window).scrollTop() ;
	var wheight=$(window).height();
	var top=$("#"+id+"").offset().top;
	var eheight=$("#"+id+"").outerHeight();
	scrTo(top); 
	//if (scr>top) {
	//	scrTo(top); 
	//} 
	//else if (scr!=top && top+eheight>scr+wheight) 
	//{ alert(2);
	//	scrTo(top);//+Math.min(eheight-wheight,0));
	//}
	//else{
	//	scrTo(top); 
	//}
	
}
function scrTo(dest) {
	$("html,body").stop().animate({ scrollTop: dest},{duration: 1000 } );
}
//打开已添加到地图的标注信息窗口
function openMarkerInfoWindow(hotelId){
  if (markerList && markerList.count() > 0 && hotelId){
    var marker = markerList.getMarkerById(hotelId);
    if (marker){
      var linkurl = "<iframe src='" + getMapHotelInfoWindow() + "HotelId=" + hotelId + "' name='textFrame' scrolling='no' width='480' height='240' marginwidth='0' MARGINHEIGHT='0' frameborder='no'></iframe>";
      marker.openInfoWindowHtml(linkurl);
    }
  }
}

//取地图汽泡窗口链接
function getMapHotelInfoWindow(){
  var linkurl = "";
  var theme = document.getElementById("Theme").value;
  var campaignId = document.getElementById("Campaign_ID").value;
  
  switch(theme){
   case "elongcn":
     linkurl = "http://www.elong.com/hotels/mapHotel.aspx?";
     break;
   case "elongen":
     linkurl = "http://www.elong.net/hotels/mapHotel.aspx?";
     break;
   case "online":
     linkurl = "http://travel.elong.com/hotels/mapHotel.aspx?Campaign_ID=" + campaignId + "&";
     break;
   case "onlineen":
     linkurl = "http://travel.elong.net/hotels/mapHotel.aspx?Campaign_ID=" + campaignId + "&";
     break;
   default:
     linkurl = "http://www.elong.com/hotels/mapHotel.aspx?";
     break;
  }
  
  return linkurl;
}


//----------------画矩形框------------------

//框选搜索
function doRectangleSearch(){
  map.disableInfoWindow();//add by zhuzhijia on 20080829 框选时隐藏气泡
  mapOperate(MapOperateType.RECTANGLE);
  isBeginDraw=true;
}

//进行地图操作状态（外部调用接口）
function mapOperate(operate){
  mapoperatetype = operate;
  
  map.disableDragging();
  
  if (rectOverlay){
    rectOverlay.remove();
  }
  
  rectOverlay = new RectangleOverlay(6,"blue","#ffffff",0.5,"crosshair");
  
  var scrollTop;
  if (document.documentElement && document.documentElement.scrollTop){
    scrollTop  = document.documentElement.scrollTop;
  }else if (document.body){
    scrollTop  = document.body.scrollTop;
  }
//  RectangleOverlay.offsetLeft = document.getElementById("map").offsetLeft;
  //  RectangleOverlay.offsetTop  = document.getElementById("map").offsetTop - scrollTop;
  
  //新版地图页解决框选定位问题
  RectangleOverlay.offsetLeft = 200; //document.getElementById("map").offsetLeft;

  RectangleOverlay.offsetTop = 200;  //document.getElementById("map").offsetTop - scrollTop;
  try {
      var offset = jQuery("#map").offset();
      RectangleOverlay.offsetLeft = offset.left; 

      RectangleOverlay.offsetTop = offset.top - scrollTop; ; 

  }
  catch (e) { }
  
  rectOverlay.addListener("mousedown",onRectMousedown);
  rectOverlay.addListener("mouseup",onRectMouseup);
  
  map.addOverlay(rectOverlay);
  
}

//画矩形框
function drawRectangle(startlatlng,latlng){
  var latlng2 = new LatLng(startlatlng.lat(),latlng.lng());
  var latlng4 = new LatLng(latlng.lat(),startlatlng.lng());
  var rectBounds = new LatLngBounds(latlng4.toGLatLng(),latlng2.toGLatLng());
  
  if (rectBox){
    rectBox.setBounds(rectBounds);
  }else{
    rectBox = new Rectangle(rectBounds.toGLatLngBounds());
    map.addOverlay(rectBox);
  }
}

//销毁矩形框
function clearRectangle(){
    
  if (isDraw){
    map.clearOverlays();
    rectBox = false;
    isDraw = false;
    mapoperatetype = false;
    startlatlng = false;
    isBeginDraw=false;
      if (rectOverlay){
        rectOverlay.remove();//add by zhuzhijia on 20080717
      }
    map.enableDragging();
    map.enableInfoWindow();
  }
 
}
//取消框选操作 add by zhuzhijia on 20080717
function clearrectOverlay()
{
    if(isBeginDraw)
    {
       
        //map.clearOverlays();
        if(rectBox)
        {
            map.removeOverlay(rectBox);
        }
        rectBox = false;
        isDraw = false;
        mapoperatetype = false;
        startlatlng = false;
        isBeginDraw=false;
          if (rectOverlay){
            rectOverlay.remove();
          }
        map.enableDragging();
        map.enableInfoWindow();
    }
}

//取矩形经纬度
function getRectLatlngs(bounds)
{
    if (bounds)
    {
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        var sw1 = new LatLng(Math.min(sw.lat(),ne.lat()),Math.min(sw.lng(),ne.lng()));
        var ne1 = new LatLng(Math.max(sw.lat(),ne.lat()),Math.max(sw.lng(),ne.lng()));
        
        return {sw:sw1,ne:ne1};
    }
    
    return false;
}

//矩形覆盖层Mousedown事件
function onRectMousedown(point){
  startlatlng = map.fromContainerPixelToLatLng(point.toGPoint());
}

//矩形覆盖层Mouseup事件
function onRectMouseup(point){
  var latlng = map.fromContainerPixelToLatLng(point.toGPoint());
  if(isDraw)
  {
    //***插入业务代码
    var rectbounds = getRectLatlngs(rectBox.bounds_);
    if (rectbounds)
        submitRangeForm(rectbounds.sw,rectbounds.ne);
  }
  clearRectangle();
  
}

//地图click事件.click,dblclick等事件参数一样
function onMapClick(overlay, point){
  if (point){
    switch(mapoperatetype){
      case MapOperateType.RECTANGLE:
        if (startlatlng && isDraw){
          //***插入业务代码
          var rectbounds = getRectLatlngs(rectBox.bounds_);
          if (rectbounds)
              submitRangeForm(rectbounds.sw,rectbounds.ne);
          clearRectangle();
        }else{
          startlatlng = point;
        }
        break;
      default:
        break;
    }
  }
}

//地图mousemove事件.mouseover,mouseout,mousemove等事件参数一样
function onMapMouseMove(latlng){
  if (startlatlng){
    switch(mapoperatetype){
      case MapOperateType.RECTANGLE:
        
        isDraw = true;
        drawRectangle(startlatlng,latlng);
        
        break;
      default:
        break;
    }
  }
  
}

//地图InfoWindowOpen事件.打开信息窗口事件（让信息窗口居中）
function onInfoWindowOpen(){
  var scrollTop;
  if (document.documentElement && document.documentElement.scrollTop){
    scrollTop  = document.documentElement.scrollTop;
  }else if (document.body){
    scrollTop  = document.body.scrollTop;
  }
   
  var offsetLeft = document.getElementById("map").offsetLeft;
  var offsetTop  = document.getElementById("map").offsetTop - scrollTop;
  
  var point = map.fromLatLngToDivPixel(map.getInfoWindow().getPoint());
  point.x += infoWindowOffsetLeft/5 ;
  point.y -= infoWindowOffsetTop/3 ;
  map.panTo(map.fromDivPixelToLatLng(point));
}

//地图InfoWindowOpen事件.打开信息窗口事件（让信息窗口居中）
function onSeoInfoWindowOpen(){
  var scrollTop;
  if (document.documentElement && document.documentElement.scrollTop){
    scrollTop  = document.documentElement.scrollTop;
  }else if (document.body){
    scrollTop  = document.body.scrollTop;
  }
   
  var offsetLeft = document.getElementById("mapSEO").offsetLeft;
  var offsetTop  = document.getElementById("mapSEO").offsetTop - scrollTop;
  
  var point = map.fromLatLngToDivPixel(map.getInfoWindow().getPoint());
  point.x += 563/5 ;
  point.y -= 300/3 ;
  map.panTo(map.fromDivPixelToLatLng(point));
}


//----------------定义客户端酒店信息(JSON)类------------------


///<class>酒店集合类，继承Array类</class>
HotelInfoSet = function(){
  this.innerArray = new Array();
}

HotelInfoSet.prototype.count = function(){
  return this.innerArray.length;
}

HotelInfoSet.prototype.add = function(hotelInfo){
  return this.innerArray.push(hotelInfo);
}

HotelInfoSet.prototype.AddRange = function(hotelInfoSet){
  this.innerArray.concat(hotelInfoSet);
}

this.clear = function(){
  this.innerArray.length = 0;
}

HotelInfoSet.prototype.getHotelInfo = function(index){
  if (index && index >= 0 && index < this.innerArray.length){
    return this.innerArray[index];
  }
  
  return null;
}

///<class>酒店信息类</class>
HotelInfo = function(hotelId,hotelName,latitude,longitude,checkInDate,checkOutDate){
 this.hotelId = hotelId;
 this.hotelName = hotelName;
 this.latitude = latitude;
 this.longitude = longitude;
 this.checkInDate = checkInDate;
 this.checkOutDate = checkOutDate;
}


//----------------定义列表与地图标注交互类------------------


///<class>标注集合类，继承Array类</class>
MarkerList = function(){
  var _markerList = new Array();
  
  this.isInherit = true;
  
  this.count = function(){
    return _markerList.length;
  }

  this.add = function(marker){
    return _markerList.push(marker);
  }

  this.AddRange = function(markerList){
    _markerList.concat(markerList);
  }
  
  this.clear = function(){
    _markerList.length = 0;
  }

  this.getMarker = function(index){
    if (index && index >= 0 && index < _markerList.length){
      return _markerList[index];
    }
    return null;
  }

    ///<summary>得到当前ID所在的索引</summary>
  ///<params>id</params>
   this.getItemIndex=function(id)
   {
     if (id && _markerList.length > 0){
      for(var i = 0;i < _markerList.length;i++){
        if (_markerList[i].id == id){
          return i;
          break;
        }
      }
    }
    
    return null;
   }
  ///<summary>用ID查找标注，如酒店ID</summary>
  ///<params>id</params>
  this.getMarkerById = function(id){
    if (id && _markerList.length > 0){
      for(var i = 0;i < _markerList.length;i++){
        if (_markerList[i].id == id){
          return _markerList[i];
          break;
        }
      }
    }
    
    return null;
  }
  
  ///<summary>转换为GMarker</summary>
  this.toGMarkerList = function(){
    var buffer = new Array();
    
    if (_markerList.length > 0){
      for(var i = 0;i < _markerList.length;i++){
        buffer.push((_markerList[i].isInherit ? _markerList[i].toGMarker() : _markerList[i]));
      }
    }
    
    return buffer;
  }
}

if(typeof(Array.prototype.push) != "function")
{
  Array.prototype.push = function()
  {
    for (var i=0; i<arguments.length; i++)
      this[this.length] = arguments[i];
      
    return this.length; 
  }
}
