/*
 * npro_start.js
 * Created on 2007/07/02
 * 
 * !!! 注意 !!!
 * cookie.js を先に読み込んでください。
 */

var KEY = "aviva_one";
var DONE = "done";
var NONE = "none";
var DAYS = 365;
var NEXT_PAGE = "start.php";
var OTHER_PAGE = "app/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;

        //起動許可
        // Windows 64bit & IE 64bit
        if(userAgent.match(/MSIE\s.*Windows\s.*Win64/)) {
                return false;
        }
        // Windows 64bit & IE 32bit
        else if( userAgent.match(/MSIE\s.*Windows\s.*WOW64/)) {
                return false;
        }
        // Windows7 IE8
        else if (userAgent.match(/MSIE\s8.*Windows\sNT\s6.1/)) {
                return true;
        }
        // WindowsVISTA IE7
        else if (userAgent.match(/MSIE\s7.*Windows\sNT\s6.0/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s8.*Windows\sNT\s6.0/)) {
                return true;
        }
        // WindowsXP, IE6-7
        else if (userAgent.match(/MSIE\s6.*Windows\sXP/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s6.*Windows\sNT\s5.*/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s7.*Windows\sXP/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s7.*Windows\sNT\s5.*/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s8.*Windows\sXP/)) {
                return true;
        }
        else if (userAgent.match(/MSIE\s8.*Windows\sNT\s5.*/)) {
                return true;
        }
        // Windows2000, IE6
        else if (userAgent.match(/MSIE\s6.*Windows\sNT\s5.*/)) {
                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;
	}

}


function Agreed_check()
{
	if (cookieEnabled() == false) {
		location.href = other;
		return;
	}

	// OS・ブラウザのチェック
	if (isAllowNavigator() == false) {
		// 規定外のOS・ブラウザ
//		alert(navigator.userAgent);
		location.href = other;
		return;
	}
	
	// 既に同意済みの場合は netizen.html に飛ばす
	if (isAgreed()) {
		location.href = npro_page;
		return;
//	}ELSE{
//		location.href = NEXT_PAGE;
//		return;
	}

}


// EOF

