/*@cc_on 
var doc = document;
eval('var document = doc');
@*/

//■GetLonLat
function GetLonLat(place){
    
    xmlhttpSelectLonLat = GetXmlHttpObject();
    if(xmlhttpSelectLonLat == null){
      alert("Browser does not support HTTP Request");
      return;
    }
    var place;
    var url = "../incweb/GetLonLat.php";
    //var place = document.getElementById("place").value;

    url = url + "?place=" + encodeURI(place);
    //url = url + "&pref=" + encodeURI(pref);
    url = url + "&sid=" + Math.random();

    xmlhttpSelectLonLat.onreadystatechange = stateChangedLonLat;
    xmlhttpSelectLonLat.open("GET",url,true);
    xmlhttpSelectLonLat.send(null);
}

function stateChangedLonLat(){
    if(xmlhttpSelectLonLat.readyState == 4){
     //alert(xmlhttpSelectLonLat.responseText);
     var lonlat = trim(xmlhttpSelectLonLat.responseText).split(",");
     var lon = document.getElementById("lon").value; //経度
     var lat = document.getElementById("lat").value; //緯度

     //if(lat == ''){
      document.getElementById("lat").value=lonlat[0];
     //}
     //if(lon == ''){
      document.getElementById("lon").value=lonlat[1];
     //}
      GoogleMaps2();
    }
}

//■LonLatClear
function LonLatClear(){
 document.getElementById("lat").value=null;
 document.getElementById("lon").value=null;
}

function trim(argValue){
    return String(argValue).replace(/^\s+|\s+$/g, "");
}

//■GoogleMaps2
function GoogleMaps2(){
    document.getElementById("map").style.height="380px";
    var map = new GMap2(document.getElementById("map"));

    //地図の座標設定
    var lon   = document.getElementById("lon").value; //経度
    var lat   = document.getElementById("lat").value; //緯度
    var myoffice = new GLatLng(lat,lon);

    //地図中心
    map.setCenter(myoffice, 16);

    //コントロール追加
    map.addControl(new GLargeMapControl());
    //map.addControl(new GSmallMapControl());
    //map.addControl(new GMapTypeControl());
    //map.addControl(new GOverviewMapControl(new GSize(200,150)));

    xy = map.getCenter();
  	
   document.getElementById("lat").value=xy.lat();
   document.getElementById("lon").value=xy.lng();

   //document.getElementById("show_xy").innerHTML = "緯度経度："+xy.lat()+","+xy.lng();
  	cpoint = new GLatLng(xy.lat(), xy.lng());
  	c_mark = new GMarker(cpoint);
  	map.addOverlay(c_mark);

  	GEvent.addListener(map, 'moveend', function(){
  		var xy = map.getCenter();
  		
    document.getElementById("lat").value=xy.lat();
    document.getElementById("lon").value=xy.lng();

    //document.getElementById("show_xy").innerHTML = "緯度経度："+xy.lat()+","+xy.lng();

  		map.removeOverlay(c_mark);
  		cpoint = new GLatLng(xy.lat(), xy.lng());
  		c_mark = new GMarker(cpoint);
  		map.addOverlay(c_mark);
  	});

    //アイコン設定
    /*var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";

    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);

    // アイコン画像
    var icon = new GIcon(baseIcon);
    icon.image = "http://www.google.com/mapfiles/marker.png";

    //マーカー表示する
    var point=new GLatLng(lat,lon);
    var marker = new GMarker(point,icon);
    map.addOverlay(marker);*/

    //吹きだし情報
    //var msg_html = "<table border=0 cellspacing=0 cellpadding=4><tr><td class=namae>＜<?=$area_name?>：<?=_hs($rec['shop_name'])?>＞</td></tr><tr><td class=font12><?=_hs($rec['shop_adr'])?><br />TEL:<?=_hs($rec['shop_tel'])?></td></tr></table>";
    //イベント

    /*marker.openInfoWindowHtml(msg_html);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(msg_html);
    });*/
}