/*
 * npro_start.js
 * Created on 2005/11/02
 * 
 * !!! 注意 !!!
 * cookie.js を先に読み込んでください。
 */

var KEY = "taiheiyo_netizen";
var DONE = "done";
var NONE = "none";
var DAYS = 365;
var NEXT_PAGE = "netizen.html";
var OTHER_PAGE = "other.html";
var expdate = new Date();

/**
 * 同意する
 * 
 */
function agreeYes()
{
	expdate = expireDays(DAYS, expdate);
	setCookie(KEY, DONE, expdate);
	location.href = NEXT_PAGE;
}


/**
 * 同意しない
 * 
 */
function agreeNo()
{
	expdate = expireDays(-DAYS, expdate);
	setCookie(KEY, NONE, expdate);
	location.href = "../index.php";
}



/**
 * 同意済みかどうか調べる
 * 
 * @return 同意済みの場合 true
 */
function isAgreed()
{
	var value = getCookie(KEY);
	return (value == DONE);
}



/**
 * 規定内のOSであるか調べる。
 * HTTP_USER_AGENT は詐称できるので信頼性は薄い...
 * 
 * @return 規定内のOSである場合true、そうでない場合false
 */
function isAllowNavigator()
{
	var userAgent = navigator.userAgent;

	if (userAgent == null || userAgent.length == 0) return false;

	// Windows2000, WindowsXP, IE5-6
	if (userAgent.match(/MSIE\s5.*Windows\sNT\s5.*/)) {
		return true;
	}
	else if (userAgent.match(/MSIE\s6.*Windows\sNT\s5.*/)) {
		return true;
	}
	else if (userAgent.match(/MSIE\s7.*Windows\sNT\s5.*/)) {
		return true;
	}
	else if (userAgent.match(/MSIE\s5.*Windows\sXP/)) {
		return true;
	}
	else if (userAgent.match(/MSIE\s6.*Windows\sXP/)) {
		return true;
	}
	else if (userAgent.match(/MSIE\s7.*Windows\sXP/)) {
		return true;
	}
	// Windows98, WindowsMe, IE5-6
	// WindowsMe の HTTP_USER_AGENT は Windows 98; Win 9x 4.90 となるらしい
	else if (userAgent.match(/MSIE\s6.*Windows\s98/)) {
		NEXT_PAGE = "otherOS.html";
		return true;
	}
	else if (userAgent.match(/MSIE\s5.*Windows\s98/)) {
		NEXT_PAGE = "otherOS.html";
		return true;
	}
	// 特別制御
	// WindowsVISTA, IE7
	else if (userAgent.match(/MSIE\s7.*Windows\sNT\s6.*/)) {
		NEXT_PAGE = "../netizen5.php";
		return true;
	}
	// Other
	return false;
}


function npro_start_first()
{
	if (cookieEnabled() == false) {
		location.href = OTHER_PAGE;
		return;
	}

	// OS・ブラウザのチェック
	if (isAllowNavigator() == false) {
		// 規定外のOS・ブラウザ
//		alert(navigator.userAgent);
		location.href = OTHER_PAGE;
		return;
	}

	// 既に同意済みの場合は netizen.html に飛ばす
	if (isAgreed()) {
		location.href = NEXT_PAGE;
		return;
	}


}
// EOF
