//------------------------------------------------------------------------------
// setCookie
//------------------------------------------------------------------------------
// 2005.09.15 MOD tanaka
//function setCookie(theName,theValue,theDay)
//function setCookie(theName,theValue,theDay,thePath)
function setCookie(theName,theValue,theDay,thePath,theDomain,theSecure)
{
	if ((theName != null) && (theValue != null))
	{
//		expDay = "Wed, 01 Jan 2020 18:56:35 GMT";	//　指定されない場合とりあえず2020年
/*		if (theDay != null) {
			theDay = eval(theDay);	//　文字列の場合でも数値にする（念のため）
			setDay = new Date();
			setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24));
			expDay = setDay.toGMTString();

// 2005.09.15 MOD tanaka	Begin
//			document.cookie = theName + "=" + escape(theValue) + ";expires=" + expDay;
			if (thePath != null) {
				document.cookie = theName + "=" + escape(theValue) + ";expires=" + expDay + ";path=" + escape(thePath);
			}else{
				document.cookie = theName + "=" + escape(theValue) + ";expires=" + expDay;
			}
// 2005.09.15 MOD tanaka	End
		}else{
// 2005.09.15 MOD tanaka	Begin
//			document.cookie = theName + "=" + escape(theValue);
			if (thePath != null) {
				document.cookie = theName + "=" + escape(theValue) + ";path=" + escape(thePath);
			}else{
				document.cookie = theName + "=" + escape(theValue);
			}
// 2005.09.15 MOD tanaka	End
		}
*/
		str = theName + "=" + escape(theValue);
		
//		if (theDay) {
		if (theDay != null) {
			theDay = eval(theDay);	//　文字列の場合でも数値にする（念のため）
//			setDay = new Date();
//			setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24));
			var nowtime = new Date().getTime();
			setDay = new Date(nowtime + (60 * 60 * 24 * 1000 * theDay));
			expDay = setDay.toGMTString();
			str += "; expires=" + expDay;
		}
//		if (thePath) {
		if (thePath != null) {
			if (thePath == 1) thePath = location.pathname;
			str += "; path=" + thePath;
		}
//		if (theDomain) {
		if (theDomain != null) {
//			if (theDomain == 1) theDomain = location.hostname.replace(/^[^\.]*/, "");
			if (theDomain == 1) theDomain = CW_SRCHP.replace(/^[^\.]*/, "");
			str += "; domain=" + theDomain;
		}
//		if (theSecure && location.protocol == "https:") {
		if ((theSecure != null) && location.protocol == "https:") {
			str += "; secure";
		}
		
		document.cookie = str;

		return true;
	}
	return false;
}

//------------------------------------------------------------------------------
// deleteCookie
//------------------------------------------------------------------------------
function deleteCookie(theName)
{
	document.cookie = theName + "=;expires=Thu,01-Jan-70 00:00:01 GMT";
	return true;
}

//------------------------------------------------------------------------------
// getCookie
//------------------------------------------------------------------------------
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;
}


//------------------------------------------------------------------------------
// refer_Cookie   -一般サイト-
//------------------------------------------------------------------------------
function refer_Cookie()
{
	if (window.navigator.cookieEnabled) {
//		document.write("クッキーは利用できます。");	// クッキーの受け入れが有効時の処理
	}
	else{
		document.write("クッキーは利用できません。");	// クッキーの受け入れが無効時の処理
	}
	if (!navigator.cookieEnabled) {
		document.write("ブラウザの設定にてクッキーの受け入れを有効にしてください。");
	}


	CK_name  = "CW_HTTP_REFER";
	CK_name01  = "CW_ACS_URL";

	//referrerの綴りに注意してください。Javascriptでは「r」を重ねます。
	if (escape(document.referrer) != "") {
		CK_Value = unescape(document.referrer);
		CK_Value = escape(CK_Value);
	}else{
// 2004.09.13 MOD tanaka
//		CK_Value = "ブックマーク/メールソフト";
		CK_Value = "bookmark/mailsoft";
//		CK_Value = escape(CK_Value);
	}
	CK_Value01 = escape(document.URL);

	CK_Value2 = getCookie(CK_name);

//	if ((! CK_Value2) || (CK_Value.indexOf(CW_SRCHP,0) == -1)) {
	if ((! CK_Value2) || ((CK_Value.indexOf(CW_SRCHP,0) == -1) && (CK_Value2.indexOf(CW_SRCHP,0) != -1) && (CK_Value != CK_Value2))) {
		CK_exp   = null;					//有効期限の日数
// 2005.09.15 MOD tanaka	Begin
//		setCookie(CK_name, CK_Value, CK_exp);
//		setCookie(CK_name01, CK_Value01, CK_exp);

		CK_path = "/";						//発行したサーバ	(setting 2007.08.16 tanaka)
//		CK_path = location.pathname;		//発行したページ=1
//		CK_path = null;						//発行したカレントディレクトリ
		//if (CK_Value01.indexOf("shopmall/mentaitsu",0) == -1) CK_path = null;
		////if(typeof(CW_PATH) != "undefined") {		// CW_PATHが定義済か否か判断
		////	CK_path = CW_PATH;
		////}else{
		////	CK_path = null;
		////}
//		CK_domain = location.hostname;		//発行したサーバドメイン=1
		CK_domain = null;					//参照可能なドメイン
		CK_secure = null;					//セキュアフラグ（SSL 通信時のみ指定可） 

//		setCookie(CK_name, CK_Value, CK_exp, CK_path);
//		setCookie(CK_name01, CK_Value01, CK_exp, CK_path);
		setCookie(CK_name, CK_Value, CK_exp, CK_path, CK_domain, CK_secure);
		setCookie(CK_name01, CK_Value01, CK_exp, CK_path, CK_domain, CK_secure);
// 2005.09.15 MOD tanaka	End
	}else{
		CK_Value = CK_Value2;
	}
	return CK_Value;
}

//------------------------------------------------------------------------------
// refer_Cookie_2   -管理サイト-
//------------------------------------------------------------------------------
function refer_Cookie_2()
{
	if (window.navigator.cookieEnabled) {
//		document.write("クッキーは利用できます。");	// クッキーの受け入れが有効時の処理
	}
	else{
		document.write("クッキーは利用できません。");	// クッキーの受け入れが無効時の処理
	}
	if (!navigator.cookieEnabled) {
		document.write("ブラウザの設定にてクッキーの受け入れを有効にしてください。");
	}


	CK_name  = "CW_HTTP_REFER_2";
	CK_name01  = "CW_ACS_URL_2";

	//referrerの綴りに注意してください。Javascriptでは「r」を重ねます。
	if (escape(document.referrer) != "") {
		CK_Value = unescape(document.referrer);
		CK_Value = escape(CK_Value);
	}else{
// 2004.09.13 MOD tanaka
//		CK_Value = "ブックマーク/メールソフト";
		CK_Value = "bookmark/mailsoft";
//		CK_Value = escape(CK_Value);
	}
	CK_Value01 = escape(document.URL);

	CK_Value2 = getCookie(CK_name);

//	if ((! CK_Value2) || (CK_Value.indexOf(CW_SRCHP,0) == -1)) {
	if ((! CK_Value2) || ((CK_Value.indexOf(CW_SRCHP,0) == -1) && (CK_Value2.indexOf(CW_SRCHP,0) != -1) && (CK_Value != CK_Value2))) {
		CK_exp   = null;					//有効期限の日数
// 2005.09.15 MOD tanaka	Begin
//		setCookie(CK_name, CK_Value, CK_exp);
//		setCookie(CK_name01, CK_Value01, CK_exp);

//		CK_path = "/";						//発行したサーバ
//		CK_path = location.pathname;		//発行したページ=1
		CK_path = null;						//発行したカレントディレクトリ
		//if (CK_Value01.indexOf("shopmall/mentaitsu",0) == -1) CK_path = null;
		////if(typeof(CW_PATH) != "undefined") {		// CW_PATHが定義済か否か判断
		////	CK_path = CW_PATH;
		////}else{
		////	CK_path = null;
		////}
//		CK_domain = location.hostname;		//発行したサーバドメイン=1
		CK_domain = null;					//参照可能なドメイン
		CK_secure = null;					//セキュアフラグ（SSL 通信時のみ指定可） 

//		setCookie(CK_name, CK_Value, CK_exp, CK_path);
//		setCookie(CK_name01, CK_Value01, CK_exp, CK_path);
		setCookie(CK_name, CK_Value, CK_exp, CK_path, CK_domain, CK_secure);
		setCookie(CK_name01, CK_Value01, CK_exp, CK_path, CK_domain, CK_secure);
// 2005.09.15 MOD tanaka	End
	}else{
		CK_Value = CK_Value2;
	}
	return CK_Value;
}


//------------------------------------------------------------------------------
// Main
//------------------------------------------------------------------------------
	CW_SRCHP = location.hostname;
	CW_SRCHP_P_MNT = "manage";
//	CW_SRCHP_P_MNT = "mana_";

//	CK_Value = refer_Cookie();

	CK_path22 = location.pathname;		//発行するページ
	if (CK_path22.indexOf(CW_SRCHP_P_MNT,0) != -1) {		//管理サイト
		CK_Value = refer_Cookie_2();
	}else{
		CK_Value = refer_Cookie();
	}
//------------------------------------------------------------------------------

