// check cookie
var ALERT_MES = "お客様がご利用になられているブラウザのcookie機能が無効となっております。\r\n大変お手数ですがブラウザのcookie機能を有効にしてご利用下さい。";
var ckName = "Cookie-Check";
var code = Math.floor(10000*Math.random()) + 1;
var savedCode = code;
var readCode;
document.cookie = ckName + "=" + escape(code);
ckName = "Cookie-Check=";
box = document.cookie + ";";
start = box.indexOf(ckName);
if(start != -1) {
	end = box.indexOf(";", start);
	readCode = unescape(box.substring(start + ckName.length, end));
} else {
	var readCode = 0;
}
if(savedCode != readCode) {
	alert(ALERT_MES);
	var topUrl = "http://" + location.host;
	var pathname = location.pathname;
	
	// pathname is /99/999999/xxx or pathname= /sitepath/99/999999/xxx
	var pathElms = pathname.split("/");
	
	/* redirect genre_top at location is not genre_top */
	if(location.href != "http://belluna.jp"
		&& location.href != "http://belluna.jp/"
		&& location.href != "http://belluna.jp/ryuryu"
		&& location.href != "http://belluna.jp/ryuryu/"
		&& location.href != "http://orelife.tv"
		&& location.href != "http://orelife.tv/") {
		
		// undef genre
		if(pathElms.length < 3) {
			window.location = topUrl;
		}
		// def genre
		else {
		// non genre_top → to genre_top
			if((pathElms[pathElms.length - 1].length != 0 && pathElms[pathElms.length - 1] != "genre_top")
				|| (pathElms[pathElms.length - 2] != "genre_top" && pathElms[pathElms.length - 1] != "genre_top")) {
			  	// /01/999999/xxx
				if(pathElms[1] == "01") {
					topUrl += "/" + pathElms[1] + "/" + pathElms[2] + "/genre_top/";
			  	// /02/999999/xxx
			  	} else if(pathElms[1] == "02") {
			  		topUrl += "/01/" + pathElms[2] + "/genre_top/";
			  	// /sitepath/99/999999/xxx
				} else {
					topUrl += "/" + pathElms[1] + "/01/" + pathElms[3] + "/genre_top/";
				}
				window.location = topUrl;
			}
		}
	}
}
