/**********************************************************************
			
			会員認証後にコンテンツ内にユーザー名を表示する

			Ver：1.00

			作成日：2003年03月17日
			更新日：2005年05月21日

**********************************************************************/

cookie = document.cookie;

currentPath = location.pathname;

//-------------------------------
// MRID がない場合
//-------------------------------
if(cookie.indexOf("MRID") == -1){

	if(currentPath.indexOf("/meminfo/") == 0){
		// 非会員ページへ
		redirectPath = currentPath.replace("/meminfo/", "/usrinfo/");
		document.location = "http://" + location.hostname + redirectPath;
	}

}else
//-------------------------------
// MRID がある場合
//-------------------------------
if(location.protocol == "http:"){
	// httpの場合、httpsにする

	// 会員ページへ(クッキーありで非会員ページにアクセスの場合）
	redirectPath = currentPath.replace("/usrinfo/", "/meminfo/");
	document.location = "https://" + location.hostname + redirectPath;

}else if(currentPath.indexOf("/usrinfo/") == 0){
	// usrinfoの場合、meminfoにする

	// 会員ページへ(クッキーありで非会員ページにアクセスの場合）
	redirectPath = currentPath.replace("/usrinfo/", "/meminfo/");
	document.location = "https://" + location.hostname + redirectPath;

}else if(! check_cookie() ){
	// cookieが異常の場合、cookie(MRID)を消去する

	document.location = location.protocol + "//" + location.hostname + "/app/cookie_err.php?" + currentPath;

}else{
	// 名前の表示をしない
}

function check_cookie(){

	err_flg = 0;

	if(cookie.indexOf("WUID") == -1) return false;

	if(cookie.indexOf("NAME") == -1) return false;

	cookieArray = cookie.split(";");
	for(i in cookieArray){
		if(cookieArray[i].indexOf("WUID") != -1)break;
	}
	wuid  = cookieArray[i].substring(cookieArray[i].indexOf("=") + 1);
	len   = wuid.length;

	if(len != 10) return false;

	ts    = "0123456789";
	tl    = ts.length;
	for(i=0; i<10; i++){
		c   = wuid.substr(i,1);
		f   = 0;
		for(j=0; j<tl; j++){
			tc = ts.substr(j,1);
			if(c == tc){
				f = 1;
				break;
			}
		}
		if(f != 1){
			return false;
		}
	}

	return true;
}

function check_namestr(src){
	err = 0;
	len = src.length;
	for(i = 0; i < len; i=i+4){
		b1 = src.substr(i,   2);
		b2 = src.substr(i+2, 2);

		if(b1 == "00"){
			err = 1; break;
		}
		if(b1 + b2 == "203E"){  // ~
			err = 1; break;
		}
	}

	if(err == 1){
		document.location = location.protocol + "//" + location.hostname + "/usrinfo/system_err.html";
	}
}
