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

// Clear
function fncInitialiseClear(){
    var wObj = document.getElementById('btnClear');
    if( wObj ){
        wObj.onclick = function(){
            try{
                document.getElementById('txtUserID').value = '';
                document.getElementById('txtInspectNumber').value = '';
            }catch(ex){
            }
        };
    }
}

// Check Input
function fncCheckInputIdentify(){
    var wResult = true;
    try{
        var wObj = document.getElementById('txtUserID');
        wResult = (wObj.value.length > 0);
        if( !wResult ){
            myAlert('ユーザーIDを入力してください。');
            wObj.focus();
        }
        if( wResult ){
            wObj = document.getElementById('txtInspectNumber');
            wResult = (wObj.value.length > 0);
            if( !wResult )
                myAlert('閲覧番号を入力してください。');
            if( wResult ){
                wResult = (wObj.value.length > 8);
                if( !wResult )
                    myAlert('閲覧番号を確認してください。');
            }
            if( !wResult )
                wObj.focus();
        }
    }catch(ex){
        wResult = false;
    }
    if( wResult )
        fncShowWait();
    return wResult;
}
function fncCheckInputGetNumber(){
    var wResult = true;
    try{
        var wObj = document.getElementById('txtUserID');
        wResult = (wObj.value.length > 0);
        if( !wResult ){
            myAlert('ユーザーIDを入力してください。');
            wObj.focus();
        }
    }catch(ex){
        wResult = false;
    }
    if( wResult )
        fncShowWait();
    return wResult;
}

function fncCheckInputDate(){
    var wResult = true;
    try{
        var wObj = new Array(3);
        for( var ix = 1; ix <= 2; ix ++ ){
            var wIndex = -1;
            wObj[0] = document.getElementById('txtYear'+String(ix));
            wObj[1] = document.getElementById('txtMonth'+String(ix));
            wObj[2] = document.getElementById('txtDay'+String(ix));
            if( wObj[0].value.length == 0 ){
                wResult = (wObj[1].value.length == 0 && wObj[2].value.length == 0);
                if( !wResult )
                    wIndex = 0;
            }else{
                wResult = !(wObj[1].value.length == 0 && wObj[2].value.length > 0);
                if( !wResult )
                    wIndex = 1;
            }
            if( !wResult ){
                myAlert('入力を確認してください。');
                wObj[wIndex].focus();
            }
            if( wResult ){
                for( var iy = 0; iy < 3; iy ++ ){
                    if( wObj[iy].value.length > 0 ){
                        // add 2018.12.xx
                        if((iy == 0) && (wObj[iy].value == '元'))
                            //wObj[iy].value = '1';
                            break;
                        var wNumber = Number(wObj[iy].value);
                        wResult = !isNaN(wNumber);
                        if( wResult )
                            wResult = (String(wNumber).indexOf('.') < 0);
                        if( wResult )
                            wResult = (wNumber > 0);
                        if( wResult && iy == 1)
                            wResult = (wNumber <= 12);
                        if( wResult && iy == 2)
                            wResult = (wNumber <= 31);
                        if( !wResult ){
                            myAlert('使用できない値が入力されています。');
                            wObj[iy].focus();
                            break;
                        }
                    }else{
                        break;
                    }
                }
            }
            if( !wResult )
                break;
        }
        if( wResult )
            fncShowWait();
    }catch(ex){
        wResult = false;
    }
    return wResult;
}
function fncCheckInputLogin(){
    var wResult = false;
    var wCode;
    for( var ix = 0; ix < 100; ix ++ ){
        var wRadio = document.getElementById('rdoIdentify'+ix);
        if( !wRadio )
            break;
        if( wRadio.checked ){
            wCode = document.getElementById(wRadio.id+'V').value;
            wResult = true;
            break;
        }
    }
    if( !wResult )
        myAlert('確認書類の種類を選択してください。');
    if( wResult ){
        var wObjOther = document.getElementById('txtIdentifyOther');
        if( !( wObjOther.style.display == 'none') ){
            if( String(wObjOther.value).length < 1 ){
                myAlert('確認書類の種類を入力してください。');
                wObjOther.focus();
                wResult = false;
            }
        }
    }
    if( wResult )
        fncShowWait();
    return wResult;
}

// Radio Input
function fncInitializeRadio(){
    var wObjOther = document.getElementById('txtIdentifyOther');
    if( wObjOther ){
        for( var ix = 0; ix < 100; ix ++ ){
            var wRadio = document.getElementById('rdoIdentify'+ix);
            if( !wRadio )
                break;
            wRadio.onclick = function(){
                if( this.checked ){
                    var wObjOther = document.getElementById('txtIdentifyOther');
                    var wObjHide = document.getElementById(this.id+'V');
                    if( wObjHide.value == '99' ){
                        wObjOther.style.display = '';
                    }else{
                        wObjOther.style.display = 'none';
                    }
                }
            };
        }
    }
}

// add 2018.12.xx
function fncOneToGannen(){
    var index = 1;
    var wObj = document.getElementById('txtYear'+String(index));       
    if ((wObj.value == '1') || (wObj.value == '01'))
            wObj.value = '元';
}


// Load Event
function window.onload(){
    fncInitialiseClear();
    fncInitializeRadio();
    fncShowMessage();
}
