/* ----------------------------------------------------------------------------
 Japaneseform.com無料会員に関するクッキーについてのプロシージャ
---------------------------------------------------------------------------- */

/* *****************************************************************************
	関数名：	GetLoginMail
	機能：		無料会員ページにログインしているメールアドレスを返します
	引数：		
	戻値：		メールアドレス
***************************************************************************** */
function GetLoginMail(){
	email=ReqCookie("JF");
//alert(email);
	return(email);
}

/* *****************************************************************************
	関数名：	ReqCookies
	機能：		クッキーの値を取得します
	引数：		cName		クッキーの名前
	戻値：		クッキーの値
***************************************************************************** */
function ReqCookie(cName){
	tmp=document.cookie+";";

	tmp1=tmp.indexOf(cName,0);
//	alert(tmp1);
	if(tmp1!=-1){
		tmp=tmp.substring(tmp1,tmp.length);
		start=tmp.indexOf("=",0)+1;
		end=tmp.indexOf(";",start);
		return(unescape(tmp.substring(start,end)));
	}
	return("");
}

/* *****************************************************************************
	関数名：	CheckLoginFree
	機能：		無料会員ページにログインしていない場合ログインページへとばす
	引数：		reURL	ログイン後に表示するURL（相対パス可）
	戻値：		なし
***************************************************************************** */
function CheckLoginFree(reURL){
	email=GetLoginMail();
	if (email==""){
		window.location.replace("../login/login.asp?dir=" + reURL) 
	}
}

/* *****************************************************************************
	関数名：	LogoutFree
	機能：		無料会員ページからログアウト（クッキーを削除）
	引数：		
	戻値：		なし
***************************************************************************** */
function LogoutFree(){
	DeleteLogin("JF");
	LogoutNavi();
}	

/* *****************************************************************************
	関数名：	DeleteLogin
	機能：		指定のクッキーを削除します
	引数：		cName		クッキーの名前
	戻値：		なし
***************************************************************************** */
function DeleteLogin(cName){
  dTime = new Date();
  dTime.setYear(dTime.getYear() - 1);
  document.cookie = cName + "=;expires=" + dTime.toGMTString();

}	

/* *****************************************************************************
	関数名：	WithdrawFree
	機能：		退会（クッキーを削除）
	引数：		なし
	戻値：		なし
***************************************************************************** */
function WithdrawFree(){
  DeleteLogin("JF");
}	

/* *****************************************************************************
	関数名：	LogoutNavi
	機能：		ログアウト後に表示するページの設定
	引数：		なし
	戻値：		なし
***************************************************************************** */
function LogoutNavi() {
  strQ = window.location.search;
  intQ = strQ.indexOf("query=",0);


	if(window.location.pathname.indexOf("jp",0) > 0) {
		lan = "jp";
	}else{
		lan = "en";
	}

	if (strQ == "" || strQ == "?"){
		if (lan == "jp"){
		window.location.replace("../../index_j.htm") ;		
		}else{
		window.location.replace("../../index.htm") ;		
		}
		return;
	}else{
		if (intQ == -1){
			strDir = strQ.replace("?dir=","");
			window.location.replace(strDir);
			return;
		}else{
			strDir = strQ.substr(0,intQ-1);
			strDir = strDir.replace("?dir=","");

			if (strDir == "") {
				if (lan == "jp"){
				window.location.replace("../../index_j.htm") ;		
				}else{
				window.location.replace("../../index.htm") ;		
				}
				return;
			}

			strQer = strQ.replace("?dir=","");
			strQer = strQer.replace(strDir,"");
			strQer = strQer.replace("&query=","");
			window.location.replace(strDir + "?" + strQer);
			return;
		}
	}
	if (lan == "jp"){
	window.location.replace("../../index_j.htm") ;		
	}else{
	window.location.replace("../../index.htm") ;		
	}

}