//####################################################################################
// kokoro.js 
//             Ver1.0  08/14/02
//             こころしなやかに用JavaScriptファイル
//             (c)2002 MediaCube Ltd. Allrights reserved.
//####################################################################################
var COOKIE = "kokoro-v10_point";
//-------------------------------------------------------------------------------
// Cookieを削除する関数
//-------------------------------------------------------------------------------
function delCookie(){
	var today = new Date();
	var gy = today.getFullYear();
	var gm = today.getMonth();
	var gd = today.getDate();
	var hs = today.getHours();
	var ms = today.getMinutes();
	var sc = today.getSeconds();
	TIME = gy + gm + gd + hs + ms + sc;
	var GET = document.cookie;
	GET = GET.split("[");
	document.cookie = GET[0] + ";expires=" + TIME.toGMTString;
}


//-------------------------------------------------------------------------------
// Cookieをセットする関数
//-------------------------------------------------------------------------------
function setCookie(value)
{
	delCookie();
	document.cookie = COOKIE + "=" + escape(value);
	return true;
}

//-------------------------------------------------------------------------------
// Cookieをセットする関数
//-------------------------------------------------------------------------------
function setCookie2(cname, value)
{
	document.cookie = cname + "=" + escape(value);
	return true;
}

//-------------------------------------------------------------------------------
// 引数nameで指定した文字の値を返す関数
//-------------------------------------------------------------------------------
function getCookie(name)	{
    var cookieStr = document.cookie
    var existNum = cookieStr.indexOf(name)
    if (existNum != -1) {
        var start = existNum + name.length + 1;
        var end = cookieStr.indexOf(";" , start);
        if(end == -1) {
            end = cookieStr.length;
        }
        var cookieValue = unescape(cookieStr.substring(start,end));
        return cookieValue;
    } else {
        return "";
    }
}


//-------------------------------------------------------------------------------
// Cookieの値を返す関数
//-------------------------------------------------------------------------------
function checkCookie()	{
	return getCookie(COOKIE);
}


//-------------------------------------------------------------------------------
// Cookieに値を追加するための関数
//-------------------------------------------------------------------------------
function addCookie(value) {
    var cookieStr = getCookie(COOKIE);
	cookieStr = cookieStr.replace(value, "");
	setCookie(cookieStr + value);
    return true;
}


//-------------------------------------------------------------------------------
// 評価ウィンドウを開く関数
//-------------------------------------------------------------------------------
function openWnd(n) {
	var cookieStr = getCookie(COOKIE);
	if (n == "A") {	point = getPointA(cookieStr);
	} else { point = getPointB(cookieStr); }
	
	var wnd = window;
	var url =HYOUKA_FILE;
	if (parseInt(point) == 99) { url = ERROR_FILE; }
	
	var point;
	if ((wnd == window) || w.closed) {
		wnd = open(url, "_self");
	} else {
		wnd.focus();
	}
	return true;
}


//-------------------------------------------------------------------------------
// 久里浜式アルコール依存症スクリーニングテストの判定コメントを返す関数
//-------------------------------------------------------------------------------
function getCommentA(point) {
	var comment = "";
	if (point <= -5) {
		comment = "まったく正常（正常飲酒群）";
	} else if ((point > -5) && (point < 0)) {
		comment = "まあまあ正常（問題飲酒予備群）";
	} else if ((point >= 0) && (point < 2)) {
		comment = "問題あり（問題飲酒群）";
	} else if (point >= 2) {
		comment = "きわめて問題多い（重篤問題飲酒群）";
	}
	return comment;
}


//-------------------------------------------------------------------------------
// 刺激に対する感受性チェックの判定コメントを返す関数
//-------------------------------------------------------------------------------
function getCommentK(point) {
	var comment = "";
	if (point <= 24) {
		comment = "感受性は低く、鈍感なようです。ある程度の感度がないと物事への対処に不都合になるし、上司や仲間から「ニブイ」とか「カタイ」とか思われてしまうことになります。";
	} else if ((point >= 25) && (point <= 39)) {
		comment = "高くもなく、低くもない感受性です。からだに抵抗力があれば病気にはかかりにくいタイプです。";
	} else if ((point >= 40) && (point <= 54)) {
		comment = "敏感な感覚、情緒を持ち合わせています。ちょっと間違うと危険な領域に踏み込みかねませんから、こころをしなやかにする訓練をしたほうがよいでしょう。";
	} else if (point >= 55) {
		comment = "刺激に敏感です。こころの状態がもろくなっている可能性があります。場合によっては専門家に相談したほうがよいことがあります。";
	}
	return comment;
}


//-------------------------------------------------------------------------------
// 得点計算関数
//-------------------------------------------------------------------------------
function getPoint(frmObj, prefix, objsize) {
	point = 0;
	for (i = 0; i < objsize; i++) {
		var se = prefix + parseInt(i + 1);
		var check = 0;
		for (j = 0; j < frmObj [se].length; j++) {
			if (frmObj [se][j].checked) {
				d = (parseInt(point)) + (parseInt(frmObj [se][j].value));
				point = d;
				check = 1;
			}
		}
		if (check == 0) {
			alert(parseInt(i + 1) + "番目の質問にお答えください");
			return -100;
		}
	}
	return point;
}

