//＋＋＋＋＋＋＋＋＋＋＋変数宣言＋＋＋＋＋＋＋＋＋＋＋

//タイトル、ＩＤ
var spot_title = '';
var spot_id ='';
var spot_address = '';
var spot_genre = '';

//エリア
var area_data = '';

//表形式
var item_name = new Array();
var item_value = new Array();
var item_link = new Array();

//イメージ表示部分
var image_link = new Array();
var imageNo = 0;

//コメント表示部分
var comment = '';

//駅名
//地域の名所駅
var st_area_nicknames;
var st_area_realnames;
var st_area_codes;
//最寄駅
var st_spot_realnames;
var st_spot_codes;


//＋＋＋＋＋＋＋＋＋＋＋変数宣言＋＋＋＋＋＋＋＋＋＋＋


function drawSpotTitle() {
	if (spot_title == undefined) {spot_title ="";}
	//項目名も値もなかったら表示しない
	if (spot_title != "") {
		document.write('<span class="spot_title">');
		document.write(spot_title);
		document.write('</span>');
	}
}

function drawSpotTitlePlain() {
	if (spot_title == undefined) {spot_title ="";}
	//項目名も値もなかったら表示しない
	if (spot_title != "") {
		document.write(spot_title);
	}
}

function drawSpotAddress() {
	if (spot_address == undefined) {spot_address ="";}
	//項目名も値もなかったら表示しない
	if (spot_address != "") {
		document.write('<span class="spot_address">');
		document.write(spot_address);
		document.write('</span>');
	}
}

function drawAreaName() {

	var areas = new Array();
	areas = area_data.split(";");
	area_code = areas[0];
	area_name = areas[1];
	area_bureau_name = areas[2];
	area_bureau_addr = areas[3];
	area_bureau_tel = areas[4];
	area_bureau_link = areas[5];
	area_bureau_mail = areas[6];

	if (area_name == undefined) {area_name ="";}
	//項目名も値もなかったら表示しない
	if (area_name != "") {
		document.write('<span class="area_name">');
		document.write(area_name);
		document.write('</span>');
	}
}

function goAreaList() {

	var areas = new Array();
	areas = area_data.split(";");
	area_code = areas[0];
	area_name = areas[1];
	area_bureau_name = areas[2];
	area_bureau_addr = areas[3];
	area_bureau_tel = areas[4];
	area_bureau_link = areas[5];
	area_bureau_mail = areas[6];

	if (area_code == undefined) {area_code ="";}
	
	if (area_code != "") {
		location.href='../arealists/area_'+area_code+'.shtml';
		return true;
	} else {
		//エラー
		return false;
	}

}

function goBureau() {

	var areas = new Array();
	areas = area_data.split(";");
	area_code = areas[0];
	area_name = areas[1];
	area_bureau_name = areas[2];
	area_bureau_addr = areas[3];
	area_bureau_tel = areas[4];
	area_bureau_link = areas[5];
	area_bureau_mail = areas[6];

	if (area_code == undefined) {area_code ="";}
	
	if (area_code != "") {
		window.open(area_bureau_link);
		return true;
	} else {
		//エラー
		return false;
	}

}

function drawBureau() {

	var areas = new Array();
	areas = area_data.split(";");
	area_code = areas[0];
	area_name = areas[1];
	area_bureau_name = areas[2];
	area_bureau_addr = areas[3];
	area_bureau_tel = areas[4];
	area_bureau_link = areas[5];
	area_bureau_mail = areas[6];

	if (area_bureau_name == undefined) {area_bureau_name ="";}
	
	if (area_bureau_name != "") {
		document.write('<font color="#3333ff"><b><u>');
		document.write(area_bureau_name);
		document.write('</u></b></font>');
		return true;
	} else {
		//エラー
		return false;
	}

}

function drawBureauTel() {

	var areas = new Array();
	areas = area_data.split(";");
	area_code = areas[0];
	area_name = areas[1];
	area_bureau_name = areas[2];
	area_bureau_addr = areas[3];
	area_bureau_tel = areas[4];
	area_bureau_link = areas[5];
	area_bureau_mail = areas[6];

	if (area_bureau_tel == undefined) {area_bureau_tel ="";}
	
	if (area_bureau_tel != "") {
		document.write(area_bureau_tel);
		return true;
	} else {
		//エラー
		return false;
	}

}

function drawItem() {
	var itemNum = item_name.length;
	
	if (itemNum == 0) {return false;}

	document.write('<span class="items">');
	for (i = 0;i < itemNum; i++) {
		var my_item_name = item_name[i];
		var my_item_value = item_value[i];
		var my_item_link = item_link[i];

		if (my_item_name == undefined) {my_item_name ="";}
		if (my_item_value == undefined) {my_item_value ="";}
		if (my_item_link == undefined) {my_item_link ="";}


		//項目名も値もなかったら表示しない
		if ((my_item_name != "")||(my_item_value != "")) {
			//ｎａｍｅ
			document.write('<div class="itemName" style="color:#006699">');
			document.write('<img src="../images/spot_arrow.gif" alt="" hspace="3">');
			document.write(my_item_name);
			document.write('</div>');
			//ｖａｌｕｅ

			if (my_item_value == "") {
				document.write('　');
			} else {
						//リンク
				if (my_item_link != "") {
					document.write('<a href="'+my_item_link+'" target="_spot">');
				}
				document.write(my_item_value);
				//リンク
				if (my_item_link != "") {
					document.write('</a>');
				}
			}

			document.write('<br style="clear: both;">');
		}
	}
	document.write('</span>');

	return itemNum;
}

function drawImages() {

	var itemNum = image_link.length;
	imageNo = 0;

	if (itemNum == 0) {return false;}

	for (i = 0;i < itemNum; i++) {
		var my_image_link = image_link[i];

		if (my_image_link == undefined) {my_image_link ="";}

		//項目名も値もなかったら表示しない
		if (my_image_link != "") {
			//ｎａｍｅ
			document.write('<img class="image" src="images/'+my_image_link+'"'+gImgOption+'><br />');
			++imageNo;
		}
	}
	document.writeln('<br>');
	return itemNum;

}

var max = 10;

function setFavorite() {

	if (spot_title == undefined) {spot_title ="";}
	if (spot_id == undefined) {spot_id ="";}
	
	if ((spot_title != "")&&(spot_id != "")) {

		var expDay = "Wed, 01 Jan 2020 10:11:11 GMT";

		var name = spot_title;
		var id  = '../japanese/'+spot_id;

		var myFavorite = new Array();

		myFavorite[0] = id+"#"+name;

		itemNum = 1;
		for (i = 0; i < 10; i++) {
			itemName = "item"+i;
			cookieValue = getCookie(itemName);
			if (cookieValue != (id+"#"+name)) {
				myFavorite[itemNum] = cookieValue;
				++itemNum;
			}
		}

		for (i = 0; i < myFavorite.length; i++) {
			itemName = "item"+i;
			setCookie(itemName,myFavorite[i]);
		}

		alert("マイスポットに追加しました");

		window.name='マイスポット';
		window.open('../MySpot.shtml','_myspot', 'SCROLLBARS=1,RESIZABLE=1,WIDTH=310,HEIGHT=330');

		return true;

	} else {
		//エラー
		return false;
	}
}


function setCookie(name, value) {
	if ((name != null)&&(value != null)) {
		expDay = "Wed, 01 Jan 2020 10:11:11 GMT";
		document.cookie = name + "=" + escape(value) + '; expires='+expDay+'; path=/h-ckp/;';
		return true;
	}
	return false;
}

function getCookie(name) {
	name +="=";
	myCookie = document.cookie + ";";
	start = myCookie.indexOf(name);
	
	if (start != -1) {
		end = myCookie.indexOf(";",start);
		retVal = unescape(myCookie.substring(start + name.length, end));
		return retVal;
	}
	return ('');
}

function viewCookie() {
	alert(document.cookie);
}


function deleteAllCokkie() {
	for (i = 0;i < max; i++) {
		itemName = "item"+i;
		deleteCookie(itemName);
	}
}
function deleteCookie(name) {
	setCookie(name, '')
	location.reload();
}

function refleshCookie() {
	var myFavorite = new Array();
	itemNum = 0;
	for (i = 0;i < max; i++) {
		itemName = "item"+i;
		myval = getCookie(itemName);
		if (myval != "") {
			myFavorite[itemNum] = myval;
			++itemNum;
		}
	}
	for (i = 0;i < max; i++) {
		itemName = "item"+i;
		myval = myFavorite[i];
		if (myval == undefined) {myval="";}
		setCookie(itemName, myval);
	}
}

function hideElement(id){
	var f = document.getElementById(id);
	f.style.visibility="hidden";
}

function showElement(id){
	var f = document.getElementById(id);
	f.style.visibility="visible";
}

function printMode() {
	print();
}

function drawComment() {

	var itemNum = comment.length;
	if (itemNum == 0) {return false;}

	document.write(comment);

	return itemNum;

}

function drawSpotStation(name,chk) {

	//最寄駅
	var st_spot_realname = new Array();
	var st_spot_code = new Array();

	st_spot_realname = st_spot_realnames.split(";");
	st_spot_code = st_spot_codes.split(";");

	var itemNum = st_spot_code.length;

	if (itemNum == 0) {return false;}

	document.write('<select name="'+name+'">');
	//無指定のを一つ記入
if(chk == 1) {
	document.writeln('<option value="-1">ほかの駅を入力する');
	document.writeln('<option value="-1">--------------------');
}
	for (i = 0;i < itemNum; i++) {
		var realname = st_spot_realname[i];
		var code = st_spot_code[i];

		if (realname == undefined) {realname ="";}
		if (code == undefined) {code ="";}

		//値がなかったら表示しない
		if ((realname != "")&&(code != "")) {
			document.writeln('<option value="'+code+'">'+realname);
		}
	}

	//無指定のを一つ記入
if(chk == 0) {
	document.writeln('<option value="-1">--------------------');
	document.writeln('<option value="-1">ほかの駅を入力する');
}
	document.write('</select>');
	return itemNum;
}

function drawInputStation(name) {
	//フェイズ２ではリストから表示せずに自由入力にする。
	//乗り換えではサポートしているので、リストからインプットフィールドに変更する。
	document.write('<input type="text" name="'+name+'">');
	return(0);
}

function drawAreaStation(name) {

	var st_area_nickname = new Array();
	var st_area_realname = new Array();
	var st_area_code = new Array();

	st_area_nickname = st_area_nicknames.split(";");
	st_area_realname = st_area_realnames.split(";");
	st_area_code = st_area_codes.split(";");

	var itemNum = st_area_code.length;

	if (itemNum == 0) {return false;}

	if (name == "ST") {
		theForm = 0;
	} else {
		theForm = 1;
	}

	document.write('<input type="text" name="'+name+'">');
	document.write('&nbsp;');

	document.write('<select name="'+name+'_list" onchange="set'+name+'(\''+theForm+'\')" >');
	//無指定のを一つ記入
	document.writeln('<option value= "0">主要駅');
//	document.writeln('<option value="-1">主要地点をプルダウンから選択');
	document.writeln('<option value="-1">------');

	for (i = 0;i < itemNum; i++) {
		var nickname = st_area_nickname[i];
		var realname = st_area_realname[i];
		var code = st_area_code[i];

		if (nickname == undefined) {nickname ="";}
		if (realname == undefined) {realname ="";}
		if (code == undefined) {code ="";}

		//値がなかったら表示しない
		if ((nickname != "")&&(realname != "")&&(code != "")) {

			if (nickname == realname) {
				show = nickname;
			} else {
				show = nickname+'('+realname+')';
			}

			document.writeln('<option value="'+code+'">'+show);
		}
	}

	//無指定のを一つ記入
	document.write('</select>');
	return itemNum;
}

function setSF(theForm)
{
	var sfIndex = document.forms[theForm].SF_list.selectedIndex;
	var sfValue = document.forms[theForm].SF_list.options[sfIndex].value;
	var sfName  = document.forms[theForm].SF_list.options[sfIndex].text;
	if (sfValue < 1) return -1;
	document.forms[theForm].SF.value = sfName;
}
function setST(theForm)
{
	var stIndex = document.forms[theForm].ST_list.selectedIndex;
	var stValue = document.forms[theForm].ST_list.options[stIndex].value;
	var stName  = document.forms[theForm].ST_list.options[stIndex].text;
	if (stValue < 1) return -1;
	document.forms[theForm].ST.value = stName;
}

function checkSelect(theForm) {

	var sfIndex = document.forms[theForm].SF.selectedIndex;
	var stIndex = document.forms[theForm].ST.selectedIndex;

	var sfValue;
	var stValue;

	if (sfIndex != undefined) {
		sfValue = document.forms[theForm].SF.options[sfIndex].value;
	} else {
		sfValue = document.forms[theForm].SF.value;
		if (sfValue == "") {sfValue = "-1";}
	}

	if (stIndex != undefined) {
		stValue = document.forms[theForm].ST.options[stIndex].value;
	} else {
		stValue = document.forms[theForm].ST.value;
		if (stValue == "") {stValue = "-1";}
	}

	if ((sfValue != "-1")&&(stValue != "-1")) {
		var options = 0;//0:日本語１：英語
		goNorikae(sfValue,stValue,options);
		return true;
	} else {
		alert('最寄り駅や出発地点を入力してください。');
		return false;
	}

}

function goNorikae(sfValue,stValue,options) {

	var URL = "http://ckp.ivcreation.com/ckp-norikae/N1?";
	URL = URL + "SF="+sfValue+"&ST="+stValue+"&OUTPUT="+options;

	nWin = window.open('','_norikae', 'SCROLLBARS=1,RESIZABLE=1,WIDTH=500,HEIGHT=400,STATUS=1');
	nWin.name='norikae';
	nWin.status = '中部観光ポータルサイト　乗り換え案内';
	nWin.focus();

	nWin.document.writeln('<html><head>');
	nWin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
	nWin.document.writeln('<title>中部観光ポータル：乗り換え案内</title>');
	nWin.document.writeln('<style type="text/css">');
	nWin.document.writeln('<!--');
	nWin.document.writeln('body {  background-image:  url(images/win.jpg); background-repeat: repeat-x}');
	nWin.document.writeln('.p_10 {  font-size: 10px; letter-spacing: 1px}');
	nWin.document.writeln('.p_16 {  font-size: 16px; letter-spacing: 1px}');
	nWin.document.writeln('.p_12 {  font-size: 12px; letter-spacing: 1px; line-height: 120%}');
	nWin.document.writeln('-->');
	nWin.document.writeln('</style>');
	nWin.document.writeln('</head>');
	nWin.document.writeln('<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	nWin.document.writeln('<div align="center">');
	nWin.document.writeln('<table height="100%" width="100%">');
	nWin.document.writeln('<tr><td class="p_10" align="right"><br><br><a href="'+URL+'" target="ckp_norikae">はじめから</a><br><br><br><br><br></td></tr>');
	nWin.document.writeln('<tr height="100%"><td align="center"><iframe name="ckp_norikae" src="'+URL+'" width="100%" height="100%" frameborder="0">iframe対応ブラウザでご覧ください。</iframe></td></tr>');
	nWin.document.writeln('<tr height="1"><td background="images/line_300.gif"><img src="images/spacer.gif" width="100%" height="1"></td></tr>');
	nWin.document.writeln('<tr><td align="center" class="p_10" height="20"><font color="#666666">Copyright(C)2004 中部運輸局, All Rights Reserved. </font></td></tr>');
	nWin.document.writeln('</table>');
	nWin.document.writeln('</div>');
	nWin.document.writeln('</body></html>');

	return true;
}

//デザイン系スクリプト
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.0
  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 && document.getElementById) x=document.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 locationMap_baseMapSize(obj) {
	document.getElementById(obj).style.width = this.width;
	document.getElementById(obj).style.height  = this.height;
}

function locationMap_pos(x,y,obj) {//x経度,y緯度、数字が大きいほうがX
	var theObj = document.getElementById(obj);
	theObj.style.left = this.vx(x) - this.icon_w / 2;
	theObj.style.top  = this.vy(y) - this.icon_h / 2;
}

function locationMap_checkArea(x,y) {//x経度,y緯度、数字が大きいほうがX
	if (this.left > x || this.right < x) {return false;}
	if (this.bottom > y || this.top < y) {return false;}
	return true;
}

function locationMap_vx(x) {
	vx = Math.round((x - this.left) / this.map_width * this.width);
	return vx;
}

function locationMap_vy(y) {
	vy = this.height - Math.round((y - this.bottom)/ this.map_height * this.height);
	return vy;
}

function locationMap() {
	this.left   = 135.25*3600*100;//135.25
	this.top    =  38*3600*100;//38
	this.right  = 140*3600*100;//140
	this.bottom =  34*3600*100;//34

	this.width = 320;
	this.height= 326;
	this.icon_w = 42;
	this.icon_h = 42;
	this.map_width = this.right - this.left;
	this.map_height = this.top - this.bottom;

//メソッド
	this.vx = locationMap_vx;
	this.vy = locationMap_vy;
	this.baseMapSize = locationMap_baseMapSize;
	this.pos = locationMap_pos;
	this.checkArea = locationMap_checkArea;
	
}

var map = new locationMap();//いくつもインスタンスをつくらない

function pos(x,y) {//x経度,y緯度、数字が大きいほうがX
	map.baseMapSize("baseMap");
	var theObj = document.getElementById("baseMap");

	//三重の下限だけ特例
	if (y < map.bottom) {y = map.bottom;}

	//範囲チェック
	if (map.checkArea(x,y) != true) {
		document.writeln("開発用メッセージ<br>この座標は範囲外です。<br>"+x+","+y+"<br>");
		document.writeln("範囲<br>"+map.left+"-"+map.right+"<br>"+map.bottom+"-"+map.top);
		
		
		theObj.style.visibility = "hidden";
		return false;

	} else {
		theObj.style.visibility = "visible";
	}
	//ポイントを移動
	map.pos(x,y,"star");
}


//φ２で追加ジャンルからで使用

//汎用出力
function outPrint(data) {
	document.writeln(data);
}

function outPrintImg(myfile,myOption) {
	document.writeln('<img src="'+myfile+'" border="0" '+myOption+'>');
}

function initSpot() {
	var obj = document.getElementById("waribiki");
	if (otoku == '1') {
		obj.style.display = "inline";
	} else {
		obj.style.display = "none";
	}
}
