/************************************/
/* ログイン画面用入力補助JavaScript */
/************************************/

/**********************************/
/* 指定フィールドへフォーカス設定 */
/**********************************/
function focusField( fld )
{
    fld.focus();
    fld.select();
}

/********************************/
/* 次フィールドへフォーカス移動 */
/********************************/
function nextFocus( curValue, nextField, colLen )
{
    var inputLen=0;

    inputLen = curValue.length;

    if( inputLen >= colLen ){
        nextField.focus();
        nextField.select();
    }
}

/********************************/
/* 次フィールドへフォーカス移動 */
/********************************/
function nextFocus2( curValue, nextField, colLen )
{
    var inputLen=0;

    inputLen = curValue.length;

    if( inputLen >= colLen ){
        nextField.focus();
    }
}

/********************************/
/* 初期フィールドへフォーカス移動 */
/********************************/
function onFocus() 
{
	
	if (document.LoginFormPc) {
		document.LoginFormPc.cardNo1.value = '';
		document.LoginFormPc.cardNo2.value = '';
		document.LoginFormPc.cardNo3.value = '';
		document.LoginFormPc.cardNo4.value = '';
		document.LoginFormPc.pssswrd.value = '';
		document.LoginFormPc.birthYyyy.value = '';
		document.LoginFormPc.birthMm.value = '';
		document.LoginFormPc.birthDd.value = '';
		document.LoginFormPc.birthGengo.value = '';
		focusField(document.LoginFormPc.cardNo1);
	} else {
		document.LoginFormPcNetId.netId.value = '';
		document.LoginFormPcNetId.pssswrd.value = '';
		focusField(document.LoginFormPcNetId.netId);
		//サファリ対応
		document.LoginSelectForm.gcd.value='4'
	}
}

/***********************************************/
/* パスワードフィールドバックスペース (暗証番号用)*/
/***********************************************/
function backSpace(form)
{
    var val = form.pssswrd.value;
    len = val.length;
    if (len > 0) {
    	form.pssswrd.value = "";
    }
	form.pssswrd.focus();
}

/***********************************************/
/* パスワードフィールドバックスペース(生年月日用) */
/***********************************************/
function backSpace2(form)
{
    var val1 = form.birthYyyy.value;
    len = val1.length;
    if (len > 0) {
    	form.birthYyyy.value = "";
    }
    var val2 = form.birthMm.value;
    len = val2.length;
    if (len > 0) {
    	form.birthMm.value = "";
    }
    var val3 = form.birthDd.value;
    len = val3.length;
    if (len > 0) {
    	form.birthDd.value = "";
    }
    
    if (form.birthGengo.value != "" || form.birthGengo.selectedIndex != 0) {
    	form.birthGengo.selectedIndex = 0;
    }
    form.birthGengo.focus();
}

/**********************************/
/* 新しいウィンドウを開いてログイン */
/* カード番号・暗証番号入力値を消去する（Login.html用） */
/**********************************/
var paramList;
/*
//ログイン強化に伴い使用停止
function openMainWindow() {

	// スクリーンのサイズを取得
	var scrX = screen.availWidth;
	var scrY = screen.availHeight;

	// メインウィンドウのオプション
	var option = 'width='+scrX+',height='+scrY
			+',toolbar=yes,menubar=yes,location=yes,directories=yes'
			+',status=yes,resizable=yes,scrollbars=yes,top=0,left=0';

	// メインウィンドウのオープン
	var win = window.open('','subwin',option);

	// 入力項目のHTMLオブジェクトを格納
	paramList = new Array();
	for (i = 1; i < openMainWindow.arguments.length; i++) {
		paramList[i - 1] = openMainWindow.arguments[i];
	}
	
	// お待ちください画面の描画
	writeLoginWait(win);
	
	win.focus();
}
*/
/**********************************/
/* ログイン中画面の描画 */
/* ログイン中の旨の文言を表示し、
/* ログインのリクエストを呼び出す */
/**********************************/
/*
//ログイン強化に伴い使用停止
function writeLoginWait() {
	
	var win = writeLoginWait.arguments[0];

	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>ログインしています...</title>');
	win.document.writeln('<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> ');
	win.document.writeln('<script language="javascript">');
	win.document.writeln('<!--');
	win.document.writeln('function login() {');
	win.document.writeln('var c1 = opener.paramList[0]');
	win.document.writeln('var c2 = opener.paramList[1];');
	win.document.writeln('var c3 = opener.paramList[2];');
	win.document.writeln('var c4 = opener.paramList[3];');
	win.document.writeln('var pw = opener.paramList[4];');

	win.document.writeln('document.form.cardNo1.value = c1.value;');
	win.document.writeln('document.form.cardNo2.value = c2.value;');
	win.document.writeln('document.form.cardNo3.value = c3.value;');
	win.document.writeln('document.form.cardNo4.value = c4.value;');
	win.document.writeln('document.form.pssswrd.value = pw.value;');
	win.document.writeln('document.form.ckFlg.value = navigator.cookieEnabled;');

	win.document.writeln('c1.value = \'\';');
	win.document.writeln('c2.value = \'\';');
	win.document.writeln('c3.value = \'\';');
	win.document.writeln('c4.value = \'\';');
	win.document.writeln('pw.value = \'\';');

	win.document.writeln('document.form.submit();');
	win.document.writeln('}');
	win.document.writeln('//-->');
	win.document.writeln('</script>');
	win.document.writeln('</head>');

	win.document.writeln('<body bgcolor="#ffffff" onLoad="login();">');

	win.document.writeln('ログイン中です。<br>');
	win.document.writeln('しばらくお待ちください。<br>');

	win.document.writeln('<form action="https://credit.orix.co.jp/NASApp/eplanet/do/LoginPc" name="form" method="POST">');	

	win.document.writeln('<input type="hidden" name="cardNo1" value="">');
	win.document.writeln('<input type="hidden" name="cardNo2" value="">');
	win.document.writeln('<input type="hidden" name="cardNo3" value="">');
	win.document.writeln('<input type="hidden" name="cardNo4" value="">');
	win.document.writeln('<input type="hidden" name="pssswrd" value="">');
	win.document.writeln('<input type="hidden" name="ckFlg" value="">');

	win.document.writeln('</form>');

	win.document.writeln('</body>');
	win.document.writeln('</html>');

	win.document.close();
}
*/
/**********************************/
/* 新しいウィンドウを開いてログイン */
/* ログイン画面を表示する */
/**********************************/
function openMainWindow02(pattern) {
/*
    //2010/12/2 ポップアップ画面表示の改修に伴い
    //window.openメソッドのオプション指定を削除

	// スクリーンのサイズを取得
	var scrX = screen.availWidth;
	var scrY = screen.availHeight;

	// メインウィンドウのオプション
	var option = 'width='+scrX+',height='+scrY
			+',toolbar=0,menubar=yes,location=0,directories=yes'
			+',status=yes,resizable=1,scrollbars=1,top=0,left=0';

	// メインウィンドウのオープン
	var win = window.open('','subwin',option);
*/
	var win = window.open('','subwin');

	// パラメータを格納
	document.form1.gcd.value = pattern;
	// hiddenの入力項目ckFlgにクッキー利用可否の判定結果を格納
	setCkFlg(document.form1);
	
	// ウィンドウを描画
	writeLoginWindow(win);
	
	win.focus();
}

/**********************************/
/* ログイン画面の描画 */
/* ログインのリクエストを呼び出す */
/**********************************/
function writeLoginWindow() {

	var win = writeLoginWindow.arguments[0];
	var svId = document.form1.svId.value;
	var gcd = document.form1.gcd.value
	var ckFlg = document.form1.ckFlg.value

	//アクション名を切り分ける
	if (svId == 2) 
	{
		var actionName = "LoginSelectRab"
	}
	else
	{
		var actionName = "LoginSelect"
	}

	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>ログイン</title>');
	win.document.writeln('<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> ');
	win.document.writeln('<script language="javascript">');
	win.document.writeln('<!--');
	win.document.writeln('function login() {');

	win.document.writeln('document.form.gcd.value = ' + gcd + ';');
	//win.document.writeln('document.form.gcd.value = opener.document.form1.gcd.value;');
	win.document.writeln('document.form.ckFlg.value = ' + ckFlg + ';');
	//win.document.writeln('document.form.ckFlg.value = opener.document.form1.ckFlg.value;');
	//win.document.writeln('document.form.ckFlg.value = navigator.cookieEnabled;');
	//win.document.writeln('document.form.svId.value = ' + svId + ';');
	//win.document.writeln('document.form.svId.value = opener.document.form1.svId.value;');

	win.document.writeln('document.form.submit();');
	win.document.writeln('}');
	win.document.writeln('//-->');
	win.document.writeln('</script>');
	win.document.writeln('</head>');

	win.document.writeln('<body bgcolor="#ffffff" onLoad="login();">');
	win.document.writeln('<form action="https://credit.orix.co.jp/NASApp/eplanet/do/' + actionName + '" name="form" method="POST">');
	//win.document.writeln('<form action="/NASApp/eplanet/do/LoginSelect" name="form" method="POST">');	
	win.document.writeln('<input type="hidden" name="gcd" value="">');
	win.document.writeln('<input type="hidden" name="ckFlg" value="">');
	win.document.writeln('<input type="hidden" name="svId" value="">');

	win.document.writeln('</form>');

	win.document.writeln('</body>');
	win.document.writeln('</html>');

	win.document.close();
}

/**********************************/
/* ログインのリクエストを呼び出す */
/* 多重送信防止 */
/**********************************/
var fExec = false;
function execLogin(form) {
	
    if(fExec == true){
        return false;    // ２回目以降は処理を行わない
    }
    fExec = true;
    form.submit();
    return false;
}

/**********************************************/
/* ブラウザのCookieオン・オフの判定フラグの取得 */
/**********************************************/
function setCkFlg(formObj) {

	tmp = "cookiecheck="+escape('true')+"; ";
	document.cookie = tmp;
	cookiecheck = getCookie("cookiecheck");

	tmp = "cookiecheck="+escape('')+"; ";
	document.cookie = tmp;

	if ( cookiecheck == "true" )
	{
		formObj.ckFlg.value="true";
	}
	else	
	{
		formObj.ckFlg.value="false";
	 }
}

/**********************************/
/*クッキー利用可能かどうかの判断 */
/**********************************/
function getCookie( key )
{
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) 
	{
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);

		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) 
		{
			return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return("");
}

/**********************************/
/*VIP・CLUB識別コードエラー時の   */
/*リンク先を制御                  */
/**********************************/
function ctrlWin(openUrl)
{
/*
    //2010/12/2 ポップアップ画面表示の改修に伴い
    //window.openメソッドのオプション指定を削除

	// スクリーンのサイズを取得
	var scrX = screen.availWidth;
	var scrY = screen.availHeight;

	// メインウィンドウのオプション
	var option = 'width='+scrX+',height='+scrY
			+',toolbar=0,menubar=yes,location=0,directories=yes'
			+',status=yes,resizable=yes,scrollbars=yes,top=0,left=0';

	// トップ画面(VIPもしくはCLUB)を開く
	window.open(openUrl,"",option);
*/
	window.open(openUrl,"");
	window.self.close();
}


