//<![CDATA[

var gMap;
var gLocalSearch;
var gMaker;

function OnLoad() {
  if (GBrowserIsCompatible()) {
    var input = document.getElementById("q");
    input.focus();

    var map = new GMap(document.getElementById("map"));
    map.addControl(new GLargeMapControl());  // 地図コントロールボタンを追加。GSmallMapControl()を設定すると･･･
                                             // GControlPosition()で表示位置を指定できる。
    gMap = map;
    // map.addControl(new GScaleControl());

    // ************************
    // *** 緯度、経度を表示 ***
    // ************************
    GEvent.addListener(map, "move", function() {  // マップをドラッグした際に、
      var center = map.getCenter();  // 中心の座標を表示する。
      // document.getElementById("message").innerHTML = center.toString();
      var x, y, z
      z = center.toString();
      x = z.split(",")[0];
      x = x.replace("(", "");
      x = x.replace(" ", "");
      y = z.split(",")[1];
      y = y.replace(")", "");
      y = y.replace(" ", "");
      document.getElementById("x").value = x;
      document.getElementById("y").value = y;
      SetMaker(x, y);
          
      var objTextarea = document.getElementsByName('output')[0];
      objTextarea.value = "<iframe src=\"http://www.namaraumai.net/map/service/blog03000300016.html?x="; 
      objTextarea.value += x;
      objTextarea.value += "&y=";
      objTextarea.value += y;
      objTextarea.value += "\" width=300 height=320 frameborder=0 scrolling=no></iframe>";

      objTextarea = document.getElementsByName('output2')[0];
      objTextarea.value = "<iframe src=\"http://www.namaraumai.net/map/service/blog03000300015.html?x="; 
      objTextarea.value += x;
      objTextarea.value += "&y=";
      objTextarea.value += y;
      objTextarea.value += "\" width=300 height=320 frameborder=0 scrolling=no></iframe>";
	  
	  objTextarea = document.getElementsByName('output3')[0];
      objTextarea.value = "<iframe src=\"http://www.namaraumai.net/map/service/blog04800300016.html?x="; 
      objTextarea.value += x;
      objTextarea.value += "&y=";
      objTextarea.value += y;
      objTextarea.value += "\" width=480 height=320 frameborder=0 scrolling=no></iframe>";
	  
	  objTextarea = document.getElementsByName('output4')[0];
      objTextarea.value = "<iframe src=\"http://www.namaraumai.net/map/service/blog04800300015.html?x="; 
      objTextarea.value += x;
      objTextarea.value += "&y=";
      objTextarea.value += y;
      objTextarea.value += "\" width=480 height=320 frameborder=0 scrolling=no></iframe>";
    });

    map.setCenter(new GLatLng(43.0611396480103, 141.35639011859894), 15);  // *** 緯度、経度、縮尺 ***
    SetMaker(43.0611396480103, 141.35639011859894);

    localsearch = new GlocalSearch();
    localsearch.setCenterPoint(map);
    localsearch.setSearchCompleteCallback(null, OnLocalSearch);
    localsearch.execute(input.value);

    gLocalSearch = localsearch;
  }
}

function SetMaker(x, y) {
  if (typeof(gMaker) != "undefined") {
    gMap.removeOverlay(gMaker);
  }
  var point = new GLatLng(x, y); // マーカを付ける場所を指定
  var maker;                     // なぜが宣言とnewが同時に出来ない
  maker = new GMarker(point);    // マーカを作成
  gMap.addOverlay(maker);        // マーカを地図上に表示
  gMaker = maker;
  return true;
}

function OnLocalSearch() {
  //if (!gLocalSearch.results) return;
  if (gLocalSearch.results.length == 0) {
    document.getElementById("x").value = "";
    document.getElementById("y").value = "";
    alert("見つかりません。");
    var input = document.getElementById("q");
    input.focus();
    return false;
  }
  var first = gLocalSearch.results[0];
  gMap.recenterOrPanToLatLng(new GPoint(parseFloat(first.lng), parseFloat(first.lat)));
  return true;
}

function CaptureForm(form) {
  gLocalSearch.execute(form["q"].value);
  return false;
}

function MyCopy(){
  var tmp = document.form1.output.value;
  document.form1.output.focus();
  document.form1.output.select();
  window.clipboardData.setData("text", tmp);
}

function MyCopy2(){
  var tmp = document.form1.output2.value;
  document.form1.output2.focus();
  document.form1.output2.select();
  window.clipboardData.setData("text", tmp);
}

function MyCopy3(){
  var tmp = document.form1.output3.value;
  document.form1.output3.focus();
  document.form1.output3.select();
  window.clipboardData.setData("text", tmp);
}

function MyCopy4(){
  var tmp = document.form1.output4.value;
  document.form1.output4.focus();
  document.form1.output4.select();
  window.clipboardData.setData("text", tmp);
}
//]]>
