﻿var ggle_map = null;
var ggle_search = null;
var ggle_geocoder = null;
var ggle_responseSearchFuncName="";
function ggle_mapload(mapname, lat, lng, zoomlevel, bsearchcontrol, blargemapcontrol) {
 ggle_maploadCore(mapname, lat, lng, zoomlevel, bsearchcontrol, blargemapcontrol, true);
}
function ggle_maploadCore(mapname, lat, lng, zoomlevel, bsearchcontrol, blargemapcontrol, bshowcontrol) {
	try{
  if (GBrowserIsCompatible()) {
  	ggle_map = new GMap2(document.getElementById(mapname));
    
    if(lat!=null && lng!=null && lat!="" && lng!="")
		ggle_map.setCenter(new GLatLng(lat, lng), parseInt(zoomlevel,10));
	else
	{
		//ggle_map.setCenter(new GLatLng(51.509500000000000, -.196800000000000), parseInt(zoomlevel,10));
		ggle_map.setCenter(new GLatLng(5.61598581915534, -165.9375), 9);
	}
	
	if(blargemapcontrol)
	{
		
    
		try{
			//ggle_map.addControl(new GLargeMapControl());
			var extLargeMapControl = new ExtLargeMapControl();
        	ggle_map.addControl(extLargeMapControl);
    	}catch(e)
    	{
    		
    	}
    	
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(200,10));
		ggle_map.addControl(new GScaleControl(), topRight);
		
		 
	}
	else
		ggle_map.addControl(new GSmallMapControl());
	
	if(bshowcontrol)
		ggle_map.addControl(new GMapTypeControl());
	
      // bind a search control to the map, suppress result list
   
 	
  }
	}catch(e)
	{
		ggle_map=null;
	}
	try{
		 if(bsearchcontrol)
	    {
			ggle_search=new google.maps.LocalSearch();
			ggle_map.addControl(ggle_search, new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
	    }
	}catch(e)
	{
		
	}
}
//GSearch.setOnLoadCallback(ggle_mapload);
function ggle_displayMap(lat,lng) {
/*  if(Hotel[index].geoCode1 == 0 && Hotel[index].geoCode2 == 0) {
    alert("죄송합니다. 해당 호텔의 정확한 위치 정보가 존재하지 않습니다.");
    return;
  }*/
   if(ggle_map==null)
   	return;
   if(lat!=null && lng!=null && lat!="" && lng!="")
   {
	  var ggle_point = new GLatLng(lat, lng);
	  ggle_map.setCenter(ggle_point, ggle_map.getZoom());
	  ggle_map.addOverlay(new GMarker(ggle_map.getCenter()));
   }
   
 
//     map.setCenter(new GLatLng(Hotel[index].geoCode1, Hotel[index].geoCode2), 15);
//    markers[index].openInfoWindowHtml(getMarkerHtml(Hotel[index]));
  //window.setTimeout(showCircle, 3000);
}

function ggle_addAddressToMap(response) {
 
 	if(ggle_map==null)
   		return;
	if(ggle_responseSearchFuncName=="")
	{
		if (!response || response.Status.code != 200) {
			alert("Sorry, we were unable to geocode that address");
		} else {

			ggle_map.clearOverlays();
			var ggle_place = response.Placemark[0];
			var ggle_point = new GLatLng(ggle_place.Point.coordinates[1],
								ggle_place.Point.coordinates[0]);
			var ggle_marker = new GMarker(ggle_point);
			ggle_map.addOverlay(ggle_marker);
			ggle_marker.openInfoWindowHtml(ggle_place.address + '<br>' +
			  '<b>Country code:</b> ' + ggle_place.AddressDetails.Country.CountryNameCode);

		}	
    
	}
	else
	{
		if (!response || response.Status.code != 200) {
			eval(ggle_responseSearchFuncName+"(null);")
		} else {

			eval(ggle_responseSearchFuncName+"(response.Placemark);")

		}
		
	}
}
function ggle_findLocation(xquery, responseFunc)
{
	//xquery=escape(xquery);
	if(ggle_map==null)
   		return;
	if(ggle_geocoder==null)
	{
		ggle_geocoder = new GClientGeocoder();
		ggle_geocoder.setBaseCountryCode("US");
	}
	ggle_responseSearchFuncName=responseFunc;
	ggle_geocoder.getLocations(xquery, ggle_addAddressToMap);
}
function ggle_CreateGSize(width, height)
{
	if(ggle_map==null)
   		return;
	return new GSize(width, height);
}
function ggle_CreateGPoint(x, y)
{
	if(ggle_map==null)
   		return;
	return new GPoint(x, y);
}
function ggle_CreateGLatLng(Lat, Lng)
{
	if(ggle_map==null)
   		return;
	return new GLatLng(Lat,	Lng);
}

function ggle_CreateMarker(latlng, image, shadow, imgsize, shadowsize, anchoroffset, infoanchoroffset, infoHTML)
{
	if(ggle_map==null)
   		return null;
	var tIcon = new GIcon();
	
    tIcon.image = image;
    tIcon.shadow = shadow;
    tIcon.iconSize = imgsize;
    tIcon.shadowSize = shadowsize;
    tIcon.iconAnchor = anchoroffset;
    tIcon.infoWindowAnchor = infoanchoroffset;
    var markerOptions = { icon:tIcon };
    // Set up our GMarkerOptions object
    var nMarker=new GMarker(latlng, markerOptions);
    if(infoHTML!="")
    {
		GEvent.addListener(nMarker, "click", 
		function() {    
		nMarker.openInfoWindowHtml(infoHTML);  
		}
		);
    }
    return nMarker;
}
function ggle_CreateMarker3(xtitle, latlng, image, shadow, imgsize, shadowsize, anchoroffset, infoanchoroffset, infoHTML)
{
	if(ggle_map==null)
   		return null;
	var tIcon = new GIcon();
	
    tIcon.image = image;
    tIcon.shadow = shadow;
    tIcon.iconSize = imgsize;
    tIcon.shadowSize = shadowsize;
    tIcon.iconAnchor = anchoroffset;
    tIcon.infoWindowAnchor = infoanchoroffset;
    var markerOptions = { icon:tIcon , title:xtitle};
    // Set up our GMarkerOptions object
    var nMarker=new GMarker(latlng, markerOptions);
    if(infoHTML!="")
    {
		GEvent.addListener(nMarker, "click", 
		function() {    
		nMarker.openInfoWindowHtml(infoHTML);  
		}
		);
    }
    return nMarker;
}
function ggle_UpdateMarker(xtitle, nMarker, latlng, image, imgsize, infoHTML)
{
	if(ggle_map==null)
   		return null;
	if(xtitle!=null)
		nMarker.$.title=xtitle;
	if(latlng!=null)
		nMarker.setLatLng(latlng);
	if(image!="")
		nMarker.setImage(image);
    if(infoHTML!="")
    {
		GEvent.clearListeners(nMarker, "click");
		GEvent.addListener(nMarker, "click", 
		function() {    
		nMarker.openInfoWindowHtml(infoHTML);  
		}
		);
    }
    return nMarker;
}
var ggle_box=null;
function ggle_makeBox(tLat, tLng, tLevel, bMoveCenter)
{
	if(ggle_map==null)
   		return;
	//var polyOptions = {geodesic:true};
	tLat=parseFloat(tLat);
	tLng=parseFloat(tLng);
	if(ggle_box!=null)
	{
		ggle_map.removeOverlay(ggle_box);
		ggle_box=null;
	}
	var latOffset = 0;
    var lonOffset = 0;
	switch(parseInt(tLevel))
	{
	case 1:
		latOffset=0.020;//0.035;
		lonOffset=0.030;//0.05
		
		break;
	}
	if(latOffset!=0 && lonOffset!=0)
	{
		var polygon = new GPolygon([
            new GLatLng(tLat-latOffset, tLng-lonOffset),  
			new GLatLng(tLat+latOffset, tLng-lonOffset),
			new GLatLng(tLat+latOffset, tLng+lonOffset),
			new GLatLng(tLat-latOffset, tLng+lonOffset),
			new GLatLng(tLat-latOffset, tLng-lonOffset)
		  ], "#f33f00", 5, 1, "#ff0000", 0.2);
		ggle_box=polygon;
		ggle_map.addOverlay(ggle_box);
	}
	
	if(bMoveCenter)
		 ggle_map.setCenter(new GLatLng(tLat, tLng), ggle_map.getZoom());
	
}
function ggle_removeBox()
{
	if(ggle_map==null)
   		return;
	if(ggle_box!=null)
	{
		ggle_map.removeOverlay(ggle_box);
		ggle_box=null;
	}
}
function ggle_CreateMarker2(xtitle, latlng, image, shadow, imgsize, shadowsize, anchoroffset, infoanchoroffset, funconclick, infoHTML)
{
	if(ggle_map==null)
   		return null;
	var tIcon = new GIcon();
	
    tIcon.image = image;
    tIcon.shadow = shadow;
    tIcon.iconSize = imgsize;
    tIcon.shadowSize = shadowsize;
    tIcon.iconAnchor = anchoroffset;
    tIcon.infoWindowAnchor = infoanchoroffset;
    
    var markerOptions = { icon:tIcon , title:xtitle};
    // Set up our GMarkerOptions object
    var nMarker=new GMarker(latlng, markerOptions);
    if(funconclick!="")
    {
		GEvent.addListener(nMarker, "dblclick", 
		function() {    
		//eval(funconclick);
		}
		);
    }
    if(infoHTML!="")
    {
		GEvent.addListener(nMarker, "click", 
		function() {    
			nMarker.openInfoWindowHtml(infoHTML);
			eval(funconclick);
		}
		);
    }
    else
    {
		GEvent.addListener(nMarker, "click", 
		function() {    
			eval(funconclick);
		}
		);
    }
    return nMarker;
}
function ggle_CreateMarkerNormal(latlng)
{
	if(ggle_map==null)
   		return null;
    var nMarker=new GMarker(latlng);
  
    return nMarker;
}
