
var cj_searchfile="http://cyberjapan.jp/cgi-bin/oss.exe?sa=pref&vl=0&op=dkini";
var sakuzufie="http://cyberjapan.jp/sakuzu.html";
var sakuzufnn="http://cyberjapan.jp/sakuzu_nn.html";

var sakuzufile;
var scflg=0;
var	oldIconM1;
var	newIconM1;
var	oldIconM2;
var	newIconM2;
var	oldIconM3;
var	newIconM3;
var	oldIconM4;
var	newIconM4;
var	oldIconM5;
var	newIconM5;
var	oldIconM7;
var	newIconM7;

var AddMarkerCount;
var AddMarkerRow  = [];
var AddMarkerData;
//var AddMarkerHead = "<table class='map_addmarker'><tr><th colspan=3>北緯</th><th colspan=3>東経</th><th rowspan='2'>削除</th></tr>";
//AddMarkerHead += "<tr><th>度</th><th>分</th><th>秒</th><th>度</th><th>分</th><th>秒</th></tr>";
var AddMarkerHead = "<table class='map_addmarker'><tr><th></th><th>度</th><th>分</th><th>秒</th><th>削除</th></tr>";

	function app_main(){
        top.isMemory();

        top.map.setMouseMode('zoom');
		top.map.openMap("http://cyberjapan.jp/japan0.htm");
//		top.map.openJSGIXML(myDmappath + "/markerXML.php",1);
		top.map.openJSGIXML(myDmappath + "/marker.xml",1);
        top.myDmapSetInitialLocation();
        top.draw_crossline();
		top.map.event('repaint','top.RepaintProc');
        top.RepaintProc();
//		top.map.enablePopup();
		top.map.openMap();

        AddMarkerCount = 0;

		if (kind.browser == 'ie' && !isLimited()){
			sakuzufile=sakuzufie;
		}else{
			sakuzufile=sakuzufnn;
		}
		top.result.location.href=sakuzufile;
		if(isLimited()) rewriteForLimited();
	}

	function draw_crossline(){
		top.map.draw_xyunit("screen");		
		top.map.draw_width(1);			//描画線の幅
		top.map.draw_color(0,150,0);		//描画色の指定(R,G,B値を0～255)
        var w = document.all.item('map').width;
        var h = document.all.item('map').height;
        var x = w / 2 - 1;
        var y = h / 2 - 1;
		top.map.draw_line([x+' 0', x+' '+h]);	//縦線
		top.map.draw_line(['0 '+y, w+' '+y]);	//横線
	}

// 再描画　中央座標を表示
	function RepaintProc() {
		if (MM_FlashCanPlay) {
			var scale=top.map.getMapScale();
			window.document.control.SetVariable("_root.control.testField.slideBarValueTemp",scale);
		}
		var lng = top.map.getCx();	//中心の経度を取得
		var lat = top.map.getCy();	//中心の緯度を取得
        var scale=top.map.getMapScale();
        top.myDmapSetFormVaules(lat,lng,scale);
        PrintXY(lng, lat);
	}


//Change Lat & Lng value in HTML Form Attribute
    function myDmapSetAttributeByID(id, name, value) {
      var element = document.getElementById(id);
      if (element) {
        element.setAttribute(name,value);
      }
    }

	// スクロール
	var scrollStateVar=0;
	var mousemode = 1;
	function mousemode_zooming(){
			top.map.setMouseMode("zoom");
			mousemode = 1;
            document.all['CategoryPanel'].style.display = "none";
	}
	function mousemode_pan(){
			top.map.setMouseMode("pan");
			mousemode = 2;
            document.all['CategoryPanel'].style.display = "none";
	}
	function mousemode_print(){
		if( mousemode != 3 ){
			mousemode = 3;
		}
		top.map.printMap();
	}
	function mousemode_select(){
		if( mousemode != 4 ){
			top.map.setMouseMode("selection");
			top.map.event('leftdown','');    //07.01.31 RSadd
			top.map.event('selection','top.SelectSymbol');
			mousemode = 4;
            document.all['CategoryPanel'].style.display = "block";
		}
	}
	function mousemode_mesure(){
			top.map.setMouseMode("mesure");
			mousemode = 5;
	}

//  シンボル選択
	function SelectSymbol(obj) {
        var str = "<h1 class='map_title'>詳細情報</h1>";
        str += "<table class='map_desc'>";
		catego = top.map.objFieldNames(obj);
		for(i=0;i<catego.length;i++){
			Namae = catego[i];
            Val  = top.map.objFieldVal(obj,Namae );
			if(Namae == "name"){
				name = Val;
			}
			if(Namae == "description"){
				desc = Val;
				desc = desc.replace("<","&lt;");
				desc = desc.replace(">","&gt;");
				desc = desc.replace("'","&#039;");
				desc = desc.replace('"','&quot;');
			}
			if(Namae == "storyid"){
				s_id = Val;
			}
		}
		str += "<tr><th><a href='"+bulletin_url+"index.php?page=article&storyid="+s_id+"'>";
		str += name + "</a></th></tr>";
//		str += "<tr><th>" + name + "</th></tr>";
		str += "<tr><td>"+desc+"</td></tr>";
          str += "</table>";
        document.all['MarkDetail'].innerHTML = str;
        top.map.redrawMap();
	}

//  カテゴリ選択　カテゴリに属するマーカの表示／非表示を切り替える。
	function SelectCategory(cat_id){
        var  markCat = "IshikawaMark." + cat_id + ".*";
        var  stat = top.map.displayLayer (markCat);
        if (stat == 1) {
          top.map.displayLayer (markCat, 0);
        }
        else {
          top.map.displayLayer (markCat, 1);
        }
    }


//  マーカー追加
	function AddMarker(){
	  var lng = top.map.getCx();	//中心の経度を取得
	  var lat = top.map.getCy();	//中心の緯度を取得
//      var markerURL = myDmappath + 'images/marker_S0.bmp';
      var markerURL = myDmappath + 'images/batu.bmp';
      	flag = document.all.marker_status.value.search(lng+","+lat);
      	if (flag == -1) {
               top.map.draw_xyunit ("deg");
	          top.map.draw_level  ("all");
	          top.map.draw_group  (AddMarkerCount);
	          top.map.draw_symbol (markerURL, 68, lng, lat);
			
	          //06.12.14 add kuwada //set 経度・緯度
			if (document.all.marker_status.value == "") {
				document.all.marker_status.value = lng + "," + lat;
			} else {
				document.all.marker_status.value += "|" + lng + "," + lat;
			}
			
	          AddMarkerRow[AddMarkerCount] = AddMarkerTableRowXY (lng, lat, AddMarkerCount);
	          AddMarkerCount ++;
	          AddMarkerTable();
	     }
    }
	function AddMarkerTable(){
      var i;
      var str = AddMarkerHead;
          for (i=0; i<AddMarkerCount; i++) {
            str += AddMarkerRow[i];
          }
          str += "</table>";
          
          //06.12.14 add kuwada
          input = "<p align='right'><input type='button' name='add_marker' id='add_marker' value='送信' onclick='AddMarker_submit_go(1);'>";
          input += "&nbsp;<input type='button' name='return' id='return' value='戻る' onclick='AddMarker_submit_go(0);'></p>";
          document.all['AddMarkerDetail'].innerHTML = str + input;
    }
    
	function AddMarkerTableRowXY (E, N, index){
		//取得した座標は「度」単位なので、「度、分、秒」に変換
		var roundMe=100;
		EH=parseInt(E);
		EM=parseInt((E-EH)*60);
		ES=(E-EH-(EM/60))*3600	;
		ESS=(Math.round(ES*roundMe)/roundMe);	
		EEE=(EH+'°'+EM+'\' '+ESS+'\"');

		NH=parseInt(N);
		NM=parseInt((N-NH)*60);
		NS=(N-NH-(NM/60))*3600;
		NSS=(Math.round(NS*roundMe)/roundMe);	
		NNN=(NH+'°'+NM+'\' '+NSS+'\"');

//        var str = "<tr><td>"+NH+"</td><td>"+NM+"</td><td>"+NSS+"</td><td>"+EH+"</td><td>"+EM+"</td><td>"+ESS+"</td>";
//        str += "<td><A href=\"javascript:void(0);\" onclick=\"DeleteMarker("+index+",'"+E+","+N+"');\">削除</A></td></tr>";
        str = "<tr><td>北緯</td><td>"+NH+"</td><td>"+NM+"</td><td>"+NSS+"</td>";
        str += "<td rowspan='2'><A href=\"javascript:void(0);\" onclick=\"DeleteMarker("+index+",'"+E+","+N+"');\">削除</A></td></tr>";
        str += "<tr><td>東経</td><td>"+EH+"</td><td>"+EM+"</td><td>"+ESS+"</td>";
        return str;
	}
	
    function DeleteMarker (index,EN) {
      var  i;
      for (i=index; i<AddMarkerCount-1; i++) {
        AddMarkerRow[i] = AddMarkerRow[i+1];
      }
      AddMarkerCount --;
      AddMarkerTable();
      document.marker.marker_status.value = document.marker.marker_status.value.replace(EN,"");
      document.marker.marker_status.value = document.marker.marker_status.value.replace("||","|");
      top.map.draw_remove (index);
    }

	function scrollMode(n) {
		scrollStateVar=n;
	}
	function scroll(n,direction) {
		if(!n) return;
		if(scrollStateVar) {
			top.map.startScroll(direction);
			scflg=1;
		}
	}
	function rollon(targetimage) {
		if(targetimage=="kasanecall") {
			document.images[targetimage].src=img1_on.src;
		}
		if(targetimage=="measuremenu") {
			document.images[targetimage].src=img3_on.src;
		}
		if(targetimage=="together") {
			document.images[targetimage].src=img5_on.src;
		}
	}
	function openwin() {
		var win1=window.open('http://cyberjapan.jp/introduction.htm','電子国土','scrollbars=yes,width=700,height=550');
		win1.focus();
	}
	function regionset(areanum) {
		if( areanum==0 ) document.clearinghouse.region.value="全国";
	}
	function readData( uri ) {
		top.map.openMap( uri );
	}
	function readData2( uri,tagname ) {
		top.map.openMap( uri,tagname );
	}
	function openLegend() {
		var win1=window.open('http://cyberjapan.jp/legendlist.htm','凡例リンク一覧','scrollbars=yes,width=300,height=300');
		win1.focus();
	}

	function mousemode_PrintXY(){
		if(isLimited()) {
			PrintXY(map.getCx(), map.getCy());	
		} else {
			mousemode = 6;
			//マウスモードをセレクションモードに
			top.map.setMouseMode('selection')
			//マウスの左ボタンを押し下げたときに実行される命令(PrintXY)を指定する。
			//このとき、引数に座標（経度、緯度）が渡される
			top.map.event('leftdown','top.PrintXY');
			isChangeM(5);
		}
	}
	function PrintXY(E,N){
		//取得した座標は「度」単位なので、「度、分、秒」に変換
		var roundMe=100;
		EH=parseInt(E);
		EM=parseInt((E-EH)*60);
		ES=(E-EH-(EM/60))*3600	;
		ESS=(Math.round(ES*roundMe)/roundMe);	
		EEE=(EH+'°'+EM+'\' '+ESS+'\"');

		NH=parseInt(N);
		NM=parseInt((N-NH)*60);
		NS=(N-NH-(NM/60))*3600;
		NSS=(Math.round(NS*roundMe)/roundMe);	
		NNN=(NH+'°'+NM+'\' '+NSS+'\"');

//		document.sample.box1.value = NNN+", "+EEE;
		document.sample.ido_do.value = NH;
		document.sample.ido_fun.value = NM;
		document.sample.ido_byou.value = NSS;

		document.sample.keido_do.value = EH;
		document.sample.keido_fun.value = EM;
		document.sample.keido_byou.value = ESS;
	}

	function clearENBox(){
		//if (document.sample.box1.value != ""){document.sample.box1.value = ""}
	}
	function scrollMout(){
		if (scflg==1){
			scrollMode(0);
			top.map.stopScroll();	//★
		}
	}
	function zoomSet(val){
		top.map.setMapScale(val);
		top.map.openMap();
	}
//スライダーバー
	function zoomingSet(str){		
		top.map.startZooming(str);
	}
	function m_up(){
		scrollMode(0);
		top.map.stopScroll();
		top.map.stopZooming();
	}
	function m_out(){
		scrollMode(0);
		top.map.stopScroll();
		top.map.stopZooming();
	}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function isMemory(){
	if(parseInt(navigator.appVersion) >=3 && (parseInt(navigator.appVersion) >= 4 || navigator.appName == 'Netscape') ){
		oldIconM1 = new Image();oldIconM1.src = myDmappath + 'images/btn_zoom.gif';
		newIconM1 = new Image();newIconM1.src = myDmappath + 'images/btn_zoom_f2.gif';
		oldIconM2 = new Image();oldIconM2.src = myDmappath + 'images/btn_move.gif';
		newIconM2 = new Image();newIconM2.src = myDmappath + 'images/btn_move_f2.gif';
		oldIconM3 = new Image();oldIconM3.src = myDmappath + 'images/btn_icon.gif';
		newIconM3 = new Image();newIconM3.src = myDmappath + 'images/btn_icon_f2.gif';
		oldIconM4 = new Image();oldIconM4.src = myDmappath + 'images/btn_measure.gif';
		newIconM4 = new Image();newIconM4.src = myDmappath + 'images/btn_measure_f2.gif';
		oldIconM5 = new Image();oldIconM5.src = myDmappath + 'images/btn_coordinates.gif';
		newIconM5 = new Image();newIconM5.src = myDmappath + 'images/btn_coordinates_f2.gif';
//		oldIconM7 = new Image();oldIconM7.src = myDmappath + 'images/btn_AddMarker.gif';
//		newIconM7 = new Image();newIconM7.src = myDmappath + 'images/btn_AddMarker_f2.gif';
	}
}
function isChangeM(imgNo){
	if(imgNo==1){
		if (document.images.iconM1.src != newIconM1.src){document.images.iconM1.src = newIconM1.src}
		if (document.images.iconM2.src != oldIconM2.src){document.images.iconM2.src = oldIconM2.src}
		if (document.images.iconM3.src != oldIconM3.src){document.images.iconM3.src = oldIconM3.src}
		if (document.images.iconM4.src != oldIconM4.src){document.images.iconM4.src = oldIconM4.src}
		if (document.images.iconM5.src != oldIconM5.src){document.images.iconM5.src = oldIconM5.src}
//		if (document.images.iconM7.src != oldIconM7.src){document.images.iconM7.src = oldIconM7.src}
	}else if(imgNo==2){
		if (document.images.iconM1.src != oldIconM1.src){document.images.iconM1.src = oldIconM1.src}
		if (document.images.iconM2.src != newIconM2.src){document.images.iconM2.src = newIconM2.src}
		if (document.images.iconM3.src != oldIconM3.src){document.images.iconM3.src = oldIconM3.src}
		if (document.images.iconM4.src != oldIconM4.src){document.images.iconM4.src = oldIconM4.src}
		if (document.images.iconM5.src != oldIconM5.src){document.images.iconM5.src = oldIconM5.src}
//		if (document.images.iconM7.src != oldIconM7.src){document.images.iconM7.src = oldIconM7.src}
	}else if(imgNo==3){
		if (document.images.iconM1.src != oldIconM1.src){document.images.iconM1.src = oldIconM1.src}
		if (document.images.iconM2.src != oldIconM2.src){document.images.iconM2.src = oldIconM2.src}
		if (document.images.iconM3.src != newIconM3.src){document.images.iconM3.src = newIconM3.src}
		if (document.images.iconM4.src != oldIconM4.src){document.images.iconM4.src = oldIconM4.src}
		if (document.images.iconM5.src != oldIconM5.src){document.images.iconM5.src = oldIconM5.src}
//		if (document.images.iconM7.src != oldIconM7.src){document.images.iconM7.src = oldIconM7.src}
	}else if(imgNo==4){
	}else if(imgNo==5){
		if (document.images.iconM1.src != oldIconM1.src){document.images.iconM1.src = oldIconM1.src}
		if (document.images.iconM2.src != oldIconM2.src){document.images.iconM2.src = oldIconM2.src}
		if (document.images.iconM3.src != oldIconM3.src){document.images.iconM3.src = oldIconM3.src}
		if (document.images.iconM4.src != oldIconM4.src){document.images.iconM4.src = oldIconM4.src}
		if (document.images.iconM5.src = newIconM5.src){document.images.iconM5.src = newIconM5.src}
//		if (document.images.iconM7.src != oldIconM7.src){document.images.iconM7.src = oldIconM7.src}
	}else if(imgNo==7){
		if (document.images.iconM1.src != oldIconM1.src){document.images.iconM1.src = oldIconM1.src}
		if (document.images.iconM2.src != oldIconM2.src){document.images.iconM2.src = oldIconM2.src}
		if (document.images.iconM3.src != oldIconM3.src){document.images.iconM3.src = oldIconM3.src}
		if (document.images.iconM4.src != oldIconM4.src){document.images.iconM4.src = oldIconM4.src}
		if (document.images.iconM5.src != oldIconM5.src){document.images.iconM5.src = oldIconM5.src}
//		if (document.images.iconM7.src != newIconM7.src){document.images.iconM7.src = newIconM7.src}
	}
	clearENBox();
}
var bhsize=0;
function resizeWin() { 
	var myH=getBrowserH();
	if (bhsize!=myH){
		theheight=mapheight();
		document.getElementById('map').style.height=theheight;
		theheight=rightheight();
		document.getElementById('result').style.height=theheight;
		//top.map.openMap();
		bhsize=myH;
	}
}
function rightheight(){
	var theret=mapheight();
	theret=theret-128;
	return theret;
}
function mapheight(){
	var myH=getBrowserH();
	var theheight=myH-205;
	var themin=265;
	if (theheight<themin){theheight=themin}
	return theheight;
}
function getBrowserH(){
	if (kind.browser=="ie"){
		var theret=document.body.clientHeight;
	}else{
		var theret=window.innerHeight-10;
	}
	return  theret;
}

var kind = new Kind();
		function Kind() {
		   var agent = navigator.userAgent.toLowerCase();
		   var major = parseInt(navigator.appVersion);
		   var minor = parseFloat(navigator.appVersion);
		   var ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
		   if(ns) {
		   		this.browser = "ns";
		   		if(major == 2) this.browser = "2";
		   		else if(major == 3) this.version = "3";
		   		else if(major == 4) this.version = "4";
		   		else if(major > 4)  this.version = "5";
		   		if(agent.indexOf('netscape6')!=-1)      this.version = "6";
		   		if(agent.indexOf('netscape/7')!=-1)     this.version = "7";
		   		if(agent.indexOf('netscape/7.0b1')!=-1) this.version = "7pr";
		   } else {
				var ie = (agent.indexOf("msie") != -1);
				if(ie) {
		   			this.browser = "ie";
					if(major == 2) this.version="3";
		   			else if(major >= 4) this.version="4";
		   		} else {
				   if(agent.indexOf("opera") != -1) {
			   			this.browser = "op";
				   		this.version = "3";
				   }
				   if(agent.indexOf("win") != -1) {
				   		this.browser = "pc";
				   		this.version = "0";
				   }
				}
			}
		}

function isFirefox() {
  return navigator.userAgent.indexOf('Firefox') != -1;
}

function isOpera() {
  return navigator.userAgent.indexOf('Opera') != -1;
}

function isLimited() {
  return map.LT_Limited == 1;
}

// 日本周辺の海岸線の表示・非表示を切り替える
function toggle_surroundings(elem) {
	if(elem.getAttribute("displayed") == "true") {
		// 表示されている場合、非表示設定にする
		top.map.displayLayer("日本周辺の海岸線", "off");
		top.map.openMap();
		elem.setAttribute("title", "日本周辺の海岸線を表示するにはここをクリック");
		elem.setAttribute("src", myDmappath + 'images/btn_surroundings_off.gif');
		elem.setAttribute("displayed", "false");
	} else {
		// 表示されていない場合、表示設定にする
		if(elem.getAttribute("loaded") == "false") {
			top.map.openMap("http://cyberjapan.jp/asia.htm");
			elem.setAttribute("loaded", "true");
		} else {
			top.map.displayLayer("日本周辺の海岸線", "on");
			top.map.openMap();
		}
		elem.setAttribute("title", "日本周辺の海岸線の表示を解除するにはここをクリック");
		elem.setAttribute("src", myDmappath + 'images/btn_surroundings_on.gif');
		elem.setAttribute("displayed", "true");
	}
}
// 指定した座標値へジャンプして表示する
function warn() {
            	alert('正しい数値を入力してください');
}

function zahyo_jump() {
            	var ido_do = Number(top.document.getElementById('ido_do').value);
            	if(isNaN(ido_do) || ido_do < 20 || ido_do > 80) { warn(); return; }
            	var ido_fun = Number(top.document.getElementById('ido_fun').value);
            	if(isNaN(ido_fun) || ido_fun < 0 || ido_fun > 60) { warn(); return; }
            	var ido_byou = Number(top.document.getElementById('ido_byou').value);
            	if(isNaN(ido_byou) || ido_byou < 0 || ido_byou > 60) { warn(); return; }
            	
            	var lat = ido_do + ido_fun / 60.0 + ido_byou / 3600.0;
            	
            	var keido_do = Number(top.document.getElementById('keido_do').value);
            	if(isNaN(keido_do) || keido_do < 100 || keido_do > 150) { warn(); return; }
            	var keido_fun = Number(top.document.getElementById('keido_fun').value);
            	if(isNaN(keido_fun) || keido_fun < 0 || keido_fun > 60) { warn(); return; }
            	var keido_byou = Number(top.document.getElementById('keido_byou').value);
            	if(isNaN(keido_byou) || keido_byou < 0 || keido_byou > 60) { warn(); return; }
            	
            	var lng = keido_do + keido_fun / 60.0 + keido_byou / 3600.0;

            	top.map.setMapCenter(lng,lat);
            	top.map.openMap();
            }

//06.12.14 add kuwada
function AddMarker_submit_go(index) {
	if (index==0) {
	//return
		var storyid = document.marker.marker_storyid.value;
		document.location.href=bulletin_url + "/index.php?page=article&storyid=" + storyid;
	} else {
	//post
		if (document.marker.marker_status.value == "" || document.marker.marker_status.value == "|") {
			window.alert("地点を選択してください");
		} else {
			document.marker.marker_add.value = 1;
			document.marker.action=myDmappath+"index.php";
			document.marker.method="post";
			document.marker.submit();
		}
	}
}


