//20080123 新Cookie処理追加
/////////////////////////////
// クッキー削除
/////////////////////////////
function checkDel(){
  // クッキー保存する場合(チェックされている)
  if(!document.form.save.checked){
    // クッキーがある場合
    if(document.cookie != ""){
      exp = new Date();     //cookieに現在日付のDateを作成する
      exp.setFullYear(exp.getYear()-1);  //1年前の日付に変更
      document.cookie="Bird-research_User=;expires="+exp.toGMTString();
    }
    document.form.user_id.value ="";
    document.form.password.value ="";
  }
}
/////////////////////////////
// クッキーの取得
/////////////////////////////
function getCookie(){
	ckary = document.cookie.split(";");
	domain = "Bird-research_User";
	const_on = "ON";
	on_off = "OFF";
	userary = new Array();

    //クッキーを取得し旧処理で発行されたクッキーの判別処理
	for( i = 0; i < ckary.length; i++ )	{
		infary = ckary[i].split("=");
		//旧処理された %00 の抜き出し
		if ( infary[0] == domain ){
			if ( infary[1].indexOf("%00") >= 0 ){
				userary = infary[1].split("%00");
				// forループから抜ける
				break;
			//新処理された内容のデコード処理
			}else{
				tempary = infary[1].split("@");

				userary[0] = decodeString(tempary[0]);
				userary[1] = decodeString(tempary[1]);
				userary[2] = tempary[2];
				// forループから抜ける
				break;
			}

		}
	}
	// 有効期限を求める
	exp = new Date();

	if ( userary.length > 2 && userary[userary.length-1] == const_on ){
		// useraryをデコードしてフォームに表示

		// ユーザ名の表示
		document.forms[0].user_id.value =userary[0];

		// パスワードの表示
		document.forms[0].password.value =userary[1];

		// チェックボックスの表示
		document.forms[0].save.checked = true;

		//次回までのクッキー有効期限の発行
		exp.setTime( exp.getTime() + 1000 * 60 * 60 * 24 * 120 );

		// ON/OFFの設定
		on_off = const_on;
	// OFF の場合
	}else{
		// 有効期限を1年前に設定
		exp.setFullYear( exp.getYear() - 1 );
	}

	// useraryからクッキーを作成path=/
	//path = ";path=/";
	newcookie = domain + "=" + userary[0] + "@" + userary[1] + "@" + on_off + ";expires=" + exp.toGMTString();

}

/////////////////////////////
// 文字列のエンコード
/////////////////////////////
function encodeString(str){
	// ユーザー　パスワードの暗号化処理
	elem = "";
	for (i=0; i< str.length; i++){
		elem += str.charCodeAt(i)+",";
	}
	// 変換後の文字列を返す
	return elem.substr(0, elem.length -1 );
}

function setCookie(obj){
	domain = "Bird-research_User";
	exp = new Date();

	if(obj.checked){
		// cookieの有効期限を求める
		exp.setTime(exp.getTime()+1000*60*60*24*120);
		//cookie作成
		document.cookie = domain + "="
				+ encodeString(document.forms[0].user_id.value) + "@"
				+ encodeString(document.forms[0].password.value) + "@ON"
				+ ";expires=" + exp.toGMTString();

	}else{
		// cookieの有効期限を1年前に設定
		exp.setFullYear(exp.getYear()-1);
		// cookieを作成
		document.cookie = domain + "=;expires=" + exp.toGMTString();

	}
}
/////////////////////////////
// 文字列のデコード
/////////////////////////////
function decodeString(str){
	// 変換文字列の初期化
	elem = "";

	// 変換前文字列を","で分割
	stary0 = str.split(",");

	// 文字コードから文字に変換
	for (i = 0; i < stary0.length; i++){
		// 変換した文字を文字列に追加
		elem += String.fromCharCode( stary0[i] );
	}

	// 変換した文字列を返す
	return elem;
}