//  inspection.js
//  Last Update:2008.08.13
//
//	History
//		2018.12.xx N.Watanabe alertおよびconfimの代替対応
//                                      alertをmyAlertに置き換え 

// Check Input Code Text
function fncCheckInput(){
    var wResult = fncCheckInputNumberValue('txtWardCode', true, true);
    if( wResult )
        wResult = fncCheckInputNumberValue('txtBookNum', true, true);
    if( wResult )
        wResult = fncCheckInputNumberValue('txtPageNum', true, false);

    if( wResult ){
        var wLenWard = document.getElementById('txtWardCode').value.length;
        var wLenBook = document.getElementById('txtBookNum').value.length;
        var wLenPage = document.getElementById('txtPageNum').value.length;
        var wBookUse = !(document.getElementById('txtBookNum').getAttribute("readonly"));
        if( wLenWard < 1 && ((wLenBook > 0 && wBookUse) || wLenPage > 0) ){
            myAlert('投票区を選択してください。');
            wResult = false;
            document.getElementById('btnSelectWard').focus();
        }else if( wLenWard > 0 && (wLenBook < 1 && wBookUse) && wLenPage > 0 ){
            myAlert('数値を入力してください。');
            wResult = false;
            document.getElementById('btnBook').focus();
        }
        if( wResult ){
            if( wLenBook > 0 && !wBookUse )
                document.getElementById('txtBookNum').value = '';
        }
    }

    if( wResult )
        fncShowWait();

    return wResult;
}

// Text Box
function fncInitializeTextBox(){
    if( document.getElementById('txtTownCode') ){
        document.getElementById('txtTownCode').onchange = fncSetTextChangePostBackTownCode;
    }
    if( document.getElementById('txtWardCode') ){
        document.getElementById('txtWardCode').onchange = fncSetTextChangePostBack;
    }
    if( document.getElementById('txtBookNum') ){
        document.getElementById('txtBookNum').onchange = fncSetTextChangePostBack;
    }
    if( document.getElementById('txtPageNum') ){
        document.getElementById('txtPageNum').onchange = fncSetTextChangePostBack;
    }
}
function fncSetTextChangePostBackTownCode(){
    document.getElementById('txtTownName').value = '';
    if( document.getElementById('sprList').GetRowCount() > 0 )
        window.setTimeout('__doPostBack(\'txtTownCode\',\'\')', 0);
}
function fncSetTextChangePostBack(){
    if( document.getElementById('sprList').GetRowCount() > 0 )
        window.setTimeout('__doPostBack(\'txtWardCode\',\'\')', 0);
}

// Spin Button
function fncCheckWard(){
    var wResult = fncCheckInputNumberValue('txtWardCode', false, true);
    if( wResult )
        fncShowWait();
    return wResult;
}
function fncCheckBook(){
    var wResult = fncCheckInputNumberValue('txtWardCode', false, true);
    if( wResult )
        wResult = fncCheckInputNumberValue('txtBookNum', false, true);
    if( wResult )
        fncShowWait();
    return wResult;
}
function fncCheckPage(){
    var wResult = fncCheckInputNumberValue('txtWardCode', false, true);
    if( wResult )
        wResult = fncCheckInputNumberValue('txtBookNum', false, true);
    if( wResult )
        wResult = fncCheckInputNumberValue('txtPageNum', false, false);
    if( wResult )
        fncShowWait();
    return wResult;
}

// Load Event
function window.onload(){
    fncInitializeList();
    fncInitializeTextBox();
    fncInitializeMove();
    fncInitializeInputNumber();
    fncListScrollSet();
    fncShowMessage();
}

// All Timer Stop
function document.onmouseup(){
    fncStopInput();
    fncMoveStop();
}