// JavaScript for OecBody

// イベントハンドラ ------------------------------------------------------------- //


// ローカルメソッド ------------------------------------------------------------- //
// 初期フォーカス位置
function InitFocus() {
    minObj = null;  // min-tabindex obj
    topObj = null;  // top obj
    cnt = document.getElementsByTagName("input").length;
    for(i=0; i<cnt; i++) {
        curObj = document.getElementsByTagName("input")[i];
        if((curObj.getAttribute("type") != "text") && 
           (curObj.getAttribute("type") != "submit") &&
           (curObj.getAttribute("type") != "password")) {
            continue;
        }
        
        if(curObj.getAttribute("disabled") == true ) {
            continue;
        }
        
        if(topObj == null) topObj = curObj;
        if(curObj.getAttribute("tabindex") > 0) {
            if(minObj == null) minObj = curObj;
            else {
                if(minObj.getAttribute("tabindex") > curObj.getAttribute("tabindex"))
                    minObj = curObj;
            }
        }
    }
    if      (minObj != null) minObj.focus();
    else if (topObj != null) topObj.focus();  
    scrollTo(0,0);  
}

// 初期フォーカス位置(LinkButton)
// LinkButtonしかない画面で、一番にフォーカスを当てる //
function InitFocusLinkButton() {
    minObj = null;  // min-tabindex obj
    topObj = null;  // top obj
    cnt = document.getElementsByTagName("a").length;
    for(i=0; i<cnt; i++) {
        curObj = document.getElementsByTagName("a")[i];
        if(curObj.getAttribute("href") == ""){
            continue;
        }
        
        if(curObj.getAttribute("disabled") == true){
            continue;
        }
        
        if(topObj == null) topObj = curObj;
        if(curObj.getAttribute("tabindex") > 0){
            if(minObj == null) minObj = curObj;
            else {
                if(minObj.getAttribute("tabindex") > curObj.getAttribute("tabindex"))
                    minObj = curObj;
            }
        }
    }
    if(minObj != null)            minObj.focus();
    else if(topObj != null)        topObj.focus();    
}
// 動作を無効にしたい場合は、以下のコメントアウトをはずす
//function InitFocus()
//{
//}

// ２重送信判定
var click_flg = 0;
function Double_ClickCheck() {
    
    if (click_flg == 0) {
        click_flg = 1;
        return true;
    } else {
        return false;
    }
}

//入力桁MAX時自動フォーカス移動
		/**
		 * Do not auto tab when the following keys are pressed
		 * 8:	Backspace
		 * 9:	Tab
		 * 16:	Shift
		 * 17:	Ctrl
		 * 18:	Alt
		 * 19:	Pause Break
		 * 20:	Caps Lock
		 * 27:	Esc
		 * 28:  変換
		 * 29:  無変換
		 * 33:	Page Up
		 * 34:	Page Down
		 * 35:	End
		 * 36:	Home
		 * 37:	Left Arrow
		 * 38:	Up Arrow
		 * 39:	Right Arrow
		 * 40:	Down Arroww
		 * 45:	Insert
		 * 46:	Delete
		 * 91:  Windowsキー
		 * 93:  メニューキー
		 * 112: F1
		 * 113: F2
		 * 114: F3
		 * 115: F4
		 * 116: F5
		 * 117: F6
		 * 118: F7
		 * 119: F8
		 * 120: F9
		 * 121: F10
		 * 122: F11
		 * 123: F12		 
		 * 144:	Num Lock
		 * 145:	Scroll Lock
		 * 240: Caps Lock
		 * 242: カタカナ／ひらがな
		 * 243: 半角／全角
		 * 244: 半角／全角
		 */
function movefocus () {
	var InpTxt = [ ];
	var e = document.forms[0].elements;
	var keys = [8, 9, 16, 17, 18, 19, 20, 27, 28, 29, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 91, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 144, 145, 240, 242, 243, 244];
	I = e.length;
	for (i = 0; i < I; i++) {
		if (e[i].type == 'text') {
			e[i].onkeyup = function (indno) {
				return function () { // maxlengthで次にフォーカス移動
					if ((this.id == 'txtPostNo1') || (this.id == 'txtPostNo2')){
						var keycd = event.keyCode;
						for (j = 0; j < keys.length; j++){
							if (keys[j] == keycd){	
								return false;
							}
						}
						if (this.maxLength == this.value.length){
							InpTxt[ (indno + 1) % InpTxt.length ].select ();
						}
					}
				}
			} (InpTxt.length);
		InpTxt.push (e[i]);
		}
	}
}

