//-------------------------------------------------------------------------------
// ページタイトル取得
// 「 -」より以前の文字のみ取得します
//-------------------------------------------------------------------------------
function setPageTitle(d){

	num = d.indexOf(" -", 0);

	if(num == -1){
		ret = d;
	}else{
		ret = d.substr(0,num);
	}
	
	return ret;
}

//-------------------------------------------------------------------------------
// アクセスログCookieのセットとCGIの呼び出し
// usr:		ユーザー名（ディレクトリに使用）
// pageName:ページ名称
//-------------------------------------------------------------------------------
function setLog(usr,pageName)
{
		// strCData:ログ書き込みの制御用（24時間保存）
		// strCCnt:	何度目の来訪か？（365日保存）
		strCData = usr+"_data";
		strCCnt  = usr+"_count";

		//===============================
		// Cookieデータ値取得
		
		// 合ったらログ書き込まない
		cdata = getCookie(strCData);
		
		// 起算カウント
		accnt = getCookie(strCCnt);
		
		accnt = new Number(accnt);
		

		// 初めて訪れる場合は0を代入
		if(accnt == null || accnt == false ){ accnt = 0; }

		//===============================
		// ログ書込み＆Cookie設定
		if(cdata == null || cdata == false){
			

			// CGIにてログ書込み
//			document.write("<img src='http://www.neothink.ne.jp/ys/aclog/aclog.cgi?"+usr+",;,"+pageName+","+accnt+","+document.referrer.replace(/,/g, " ")+","+b_furiwake(window.innerHeight+'x'+window.innerWidth,document.body.clientHeight+'x'+document.body.clientWidth)+"' width=0 height=0/>");

			kanma = "&#44;";

			document.write("<img src='http://www.neothink.ne.jp/ys/aclog/aclog.cgi?"+usr+",;,"+pageName+","+accnt+","+document.referrer.replace(/,/g,kanma)+","+b_furiwake(window.innerHeight+'x'+window.innerWidth,document.body.clientHeight+'x'+document.body.clientWidth)+"' width=0 height=0/>");


			// 1日間保存
			ret = setCookie(strCData,"IN",1);

			// 起算値＋１（365日保存）
			ret = setCookie(strCCnt,accnt+1,365);
		}


}

//-------------------------------------------------------------------------------
// ブラウザ振分け
//-------------------------------------------------------------------------------
function b_furiwake(n,m){
	b = navigator.appName.charAt(0);
	if (b == "M") {
		return m;
	} 
	return n;
}


//-------------------------------------------------------------------------------
//　一時的にCookieを使用するための関数
//　成功した時はtrue,失敗した時はfalseを返す
//-------------------------------------------------------------------------------
function tempCookie(theName__,theValue__)
{
	if ((theNmae != null) && (theValue__ != null))
	{
		document.cookie = theName__ + "="+theValue__;
		return true;
	}
	return false;
}

//　Cookieにデータを保存する
//　成功した時はtrue,失敗した時はfalseを返す
function setCookie(theName__,theValue__,theDay__)
{
	if ((theName__ != null) && (theValue__ != null))
	{
	
		var expDay__ = "Wed, 01 Jan 2020 18:56:35 GMT";	//　指定されない場合とりあえず2020年
		if (theDay__ != null)
		{
			theDay__ = eval(theDay__);	//　文字列の場合でも数値にする（念のため）
			var setDay = new Date();
			setDay.setTime(setDay.getTime()+(theDay__*1000*60*60*24));
			expDay__ = setDay.toGMTString();
		}
		document.cookie = theName__ + "="+escape(theValue__)+";expires="+expDay__;
		return true;
	}
	return false;
}

//-------------------------------------------------------------------------------
//　Cookieのデータを削除する（即座にファイルから消える訳じゃありません）
//　常にtrueを返す
//-------------------------------------------------------------------------------
function deleteCookie(theName__)
{
	document.cookie = theName__ + "=;expires=Thu,01-Jan-70 00:00:01 GMT";
	return true;
}

//-------------------------------------------------------------------------------
//　Cookieから指定されたデータを抜きだす
//　成功した時はnull以外,失敗した時はfalseを返す
//-------------------------------------------------------------------------------
function getCookie(theName__)
{
	theName__ += "=";	//　=を追加して検索の手抜きをする

	theCookie__ = document.cookie+";";	//　検索時最終項目で-1になるのを防ぐ

	start__ = theCookie__.indexOf(theName__);	//　指定された名前を検索する

	if (start__ != -1)
	{
		end__ = theCookie__.indexOf(";",start__);
		return unescape(theCookie__.substring(start__+theName__.length,end__));
	}

	return false;
}


