//=======================================================================
//  @file ja_define.js
//  @brief ＪＡ googleマップデータ
//  
//=======================================================================
var MAP_FIRST_POINT_X	= 138.603515625;		//マップの初期緯度
var MAP_FIRST_POINT_Y	= 38.341656192795924;	//マップの初期経度
var MAP_BIG_WIDTH 		= '500px';				//大きいのマップの幅
var MAP_BIG_HEIGHT 		= '400px';				//大きいのマップの高さ
var MAP_SMALL_WIDTH		= '380px';				//小さいのマップの幅
var MAP_SMALL_HEIGHT	= '280px';				//小さいのマップの高さ
var MAP_FIRST_ZOOM		= 12;					//マップの初期拡大数
var MAP_SECOND_ZOOM		= 9;					//マップの2番目拡大数
var MAP_THIRD_ZOOM		= 3;					//マップの3番目拡大数
var MAP_FOURTH_ZOOM		= 1;					//マップの4番目拡大数
var JA_COL_NUM			= 4;					//マップの下に表示されるＪＡ表の列の数
var JA_TD_WIDTH			= 110;					//マップの下に表示されるＪＡ表のTDのwidth
var NOAJAX_PAGE			= "notajax.html";

var NODATA_MESSAGE		= "申し訳ありませんが<br>地図は未登録となっております。";	//データが無いときのメッセージ
var NOMAP_MESSAGE		= "<table border=\"0\" bgcolor=\"#F1F2EB\" width=\"380px\" height=\"280px\"><tr><td>申し訳ありませんがお使いのブラウザでは<br>地図を見ることができません。<br>winIE5.5+，Mac Safari1.2+，Firefoxなどでご覧下さい。</td></tr></table>";	//データが無いときのメッセージ

//テーブル
var g_tblTenpoU		= new Array( "店舗名", "店舗番号", "郵便番号", "住所", "電話番号");

//グローバル変数
var o_Map, o_Icon, o_Icon2;

//=========================================================================
//		innerHTML
//=========================================================================
function InHtmlError	( code ){ document.getElementById('no_message').innerHTML	= code; }
function InHtmlReset	( code ){ document.getElementById('reset').innerHTML		= code; }
function InHtmlRInfo	( code ){ document.getElementById('right_info').innerHTML	= code; }
function InHtmlJaName	( code ){ document.getElementById('ja_name').innerHTML		= code; }
function InHtmlPankuzu	( code ){ document.getElementById('pankuzu').innerHTML		= code; }
function InHtmlUInfo	( code ){ document.getElementById('under_info').innerHTML	= code; }
function InHtmlSearch	( code ){ document.getElementById('kensaku').innerHTML		= code; }
function InHtmlAnswer	( code ){ document.getElementById('answer').innerHTML		= code; }


//---------------------------------------------------------------------
//	ブラウザチェック
//	@return Description
//---------------------------------------------------------------------
function CheckBrowser() {
	if( !GBrowserIsCompatible() ){
//	if( !chkAjaBrowser() || !GBrowserIsCompatible() ){		
		if( !(navigator.userAgent.indexOf("MSIE 5.5")!=-1)){
			location.href = NOAJAX_PAGE;
		}
	}
}


//---------------------------------------------------------------------
//	アイコン取得
//---------------------------------------------------------------------
function GetIcon ( flag ) {
	var icon 			= new GIcon();
	if( flag ){
		icon.image 			= "./images/icon_map_l.png";
		icon.shadow 		= "./images/icon_map_l_shadow.png";
		icon.iconSize 		= new GSize(44,31);
		icon.shadowSize 	= new GSize(44,31);
		icon.iconAnchor 	= new GPoint(16, 31);
		icon.printImage		= "./images/icon_map_l.gif";
		icon.printShadow	= "./images/icon_map_l_shadow.gif";
	}else{
		icon.image 			= "./images/icon_map_s.png";
		icon.shadow 		= "./images/icon_map_s_shadow.png";
		icon.iconSize 		= new GSize(35,24);
		icon.shadowSize 	= new GSize(35,24);
		icon.iconAnchor 	= new GPoint(11, 24);
		icon.printImage		= "./images/icon_map_s.gif";
		icon.printShadow	= "./images/icon_map_s_shadow.gif";
	}
	return icon;
}

//---------------------------------------------------------------------
//	ＪＡ用マップ作成
//	@param width 横のサイズ
//	@param height たてのサイズ
//	@return map		GMap
//---------------------------------------------------------------------
function CreateMap( width, height ) {
	var mapDiv = document.getElementById("map");
	mapDiv.style.width 	= width;
	mapDiv.style.height	= height;
	var map = new GMap( mapDiv );
	map.addControl( new GMapTypeControl() );
	map.addControl( new GSmallMapControl() );
	return map;
}


//---------------------------------------------------------------------
//	マップの描画
//	@param visible 描画するかどうか
//	@return Description
//---------------------------------------------------------------------
function MapVisible( visible ){
	var mapDiv = document.getElementById("map");
	if( visible ){
		mapDiv.style.visibility = "visible";
		mapDiv.style.Display 	= "block";
//		mapDiv.style.Display 	= "inline";
//		mapDiv.style.Display 	= "list-item";
		mapDiv.style.width 		= MAP_SMALL_WIDTH;
		mapDiv.style.height 	= MAP_SMALL_HEIGHT;
	}else{
		mapDiv.style.visibility = "hidden";
		mapDiv.style.Display 	= "none";
		mapDiv.style.width 		= "0px";
		mapDiv.style.height 	= "0px";
	}
}


//---------------------------------------------------------------------
//	マップの描画
//	@param visible 描画するかどうか
//	@return Description
//---------------------------------------------------------------------
function NoDataMesVisible( visible ){
	var mesDiv = document.getElementById('no_message');
	if( visible ){
		InHtmlError( NODATA_MESSAGE );
		mesDiv.style.visibility = "visible";
		mesDiv.style.Display 	= "block";
	}else{
		InHtmlError("");
		mesDiv.style.visibility = "hidden";
		mesDiv.style.Display 	= "none";
	}
}



//---------------------------------------------------------------------
//	マップを表示できないときの処理
//	@return Description
//---------------------------------------------------------------------
function DataSearchProcess( flag ) {
	if( flag ){
		//マップ表示
		MapVisible( true );
		
		//マップがみつかった
		NoDataMesVisible( false );
		
	}else{
		//マップ非表示
		MapVisible( false );
		
		//マップがみつからない
		NoDataMesVisible( true );
		
		//リセットボタン消去
		InHtmlReset('');
	}
}


//---------------------------------------------------------------------
//	パンくず作成
//	@return html
//---------------------------------------------------------------------
function CreatePankuzu ( pref, hoten, pid, hid, no ) {
	var html = "<a href=index.html >全国</a>";
	if( pref != null || pref != undefined ){
		if( hoten != null || hoten != undefined ){
			html += "　>>　<a href=ta1.php?pref="+pid+">"+pref+"</a>";
			if( hid != undefined && no != undefined ){
				html += "　>>　<a href=ja_honten.php?pref="+pid+"&id="+hid+"&no="+no+">"+hoten+"</a>";
			}else{
				html += "　>>　"+hoten;
			}
		}else{
			html += "　>>　"+pref;
		}
	}
	return html;
}

//---------------------------------------------------------------------
//	右の情報ＨＴＭＬ作成(店舗)
//	@param param 	代入パラメータ
//	@param tblr 	左表	
//	@param tblr 	右表
//	@return			作成文字列
//---------------------------------------------------------------------
function CreateRightInfo ( param, url ) {
	var html="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"mapdata\">";
	html += "<tr><th class=\"keniki\">"+param[0]+"</th></tr>";
	for( var i = 1; i < param.length; i++ ){
		if( i == param.length-1 && url ){
			if( param[i] ){
				html += "<tr><td><a href=\""+param[i]+"\" target=\"_blank\" class=\"outsidelink\">ホームページはこちら<span class=\"hideurl\">("+param[i]+")</span></a></td></tr>";
			}else{
				html += "<tr><td></td></tr>";
			}
		}else{
			if( (i%2) ){
				html += "<tr><th>"+param[i]+"</th></tr>";
			}else{
				if( i == 2 && param[i-1] == '店舗名'){
					html += "<tr><td><b>"+param[i]+"</b></td></tr>"
				}
				else {
					html += "<tr><td>"+param[i]+"</td></tr>";
				}
			}
		}
	}
	html +="</table>";
	return html;
}


//---------------------------------------------------------------------*/
//  日本語の各行の番号取得
//  @param word チェック文字列
//  @return 文字行番号
//---------------------------------------------------------------------*/
function CheckJapaneseLine ( word )
{
	if( word.indexOf('ｼﾝﾚﾝ') != -1 ) return 10;		//その他
	if( word.match(/^[ｱ-ｵ]/) ) return 0;		//あ行
	if( word.match(/^[ｶ-ｺ]/) ) return 1;		//か行
	if( word.match(/^[ｻ-ｿ]/) ) return 2;		//さ行
	if( word.match(/^[ﾀ-ﾄ]/) ) return 3;		//た行
	if( word.match(/^[ﾅ-ﾉ]/) ) return 4;		//な行
	if( word.match(/^[ﾊ-ﾎ]/) ) return 5;		//は行
	if( word.match(/^[ﾏ-ﾓ]/) ) return 6;		//ま行
	if( word.match(/^[ﾔ-ﾖ]/) ) return 7;		//や行
	if( word.match(/^[ﾗ-ﾛ]/) ) return 8;		//ら行
	if( word.match(/^[ﾜｦﾝ]/) ) return 9;		//わ行

	return -1;
}

//---------------------------------------------------------------------
//	あ行等のHTML作成
//	@param num 行の最大数
//	@param line 行番号
//	@return Description
//---------------------------------------------------------------------
function GetJapaneseLine ( num, line )
{
	var word	=	new Array("あ行","か行","さ行","た行","な行","は行","ま行","や行","ら行","わ行","その他");	//行の名前
	var rowspan = (num % JA_COL_NUM) ? Math.floor(num / JA_COL_NUM)+1 : Math.floor(num / JA_COL_NUM);
	if( rowspan == 0 ) rowspan = 1;
	return "<tr><th rowspan=\""+rowspan+"\" class=\"line\" >"+word[line]+"</th>"; 
}


//---------------------------------------------------------------------
//	クエリーの取得
//	@return Description
//---------------------------------------------------------------------
function GetQuery( id ){
	if (location.search.length > 1) {
		var m_Array = location.search.substr(1).split("&"); 
		for (idx in m_Array) {
			if( id == m_Array[idx].split("=")[0] ){
				return m_Array[idx].split("=")[1];
			}
		}
	}
	return null;
}

//---------------------------------------------------------------------
//	別ウィンドウでURL表示
//	@return Description
//---------------------------------------------------------------------
function GetShopURL( pref, code, no, ja, shop ){
	element = window.open( "", "win_url", "width=600,height=300");
	element.document.open();
	element.document.write("<html>"+
	"<head>"+
	"<link href=\"../common/css/basic/base.css\" rel=\"stylesheet\" type=\"text/css\" />"+
 "<link href=\"../common/css/3rd/base.css\" rel=\"stylesheet\" type=\"text/css\" />"+
 "<link href=\"../common/css/tenpo/base.css\" rel=\"stylesheet\" type=\"text/css\" />"+
	"<title>地図URL</title>"+
	"</head>"+
 "<body id=\"popup_url\">"+
 "<div id=\"popup_url_contents\">"+
	"<h3>"+
	"地図URL"+
	"</h3>"+
 "<div id=\"url_area\">"+
	"全国　>>　"+GetJaName( pref )+"　>>　"+ja+"　>>　"+shop+"　の地図URL"+
	"<form>"+
	"<textarea name=\"urlerea\" rows=\"5\" cols=\"50\" >http://www.jabank.org/tenpo/shiten_search.php?pref="+pref+"&code="+code+"&no="+no+"</textarea>"+
	"<p class=\"urlbtn\">"+
	"<a href=\"javascript:window.close();\">"+
	"<img src=\"../common/images/util/btn_close.gif\" alt=\"ウィンドウを閉じる\" width=\"115\" height=\"29\" border=\"0\" />"+
	"</a>"+
	"</p>"+
	"</form>"+
 "</div>"+
 "</div>"+
 "</body>"+
	"</html>"
	);
	element.document.close();
}

//---------------------------------------------------------------------
//	リセットボタン等のセット
//	@return Description
//---------------------------------------------------------------------
function getConfigButton( reset, print, url ) {
	var button = "<p class=\"mapbtn_s\">";
	if( reset ){
//		button += "<img src=\"images/btn_mapreset.gif\" alt=\"表示位置をリセット\" width=\"111\" height=\"29\" border=\"0\" onClick=\"o_Map.centerAndZoom( new GPoint( "+reset[0]+", "+reset[1]+" ), "+reset[2]+" )\" class=\"btn_reset\" />&nbsp;";
		button += "<a href='#' onClick=\"o_Map.centerAndZoom( new GPoint( "+reset[0]+", "+reset[1]+" ), "+reset[2]+" )\"><img src=\"images/btn_mapreset.gif\" alt=\"表示位置をリセット\" width=\"111\" height=\"29\" border=\"0\" class=\"btn_reset\" /></a>&nbsp;";
	}
	if( print ){
		button += "<a href='#' onClick=\"window.print()\"><img src=\"images/btn_print.gif\" alt=\"このページを印刷する\" width=\"128\" height=\"29\" border=\"0\" class=\"btn_print\" /></a>&nbsp;";
//		button += "<img src=\"images/btn_print.gif\" alt=\"このページを印刷する\" width=\"128\" height=\"29\" border=\"0\" onClick=\"window.print()\" class=\"btn_print\" />&nbsp;";
	}
	if( url ){
		button += "<a href='#' onClick='GetShopURL( \""+url[0]+"\", "+url[1]+"000"+","+url[2]+","+url[3]+","+url[4]+")'\"><img src=\"images/btn_mapurl.gif\" alt=\"地図URLを表示\" width=\"111\"  height=\"29\" border=\"0\" class=\"btn_url\" /></a>";
//		button += "<img src=\"images/btn_mapurl.gif\" alt=\"地図URLを表示\" width=\"111\"  height=\"29\" border=\"0\" onClick='GetShopURL( \""+url[0]+"\", "+url[1]+"000"+","+url[2]+","+url[3]+","+url[4]+")'\" class=\"btn_url\" />";
	}
	button += "</p>";

	return button;
}

//---------------------------------------------------------------------
//	都道府県データ取得
//	@param	flag 0:県名取得		1:番号取得
//	@param code 検索用code
//	@return 名前
//---------------------------------------------------------------------
function GetPrefName( flag, code ){
	var prefname = Array(
		'0101','北海道(道北)',
		'0102','北海道(道東)',
		'0103','北海道(道南・道央)',
		'0200','青森県',
		'0300','岩手県',
		'0400','宮城県',
		'0500','秋田県',
		'0600','山形県',
		'0700','福島県',
		'0800','茨城県',
		'0900','栃木県',
		'1000','群馬県',
		'1100','埼玉県',
		'1200','千葉県',
		'1300','東京都',
		'1400','神奈川県',
		'1500','新潟県',
		'1600','富山県',
		'1700','石川県',
		'1800','福井県',
		'1900','山梨県',
		'2000','長野県',
		'2100','岐阜県',
		'2200','静岡県',
		'2300','愛知県',
		'2400','三重県',
		'2500','滋賀県',
		'2600','京都府',
		'2700','大阪府',
		'2800','兵庫県',
		'2900','奈良県',
		'3000','和歌山県',
		'3100','鳥取県',
		'3200','島根県',
		'3300','岡山県',
		'3400','広島県',
		'3500','山口県',
		'3600','徳島県',
		'3700','香川県',
		'3800','愛媛県',
		'3900','高知県',
		'4000','福岡県',
		'4100','佐賀県',
		'4200','長崎県',
		'4300','熊本県',
		'4400','大分県',
		'4500','宮崎県',
		'4600','鹿児島県',
		'4700','沖縄県'
	);
	for( var i = flag; i < prefname.length*2; i+=2 ){
		if( flag == 0 ){
			if( prefname[i] == Number(code) ) return prefname[i+1];
		}
		if( flag == 1 ){
			if( prefname[i] == code ) return prefname[i-1];			
		}
	}
	return null;
}


//---------------------------------------------------------------------
//	ＪＡ名取得
//	@param no Discription
//	@return Description
//---------------------------------------------------------------------
function GetJaName( no ){
	var prefname = Array(
		'0101','北海道(道北)',
		'0102','北海道(道東)',
		'0103','北海道(道南・道央)',
		'0200','青森',
		'0300','岩手',
		'0400','宮城',
		'0500','秋田',
		'0600','山形県',
		'0700','福島',
		'0800','茨城',
		'0900','栃木',
		'1000','群馬',
		'1100','埼玉',
		'1200','千葉',
		'1300','東京',
		'1400','神奈川',
		'1500','新潟',
		'1600','富山',
		'1700','石川',
		'1800','福井',
		'1900','山梨',
		'2000','長野',
		'2100','岐阜',
		'2200','静岡',
		'2300','愛知',
		'2400','三重',
		'2500','滋賀',
		'2600','京都',
		'2700','大阪',
		'2800','兵庫',
		'2900','奈良',
		'3000','和歌山',
		'3100','鳥取',
		'3200','島根',
		'3300','岡山',
		'3400','広島',
		'3500','山口',
		'3600','徳島',
		'3700','香川',
		'3800','愛媛',
		'3900','高知',
		'4000','福岡',
		'4100','佐賀',
		'4200','長崎',
		'4300','熊本',
		'4400','大分',
		'4500','宮崎',
		'4600','鹿児島',
		'4700','沖縄'
	);
	for( var i = 0; i < prefname.length*2; i+=2 ){
		if( prefname[i] == no ){
			return "JAバンク"+prefname[i+1];
		}
	}
	return -1;
}
