
//サブミットボタンの二重クリックをチェック用変数
var cJS_OnSubmitCHK=0;

/* 
関数一覧

《総合》
gJS_AllErrChk(CheckForm,inText,Title,Type,MaxLength,NullFlag)	入力された文字列の総合チェックを行う


《汎用》
gJS_NullChk(inText)	入力された情報がＮｕｌｌのみかチェックする
gJS_StrConv(inText)	入力された情報の文字数を返す
gJS_InLen(inText)		入力された情報に制御文字がないかチェックする
gJS_isDate(inText)		入力された情報が日付型として正しいかチェックする
gJS_isNumeric(inTYPE,inText)	入力された文字が数字のみかチェックする
gJS_dateSB(InText_A,InText_B)	入力された日付の「A<B」をチェックする

gJS_HrefUrlEXchange(inURL,inParam)	入力された文字列に意味を持たないランダム数を付加して返す
gJS_GetRandumMakeForDat()		日付からランダム文字列を作成する

《個別》
gJS_DblSubmitChk()		サブミットボタンの二重クリックをチェックする

****************************************************************************
[関数名] gJS_AllErrChk
[概要]
入力された文字列の総合チェックを行う
PmpackC用関数として作成。V2でWssでも使用

[引数]
CheckForm：フォームオブジェクト
inText：チェック対象
Title：エラー表示メッセージのタイトル
Type：文字型
	[ATH01]：空白許可の文字型

MaxLength：最大文字数
NullFlag：必須チェック		「1：必須」「0：チェック無し」

[返り値]:---

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
=============================================================================*/
function gJS_AllErrChk(CheckForm,inText,Title,Type,MaxLength,NullFlag)
{
	var msg = '';
	var check_id = new Array('\\','\'',',','"','&','%','?','-',' ') ;

	if( NullFlag == 1 )
	{
		if( Type == 'ATH01') {
			if( inText == '' ) {
				mes = Title + 'を入力してください。';
				alert(mes);
				CheckForm.focus();
				return false;
			}
		} else {
			if( gJS_NullChk(inText) ) {
				mes = Title + 'を入力してください。';
				alert(mes);
				CheckForm.focus();
				return false;
			}
		}
	}

	if( MaxLength != 0 )
	{
		if( gJS_StrConv(inText) > MaxLength )
		{
			mes = Title + 'は ' + MaxLength + ' バイト以内で入力して下さい。';
			alert(mes);
			CheckForm.focus();
			return false;
		}
	}

	if( Type == 'INT' || Type == 'FLOAT') {
		if( gJS_isNumeric(Type,inText) == false ) {
			mes = Title + 'には数字を入力して下さい。';
			alert(mes);
			CheckForm.focus();
			return false;
		}
	}

	if( Type == 'ID')
	{
		n = new RegExp("　","g") ;
		if (n.test(inText))
		{
			mes = Title + 'に「全角スペース」は使用できません。' ;
			alert(mes);
			CheckForm.focus();
			return false;
		}

		for(j = 0; j < inText.length; j++)
		{
			wk = inText.charAt(j) ;

			for (i = 0; i < check_id.length; i++)
			{
				if (wk == check_id[i])
				{
					if (check_id[i] == ' ')
					{
						mes = Title + 'に「半角スペース」は使用できません。' ;
					}
					else
					{
						mes = Title + 'に「' + check_id[i] + '」は使用できません。' ;
					}
					alert(mes);
					CheckForm.focus();
					return false;
				}
			}
		}
	}

	if( Type == 'DAT' )
	{
		if( gJS_NullChk(inText) == false )
		{
			if( gJS_isDate(inText) == false )
			{
				mes = Title + 'が 日付として正しくありません。';
				alert(mes);
				CheckForm.focus();
				return false;
			}
		}
	}


	//if( UrlFlag == 1 )
	//{
	//	if( gJS_InLen(inText) )
	//	{
	//		mes = Title + 'には制御文字（&,%,?,-,[スペース])は使用できません。';
	//		alert(mes);
	//		CheckForm.focus();
	//		return false;
	//	}
	//}

	return true;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_NullChk
[概要]
入力された情報がＮｕｌｌのみかチェックする

[引数]
inText：チェック対象

[返り値]:「true：Nullのみ」「false：Nullではない」

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
=============================================================================*/
function gJS_NullChk(inText)
{
	var intxtlen;
	var chkmsg;
	var cnt;	
	var cwk ;
	var sp = '　' ;

	intxtlen = inText.length;


	if(intxtlen == '')
	{
		return true;
	}

	for(cnt=0 ; cnt < intxtlen ; cnt++)
	{
		chkmsg = inText.charAt(cnt);
		
		//if(chkmsg != ' ')
		//if(chkmsg !=' ' && chkmsg != '　' && escape(chkmsg) != '%0D' && escape(chkmsg) != '%0A')
		if(chkmsg != ' ' && escape(chkmsg) != '%0D' && escape(chkmsg) != '%0A')
		{
			cwk = (sp.length == 1) ? chkmsg : chkmsg + inText.charAt(++cnt) ;
			if (cwk != sp)
			{
				return false;
			}
			else ;
		}
		else
		{
			if(cnt == (intxtlen-1))
			{
				return true;
			}
		}
	}

	return true;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_StrConv
[概要]
入力された情報の文字数を返す

[引数]
inText：チェック対象

[返り値]:文字数

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
01/10/31 TT)沓掛      ブラウザを問わず「charCodeAt」で判定
=============================================================================*/
function gJS_StrConv(inText)
{
	var nCntMax=0;
	var nCnt=0;
	var nLen=0;
	var Code;


	nCntMax = inText.length;

	//if (navigator.appName == 'Netscape') 
	//{
	//	nLen = nCntMax;
	//}
	//else 
	//{
		for (nCnt=0,nLen=nCntMax; nCnt<nCntMax; nCnt++ )
		{
			Code = inText.charCodeAt(nCnt);
			
			if ( !(  (0 <= Code && Code <= 128) || (160 <= Code && Code <= 222) || (253 <= Code && Code <= 254) || ("ｦ".charCodeAt() <= Code && Code <= "ﾟ".charCodeAt()))) 
			{
				nLen++;
			}
		}
	//}

	return nLen;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_InLen
[概要]
入力された情報に制御文字がないかチェックする

[引数]
inText：チェック対象

[返り値]:「true：制御文字あり」「false：制御文字なし」

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
=============================================================================*/
function gJS_InLen(inText)
{
	var nCntMax=0;
	var nCnt=0;

	var chemsg='';

	nCntMax = inText.length;
	for(nCnt=0 ; nCnt < nCntMax ; nCnt++ )
	{
		chkmsg = inText.charAt(nCnt);
		if( chkmsg == '&'|| chkmsg == '%'|| chkmsg == '?'|| chkmsg == '-'|| chkmsg == ' '|| chkmsg == '　' ) 
		{
			return true;
		}
	}

	return false;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_isDate
[概要]
入力された情報が日付型として正しいかチェックする

[引数]
inText：チェック対象

[返り値]:「true：正しい」「false：正しくない」

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
01/07/03 TT)沓掛     2桁の日付を正常と判定できるよう変更	（70年を境とする）⇒010718　50年に変更
=============================================================================*/
function gJS_isDate(inText)
{
	var Cnt;
	var Flag = 0;

	var InTextLen;

	var sText_y = '';
	var sText_m = '';
	var sText_d = '';
	var iText_y = 0;
	var iText_m = 0;
	var iText_d = 0;

	var CheckText = '';


	InTextLen = inText.length;


	for( Cnt = 0 ; Cnt < InTextLen ; Cnt++ )
	{
		CheckText = inText.charAt(Cnt);

		if( CheckText == '/' )
		{	
			Flag++;
		}
		else
		{
			
			if( CheckText >= 0 || CheckText < 10 )
			{
				if( Flag == 0 )
				{
					sText_y = sText_y + CheckText;
				}
				if( Flag == 1 )
				{
					sText_m = sText_m + CheckText;
				}
				if( Flag == 2 )
				{
					sText_d = sText_d + CheckText;
				}
			}
			else
			{
				return false;
			}

		}
	}


	//スラッシュの回数を数える（2回以外はエラー）
	if( Flag != 2 )	{
		return false;
	}
	//データ値存在テスト
	if( sText_y.length==0 || sText_m.length==0 || sText_d.length==0)	{
		return false;
	}
	//年をチェック
	//2桁の場合は70を基準とし4桁に修正する
	if( sText_y.length == 2)	{
		iText_y = eval(sText_y);
		if( iText_y < 50 )	{
			iText_y = iText_y + 2000;
		} else {
			iText_y = iText_y + 1900;
		}
	}else{
		iText_y = eval(sText_y);
	}
	if( iText_y.toString().length != 4 )	{
		return false;
	}

	//月をチェック（１〜12）
	iText_m = eval(sText_m);
	if( iText_m < 1 || iText_m > 12 ) {
		return false;
	}

	//日をチェック（１〜31）
	iText_d = eval(sText_d);
	if( iText_m == 1 || iText_m == 3 || iText_m == 5 || iText_m == 7 || iText_m == 8 || iText_m == 10 || iText_m == 12 ){
		if( iText_d < 1 || iText_d > 31 ){
			return false;
		}
	} else{
		if( iText_d < 1 || iText_d > 30 )	{
			return false;
		}
	}

	//閏年のロジック
	if( iText_m == 2 ){
		if( iText_y % 400 == 0 || (iText_y % 4 == 0 && iText_y % 100 != 0) ){
			if( iText_d > 29 )	{
				return false;
			}
		} else{
			if( iText_d > 28 )	{
				return false;
			}
		}
	}	

	return true;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_isNumeric
[概要]
入力された文字が数字のみかチェックする

[引数]
inTYPE:チェック型
	[INT]:整数のみ
	[FLOAT]:小数点許可
inText：チェック対象

[返り値]:「true：正しい」「false：正しくない」

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
01/01/30 TT)沓掛      inTYPE追加　小数点のチェックを可能にする
=============================================================================*/
function gJS_isNumeric(inTYPE,inText)
{
	var nCntMax=0;
	var nCnt=0;

	var Code;

	nCntMax = inText.length;

	for (nCnt=0; nCnt < nCntMax; nCnt++ )
	{
		Code = inText.charCodeAt(nCnt);
		//alert(nCnt + ':[' + Code + ']');
		
		if( !(48 <= Code && Code <= 57) )	{
			if( Code==46 && inTYPE=='FLOAT' ) {
				//ok
			}else{
				return false;
			}
		}
	}

	return true;
}
// ****************************************************************************



/* ****************************************************************************
[関数名] gJS_dateSB
[概要]
入力された日付の「A<B」をチェックする

[引数]
InText_A：チェック対象A
InText_B：チェック対象B

[返り値]:「true：正しい」「false：正しくない」

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      [V1L03→V2_01] コメント付加のみ	
=============================================================================*/
function gJS_dateSB(InText_A,InText_B)
{
	var Cnt;
	var Flag;

	var CheckText;
	var InTextLen;

	var AnsText_A;
	var AnsText_B;

	var InText_y;
	var InText_m;
	var InText_d;



	Flag = 0;
	InText_y = '';
	InText_m = '';
	InText_d = '';
	InTextLen = InText_A.length;

	for( Cnt = 0 ; Cnt < InTextLen ; Cnt++ )
	{
		CheckText = InText_A.charAt(Cnt);

		if( CheckText == '/' )
		{	
			Flag++;
		}
		else
		{
			if( CheckText >= 0 || CheckText < 10 )
			{
				if( Flag == 0 )
				{
					InText_y = InText_y + CheckText;
				}
				if( Flag == 1 )
				{
					InText_m = InText_m + CheckText;

				}
				if( Flag == 2 )
				{
					InText_d = InText_d + CheckText;
				}
			}
		}
	}

	AnsText_A = InText_y;

	if( InText_m.length == 1 )
	{
		AnsText_A = AnsText_A + '0';
	}
	AnsText_A = AnsText_A + InText_m;

	if( InText_d.length == 1 )
	{
		AnsText_A = AnsText_A + '0';
	}
	AnsText_A = AnsText_A + InText_d;


	Flag = 0;
	InText_y = '';
	InText_m = '';
	InText_d = '';
	InTextLen = InText_B.length;

	for( Cnt = 0 ; Cnt < InTextLen ; Cnt++ )
	{
		CheckText = InText_B.charAt(Cnt);

		if( CheckText == '/' )
		{	
			Flag++;
		}
		else
		{
			if( CheckText >= 0 || CheckText < 10 )
			{
				if( Flag == 0 )
				{
					InText_y = InText_y + CheckText;
				}
				if( Flag == 1 )
				{
					InText_m = InText_m + CheckText;

				}
				if( Flag == 2 )
				{
					InText_d = InText_d + CheckText;
				}
			}
		}
	}



	if( gJS_NullChk(InText_A) || gJS_NullChk(InText_B))
	{
		return true;
	}
	else
	{
		AnsText_B = InText_y;

		if( InText_m.length == 1 )
		{
			AnsText_B = AnsText_B + '0';
		}
		AnsText_B = AnsText_B + InText_m;

		if( InText_d.length == 1 )
		{
			AnsText_B = AnsText_B + '0';
		}
		AnsText_B = AnsText_B + InText_d;


		if( AnsText_A > AnsText_B )
		{
			return false;
		}
	}

	return true;
}
// ****************************************************************************


/* ****************************************************************************
[関数名] gJS_HrefUrlEXchange
[概要]
入力された文字列に意味を持たないランダム数を付加して返す

[引数]
inURL：ランダム文字を追加する対象のURL文字列
inParam：URLに付加するクエリーストリング

[返り値]:---

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      V1L03toV2β_TT01 [Err_021] 新規作成
=============================================================================*/
function gJS_HrefUrlEXchange(inURL,inParam)
{
	var urlstr='';

	urlstr = inURL + inParam;

	if( inParam == '' )	{
		urlstr = urlstr + '?tempstr=' + gJS_GetRandumMakeForDat();
	}
	else {
		urlstr = urlstr + '&tempstr=' + gJS_GetRandumMakeForDat();
	}
	
	//alert(urlstr);
	return urlstr;
}
// *****************************************************************************


/* ****************************************************************************
[関数名] gJS_GetRandumMakeForDat
[概要]
日付からランダム文字列を作成する

[引数]：---

[返り値]:
作成した文字列

-更新日- ---更新者--- ------------------------内容---------------------------
01/06/13 TT)沓掛      V1L03toV2β_TT01 [Err_021] 新規作成
=============================================================================*/
function gJS_GetRandumMakeForDat(){
	var theTime;
	var h,m,s
	
	theTime = new Date();

	h = theTime.getHours();
	m = theTime.getMinutes();
	s = theTime.getSeconds();
	
	return h + '' + m + '' + s;
}


/* ****************************************************************************
[関数名] gJS_DblSubmitChk
[概要]
サブミットボタンの二重クリックをチェックする

[引数]：---
[返り値]:---

-更新日- ---更新者--- ------------------------内容---------------------------
02/07/10 TT)沓掛      作成
=============================================================================*/
function gJS_DblSubmitChk()
{
	if( cJS_OnSubmitCHK == 0 ) 	{
		cJS_OnSubmitCHK = 1;
		return true;
	} else {
		alert('ただいま処理中です。お待ちください。');
		return false;
	}
}

