﻿// 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;
            }
        }
    }
    try {
        if      (minObj != null) minObj.focus();
        else if (topObj != null) topObj.focus();
    }
    catch(e) {}
    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;
            }
        }
    }
    try {
        if      (minObj != null) minObj.focus();
        else if (topObj != null) topObj.focus();
    }
    catch(e) {}
    scrollTo(0,0);
}
// 動作を無効にしたい場合は、以下のコメントアウトをはずす
//function InitFocus()
//{
//}

// ２重送信判定
var click_flg = 0;
function Double_ClickCheck() {
    NoOnBeforeUnload();
    if (click_flg == 0) {
        click_flg = 1;
        return true;
    } else {
        return false;
    }
}

// アンロード時のダイアログを非表示にする
// dialog_flgはBasePageのScript出力時に宣言する
function NoOnBeforeUnload(){
    dialog_flg = 1;
}

window.onbeforeunload = function(event){
  event = event || window.event; 
  if (dialog_flg == 0){
    event.returnValue = '続行すると、最初のページに移動（またはシステムを終了）します。これまでの処理内容は失われます。';
  }
}

// 文字列をクリックすることによる、テキストの切り替え
function ChangeLabelText(target){
   var hdnName = GetHiddenValue("h_Name_" + target.id);
   if (hdnName == null) return;
   var hdnCount = GetHiddenValue("h_Count_" + target.id);
   // classが"input"のものを全て取得
   var cnt = document.getElementsByTagName("input").length;

   if (hdnName.value == target.innerHTML) {
        target.innerHTML = hdnName.value.substring(0,hdnCount.value-1) + "…";
        target.title = hdnName.value;
        // ループで処理
        for (var i = 0; i < cnt; i++) {
            var obj = document.getElementsByTagName("input")[i];
            if (obj.type == "hidden") {
                if (obj.id.indexOf(target.id) < 0 && obj.id.indexOf("h_Name_") == 0) {
                    var tobject = document.getElementById(obj.id.replace("h_Name_", ""));
                    var thdnCount = GetHiddenValue(obj.id.replace("h_Name_", "h_Count_")).value;
                    tobject.innerHTML = obj.value.substring(0,thdnCount-1) + "…";
                    tobject.title = obj.value;
                }
            }
        }
   }
   else
   {
        target.innerHTML = hdnName.value;
        target.title = "";
        // ループで処理
        for (var i = 0; i < cnt; i++) {
            var obj = document.getElementsByTagName("input")[i];
            if (obj.type == "hidden") {
                if (obj.id.indexOf(target.id) < 0 && obj.id.indexOf("h_Name_") == 0) {
                    var tobject = document.getElementById(obj.id.replace("h_Name_", ""));
                    tobject.innerHTML = obj.value;
                    tobject.title = "";
                }
            }
        }
   }
}

function GetHiddenValue(hdnName) {
    var obj = document.forms[0].elements[hdnName];
    return obj;
}

