/*
* common.js
* [Attention] JSファイルの文字コードはSJISです
*/

//------------------------------
// WindowClose
//------------------------------
function doClose(closeMessage)
{
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1)
    {
        window.close();
        return;
    } else {
        if (( window.opener != null ) && (window.opener.closed == false))
        {
            window.close();
            return;
        }
    }

    if ( closeMessage == "" )
    {
        closeMessage = "ブラウザの[×]ボタンをクリックして終了してください。";
    }

    alert(closeMessage);
    //alert(document.cookie);

}


//------------------------------
// 確認してから、サブミット実行
//------------------------------
function doSubmitAndConfirm()
{
    if ( confirm("編集中のデータは失われます。よろしいですか？") == false )
    {
        return;
    }
    document.forms[0].submit();
}

//------------------------------
// 呼び出し先をサブミットし、次画面を閉じる
//------------------------------
function doOpenerSubmitAndSelfClose()
{
    if ( window.opener )
    {
        window.opener.document.forms[0].submit();
        window.close();
    }
}

//------------------------------
// 呼び出し先に画面モードをセットし、サブミットし、次画面を閉じる
//------------------------------
function doOpenerSubmitAndSetModeAndClose(mode)
{
    if ( window.opener )
    {   
        window.opener.document.forms[0].mode.value = mode;
        window.opener.document.forms[0].submit();
        window.close();
    }
}

function doOpenerSubmitOnEmptyMode()
{
    if ( window.opener )
    {
        window.opener.document.forms[0].mode.value = '';
        window.opener.document.forms[0].submit();
    }
}

//------------------------------
// パラメータを追加指定して、サブミット実行
//------------------------------
function doSubmit(moreParam)
{
    if ( moreParam.length > 0 )
    {
        var targetAction = document.forms[0].action;
        document.forms[0].action = targetAction + moreParam;
    }
    
    document.forms[0].submit();
}

//------------------------------
// 画面モードを指定して、サブミット実行
//------------------------------
function doSubmitAndSetMode(mode)
{
    if ( mode == 9 )
    {
        if (confirm("データは削除されます。よろしいですか？") == false )
        {
            return;
        }
    }

    document.forms[0].mode.value = mode;
    document.forms[0].submit();
}

//------------------------------
// ログアウト処理
//------------------------------
function doLogOut()
{
    alert('cannot logout.');
}

//------------------------------
// 画面を初期表示状態にする
//------------------------------
function doInitPage()
{
    var targetUrl   = document.forms[0].action;
    window.location = targetUrl;
}

//------------------------------
// 一覧のチェックボックスがチェックされているか
//------------------------------
function isCheckedListByName(name)
{
    var objName;
    var eles = document.forms[0].elements;
    for ( i=0;i<eles.length;i++)
    {
        if ( eles[i].type != "checkbox" ) 
        {
            continue;
        }

        objName = eles[i].name.substring(0,name.length);
        if ( objName == name )
        {
            if ( eles[i].checked == true )
            {
                return true;
            }
        }
    }

    alert('選択してください。');
    return false;
}

//-----------------------------
// チェックボックス全選択
//-----------------------------
function checkListAll(headName,flag)
{
    var objHeadName   = '';
    var eles = document.getElementsByTagName("INPUT");

    for ( i=0;i<eles.length;i++)
    {
        if ( eles[i].type != "checkbox" )
        {
             continue;
        }

        var objHeadName = eles[i].name.substring(0,headName.length);
        if ( objHeadName == headName )
        {
            if ( flag == 'check' )
            {
                if (! eles[i].checked )
                    eles[i].click();
            }
            else if ( flag == 'uncheck' )
            {
                if ( eles[i].checked )
                   eles[i].click();
            }
            else if ( flag == 'reverse' )
            {
                eles[i].click();
            }
        }
    }
}
