//  common.js
//  Last Update:2008.08.11
//
//  HISTORY    : 2018.12.xx N.Watanabe AlertおよびConfirmの代替対応
//                                      MyAlert(Alertと同等のダイアログイメージを表示する関数)を作成
//                                      MyConfirm(Confirmと同等のダイアログイメージを表示する関数)を作成
//                                      AlertをMyAlertに置き換え 
//                                      ConfirmをMyConfirmに置き換え 
//  HISTORY    : 2018.11.xx N.Watanabe 元年対応


var TIME_OUT_COUNT = 350;
var TIME_WAIT_FEW = 500;

// Loding Wait Icon
var mIcon = new Image();
try{
    mIcon.src = 'css/img/icosearch.gif';
}catch(ex){
}

// Show Message
function fncShowMessage(){
    var wObj = document.getElementById('hidMessage');
    if( wObj ){
        if( wObj.value.length > 0 )
            myAlert(wObj.value);
        wObj.value = '';
    }
}

// Ask End
function fncAskEnd(){
//    var wResult = confirm('閲覧を終了します confirm。よろしいですか？');
//    if( wResult )
//        fncShowWait();
//    return wResult

    // myConfirmはダイアログイメージを表示するのみでボタンの押下を待たない
    var wResult = myConfirm('閲覧を終了します。よろしいですか？');
    return true;
}

// Input Base
function fncInitializeInputBase(){
    var wObj = fncInitializeInputBase_GetObject();
    if( wObj ){
        fncInitializeInputBase_SetSize();
        function window.onscroll(){
            fncInitializeInputBase_SetSize();
        };
        function window.onresize(){
            fncInitializeInputBase_SetSize();
        };
    }
    return wObj;
}
function fncInitializeInputBase_GetObject(){
    var wObj = document.getElementById('pnlInputNumber');
    if( !wObj )
        wObj = document.getElementById('pnlInputCode');
    if( !wObj )
        wObj = document.getElementById('pnlInputDate');
    if( !wObj )
        wObj = document.getElementById('pnlInputText');
    if( !wObj )
        wObj = document.getElementById('pnlHistory');
    return wObj;
}
function fncInitializeInputBase_SetSize(){
    var wObj = fncInitializeInputBase_GetObject();
    if( wObj ){
        var wWidthC = document.documentElement.clientLeft + document.documentElement.clientWidth;
        var wWidthS = document.documentElement.scrollLeft + document.documentElement.scrollWidth;
        var wHeightC = document.documentElement.clientTop + document.documentElement.clientHeight;
        var wHeightS = document.documentElement.scrollTop + document.documentElement.scrollHeight;
        wWidthS = Math.min(wWidthS, wWidthC + 800)
        wHeightS = Math.min(wHeightS, wHeightC + 600)
        wObj.style.width = String(Math.max(wWidthC, wWidthS)) + 'px'
        wObj.style.height = String(Math.max(wHeightC, wHeightS)) + 'px'
    }
}

// Get Disabled Class Name
function fncGetDisabledClass( strNowClassName, bolDisabled ){
    for( var ix = 0; ix < 5; ix ++ ){
        var wCss;
        if( ix == 0 )
            wCss = 'cssButton';
        else if( ix == 1 )
            wCss = 'cssSubmit';
        else if( ix == 2 )
            wCss = 'cssSearch';
        else if( ix == 3 )
            wCss = 'cssTextBoxShowOnly';
        else if( ix == 4 )
            wCss = 'cssTextBox';

        var wIndex = strNowClassName.indexOf(wCss, 0);
        if( wIndex >= 0 ){
            var wDisabled = (strNowClassName.indexOf('DE', wIndex + wCss.length) == (wIndex + wCss.length));
            if( bolDisabled && (!wDisabled) )
                return strNowClassName.replace(wCss, wCss + 'DE');
            else if( (!bolDisabled) && wDisabled )
                return strNowClassName.replace(wCss + 'DE', wCss);
            else
                return strNowClassName;
        }
    }
}

// Input Number
var mTimerInput = Number.NaN;
function fncInitializeInputNumber(){
    try{
        var wBase = fncInitializeInputBase();
        if( wBase.getAttribute('id') == 'pnlInputNumber' ){
            var wPrgs = wBase.getElementsByTagName('p');
            for(var ix1 = 1; ix1 < wPrgs.length; ix1 ++ ){
                var wButtons = wPrgs[ix1].getElementsByTagName('button');
                for(var ix2 = 0; ix2 < wButtons.length; ix2 ++ ){
                    wButtons[ix2].onmousedown = function(){fncInputNumber(Number(this.firstChild.nodeValue));};
                    wButtons[ix2].onmouseup = fncStopInput;
                }
            }
        }
    }catch(ex){
    }
}
function fncInputNumber( numValue ){
    try{
        fncStopInput();
        var wObj = document.getElementById('txtInputNum');
        if( isNaN(numValue) || (numValue < 0) ){
            if( wObj.value.length > 0 ){
                wObj.value = wObj.value.substring(0, wObj.value.length - 1);
                mTimerInput = window.setTimeout('fncInputNumber('+numValue+')', TIME_OUT_COUNT);
            }

        }else{
            if( wObj.value.length < wObj.maxLength ){
                wObj.value += String(numValue);
                mTimerInput = window.setTimeout('fncInputNumber('+numValue+')', TIME_OUT_COUNT);
            }
        }

    }catch(ex){
    }
}
function fncStopInput(){
    if( !isNaN(mTimerInput) )
        window.clearTimeout(mTimerInput);
    mTimerInput = Number.NaN;
}

// Input Code
function fncInitializeInputCode(){
    try{
        var wBase = fncInitializeInputBase();
        if( wBase.getAttribute('id') == 'pnlInputCode' ){
            var wPrgs = wBase.getElementsByTagName('p');
            for(var ix1 = 1; ix1 < wPrgs.length; ix1 ++ ){
                var wButtons = wPrgs[ix1].getElementsByTagName('button');
                for(var ix2 = 0; ix2 < wButtons.length; ix2 ++ ){
                    wButtons[ix2].onmousedown = function(){fncInputCode(this.firstChild.nodeValue);};
                    wButtons[ix2].onmouseup = fncStopInput;
                }
            }
        }
    }catch(ex){
    }
}
function fncInputCode( strValue ){
    try{
        fncStopInput();
        var wObj = document.getElementById('txtInputCode');
        if( (strValue.length > 1) || (strValue.length < 1) ){
            if( wObj.value.length > 0 ){
                wObj.value = wObj.value.substring(0, wObj.value.length - 1);
                mTimerInput = window.setTimeout('fncInputCode("'+strValue+'")', TIME_OUT_COUNT);
            }
        }else{
            if( wObj.value.length < wObj.maxLength ){
                wObj.value += strValue;
                mTimerInput = window.setTimeout('fncInputCode("'+strValue+'")', TIME_OUT_COUNT);
            }
        }

    }catch(ex){
    }
}

// Input Date
var mInputDateNow = 0;
function fncInitializeInputDate(){
    try{
        var wBase = fncInitializeInputBase();
        if( wBase.getAttribute('id') == 'pnlInputDate' ){
            var wPrgs = wBase.getElementsByTagName('p');
            for(var ix1 = 1; ix1 < wPrgs.length; ix1 ++ ){
                // クリアボタン
                if( wPrgs[ix1].getAttribute('id') == 'prgInputDateClear' ){
                    var wButtons = wPrgs[ix1].getElementsByTagName('button');
                    if( wButtons.length > 0 )
                        wButtons[0].onclick = fncInputDateClear;
                // 元号、数字、年月日ボタン
                }else{
                    var wButtons = wPrgs[ix1].getElementsByTagName('button');

                    for(var ix2 = 0; ix2 < wButtons.length; ix2 ++ ){
                        if( wButtons[ix2].getAttribute('id') == 'btnBSInputD' )
                            wButtons[ix2].onmousedown = function(){fncInputDate('');};
                        else
                            wButtons[ix2].onmousedown = function(){fncInputDate(this.firstChild.nodeValue);};
                        wButtons[ix2].onmouseup = fncStopInput;
                    }
                }
            }

            if( !fncInputDateGetTextObj(0) )
                return;
            if( fncInputDateGetTextObj(0).value.length < 1 )            // 元号
                mInputDateNow = 0;
            else if( fncInputDateGetTextObj(1).value.length < 1 )       // 年
                mInputDateNow = 1;
            else if( fncInputDateGetTextObj(2).value.length < 1 )       // 月
                mInputDateNow = 2;
            else if( fncInputDateGetTextObj(3).value.length < 1 )       // 日
                mInputDateNow = 3;
            else
                mInputDateNow = 4;

            var wButtons, ix;
            wButtons = document.getElementById('prgInputDateG').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wButtons[ix].disabled = (mInputDateNow > 0);
                wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
            }

            wButtons = document.getElementById('divInputDateNumber').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wButtons[ix].disabled = ((mInputDateNow < 1) || (mInputDateNow > 3));
                if( !wButtons[ix].disabled )
                    wButtons[ix].disabled = (wButtons[ix].getAttribute('id') == 'btnBSInputD');
                wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
            }

            wButtons = document.getElementById('prgInputDateSet').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wButtons[ix].disabled = ((ix + 1) != mInputDateNow);
                wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
            }

        }
    }catch(ex){
    }
}
function fncInputDate( strValue ){
    try{
        fncStopInput();

        var wObj = fncInputDateGetTextObj(mInputDateNow);
        if( !wObj )
            return;

        if( (strValue == '年') || (strValue == '月') || (strValue == '日') ){
            if( !fncInputDateCheck(wObj.value) )
                return;
        }
        
        var wFlagBS = (strValue.length < 1);
        var wFlagNumber = (!wFlagBS && !isNaN(strValue));
        
        // １文字削除
        if( wFlagBS ){
            if( mInputDateNow == 0 ){
                wObj.value = '';
            }else{
                if( wObj.value.length > 0 ){
                    wObj.value = wObj.value.substring(0, wObj.value.length - 1);
                    if( wObj.value.length > 0 )
                        mTimerInput = window.setTimeout("fncInputDate('"+strValue+"')", TIME_OUT_COUNT);
                }
            }
        // 数字
        }else if( wFlagNumber ){
            if( wObj.value.length < wObj.maxLength - 1 ){
                wObj.value += strValue;
                if( wObj.value.length < wObj.maxLength - 1 )
                    mTimerInput = window.setTimeout("fncInputDate('"+strValue+"')", TIME_OUT_COUNT);
            }
        // 元号 年月日
        }else{
            // 表示欄の表示済み文字数が最大文字数未満であればクリックされたボタンの文字を追加
            if( wObj.value.length < wObj.maxLength ){
                // add_s 2018.11.xx N.Watanabe 年ボタンクリック時は、年欄に"1"が表示されていれば"元年"を表示
                if( strValue == '年' && wObj.value == '1')
                    wObj.value = '元年';
                else
                // add_e 2018.11.xx
                    wObj.value += strValue;
            }
        }

        if( !wFlagNumber && !wFlagBS ){
            mInputDateNow ++;
            fncInputDateChangeEnabled(mInputDateNow - 1, false);
            fncInputDateChangeEnabled(mInputDateNow, true);
            fncInputDateChangeEnabled(10, (mInputDateNow < 4));
            fncInputDateChangeEnabled(11, false);
            fncInputDateChangeEnabled(20, (mInputDateNow > 1));
        }
        
        if( wFlagNumber ){
            fncInputDateChangeEnabled(11, true);
            fncInputDateChangeEnabled(20, false);
        }

        if( wFlagBS ){
            fncInputDateChangeEnabled(11, (wObj.value.length > 0));
            if( (mInputDateNow == 2) || (mInputDateNow == 3) )
                fncInputDateChangeEnabled(20, (wObj.value.length == 0));
        }

    }catch(ex){
    }

}
// 年月日の入力チェック
function fncInputDateCheck( strNum ){

    if( strNum == '' ){
        myAlert('数字を入力してください。');
        return false;
    }
    var wNum = Number(strNum);
    if( isNaN(wNum) ){
        myAlert('数字を入力してください。');
        return false;
    }
    if( wNum < 1 ){
        myAlert('入力されている数字が小さすぎます。');
        return false;
    }
    // 月は１２以下
    if( (mInputDateNow == 2) && (wNum > 12) ){
        myAlert('入力されている数字が大きすぎます。');
        return false;
    }
    // 日は３１以下
    if( (mInputDateNow == 3) && (wNum > 31) ){
        myAlert('入力されている数字が大きすぎます。');
        return false;
    }
    
    return true;
    
}
function fncInputDateChangeEnabled( numKind, bolEnabled ){
    try{
        var wButtons, wDisabled, ix;

        if( numKind == 0 ){
            wButtons = document.getElementById('prgInputDateG').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wDisabled = !bolEnabled;
                    if( wDisabled != wButtons[ix].disabled ){
                    wButtons[ix].disabled = wDisabled;
                    wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
                }
            }

        }else if( numKind < 10 ){
            wButtons = document.getElementById('prgInputDateSet').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wDisabled = !(bolEnabled && (ix + 1) == numKind);
                if( wDisabled != wButtons[ix].disabled ){
                    wButtons[ix].disabled = wDisabled;
                    wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
                }
            }

        }else if( numKind == 10 ){
            wButtons = document.getElementById('divInputDateNumber').getElementsByTagName('button');
            for( ix = 0; ix < wButtons.length; ix ++ ){
                wDisabled = !bolEnabled;
                if( wDisabled != wButtons[ix].disabled ){
                    wButtons[ix].disabled = wDisabled;
                    wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
                }
            }

        }else if(numKind == 11 ){
            var wButtons = document.getElementById('btnBSInputD');
            wDisabled = !bolEnabled;
            if( wDisabled != wButtons.disabled ){
                wButtons.disabled = wDisabled;
                wButtons.className = fncGetDisabledClass(wButtons.className, wButtons.disabled);
            }

        }else if(numKind == 20 ){
            var wButtons = document.getElementById('btnEndInputDate');
            wDisabled = !bolEnabled;
            if( wDisabled != wButtons.disabled ){
                wButtons.disabled = wDisabled;
                wButtons.className = fncGetDisabledClass(wButtons.className, wButtons.disabled);
            }
        }
    }catch(ex){
    }
}
function fncInputDateGetTextObj( numKind ){
    try{
        if( numKind == 0 )
            return document.getElementById('txtInputDateG');
        else if( numKind == 1 )
            return document.getElementById('txtInputDateY');
        else if( numKind == 2 )
            return document.getElementById('txtInputDateM');
        else if( numKind == 3 )
            return document.getElementById('txtInputDateD');
        else
            return undefined;
    }catch(ex){
        return undefined;
    }
}
// クリアボタン
function fncInputDateClear(){
    try{
        mInputDateNow = 0;

        document.getElementById('txtInputDateG').value = '';
        document.getElementById('txtInputDateY').value = '';
        document.getElementById('txtInputDateM').value = '';
        document.getElementById('txtInputDateD').value = '';

        var wButtons, ix;
        wButtons = document.getElementById('prgInputDateG').getElementsByTagName('button');
        for( ix = 0; ix < wButtons.length; ix ++ ){
            wButtons[ix].disabled = false;
            wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
        }

        wButtons = document.getElementById('divInputDateNumber').getElementsByTagName('button');
        for( ix = 0; ix < wButtons.length; ix ++ ){
            wButtons[ix].disabled = true;
            wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
        }

        wButtons = document.getElementById('prgInputDateSet').getElementsByTagName('button');
        for( ix = 0; ix < wButtons.length; ix ++ ){
            wButtons[ix].disabled = true;
            wButtons[ix].className = fncGetDisabledClass(wButtons[ix].className, wButtons[ix].disabled);
        }
        
        var wSubmit = document.getElementById('btnEndInputDate');
        wSubmit.disabled = false;
        wSubmit.className = fncGetDisabledClass(wSubmit.className, wSubmit.disabled);

    }catch(ex){
    }

}

// CheckInputNumber
function fncCheckInputNumberValue( strID, bolEmpty, bolZero ){
    try{
        var wObj = document.getElementById(strID);
        var wText = String(wObj.value);
        var wResult = true;

        var wMaxCode = '9';
        for( var ix = 1; ix < wObj.maxLength; ix ++ )
            wMaxCode += '9';

        var wNum = parseInt(Number(wText));
        
        if( wText.length > 0 ){
            if( isNaN(wNum) ){
                myAlert('数値を入力してください。');
                wResult = false;
            }else{
                if( ((bolZero && wNum < 0) || (!bolZero && wNum < 1)) || wNum > Number(wMaxCode) ){
                    myAlert('使用できない値が入力されています。');
                    wResult = false;
                }
            }
        }else{
            if( !bolEmpty ){
                myAlert('数値を入力してください。');
                wResult = false;
            }
        }

        if( !wResult )
            wObj.focus();

        return wResult;
        
    }catch(ex){
        myAlert('入力が確認できません。');
        return false;
    }
}

// List Page Change
function fncChangePage(){
    fncShowWait();
}

// Select List
var mFlagListSelectAction = true;
var mActiveRow = Number.MIN_VALUE;
var mActiveCol = Number.MIN_VALUE;
function fncInitializeList(){
    try{
        var wObj = document.getElementById('sprList');
        if( wObj ){
            wObj.onSelectionChanged = function(){
                if( !mFlagListSelectAction )
                    return;

                var wRow = this.GetSelectedRange().row;
                this.ClearSelection();

                var wBlock = fncGetListBlock();
                if( wRow % wBlock > 0 )
                    wRow -= wRow % wBlock;

                mFlagListSelectAction = false;
                this.SetSelectedRange(wRow, 0, wBlock, this.GetColCount());
                mFlagListSelectAction = true;
            };

        }else{
            wObj = document.getElementById('sprSelectTown');
            if( !wObj )
                wObj = document.getElementById('sprSelectWard');
            if( !wObj )
                return;

            mActiveRow = fncGetActiveRow(wObj);
            mActiveCol = fncGetActiveCol(wObj);

            fncSetSelectActiveCellColor(wObj);

            wObj.onActiveCellChanged = function(){
                fncSetSelectActiveCellColor(this);
            }
            wObj.onActiveCellChanging = function(){
                fncSetSelectActiveCellColor(this);
            }

            wObj.onSelectionChanged = function(){
                fncSetSelectActiveCellColor(this);

                if( !mFlagListSelectAction )
                    return;

                var wRow = this.GetSelectedRange().row;
                var wCol = this.GetSelectedRange().col;
                var wColLeft = wCol;
                if( wColLeft % 2 > 0 )
                    wColLeft -= wColLeft % 2;

                this.ClearSelection();
                if( this.GetValue(wRow, wColLeft).length < 1 ){
                    this.SetActiveCell(mActiveRow, mActiveCol);
                    return;
                }

                mFlagListSelectAction = false;
                this.SetActiveCell(wRow, wCol);
                this.SetSelectedRange(wRow, wColLeft, 1, 2);
                mActiveRow = wRow;
                mActiveCol = wColLeft;
                mFlagListSelectAction = true;
            };
        }
    }catch(ex){
    }
}
function fncSetSelectActiveCellColor(pObj){
    try{
        var wRow, wCol, wColB;
        wRow = fncGetActiveRow(pObj);
        wCol = fncGetActiveCol(pObj);
        if( wCol >= 0 && wRow >= 0 ){
            if( wCol % 2 > 0 )
                wColB = wCol - 1;
            else
                wColB = wCol + 1;
            pObj.GetCellByRowCol(wRow, wCol).style.backgroundColor = pObj.GetCellByRowCol(wRow, wColB).style.backgroundColor;
        }
    }catch(ex){
    }
}
function fncGetActiveRow(pList){
    if( document.all )
        return pList.ActiveRow;
    else
        return pList.GetActiveRow();
}
function fncGetActiveCol(pList){
    if( document.all )
        return pList.ActiveCol;
    else
        return pList.GetActiveCol();
}

// Select List Block Count
function fncGetListBlock(){
    try{
        var wBlockID = 'hidListRowBlock';
        var wBlock = 1;
        if( document.getElementById(wBlockID) ){
            wBlock = Number(document.getElementById(wBlockID).value);
            if( isNaN(wBlock) || wBlock < 1)
                wBlock = 1;
        }
        return wBlock;

    }catch(ex){
        return 1;
    }
}

// Move Select
var mTimerMove = Number.NaN;
function fncInitializeMove(){
    try{
        if( document.getElementById('btnRowMoveUp') ){
            document.getElementById('btnRowMoveUp').onmousedown = fncMoveRowPrev;
            document.getElementById('btnRowMoveDown').onmousedown = fncMoveRowNext;
            document.getElementById('btnRowMoveUp').onmouseup = fncMoveStop;
            document.getElementById('btnRowMoveDown').onmouseup = fncMoveStop;
            
        }else if( document.getElementById('btnSelectTownUp') ){
            document.getElementById('btnSelectTownUp').onmousedown = fncMoveRowPrev;
            document.getElementById('btnSelectTownDown').onmousedown = fncMoveRowNext;
            document.getElementById('btnSelectTownUp').onmouseup = fncMoveStop;
            document.getElementById('btnSelectTownDown').onmouseup = fncMoveStop;
            
        }else if( document.getElementById('btnSelectWardUp') ){
            document.getElementById('btnSelectWardUp').onmousedown = fncMoveRowPrev;
            document.getElementById('btnSelectWardDown').onmousedown = fncMoveRowNext;
            document.getElementById('btnSelectWardUp').onmouseup = fncMoveStop;
            document.getElementById('btnSelectWardDown').onmouseup = fncMoveStop;

        }else if( document.getElementById('btnHistoryRowMoveUp') ){
            document.getElementById('btnHistoryRowMoveUp').onmousedown = fncMoveRowPrev;
            document.getElementById('btnHistoryRowMoveDown').onmousedown = fncMoveRowNext;
            document.getElementById('btnHistoryRowMoveUp').onmouseup = fncMoveStop;
            document.getElementById('btnHistoryRowMoveDown').onmouseup = fncMoveStop;
        }
    }catch(ex){
    }

    var wObj = fncGetMoveSelectList();
    if( wObj ){
        if( (wObj.GetRowCount() > 0) && (wObj.GetSelectedRanges().length < 1) ){
            wObj.ClearSelection();
            wObj.SetSelectedRange(0, 0, 1, wObj.GetColCount());
            wObj.focus();
        }
    }

}
function fncMoveRowNext(){
    try{
        fncMoveStop();

        var wObj = fncGetMoveSelectList();
        if( !wObj )
            return;
        if( wObj.GetRowCount() < 1 )
            return;
        var wFlagShowRowHeader = ( wObj == document.getElementById('sprHistory') );

        var wRange = wObj.GetSelectedRange();
        var wRow = wRange.row + fncGetListBlock();
        var wCol = wRange.col;
        if( (wCol + wRange.colCount < wObj.GetColCount()) && (wRow >= wObj.GetRowCount()) ){
            wCol += wRange.colCount;
            wRow = 0;
        }
        if( wFlagShowRowHeader && wCol < 0 )
            wCol = 0;
        if( (wRow >= 0) && (wRow < wObj.GetRowCount()) && (wCol >= 0) && (wCol < wObj.GetColCount()) ){
            wObj.ClearSelection();
            if( wFlagShowRowHeader )
                wObj.SetSelectedRange(wRow, wCol - 1, wRange.rowCount, wRange.colCount);
            else
                wObj.SetSelectedRange(wRow, wCol, wRange.rowCount, wRange.colCount);
            wObj.ScrollTo(wRow, wCol);
            mTimerMove = window.setTimeout('fncMoveRowNext()', TIME_OUT_COUNT);
        }

    }catch(ex){
    }
}
function fncMoveRowPrev(){
    try{
        fncMoveStop();

        var wObj = fncGetMoveSelectList();
        if( !wObj )
            return;
        if( wObj.GetRowCount() < 1 )
            return;
        var wFlagShowRowHeader = ( wObj == document.getElementById('sprHistory') );

        var wRange = wObj.GetSelectedRange();
        var wRow = wRange.row - fncGetListBlock();
        var wCol = wRange.col;
        if( (wCol > 0) && (wRow < 0) ){
            wCol -= wRange.colCount;
            wRow = wObj.GetRowCount() - 1;
        }
        if( wFlagShowRowHeader && wCol < 0 )
            wCol = 0;
        if( (wRow >= 0) && (wRow < wObj.GetRowCount()) && (wCol >= 0) && (wCol < wObj.GetColCount()) ){
            wObj.ClearSelection();
            if( wFlagShowRowHeader )
                wObj.SetSelectedRange(wRow, wCol - 1, wRange.rowCount, wRange.colCount);
            else
                wObj.SetSelectedRange(wRow, wCol, wRange.rowCount, wRange.colCount);
            wObj.ScrollTo(wRow, wCol);
            mTimerMove = window.setTimeout('fncMoveRowPrev()', TIME_OUT_COUNT);
        }

    }catch(ex){
    }
}

function fncMoveStop(){
    if( !isNaN(mTimerMove) )
        window.clearTimeout(mTimerMove);
    mTimerMove = Number.NaN;
}
function fncGetMoveSelectList(){
    if( document.getElementById('sprHistory') )
        return document.getElementById('sprHistory');
    if( document.getElementById('sprSelectTown') )
        return document.getElementById('sprSelectTown');
    if( document.getElementById('sprSelectWard') )
        return document.getElementById('sprSelectWard');
    if( document.getElementById('sprList') )
        return document.getElementById('sprList');
    return undefined;
}

// Show Wait
var mTimerShowWait = Number.NaN;
function fncShowWait(){
    if( !isNaN(mTimerShowWait) )
        window.clearTimeout(mTimerShowWait);
    mTimerShowWait = Number.NaN;

    try{
        var wIcon = document.createElement('img');
        wIcon.setAttribute('src', mIcon.src);
        wIcon.setAttribute('alt', 'wait icon');
        wIcon.setAttribute('title', 'しばらくお待ちください。');
        var wLineIcon = document.createElement('p');
        var wLineText = document.createElement('p');
        var wDiv = document.createElement('div');
        wDiv.setAttribute('id', 'divWaitImagePanel');

        wLineIcon.appendChild(wIcon)
        wLineText.appendChild(document.createTextNode('しばらくお待ちください。'))
        wDiv.appendChild(wLineIcon);
        wDiv.appendChild(wLineText);
        document.body.appendChild(wDiv);
        wDiv.style.visibility = 'visible';
    }catch(ex){
    }
}
function fncHideWait(){
    try{
        document.body.removeChild(document.getElementById('divWaitImagePanel'));
    }catch(ex){
    }
}
function fncShowWaitFew(){
    if( !isNaN(mTimerShowWait) )
        window.clearTimeout(mTimerShowWait);

    mTimerShowWait = window.setTimeout('fncShowWait()', TIME_WAIT_FEW);
}

// List Scroll
function fncListScrollSet(){
    var wObj = document.getElementById('hidResetScroll');
    if( wObj ){
        if( wObj.value.length > 0 ){
            var wText = wObj.value.split(';');
            if( wText.length == 5 ){
                if( wText[0] == 'c' ){
                    var wList = document.getElementById(wText[1]);
                    if( wList ){
                        var wTop = Number(wText[2]);
                        var wLeft = Number(wText[3]);
                        if( !isNaN(wTop) && !isNaN(wLeft) ){
                            var wActiveRow = fncGetActiveRow(wList);
                            var wActiveCol = fncGetActiveCol(wList);
                            wList.ScrollTo(wTop, wLeft);
                            wList.SetActiveCell(wActiveRow, wActiveCol);
                        }
                        wObj.setAttribute('value', '');
                    }
                }
            }
        }
    }
}
function fncListScrollSave(){
    var wObj = document.getElementById('hidResetScroll');
    if( !wObj )
        return;
    
    var wList = document.getElementById('sprList');
    if( wList ){
        var wView = document.getElementById('sprList_view');
        if( wView )
            wObj.setAttribute('value', 'p;sprList;'+wView.scrollTop+';'+wView.scrollLeft+';');
        else
            wObj.setAttribute('value', '');
    }
}

// Combination
function fncShowWaitAndListScrollSave(){
    fncShowWait();
    fncListScrollSave();
}
function fncShowWaitFewAndListScrollSave(){
    fncShowWaitFew();
    fncListScrollSave();
}
// add 2018.12.xx N.Watanabe
function isInputElement(pElement){
    return (
                ((pElement.type == "text") || (pElement.type == "submit") || (pElement.type == "button") || (pElement.type == "checkbox")) &&
               !((pElement.id == "btnAlertOk") || (pElement.id == "btnConfirmCancel") || (pElement.id == "btnConfirmOk"))
            ||
                (pElement.id == "sprList")
            );
}

function setDisabled(disabled){
//    confirm('setDisabled ')

    var wObj2; 
    
    wObj2 = document.getElementsByTagName('*');

    for( ix = 0; ix < wObj2.length; ix ++ ){
       if (isInputElement(wObj2[ix]))
            wObj2[ix].disabled = disabled;

    }
}

// add 2018.12.xx N.Watanabe
function myConfirm(msg){
    return myAlertSub('名簿閲覧', msg, false);
}

// add 2018.12.xx N.Watanabe
function myAlert(msg){
    return myAlertSub('名簿閲覧', msg, true);
}

// add 2018.12.xx N.Watanabe
function myAlertSub(myTitle, myMessage, alert_confirm){
	// タイトルとメッセージをセットする
	myMessage = myMessage.replace(/\n/g, "<BR>");
	document.getElementById("divAlertTitle").innerHTML = myTitle;
	document.getElementById("pAlertMessage").innerHTML = myMessage;

	// 中央に表示
	myXs = document.body.scrollLeft;	
	myYs = document.body.scrollTop;
	myX = (window.innerWidth !== undefined) ? window.innerWidth : document.body.clientWidth;
	myY = (window.innerHeight !== undefined) ? window.innerHeight : document.body.clientHeight;
	document.getElementById("divAlertBase").style.left = myX / 2 - (myX/2/2) + myXs + myXs;
	document.getElementById("divAlertBase").style.top = myY / 2 - (myY/2/2) + myYs;

	// ボタンの表示設定
    // alert時はalert用のOKボタン(<input type="button">)のみ表示
    if(alert_confirm){
    	document.getElementById("pAlertMark").style.display = "inline";
    	document.getElementById("pConfirmMark").style.display = "none";

    	document.getElementById("btnConfirmOk").style.display = "none";
    	document.getElementById("btnConfirmCancel").style.display = "none";
    	document.getElementById("btnAlertOk").style.display = "inline";

    // confirmはconfirm用のOKボタン(<asp:Button)およびキャンセルボタン(<input type="button">)を表示
    } else {
    	document.getElementById("pAlertMark").style.display = "none";
    	document.getElementById("pConfirmMark").style.display = "inline";

    	document.getElementById("btnConfirmOk").style.display = "inline";
    	document.getElementById("btnConfirmCancel").style.display = "inline";
    	document.getElementById("btnAlertOk").style.display = "none";
    }

	// 警告画面を表示
	document.getElementById("divAlertBase").style.visibility = "visible";

    // 各コントロールを使用不可状態に設定
    setDisabled(true);
}

// add 2018.12.xx N.Watanabe alert疑似ダイアログを閉じる
function myAlertClose(ok_cancel){
	// 警告画面を隠す
	document.getElementById("divAlertBase").style.visibility = "hidden";

    setDisabled(false);

    return ok_cancel;
}

// add 2018.12.xx N.Watanabe confirm疑似ダイアログを閉じる
function myConfirmClose(ok_cancel){
	// 警告画面を隠す
	document.getElementById("divAlertBase").style.visibility = "hidden";

    setDisabled(false);

    // OKでダイアログを閉じる場合は「しばらくお待ちください」を表示
    if(ok_cancel)
        fncShowWait();

    return ok_cancel;
}
