﻿// ========================================================================
// ROCOCO Library
//
// Copyright (c) 2006-2007, NARO (National Agriculture and Food Research Organization, Japan)
// All rights reserved.
// ------------------------------------------------------------------------
//
// 使用許諾書は http://www.finds.jp/rococo/b2/license.html にあります．
//
// ========================================================================
Rococo.rccgm = new Object();
Rococo.rccgm.local = new Object();
Rococo.rccgm.locale = new Object();
Rococo.rccgm.locale.Rccgm = {
  size: function() { return Rococo.lang == 'en' ? 'size' : 'サイズ'; },
  cmark: function() { return Rococo.lang == 'en' ? 'center marker' : '中心マーカ' ;},
  mousewheel: function() { return Rococo.lang == 'en' ? 'mouse wheel' : 'マウスホイール';},
  latitude: function() { return Rococo.lang == 'en' ? 'lat' : '緯度';},
  longitude: function() { return Rococo.lang == 'en' ? 'lon' : '経度';},
  move: function() { return Rococo.lang == 'en' ? 'move' : '移動';},
  view_title: function() { return Rococo.lang == 'en' ? 'VIEW SETTING' : '表示設定';},
  gotodd_title: function() { return Rococo.lang == 'en' ? 'GOTO LAT/LON' : '緯度経度移動';},
  jpgeocode_title: function() { return Rococo.lang == 'en' ? 'GOTO PREF' : '市区町村移動';},
  view_help: function() { return Rococo.lang == 'en' ? 'to change map size or visibility of a center marker' : '地図のサイズ変更、中心マーカ表示の切り替え等を行います。' ;},
  gotodd_help: function() { return Rococo.lang == 'en' ? 'to go to the place indicated by latitude and longitude. positive latitude means northern and positivbe longitude means eastern.' : '移動経度(緯度の正方向は北緯・東経)を入力して「移動」ボタンをクリックすると、その位置に移動します。' ;},
  jpgeocode_help: function() { return Rococo.lang == 'en' ? 'to go to the prefecture or city, town or village' : '都道府県・市区町村を指定すると、その都道府県または市区町村に移動します。' ;}
};
Rococo.rccgm.preset = new Object();
Rococo.rccgm.local.preset = new Object();
Rococo.rccgm.local.preset.prefecturelist = [
  { value:  1, text:'北海道'  }, { value:  2, text:'青森県'  }, { value:  3, text:'岩手県'  }, { value:  4, text:'宮城県'  },
  { value:  5, text:'秋田県'  }, { value:  6, text:'山形県'  }, { value:  7, text:'福島県'  }, { value:  8, text:'茨城県'  },
  { value:  9, text:'栃木県'  }, { value: 10, text:'群馬県'  }, { value: 11, text:'埼玉県'  }, { value: 12, text:'千葉県'  },
  { value: 13, text:'東京都'  }, { value: 14, text:'神奈川県'}, { value: 15, text:'新潟県'  }, { value: 16, text:'富山県'  },
  { value: 17, text:'石川県'  }, { value: 18, text:'福井県'  }, { value: 19, text:'山梨県'  }, { value: 20, text:'長野県'  },
  { value: 21, text:'岐阜県'  }, { value: 22, text:'静岡県'  }, { value: 23, text:'愛知県'  }, { value: 24, text:'三重県'  },
  { value: 25, text:'滋賀県'  }, { value: 26, text:'京都府'  }, { value: 27, text:'大阪府'  }, { value: 28, text:'兵庫県'  },
  { value: 29, text:'奈良県'  }, { value: 30, text:'和歌山県'}, { value: 31, text:'鳥取県'  }, { value: 32, text:'島根県'  },
  { value: 33, text:'岡山県'  }, { value: 34, text:'広島県'  }, { value: 35, text:'山口県'  }, { value: 36, text:'徳島県'  },
  { value: 37, text:'香川県'  }, { value: 38, text:'愛媛県'  }, { value: 39, text:'高知県'  }, { value: 40, text:'福岡県'  },
  { value: 41, text:'佐賀県'  }, { value: 42, text:'長崎県'  }, { value: 43, text:'熊本県'  }, { value: 44, text:'大分県'  },
  { value: 45, text:'宮崎県'  }, { value: 46, text:'鹿児島県'}, { value: 47, text:'沖縄県'  }
];
Rococo.rccgm.preset.createTopMenuSettings = function(thisobj,types) {
  if( types == null ) { return null; }
  var ret = new Array();
  var len = types.length;
  for( var n = 0; n < len; n++ ) {
    var s = Rococo.rccgm.local.preset.createTopMenuItemSettings(thisobj,types[n]);
    if( s != null ) {
      ret.push(s);
    }
  }
  return ret;
};
Rococo.rccgm.local.preset.createTopMenuItemSettings=function(thisobj,type) {
  if( type == null ) { return null; }
  type = type.toLowerCase();
  if( type == 'view' ) {
    var arr_items = [
      {
	subid: 'view',
	tagname:'select',
	title: Rococo.rccgm.locale.Rccgm.size(),
	subid:'size',
	attributes: {
	  list: [
		{text:'-------', value:'' },
		{text:'400x300', value:'400x300'}, {text:'480x360', value:'480x360'},
		{text:'600x450', value:'600x450'}, {text:'800x600', value:'800x600'},
		{text:'960x720', value:'960x720'} ],
	  value:'480x360'
	},
	events: [{
	  type: 'change',
	  listener:function() { thisobj.changeMapSize(); }
	}]
      },
      {
	tagname:'checkbox',
	title: Rococo.rccgm.locale.Rccgm.cmark(),
	subid:'cmark',
	attributes: {
	  value: true
	},
	events : [{
	  type: 'click',
	  listener: function() { thisobj.changeCmarkVisible(); }
	}]
      },
      {
	tagname:'checkbox',
	title: Rococo.rccgm.locale.Rccgm.mousewheel(),
	subid:'mousewheel',
	attributes : {
	  value: true
	}
      }
    ];
    return {
	subid: 'view',
	title: Rococo.rccgm.locale.Rccgm.view_title(),
	helplines: [Rococo.rccgm.locale.Rccgm.view_help()],
	items: arr_items
      };
  }
  else if( type == 'gotodd' ) {
    var arr_items = [
      {
	tagname:'text',
	title: Rococo.rccgm.locale.Rccgm.latitude(),
	subid:'lat',
	attributes: {
	  style: { width: '95%' }
	}
      },
      {
	tagname:'text',
	title: Rococo.rccgm.locale.Rccgm.longitude(),
	subid:'lon',
	attributes: {
	  style: { width: '95%' }
	}
      },
      {
	tagname:'submit',
	subid:'button',
	attributes: {
	  value: Rococo.rccgm.locale.Rccgm.move()
	},
	events: [{
	  type: 'click',
	  listener: function() { thisobj.changeMapCenter(); }
	}]
      }
    ];
    return {
	subid: 'gotodd',
	title: Rococo.rccgm.locale.Rccgm.gotodd_title(),
	helplines: [Rococo.rccgm.locale.Rccgm.gotodd_help()],
	items: arr_items
      };
  }
  else if( type == 'jpgeocode' ) {
    var arr_items = [
      {
	tagname:'select',
	subid:'pref',
	attributes: {
	  list: Rococo.rccgm.local.preset.prefecturelist,
	  firstrow: Rococo.tk.preset.emptyline_integer,
	  value: -1
	},
	events: [{
	  type: 'change',
	  listener: function() { thisobj.onChangePref(); }
	}]
      },
      {
	tagname:'select',
	subid:'mncpl',
	attributes: {
	  list: [ {text:'-----', value:-1} ]
	},
	events: [{
	  type: 'change',
	  listener: function() {  thisobj.onChangeMncpl(); }
	}]
      }
    ];
    return {
	subid: 'jpgeocode',
	title: Rococo.rccgm.locale.Rccgm.jpgeocode_title(),
	helplines: [Rococo.rccgm.locale.Rccgm.jpgeocode_help()],
	items: arr_items
      };
  }
};
Rococo.rccgm.local.MeshLayer = new Object();
Rococo.rccgm.local.MeshLayer.findPalletteIndex = function(rawcolor,rawpallette) {
  if( rawcolor == null ) { return -1; }
  var len_pal = rawpallette.length;
  for( var n_pal = 0; n_pal < len_pal; n_pal++ ) {
    if( rawcolor.equals(rawpallette[n_pal]) ) {
      return n_pal;
    }
  }
  rawpallette.push(rawcolor);
  return len_pal;
};
Rococo.rccgm.local.MeshLayer.getBGC = function(rawpallette) {
  for( var bg = 255; bg > 0 ; bg-- ) {
    bg = new Rococo.tk.Color(bg,bg,bg);
    var hit = false;
    for( var n_pal in rawpallette ) {
      if( bg.equals(rawpallette[n_pal]) ) {
        hit =true;
        break;
      }
    }
    if( hit == false ) {
      return bg;
    }
  }
  return new Rococo.tk.Color(0,0,0);
};
Rococo.rccgm.local.MeshLayer.createSubColors = function(rawcolors, rmin, cmin, rmax, cmax ) {
  var subcolors = new Array();
  var subpallette = new Array();
  var len_pal = 0;
  var n_row, n_col;
  for( n_row = rmin; n_row <= rmax; n_row++ ) {
    var subcolors_row = new Array();
    for( n_col = cmin; n_col <= cmax; n_col++ ) {
      var rawcolor = rawcolors[n_row][n_col];
      subcolors_row.push(1+Rococo.rccgm.local.MeshLayer.findPalletteIndex(rawcolor,subpallette));
    }
    subcolors.push(subcolors_row.join(','));
  }
  return { 'colors': subcolors.join(','), 'rawpallette' : subpallette };
};
Rococo.rccgm.local.MeshLayer.serializePallette = function(pallette) {
  var len_pal = pallette.length;
  var ret = pallette[0].join(':');
  for( var n_pal = 1; n_pal < len_pal; n_pal++ ) {
    ret = ret + ',' + pallette[n_pal].join(':');
  }
  return ret;
};
Rococo.rccgm.MeshLayer = function( copyrights, minResolution, maxResolution, origin, data, legend, opacity ) {
  var elder = new GTileLayer( copyrights, minResolution, maxResolution );
  Rococo.ut.inherit( elder, this );
  var url_prefix = 'http://www.finds.jp/ws/gmmesh.php';
  var n_col, len_col;
  var n_row, len_row;
  len_row = data.length;
  len_col = 0;
  var rawcolors = new Array();
  var pallette = new Array();
  for( n_row = 0; n_row < len_row; n_row++ ) {
    var rawcolors_row = new Array();
    var len = data[n_row].length;
    if( len > len_col ) { len_col = len; }
    for( n_col = 0; n_col < len; n_col++ ) {
      var d = data[n_row][n_col];
      if( d != null ) {
        rawcolors_row[n_col] = legend.getColor(d);
      }
    }
    rawcolors.push(rawcolors_row);
  }
  var proj = new GMercatorProjection(maxResolution+1);
  var ex_lat1 = origin.orig.lat;
  var ex_lat2 = ex_lat1 + origin.skip.lat * len_row;
  var ex_lon1 = origin.orig.lon;
  var ex_lon2 = ex_lon1 + origin.skip.lon * len_col;
  var ex_n, ex_s, ex_w, ex_e;
  if( ex_lat1 < ex_lat2 ) {
    ex_s = ex_lat1;
    ex_n = ex_lat2;
  }
  else {
    ex_s = ex_lat2;
    ex_n = ex_lat1;
  }
  if( ex_lon1 < ex_lon2 ) {
    ex_w = ex_lon1;
    ex_e = ex_lon2;
  }
  else {
    ex_w = ex_lon2;
    ex_e = ex_lon1;
  }
  opacity = opacity < 0 ? 0 : ( opacity > 1 ? 1 : opacity );
  this.getOpacity = function() { return opacity; }
  var colorset = Rococo.rccgm.local.MeshLayer.createSubColors(rawcolors,0,0,len_row-1,len_col-1);
  var bgcolor_url = Rococo.rccgm.local.MeshLayer.getBGC(colorset.rawpallette).join(':');
  var url_fail = url_prefix + '?t=t&img=gif&bg=' + bgcolor_url;
  if(  len_row <=64 && len_col <=64 && colorset.rawpallette.length < 255 ) {
    var url_preset = url_prefix + '?t=t&img=gif&bg=' + bgcolor_url
	+'&p='+Rococo.rccgm.local.MeshLayer.serializePallette(colorset.rawpallette)
	+'&d='+colorset.colors
	+'&sx='+origin.skip.lon+'&sy='+origin.skip.lat
	+'&lat='+origin.orig.lat+'&lon='+origin.orig.lon
	+'&cx='+len_col+'&cy='+len_row;
    this.getTileUrl = function(tile,zoom) {
	  var x1 = tile.x*256;
	  var y1 = tile.y*256;
	  var nw = proj.fromPixelToLatLng(new GPoint(x1,y1),zoom);
	  var se = proj.fromPixelToLatLng(new GPoint(x1+256,y1+256),zoom);
	  var tex_n = Math.floor(nw.lat() * 3600);
	  var tex_s = Math.floor(se.lat() * 3600);
	  var tex_w = Math.floor(nw.lng() * 3600);
	  var tex_e = Math.floor(se.lng() * 3600);
	  if( tex_n < ex_s || tex_s > ex_n || tex_w > ex_e || tex_e < ex_w ) {
	    return url_fail;
	  }
	  return url_preset +'&tx='+tile.x+'&ty='+tile.y+'&zoom='+zoom;
	};
  }
  else {
    colorset = null;
    var url_preset = url_prefix + '?t=t&img=gif&bg=' + bgcolor_url
	+'&sx='+origin.skip.lon+'&sy='+origin.skip.lat;
    this.getTileUrl = function(tile,zoom) {
	  var x1 = tile.x*256;
	  var y1 = tile.y*256;
	  var nw = proj.fromPixelToLatLng(new GPoint(x1,y1),zoom);
	  var se = proj.fromPixelToLatLng(new GPoint(x1+256,y1+256),zoom);
	  var tex_n = Math.floor(nw.lat() * 3600);
	  var tex_s = Math.floor(se.lat() * 3600);
	  var tex_w = Math.floor(nw.lng() * 3600);
	  var tex_e = Math.floor(se.lng() * 3600);
	  if( tex_n < ex_s || tex_s > ex_n || tex_w > ex_e || tex_e < ex_w ) {
	    return url_fail;
	  }
	  var rn = Math.floor((tex_n - origin.orig.lat) / origin.skip.lat);
	  var rs = Math.floor((tex_s - origin.orig.lat) / origin.skip.lat);
	  var cw = Math.floor((tex_w - origin.orig.lon) / origin.skip.lon);
	  var ce = Math.floor((tex_e - origin.orig.lon) / origin.skip.lon);
	  var rmin, rmax, cmin, cmax;
	  if( rn < rs ) { rmin = rn-1; rmax = rs+1; }
	  else { rmin = rs-1; rmax = rn+1; }
	  if( cw < ce ) { cmin = cw-1; cmax = ce+1; }
	  else { cmin = ce-1; cmax = cw+1; }
	  if( rmin < 0 ) { rmin = 0; }
	  if( rmax > len_row-1 ) { rmax = len_row-1; }
	  if( cmin < 0 ) { cmin = 0; }
	  if( cmax > len_col-1 ) { cmax = len_col-1; }
          var subcolorset = Rococo.rccgm.local.MeshLayer.createSubColors(rawcolors, rmin, cmin, rmax, cmax );
	  if( subcolorset.colors == '' || subcolorset.rawpallette.length <= 0 ) {
	    return url_fail;
	  }
	  var olat = origin.orig.lat + rmin * origin.skip.lat;
	  var olon = origin.orig.lon + cmin * origin.skip.lon;
	  var vrows = rmax-rmin+1;
	  var vcols = cmax-cmin+1;
	  return url_preset
		+'&p='+Rococo.rccgm.local.MeshLayer.serializePallette(subcolorset.rawpallette)
		+'&d='+subcolorset.colors
		+'&lat='+olat+'&lon='+olon
		+'&cx='+vcols+'&cy='+vrows
		+'&tx='+tile.x+'&ty='+tile.y+'&zoom='+zoom;
	};
  }
};
Rococo.rccgm.local.Rccgm = new Object();
Rococo.rccgm.init = function() {
  Rococo.initIeVml();
}
Rococo.init.push(Rococo.rccgm.init);
Rococo.rccgm.Rccgm = function( element, options, constraction ) {
  this.rootElement = Rococo.tk.em.recreateElement(element);
  if( constraction == null ) { constraction = 3; }
  if( options == null ) { options = new Object(); }
  if( options.lang == null && Rococo.lang == null ) { options.lang = 'ja'; }
  if( options.lat  == null ) { options.lat  = 37; }
  if( options.lon  == null ) { options.lon  = 139; }
  if( options.zoom == null ) { options.zoom = 4; }
  if( options.type == null ) { options.type = G_DEFAULT_MAP_TYPES ? G_DEFAULT_MAP_TYPES[0] : null; }
  if( options.cmark == null ) { options.cmark = new Object(); }
  if( options.cmark.visible == null ) { options.cmark.visible = true; }
  if( options.cmark.url == null ) { options.cmark.url = 'http://www.finds.jp/rococo/b2/cmark.gif'; }
  if( options.cmark.width == null ) { options.cmark.width = 32; }
  if( options.cmark.height == null ) { options.cmark.height = 32; }
  if( options.cmark.center_x == null ) { options.cmark.center_x = 15; }
  if( options.cmark.center_y == null ) { options.cmark.center_y = 15; }
  if( options.mousewheel == null ) { options.mousewheel = true; }
  if( options.position == null ) {
    if( Rococo.browser && Rococo.browser.agent == 'ie' && parseFloat(Rococo.browser.version) < 7.0 ) {
      options.position = 'static';
    }
    else {
      options.position = 'relative';
    }
  }
  if( options.mapcontrol == null ) { options.mapcontrol = 2; }
  if( options.typecontrol == null ) { options.typecontrol = true; }
  var url_options = Rococo.ut.getParamArray(document.URL);
  if( url_options != null ) {
    if( url_options.lang == 'ja' || url_options.lang == 'en' ) { options.lang = url_options.lang; }
    if( Rococo.ut.isNumeric(url_options.lat) && Rococo.ut.isNumeric(url_options.lon) ) {
      options.lat = parseFloat(url_options.lat);
      options.lon = parseFloat(url_options.lon);
    }
    if( Rococo.ut.isNumeric(url_options.zoom) && url_options.zoom > 0 ) { options.zoom = parseInt(url_options.zoom); }
    if( url_options.mapw && url_options.mapw != '' && url_options.maph && url_options.maph != '' ) {
      options.mapw = url_options.mapw;
      options.maph = url_options.maph;
    }
    if( url_options.t == 'k' ) { options.type = G_SATELLITE_MAP; }
    else if( url_options.t == 'h' ) { options.type = G_HYBRID_MAP; }
  }
  this.options = options;
  if( options != null && options.lang != null ) {
    Rococo.lang = options.lang;
  }
  this.cmark = new Object();
  this.cmark.icon = new GIcon();
  this.cmark.icon.image = options.cmark.url;
  this.cmark.icon.iconSize = new GSize(options.cmark.width,options.cmark.height);
  this.cmark.icon.iconAnchor = new GPoint(options.cmark.center_x,options.cmark.center_y);
  this.cmark.opts = {icon:this.cmark.icon,clickable:false,draggable:false,bouncy:false};
  this.cmark.marker = null;
  this.rootElement.style.position = options.position;
  this.topmenuholder = this.rootElement.createChild('topmenuholder','div');
  Rococo.pnl.recreateMenuHolder(this.topmenuholder);
  this.rootElement.setChild('topmenuholder',this.topmenuholder);
  this.mapholder = this.rootElement.createChild('mapholder','div');
  this.mapelement = this.mapholder.createChild('map','div');
  this.mapholder.setChild('map',this.mapelement);
  this.mapholder.setChild('legendholder',this.mapholder.createChild('legendholder','div'));
  this.rootElement.setChild('mapholder',this.mapholder);
  this.consoleholder = this.rootElement.createChild('consoleholder','div');
  Rococo.pnl.recreateConsoleHolder(this.consoleholder);
  this.rootElement.setChild('consoleholder',this.consoleholder);
  this.systemmessage = this.rootElement.createChild('systemmessage','div');
  this.rootElement.setChild('systemmessage',this.systemmessage);
  this.freepanel = this.rootElement.createChild('freepanel','div');
  this.rootElement.setChild('freepanel',this.freepanel);
  this.alert = this.rootElement.createChild('alert','div');
  Rococo.pnl.recreateAlert(this.alert);
  this.alert.style.display = 'none';
  this.rootElement.setChild('alert',this.alert);
  /* マップホルダのサイズ設定 */
  if( options && options.mapw ) {
    this.mapholder.style.width = options.mapw;
  }
  if( options && options.maph ) {
    this.mapholder.style.height = options.maph;
  }
  if( constraction & 0x01 ) { this.appendTopMenu(Rococo.rccgm.preset.createTopMenuSettings(this,['view','gotodd','jpgeocode'])); }
  if( constraction & 0x02 ) { this.createMap(); }
};
Rococo.rccgm.Rccgm.prototype.showAlert = function( title, lines, type, listeners ) {
  if( Rococo.browser && Rococo.browser.agent == 'ie' && parseFloat(Rococo.browser.version) < 7.0 ) {
    var topmenuholder = this.topmenuholder;
    var mapholder = this.mapholder;
    var consoleholder = this.consoleholder;
    var systemmessage = this.systemmessage;
    var freepanel = this.freepanel;
    var d_topmenuholder = topmenuholder.style.display;
    var d_mapholder = mapholder.style.display;
    var d_consoleholder = consoleholder.style.display;
    var d_systemmessage = systemmessage.style.display;
    var d_freepanel = freepanel.style.display;
    topmenuholder.style.display = 'none';
    mapholder.style.display = 'none';
    consoleholder.style.display = 'none';
    systemmessage.style.display = 'none';
    freepanel.style.display = 'none';
    if( !listeners ) {
      listeners = new Array();
    }
    var fnc_switcher = function() {
      topmenuholder.style.display = d_topmenuholder;
      mapholder.style.display = d_mapholder;
      consoleholder.style.display = d_consoleholder;
      systemmessage.style.display = d_systemmessage;
      freepanel.style.display = d_freepanel;
    };
    listeners.push({'type': 'close', 'handler': fnc_switcher});
  }
  this.alert.show(title,lines,type,listeners);
};
Rococo.rccgm.Rccgm.prototype.getChild = function(subid) {
  return this.rootElement.getChild(subid);
};
Rococo.rccgm.Rccgm.prototype.setChild = function(subid,element) {
  return this.rootElement.setChild(subid,element);
};
Rococo.rccgm.Rccgm.prototype.appendTopMenu = function(settings) {
  if( this.topmenuholder == null ) { return; }
  for( var m in settings ) {
    var menuset = settings[m];
    this.topmenuholder.appendItem(menuset.subid,menuset.title,menuset.helplines,menuset.cn_prefix,false,menuset.items);
  }
};
Rococo.rccgm.Rccgm.prototype.createMap = function() {
    var options = this.options;
    var thisobj = this;
    if( options.mapw && options.maph ) {
      this.setMapSize({width: options.mapw, height: options.maph});
    }
    else {
      this.changeMapSize();
    }
    this.map = new GMap2(this.mapholder.getChild('map'));
    this.map.setCenter(new GLatLng(parseFloat(options.lat),parseFloat(options.lon)),parseFloat(options.zoom));
    this.map.setMapType(options.type);
    this.map.enableDoubleClickZoom();
    this.map.enableContinuousZoom();
    if( options.mapcontrol == 2 ) {
      this.map.addControl(new GLargeMapControl());
    }
    else if( options.mapcontrol == 1 ) {
      this.map.addControl(new GSmallMapControl());
    }
    if( options.typecontrol ) {
      this.map.addControl(new GMapTypeControl());
    }
    /* フォーカス用オーバレイ生成 */
    this.onMapMove();
    /* マップ移動イベントをつかまえる */
    var handle = this.handle;
    GEvent.addListener(this.map, 'move', function() { thisobj.onMapMove(); } );
    if( options != null && options.cmark != null && options.cmark.visible != null ) {
      this.setCmarkVisible(options.cmark.visible);
    }
/*
    if( this.mapholder != null && this.mapholder.getChild('map') != null ) {
      var divmap = this.mapholder.getChild('map');
      var thisobj = this;
      divmap.addEventHandler('mousewheel', function(event) {thisobj.onMouseWheel(event);} );
      this.setMouseWheelEnable( (options!=null && options.mousewheel==true) );
    }
*/
  var menu_view = this.topmenuholder.getChild('view');
  if( menu_view != null ) {
    var ck_mousewheel = menu_view.getItem('mousewheel').getChild('input');
    if( ck_mousewheel ) {
      ck_mousewheel.addEventHandler('change', function(event) { thisobj.changeScrollWheelEnabled();});
    }
  }
  var wheelenabled = (options!=null && options.mousewheel==true);
  this.setMouseWheelEnable( wheelenabled );
};
Rococo.rccgm.Rccgm.prototype.setMapSize = function(size) {
  if( size == null ) {
    return;
  }
  var latlng = this.map != null ? this.map.getCenter() : null;
  var wstr = size.width;
  var hstr = size.height;
  var w = null ,h = null;
  if( wstr != null && wstr != '' ) {
    w = new Rococo.ut.CssNumberUnit(wstr);
    if( w && w.number > 0 && this.mapelement != null ) {
      this.mapelement.style.width = w.ToString();
    }
  }
  if( hstr != null && hstr != '' ) {
    h = new Rococo.ut.CssNumberUnit(hstr);
    if( h && h.number > 0 && this.mapelement != null ) {
      this.mapelement.style.height = h.ToString();
    }
  }
  if( this.topmenuholder
	&& this.topmenuholder.getChild('view')
	&& this.topmenuholder.getChild('view').getItem('size')
	&& this.topmenuholder.getChild('view').getItem('size').getChild('input')
	&& w != null && w.unit == 'px' && h != null && h.unit == 'px' ) {
    var value = w.number + 'x' +  h.number;
    var found = false;
    var select = this.topmenuholder.getChild('view').getItem('size').getChild('input');
    var arr = select.getElementsByTagName('option');
    var len = arr.length;
    for( var n = 0; n < len; n++ ) {
      if( arr[n].value == value ) {
        found = true;
      }
    }
    if( found == false ) {
      select.selectedIndex = 0;
    }
  }
  if( this.map != null ) {
    this.map.checkResize();
    if( latlng != null ) {
      this.map.setCenter(latlng);
    }
    this.onMapMove();
  }
};
Rococo.rccgm.Rccgm.prototype.setCmarkVisible = function(visible) {
    if( this.cmark == null ) { return; }
    /* フォーカスオーバレイが存在するなら削除 */
    if( this.cmark.marker != null ) {
      this.map.removeOverlay( this.cmark.marker );
      this.cmark.marker = null;
    }
    var ck = null;
    if( this.topmenuholder != null ) {
      var menu_view = this.topmenuholder.getChild('view');
      if( menu_view != null ) {
        ck = menu_view.getItem('cmark').getChild('input');
      }
    }
    if( visible == true ) {
      /* フォーカスオーバレイを新たに生成→追加 */
      if( this.cmark.opts != null ) {
        this.cmark.marker = new GMarker(this.map.getCenter(), this.cmark.opts);
        this.map.addOverlay(this.cmark.marker);
      }
      if( ck ) { ck.setValue(true); }
    }
    else {
      if( ck ) { ck.setValue(false); }
    }
};
Rococo.rccgm.Rccgm.prototype.changeCmarkVisible = function() {
    /* チェックを見る */
    var ck = null;
    if( this.topmenuholder ) {
      var menu_view = this.topmenuholder.getChild('view');
      if( menu_view ) {
        ck = menu_view.getItem('cmark').getChild('input');
      }
    }
    if( ck != null ) {
      this.setCmarkVisible(ck.getValue());
    }
    else {
      if( this.options && this.options.cmark ) {
        this.setCmarkVisible(this.options.cmark.visible);
      }
    }
};
Rococo.rccgm.Rccgm.prototype.setMouseWheelEnable = function(enabled) {
    var ck = null;
    if( this.topmenuholder != null ) {
      var menu_view = this.topmenuholder.getChild('view');
      if( menu_view != null ) {
        ck = menu_view.getItem('mousewheel').getChild('input');
      }
    }
    if( ck != null ) {
      ck.setValue(enabled == true ? true : false);
    }
    this.changeScrollWheelEnabled();
};
Rococo.rccgm.Rccgm.prototype.changeMapSize = function() {
  if( this.topmenuholder
	&& this.topmenuholder.getChild('view')
	&& this.topmenuholder.getChild('view').getItem('size')
	&& this.topmenuholder.getChild('view').getItem('size').getChild('input') ) {
    var s_size =  this.topmenuholder.getChild('view').getItem('size').getChild('input').getValue();
    if( s_size == null || s_size == '' ) {
      return;
    }
    var arr_size = s_size.split('x');
    if( arr_size && arr_size.length == 2 ) {
      this.setMapSize({width:arr_size[0],height:arr_size[1]});
    }
  }
  else if( this.rootElement && this.rootElement.getCssProperty ) {
    var w = this.mapelement.getCssProperty('width');
    var h = this.mapelement.getCssProperty('height');
    if( w && h ) {
      this.setMapSize({'width': w, 'height': h });
    }
  }
};
Rococo.rccgm.Rccgm.prototype.changeMapCenter = function() {
    if( this.topmenuholder == null ) { return; }
    var menu_gotodd = this.topmenuholder.getChild('gotodd');
    if( menu_gotodd == null ) { return; }
    var tLat = menu_gotodd.getItem('lat').getChild('input');
    var tLon = menu_gotodd.getItem('lon').getChild('input');
    if( this.map != null && tLat != null && tLon != null ) {
      this.map.setCenter( new GLatLng(tLat.getValue(),tLon.getValue()), this.map.getZoom() );
    }
};
Rococo.rccgm.Rccgm.prototype.changeScrollWheelEnabled = function() {
  if( this.map != null ) {
    var menu_view = this.topmenuholder.getChild('view');
    if( menu_view != null ) {
      var ck_mousewheel = menu_view.getItem('mousewheel').getChild('input');
      if( ck_mousewheel ) {
        var enabled_new = ck_mousewheel.getValue();
        var enabled_old = this.map.scrollWheelZoomEnabled();
        if( enabled_old != enabled_new ) {
          if( enabled_new ) {
            this.map.enableScrollWheelZoom();
          }
          else {
            this.map.disableScrollWheelZoom();
          }
        }
      }
    }
  }
};
Rococo.rccgm.Rccgm.prototype.onMouseWheel = function(event) {
    if( this.map == null ) { return; }
    var flg_mwheel = null;
    var flg_cmark = null;
    if( this.topmenuholder != null ) {
      var menu_view = this.topmenuholder.getChild('view');
      if( menu_view != null ) {
        if( menu_view.getItem('mousewheel') != null && menu_view.getItem('mousewheel').getChild('input') != null ) {
          flg_mwheel = menu_view.getItem('mousewheel').getChild('input').getValue();
        }
        if( menu_view.getItem('cmark') != null && menu_view.getItem('cmark').getChild('input') != null ) {
          flg_cmark = menu_view.getItem('cmark').getChild('input').getValue();
        }
      }
    }
    if( flg_mwheel == null ) {
      flg_mwheel = this.options ? this.options.mousewheel : false;
    }
    if( flg_cmark == null ) {
      if( this.options != null && this.options.cmark != null ) {
        flg_cmark = this.options.cmark.visible;
      }
      if( flg_cmark == null ) {
        flg_cmark = false;
      }
    }
    if( flg_mwheel != true ) { return; }
    var d = 0;
    if( event == null ) { event = window.event; }
    if( event.wheelDelta != null ) {
      d = event.wheelDelta / 120;
      d = -d;
    }
    else if( event.detail ) {
      d = event.detail / 3;
    }
    var dz = (d < 0 ? 1 : (d > 0 ? -1: 0));
    this.map.setZoom(this.map.getZoom() + dz );
    if( event.preventDefault ) { event.preventDefault(); }
    event.returnValue = false;
};
Rococo.rccgm.Rccgm.prototype.onMapMove = function() {
    this.changeCmarkVisible();
    if( this.topmenuholder == null ) { return; }
    var form = this.topmenuholder.getChild('gotodd');
    if( form == null ) { return; }
    var tLat = form.getItem('lat').getChild('input');
    var tLon = form.getItem('lon').getChild('input');
    if( tLat != null && tLon != null ) {
      if( this.map != null ) {
        var now_latlon = this.map.getCenter();
        if( now_latlon != null ) {
          tLat.setValue(now_latlon.lat());
          tLon.setValue(now_latlon.lng());
        }
      }
    }
};
Rococo.rccgm.Rccgm.prototype.onGotJPGeocode = function( status, res ) {
    if( status == false )  { this.getChild('systemmessage').writeXhtml( '<p>'+res+'</p>' ); }
    else if( this.map != null ) {
      this.map.setCenter(new GLatLng(res.result.latitude,res.result.longitude), this.map.getZoom() );
    }
};
Rococo.rccgm.Rccgm.prototype.onChangePref = function() {
    if( this.topmenuholder == null ) { return null; }
    var menu_jpgeocode = this.topmenuholder.getChild('jpgeocode');
    if( menu_jpgeocode == null ) { return null; }
    /* pref select取得 */
    var thisobj = this;
    var select = menu_jpgeocode.getItem('pref').getChild('input');
    var pcode = select.value;
    var sel_mncpl = menu_jpgeocode.getItem('mncpl').getChild('input');
    sel_mncpl.clearAllChildren();
    sel_mncpl.appendOptions([Rococo.tk.preset.emptyline_integer]);
    if( pcode > 0 ) {
      var urlset, decset, req;
      urlset = Rococo.jp.cl.jsonp.municipalitylist.url;
      decset = Rococo.jp.cl.jsonp.municipalitylist.decision;
      req = new Rococo.cl.jsonp.JsonpRequest('municipalitylist', urlset, decset );
      req.request('pcode='+pcode,function(status,result){thisobj.onGotMncpl(status,result);});
      urlset = Rococo.jp.cl.jsonp.geocode.url;
      decset = Rococo.jp.cl.jsonp.geocode.decision;
      req = new Rococo.cl.jsonp.JsonpRequest('geocode', urlset, decset );
      req.request('pcode='+pcode,function(status,result){thisobj.onGotJPGeocode(status,result);});
    }
};
Rococo.rccgm.Rccgm.prototype.onGotMncpl = function( status, res ) {
  if( this.topmenuholder == null ) { return; }
  var menu_jpgeocode = this.topmenuholder.getChild('jpgeocode');
  if( menu_jpgeocode == null ) { return; }
  var sel_mncpl = menu_jpgeocode.getItem('mncpl').getChild('input');
  sel_mncpl.clearAllChildren();
  sel_mncpl.appendOptions([Rococo.tk.preset.emptyline_integer]);
  if( status == false )  { this.getChild('systemmessage').writeXhtml( "<p>市区町村取得でエラーが発生しました " + res + '</p>' ); }
  else {
    var len = res.result.municipality.length;
    var arr = new Array();
    for( var n = 0; n < len; n++ ) {
      var mncpl = res.result.municipality[n];
      arr.push({text: mncpl.mname, value: mncpl.mcode});
    }
    sel_mncpl.appendOptions(arr);
  }
};
Rococo.rccgm.Rccgm.prototype.onChangeMncpl = function() {
  if( this.topmenuholder == null ) { return; }
  var menu_jpgeocode = this.topmenuholder.getChild('jpgeocode');
  if( menu_jpgeocode == null ) { return; }
  var thisobj = this;
  var select = menu_jpgeocode.getItem('mncpl').getChild('input');
  var mcode = select.getValue();
  if( mcode > 0 ) {
    var urlset = Rococo.jp.cl.jsonp.geocode.url;
    var decset = Rococo.jp.cl.jsonp.geocode.decision;
    var req = new Rococo.cl.jsonp.JsonpRequest('geocode', urlset, decset );
    req.request('mcode='+mcode,function(status,result){thisobj.onGotJPGeocode(status,result);});
  }
};

