
var shop_id;
var pref_id;
var shop_name;
var pref_name;

var ck_cook = document.cookie.split(";");
var i1=0;
var i2=0;
var i3=0;
var i4=0;


//alert(document.cookie);

for(a=0; a<ck_cook.length; a++){
	splt = ck_cook[a].split("=");
	splt[0] = splt[0].replace(" ","");
	if(splt[0] == "third_planet_pref_id"){
		pref_id = splt[1];
		i1 = 1;
	}
	if(splt[0] == "third_planet_shop_id"){
		shop_id = splt[1];
		i2 = 1;
	}
}

if(!(i1 == 1 && i2 == 1)){
	shop_id = 14;
	shop_name = "港北ニュータウン店";
	document.cookie = "third_planet_pref_id="+pref_id+"; path=/; expires=Fri, 31-Dec-2030 23:59:59; ";
	document.cookie = "third_planet_shop_id="+shop_id+"; path=/; expires=Fri, 31-Dec-2030 23:59:59; ";
}


//地域および店舗変更を選択した場合
//都道府県一覧を表示
function ShowPrefList(){
	document.getElementById('all_pref').style.display = "block";

}


//都道府県を選択した場合
//店舗一覧を別ウィンドウで表示
function Select(pref_id){

	strUrl = "/shop_list.php?pref_id="+pref_id;
	subWin = window.open(strUrl,"","width=320,height=200,location=no,scrollbars=yes,menubar=no");

}


//都道府県を選択した場合
//地域を表示、店舗をクリア
//都道府県一覧を非表示
//現在は使用していません
function SelectPref(pref_name){

}


//店舗名を選択した場合
//地域、店舗を表示
//リンクを変更
//都道府県一覧を非表示
function selectShop(id,shop_name,pref_id,pref_name){

	window.opener.document.getElementById('pref_name').innerHTML = pref_name;
	window.opener.document.getElementById('shop_name').innerHTML = shop_name;

	if(id){
		window.opener.document.getElementById('shop_info').href = "/shop/detail/index.php?shop_id="+id;
		window.opener.document.getElementById('event_info').href = "/shop/detail/event.php?shop_id="+id;
		window.opener.document.getElementById('machine_info').href = "/shop/detail/machine.php?shop_id="+id;
	}else if(pref_id){
		window.opener.document.getElementById('shop_info').href = "/shop/result.php?pref_id="+pref_id;
		window.opener.document.getElementById('event_info').href = "/shop/event/index.php?pref_id="+pref_id;
		window.opener.document.getElementById('machine_info').href = "/shop/machine/index.php?pref_id="+pref_id;
	}

	window.opener.setCookit(pref_name,shop_name,pref_id,id);

	window.opener.document.getElementById('all_pref').style.display = "none";

	window.close();

}


function cancel(){

	document.getElementById('all_pref').style.display = "none";

}


//地域および店舗変更のクラス変更
function changeColor(id){

	document.getElementById(id).className = "change_color2";

}

//地域および店舗変更のクラス変更
function changeColor2(id){

	document.getElementById(id).className = "change_color";

}


function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}

function setCookit(p_name,s_name,p_id,s_id){

	var period = 7;
	var cook;
	// 有効期限の作成
	var nowtime = new Date().getTime();
	var clear_time = new Date(nowtime + (60 * 60 * 24 * 1000 * period));
	var expires = clear_time.toGMTString();




	cook = "third_planet_pref_id="+p_id+"; path=/; expires=Fri, 31-Dec-2030 23:59:59; ";
	document.cookie = cook;
	cook = "third_planet_shop_id="+s_id+"; path=/; expires=Fri, 31-Dec-2030 23:59:59; ";
	document.cookie = cook;
}
