;
var formOnloadStatus = false;

// start : for pc site -----------------------------------------------------
var OK_icon = '<img src="' + OK_icon_src + '" width="13" height="13" alt="" class="td_color1" style="border: none; padding: 0px; margin: 0px 3px 0px;" />';
var NG_icon = '<img src="' + NG_icon_src + '" width="13" height="13" alt="" class="td_color1" style="border: none; padding: 0px; margin: 0px 3px 0px;" />';
var messageBr = '<br />';
var loadingDisplay1 = '<img src="' + SEARCH_icon_src + '" width="13" height="13" class="td_color1" style="border: none; padding: 0px; margin: 0px 3px 0px;" />';
var loadingDisplay2 = '<img src="' + SEARCH_icon_src + '" width="13" height="13" class="td_color1" style="border: none; padding: 0px; margin: 0px 3px 0px;" />';
var needStateUpperBorder = false;

// エラー表示OFF
function hideErrorDisplay(msgElem, strict) {
    if (!formOnloadStatus || !globalObj.formErrorStatus) {
        return;
    }
    var name = msgElem.replace(/_status/, '');
    var errorBox = $$('.form_error_box');
    var blockElem = $(name + '_block');
    if (blockElem) {
        var borderElem = $(name + '_border');
        var noticeElem = $(name + '_notice');
        if (!strict) {
            if (Element.hasClassName(blockElem, 'form_alpha')) {
                Element.removeClassName(blockElem, 'form_alpha');
            }
        }
        if (Element.hasClassName(blockElem, ERROR_CLASS)) {
            Element.removeClassName(blockElem, ERROR_CLASS);
            if (borderElem) {
                borderElem.style.display = 'none';
            }
            if (noticeElem) {
                noticeElem.style.display = 'none';
            }
        }
    }
    if (errorBox[0] && errorBox[0].style.display !== 'none' && $$('.' + ERROR_CLASS).length === 0) {
        errorBox.each(function(elem) {
            elem.style.display = 'none';
        });
    }
}

// 透過表示OFF
function hideDiaphanousDisplay(msgElem) {
    if (!formOnloadStatus || !globalObj.formErrorStatus) {
        return;
    }
    var name = msgElem.replace(/_status/, '');
    var blockElem = $(name + '_block');
    if (blockElem && Element.hasClassName(blockElem, 'form_alpha')) {
        Element.removeClassName(blockElem, 'form_alpha');
    }
}

// 州上部線フラグ
function getNeedStateUpperBorder() {
    var needBorder = false;
    if (browserType === 'ie8') {
        var blockElem = $('address_localarea_block');
        if (blockElem && Element.hasClassName(blockElem, 'form_alpha')) {
            needBorder = true;
        }
    }
    return needBorder;
}

// 区切り線の表示切り替え
function toggleFormLine(msgElem, value) {
    var name = msgElem.replace(/_status/, '');
    var borderElem = $(name + '_border');
    var blockElem = $(name + '_block');
    if (value === 'none') {
        if (borderElem) {
            borderElem.style.display = 'none';
        }
    } else {
        if (borderElem && blockElem && (Element.hasClassName(blockElem, ERROR_CLASS) || needStateUpperBorder)) {
            borderElem.style.display = value;
        }
    }
}

function loginCheck(emailElem, passwordElem) {
    if ($F(emailElem) && $F(passwordElem)) {
        hideErrorDisplay(emailElem);
        hideErrorDisplay(passwordElem);
    }
}
// end : for pc site -----------------------------------------------------

// 簡単な入力チェック
function checkEasyInput(elem, msgElem, required, strict) {
    if ($F(elem).length==0) {
        if (required) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;
            if (!strict) {
                hideDiaphanousDisplay(msgElem);
            }
            return false;
        }
        else {
            $(msgElem).innerHTML = "";
        }
    }
    else {
        $(msgElem).innerHTML = OK_icon;
        hideErrorDisplay(msgElem, strict);
    }
    return true;
}

// 簡単な選択チェック
function checkEasySelect(elem, msgElem, required) {
    if ($F(elem)=="") {
        if (required) {
            $(msgElem).innerHTML = NG_icon + MSG_SELECT;
            hideDiaphanousDisplay(msgElem);
        }
        else {
            $(msgElem).innerHTML = "";
            hideErrorDisplay(msgElem);
        }
    } else {
        $(msgElem).innerHTML = OK_icon;
        hideErrorDisplay(msgElem);
    }
}

// ！(必須)をセット
function setRequired(msgElem, required) {
    if (required) {
        if ($(msgElem)) {
            $(msgElem).innerHTML = LBL_REQUIRED;
        }
    } else {
        if ($(msgElem)) {
            $(msgElem).innerHTML = "&nbsp;";
        }
    }
}

// 郵便番号チェック
var latestPostal;
function checkPostalInput(elem1, elem2, msgElem, required, convert, target_pref, target_address1, target_address2, language) {

    // 郵便番号から住所をセット
    function addressSet(request) {
        var result = eval('(' + request.responseText + ')');

        if (result.error) {
            $(msgElem).innerHTML = NG_icon + MSG_NOPOST;
            // フォームリセット
            $(target_address1).value = "";
            $(target_address2).value = "";
            $(target_pref+"_status").innerHTML = "";
            $(target_address1+"_status").innerHTML = "";
            $(target_address2+"_status").innerHTML = "";
        }
        else {
            $(msgElem).innerHTML = OK_icon;
            if (result['pref_no']) {
                $(target_pref).value = result['pref_no'];
                $(target_pref+"_status").innerHTML = OK_icon;
                hideErrorDisplay(msgElem);
                hideErrorDisplay(target_pref+"_status");
            } else {
                $(target_pref+"_status").innerHTML = "";
            }

            if (result['address1']) {
                $(target_address1).value = result['address1'];
                $(target_address1+"_status").innerHTML = OK_icon;
                hideErrorDisplay(target_address1+"_status");

                $(target_address2).value = result['address2'];

                if (result['address2']) {
                    $(target_address2+"_status").innerHTML = NG_icon + MSG_BANCHI;
                } else {
                    $(target_address2+"_status").innerHTML = "";
                }
                hideDiaphanousDisplay(target_address2+"_status");
            } else {
                $(target_address1+"_status").innerHTML = "";
                hideDiaphanousDisplay(target_address1+"_status");
            }
        }
    }

    if ((($F(elem1).length==0 || $F(elem2).length==0) && $F('address_pref') != '48') || ($F(elem1).length==0 && $F('address_pref') == '48')) {
        $(msgElem).innerHTML = NG_icon + MSG_INPUT;
    } else if ((!$F(elem1).match(/^[0-9]{3}$/) || !$F(elem2).match(/^[0-9]{4}$/)) && $F('address_pref') != '48') {
        $(msgElem).innerHTML = NG_icon + MSG_NUMERIC1;
    } else if ($F('address_pref') != '48') {
        // 上3桁・下4桁がきちんと入力されている場合のみ
        // タブとか→とかを押した場合はチェックしないようにする
        if (convert) {
            if ($F(elem1) == '000' && $F(elem2) == '0000') {
                $(msgElem).innerHTML = OK_icon;
                hideErrorDisplay(msgElem);
                latestPostal = $F(elem1) + $F(elem2);
                // 日本国外
                $(target_pref+"_status").innerHTML = OK_icon;
                hideErrorDisplay(target_pref+"_status");
                $(target_pref).value = '48';
                $(target_address1+"_status").innerHTML = "";
                $(target_address2+"_status").innerHTML = "";
                checkCountry(language, false);
                hideDiaphanousDisplay("address_country_status");
            }
            else if (($F(elem1) + $F(elem2)) != latestPostal) {
                $(msgElem).innerHTML = loadingDisplay1;
                latestPostal = $F(elem1) + $F(elem2);
                // メッセージ表示
                $(target_pref+"_status").innerHTML = loadingDisplay1;
                $(target_address1+"_status").innerHTML = loadingDisplay2;
                $(target_address2+"_status").innerHTML = loadingDisplay2;
                // parsは他にも必要な情報があれば入れる
                var pars = "go=address-search&post_number=" + $F(elem1) + $F(elem2);
                var myAjax = new Ajax.Request (
                    xmlUrl,
                    {
                        method: 'get',
                        parameters: pars,
                        onComplete: addressSet
                    }
                );
            }
            else if (!latestPostal) {
                $(msgElem).innerHTML = OK_icon;
                hideErrorDisplay(msgElem);
            }
            checkOverSeaTel();
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
            latestPostal = $F(elem1) + $F(elem2);
        }
    } else {
        $(msgElem).innerHTML = OK_icon;
        hideErrorDisplay(msgElem);
    }
}

// メールアドレスチェック
var latestEmail;
function checkEmailInput(elem, msgElem, required, overlap) {

    if ($F(elem).length==0) {
        if (required) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;
        }
        else {
            $(msgElem).innerHTML = "";
        }
        latestEmail = "";
    } else if (!$F(elem).match(/^[\/0-9A-Za-z_-][+?\/0-9A-Za-z.._-]*@[0-9A-Za-z_-]+[\.]+[0-9A-Za-z_..-]+[A-Za-z]$/)) {
        $(msgElem).innerHTML = NG_icon + MSG_NUMERIC2;
        latestEmail = "";
    } else {
        if (overlap) {
            checkOverlapEmail(elem, msgElem, 1, '');
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
        }
    }
}

var latestOverlap = {email:'', error:false};
function checkOverlapEmail(elem1, msgElem, login, elem2) {
    var res1 = true;
    var res2 = true;
    var email = $F(elem1);
    if (!email) {
        $(msgElem).innerHTML = OK_icon;
        res1 = true;
        if (elem2) {
            res2 = checkConfirmEmail(elem1, elem2);
            if (res1 && res2) {
                hideErrorDisplay(msgElem);
            }
        } else {
            hideErrorDisplay(msgElem);
        }
        return;
    } else {
        if (email === latestOverlap.email) {
            if (latestOverlap.error === true) {
                $(msgElem).innerHTML = NG_icon + MSG_OVERLAP;
                res1 = false;
                if (elem2) {
                    res2 = checkConfirmEmail(elem1, elem2);
                }
                return;
            } else {
                $(msgElem).innerHTML = OK_icon;
                res1 = true;
                if (elem2) {
                    res2 = checkConfirmEmail(elem1, elem2);
                    if (res1 && res2) {
                        hideErrorDisplay(msgElem);
                    }
                } else {
                    hideErrorDisplay(msgElem);
                }
                return;
            }
        }
    }
    var pars = 'go=check-overlap-email&email=' + email;
    if (login) {
        pars += '&login=' + login;
    }
    var myAjax = new Ajax.Request (
        xmlUrl,
        {
            method: 'post',
            parameters: pars,
            onComplete: function (httpObj) {
                latestOverlap.email = email;
                if (httpObj && httpObj.responseText === '1') {
                    $(msgElem).innerHTML = NG_icon + MSG_OVERLAP;
                    latestOverlap.error = true;
                    res1 = false;
                    if (elem2) {
                        res2 = checkConfirmEmail(elem1, elem2);
                    }
                } else {
                    $(msgElem).innerHTML = OK_icon;
                    latestOverlap.error = false;
                    res1 = true;
                    if (elem2) {
                        res2 = checkConfirmEmail(elem1, elem2);
                        if (res1 && res2) {
                            hideErrorDisplay(msgElem);
                        }
                    } else {
                        hideErrorDisplay(msgElem);
                    }
                }
            }
        }
    );
}

function checkConfirmEmail(elem1, elem2) {
    var msgElem = elem2 + '_status';
    var res = false;
    if ($F(elem2).length==0) {
        $(msgElem).innerHTML = NG_icon + MSG_INPUT;
    } else if ($F(elem2).match(/[^+?\/0-9A-Za-z@\._-]+/)) {
        $(msgElem).innerHTML = NG_icon + MSG_NUMERIC2;
    } else if (!$F(elem2).match(/^[\/0-9A-Za-z_-][+?\/0-9A-Za-z.._-]*@[0-9A-Za-z_-]+[\.]+[0-9A-Za-z_..-]+[A-Za-z]$/)) {
        $(msgElem).innerHTML = NG_icon + MSG_INPUT2;
    } else if ($F(elem1) != $F(elem2)) {
        $(msgElem).innerHTML = NG_icon + MSG_NOMATCH;
    } else {
        $(msgElem).innerHTML = OK_icon;
        res = true;
    }
    return res;
}

//電話番号orFAXチェック
function checkTelInput(elem1, elem2, elem3, msgElem, required, strict) {
    var result = true;
    var useStatusDisplay = true;
    var allEmptyCheck = function() {
        if ($F(elem1).length==0 && $F(elem2).length==0 && $F(elem3).length==0) {
            return true;
        }
        return false;
    };
    var emptyValueCheck = function() {
        if ($F(elem1).length==0 || $F(elem2).length==0 || $F(elem3).length==0) {
            return true;
        }
        return false;
    };
    var jpTelCheck = function() {
        if (!$F(elem1).match(/^[0-9]+$/) || !$F(elem2).match(/^[0-9]+$/) || !$F(elem3).match(/^[0-9]{4}$/)) {
            $(msgElem).innerHTML = NG_icon + MSG_NUMERIC1;
            return false;
        }
        return true;
    };
    var enTelCheck = function() {
        if ((!$F(elem1).match(/^[0-9\+(][0-9 \.\+()]{1,9}$/) || !$F(elem2).match(/^[0-9 \.\+()]{1,10}$/) || !$F(elem3).match(/^[0-9 \.\+()]{1,9}[0-9]$/))) {
            $(msgElem).innerHTML = NG_icon + MSG_NUMERIC5;
            return false;
        }
        return true;
    };
    if (required) {
        if (emptyValueCheck()) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;;
            result = false;
        } else {
            if ($F('address_pref') != 48) {
                result = jpTelCheck();
                changeTelNotice(msgElem, false);
            } else {
                result = enTelCheck();
                changeTelNotice(msgElem, true);
            }
        }
    } else {
        if (allEmptyCheck()) {
            $(msgElem).innerHTML = "";
            useStatusDisplay = false;
        } else if (emptyValueCheck()) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;
            result = false;
        } else {
            if ($F('address_pref') != 48) {
                result = jpTelCheck();
                changeTelNotice(msgElem, false);
            } else {
                result = enTelCheck();
                changeTelNotice(msgElem, true);
            }
        }
    }
    if (result) {
        hideErrorDisplay(msgElem, strict);
        if (useStatusDisplay) {
            $(msgElem).innerHTML = OK_icon;
        }
    }
}

// 海外電話番号orFAXチェック
function checkTelInputEng(elem, msgElem, required) {
    var tmp_elem = $F(elem);
    if (required) {
        if (tmp_elem.length==0) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;
        } else if (!tmp_elem.match(/^[0-9+(][0-9 \.\-\+()]{1,28}[0-9]$/)) {
            $(msgElem).innerHTML = NG_icon + MSG_NUMERIC4;
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
        }
    } else {
        if (tmp_elem.length==0) {
            $(msgElem).innerHTML = "";
            hideErrorDisplay(msgElem);
        } else if (!tmp_elem.match(/^[0-9+(][0-9 \.\-\+()]{1,28}[0-9]$/)) {
            $(msgElem).innerHTML = NG_icon + MSG_NUMERIC4;
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
        }
    }
}

// 電話番号orFAX注意書き変更
function changeTelNotice(msgElem, en) {
    if (!en) {
        $('before_' + msgElem).innerHTML = MSG_NUMERIC3;
        $('after_' + msgElem).innerHTML = '';
        $('after_' + msgElem).style.display = 'inline';
    } else {
        $('before_' + msgElem).innerHTML = '';
        $('after_' + msgElem).innerHTML = MSG_NUMERIC4;
        $('after_' + msgElem).style.display = 'block';
    }
};

// パスワードチェック
function checkPasswordInput(elem, msgElem, elem2, msgElem2, required) {

    if (required) {
        if ($F(elem).length==0) {
            $(msgElem).innerHTML = NG_icon + MSG_INPUT;
        } else if (!$F(elem).match(/^[0-9a-z]+$/)) {
            $(msgElem).innerHTML = NG_icon + MSG_NUMERIC2;
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
        }

        if ($F(elem2).length==0) {
            $(msgElem2).innerHTML = NG_icon + MSG_INPUT;
        } else if (!$F(elem2).match(/^[0-9a-z]+$/)) {
            $(msgElem2).innerHTML = NG_icon + MSG_NUMERIC2;
        } else if ($F(elem) != $F(elem2)) {
            $(msgElem2).innerHTML = NG_icon + MSG_NOMATCH;
        } else {
            $(msgElem2).innerHTML = OK_icon;
            hideErrorDisplay(msgElem2);
        }
    }
    else {
        if ($F(elem).length==0 && $F(elem2).length==0) {
            $(msgElem).innerHTML = "";
            $(msgElem2).innerHTML = "";
            hideErrorDisplay(msgElem2);
        } else {
            if ($F(elem).length==0) {
                $(msgElem).innerHTML = NG_icon + MSG_INPUT;
            } else if (!$F(elem).match(/^[0-9a-z]+$/)) {
                $(msgElem).innerHTML = NG_icon + MSG_NUMERIC2;
            } else {
                $(msgElem).innerHTML = OK_icon;
                hideErrorDisplay(msgElem);
            }

            if ($F(elem2).length==0) {
                $(msgElem2).innerHTML = NG_icon + MSG_INPUT;
            } else if (!$F(elem2).match(/^[0-9a-z]+$/)) {
                $(msgElem2).innerHTML = NG_icon + MSG_NUMERIC2;
            } else if ($F(elem) != $F(elem2)) {
                $(msgElem2).innerHTML = NG_icon + MSG_NOMATCH;
            } else {
                $(msgElem2).innerHTML = OK_icon;
                hideErrorDisplay(msgElem2);
            }
        }
    }
}

// イベント初期化
function initEvent(division, page, mode, dm, language, country) {
    // page 1:member_register, 2:member_change, 4:cart(new), 5:contact, 6:genpassword, 3:others, 7:cart(member)
    if (mode != 'none' && !(navigator.userAgent.indexOf("MSIE")>=0 && navigator.userAgent.indexOf("Mac_PowerPC")>=0)) {
        if (page!=5 && page!=6) {
            if (page==3 && division==2) {
                if (language=='Japanese') {
                    if (mode=='all' || mode=='input') {
                        setKanaRequired(false);
                    }
                }
            } else {
                if (language=='Japanese') {
                    if (mode=='all' || mode=='input') {
                        setKanaRequired(true);
                    }
                }
            }
            if (country==true) {
                if (mode=='all' || (mode=='input' && $F('address_country')!="")) {
                    checkCountry(language, false);
                }
            }
        }
    }
    formOnloadStatus = true;
    return;
}

// イベント定義
function setEvent(division, page, dm, language, country) {
    // page 1:member_register, 2:member_change, 4:cart(new), 5:contact, 6:genpassword, 3:others, 7:cart(member)

    if (!(navigator.userAgent.indexOf("MSIE")>=0 && navigator.userAgent.indexOf("Mac_PowerPC")>=0)) {
        if (page==5) {
            // お問い合わせ
            $('name').onkeyup = function () {checkName(true);};
            $('name').onfocus = function () {checkName(true);};
            $('name').onblur = function () {checkName(true);};
            $('email1').onkeyup = function () {checkEmailDual(false, false);};
            $('email1').onfocus = function () {checkEmailDual(false, false);};
            $('email1').onblur = function () {checkEmailDual(false, false);};
            $('email2').onkeyup = function () {checkEmailDual(false, false);};
            $('email2').onfocus = function () {checkEmailDual(false, false);};
            $('email2').onblur = function () {checkEmailDual(false, false);};
            $('title').onkeyup = function () {checkTitle();};
            $('title').onfocus = function () {checkTitle();};
            $('title').onblur = function () {checkTitle();};
            $('content').onkeyup = function () {checkContent();};
            $('content').onfocus = function () {checkContent();};
            $('content').onblur = function () {checkContent();};
        } else if (page==6) {
            // パスワード忘れ
            $('name').onkeyup = function () {checkName(true);};
            $('name').onfocus = function () {checkName(true);};
            $('name').onblur = function () {checkName(true);};
            $('email1').onkeyup = function () {checkEmail(false);};
            $('email1').onfocus = function () {checkEmail(false);};
            $('email1').onblur = function () {checkEmail(false);};
        } else {
            if (division==2) {
                // 法人
                $('company_name').onkeyup = function () {checkCompanyName();};
                $('company_name').onfocus = function () {checkCompanyName();};
                $('company_name').onblur = function () {checkCompanyName();};
                $('department_name').onkeyup = function () {checkDepartmentName();};
                $('department_name').onfocus = function () {checkDepartmentName();};
                $('department_name').onblur = function () {checkDepartmentName();};
            }
            if (country==true) {//国が表示されていたら国のチェック
                $('address_country').onchange = function () {checkCountry(language, false);setLocalArea(language);};
                $('address_country').onfocus = function () {checkCountry(language, false);};
                $('address_country').onblur = function () {checkCountry(language, false);};
                $('address_localarea').onchange = function () {checkLocalArea();};
                $('address_localarea').onfocus = function () {checkLocalArea();};
                $('address_localarea').onblur = function () {checkLocalArea();};
            }
            if (page==3 && division==2) {
                // 送り主・お届け先の法人は担当者名とフリガナ不要
                $('name').onkeyup = function () {checkName(false);};
                $('name').onfocus = function () {checkName(false);};
                $('name').onblur = function () {checkName(false);};
                if (language=='Japanese') {
                    $('name_ph').onkeyup = function () {checkKana(false, false);};
                    $('name_ph').onfocus = function () {checkKana(false, false);};
                    $('name_ph').onblur = function () {checkKana(false, false);};
                }
            } else {
                $('name').onkeyup = function () {checkName(true);};
                $('name').onfocus = function () {checkName(true);};
                $('name').onblur = function () {checkName(true);};
                if (language=='Japanese') {
                    $('name_ph').onkeyup = function () {checkKana(true, false);};
                    $('name_ph').onfocus = function () {checkKana(true, false);};
                    $('name_ph').onblur = function () {checkKana(true, false);};
                }
            }
            if (language=='Japanese') {
                if (page==3 && division==2) {
                    $('address_postal1').onkeyup = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_postal1').onfocus = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_postal1').onblur = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_postal2').onkeyup = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_postal2').onfocus = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_postal2').onblur = function () {checkPostal(true, language);checkKana(false, true);};
                    $('address_pref').onfocus = function () {hideDiaphanousDisplay('address_pref');};
                    $('address_pref').onchange = function () {checkPrefecture(country);checkKana(false, true);checkOverSeaTel();};
                    $('address_pref').onblur = function () {checkPrefecture(country);checkKana(false, true);};
                } else {
                    $('address_postal1').onkeyup = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_postal1').onfocus = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_postal1').onblur = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_postal2').onkeyup = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_postal2').onfocus = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_postal2').onblur = function () {checkPostal(true, language);checkKana(true, true);};
                    $('address_pref').onfocus = function () {hideDiaphanousDisplay('address_pref');};
                    $('address_pref').onchange = function () {checkPrefecture(country);checkKana(true, true);checkOverSeaTel();};
                    $('address_pref').onblur = function () {checkPrefecture(country);checkKana(true, true);};
                }
            } else {
                $('address_postal').onkeyup = function () {checkPostalEng();};
                $('address_postal').onfocus = function () {checkPostalEng();};
                $('address_postal').onblur = function () {checkPostalEng();};
            }
            $('address1').onkeyup = function () {checkAddress1();};
            $('address1').onfocus = function () {checkAddress1();};
            $('address1').onblur = function () {checkAddress1();};
            $('address2').onfocus = function () {checkAddress2();};
            $('address2').onblur = function () {checkAddress2();};
            if (language=='Japanese') {
                $('address3').onkeyup = function () {checkAddress3(false);};
                $('address3').onfocus = function () {checkAddress3(false);};
                $('address3').onblur = function () {checkAddress3(false);};
            } else {
                $('address3').onkeyup = function () {checkAddress3(true);};
                $('address3').onfocus = function () {checkAddress3(true);};
                $('address3').onblur = function () {checkAddress3(true);};
            }
            if (page==1 || page==4) {
                // お客様情報新規登録の場合はメールアドレス確認が必要
                var registration = false;
                if (page==1) {
                    registration = true;
                }
                $('email1').onkeyup = function () {checkEmailDual(true, registration);};
                $('email1').onfocus = function () {checkEmailDual(true, registration);};
                $('email1').onblur = function () {checkEmailDual(true, registration);};
                $('email2').onkeyup = function () {checkEmailDual(true, registration);};
                $('email2').onfocus = function () {checkEmailDual(true, registration);};
                $('email2').onblur = function () {checkEmailDual(true, registration);};
            } else if (page==2 || page==7) {
                $('email1').onkeyup = function () {checkEmail(true);};
                $('email1').onfocus = function () {checkEmail(true);};
                $('email1').onblur = function () {checkEmail(true);};
            }
            if (language=='Japanese') {
                $('tel1').onkeyup = function () {checkTel(false);};
                $('tel1').onfocus = function () {checkTel(false);};
                $('tel1').onblur = function () {checkTel(false);};
                $('tel2').onkeyup = function () {checkTel(false);};
                $('tel2').onfocus = function () {checkTel(false);};
                $('tel2').onblur = function () {checkTel(false);};
                $('tel3').onkeyup = function () {checkTel(false);};
                $('tel3').onfocus = function () {checkTel(false);};
                $('tel3').onblur = function () {checkTel(false);};
            } else {
                $('tel').onkeyup = function () {checkTelEng();};
                $('tel').onfocus = function () {checkTelEng();};
                $('tel').onblur = function () {checkTelEng();};
            }
            if (page==1 || page==2 || page==4 || page==7) {
                if (language=='Japanese') {
                    $('fax1').onkeyup = function () {checkFax(false);};
                    $('fax1').onfocus = function () {checkFax(false);};
                    $('fax1').onblur = function () {checkFax(false);};
                    $('fax2').onkeyup = function () {checkFax(false);};
                    $('fax2').onfocus = function () {checkFax(false);};
                    $('fax2').onblur = function () {checkFax(false);};
                    $('fax3').onkeyup = function () {checkFax(false);};
                    $('fax3').onfocus = function () {checkFax(false);};
                    $('fax3').onblur = function () {checkFax(false);};
                } else {
                    $('fax').onkeyup = function () {checkFaxEng();};
                    $('fax').onfocus = function () {checkFaxEng();};
                    $('fax').onblur = function () {checkFaxEng();};
                }
                if (dm==true) {
                    $('dm1').onclick = function () {checkDm();};
                    $('dm1').onfocus = function () {checkDm();};
                    $('dm1').onblur = function () {checkDm();};
                    $('dm2').onclick = function () {checkDm();};
                    $('dm2').onfocus = function () {checkDm();};
                    $('dm2').onblur = function () {checkDm();};
                }
            }
            if (page==1) {
                $('pswd').onkeyup = function () {checkPassword(true);};
                $('pswd').onfocus = function () {checkPassword(true);};
                $('pswd').onblur = function () {checkPassword(true);};
                $('pswd2').onkeyup = function () {checkPassword(true);};
                $('pswd2').onfocus = function () {checkPassword(true);};
                $('pswd2').onblur = function () {checkPassword(true);};
            } else if (page==2 || page==4) {
                $('pswd').onkeyup = function () {checkPassword(false);};
                $('pswd').onfocus = function () {checkPassword(false);};
                $('pswd').onblur = function () {checkPassword(false);};
                $('pswd2').onkeyup = function () {checkPassword(false);};
                $('pswd2').onfocus = function () {checkPassword(false);};
                $('pswd2').onblur = function () {checkPassword(false);};
            }
        }
    }
}

function checkTitle() {
    checkEasyInput('title', 'title_status', true);
}

function checkContent() {
    var res = checkEasyInput('content', 'content_status', true);
    if (!res) {
        $('content_status').innerHTML = messageBr + NG_icon + MSG_INPUT;
    } else {
        $('content_status').innerHTML = messageBr + OK_icon;
    }
}

function checkCompanyName() {
    checkEasyInput('company_name', 'company_name_status', true);
}

function checkDepartmentName() {
    checkEasyInput('department_name', 'department_name_status', false);
}

function checkName(required) {
    checkEasyInput('name', 'name_status', required);
}

function checkKana(required, strict) {
    if ($('address_pref').value == '48') {
        checkEasyInput('name_ph', 'name_ph_status', false, strict);
        if (required) {
            hideErrorDisplay('name_ph_status', strict);
        }
    } else {
        checkEasyInput('name_ph', 'name_ph_status', required, strict);
    }
    setKanaRequired(required);
}

function setKanaRequired(required) {
    if ($('address_pref').value == '48') {
        setRequired('name_ph_required', false);
    } else {
        setRequired('name_ph_required', required);
    }
}

function checkPostal(convert, language) {
    checkPostalInput('address_postal1', 'address_postal2', 'address_postal_status', true, convert, 'address_pref', 'address1', 'address2', language);
}

function checkPostalEng() {//英語の時
    checkEasyInput('address_postal', 'address_postal_status', true);
}
function checkCountry(language, strict) {
    var msgElem = 'address_country_status';
    var country = $('address_country');
    var required = false;
    if (!country) {
        return false;
    }
    if (language=='English' || $('address_pref').value == '48') {
        required = true;
        setRequired('country_required', true);
    } else {
        setRequired('country_required', false);
    }
    if (country.value == "") {    
        if (required) {
            $(msgElem).innerHTML = NG_icon + MSG_SELECT;
            hideDiaphanousDisplay(msgElem);
        }
        else {
            $(msgElem).innerHTML = "";
            hideErrorDisplay(msgElem, strict);
        }
    } else {
        var pref = $('address_pref');
        if (pref && ((pref.value == '48' && country.value == '61') || (pref.value != '48' && country.value != '61'))) {
            $('address_country_status').innerHTML = messageBr + NG_icon + MSG_PREF;
            hideDiaphanousDisplay(msgElem);
        } else {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem, strict);
        }
    }
}

function checkLocalArea() {
    checkEasySelect('address_localarea', 'address_localarea_status', true);
}

function checkPrefecture(country, language) {
    checkEasySelect('address_pref', 'address_pref_status', true);
    if (country) {
        checkCountry(language, true);
    }
}
function checkOverSeaTel() {
    var en = false;
    var strict = true;
    if ($F('address_pref') == 48) {
        en = true;
    }
    if ($F('tel1') || $F('tel2') || $F('tel3')) {
        checkTelInput('tel1', 'tel2', 'tel3', 'tel_status', true, strict);
    } else {
        changeTelNotice('tel_status', en);
    }
    if ($('fax1')){
        if ($F('fax1') || $F('fax2') || $F('fax3')) {
            checkTelInput('fax1', 'fax2', 'fax3', 'fax_status', false, strict);
        } else {
            changeTelNotice('fax_status', en);
        }
    }
}
function checkAddress1() {
    checkEasyInput('address1', 'address1_status', true);
}

function checkAddress2() {
    checkEasyInput('address2', 'address2_status', false);
}

function checkAddress3(required) {
    checkEasyInput('address3', 'address3_status', required);
}

function checkEmail(overlap) {
    checkEmailInput('email1', 'email1_status', true, overlap);
}

function checkEmailDual(overlap, registration) {
    var email1Error = false;
    if ($F('email1').length==0) {
        $('email1_status').innerHTML = NG_icon + MSG_INPUT;
        email1Error = true;
    } else if ($F('email1').match(/[^+?\/0-9A-Za-z@\._-]+/)) {
        $('email1_status').innerHTML = NG_icon + MSG_NUMERIC2;
        email1Error = true;
    } else if (!$F('email1').match(/^[\/0-9A-Za-z_-][+?\/0-9A-Za-z.._-]*@[0-9A-Za-z_-]+[\.]+[0-9A-Za-z_..-]+[A-Za-z]$/)) {
        $('email1_status').innerHTML = NG_icon + MSG_INPUT2;
        email1Error = true;
    } else {
        var needOverlapCheck = false;
        if (overlap) {
            if (registration) {
                needOverlapCheck = true;
            } else {
                if ($('pswd') && $F('pswd')) {
                    needOverlapCheck = true;
                }
            }
        }
        if (needOverlapCheck) {
            checkOverlapEmail('email1', 'email1_status', 0, 'email2');
            return;
        } else {
            $('email1_status').innerHTML = OK_icon;
        }
    }
    var res = checkConfirmEmail('email1', 'email2');
    if (res) {
        hideErrorDisplay('email1_status');
    }
}

function checkTel(strict) {
    checkTelInput('tel1', 'tel2', 'tel3', 'tel_status', true, strict);
}
function checkTelEng() {
    checkTelInputEng('tel', 'tel_status', true);
}

function checkFax(strict) {
    checkTelInput('fax1', 'fax2', 'fax3', 'fax_status', false, strict);
}
function checkFaxEng() {
    checkTelInputEng('fax', 'fax_status', false);
}

function checkDm() {
    if (!$('dm1').checked && !$('dm2').checked) {
        $('dm_status').innerHTML = NG_icon + MSG_SELECT;
    } else {
        $('dm_status').innerHTML = OK_icon;
        hideErrorDisplay('dm_status');
    }
}

function checkPassword(required) {
    checkPasswordInput('pswd', 'pswd_status', 'pswd2', 'pswd2_status', required);
}

function checkQuestion(page, name, required, onloadFlag) {//アンケート欄チェック nakayama
    // page 1:member_register, 4:cart, 5:contact
    if (page==4) {
        q_msgElem="customer_question_status_"+name;
        q_length = document.register.elements['customer_question['+name+']'].value.length;
    } else {
        q_msgElem="question_status_"+name;
        q_length = document.checkForm.elements['question['+name+']'].value.length;
    }
    if (q_length==0) {
        if (required) {
            $(q_msgElem).innerHTML = NG_icon + MSG_INPUT;
        }
        else {
            $(q_msgElem).innerHTML = "";
        }
    }
    else {
        $(q_msgElem).innerHTML = OK_icon;
        if (onloadFlag !== 1) {
            hideErrorDisplay(q_msgElem);
        }
    }
}

function checkVerification(page, name) {
    // page 4:cart
    if (page==4) {
        msgElem = name + "_status";
        if ($F(name) == 1) {
            $(msgElem).innerHTML = OK_icon;
            hideErrorDisplay(msgElem);
        } else {
            $(msgElem).innerHTML = messageBr + NG_icon + MSG_CONFIRM;
            hideDiaphanousDisplay(msgElem);
        }
    }
}

function mailCheck(elem) {
    var msgElem = elem + "_status";
    checkEmailInput(elem, msgElem, true, '');
}

function setLocalArea(language) {
    var val = $('address_country').value;
    var addressCityElem = $('address3_city');
    var listobj = $('address_localarea');
    listobj.length = 0;
    listobj[0] = new Option('----', '');
    if (val && (val == 202 || val == 222 || val == 238)) {
        var pars = "go=address-local-search&countryid=" + val;
        var myAjax = new Ajax.Request (
            xmlUrl,
            {
                method: 'get',
                parameters: pars,
                onSuccess: function(request) {
                    if (request.readyState == 4 && request.status == 200) {
                        $('address_localarea_block').style.display = '';
                        if (language=='English' && addressCityElem) {
                            addressCityElem.innerHTML = "(City)";
                        }
                        var data = eval( "(" + request.responseText + ")" );
                        for (var i=0;i<data.local.length;i++) {
                            listobj[i+1] = new Option(data.local[i].name, data.local[i].id);
                        }
                        hideDiaphanousDisplay('address_localarea_status');
                        toggleFormLine('address_localarea_status', 'block');
                    }
                }
            }
        );
    } else {
        toggleFormLine('address_localarea_status', 'none');
        $('address_localarea_block').style.display = 'none';
        if (language=='English' && addressCityElem) {
            addressCityElem.innerHTML = "(City, State)";
        }
    }
}

