////////////////////////////////////////////////////////////////////////////////
//
//
// ラスター地図表示/操作スクリプト
//
//
////////////////////////////////////////////////////////////////////////////////
//
// ■更新履歴
//
// 2004/12/27	YOSHIDA		1.0.00	新規作成
// 2005/02/01	YOSHIDA		1.0.10	道路交通情報対応 loadTraffic() unloadTraffic() isTraffic()
// 2005/02/03	YOSHIDA		1.0.20	スケール画像が用意必須だったが、無くてもエラーが出ないよう修正
// 2005/02/03	YOSHIDA		1.0.30	地図上のScale,Target,Directionの表示/非表示を切り替え可能に
// 2005/02/08	YOSHIDA		1.0.40	setForm()しなくも描画できるように修正
//									<input name="lon"><input name="lat">を設置しなくても描画できるように修正
//									移動係数関連のインターフェイスを追加
//									パレットファイル関係のインターフェイスを追加
// 2005/02/10	YOSHIDA		1.0.50	DrawScale=2が指定できるよう対応

// 2005/03/11	YOSHIDA		1.0.60	任意のkey値に結びつくvalue値を設定可能に。

// 2005/03/16	YOSHIDA		1.0.70	回転中、上下左右キーでの移動不具合を解消

//				ISHIKAWA	1.0.80	ImageRasterNV_getForm　ImageRasterNV_getLevel 追加
// 2005/04/05	YOSHIDA		1.1.00	ルートの出発地目的地を個別のアイコンで表示できるよう修正
//									addIcon()の返り値として配列インデックスを返すよう修正
// 2005/05/26	YOSHIDA		1.2.00	各イベント関数を定義
// 2005/05/30	YOSHIDA		1.3.00	複数経路を描画できるように修正(Routeクラスを追加)
//									serRoute(),setMethod(),setRouteColor()のパラメータを修正
// 2005/06/24	YOSHIDA		1.3.01	delRoute()に引数isDelIconを追加。Route削除時のIcon削除をコントロール
//									setRouteWithIcons()にmethod引数を追加
// 2005/06/27	YOSHIDA		1.3.02	delRoute(idx,isDelIcon)で、routeオブジェクトの個数以上のidxを指定した際falseを返す(エラー回避)
// 2005/08/18	YOSHIDA		2.0.00	ラスター地図上にレイヤーを配置させるクラスを作成
// 2005/09/20	YOSHIDA		2.0.01	window.onloadで地図を描画するよう変更
// 2005/09/25	YOAHIDA		2.1.00	アイコンレイヤーを使用する際は<div>タグで地図を生成するよう変更
// 2005/09/29	YOAHIDA		2.1.01	地図上に任意の緯度経度にメッセージを出せるようにする createMsg(lon,lat,text)を実装

// 2005/09/30	YOSHIDA		2.1.10	レイヤーメッセージクラスを作成(外部からもメッセージクラス生成可能)
//									ImageRaster.MessageCreator(経度,緯度,'表示内容');で作成
//									実装メソッド：close() active() moveTo(x,y) changeText(String)
//									moveTo(x,y)はImageRaster.transLonToPix(経度) ImageRaster.transLatToPix(緯度)と併せて使用可能。

// 2005/10/03	YOSHIDA		2.1.11	createIconLayer()にntMsg引数を追加。生成したアイコンクリック時に表示するメッセージを指定出来るように修正
//							2.1.12	NTLayerMessageクラスに以下のメソッドを追加
//									↓表示画像を定義
//									NTLayerMessage.setBoardImage(top_image_src,backgournd_image_src,bottom_image_src);
//									↓影画像を定義
//									NTLayerMessage.setShadowImage(image_src)
//									↓ボタン画像を定義
//									NTLayerMessage.setCloseImage(image_src)
// 2005/10/04	YOSHIDA		2.1.20	createMapToolbar()により、地図内にスケール変更ツールボックスを表示する。

//									ツールボックスはImageRasterで保持しているlevelレンジを参照しツールバーを作成
// 2005/10/06	YOSHIDA		2.1.21	movemap()すると緯度の値が正常に取得できない問題を解決
// 2005/10/06	YOSHIDA		2.1.22	setScaleWithCenter(lon1,lat1,lon2,lat2....lonn,latn)で中心地点は固定で指定した地点を全て含むスケールとズームをセットする
// 2005/10/11	YOSHIDA		2.1.23	createIconLayerImage()第三・第四引数に画像サイズを追加
//									createIconLayerImage(画像パス,画像パス,横サイズ,縦サイズ,経度,緯度,名称,住所,電話,メッセージ)
// 2005/10/12	YOSHIDA		2.1.24	ImageRaster.sageCreator数を追加 ( isClose(true/false), isMove(true/false))
// 2005/10/13	YOSHIDA		2.1.25	ImageRaster.delRouteAll()を追加
// 2005/10/13	YOSHIDA		2.1.26	ブラウザキャッシュ防止の為、this.IconLayersがNullで無い場合、image urlにtime引数を追加
// 2005/11/02	YOSHIDA		2.1.30	FireFox/NN7/Opera/Sleipnirに対応

// 2006/03/13	NAKAO		2.1.40	有料道路対応 ImageRasterNVへのパラメータを追加
// 2006/03/29	NAKAO		2.1.41	渋滞考慮対応 loadTrafficへのパラメータを追加
	
//////////////////////////////////////////////////////////////////////
//
// オーバーライド関数
//
//////////////////////////////////////////////////////////////////////

// @param	: なし

// @return	: なし

// @		: 地図をクリックした時のコールされる関数。要オーバーライド


function onMapClick(){}

// @param	: なし

// @return	: なし

// @		: 地図が移動した時のコールされる関数。要オーバーライド


function onMapMove(lon,lat){}

// @param	: なし

// @return	: なし

// @		: 地図がロードされ時のコールされる関数。要オーバーライド


function onMapLoad(ImageRasterClass){}

// @param	: 変更前width , 変更前height , 変更後width , 変更後height
// @return	: なし

// @		: 地図画像サイズを変更した時のコールされる関数。要オーバーライド


function onChgMapSizeNum(a,b,c,d){}

// @param	: 変更前地図サイズインデックス , 変更後地図サイズインデックス
// @return	: なし

// @		: 地図画像サイズを変更した時のコールされる関数。要オーバーライド


function onChgMapSizeIdx(a,b){}

// @param	: 変更スケール値 , 変更後スケール値
// @return	: なし

// @		: スケール値を変更した時のコールされる関数。要オーバーライド


function onChgMapScale(a,b){}

// @param	: 変更前ズーム値 , 変更後ズーム値
// @return	: なし

// @		: ズーム値を変更した時のコールされる関数。要オーバーライド


function onChgMapZoom(a,b){}

// @param	: 変更前レベル値 , 変更後レベル値
// @return	: なし

// @		: レベル値を変更した時のコールされる関数。要オーバーライド


function onChgMapLevel(a,b){}

// @param	: 変更前回転角度 , 変更後回転角度
// @return	: なし

// @		: 回転角度を変更した時のコールされる関数。要オーバーライド


function onChgMapAngle(a,b){}


//////////////////////////////////////////////////////////////////////
//
// ImageRasterオブジェクト外関数
//
//////////////////////////////////////////////////////////////////////

// @param	: レイヤーID , 目標X座標 , 目標Y座標

// @return	: なし

// @		: 地図上に表示されたレイヤーを動かします。

/*
function moveMap(id,x,y){
	var m = document.images(id);
	var mx = new Number(m.style.left.substr(0,m.style.left.indexOf("px")));
	var my = new Number(m.style.top.substr(0,m.style.top.indexOf("px")));
	m.style.left = mx - (mx-x)/10;
	m.style.top = my - (my-y)/10;
	if(Math.abs(x - m.style.left.substr(0,m.style.left.indexOf("px")))<2) m.style.left = x;
	if(Math.abs(y - m.style.top.substr(0,m.style.top.indexOf("px")))<2) m.style.top = y;

	if(m.style.left.substr(0,m.style.left.indexOf("px")) != x || m.style.top.substr(0,m.style.top.indexOf("px")) != y){
		var a = setTimeout("moveMap('"+id+"',"+x+","+y+")",10);
	}
}
*/

var ImageRasterGroup = new Array();
var WindowLoaded = false;
function addImageRasterGroup(obj){
	ImageRasterGroup[ImageRasterGroup.length] = obj;
}

window.onload = function(){
	for(var i=0; i < ImageRasterGroup.length; i++){
		ImageRasterGroup[i].init();
	}
	WindowLoaded = true;
};

var b = new Browser();
if(b.isNN4){
	window.captureEvents(Event.MOUSEDOWN);
	window.onmousedown = function(e){
		for(var i=0; i < ImageRasterGroup.length; i++){
			ImageRasterGroup[i].mapClickNN47(e.target,e.layerX,e.layerY);
		}
	};
	window.captureEvents(Event.ONLOAD);
	window.onLoad = function(e){
		for(var i=0; i < ImageRasterGroup.length; i++){
			ImageRasterGroup[i].init();
		}
	};
}

function getParent(obj){
	if(b.isIe5){ return obj.parentElement; }
//	if(b.isNN6) return obj.parentLayer;
	if(b.isFF || b.isOpera || b.isNN6){ return obj.parentNode;}
	return obj;
}

// スタイルシート

document.write('<STYLE type="text/css"><!--');
document.write('.clsIconFaceOff {');
document.write('    background-color : FF0000;');
document.write('    vertical-align   : middle;');
document.write('    padding-left: 3px;');
document.write('    padding-top: 1px;');
document.write('    padding-right: 2px;');
document.write('    padding-bottom: 1px;');
document.write('    font-weight	 : bold;');
document.write('    text-align   : center;');
document.write('    cursor: hand;');
document.write('    width :15px ;');
document.write('    height:15px ;');
document.write('    font-size:10px ;');
document.write('    color:#000000 ;');
document.write('    BORDER-LEFT:  #000000 1px solid;');
document.write('    BORDER-TOP: #000000 1px solid;');
document.write('    BORDER-RIGHT:  #000000 1px solid;');
document.write('    BORDER-BOTTOM: #000000 1px solid;');
document.write('}');
document.write('.clsIconFaceOn {');
document.write('    background-color : 000000; ');
document.write('    vertical-align   : middle;');
document.write('    padding-left: 3px;');
document.write('    padding-top: 1px;');
document.write('    padding-right: 2px;');
document.write('    padding-bottom: 1px;');
document.write('    font-weight	 : bold;');
document.write('    text-align   : center;');
document.write('    width :15px ;');
document.write('    height:15px ;');
document.write('    font-size:10px ;');
document.write('    color:#FFFFFF ;');
//document.write('    text-indent	 : 2px;');
document.write('    cursor: hand;');
document.write('    BORDER-LEFT:  #FFFFFF 1px solid;');
document.write('    BORDER-TOP: #FFFFFF 1px solid;');
document.write('    BORDER-RIGHT:  #003897 1px solid;');
document.write('    BORDER-BOTTOM: #003897 1px solid;');
document.write('}');
document.write('--></STYLE>');


//////////////////////////////////////////////////////////////////////
//
// クラス：ImageRasterNV
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: 地図操作クラスの定義
//
function ImageRasterNV(image,lon,lat,w,h,ismove){

	//
	// Properties
	//

	var gTool = null;
	var gMapImage = null;
	var copyright=null;
	// 地図画像がロードされたかどうか(連続クリック対策：ロードされないと次のクリックは無視)
	loaded = false;
	loading = false;
	this.isMove = ismove != null ? ismove : true;
	this.path = "";
	this.MapIntarfaceURL = "http://leo2.navitime.co.jp/navitest/yoshida/MapImage_us.jsp";
	this.className = "ImageRasterNV";
	// 各メッシュの1pxに相当する経度移動値
	this.arrpxLon = new Array("200000","33333","2727","818","163");
	// 各メッシュの1pxに相当する緯度移動値
	this.arrpxLat = new Array("160000","26667","2223","667","134");

	this.mapScale = new Array();
	this.param = new Array();
	this.targetForm = null;

	this.scale = 3;
	this.zoom  = 3;
	this.level = 0;
	this.angle = 0;

	var MapWidth = w;
	var MapHeight = h;
	this.MapSizeLevel = 1;
	this.MapSizes = new Array();

	this.Longitude = lon;
	this.Latitude = lat;
	this.Palette = "";

	this.OffsetX=0;
	this.OffsetY=0;
	// 経路設定

	this.route = new Array();
	this.traffic = "";

	// 距離画像

	this.imgRange = new Array();
	// 地図上に表示するアイコンクラス
	this.icons = new Array();
	this.MapIconScale = 1;
	this.MapIconDirection = 1;
	this.MapIconTarget = 0;
	this.IconLayers = new Array();
	//ローカル変数
	this.frame=null;
	//
	// Methods
	//

	this.getMapObject = 	function(){ return gMapImage; };
	this.setMapServer = 	function(url){this.MapIntarfaceURL = url;};
	this.getMapServer = 	function(){ return this.MapIntarfaceURL;};
	this.getMapSizeX = 		function(){ return MapWidth;};
	this.setMapSizeX = 		function(w){
		if(this.gMapLayer!=null){
			getParent(this.gMapLayer).style.width = w;
		}
		if(this.frame != null && (b.isFF || b.isNN)){
			getParent(this.frame).style.width = w;
		}
		MapWidth = w;
	};
	this.getMapSizeY = 		function(){ return MapHeight;};
	this.setMapSizeY = 		function(h){
		if(this.gMapLayer!=null){
			getParent(this.gMapLayer).style.height = h;
		}
		if(this.frame != null && (b.isFF || b.isNN)){
			getParent(this.frame).style.height = h;
		}
		MapHeight = h;
	};
	
	this.getScale = 		function(){ return this.scale;};
	this.getZoom = 			function(){ return this.zoom;};
	this.setScale = 		function(i){ if(this.scale!=i){ onChgMapScale(this.scale,i);} this.scale=i;};
	this.setZoom = 			function(i){ if(this.zoom!=i){ onChgMapScale(this.zoom,i);} this.zoom=i;};
	this.setLevel = 		function(l){ this.level = l; this.setScale(this.mapScale[l].scale); this.setZoom(this.mapScale[l].zoom);};
	this.getLevel = 		function(){ return this.level; };
	this.getLon = 			function(){ return new Number(this.Longitude);};
	this.getLat = 			function(){ return new Number(this.Latitude);};
	this.getLonDMS_Object = function(){ return new DegreeMinuteSecond(this.getLon());};
	this.getLatDMS_Object = function(){ return new DegreeMinuteSecond(this.getLat());};
	this.setLon = 			function(x){ this.Longitude = x;};
	this.setLat = 			function(y){ this.Latitude = y;};
	this.getAngle = 		function(){ return new Number(this.angle);};
	this.setAngle = 		function(a){ if(a < 0){a = 360+a;} if(a > 359){a = a-360;} if(this.angle!=a) onChgMapAngle(this.angle,a); this.angle = a; this.drawImage();};


	this.setScaleWithCenter = function(){

		var newScale = 1;
		var newZoom = 1;
		var lonRange=0;
		var latRange=0;
		for(var i=0; i<this.setScaleWithCenter.arguments.length; i+=2){
			var lon = this.setScaleWithCenter.arguments[i];
			var lat = this.setScaleWithCenter.arguments[i+1];

			if(lon==null || lat==null){ continue;}
			if(Math.abs(lon - this.getLon()) > lonRange){ lonRange = Math.abs(lon - this.getLon());}
			if(Math.abs(lat - this.getLat()) > latRange){ latRange = Math.abs(lat - this.getLat());}
		}
		lonRange = lonRange * 2 + 10000;
		latRange = latRange * 2 + 10000;

		var maxScale = this.getMapScaleLength() > 0 ? this.mapScale[this.getMapScaleLength()-1].scale : 0;
		var minScale = this.getMapScaleLength() > 0 ? this.mapScale[0].scale: 4;
		loops:for(iscale = maxScale; iscale >= minScale; iscale--){
			loopz:for(izoom = 30; izoom > 2; izoom--){
				var pxOfLon = Math.ceil(this.arrpxLon[iscale]/izoom);
				var pxOfLat = Math.ceil(this.arrpxLat[iscale]/izoom);
				if(this.getMapSizeX() * pxOfLon > lonRange && this.getMapSizeY() * pxOfLat > latRange){
					newScale = iscale;
					newZoom = izoom;
					break loops;
					break loopz;
				}
			}
		}

		this.setScale(newScale);
		this.setZoom(newZoom);
	};

	//////////////////////////////////////////////////////////////////////
	//
	// スケール追加
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: minlon = 経度の最小値
	// 			: minlat = 緯度の最小値
	// 			: maxlon = 経度の最大値
	// 			: maxlat = 緯度の最大値
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 緯度経度の最小最大値から、2点が一画面に表示できるスケールを追加
	//
	this.setScaleLonLat = function(){
		var newScale = 1;
		var newZoom = 1;
		var newLevel = this.getMapScaleLength();
		var maxlon=0;
		var minlon=0;
		var maxlat=0;
		var minlat=0;
		for(var i=0; i<this.setScaleLonLat.arguments.length; i+=2){
			var lon = this.setScaleLonLat.arguments[i];
			var lat = this.setScaleLonLat.arguments[i+1];

			if(lon==null || lat==null){ continue;}
			if(maxlon == 0 || maxlon < lon){ maxlon=lon;}
			if(minlon == 0 || minlon > lon){ minlon=lon;}
			if(maxlat == 0 || maxlat < lat){ maxlat=lat;}
			if(minlat == 0 || minlat > lat){ minlat=lat;}
		}
		// 多少の余裕を持つため緯度経度間隔値を1割増

		var lonRange = Math.abs(maxlon - minlon)+10000;
		var latRange = Math.abs(maxlat - minlat)+10000;

		var maxScale = this.getMapScaleLength() > 0 ? this.mapScale[this.getMapScaleLength()-1].scale : 0;
		var minScale = this.getMapScaleLength() > 0 ? this.mapScale[0].scale: 4;
		loops:for(iscale = maxScale; iscale >= minScale; iscale--){
			loopz:for(izoom = 30; izoom > 2; izoom--){
				var pxOfLon = Math.ceil(this.arrpxLon[iscale]/izoom);
				var pxOfLat = Math.ceil(this.arrpxLat[iscale]/izoom);
				if(this.getMapSizeX() * pxOfLon > lonRange && this.getMapSizeY() * pxOfLat > latRange){
					newScale = iscale;
					newZoom = izoom;
					break loops;
					break loopz;
				}
			}
		}

		for(var i=0; i < this.getMapScaleLength(); i++){
			if(this.mapScale[i].scale == newScale && this.mapScale[i].zoom == newZoom){
				this.setLevel(i);
				return;
			}
		}
		if(newScale == 1 && newZoom == 1){
			newZoom = 2;
		}
		this.addMapScale(newScale,newZoom);
		this.setLevel(newLevel);
	};

	//////////////////////////////////////////////////////////////////////
	//
	// スケール郡のソート

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 登録されているスケールを小さい順にソートする

	//
	this.sortMapScale = 	function(){
		var wkScale = new Array();
		var lv = 0;
		for(var i=0; i < this.getMapScaleLength(); i++){
			// 空のMapScaleクラスを生成

			wkScale[i] = new MapScale(0,0);
			if(i==0){
				wkScale[i].scale = this.mapScale[i].scale;
				wkScale[i].zoom = this.mapScale[i].zoom;
			}else{
				for(var x=wkScale.length-2; x >= 0 ; x--){
					if((this.mapScale[i].scale == wkScale[x].scale && this.mapScale[i].zoom > wkScale[x].zoom)|| this.mapScale[i].scale > wkScale[x].scale || x == 0){

						wkScale[x+1].scale = this.mapScale[i].scale;
						wkScale[x+1].zoom = this.mapScale[i].zoom;
						if(this.level == i){
							lv = x+1;
						}
						break;
					}else{
						wkScale[x+1].scale = wkScale[x].scale;
						wkScale[x+1].zoom = wkScale[x].zoom;
						if(this.level == x){
							lv = x+1;
						}
					}
				}
			}
		}
		this.mapScale = wkScale;
		this.setLevel(lv);
	};

	this.getLonDMS = function(){
		var tmp_do=(this.getLon()-this.getLon()%3600000)/3600000;
		var tmp_fun=((this.getLon()-tmp_do*3600000)-(this.getLon()-tmp_do*3600000)%60000)/60000;
		var tmp_byou=((this.getLon()-tmp_do*3600000-tmp_fun*60000)-((this.getLon()-tmp_do*3600000-tmp_fun*60000)%1000))/1000;
		var ret;
		ret = tmp_do+'ﾟ'+tmp_fun+'\''+tmp_byou+'"';
		return ret;
	};

	this.getLatDMS = function(){
		var tmp_do=(this.getLat()-this.getLat()%3600000)/3600000;
		var tmp_fun=((this.getLat()-tmp_do*3600000)-(this.getLat()-tmp_do*3600000)%60000)/60000;
		var tmp_byou=((this.getLat()-tmp_do*3600000-tmp_fun*60000)-((this.getLat()-tmp_do*3600000-tmp_fun*60000)%1000))/1000;
		ret = tmp_do+'ﾟ'+tmp_fun+'\''+tmp_byou+'"';
		return ret;
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図移動(緯度・経度指定)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: lon = 経度
	// 			: lat = 緯度
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 緯度・経度を指定して地図を移動する

	//
	this.setLonLat = function(lon,lat){
		this.setLon(lon);
		this.setLat(lat);
		if(gMapImage != null){
			alert(3543543654);
			this.drawImage();
		}
		onMapMove(this.getLon(),this.getLat());
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図移動(緯度・経度指定)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: minlon = 経度
	// 			: minlat = 緯度
	// 			: maxlon = 経度
	// 			: maxlat = 緯度
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 最大/最小の緯度経度から中心地点の座標へ移動する

	//
	this.setLonLatMin2Max = function(){

		var maxlon=0;
		var minlon=0;
		var maxlat=0;
		var minlat=0;

		for(var i=0; i<this.setLonLatMin2Max.arguments.length; i+=2){
			var lon = this.setLonLatMin2Max.arguments[i];
			var lat = this.setLonLatMin2Max.arguments[i+1];

			if(lon==null || lat==null){ continue;}

			if(maxlon < lon || maxlon==0){ maxlon=lon;}
			if(minlon > lon || minlon==0){ minlon=lon;}
			if(maxlat < lat || maxlat==0){ maxlat=lat;}
			if(minlat > lat || minlat==0){ minlat=lat;}
		}
		var lon = Math.round(minlon + (maxlon - minlon)/2);
		var lat = Math.round(minlat + (maxlat - minlat)/2);
		this.setLon(lon);
		this.setLat(lat);
		if(gMapImage != null){
			this.drawImage();
		}
	};


	//////////////////////////////////////////////////////////////////////
	// @param	: key 引数のkey
	// @param	: value 引数の値
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: MapServerに渡す引数を追加する
	//
	this.addParam = function(key,value){
		var isThere = false;
		for(var i = 0; i < this.param.length; i++){
			if(this.param[i].key == key){
				isThere = true;
			}
		}
		if(isThere == false){
			this.param[this.param.length] = new ASPParam(key,value);
		}
	};

	//////////////////////////////////////////////////////////////////////
	// @param	: key 引数のkey
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: MapServerに渡す引数を削除する
	//
	this.delParam = function(key){
		for(var i = 0; i < this.param.length; i++){
			if(this.param[i].key == key){
				this.param[i].key = "";
				this.param[i].value = "";
			}
		}
	};


	this.setOffsetX = 		function(x){ this.OffsetX=x;};
	this.setOffsetY = 		function(y){ this.OffsetY=y;};
	this.getOffsetX = 		function(){ return this.OffsetX;};
	this.getOffsetY = 		function(){ return this.OffsetY;};

	//////////////////////////////////////////////////////////////////////
	//
	// 経路描画
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: lon1 = 出発地点：経度
	// 			: lat1 = 出発地点：緯度
	// 			: lon2 = 到着地点：経度
	//			: lat2 = 到着地点：緯度
	//			: method
	//			: orvicon
	//			: dnvicon
	//			: orvTf
	//			: dnvTf
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上に経路を引く
	//
	this.setRoute = function(lon1,lat1,lon2,lat2,method,orvicon,dnvicon,orvTf,dnvTf){
		var index = this.icons.length;
		this.icons[index] = new Icon();
		this.icons[index].lon = lon1;
		this.icons[index].lat = lat1;
		this.icons[index].id = (orvicon==null) ? "10001" : orvicon;
		if(orvTf != null){
			this.icons[index].tollRoadFlg = orvTf;
		}
		var orv = index;

		index = this.icons.length;
		this.icons[index] = new Icon();
		this.icons[index].lon = lon2;
		this.icons[index].lat = lat2;
		this.icons[index].id = (dnvicon==null) ? "10002" : dnvicon;
		if(dnvTf != null){
			this.icons[index].tollRoadFlg = dnvTf;
		}		
		var dnv = index;

		var routeidx = this.route.length;
		this.route[routeidx] = new Route(routeidx,orv,dnv);
		this.route[routeidx].methodno = (method==null) ? 10 : method;
		if(gMapImage != null){
			this.drawImage();
		}
		return routeidx;
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 経路削除
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: int idx = routeオブジェクト指定番号(setRoute()の返り値)
	//			: boolean isDelIcon = routeで使用しているアイコンを削除するかどうか　true = 削除 false = 残す
	// @return	: boolean	true = 正常削除 / false = 削除不可
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上の経路を削除する
	//
	this.delRoute = function(idx,isDelIcon){

		var dmicons = new Array();
		var dmroute = new Array();
		var orvico,dnvico;

		if(this.route.length < 1 || this.route.length <= idx){
			return false;
		}

		if(idx!=null && idx>=0){
			orvico = this.route[idx].orv;
			dnvico = this.route[idx].dnv;
		}else if(this.route.length > 0 && idx < this.route.length){
			orvico = this.route[this.route.length-1].orv;
			dnvico = this.route[this.route.length-1].dnv;
		}else{
			return false;
		}

		if(isDelIcon==null){ isDelIcon = true;}
		// isDelIconがtrueの時はRouteに指定されたIconも削除する
		if(isDelIcon){
			for(var i=0; i < this.icons.length; i++){
				if(i != orvico && i != dnvico){
					dmicons.push(this.icons.shift());
				}
			}
			this.icons = dmicons;
		}

		for(var r=0; r < this.route.length; r++){
			if(this.route[r].id!=idx){
				dmroute.push(this.icons.shift());
			}
		}
		this.route = dmroute;

		if(gMapImage != null){
			this.drawImage();
		}
		return true;
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 経路削除
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: boolean isDelIcon = routeで使用しているアイコンを削除するかどうか　true = 削除 false = 残す
	// @return	: boolean	true = 正常削除 / false = 削除不可
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上の経路を削除する
	//
	this.delRouteAll = function(isDelIcon){

		this.route = new Array();

		// isDelIconがtrueの時は全て削除
		if(isDelIcon==null){ isDelIcon = true;}
		if(isDelIcon){ this.icons = new Array();}

		if(gMapImage != null){
			this.drawImage();
		}
		return true;
	};


	//////////////////////////////////////////////////////////////////////
	// @param	: icon1･･･出発地を表すアイコンの番号
	//            icon2･･･目的地を表すアイコンの番号
	//            method･･･移動手段
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 予め登録してあるiconを出発地アイコン、目的地アイコンに入れ替える。

	//
	this.setRouteIcons = function(icon0,icon1,method){
		var routeidx=this.route.length;
		this.route[routeidx] = new Route(routeidx,icon0,icon1);
		this.route[routeidx].methodno = (method==null) ? 10 : method;

		if(gMapImage != null){
			this.drawImage();
		}
		return routeidx;
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 交通手段設定

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: method　交通手段コード

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 経路の交通手段を設定する

	//
	this.setMethod = function(method,idx){
		if(idx != null && idx >= 0 && this.route[idx] != null){
			this.route[idx].methodno = method;
		}else if(this.route.length > 0){
			this.route[0].methodno = method;
		}else{
			return;
		}
		if(gMapImage != null){
			this.drawImage();
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 経路色指定

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: r RGB赤要素(0～255)
	//			　g RGB緑要素(0～255)
	//			　b RGB青要素(0～255)
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 経路の交通手段を設定する

	//
	this.setRouteColor =function(r,g,b,idx){
		if(idx != null && idx >= 0 && this.route[idx] != null){
			this.route[idx].R = r;
			this.route[idx].G = g;
			this.route[idx].B = b;
		}else if(this.route.length > 0){
			this.route[0].R = r;
			this.route[0].G = g;
			this.route[0].B = b;
		}else{
			return;
		}
		if(gMapImage != null){
			this.drawImage();
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 渋滞考慮パラメータ生成
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: vics 経路探索タイムスタンプ（yyyyMMddHHmmss）

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 渋滞考慮パラメータを生成する

	//
	this.loadTraffic = 		function(vics){
		if(vics != null){
			this.traffic = "&Vics="+vics;
		}else{
			this.traffic = "&Vics=00000000000000";
		} 
	};
	
	this.unloadTraffic = 	function(){ this.traffic = ""; };
	this.isTraffic = 		function(){ return (this.traffic != "") ? true: false; };
	var isFirst = true;
	//////////////////////////////////////////////////////////////////////
	//
	// 地図更新
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: x = 中心地点経度(1/1000秒単位)
	// 			: y = 中心地点緯度(1/1000秒単位)
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図画像を更新する
	//
	this.drawImage = function(){
		if(loading){ return;}
		this.getMapImage();
		if(MapName.length == 0 || gMapImage==null){
			alert("Map Image could not load " + MapName);
			return;
		}
		loading = true;
		gMapImage.src=this.getURL();

		gMapImage.width = MapWidth;
		gMapImage.height = MapHeight;
		var imgClass = this;		
		gMapImage.onload=function(){
			imgClass.drawAllLayer();
			imgClass.reloadLayer();
			// TODO Opera		
			// 画像の描画後にdivの位置を調整する
			if((b.isOpera) && isFirst && this.gMapLayer!=null){
				imgClass.frame.style.visibility = 'hidden';
				imgClass.frame.style.display = 'inline';
				imgClass.mapPosX = imgClass.frame.offsetLeft;
				imgClass.mapPosY = imgClass.frame.offsetTop;
				imgClass.frame.style.display = 'none';
				imgClass.gMapLayer.style.left = imgClass.mapPosX;
				imgClass.gMapLayer.style.top = imgClass.mapPosY;
				imgClass.frame.style.visibility = 'visible';
				isFirst=false;
			}
			onMapLoad(imgClass);
			
		};
		
		loaded = true;
		loading = false;
		
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図移動(方向キー)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: l = (1:左に移動する 0:移動なし)
	// 			: u = (1:上に移動する 0:移動なし)
	// 			: r = (1:右に移動する 0:移動なし)
	// 			: d = (1:下に移動する 0:移動なし)
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 方向リンクをクリックされた時に実行される
	//
	this.moveMap = function(l,u,r,d){
		if(loading){ return;}

		this.setOffsetX(0);
		this.setOffsetY(0);

		if(l != 0){
			this.setOffsetX(-this.getMapSizeX()/2);
		}
		if(u != 0){
			this.setOffsetY(-this.getMapSizeY()/2);
		}
		if(r != 0){
			this.setOffsetX(this.getMapSizeX()/2);
		}
		if(d != 0){
			this.setOffsetY(this.getMapSizeY()/2);
		}
		this.setLon(this.getLon() + this.transPixToPosLon(this.getOffsetX(),this.getOffsetY()));
		this.setLat(this.getLat() - this.transPixToPosLat(this.getOffsetX(),this.getOffsetY()));
		if(gMapImage != null){
			this.drawImage();
		}
		onMapMove(this.getLon(),this.getLat());
	};

	//////////////////////////////////////////////////////////////////////
	//
	// ピクセル→緯度経度変換処理

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: ピクセル値
	// @return	: 緯度または経度
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: ピクセル値をscale,zoomに準拠して緯度経度に変換する
	//
	this.transPixToPosLon = function(x,y){
		var moveX,z1,z2,z2_1,z2_2;
		if(this.getAngle() == 0){
			moveX = x;
		}else{
			//X座標Y座標の切り替え

			if(this.getAngle() < 90){
				z1 = y;
				z2 = -x;
			}else if(this.getAngle() < 180){
				z1 = -x;
				z2 = -y;
			}else if(this.getAngle() < 270){
				z1 = -y;
				z2 = x;
			}else{
				z1 = x;
				z2 = y;
			}
			r = (this.getAngle() % 90) * (3.14/180);
			z2_1 = z1 * Math.tan(r);
			z2_2 = z2 - z2_1;
			moveX = -Math.ceil(z2_2 * Math.cos(r) );
		}
		return Math.ceil(moveX * (this.arrpxLon[this.getScale()] / this.getZoom()));
	};

	this.transPixToPosLat = function(x,y){
		var moveX,z1,z2,z2_1,z2_2;
		if(this.getAngle() == 0){
			moveY = y;
		}else{
			//X座標Y座標の切り替え

			if(this.getAngle() < 90){
				z1 = y;
				z2 = -x;
			}else if(this.getAngle() < 180){
				z1 = -x;
				z2 = -y;
			}else if(this.getAngle() < 270){
				z1 = -y;
				z2 = x;
			}else{
				z1 = x;
				z2 = y;
			}
			r = (this.getAngle() % 90) * (3.14/180);
			z2_1 = z1 * Math.tan(r);
			z2_2 = z2 - z2_1;
			moveY = Math.ceil(z1 / Math.cos(r) + (z2_2 * Math.sin(r)) );
		}

		return Math.ceil(moveY * (this.arrpxLat[this.getScale()] / this.getZoom()));
	};


	//////////////////////////////////////////////////////////////////////
	//
	// ログ出力処理

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: ログ文字列
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: <textare name=log></textarea>にログを出力

	//
	this.outLog = function(msg){
		if(this.targetForm.log != null){
			this.targetForm.log.value += msg + "\n";
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図クリック処理

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上をマウスでクリックした際に中心点を移動させる
	//
	
	this.mapClickPixels = function(w,h){
		if(loading){ return;}
		this.setOffsetX(w - this.getMapSizeX()/2);
		this.setOffsetY(h - this.getMapSizeY()/2);
		this.setLon(this.getLon() + this.transPixToPosLon(this.getOffsetX(),this.getOffsetY()));
		this.setLat(this.getLat() - this.transPixToPosLat(this.getOffsetX(),this.getOffsetY()));
		if(gMapImage != null){
			this.drawImage();
		}
		onMapMove(this.getLon(),this.getLat());
	};
	
	
	//////////////////////////////////////////////////////////////////////
	//
	// 地図クリック処理(IE)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上をマウスでクリックした際に中心点を移動させる
	//
	this.mapClick = function(e){

		if(b.isNN || b.isFF){
			if(b.isNN4){ return;}
			//右クリック禁止
			if(e.which!=1){ return;}
			this.mapClickNN60(e);
			return;
		}
		//右クリック禁止
		if(!b.isOpera && window.event.button != 1){ return ;}

		var offsetX = window.event.offsetX;
		var offsetY = window.event.offsetY;

		if(this.isIe5 && this.isMac){
			offsetY += document.body.scrollTop;
		}
		this.setOffsetX(new Number(offsetX) - this.getMapSizeX()/2);
		this.setOffsetY(new Number(offsetY) - this.getMapSizeY()/2);

//		moveMap(gMapImage.id , gMapImage.style.left+(gMapImage.style.width/2-offsetX),gMapImage.style.top+(gMapImage.style.height/2-offsetY));

		this.setLon(this.getLon() + this.transPixToPosLon(this.getOffsetX(),this.getOffsetY()));
		this.setLat(this.getLat() - this.transPixToPosLat(this.getOffsetX(),this.getOffsetY()));
		if(gMapImage != null){
			this.drawImage();
		}
		onMapClick(this.getLon(),this.getLat());
		onMapMove(this.getLon(),this.getLat());
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図クリック処理(NN4.7)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: e = マウスクリックイベント

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上をマウスでクリックした際に中心点を移動させる
	//
	this.mapClickNN47 = function(target,x,y){
		if(target == gMapImage){
			NNx = x - gMapImage.x;
			NNy = y -gMapImage.y;
			this.setOffsetX(NNx - this.getMapSizeX()/2);
			this.setOffsetY(NNy - this.getMapSizeY()/2);
			this.setLon(this.getLon() + this.transPixToPosLon(this.getOffsetX(),this.getOffsetY()));
			this.setLat(this.getLat() - this.transPixToPosLat(this.getOffsetX(),this.getOffsetY()));
			if(gMapImage != null){
				this.drawImage();
			}
			onMapClick(this.getLon(),this.getLat());
			onMapMove(this.getLon(),this.getLat());
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図クリック処理(NN7)
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: e = マウスクリックイベント

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上をマウスでクリックした際に中心点を移動させる
	//
	this.mapClickNN60 =	function(e){
		if(e.target == gMapImage){
			if(gMapImage.x != null && gMapImage.y != null){
				// for NetScape 7
				NNx = e.layerX - gMapImage.x;
				NNy = e.layerY -gMapImage.y;
			}else{
				// for NetScape 6
				NNx = e.layerX - gMapImage.offsetTop;
				NNy = e.layerY -gMapImage.offsetLeft;

			}
			this.setOffsetX(NNx - this.getMapSizeX()/2);
			this.setOffsetY(NNy - this.getMapSizeY()/2);
			this.setLon(this.getLon() + this.transPixToPosLon(this.getOffsetX(),this.getOffsetY()));
			this.setLat(this.getLat() - this.transPixToPosLat(this.getOffsetX(),this.getOffsetY()));
			if(gMapImage != null){
				this.drawImage();
			}
			onMapClick(this.getLon(),this.getLat());
			onMapMove(this.getLon(),this.getLat());
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図縮尺変更処理

	//
	//////////////////////////////////////////////////////////////////////
	// @param	: scale,zoomを特定するための数値
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図の拡大、縮小を行う
	//
	this.mapSetLevel = function(level){
		if(level < 0){ return;}
		if(level >= this.getMapScaleLength()){ return;}
		if(this.getLevel() == level){ return;}
		onChgMapLevel(this.getLevel(),level);

		this.setLevel(level);
		
		if(gMapImage != null){
			this.drawImage();
		}
	};

	this.mapSetScaleZoom = function(s,z){
		if(s < 1){ return;}
		if(s > 4){ return;}
		if(z < 1){ return;}

		if(this.getScale()!=s){onChgMapScale(this.getScale(),s);}
		if(this.getZoom()!=z){onChgMapZoom(this.getZoom(),z);}

		this.setScale(s);
		this.setZoom(z);

		if(gMapImage != null){
			this.drawImage();
		}

	};

	//////////////////////////////////////////////////////////////////////
	//
	// 地図画像サイズ変更
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: width,height
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図のサイズを変更する
	//
	this.changeMapSize = function(idx){
		if(this.MapSizeLevel == idx){ return;}
		var w = this.MapSizes[idx].width;
		var h = this.MapSizes[idx].height;

		if(this.getMapSizeX==w && this.getMapSizeY == h){ return;}

		onChgMapSizeIdx(this.MapSizeLevel,idx);
		onChgMapSizeNum(this.getMapSizeX,this.getMapSizeY,w,h);

		this.MapSizeLevel = idx;
		this.setMapSizeX(w);
		this.setMapSizeY(h);

		if(gMapImage != null){
			this.drawImage();
		}
	};


	this.setPath = function(image_path){ this.path = image_path;};

	//////////////////////////////////////////////////////////////////////
	//
	// アイコン挿入
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: lon = 中心地点経度(1/1000秒単位)
	// 			: lat = 中心地点緯度(1/1000秒単位)
	//			: name = 名称
	//			: icon = ICON ID or 画像URL
	//			: position = アイコン表示位置
	//				012
	//				345
	//				678
	//			：tf = 有料道路フラグ(2･･有料道路上のPOI,1･･一般道路上のPOI,-1･･デフォルト値)	
	// @return	: 追加されたアイコン番号
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図上に表示するアイコンを追加します

	//
	this.addIcon = function(lon,lat,name,icon,position,tf){
		var index = this.icons.length;
		this.icons[index] = new Icon();
		this.icons[index].lon = lon;
		this.icons[index].lat = lat;
		this.icons[index].name = name;
		icon = new String(icon);
		if(icon != ""){
			if((icon > 0 && icon < 100) || icon.match(/^100\d{2}$/i)){
				this.icons[index].id = icon;
			}else {
				this.icons[index].image = icon;
			}
		}
		this.icons[index].position = position;
		if(tf != null){
			this.icons[index].tollRoadFlg = tf
		}
		return index;
	};

	//////////////////////////////////////////////////////////////////////
	//
	// アイコン削除
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 既存のアイコンを削除
	//
	this.delIconAll = function(){
		this.icons = new Array();
	};

	//////////////////////////////////////////////////////////////////////
	//
	// アイコン削除
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: idx = インデックス番号
	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 既存のアイコンを削除
	//
	this.delIcon = function (idx){
		var dmicons = new Array();
		for(var i=0; i < this.icons.length; i++){
			if(i != idx){
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.route[r].orv = dmicons.length;}
					if(this.route[r].dnv == i){ this.route[r].dnv = dmicons.length;}
				}
				dmicons.push(this.icons.shift());
			}else{
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.delRoute(this.route[r].id);}
					if(this.route[r].dnv == i){ this.delRoute(this.route[r].id);}
				}
			}
		}
		this.icons = dmicons;
	};

	//////////////////////////////////////////////////////////////////////
	// @param	: name = 名称
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 名称の一致するアイコンを1件削除
	//
	this.delIconByName = function(name){
		var deleted = false;
		var dmicons = new Array();
		for(var i=0; i < this.icons.length; i++){
			if(this.icons[i].name != name || deleted){
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.route[r].orv = dmicons.length;}
					if(this.route[r].dnv == i){ this.route[r].dnv = dmicons.length;}
				}
				dmicons.push(this.icons.shift());
			}else{
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.delRoute(this.route[r].id);}
					if(this.route[r].dnv == i){ this.delRoute(this.route[r].id);}
				}
				deleted = true;
			}
		}
		this.icons = dmicons;
	};

	//////////////////////////////////////////////////////////////////////
	// @param	: name = 名称
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 名称の一致するアイコンを全件削除
	//
	this.delIconByNameAll = function(name){
		var dmicons = new Array();
		for(var i=0; i < this.icons.length; i++){
			if(this.icons[i].name != name){
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.route[r].orv = dmicons.length;}
					if(this.route[r].dnv == i){ this.route[r].dnv = dmicons.length;}
				}
				dmicons.push(this.icons.shift());
			}else{
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.delRoute(this.route[r].id);}
					if(this.route[r].dnv == i){ this.delRoute(this.route[r].id);}
				}
			}
		}
		this.icons = dmicons;
	};

	//////////////////////////////////////////////////////////////////////
	// @param	: lon = 経度
	//			: lat = 緯度
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 緯度経度の一致するアイコンを削除
	//
	this.delIconByLonLat = function(lon,lat){
		var dmicons = new Array();
		for(var i=0; i < this.icons.length; i++){
			if(this.icons[i].lon != lon || this.icons[i].lat != lat){
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.route[r].orv = dmicons.length;}
					if(this.route[r].dnv == i){ this.route[r].dnv = dmicons.length;}
				}
				dmicons.push(this.icons.shift());
			}else{
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.delRoute(this.route[r].id);}
					if(this.route[r].dnv == i){ this.delRoute(this.route[r].id);}
				}
			}
		}
		this.icons = dmicons;
	};

	//////////////////////////////////////////////////////////////////////
	// @param	: id = アイコンID
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: アイコンIDの一致するアイコンを削除
	//
	this.delIconById = function(id){
		var dmicons = new Array();
		for(var i=0; i < this.icons.length; i++){
			if(this.icons[i].id != id){
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.route[r].orv = dmicons.length;}
					if(this.route[r].dnv == i){ this.route[r].dnv = dmicons.length;}
				}
				dmicons.push(this.icons.shift());
			}else{
				for(var r=0; r < this.route.length; r++){
					if(this.route[r].orv == i){ this.delRoute(this.route[r].id);}
					if(this.route[r].dnv == i){ this.delRoute(this.route[r].id);}
				}
			}
		}
		this.icons = dmicons;
	};

	this.setForm = 			function(frm){ this.targetForm = frm;};
	this.getForm = 			function(){ return this.targetForm;};
	//////////////////////////////////////////////////////////////////////
	//
	// 地図画像URL
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: URL
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 地図画像のURLを取得する

	//
	this.getURL = function(){
		var url = this.MapIntarfaceURL;
		url += "?MapCenterX="+this.getLon();
		url += "&MapCenterY="+this.getLat();
		url += "&MapScale="+this.getScale();
		url += "&MapZoom="+this.getZoom();
		url += "&MapWidth="+this.getMapSizeX();
		url += "&MapHeight="+this.getMapSizeY();
		url += "&MapAngle="+this.getAngle();
		url += "&DrawScale=" + this.MapIconScale;
		url += "&DrawDirection=" + this.MapIconDirection;
		url += "&DrawTarget=" + this.MapIconTarget;
		url += this.traffic;
		//Icons
		for(var i = 0; i < this.icons.length; i++){
			if(this.icons[i] != null){
				url += this.icons[i].getURL(i);
			}
		}
		//Routes
		for(var i=0; i < this.route.length; i++){
			url += this.route[i].getURL();
		}
		//Palette
		if(this.Palette != ""){
			url += "&Palette=" + this.Palette;
		}
		// Another param 2005/03/11
		for(var i = 0; i < this.param.length; i++){
			if(this.param[i].key == ""){ continue;}
			url += "&" + this.param[i].key + "=" + this.param[i].value;
		}
		
		//キャッシュ防止処理

//		if(this.MsgObjects.length > 0){
			var now = new Date();
			url += "&time=" + (now.getTime() - 1103760000);
//		}
		return url;
	};


	//////////////////////////////////////////////////////////////////////
	//
	// マップサイズ定義
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: w = 横幅

	// 			: h = 縦幅

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 切り替えマップサイズのバリエーションを定義する
	//
	this.addMapSize = function(w,h){
		idx = this.MapSizes.length == 0 ? 1 : this.MapSizes.length;
		this.MapSizes[idx] = new MapSize(idx+1 , w, h);
	};


	this.getMapSizeLength = function(){ return this.MapSizes.length; };

	//////////////////////////////////////////////////////////////////////
	//
	// スケール定義
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: w = 横幅

	// 			: h = 縦幅

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 切り替えマップサイズのバリエーションを定義する
	//
	this.addMapScale = 		function(s,z){
		idx = this.mapScale.length;
		this.mapScale[idx] = new MapScale(s,z);
	};

	this.getMapScaleLength=	function(){ return this.mapScale.length; };
	this.delMapScale = 		function(){ this.mapScale = new Array();};

	this.drawMapIconScale =	function(ds){ this.MapIconScale = ds!=null?ds:1; };
	this.delMapIconScale =	function(){ this.MapIconScale = 0; };
	this.drawMapIconDir =	function(dr){ this.MapIconDirection = dr!=null?dr:1; };
	this.delMapIconDir =	function(){ this.MapIconDirection = 0; };;
	this.drawMapIconTarget=	function(tg){ this.MapIconTarget = tg!=null?tg:1; };
	this.delMapIconTarget =	function(){ this.MapIconTarget = 0; };

	this.setTransLon =		function(idx,value){this.arrpxLon[idx] = value;};
	this.setTransLonArray = function(arrValue){ this.arrpxLon = arrValue; };
	this.setTransLat =		function(idx,value){this.arrpxLat[idx] = value;};
	this.setTransLatArray = function(arrValue){ this.arrpxLat = arrValue; };

	this.setPalette = 		function(plt){this.Palette = plt;};
	this.delPalette = 		function(){ this.Palette = ""; };

	//////////////////////////////////////////////////////////////////////
	//
	// windowがLoadされた時に呼ばれる関数
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: なし

	// @return	: なし

	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 明示的にdrawImage()がコールされない時に呼ばれる描画メソッド
	//
	this.init=function(){
		if(loaded == false){
			this.drawImage();
		}
	};
/*
	this.checkDocument=function(){
		if(loaded){return;}
		var imgcls = this;
		if(b.getObject(MapName,"layer")==null){
			setTimeout(function(){imgcls.checkDocument()},10);
		}else{
			this.drawImage();
		}
	};
*/	
	function Ly(a){
		a.id = "layer";
		a.style.visibility = 'hidden';
		a.style.top = 0;
		a.style.left = 0;
		a.style.zIndex = 99;
		return a;
	};
	function Im(a,z){
		a.width = w;
		a.height = h;
		// 右クリック禁止
		a.oncontextmenu=function(){return false};
		if(z.isMove){
			a.onmousedown=function(e){
				z.mapClick(e);
			};
			a.className = "cursor";
		}
		return a;
	};

	// TODO Opera
	this.mapPosX = 0;
	this.mapPosY = 0;
	this.getMapImage=function(){
		if(gMapImage!=null){ return;}
		if(MapName.length > 0 && b.getObject(MapName,"layer")!=null && b.getObject(MapName,"layer").tagName=="DIV"){
			var parentdiv = b.getObject(MapName,"layer");
			parentdiv.style.overflow="hidden";
			parentdiv.style.textAlign = "left";
			parentdiv.style.width = w;
			parentdiv.style.height = h;

			if(b.isFF || b.isNN6){
				this.frame = document.createElement("IFRAME");
				this.frame.style.position="relative";
				this.frame.name = "IF";
				this.frame.width = "100%";
				this.frame.height = "100%";
				this.frame.marginHeight = 0;
				this.frame.marginWidth = 0;
				this.frame.scrolling = "no";
				this.frame.frameBorder = "0";
				parentdiv.appendChild(this.frame);

				if(b.isOpera){
					var i=0;
					while(window.IF.document==null){
						i++;
					}
				}
				window.IF.document.open();
				var NFontPointSize = 9;
				var NFontFamilyStyle = "font-family:Osaka,Verdana, Geneva, ＭＳ Ｐゴシック,Arial,Helvetica,serif;";
				var NMoveStyle = b.isNN ? "":"position:relative; top:1px; left:1px;";
				window.IF.document.write('<html><head>');
//				window.IF.document.write('<script type="text/javascript">function al(a){var b=document.getElementById(\'layer\'); alert(b); document.appendChild(a);}</script>');
				window.IF.document.write('<STYLE type="text/css"><!--');
				window.IF.document.write('BODY			{BACKGROUND-COLOR: #FFFFFF; FONT-SIZE: ' + NFontPointSize + 'pt; color: #000000; ' + NFontFamilyStyle + '}');
				window.IF.document.write('A:link		{COLOR: #4444AA; SIZE: ' + NFontPointSize + 'pt; TEXT-DECORATION: underline; ' + NFontFamilyStyle + '}');
				window.IF.document.write('A:visited		{COLOR: #4444AA; SIZE: ' + NFontPointSize + 'pt; TEXT-DECORATION: underline; ' + NFontFamilyStyle + '}');
				window.IF.document.write('A:active		{COLOR: #FF0000; SIZE: ' + NFontPointSize + 'pt; TEXT-DECORATION: underline; ' + NFontFamilyStyle + '}');
				window.IF.document.write('A:hover		{COLOR: #FF8800; SIZE: ' + NFontPointSize + 'pt; TEXT-DECORATION: underline; ' + NFontFamilyStyle + '}');
				window.IF.document.write('TABLE,TH,TD	{FONT-SIZE: ' + NFontPointSize + 'pt; color: #333333; ' + NFontFamilyStyle + '}');
				window.IF.document.write('SELECT		{FONT-SIZE: ' + NFontPointSize + 'pt; color: #333333; ' + NFontFamilyStyle + '}');
				window.IF.document.write('IMG			{border:0px}');
				window.IF.document.write('--></STYLE>');
				window.IF.document.write('</head><body><div id="layer"></div><img id="IFImg"></body></html>');
				window.IF.document.close();
				this.gMapLayer = Ly(window.IF.document.getElementById("layer"));
				gMapImage = Im(window.IF.document.getElementById("IFImg"),this);
				
			}else{
				// TODO Opera
				if(b.isOpera){
					this.frame = document.createElement("IFRAME");
					this.frame.style.position="relative";
					parentdiv.appendChild(this.frame);
					this.mapPosX = this.frame.offsetLeft;
					this.mapPosY = this.frame.offsetTop;
					this.frame.style.display = 'none';
				}	
				this.gMapLayer = Ly(document.createElement("DIV"));
				// TODO Opera
				if(b.isOpera){
					this.gMapLayer.style.position="absolute";
					this.gMapLayer.style.clip = "rect(0px," + w + "px," + h + "px,0px)";
					this.gMapLayer.style.top = 0+this.mapPosY;
					this.gMapLayer.style.left = 0+this.mapPosX;
				}
				var imagediv = document.createElement("DIV");
				imagediv.id = "image";
				imagediv.style.zIndex = 98;
				
				gMapImage = Im(document.createElement("IMG"),this);
				parentdiv.appendChild(this.gMapLayer);
//				parentdiv.appendChild(imagediv);
				parentdiv.appendChild(gMapImage);
			}
		}else{
			if(MapName.length > 0 && b.getObject(MapName,"image")!=null){
				gMapImage = b.getObject(MapName,"image");
			}
		}
	};

	//////////////////////////////////////////////////////////////////////
	//
	// レイヤー作成
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: text = アイコンの内容
	// 			: lon = 経度
	// 			: lon = 緯度
	// 			: name = 店舗/住所名称
	// 			: address = 住所
	// 			: tel = 電話番号
	// 			: NTLayerMessage = アイコンクリック時に表示されるメッセージ指定(指定ナシの場合定型フォーマットで作成される)
	// @return	: 
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 
	//
	this.createIconLayer = function(text,lon,lat,name,address,tel,ntMsg){
		if(this.gMapLayer == null){ return;}
		var i = this.IconLayers.length;
		if(gMapImage == null){
			alert("Could not create icon layers, at first you must create map image tag.");
			return;
		}
		var layer;
		layer = document.createElement("DIV");
		layer.id = "IconLayer"+i;
		layer.className = "clsIconFaceOff";
		layer.style.position = "absolute";
		layer.style.display = "block";
		layer.style.visibility = 'hidden';
		layer.style.width = 7;
		layer.style.height = 7;
		layer.style.left = this.transLonToPix(lon)-(cutpx(layer.style.width)/2);
		layer.style.top  = this.transLatToPix(lat)-cutpx(layer.style.height);
		this.gMapLayer.appendChild(layer);
		layer.innerHTML = text+"<br>";
		layer.onmouseover=function(){
			this.className = "clsIconFaceOn";
			this.style.zIndex|=1024;
		};
		layer.onmouseout = function(){
			this.className="clsIconFaceOff";
			this.style.zIndex&=~1024;
		};

		Object.prototype.lon = null;
		Object.prototype.lat = null;
		Object.prototype.innerValue = null;
		Object.prototype.address = null;
		Object.prototype.tel = null;

		layer.lon = lon;
		layer.lat = lat;
		layer.name = name;
		layer.address = address;
		layer.tel = tel;
		layer.innerValue = name + "<br>"+ address + "<br>"+ tel + "<br>";
		var imgClass = this;

		if(ntMsg == null){
			layer.onmousedown=function(event){
				imgClass.createMsg(this.lon,this.lat,this.innerValue);
			};
		}else{
			layer.onmousedown=function(event){
				ntMsg.active();
			};
		}
		this.IconLayers[i] = layer;
		return layer;
	};

	this.drawCopyRight=function(){
		copyright = new NTCopyRight(this);
	};

	//////////////////////////////////////////////////////////////////////
	//
	// レイヤー作成
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: src = 画像パス
	// 			: src_act = onmouse時の画像

	// 			: lon = 経度
	// 			: lon = 緯度
	// 			: name = 店舗/住所名称
	// 			: address = 住所
	// 			: tel = 電話番号
	// 			: NTLayerMessage = アイコンクリック時に表示されるメッセージ指定(指定ナシの場合定型フォーマットで作成される)
	// @return	: 
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 
	//
	this.createIconLayerImage = function(src,src_act,w,h,lon,lat,name,address,tel,ntMsg,func){

		if(this.gMapLayer == null){ return;}
		
		var i = this.IconLayers.length;
		if(gMapImage == null){
			alert("Could not create icon layers, at first you must create map image tag.");
			return;
		}
		this.IconLayers[i] = new NTIcon(this,i,src,src_act,w,h,lon,lat,ntMsg,func);
	};

	this.focusIcon = function(index){
		this.IconLayers[index].active();
	};

	this.unfocusIcon = function(index){
		this.IconLayers[index].init();
	};

	this.transLonToPix = function(lon){
		if(lon == null){ return null;}
		var a = this.transPixToPosLon(this.getMapSizeX(),this.getMapSizeY()/2);
		var b = lon - 	this.getLon();
		var c = ((b/a) * this.getMapSizeX()) + (this.getMapSizeX()/2);
		return Math.ceil(c);
	};
	this.transLatToPix = function(lat){
		if(lat == null){ return null;}
		var a = this.transPixToPosLat(this.getMapSizeX()/2,this.getMapSizeY());
		var b = this.getLat() - lat;
		var c = ((b/a) * this.getMapSizeY()) + (this.getMapSizeY()/2);
		return Math.ceil(c);
	};
	this.reloadLayer = function(){
		if(this.gMapLayer==null){ return;}
		for(var i = 0; i < this.IconLayers.length; i++){
			this.IconLayers[i].move();
		}

		for(var i = 0; i < this.MsgObjects.length; i++){
			// 移動フラグがfalseの場合メッセージの移動はしない

			if(this.MsgObjects[i].moveEnable==false){ continue;}

			var x = this.transLonToPix(this.MsgObjects[i].lon);
			var y = this.transLatToPix(this.MsgObjects[i].lat);
			this.MsgObjects[i].moveTo(x,y);
		}

		this.gMapLayer.style.visibility = 'visible';

	};

	//////////////////////////////////////////////////////////////////////
	//
	// メッセージレイヤー作成
	//
	//////////////////////////////////////////////////////////////////////
	// @param	: lon = 経度
	// 			: lat = 緯度
	// 			: text = 表示内容
	// 			: isShown = 初期表示(true…表示ON / false…表示OFF)(デフォルトfalse)
	// 			: isClose = closeボタン表示(true…表示ON / false…表示OFF)(デフォルトtrue)
	// 			: isMove = 地図クリックと同時に移動(true…移動ON / false…移動OFF)(デフォルトtrue)
	//						falseの場合常に最初に表示した位置に留まる。(中心に置いたら地図を動かしてもメッセージは中心に表示されたまま)
	// @return	: 
	// Copyright: NAVITIME JAPAN CO,.LTD.
	// @author	: Masakazu Yoshida
	// @version	: 1.0
	// @		: 
	//
	this.MessageCreator=function(lon,lat,text,isShown,isClose,isMove){
		var x = this.transLonToPix(lon);
		var y = this.transLatToPix(lat);
		var msgobj = new NTLayerMessage(this,x,y,lon,lat,text,isClose,isMove);
		// 初期表示
		if(isShown == true){
			msgobj.display = true;
			msgobj.active();
		}
		// 配列にオブジェクトをセット
		this.MsgObjects[this.MsgObjects.length] = msgobj;
		
		return msgobj;
	};

	this.createMsg=function(lon,lat,text){
		if(this.gMsgLayer==null){
			return this.gMsgLayer =  this.MessageCreator(lon,lat,text,true);
		}else{
			var x = this.transLonToPix(lon);
			var y = this.transLatToPix(lat);
			this.gMsgLayer.moveTo(x,y);
			this.gMsgLayer.text = text;
			this.gMsgLayer.active();
			return this.gMsgLayer;
		}
	};


	this.drawAllLayer = function(){
		for(var i = 0; i < this.IconLayers.length; i++){
			if(!this.IconLayers[i].loaded){this.IconLayers[i].draw();}
		}
		// メッセージをロード

		for(var i = 0; i < this.MsgObjects.length; i++){
			if(this.MsgObjects[i].loaded == false){ this.MsgObjects[i].draw();}
		}
		// Toolbarをロード

		if(gTool!=null){
			gTool.draw();
		}
		if(copyright!=null && copyright.loaded==false){
			copyright.draw();
		}
	};

	this.getLayerXPos = function(l){ return cutpx(l.style.left);};
	this.getLayerYPos = function(l){ return cutpx(l.style.top);};
	function cutpx(x){return Math.ceil(x.substr(0,x.indexOf("px")));};

	this.createMapToolbar = function(scale,zoom){
		if(scale == null || scale < 0 || scale > 5){
			scale = this.getScale();
		}
		if(zoom == null || zoom < 1 || zoom > 100){
			zoom = this.getZoom();
		}
//		if(this.gMapLayer == null){ return;}
		gTool = new MapToolBar(this,scale,zoom, this.getMapSizeX(), this.getMapSizeY());
	};
	
	this.clearAllIcons = function(){
		for(var i=0; i<this.IconLayers.length; i++){
			this.IconLayers[i].remove();
		}
		this.IconLayers=new Array();
		for(var i=0; i<this.MsgObjects.length; i++){
			this.MsgObjects[i].remove();
		}
		this.MsgObjects = new Array();
	};
	
	
	//
	// Constructor
	//
	var MapName = image;
	this.gMapLayer = null;
	this.gMsgLayer = null;
	this.MsgObjects = new Array();
	this.getMapImage();

	this.setMapSizeX(w);
	this.setMapSizeY(h);
	this.addMapScale(0,8);
	this.addMapScale(1,6);
	this.addMapScale(1,20);
	this.addMapScale(2,3);
	this.addMapScale(2,5);
	this.addMapScale(3,3);
	this.addMapScale(3,5);
	this.addMapScale(3,8);
	this.addMapScale(4,3);
	this.addMapScale(4,5);
	this.addMapScale(4,7);
	this.setLevel(7);
	addImageRasterGroup(this);
//	this.checkDocument();
}


//////////////////////////////////////////////////////////////////////
//
// アイコンURL取得

//
//////////////////////////////////////////////////////////////////////
// @param	: no = 配列のインデックス番号
// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: アイコン情報をURL形式で出力します

//
function Icon_getURL(no){
	var ret = "&Icon" + no + "=" + this.id + ",";
	ret += this.lon + ",";
	ret += this.lat + ",";
	ret += this.name + ",";
	ret += this.image + ",";
	ret += (this.id > 0 || this.image != "") ? "1,":"0,";
	ret += (this.name != "") ? "1,":"0,";
	ret += this.position + ",";
	ret += this.tollRoadFlg;	
	return ret;
}

//////////////////////////////////////////////////////////////////////
//
// クラス：Icon
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: アイコンクラス
//
function Icon(){
	this.id = 0;
	this.lon = 0;
	this.lat = 0;
	this.name = "";
	this.image = "";
	this.position = 0;
	this.tollRoadFlg = -1;
	this.getURL = Icon_getURL;
}

//////////////////////////////////////////////////////////////////////
//
// クラス：Route
//
//////////////////////////////////////////////////////////////////////
function Route(id,orv,dnv){
	this.id = id;
	this.orv = orv;
	this.orvnode = "";
	this.orvtime = "";
	this.dnv = dnv;
	this.dnvnode = "";
	this.dnvtime = "";
	this.linkno = "";
	this.linknm = "";
	this.trainno = "";
	this.trainnm = "";
	this.methodno = "10";
	this.methodnm = "";
	this.R = "255";
	this.G = "0";
	this.B = "0";

	this.setRGB = function(r,g,b){
		this.R = r;
		this.G = g;
		this.B = b;
	};
	this.setMethod = function(nm){
		this.methodno = nm;
	};
	this.getURL = function(){
		var url = "";
		url += "&Route"+ this.id +"=" + this.orv;
		url += "," + this.orvnode;
		url += "," + this.orvtime;
		url += "," + this.dnv;
		url += "," + this.dnvnode;
		url += "," + this.dnvtime;
		url += "," + this.linkno;
		url += "," + this.linknm;
		url += "," + this.trainno;
		url += "," + this.trainnm;
		url += "," + this.methodno;
		url += "," + this.methodnm;
		url += "," + this.R;
		url += "," + this.G;
		url += "," + this.B;
		return url;
	};
}

//////////////////////////////////////////////////////////////////////
//
// クラス：MapSize
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: マップサイズクラス
//
function MapSize(id,w,h){
	this.id = id;
	this.width = w;
	this.height = h;
}

//////////////////////////////////////////////////////////////////////
//
// クラス：MapScale
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: マップスケールクラス
//
function MapScale(s,z){
	this.scale = s;
	this.zoom = z;
}

//////////////////////////////////////////////////////////////////////
//
// クラス：ASPParam
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: ASP引数管理クラス
//
function ASPParam(k,v){
	this.key = k;
	this.value = v;
}

//////////////////////////////////////////////////////////////////////
//
// クラス：DegreeMinuteSecond
//
//////////////////////////////////////////////////////////////////////
// @param	: 1/1000秒の緯度経度
// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: 緯度経度を正式な形で保持しているオブジェクト

//
function DegreeMinuteSecond(milsec){
	this.degree=(milsec-milsec%3600000)/3600000;
	this.minute=((milsec-this.degree*3600000)-(milsec-this.degree*3600000)%60000)/60000;
	this.second=((milsec-this.degree*3600000-this.minute*60000)-((milsec-this.degree*3600000-this.minute*60000)%1000))/1000;
	this.milliSecond=milsec-this.degree*3600000-this.minute*60000-this.second*1000;;
}


//////////////////////////////////////////////////////////////////////
//
// クラス：Browser
//
//////////////////////////////////////////////////////////////////////
// @param	: なし

// @return	: なし

// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: ユーザーのブラウザ環境を格納

//
function Browser(){
	var agent = navigator.userAgent;
	var appver = navigator.appVersion;
	var navi = navigator.appName;
	
	
	this.isDom = (document.getElementById!=null);
	this.isOpera = (agent.indexOf("Opera")>-1);
	this.isIe4 = (document.all && !this.isDom && !this.isOpera);
	this.isIe5 = (document.all && this.isDom && !this.isOpera);
	this.isIe = (this.isIe4 || this.isIe5);
	this.isFF = (agent.indexOf("Firefox")>-1);
	this.isNN = (navi.indexOf("Netscape",0)>-1 && !this.isFF);
	this.isNN4 = (document.layers && this.isNN);
	this.isNN6 = (this.isDom && this.isNN);
	this.isWin = (agent.indexOf('Win') != -1);
	this.isMac = (agent.indexOf('Mac') != -1);
}
Browser.prototype.getObject = function(name,type){
	if(this.isDom){
		return document.getElementById(name);
	}else{
		if(type=="image"){
			return eval("document.images[\"" + name + "\"]");
		}
		if(type=="form"){
			return eval("this.targetForm." + name);
		}
		if(type=="layer"){
			return document.layers[name];
		}
	}
	return null;
};


//////////////////////////////////////////////////////////////////////
//
// クラス：NTLayerMessage
//
//////////////////////////////////////////////////////////////////////
function NTLayerMessage(imageRaster,x,y,lon,lat,text,close,move){

	var layer = null;
	var panel = null;
	var shadow = null;
	this.x = x;
	this.y = y;
	this.lon = lon;
	this.lat = lat;
	this.text = text;
	this.loaded = false;
	this.display = false;
	var isclose = close!=null ? close : true;
	this.moveEnable  = move!=null ? move : true;
	
	var boardImageTop = null;
	var boardImageBack = null;
	var boardImageBottom = null;
	
	this.shadowImage = null;
	this.closeImage = null;
	var MsgOffsetWidth=0;
	
	// メッセージボードに画像を使用する
	this.setBoardImage = function(top,tw,th,background,bw,bh,bottom,btw,bth){
		
		boardImageTop = new Image(tw,th);
		boardImageTop.src = top;

		boardImageBack = new Image(bw,bh);
		boardImageBack.src = background;

		boardImageBottom = new Image(btw,bth);
		boardImageBottom.src = bottom;
		boardImageBottom.style.cursor = "hand";
		boardImageBottom.onmousedown=function(e){
			var offsetX;
			var offsetY;
			
			if(b.isFF || b.isNN){
				if(imageRaster.getMapObject().x != null && imageRaster.getMapObject().y != null){
				
					// for NetScape 7
					offsetX = e.layerX - this.x;
					offsetY = e.layerY - this.y;
				}else{
					// for NetScape 6
					offsetX = e.layerX - this.x;
					offsetY = e.layerY - this.y;
				}
			}else{
					
				offsetX = window.event.offsetX;
				offsetY = window.event.offsetY;
				if(imageRaster.isIe5 && this.isMac){
					offsetY += document.body.scrollTop;
				}
			}
			imageRaster.mapClickPixels(imageRaster.getLayerXPos(layer)+imageRaster.getLayerXPos(this)+offsetX,imageRaster.getLayerYPos(layer)+layer.offsetHeight-this.height+offsetY);
		};
		
	};

	// 影イメージをセット
	this.setShadowImage = function(src,width,height){
		this.shadowImage = new Image(width,height);
		this.shadowImage.src = src;
	};

	// 閉じるボタンをセット
	this.setCloseImage = function(src,width,height){
		this.closeImage = new Image(width,height);
		this.closeImage.src = src;
	};

	var m0,mb,mt,ms;
	var parent = imageRaster.gMapLayer;
	this.draw = function(){
		m0 = document.createElement("DIV");
		m0.style.position="absolute";
		m0.style.visibility = 'hidden';
		m0.style.zIndex=100;
		parent.appendChild(m0);

		// 枠
		mt = document.createElement("DIV");
		mt.style.width=220;
		mt.style.cursor = "default";
//		mt.style.textAlign ="left";
		mt.style.position="relative";
		mt.style.fontSize=11;
		mt.style.zIndex=101;
		if(boardImageTop == null && boardImageBack == null && boardImageBottom==null){
			mt.style.background = "#FFFFFF";
			mt.style.borderColor= "#333333";
			mt.style.borderStyle= "solid";
			mt.style.borderWidth= "1";
			mt.style.padding=5;
			mt.style.height=80;
			mt.innerHTML = this.text;
			mt = this.chgAncherTarget(mt);
			m0.appendChild(mt);
		}else{
			mt.appendChild(boardImageTop);
			var mv = document.createElement("DIV");
			mv.style.backgroundImage = 'url(' + boardImageBack.src + ')';
//			mv.style.padding=5;
			mt.appendChild(mv);
			mv.innerHTML = '<table border="0" cellspacing="0" cellpadding="5" width="220"><tr><td>' + this.text + '</td></tr></table>';
			mv = this.chgAncherTarget(mv);			
			m0.appendChild(mt);
			m0.appendChild(boardImageBottom);
		}

		MsgOffsetWidth = mt.offsetWidth;
		//ブラウザの進む/戻る対応

		if(MsgOffsetWidth == 0){
			MsgOffsetWidth = 220;
		}
		this.text = mt;

		// 影
		ms = document.createElement("DIV");
		if(this.shadowImage == null){
			ms.style.background ="#000000";
			ms.style.width=MsgOffsetWidth;
			ms.style.height=mt.offsetHeight;
			ms.style.top = 5;
			ms.style.left = 5;
		}else{
			ms.appendChild(this.shadowImage);
		}
		ms.style.position="absolute";
		ms.style.visibility = 'hidden';
		ms.style.cursor = "hand";
		ms.onmousedown=function(e){
			var offsetX;
			var offsetY;
			if(b.isFF || b.isNN){
				if(imageRaster.getMapObject().x != null && imageRaster.getMapObject().y != null){
					// for NetScape 7
					offsetX = e.layerX - this.style.width;
					offsetY = e.layerY - this.style.height;
				}else{
					// for NetScape 6
					offsetX = e.layerX - this.style.width;
					offsetY = e.layerY - this.style.height;
				}
			}else{
				offsetX = window.event.offsetX;
				offsetY = window.event.offsetY;
				if(imageRaster.isIe5 && this.isMac){
					offsetY += document.body.scrollTop;
				}
			}
			imageRaster.mapClickPixels(imageRaster.getLayerXPos(this)+offsetX,imageRaster.getLayerYPos(this)+offsetY);
		};
		ms.style.filter='progid:DXImageTransform.Microsoft.alpha(opacity=40)';
		ms.style.zIndex=1;
		parent.appendChild(ms);
		shadow = ms;
		
		// 閉じるボタン
		if(isclose){
			mb = document.createElement("DIV");
			if(this.closeImage == null){

				mb.style.color="#000000";
				mb.innerHTML = "x";
				mb.style.background = "#FFFFFF";
				mb.style.borderColor= "#333333";
				mb.style.borderStyle= "solid";
				mb.style.borderWidth= "1";
				mb.style.fontSize=10;
				mb.style.textAlign ="center";
				mb.style.width=15;
				mb.style.height=15;
				mb.style.left = MsgOffsetWidth - 20;
			}else{
				mb.appendChild(this.closeImage);
				mb.style.left = MsgOffsetWidth - this.closeImage.width-5;
			}
			mb.style.top = 4;
			mb.style.position="absolute";
			mb.style.cursor= "hand";
			mb.onmousedown=function(){
				layer.style.visibility = 'hidden';
				shadow.style.visibility = 'hidden';
			};
			mb.style.zIndex=102;
			m0.appendChild(mb);
		}

		layer = m0;
		if(this.display == true){
			show();
		}
		this.moveTo(x,y);
		layer.onmouseover = function(){
			this.style.zIndex|=1024;
		};
		layer.onmouseout = function(){
			this.style.zIndex&=~1024;
		};
		
		this.loaded = true;
	};

	this.remove = function(){
		var objects = [m0,mt,ms,mb];
		for(var o=0; o<objects.length; o++){
			if(objects[o]==null || typeof objects[o] != "object") continue;
			for(var i=0; i<objects[o].parentNode.childNodes.length; i++){
				if(objects[o].parentNode.childNodes[i]==objects[o]){
					objects[o].parentNode.removeChild(objects[o].parentNode.childNodes[i]);
					break;
				}
			}
		}
	}

	this.close = function(){
		if(layer == null){ return;}
		layer.style.visibility = 'hidden';
		shadow.style.visibility = 'hidden';
	};

	this.moveToLonLat = function(lon,lat){
		var x1 = imageRaster.transLonToPix(lon);
		var y1 = imageRaster.transLatToPix(lat);
		this.moveTo(x1,y1);
	};

	this.moveTo = function(x,y){
		if(layer == null){ return;}
		this.x = x-(Math.ceil(MsgOffsetWidth)/2);
		this.y = y-(Math.ceil(layer.offsetHeight));
		layer.style.left = this.x;
		layer.style.top = this.y;
		
		shadow.style.left = this.x;
		shadow.style.top = this.y + layer.offsetHeight - shadow.offsetHeight;
	};

	this.active = function(){
		if(layer == null){ return;}
		show();
		layer.style.zIndex=100;
	};

	this.changeText = function(text){
		panel.innerHTML = text;
	};

	function show(){
		if(layer != null){
				layer.style.visibility = 'visible';
		}
		if(shadow != null){
				shadow.style.visibility = 'visible';
		}
	}

//	if(WindowLoaded){this.draw();}
}
//////////////////////////////////////////////////////////////////////
//
// アンカーターゲット変更
//
//////////////////////////////////////////////////////////////////////
// @param	: Div Element
// @return	: Div Element
// Copyright: NAVITIME JAPAN CO,.LTD.
// @author	: Masakazu Yoshida
// @version	: 1.0
// @		: IE/Opera以外のブラウザの場合、地図がiframe内にあるため、iframe内のアンカーに対して、target="_parent"を付加する必要がある。

//
NTLayerMessage.prototype.chgAncherTarget=function(a){
	if(b.isIe || b.isOpera){ return a; }
	if(b.isNN){
		//Netscapeの場合

		for(var i=0; i<a.childNodes.length; i++){
			if(a.childNodes.item(i).tagName=="A"){
				a.childNodes.item(i).target="_parent";
			}else{
				continue;
			}
		}		
	}else{
		//FireFoxの場合

		for(i in a.childNodes){
			if(i!=null && a.childNodes.item(i).tagName=="A"){
				a.childNodes.item(i).target="_parent";
			}else{
				continue;
			}
	/*
			if(obj!=null){
				for(key in obj){
					try{
						document.write(key + "=" + obj[key] + "<br>");
					}catch(e){
						break;
					}
				}
			}
			document.write("<br><br><br>");
	*/
		}
	}
	return a;
};

function MapToolBar(image ,zoom, scale,mapx, mapy){

	var layers = new Array();
	var imageRaster = image;
	var z = zoom;
	var s = scale;
	var x = mapx;
	var y = mapy;
	var btnw = 12;
	var btnh = 20;

	function cp(w,h,c,bc,l,t,pos,cs){
		var ret = document.createElement("DIV");
		if(c!=null){ ret.style.background= c;}
		if(bc!=null){ ret.style.borderColor= bc;}
		if(bc!=null){ ret.style.borderStyle= "solid";}
		if(bc!=null){ ret.style.borderWidth= "1";}
		if(w!=null){ ret.style.width = w;}
		if(h!=null){ ret.style.height = h;}
		if(t!=null){ ret.style.top = t;}
		if(l!=null){ ret.style.left = l;}
		if(pos!=null){ret.style.position = pos;}
		if(cs!=null){ ret.style.cursor = cs;}
		ret.style.zIndex=1500;
		return ret;
	};

	function cb(lv,tx,l,t,w,h){
		var c = "#EEEEEE";
		var bc = "#888888";
		var ac = "#CADACB";
		var cc = "#007733";
		if(w==null){ w = btnw;}
		if(h==null){ h = btnh;}
		Object.prototype.scaleLevel = null;

		var ret = document.createElement("DIV");
		ret.style.background= c;
		var il = document.createElement("DIV");
		il.style.fontSize=11;
		il.style.width = w-2;
		il.style.height = h-2;
		il.style.borderTopColor= "#FFFFFF";
		il.style.borderLeftColor= "#FFFFFF";
		il.style.borderRightColor= "#BBBBBB";
		il.style.borderBottomColor= "#BBBBBB";
		il.style.borderStyle= "solid";
		il.style.borderWidth= "1";
		il.style.textAlign ="center";
		if(tx!=null){ il.innerHTML = tx;}
		ret.appendChild(il);
		ret.scaleLevel = lv;
		ret.style.borderStyle= "solid";
		ret.style.borderWidth= "1";
		ret.style.width = w;
		ret.style.height = h;
		if(t!=null){ ret.style.top = t;}
		if(l!=null){ ret.style.left = l;}
		ret.style.position = "absolute";
		ret.style.cursor = "hand";
		ret.onmouseover=function(){
			if(image.getLevel() != lv){
				this.style.background=ac;
			}
		};
		ret.onmouseout=function(){
			if(image.getLevel() != lv){
				this.style.background=c;
			}
		};

		if(image.getLevel() == lv){
			ret.style.background=cc;
		}

		ret.onmouseup=function(){
			if(image.getLevel() != lv){
				image.mapSetLevel(eval(lv));
				for(var i = 0; i < layers.length; i++){
					if(layers[i].scaleLevel == image.getLevel()){
						layers[i].style.background = cc;
					}else{
						layers[i].style.background = c;
					}
				}
			}
		};
		ret.style.zIndex=1510;
		layers[layers.length] = ret;
		return ret;
	};

	var loaded = false;
	
	this.draw = function(){
		if(loaded){ return; }
		var div = imageRaster.gMapLayer;
		var minX = Math.ceil(mapx-(image.mapScale.length * (btnw+3))-(btnh+10)*2);
		var maxX = Math.ceil(minX + 220 - btnw);
	
		var lb = cp(mapx - minX-5,btnh+10,"#777777","#000000",minX-1,3,"absolute","default");
		lb.style.filter='progid:DXImageTransform.Microsoft.alpha(opacity=60)';
		div.appendChild(lb);
	
		for(var i = 0; i < image.mapScale.length; i++){
			var l = cb(i,"",minX + btnh + 10 + (i * (btnw+3)),8);
			div.appendChild(l);
		}
	
		var lp = cb("image.getLevel() +1","+",minX + btnh + 10 + (image.mapScale.length * (btnw+3)),8,btnh,btnh);
		var lm = cb("image.getLevel() -1","&minus;",minX + 5,8,btnh,btnh);
		div.appendChild(lp);
		div.appendChild(lm);
		loaded = true;
	};	
	if(WindowLoaded){ this.draw();}
	return this;
}

function NTCopyRight(imageRaster){
	var h=18;
	var w=0;
	this.loaded = false;
	
	this.draw=function(){
		var parent = imageRaster.gMapLayer;
		if(imageRaster.traffic!=""){
			//VICS/JARTICを表示
			var c = document.createElement("DIV");
			c.style.color = "#FFFFFF";
			c.style.fontSize=11;
			c.innerHTML="交通情報:VICS/JARTIC";
			c.style.position = "absolute";
			c.style.width =136;
			c.style.left = imageRaster.getMapSizeX()-205;
			c.style.top = imageRaster.getMapSizeY()-20;
			c.style.zIndex=1522;
			parent.appendChild(c);
			h+=18;
		}
		var b = document.createElement("DIV");
		b.innerHTML="地図:昭文社/住友電工/国土地理院";
		b.style.width =190;
		b.style.fontSize=11;
		b.style.left = imageRaster.getMapSizeX()-205;
		b.style.top = imageRaster.getMapSizeY()-h;
		b.style.color = "#FFFFFF";
		b.style.position = "absolute";
		b.style.zIndex=1521;
		parent.appendChild(b);

		var a = document.createElement("DIV");
		a.style.position = "absolute";
		a.style.background ="#000000";
		a.style.width =210;
		a.style.height = h-1;
		a.style.left = imageRaster.getMapSizeX()-215;
		a.style.top = imageRaster.getMapSizeY()-h-2;
		a.style.filter='progid:DXImageTransform.Microsoft.alpha(opacity=70)';
		a.style.zIndex=1520;
		parent.appendChild(a);
		this.loaded=true;
	};
	if(WindowLoaded){ this.draw();}
}

function NTIcon(a,i,src1,src2,w,h,f,g,msg,func){
	var lon = f;
	var lat = g;
	var name;
	var address;
	var tel;
	var layer;
	var src1 = src1;
	var src2 = src2;
	var msg = msg;
	var func = func;
	var ImageRaster = a;
	this.setName=function(a){ name = a;};
	this.setAddress=function(a){ address = a;};
	this.setTel=function(a){ tel = a;};
	this.getAddress=function(){return address;};
	this.getName=function(){return name;};
	this.getTel=function(){return tel;};
	this.loaded = false;
				
	function cutpx(x){return Math.ceil(x.substr(0,x.indexOf("px")));};
	this.draw=function(){
	
		layer = document.createElement("DIV");
		layer.id = "IconLayer"+i;
		layer.style.position = "absolute";
		layer.style.visibility = 'hidden';
		layer.style.zIndex = 50;
		layer.style.width = w;
		layer.style.height = h;
		layer.style.left = ImageRaster.transLonToPix(lon)-(cutpx(layer.style.width)/2);
		layer.style.top  = ImageRaster.transLatToPix(lat)-cutpx(layer.style.height);

		layer.appendChild(image = document.createElement("IMG"));
		image.id="IconLayerImage"+i;
		image.width = w;
		image.height = h;
		image.src=src1;
/*
		if(b.isOpera){

//			var txt = '<div id="IconLayer'+i+'" style="position:absolute; visibility:hidden; zindex:50; width:'+w+'; height'+h+'; left:'+ImageRaster.transLonToPix(lon)-(cutpx(layer.style.width)/2)+'; top:'+ImageRaster.transLatToPix(lat)-cutpx(layer.style.height)+';"></div>';
//			ImageRaster.gMapLayer.insertAdjacentHTML('BeforeEnd',txt);
//			layer=window.IF.document.getElementById?
//			window.IF.document.getElementById("IconLayer"+i):(document.all?document.all("IconLayer"+i):null);

//			window.IF.al(layer);
		}else{
			ImageRaster.gMapLayer.appendChild(layer);
		}
*/
		ImageRaster.gMapLayer.appendChild(layer);
		layer.onmouseover=function(){
			if(msg!=null){this.style.cursor = "hand";}
			this.style.zIndex|=1024;
			if(src2 != null && src2 != ""){
				var act = new Image();
				act.src = src2;
				image.src = act.src;
			}
		};
		layer.onmouseout = function(){
			this.style.zIndex&=~1024;
			if(src2 != null && src2 != ""){
				image.src = src1;
			}
		};
		var p = this;
		layer.onmousedown=function(event){
			ImageRaster.setLonLat(lon,lat);
			if(msg != null){ msg.active();}
			if(func!=null){
				try{
					func.call();
				}catch(e){
				}
			}
		};
		this.loaded = true;
		
	};
	
	this.remove = function(){
		var objects = [document.getElementById("IconLayerImage"+i),document.getElementById("IconLayer"+i)];
		for(var o=0; o<objects.length; o++){
			if(objects[o]==null || typeof objects[o] != "object") continue;
			for(var i=0; i < objects[o].parentNode.childNodes.length; i++){
				if(objects[o].parentNode.childNodes[i]==objects[o]){
					objects[o].parentNode.removeChild(objects[o].parentNode.childNodes[i]);
					break;
				}
			}
		}
	}
	
	this.active=function(){
		layer.className = "clsIconFaceOn";
		layer.style.zIndex|=1024;
	};
	this.init=function(){
		layer.className="clsIconFaceOff";
		layer.style.zIndex&=~1024;
	};
	
	this.move=function(){
		layer.style.left = ImageRaster.transLonToPix(lon) - (cutpx(layer.style.width)/2);
		layer.style.top = ImageRaster.transLatToPix(lat) - (cutpx(layer.style.height));
		layer.style.visibility = 'visible';
	};
	if(WindowLoaded){
		this.draw();
		if(msg != null){
			msg.draw();
		}
	}
}
