
var str=location.search;

if(str !="") {
	str=str.substring(1,str.length);
	sub=str.split("&");
	L_i=sub[0]; R_i=sub[1]; Zoom_i=Number(sub[2]);
		
}


function NetPost(yuubin, sub)
{
    var length = yuubin.length;
    if ( length ) {
    var chpost = new String();
        for ( var i=0; i < length; i++ ) {
             var c = yuubin.charCodeAt(i) - 5;
                 c = String.fromCharCode(c);
                 chpost += c;
         }
         location.href=chpost + sub;
    }
}

function FocusReset(no) {
	if ( parent.document.getElementById("tab"+no) ) {
		parent.document.getElementById("tab"+no).className = "map_menu";
		return true;
	}
	return false;
 
}

var child_id = new Array();
var L_i,R_i,Zoom_i;
var map_g;
var tab_Index=0;

function FocusTab(c_id) {
 	var i = 0;
			
	while( FocusReset(i++) );

	for ( var no=0; no < parent.child_id.length; no++) {
		if (parent.child_id[no] == c_id) {
			parent.tab_Index=no;
			break;
		}	
	}
	
	if (parent.document.getElementById("tab"+no)) {
		parent.document.getElementById("tab"+no).className = "map_menu_s";
	
	}
}

function FocusTab_I(index) {
	if ( index < parent.child_id.length) {
		if (parent.document.getElementById("disp")) {
			if (parent.document.getElementById("tab"+index).href)
				parent.document.getElementById("disp").src=parent.document.getElementById("tab"+index).href;
			
	
		}	
	}
}

var index_i = new Array();
var index_s = new Array();
var index_t = new Array();
var flag=false;
var win_i=0;

function FocusReset2() {
    for (var k=0; k < index_i.length; k++) {    
	if (document.getElementById("focus"+k) ) {	       
		document.getElementById("focus"+k).className = "map_index";

	}
    }
}

function FocusTab2(no) {
   
	FocusReset2();
	if (document.getElementById("focus"+no) ) {   
		document.getElementById("focus"+no).className = "map_index_s";
	}
     
}



function tabWindow(id) {
	if (!flag) return;
	if ( index_s[id] ) {
		index_i[id].openInfoWindowHtml(index_s[id]);
	} else {
		index_i[id].openInfoWindowTabsHtml(index_t[id]);
	}
        FocusTab2(id);
	win_i = id;
}

function Next_Prev(type)
{
	if ( type ) {
		if ( win_i < index_i.length ) {
			win_i += 1;
			tabWindow(win_i);
		} 
	} else if (win_i > 0 ) {
		win_i -= 1;
		tabWindow(win_i);
	}
}



function EventSet(id)
{
	GEvent.addListener(index_i[id], "click", function() {
		tabWindow(id);
	});
	GEvent.addListener(index_i[id], "infowindowclose", function() {
		FocusReset2();
	});
}

function iframeResize(){
	
	if (window.parent.document.getElementById('l_menu') != null ) {	
		var PageHight = document.body.scrollHeight; // ページの高さを取得
		window.parent.document.getElementById('l_menu').style.height = PageHight + 5 + 'px'; // iframeの高さを変更
	}

}


/* Cookie への書き出し
     引数 key　 : データキー （半角英数 _ のみ）
     引数 value : データの値（日本語可）
     引数 days  : データを保持する日数（ 0 の時は有効期限は省略）
*/

function WriteCookie(key, value, days) {
	var str = key + "=" + escape(value) + ";";         // 書き出す値１ : key=value
	if (days != 0) {                                                 /* 日数 0 の時は省略 */
        	var dt = new Date();                                   // 現在の日時
        	dt.setDate(dt.getDate() + days);                   // days日後の日時
        	str += "expires=" + dt.toGMTString() + ";"; // 書き出す値２ : 有効期限
	}
	document.cookie = str;                                   // Cookie に書き出し
}

/* Cookie の読み込み
     引数 key : 求める値のキー
     戻り値　 : 値（ない時は空文字""
*/

function ReadCookie(key) {
	var sCookie = document.cookie;    // Cookie文字列
	var aData = sCookie.split(";");       // ";"で区切って"キー=値"の配列にする
	var oExp = new RegExp(" ", "g");   // すべての半角スペースを表す正規表現
	key = key.replace(oExp, "");          // 引数keyから半角スペースを除去

	var i = 0;
	while (aData[i]) {                           /* 語句ごとの処理 : マッチする要素を探す */
		var aWord = aData[i].split("=");                         // さらに"="で区切る
        	aWord[0] = aWord[0].replace(oExp, "");              // 半角スペース除去
        	if (key == aWord[0]) return unescape(aWord[1]); // マッチしたら値を返す
        	if (++i >= aData.length) break;                          // 要素数を超えたら抜ける
	}
	return "";                                   // 見つからない時は空文字を返す
}

// Cookie の削除 （引数key : キー）
function DeleteCookie(key) {
	var dt = new Date();                                         // 現在の日時
	var str = key + "=;expires=" + dt.toGMTString(); // Cookie 文字列
	document.cookie = str;                                    // Cookie に書き出し
}

function WriteMap(id) {
	var bounds=map_g.getBounds();
	var ce=bounds.getCenter();	//緯度 ce.lat()、ce.lng()
	var z=map_g.getZoom();		//倍率
	var infoWin = map_g.getInfoWindow();
	var pop=infoWin.isHidden();	//吹き出し表示＝false
	var tab = infoWin.getSelectedTab();	//タブインデックス
	
	
	
	WriteCookie(id, id, 0);		//id＝地図の識別子
	WriteCookie(id+"lat", ce.lat(), 0);
	WriteCookie(id+"lng", ce.lng(), 0);
	WriteCookie(id+"zoom", z, 0);


	WriteCookie(id+"i", win_i, 0);		//win_i＝吹き出しのインデックス
	WriteCookie(id+"pop", pop, 0);
	WriteCookie(id+"tab", tab, 0);
}

function ReadMap(id) {
	
	var mdata = new Array();

	if (ReadCookie(id) == id) { 
		mdata[0]=ReadCookie(id+"lat");
		mdata[1]=ReadCookie(id+"lng");
		mdata[2]=ReadCookie(id+"zoom");
		mdata[3]=ReadCookie(id+"i");
		mdata[4]=ReadCookie(id+"pop");
		mdata[5]=ReadCookie(id+"tab");		
		for (var i=0; i< 6; i++) {
			if ( mdata[i] == "") 
				i =10; 	
		}
		if ( i == 6 ) {
			return mdata;
		}
		
	}
	return null;
}

function DeleteMap() {
	DeleteCookie("map_id");
	DeleteCookie("map_lat");
	DeleteCookie("map_lng");
	DeleteCookie("map_zoom");

	DeleteCookie("map_i");
	DeleteCookie("map_pop");
	DeleteCookie("map_tab");
}

