/* InputStrTxt用JavaScript関数群 */

/* OnBlur処理 */
function UxInputStrTxtOnBlur(txtId,MaxByte,Type,Mode){
	if (Type == "Wide"){//半角→全角モードの場合
		//document.getElementById(txtId).value = UxToWideKana(document.getElementById(txtId).value);
	} else if(Type == "NarrowEizi"){//英字のみ全角→半角モードの場合
		document.getElementById(txtId).value = UxToNarrowEizi(document.getElementById(txtId).value);
		document.getElementById(txtId).value = UxAsciiGaiDel(document.getElementById(txtId).value);
	} else if(Type == "Num"){//数値のみ全角→半角モードの場合
		document.getElementById(txtId).value = UxToNarrowEizi(document.getElementById(txtId).value);//英字系を全角→半角
		document.getElementById(txtId).value = UxNumGaiDel(document.getElementById(txtId).value);//数値以外は排除
		if (Mode == "No"){
			if (document.getElementById(txtId).value != ""){//数値が入っていた場合は前ゼロ埋め処理
				document.getElementById(txtId).value = FormatZeroNum(document.getElementById(txtId).value,MaxByte);
			}
		}
	} 
	//MaxByteが0以外なら
	if(MaxByte != 0){
		var NowByte =  ByteChk(document.getElementById(txtId).value);//現在のバイト数をチェック
		if (NowByte > MaxByte){//MaxByteを超えていた場合はOver分の文字列を削る
			var OverStrNum = NowByte - MaxByte;
			var DelLenNum = 0;
			var LenByte = 0;
	
			for(iq = document.getElementById(txtId).value.length - 1;iq > 0 ;iq--){
				var d = document.getElementById(txtId).value.charAt(iq);
				LenByte = LenByte + ByteChk(d);
				DelLenNum = DelLenNum + 1;
				//alert(LenByte + ":" + DelLenNum + ":" + OverStrNum);
				if (LenByte >= OverStrNum){
					document.getElementById(txtId).value = document.getElementById(txtId).value.substring(0, (document.getElementById(txtId).value.length - DelLenNum));  
					break;
				} 
				
			}
	
		}
	}
}

/* キープレス処理（ノーマル） */
function UxInputStrTxtKeyPless(txtId, MaxByte, key, Type, Mode) {
    //制御文字はOK
    if ((key == 8  || key == 9) || (key == 19) || (key <= 27 && key >= 29) || (key <= 33 && key >= 36) || (key == 45 || key == 46) ||
        (key <= 91 || key == 93) || (key == 229 || key == 240 || key == 242)) {
	    return true;
	}
	//数値以外の入力はキャンセル
	if (((key < 47) || (key > 58)) && (Type == "Num")) {
	    return false;
	}
	if (MaxByte != 0) {
		var NowByte =  ByteChk(document.getElementById(txtId).value);
		if (NowByte >= MaxByte){
			if(document.selection.createRange().text.length == 0){
				return false;
			}
		}
	}
	return true;
}

/* キープレス処理（EnterKeyを押した場合に同時にチェックを行なう） */
function UxInputStrTxtKeyPlessEx(txtId,MaxByte,key,Type,Mode){
	if(key == "13"){
		if (Type == "Wide"){
			//document.getElementById(txtId).value = UxToWideKana(document.getElementById(txtId).value);
		} else if(Type == "NarrowEizi"){
			document.getElementById(txtId).value = UxToNarrowEizi(document.getElementById(txtId).value);
			document.getElementById(txtId).value = UxAsciiGaiDel(document.getElementById(txtId).value);
		} else if(Type == "Num"){
			document.getElementById(txtId).value = UxToNarrowEizi(document.getElementById(txtId).value);
			document.getElementById(txtId).value = UxNumGaiDel(document.getElementById(txtId).value);
			if (Mode == "No"){
				if (document.getElementById(txtId).value != ""){
					document.getElementById(txtId).value = FormatZeroNum(document.getElementById(txtId).value,MaxByte);
				}
			}
		}
		return true;
	} else if(((key < 48) && (key > 57)) && (Type == "Num")) {
		return false;
	}
	if(MaxByte != 0){
		var NowByte =  ByteChk(document.getElementById(txtId).value);
		if (NowByte >= MaxByte){
			if(document.selection.createRange().text.length == 0){
				return false;
			}
		}
	}
	return true;
}

/* 数値以外を文字列から削除 */
function UxNumGaiDel(Value){
	var NewValue = new String();
	for (i=0; i<Value.length; i++){
		var ChkNum = Value.charAt(i);
		var ChkNumNo = "0123456789".indexOf(ChkNum);
		if(ChkNumNo != -1){
			NewValue = NewValue + ChkNum;
		}
	}
	return NewValue;
}

//テキストリンク共通関数
function chg_tlnkBtnEnable(tlnkContentTxtId, tlnkBtnId){
    if (tlnkContentTxtId.value != '') {
      tlnkBtnId.disabled = '';
      tlnkBtnId.src = '../images/FIND.gif';
    } else {
      tlnkBtnId.disabled = 'disabled';
      tlnkBtnId.src = '../images/FIND_NG.GIF';
    }
}
