<!--
/*
 * 『共通ＪａｖａＳｃｒｉｐｔ』
 * 『クライアント処理』の標準に従い
 * 定義された共通ＪａｖａＳｃｒｉｐｔファイル。
 *
 * <PRE>
 * VERSION  : 1.0.0
 * AUTHOR   : SCS
 * DATE     : 2002/07/01
 * HISTORY  : 2002/07/01    SCS     :新規作成
 * </PRE>
 */

// 戻るボタンを無効にする。
window.focus();

/**
 * サブミットフラグ<BR>
 * <PRE>
 * サブミット処理を行う為のフラグです。
 * 通常の画面遷移では、このフラグが false の場合のみサブミットが行なわれます。
 * 初期値は true と設定されており、
 * 『ＪＳＰ　ＩＮＩＴメソッド内共通処理』にて false が設定されます。
 * これは、ブラウザがレスポンス受信中にサブミットを発生させない為の仕組みです。
 * </PRE>
 */
var bFlgSubmitted = true;

/**
 * <PRE>
 * 『サブミット処理』
 * ブラウザの入力内容をサーブレットへ送信します。
 * 通常submit処理を行う場合当メソッドを使用して下さい。
 * ＜使用例＞
 * function fncSubmit()
 * {
 *     submitForm();                // Submitを行う部分で呼出
 * }
 *
 * 注意） document.form.submit() は直接JSP内部で使用しないで下さい。
 * <B>引数</B>              なし
 * <B>返却値</B>            なし
 * </PRE>
 */
function submitForm()
{
    var sNextPage = document.form.NEXT_PAGE.value;

    if(bFlgSubmitted == false)
    {
        // ダウンロードの時はそのままサブミットする。
        if( sNextPage == "/zz/common/ZZDownloadOpen.jsp" ||
            sNextPage == "/zz/common/ZZDownloadSave.jsp")
        {
            document.form.submit();
        }
        // 当画面を含むサブミット対象の場合、
        // 一番最初のリクエストのみサブミットする。
        else if(document.form.target == "_self"     ||
                document.form.target == "_top"      ||
                document.form.target == "_parent"   ||
                document.form.target == ""          ||
                document.form.target == "main")
        {
            bFlgSubmitted = true;
            document.form.submit();
        }
        // 当画面を含まないサブミット対象の場合、
        // そのままサブミットする。
        else
        {
            document.form.submit();
        }
    }
    
    return;
}

/**
 * <PRE>
 * 『先頭に付加されているブランク（半角スペース）を文字列から削除します。』
 *
 * 例）
 * @    getLeftTrimmedString(" AIUEO  ");
 *
 *       結果：|AIUEO  |
 *
 * A    getLeftTrimmedString("   あいうえお  ");
 *
 *       結果：|あいうえお  |
 * <B>引数</B>
 *              sSrc            変換前文字列
 * <B>返却値</B>
 *              String          変換後文字列
 * </PRE>
 */
function getLeftTrimmedString(sSrc)
{
    // 引数のタイプがstring以外
    if ("string" != typeof(sSrc)) {
        return "";
    }
    
    var sTmpStr = sSrc;
    
    while(  sTmpStr != "" &&
            sTmpStr.charAt(0) == ' ')
    {
        sTmpStr = sTmpStr.substring(1, sTmpStr.length);
    }
    
    return sTmpStr;
}

/**
 * <PRE>
 * 『末尾に付加されているブランク（半角スペース）を文字列から削除します。』
 *
 * 例）
 * @    getRightTrimmedString(" AIUEO  ");
 *
 *       結果：| AIUEO|
 *
 * A    getRightTrimmedString("   あいうえお  ");
 *
 *       結果：|   あいうえお|
 * <B>引数</B>
 *              sSrc            変換前文字列
 * <B>返却値</B>
 *              String          変換後文字列
 * </PRE>
 */
function getRightTrimmedString(sSrc)
{
    // 引数のタイプがstring以外
    if ("string" != typeof(sSrc)) {
        return "";
    }
    
    var sTmpStr = sSrc;
    
    while(  sTmpStr != "" &&
            sTmpStr.charAt(sTmpStr.length - 1) == ' ')
    {
        sTmpStr = sTmpStr.substring(0, sTmpStr.length - 1);
    }
    
    return sTmpStr;
}

/**
 * <PRE>
 * 『先頭及び末尾に付加されているブランク（半角スペース）を文字列から削除する。』
 *
 * 例）
 * @    getTrimmedString(" AIUEO  ");
 *
 *       結果：|AIUEO|
 *
 * A    getTrimmedString("   あいうえお  ");
 *
 *       結果：|あいうえお|
 * <B>引数</B>
 *              sSrc            変換前文字列
 * <B>返却値</B>
 *              String          変換後文字列
 * </PRE>
 */
function getTrimmedString(sSrc)
{
    // 引数のタイプがstring以外
    if ("string" != typeof(sSrc)) {
        return "";
    }
    
    var sTmpStr = sSrc;
    
    sTmpStr = getLeftTrimmedString(sTmpStr)
    sTmpStr = getRightTrimmedString(sTmpStr);
    
    return sTmpStr;
}

/**
 * <PRE>
 *  『フォーカスの設定』
 *   引数で指定されオブジェクトにフォーカスを設定します。
 * <B>引数</B>
 *              oSrc        フォーカスを設定するオブジェクト
 * <B>返却値</B>            なし
 * </PRE>
 */
 
 /**
  *
  *
  *
  *
  */
function requestFocus(oSrc)
{
    // 引数のタイプがobject以外
    if ("object" != typeof(oSrc)) {
        return;
    }

    if ("text" == oSrc.type || "password" == oSrc.type || "file" == oSrc.type ||
        "textarea" == oSrc.type) {
        // 引数のオブジェクトが"Text","Password","TextArea","FileUpload"の場合
        oSrc.focus();
        oSrc.select();
    } else if ("select-one" == oSrc.type || "select-multiple" == oSrc.type ||
               "button" == oSrc.type || "reset" == oSrc.type || "submit" == oSrc.type ) {
        // 引数のオブジェクトが"Button","Submit","Reset","Select"の場合
        oSrc.focus();
    } else {
        if (oSrc.length && oSrc.length > 0) {
            if ("radio" == oSrc[0].type || "checkbox" == oSrc[0].type) {
                // 引数のオブジェクトが"Chekbox","Radio"の場合
                oSrc[0].focus();
            }
        } else {
            if ("radio" == oSrc.type || "checkbox" == oSrc.type) {
                // 要素が1の"Chekbox","Radio"の場合
                oSrc.focus();
            }
        }
    }
    
    return;
}

/**
 * <PRE>
 * Sifit_JISでのバイト数を取得する。
 * <B>引数</B>     obj チェック対象Object
 * <B>返却値</B>   バイト数
 * </PRE>
 */
function getBytes(sSrc)
{
    // 文字列以外の場合は0を返す
    if (typeof(sSrc) != "string") {
        return 0;
    }

    var nByte = 0;
    for (var i = 0; i < sSrc.length; i++) {
        var nCharCode = sSrc.charCodeAt(i);
        if (nCharCode < 0x0020 || nCharCode>0x007E && nCharCode<0xFF60 || nCharCode>0xFF9F) {
            nByte += 2;
        } else {
            nByte += 1;
        }
    }
    
    return nByte;
}

/**
 * <PRE>
 * 半角チェック(Sift_JISでの1バイト)を行う。
 * すべての文字が半角の場合true、それ以外の場合falseを返す。
 * <B>引数</B>     sSrc (string型)
 * <B>返却値</B>   論理型
 *          true    すべての文字が半角
 *          false   いずれかの文字が半角ではない
 */
function isHalfWidthLetters(sSrc)
{
    if ("string" != typeof(sSrc)) {
        return false;
    }

    for (var i = 0; i < sSrc.length; i++) {
        var nCharCode = sSrc.charCodeAt(i);
        if (nCharCode < 0x0020 || nCharCode>0x007E && nCharCode<0xFF60 || nCharCode>0xFF9F) {
            return false;
        }
    }
    return true;
}

/**
 * <PRE>
 * 全角チェック(Sift_JISでの2バイト)を行う。
 * すべての文字が全角の場合true、それ以外の場合falseを返す。
 * <B>引数</B>     sSrc (string型)
 * <B>返却値</B>   論理型
 *          true    すべての文字が全角
 *          false   いずれかの文字が全角ではない
 * 備考     半角以外かつエスケープ文字でない場合trueとなる
 * </PRE>
 */
function isFullWidthLetters(sSrc)
{
    if ("string" != typeof(sSrc)) {
        return false;
    }

    for (var i = 0; i < sSrc.length; i++) {
        var cSrc= sSrc.charAt(i);
        if (isHalfWidthLetters(cSrc) == true || cSrc == '\n' || cSrc == '\b' ||
            cSrc == '\f' || cSrc == '\r' || cSrc == '\t') {
            return false;
        }
    }

    return true;
}

/**
 * <PRE>
 *  半角チェック(Sift_JISでの1バイト)を行う。
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 * <B>引数</B>     oSrc         処理対象オブジェクト
 *                 sFieldName   項目名
 * <B>返却値</B>   なし
 *
 * </PRE>
 */
function setHalfWidthFormatOnBlur(oSrc ,sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    // 右トリムを実施
    oSrc.value = getRightTrimmedString(oSrc.value);

    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }

    var sInputString = oSrc.value;
    
    // 日付の形式エラー
    if (isHalfWidthLetters(sInputString) == false) {
        showAlertDialog(sFieldName, "PRO-03005", CMMSG_PRO_03005);
        requestFocus(oSrc);
        return false;
    }
    
    return true;
}

/**
 * <PRE>
 *  全角チェック(Sift_JISでの2バイト)を行う。
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 * <B>引数</B>     oSrc         処理対象オブジェクト
 *                 sFieldName   項目名
 * <B>返却値</B>   なし
 *
 * </PRE>
 */
function setFullWidthFormatOnBlur(oSrc ,sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    // 右トリムを実施
    oSrc.value = getRightTrimmedString(oSrc.value);

    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }

    var sInputString = oSrc.value;
    
    // 日付の形式エラー
    if (isFullWidthLetters(sInputString) == false) {
        showAlertDialog(sFieldName, "PRO-03006", CMMSG_PRO_03006);
        requestFocus(oSrc);
        return false;
    }
    
    return true;
}

/**
 * <PRE>
 *   『入力可、入力不可の制御』
 *   引数で指定されたオブジェクトの入力可・不可の設定を行います。
 *   テキストフィールド（含むパスワード、テキストエリア）に関しては
 *   入力不可時にサブミットを行った場合値の送信が行われます。
 *   当メソッドは、動的に入力可・不可の設定を変更する場合使用して下さい。
 *   画面表示時から入力可・不可の変更が無い場合は、JSPに直接readOnly または
 *   disabledを指定して下さい。
 *
 *   (注意） オブジェクトのタイプがボタン（リセット、サブミット含む）
 *           コンボボックス、ラジオボタン、チェックボックスについては
 *           入力不可時にサブミットを行った場合値の送信が行われません。
 *           上記オブジェクトを入力不可にした場合でかつ値の送信を行う
 *           がある場合別途対策が必要です。
 * <B>引数</B>
 *          oSrc                処理対象オブジェクト
 *          bEnable             入力可不可
 *                              (true: 入力可  false:入力不可）
 * <B>返却値</B>   なし
 * </PRE>
 */
function setEnabled(oSrc, bEnable)
{
    if ("object" != typeof(oSrc)) {
        return;
    }

    if ("text" == oSrc.type || "password" == oSrc.type || "file" == oSrc.type || "textarea" == oSrc.type) {
        // 引数のオブジェクトが"Text","Password","TextArea","FileUpload"の場合
        if (bEnable == true) {
            oSrc.readOnly = false;
            oSrc.style.backgroundColor = "#FFFFFF";
            
            oSrc.style.cursor = "text";
            if(oSrc.tabIndex < 0)
            {
                oSrc.tabIndex = (oSrc.tabIndex + 1) * -1;
            }
        } else {
            oSrc.readOnly = true;
            //oSrc.style.backgroundColor = "#F0F0F0";
            oSrc.style.backgroundColor = "#FFFFFF";
            
            oSrc.style.cursor = "default";
            if(oSrc.tabIndex >= 0)
            {
                oSrc.tabIndex = (oSrc.tabIndex * -1) - 1;
            }
        }
    } else if ("button" == oSrc.type || "reset" == oSrc.type || "submit" == oSrc.type ||
               "select-one" == oSrc.type || "select-multiple" == oSrc.type) {
        // 引数のオブジェクトがボタン、コンボボックスの場合
        if (bEnable == true) {
            oSrc.disabled = false;
        } else {
            oSrc.disabled = true;
        }
    } else {
        if (oSrc.length && oSrc.length > 0) {
            if ("radio" == oSrc[0].type || "checkbox" == oSrc[0].type) {
                // 引数のオブジェクトが"Chekbox","Radio"の場合
                var bSet = false;
                if (bEnable == false) {
                    bSet = true;
                }

                if (oSrc.length) {
                    for (var i = 0; i < oSrc.length; i++) {
                        oSrc[i].disabled = bSet;
                    }
                }
            }
        } else {
            // 要素が1の"Chekbox","Radio"の場合
            if ("radio" == oSrc.type || "checkbox" == oSrc.type) {
                if (bEnable == true) {
                    oSrc.disabled = false;
                } else {
                    oSrc.disabled = true;
                }
            }
        }
    }
    
    return;
}


/********************************************************************************/
/*  ダイアログウィンドウ表示                                                    */
/********************************************************************************/


/**
 * <PRE>
 * 指定されたダイアログをOpenする。
 * <B>引数</B>
 *          sUrl    ダイアログに表示するhtmlファイル名やJSP名
 *          sFrame  ダイアログのフレーム名（トランジット属性）
 *          nWidth  ダイアログの幅
 *          nHeight ダイアログの高さ
 * <B>返却値</B>   なし
 * </PRE>
 */
function openDialog(sUrl, sFrame, nWidth, nHeight)
{
    var objWin = window.open(   sUrl, sFrame,
                                "toolbar=no, location=no, directories=no," +
                                "menubar=no, scrollbars=no ,resizable=no," +
                                "width=" + nWidth + ",height=" + nHeight + "," +
                                "left=0, top=0");
    return objWin;
}

/**
 * <PRE>
 * ヘルプダイアログををOpenする。
 * <B>引数</B>     sUrl ダイアログに表示するhtmlファイル名やJSP名
 * <B>返却値</B>   なし
 * </PRE>
 */
function openHelpDialog(sUrl)
{
    var objWin = window.open(   sUrl, "help",
                                "toolbar=no, location=no, directories=no," +
                                "menubar=no, scrollbars=yes ,resizable=no," +
                                "width=640 ,height=480, left=0 ,top=0");
    return objWin;
}


/********************************************************************************/
/*  ダイアログ表示                                                              */
/********************************************************************************/


/**
 * <PRE>
 * 警告ダイアログ(Alert)を表示する。
 * <B>引数</B>
 *          sTitle              タイトル
 *          sMessage_id         メッセージＩＤ
 *          sMessage            メッセージ
 * <B>返却値</B>   なし
 * </PRE>
 */
 
/**
 * <PRE>
 * ﾏﾔﾊｾｾｯｸ豢ｰｿﾚ
 * <B>ｲﾎﾊ</B>          
 *         sTitle       ｴｰｿﾚｱﾌ
 *         sMessage     ﾐﾅﾏ｢ﾄﾚﾈﾝ
 * <B></B>
 * <PRE>
 */
function showAlertDialog(sTitle,sMessage)
{
    alert(sTitle + "\n" + sMessage);
    return;
}

/**
 * <PRE>
 * 確認ダイアログ(Confirm)を表示する。
 * <B>引数</B>
 *              sTitle          タイトル
 *              sMessage_id     メッセージＩＤ
 *              sMessage        メッセージ
 * <B>返却値</B>
 *              論値型  true    OK ボタン押下
 *                      false   キャンセルボタン押下
 * </PRE>
 */
 
 /**
 * <PRE>
 * ﾏﾔﾊｾﾈｷﾈﾏｴｰｿﾚ
 * <B>ｲﾎﾊ</B>          
 *         sTitle       ｴｰｿﾚｱﾌ
 *         sMessage     ﾐﾅﾏ｢ﾄﾚﾈﾝ
 * <B></B>
 * <PRE>
 */
function showConfirmDialog(sTitle,sMessage)
{
    return confirm(sTitle + "\n" + sMessage);
}


/********************************************************************************/
/*  フォーカス遷移に伴なうフォーマット設定                                      */
/********************************************************************************/


/**
 * <PRE>
 * 『テキストフィールド（文字列）にフォーカスが設定された場合の処理』
 *  引数で指定されたテキストフィールドにフォーカスが設定された場合、入力文字列を選択状態にします。
 *
 *  『input要素、type属性 text(文字列)』
 *  『input要素、type属性 password』
 *  『input要素、type属性 file』で使用可能です。
 *
 * ＜使用例＞
 *  <input size="15" maxlength="15" name="wpText" type="text" onFocus="setTextFieldFormatOnFocus(this)">
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setTextFieldFormatOnFocus(oSrc)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if("object" != typeof(oSrc))
    {
        return;
    }
    
    // 引数のオブジェクトが"Text","Password","File"の場合のみ、処理を継続
    if("text" != oSrc.type && "password" != oSrc.type && "file" == oSrc.type)
    {
        return;
    }
    
    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return;
    }
    
    oSrc.select();
    
    return;
}

/**
 * <PRE>
 * 『テキストフィールド（文字列）のフォーカスが離れた場合の処理』
 *  引数で指定されたテキストフィールドのフォーカスが離れた時に入力バイト数(Shift_JIS)のチェックを行います。
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 *
 *  『input要素、type属性 text(文字列)』
 *  『input要素、type属性 password』
 *  『input要素、type属性 file』で使用可能です。
 *
 * ＜使用例＞
 *  <input size="15" maxlength="15" name="wpText" type="text" onBlur="setTextFieldFormatOnBlur(this, 'テキストフィールド')">
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 *              sFieldName      項目名
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setTextFieldFormatOnBlur(oSrc, sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    
    // 引数のオブジェクトが"Text","Password","File"の場合のみ、処理を継続
    if("text" != oSrc.type && "password" != oSrc.type && "file" == oSrc.type)
    {
        return true;
    }
    
    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }
    
    // 右トリムを実施
    oSrc.value = getRightTrimmedString(oSrc.value);
    
    // (注）maxLengthの大文字小文字は変更しないこと
    var nMaxLength = oSrc.maxLength;
    var nInputByte = getBytes(oSrc.value);

    if (nInputByte > nMaxLength) {
        showAlertDialog(sFieldName,"ﾊｾﾝｳ､ｶﾈｳｬｳｷｶﾎｧ!");
        requestFocus(oSrc);
        return false;
    }
    
    return true;
}

/**
 * <PRE>
 * 『テキストフィールド（日付）にフォーカスが設定された場合の処理』
 *  引数で指定されたテキストフィールドにフォーカスが設定された場合、入力文字列を選択状態にします。
 *
 *  『input要素、type属性 text(日付）』で使用可能です。
 *
 * ＜使用例＞
 *  <input size="10" maxlength="10" name="wpDateText" type="text" onFocus="setDateFieldFormatOnFocus(this)">
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setDateFieldFormatOnFocus(oSrc)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return;
    }
    
    // 引数のオブジェクトが"Text"の場合のみ、処理を継続
    if ("text" != oSrc.type) {
        return;
    }

    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return;
    }

    oSrc.select();
    
    return;
}

/**
 * <PRE>
 * 『テキストフィールド（日付）のフォーカスが離れた場合の処理』
 *  引数で指定されたテキストフィールドのフォーカスが離れた時に日付型のフォーマットチェックならびに
 *  表示用フォーマット(YYYY/MM/DD形式）の変換行います。
 *    例） 入力日付  011010 => 変換日付 2001/10/10
 *  年が2桁で指定された場合85未満を2000年台、85以上を1900年台として解釈します。
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 *
 *  『input要素、type属性 text(日付）』で使用可能です。
 *
 * ＜使用例＞
 *  <input size="10" maxlength="10" name="wpDateText" type="text" onBlur="setDateFieldFormatOnBlur(this, 'YMd', '日付フィールド')">
 *
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 *                                YYYY/MM/DD
 *                                YYYY-MM-DD
 *                                YYYYMMDD
 *                                YY/MM/DD
 *                                YY-MM-DD
 *                                YYMMDD
 *                                YYYY/MM
 *                                YYYY-MM
 *                                YYYYMM
 *                                YY/MM
 *                                YY-MM
 *                                YYMM
 *              sFormat         フォーマット指定文字列
 *                                YMD：日付まで必須
 *                                YMd：月まで必須、日付は任意
 *                                YM ：月まで必須
 *              sFieldName      項目名
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setDateFieldFormatOnBlur(oSrc, sFormat, sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    
    // 引数のオブジェクトが"Text"の場合のみ、処理を継続
    if ("text" != oSrc.type) {
        return true;
    }
    
    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }
    
    // 右トリムを実施
    oSrc.value = getRightTrimmedString(oSrc.value);

    if (sFormat != "YMD" && sFormat != "YMd" && sFormat != "YM") {
        return true;
    }

    var sInputString = oSrc.value;

    if (sInputString == "") {
        return true;
    }

    var sConvert = getDateFormattedString(sInputString, sFormat);
    
    // 日付の形式エラー
    if (sConvert == "") {
        showAlertDialog(sFieldName,"ﾇﾊ菠ﾕﾈｷﾈﾕﾆﾚｸﾊｽ!" + "\n" + "YYYYMMDD");
        requestFocus(oSrc);
        return false;
    }

    oSrc.value = sConvert;
    
    return true;
}

/**
 * <PRE>
 * 『文字列の日付型フォーマット変換』
 *  引数で指定された文字列の日付型のフォーマットチェックならびに
 *  表示用フォーマット(YYYY/MM/DD形式）の変換を行います。
 *    例） 入力日付  011010 => 変換日付 2001/10/10
 *  年が2桁で指定された場合85未満を2000年台、85以上を1900年台として解釈します。
 *  エラー時は、空文字列を返します。
 *
 * <B>引数</B>
 *              sValue            処理対象文字列
 *                                YYYY/MM/DD
 *                                YYYY-MM-DD
 *                                YYYYMMDD
 *                                YY/MM/DD
 *                                YY-MM-DD
 *                                YYMMDD
 *                                YYYY/MM
 *                                YYYY-MM
 *                                YYYYMM
 *                                YY/MM
 *                                YY-MM
 *                                YYMM
 *              sFormat         フォーマット指定文字列
 *                                YMD：日付まで必須
 *                                YMd：月まで必須、日付は任意
 *                                YM ：月まで必須
 *              sFieldName      項目名
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function getDateFormattedString(sValue, sFormat)
{
    // 両トリムを実施
    var sInputString = getTrimmedString(sValue);
    
    if (sInputString == "") {
        return "";
    }

    var bError = false;

    // 日付フォーマットのチェック
    var sTmpSplitStr;
    var nTmpYear   = 0;
    var nTmpMonth  = 0;
    var nTmpDay    = 0;
    var sTmpYear   = "";
    var sTmpMonth  = "";
    var sTmpDay    = "";
    var bUsedDay   = false;
    var BASE_YEAR = 85;

    // '/'区切り
    sTmpSplitStr = sInputString.split("/");
    if (sTmpSplitStr.length == 1) {
        // '-'区切り
        sTmpSplitStr = sInputString.split("-");
    }

    var bUsedSep;
    /****************************/
    /* 区切り文字ありの日付入力 */
    /****************************/
    if (sTmpSplitStr.length > 1) {
        bUsedSep = true;
        // YYYY/MM/DD,YY/MM/DD(DD任意含む),YYYY/MM,YY/MM形式
        // YYYY-MM-DD,YY-MM-DD(DD任意含む),YYYY-MM,YY-MM形式
        if ((sFormat == "YMD") && (sTmpSplitStr.length != 3)) {
            bError = true;
        } else if (sFormat == "YMd" && sTmpSplitStr.length != 3 && sTmpSplitStr.length != 2) {
            bError = true;
        } else if (sFormat == "YM" && sTmpSplitStr.length != 2) {
            bError = true;
        }

        // 数値以外の文字の混在チェック
        for (var i = 0; i < sTmpSplitStr.length; i++) {
            if (isNaN(sTmpSplitStr[i]) == true) {
                bError = true;
                break;
            }
        }

        if (bError == false) {
            // 年の取得
            sTmpYear = sTmpSplitStr[0];
            nTmpYear = Number(sTmpYear);

            // 年が2桁の場合4桁に変換
            if (sTmpYear.length == 2) {
                if (nTmpYear < BASE_YEAR) {
                    sTmpYear = "20" + sTmpYear;
                } else {
                    sTmpYear = "19" + sTmpYear;
                }
                nTmpYear = Number(sTmpYear);
            }

            // 月の取得
            sTmpMonth = sTmpSplitStr[1];
            nTmpMonth = Number(sTmpMonth);
            if (sTmpSplitStr.length == 3) {
                // 日の取得
                sTmpDay = sTmpSplitStr[2];
                nTmpDay = Number(sTmpDay);
                bUsedDay = true;
            }
        }
    /****************************/
    /* 区切り文字なしの日付入力 */
    /****************************/
    } else {
        bUsedSep = false;
         // 数値以外の文字の混在チェック
        if (isNaN(sInputString) == true) {
            bError = true;
        }

        // YYYYMMDD,YYMMDD形式
        if (sFormat == "YMD" && sInputString.length != 8 && sInputString.length != 6) {
            bError = true;
        } else if (sFormat == "YMd" && sInputString.length != 8 && sInputString.length != 6 &&
                   sInputString.length != 4) {
            bError = true;
        } else if (sFormat == "YM" && sInputString.length != 6 && sInputString.length != 4) {
            bError = true;
        }

        // 年月日の取得
        if (bError == false) {
            if (sInputString.length == 8) {
                // YYYYMMDD
                sTmpYear = sInputString.substring(0, 4);
                nTmpYear = Number(sTmpYear);
                sTmpMonth = sInputString.substring(4, 6);
                nTmpMonth = Number(sTmpMonth);
                sTmpDay = sInputString.substring(6, 8);
                nTmpDay = Number(sTmpDay);
                bUsedDay = true;
            } else if (sInputString.length == 6) {
                // YYYYMM
                sTmpYear = sInputString.substring(0, 4);
                nTmpYear = Number(sTmpYear);
                sTmpMonth = sInputString.substring(4, 6);
                nTmpMonth = Number(sTmpMonth);

                if (nTmpYear < 1900 || 3000 <= nTmpYear || nTmpMonth < 1 || 12 < nTmpMonth) {
                    // YYMMDD
                    sTmpYear = sInputString.substring(0, 2);
                    nTmpYear = Number(sTmpYear);
                    sTmpMonth = sInputString.substring(2, 4);
                    nTmpMonth = Number(sTmpMonth);
                    sTmpDay = sInputString.substring(4, 6);
                    nTmpDay = Number(sTmpDay);
                    bUsedDay = true;
                }
            } else if (sInputString.length == 4) {
                // YYMM
                sTmpYear = sInputString.substring(0, 2);
                nTmpYear = Number(sTmpYear);
                sTmpMonth = sInputString.substring(2, 4);
                nTmpMonth = Number(sTmpMonth);
            }

            // 年が2桁の場合4桁に変換
            if (sTmpYear.length == 2) {
                if (nTmpYear < BASE_YEAR) {
                    sTmpYear = "20" + sTmpYear;
                } else {
                    sTmpYear = "19" + sTmpYear;
                }
                nTmpYear = Number(sTmpYear);
            }
        }
    }

    // 年の有効範囲チェック
    if (nTmpYear < 0 || 9999 < nTmpYear) {
        bError = true;
    }
    // 月の有効範囲チェック
    if (nTmpMonth < 1 || 12 < nTmpMonth) {
        bError = true;
    }

    // 日の有効範囲チェック
    if (sFormat == "YMD" && (nTmpDay < 1 || 31 < nTmpDay)) {
        bError = true;
    } else if (sFormat == "YMD" && bUsedDay == true && (nTmpDay < 1 || 31 < nTmpDay)) {
        bError = true;
    }

    // 晦日チェック
    if(sFormat == "YMD" && ((nTmpMonth  == 4) == true || (nTmpMonth  == 6) == true ||
        (nTmpMonth  == 9) == true || (nTmpMonth  == 11) == true) )
    {
        if( 31 <= nTmpDay )
        {
            bError = true;
        }
    }
    // うるう年チェック
    if(sFormat == "YMD" && ((nTmpMonth == 2) == true))
    {
        //年は、4で割り切れて、100で割り切れない、若しくは400で割り切れるか？
        if( ((nTmpYear % 4) == 0 && (nTmpYear % 100) != 0) || (nTmpYear % 400) == 0 )
        {
            if( 29 < nTmpDay )
            {
                bError = true;
            }
        }
        else
        {
            if( 28 < nTmpDay )
            {
                bError = true;
            }
        }
    }
    
    if(bError == true)
    {
        return "";
    }
    
    // YYYY/MM/DD形式に変換する
    var sConvert = "";              // 変換文字列
    if (sFormat == "YMD") {
        sConvert = sTmpYear + "/" + sTmpMonth + "/" + sTmpDay;
    } else if (sFormat == "YMd") {
        if (bUsedDay == true) {
            sConvert = sTmpYear + "/" + sTmpMonth + "/" + sTmpDay;
        } else {
            sConvert = sTmpYear + "/" + sTmpMonth;
        }
    } else if (sFormat == "YM") {
        sConvert = sTmpYear + "/" + sTmpMonth;
    }
    
    return sConvert;
}

/**
 * <PRE>
 * 『テキストフィールド（数値）にフォーカスが設定された場合の処理』
 *  引数で指定されたテキストフィールドにフォーカスが設定された時にカンマ編集を解除し、入力文字列を
 *  選択状態にします。
 *
 *  『input要素、type属性 text(数値）』で使用可能です。
 *
 * ＜例＞
 *   入力文字     1,000
 *   変換文字     1000
 * ＜使用例＞
 *   <input size="15" maxlength="15" name="wpNumberText" type="text" onFocus="setNumberFieldFormatOnFocus(this)">
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setNumberFieldFormatOnFocus(oSrc)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return;
    }
    
    // 引数のオブジェクトが"Text"の場合のみ、処理を継続
    if ("text" != oSrc.type) {
        return;
    }

    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return;
    }
    
    var sInputString = oSrc.value;

    if (sInputString == "") {
        return;
    }

    // 入力文字列のカンマ編集を外す
    while (sInputString.indexOf(",") != -1) {
        sInputString = sInputString.replace(",", "");
    }

    oSrc.value = sInputString;
    oSrc.select();
    
    return;
}

/**
 * <PRE>
 * 『テキストフィールド（数値）のフォーカスが離れた場合の処理』
 *  引数で指定されたテキストフィールドのフォーカスが離れた時にフォーマットチェック,桁数チェックおよび
 *  フォーマット変換を行います
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 *
 *  『input要素、type属性 text(数値）』で使用可能です。
 *
 * ＜例＞
 *   入力文字     1,000  フォーマット文字 ###,###.00#
 *   変換文字     1000.00
 * ＜使用例＞
 *   <input size="15" maxlength="15" name="wpNumberText" type="text" onBlur="setNumberFieldFormatOnBlur(this, 10, 3, '###,000.00#', 'テキストフィールド')">
 *
 *
 * <B>引数</B>
 *              oSrc            処理対象テキストフィールド
 *              nAllDigit       全体桁数
 *              nDecimalDigit   小数部桁数
 *              sFormat         フォーマット指定文字列
 *                                フォーマット指定文字列にて使用可能な文字
 *                                0  ,  .  #
 *                                # は任意の数字を表す。
 *                                0 は変換対象数値の小数部が書式の小数部よりも小さい場合、
 *                                  不足桁数分0を小数部に追加する。
 *              sFieldName      項目名
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setNumberFieldFormatOnBlur(oSrc, nAllDigit, nDecimalDigit, sFormat, sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    
    // 引数のオブジェクトが"Text"の場合のみ、処理を継続
    if ("text" != oSrc.type) {
        return true;
    }
    
    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }
    
    // 右トリムを実施
    var sInputString = getRightTrimmedString(oSrc.value);
    if (sInputString == "") {
        return true;                             // 入力文字列が空の場合処理しない
    }
    
    if(sInputString == "0"){
    	return true;
    }
    
    /****************************/
    /*      桁数チェック        */
    /****************************/
    // 左トリムを実施
    sInputString = getLeftTrimmedString(oSrc.value);
    
    // 先頭に符号があれば符号を削除する
    while (sInputString.charAt(0) == '+' || sInputString.charAt(0) == '-') {
        sInputString = sInputString.substring(1, sInputString.length);
    }

    // 入力文字列のカンマ編集を外す
    while (sInputString.indexOf(",") != -1) {
        sInputString = sInputString.replace(",", "");
    }
	
    var sInputIntPart = "";             // 整数部文字列
    var sInputDecPart = "";             // 小数部文字列
    var nInputIntDigit = 0;             // 整数部文字列桁数
    var nInputDecDigit = 0;             // 小数部文字列桁数
    var bAnyDecimalPart = false;
    var nInputAllDigit = 0;

    // 入力文字列の整数部、小数部の分割
    if (sInputString.indexOf(".") == -1) {
        sInputIntPart = sInputString;
        nInputIntDigit = sInputString.length;
    } else {
        var sTmp = "";
        sTmp = sInputString.split(".");
        sInputIntPart = sTmp[0];
        nInputIntDigit = sInputIntPart.length;
        sInputDecPart = sTmp[1];
        nInputDecDigit = sInputDecPart.length;
        bAnyDecimalPart = true;
    }
    
    // 入力文字列の数値部分の桁数取得
    nInputAllDigit = nInputIntDigit + nInputDecDigit;

    // 入力桁数超過チェック
    if (nInputAllDigit > nAllDigit || nInputDecDigit > nDecimalDigit ||
        nInputIntDigit > (nAllDigit - nDecimalDigit)) {
        showAlertDialog(sFieldName,"ﾊｾﾝｳ､ｶﾈｳｬｳｷｶﾎｧ!");
        requestFocus(oSrc);
        return false;
    }
    
    // 数値フォーマット処理実行
    var sConvString = getNumberFormattedString( oSrc.value, nAllDigit, nDecimalDigit, sFormat );
    
    // フォーマットエラー時
    if(sConvString == "")
    {
        showAlertDialog(sFieldName,"ﾊ菠ﾖﾐｴ贇ﾚｷﾇﾊﾗﾖﾊｾﾝ!");
        requestFocus(oSrc);
        return false;
    }
    else
    {
        oSrc.value = sConvString;
    }
    
    return true;
}

/**
 * <pre>
 * 『文字列の数値型フォーマット変換』
 *  文字列を引数で指定されたフォーマット形式で変換します。
 *  数値とみなされない文字が含まれていた場合はエラーとなり、空文字列を返します。
 *
 * ＜例＞
 *   入力文字     1,000  フォーマット文字 ###,###.00#
 *   変換文字     1000.00
 *
 * <B>引数</B>
 *              sValue          変換対象文字列
 *              nAllDigit       全体桁数
 *              nDecimalDigit   小数部桁数
 *              sFormat         フォーマット指定文字列
 *                                フォーマット指定文字列にて使用可能な文字
 *                                0  ,  .  #
 *                                # は任意の数字を表す。
 *                                0 は変換対象数値の小数部が書式の小数部よりも小さい場合、
 *                                  不足桁数分0を小数部に追加する。
 * <B>返却値</B>
 *              正常時　　フォーマットされた文字列
 *              エラー時　空文字列
 * </pre>
 */
function getNumberFormattedString( sValue, nAllDigit, nDecimalDigit, sFormat )
{
    // トリムを実施
    var sInputString = getTrimmedString(sValue);

    // 先頭に符号があるか判定
    var bMinus = false;                 // マイナス符号指定有無
    var bPlus  = false;                 // プラス符号指定有無

    // 符号が連続する場合最後の符号を解釈する
    // 例）+-+-140 の場合 -140と解釈
    while (sInputString.charAt(0) == '+' || sInputString.charAt(0) == '-') {
        if (sInputString.charAt(0) == '+') {
            bPlus  = true;
            bMinus = false;
        } else if (sInputString.charAt(0) == '-') {
            bMinus = true;
            bPlus  = false;
        }

        // 先頭に符号があれば符号を削除する
        if (bMinus == true || bPlus == true) {
            sInputString = sInputString.substring(1, sInputString.length);
        }
    }

    // 入力文字列のカンマ編集を外す
    while (sInputString.indexOf(",") != -1) {
        sInputString = sInputString.replace(",", "");
    }

    // 入力文字に数値以外の文字が存在するかチェック
    if (isNaN(sInputString) == true) {
        return "";
    }

    //
    var sFmtWork = sFormat;
    while (sFmtWork.indexOf(",") != -1) {
        sFmtWork = sFmtWork.replace(",", "");
    }

    var nFmtAllDigit = 0;               // フォーマット文字列桁数
    var nFmtIntDigit = 0;               // フォーマット文字列桁数（整数部）
    var nFmtDecDigit = 0;               // フォーマット文字列桁数（小数部）
    var sFmtIntPart = "";               // フォーマット文字列（整数部）
    var sFmtDecPart = "";               // フォーマット文字列（小数部）
    if (sFmtWork.indexOf(".") == -1) {
        nFmtIntDigit = sFmtWork.length;
        sFmtIntPart = sFmtWork;
    } else {
        var sTmp = sFmtWork.split(".");
        sFmtIntPart = sTmp[0];
        sFmtDecPart = sTmp[1];
        nFmtIntDigit = sFmtIntPart.length;
        nFmtDecDigit = sFmtDecPart.length;
    }
    nFmtAllDigit = nFmtIntDigit + nFmtDecDigit;

    var sInputIntPart = "";             // 整数部文字列
    var sInputDecPart = "";             // 小数部文字列
    var nInputIntDigit = 0;             // 整数部文字列桁数
    var nInputDecDigit = 0;             // 小数部文字列桁数
    var bAnyDecimalPart = false;
    var nInputAllDigit = 0

    // 入力文字列の整数部、小数部の分割
    if (sInputString.indexOf(".") == -1) {
        sInputIntPart = sInputString;
        nInputIntDigit = sInputString.length;
    } else {
        var sTmp = "";
        sTmp = sInputString.split(".");
        sInputIntPart = sTmp[0];
        nInputIntDigit = sInputIntPart.length;
        sInputDecPart = sTmp[1];
        nInputDecDigit = sInputDecPart.length;
        bAnyDecimalPart = true;
    }

    nInputAllDigit = nInputIntDigit + nInputDecDigit;

    // 整数部の前Zeroを削除する
    var sWork = sInputIntPart;
    while (sWork.indexOf(",") != -1) {
        sWork = sWork.replace(",",  "");
    }

    // 書式を整数部と小数部に分ける
    if (sFormat.indexOf(".") == -1) {
        sFmtIntPart = sFormat;
        sFmtDecPart = "";
    } else {
        sFmtIntPart = sFormat.substr(0, sFormat.indexOf("."));
        sFmtDecPart = sFormat.substr(sFormat.indexOf(".") + 1, sFormat.length);
        bAnyDecimalPart = true;
    }

    // フォーマット文字列長が、入力最大桁数に満たない場合はフォーマット文字列を補完する
    // 整数部フォーマット文字列の','を取り除いた長さを求める
    sWork = sFmtIntPart;
    while (sWork.indexOf(",") != -1) {
        sWork = sWork.replace(",",  "");
    }
    var nFmtIntPartDigit = sWork.length;

    // 整数部のフォーマット文字列が入力最大桁数以下の場合
    // 入力桁数を超過するまで、先頭の位置よりフォーマット文字列を繰り返し追加する
    var sOrgFmtIntPart = sFmtIntPart;
    while (nFmtIntPartDigit < (nAllDigit - nDecimalDigit)) {
        var nStartPos = sFmtIntPart.indexOf(",");
        if (nStartPos == -1) {
            nStartPos = 0;
        }
        sWork = sFmtIntPart.substring(nStartPos, sFmtIntPart.length);
        sFmtIntPart = sOrgFmtIntPart + sWork;

        // 整数部フォーマット文字列の','を取り除いた長さを求める
        sWork = sFmtIntPart;
        while (sWork.indexOf(",") != -1) {
            sWork = sWork.replace(",",  "");
        }
        nFmtIntPartDigit = sWork.length;
    }

    // 小数部フォーマット文字列の','を取り除いた長さを求める
    sWork = sFmtDecPart;
    while (sWork.indexOf(",") != -1) {
        sWork = sWork.replace(",",  "");
    }
    var nFmtDecPartDigit = sWork.length;

    // 小数部のフォーマット文字列が入力最大桁数以下の場合
    // 入力桁数を超過するまで、最後尾に#を繰り返し追加する
    while (sFmtDecPart.length < nDecimalDigit) {
        sFmtDecPart = sFmtDecPart + "#";
    }

    // 整数部を書式の長さにあわせるために、前に空白を追加
    var nIntegerPartLen = sInputIntPart.length;
    for (var i = 0; i < sFmtIntPart.length - nIntegerPartLen; i++ ) {
        sInputIntPart = " " + sInputIntPart;
    }

    // 整数部を書式に従って変換
    var nIntegerPartPos = sInputIntPart.length;
    var nIntegerFmtPartPos = sInputIntPart.length;
    var sConvString = "";

    for ( ;nIntegerFmtPartPos > 0; nIntegerPartPos--, nIntegerFmtPartPos--) {
        if (sFmtIntPart.charAt(nIntegerFmtPartPos - 1) == '0') {
            if (sInputIntPart.charAt(nIntegerPartPos - 1) == ' ') {
                sConvString = "0" + sConvString;
            } else {
                sConvString = sInputIntPart.charAt(nIntegerPartPos - 1) + sConvString;
            }
        } else if (sFmtIntPart.charAt(nIntegerFmtPartPos - 1) == '#') {
            if (sInputIntPart.charAt(nIntegerPartPos - 1) == ' ') {
                break;
            } else {
                sConvString = sInputIntPart.charAt(nIntegerPartPos - 1) + sConvString;
            }
        } else if (sFmtIntPart.charAt(nIntegerFmtPartPos - 1) == ',') {
            if (sInputIntPart.charAt(nIntegerPartPos - 1) != ' ') {
                sConvString = sInputIntPart.charAt(nIntegerPartPos - 1) + "," + sConvString;
                nIntegerFmtPartPos--;
            } else {
                break;
            }
        }
    }
    
    // 少数部以下も書式にあわせて変換する
    if (bAnyDecimalPart == true) {
        sWork = "";
        for (var i = 0;i < sFmtDecPart.length;i++ ) {
            if (sFmtDecPart.charAt(i) == '0') {
                if (i < sInputDecPart.length) {
                    sWork = sWork + sInputDecPart.charAt(i);
                } else {
                    sWork = sWork + '0';
                }
            } else if (sFmtDecPart.charAt(i) == '#') {
                if (i < sInputDecPart.length) {
                    sWork = sWork + sInputDecPart.charAt(i);
                } else {
                    break;
                }
            }
        }
        if (sWork != "") {
            sConvString = sConvString + "." + sWork;
        }
    }

    // 前ZEROの削除
    if (sConvString.length > 1) {
        while (sConvString.charAt(0) == '0' || sConvString.charAt(0) == ',') {
            sConvString = sConvString.substr(1, sConvString.length);
        }

        // 先頭が'.'の場合前ZEROを付加
        if (sConvString.charAt(0) == '.') {
            sConvString = "0" + sConvString;
        }
    }

    // マイナス符号が入力された場合マイナス符号を先頭に付加
    if (bMinus == true) {
        sConvString = "-" + sConvString;
    }
    
    return sConvString;
}

/**
 * <PRE>
 * 『テキストエリアにフォーカスが設定された場合の処理』
 *  引数で指定されたテキストエリアにフォーカスが設定された時に入力文字列を選択状態にします。
 *
 *  『textarea要素』で使用可能です。
 *
 * ＜使用例＞
 *  <textarea name="wpArea" rows="3" cols="50" onFocus="setTextAreaFormatOnFocus(this)">
 *  </textarea>
 * <B>引数</B>
 *              oSrc            処理対象テキストエリア
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setTextAreaFormatOnFocus(oSrc)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return;
    }
    
    // 引数のオブジェクトが"TextArea"の場合のみ、処理を継続
    if ("textarea" != oSrc.type) {
        return;
    }

    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return;
    }
    
    oSrc.select();
    
    return;
}

/**
 * <PRE>
 * 『テキストエリアのフォーカスが離れた場合の処理』
 *  引数で指定されたテキストエリアのフォーカスが離れた時に入力バイト数(Shift_JIS)のチェックを行います。
 *  エラー時は自動的に警告ダイアログ(Alert)を表示し、再入力を促します。
 *
 *  『textarea要素』で使用可能です。
 *
 * ＜使用例＞
 *  <textarea name="wpArea" rows="3" cols="50" onBlur="setTextAreaFormatOnBlur(this, 10, 'テキストエリア')">
 *  </textarea>
 * <B>引数</B>
 *              oSrc            処理対象テキストエリア
 *              nByte           入力文字数(Byte)
 *              sFieldName      項目名
 * <B>返却値</B>
 *              なし
 * </PRE>
 */
function setTextAreaFormatOnBlur(oSrc, nByte, sFieldName)
{
    // 引数のタイプがobjectの場合のみ、処理を継続
    if ("object" != typeof(oSrc)) {
        return true;
    }
    
    // 引数のオブジェクトが"TextArea"の場合のみ、処理を継続
    if ("textarea" != oSrc.type) {
        return true;
    }
    
    // 編集不可項目時
    if (oSrc.readOnly == true) {
        return true;
    }
    
    // 右トリムを実施
    oSrc.value = getRightTrimmedString(oSrc.value);

    var nInputByte = getBytes(oSrc.value)
    if (nInputByte > nByte) {
        showAlertDialog(sFieldName, "PRO-03001", CMMSG_PRO_03001);
        requestFocus(oSrc);
        return false;
    }
    
    return true;
}

