suz_ConfirmMsgFlg = true; // 確認メッセージ表示フラグ
$(function() {
suz_showPassword(); // パスワードの表示/非表示切替ボタン
suz_submitRestriction() // formSubmit制限
// 国ID変更
$("table.Registration").on('change', '#suz_countryID', function(ev) {
//Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/nonrwd/getFormList/",
data: { countryId: $(this).val(), stateId: null, token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value"), rwd: document.getElementById("suz-responsive") != null },
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
suz_resetForm(data); // フォーム再生成
suz_checkPrev($('#suz_countryID')); // 前方入力チェック
// プライバシー確認表示
$('#suz_agreementControl').html(data['agreementControl']);
suz_showRegisterTopBottomGuide();
$('#suz_countryID').focus();
$('#suz_countryID').blur();
},
function(req, stat, err) {
if (req.status == 401 || req.status == 404 || req.status == 500) {
window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp";
return false;
}
alert(err);
return false;
});
});
// 州ID変更
$("table.Registration").on('change', '#suz_stateID', function(ev) {
//Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/nonrwd/getFormList/",
data: { countryId: $("#suz_countryID").val(), stateId: $(this).val(), token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value"), rwd: document.getElementById("suz-responsive") != null },
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
suz_resetForm(data); // フォーム再生成
suz_callRegValidator($('#suz_stateID').attr('name'), $('#suz_stateID').attr('value')); // 自項目再チェック
$('#suz_stateID').focus();
$('#suz_stateID').blur();
},
function(req, stat, err) {
if (req.status == 401 || req.status == 404 || req.status == 500) {
window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp";
return false;
}
alert(err);
return false;
});
});
// 入力フォーム生成
function suz_resetForm(data) {
var formList = data['formList'];
var tbody = $('table.Registration').find('tbody');
tbody.empty();
for (var cnt in formList) {
var regForm = formList[cnt];
if (($('#suz_registrationMode').html() === 'edit' || $('#suz_npst').html() === '1') && regForm.visualControlId == 5) {
continue;
}
if (regForm.visualControlId != 6) {
var tr = '
';
if (regForm.visualControlId !== 3 && regForm.visualControlId !== 4) {
tr += '';
}
tr += ' | ';
}
if ('zipCode' === regForm.fieldName && 1 === data['attrAddresssearchtypeid']) {
tr += '';
tr += '';
} else {
switch (regForm.visualControlId) {
case 1: // text
tr += '';
break;
case 2: // drop
tr += '';
break;
case 3: // check
var items = data[regForm.mapName];
for (var key in items) {
var checkId = 'check' + regForm.fieldName + '_' + key;
tr += '';
}
break;
case 4: // radio
var items = data[regForm.mapName];
tr += '';
break;
case 5: // password
tr += '' + $('#suz_ShowPassword').html() + '' + $('#suz_HidePassword').html() + ''
} else {
tr += '"/>';
}
break;
case 6: // hidden
tr = '';
break;
}
}
if (regForm.visualControlId != 6) {
tr += ' | ' + regForm.descriptionValue + ' |
';
}
tbody.append(tr);
}
suz_showPassword(); // パスワードの表示/非表示切替ボタン
}
// 市ID変更
// ⇒Zipcode自動入力
$("table.Registration").on('change', '#suz_cityID', function(ev) {
//パラメタ取得
var countryId = $("select[name='countryID']").val();
var stateId = $("select[name='stateID']").val();
cityId = $(this).val();
//Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/changeCity/",
data: { countryId: countryId, stateId: stateId, cityId: cityId, token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value") },
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
var zipCd = $("input[name='zipCode']");
if (data['count'] == 0) {
zipCd.val(data['zipCode']);
} else {
zipCd.val("");
}
suz_callRegValidator('zipCode', zipCd.val());
},
function(req, stat, err) {
if (req.status == 401) {
window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp";
return false;
}
alert(err);
return false;
});
}
);
// 実行ボタン
$("#submit2").click(function() {
suz_ConfirmMsgFlg = false;
});
// プライバシーチェック(親)
$('#suz_registerTopGuide, #suz_registerBottomGuide, #suz_profileTopGuide, #suz_profileBottomGuide').on('check:on', '#agreeAll', function() {
if (suz_privacyCheckFlg) {
return true;
}
suz_linkedCheckBox('#as_agreeBoxCheked dd input.CustomCheckbox', 'checkOn');
suz_checkBoxDecision();
});
$('#suz_registerTopGuide, #suz_registerBottomGuide, #suz_profileTopGuide, #suz_profileBottomGuide').on('check:off', '#agreeAll', function() {
if (suz_privacyCheckFlg) {
return true;
}
suz_linkedCheckBox('#as_agreeBoxCheked dd input.CustomCheckbox', 'checkOff');
suz_checkBoxDecision();
});
// プライバシーチェック(子)
$('#suz_registerTopGuide, #suz_registerBottomGuide, #suz_profileTopGuide, #suz_profileBottomGuide').on('check:on', '#as_agreeBoxCheked dd input.CustomCheckbox', function() {
if (suz_privacyCheckFlg) {
return true;
}
if ($('#as_agreeBoxCheked dd span.CustomCheckbox').length == $('#as_agreeBoxCheked dd span.checked').length) {
suz_linkedCheckBox('#agreeAll', 'checkOn');
}
suz_checkBoxDecision();
});
$('#suz_registerTopGuide, #suz_registerBottomGuide, #suz_profileTopGuide, #suz_profileBottomGuide').on('check:off', '#as_agreeBoxCheked dd input.CustomCheckbox', function() {
if (suz_privacyCheckFlg) {
return true;
}
suz_linkedCheckBox('#agreeAll', 'checkOff');
suz_checkBoxDecision();
});
// 入力チェック処理
// 前方項目チェック
$("table.Registration").on('focus', ":text,:password,:radio", function() {
suz_checkPrev($(this));
});
$("table.Registration").on('focus', "input.CustomCheckbox", function() {
suz_checkPrev($(this));
});
$("table.Registration").on('focus', "select.CustomSelect", function() {
suz_checkPrev($(this).parent().prev());
});
// IE用離脱メッセージ回避
$("table.Registration").on('click', "select.CustomSelect", function() {
suz_ConfirmMsgFlg = false;
setTimeout(function() { suz_ConfirmMsgFlg = true; }, 0);
});
// 自項目チェック
$("table.Registration").on('blur', ":text,:password", function() {
if ($(this).attr('name')) {
suz_callRegValidator($(this).attr('name'), $(this).attr('value'));
} else { // パスワード表示対応
suz_callRegValidator($(this).next().attr('name'), $(this).attr('value'));
}
// パスワード変更時の確認用パスワードチェック
if ($(this).hasClass('passwordShowing') || $(this).attr('name') == 'password') {
var cnfPwd = $("table.Registration").find('#suz_tr_confirmPassword').find(":password");
if (cnfPwd.length > 0) {
var cnfPwdVal = cnfPwd.attr('value');
if (cnfPwd.css('display') == 'none') {
cnfPwdVal = $("table.Registration").find('#suz_tr_confirmPassword').find(".passwordShowing").attr('value');
}
if (cnfPwdVal !== '') {
suz_callRegValidator('confirmPassword', cnfPwdVal);
}
}
}
// メールアドレス変更時の確認用メールアドレスチェック
if ($("table.Registration").find('#suz_tr_confirmEmailAddress').length > 0 && $(this).attr('name') == 'emailAddress') {
var cnfEmailVal = $("table.Registration").find('#suz_tr_confirmEmailAddress').find(":text").attr('value');
if (cnfEmailVal !== '') {
suz_callRegValidator('confirmEmailAddress', cnfEmailVal);
}
}
});
$("table.Registration").on('change', ":radio", function() {
suz_callRegValidator($(this).attr('name'), $(this).attr('value'));
});
$("table.Registration").on('change', "select", function() {
suz_callRegValidator($(this).attr('name'), $(this).attr('value'));
});
$('table.Registration').on('check:on', 'input.CustomCheckbox', function() {
suz_callRegValidator($(this).attr('name'), "on");
});
$('table.Registration').on('check:off', 'input.CustomCheckbox', function() {
suz_callRegValidator($(this).attr('name'), "off");
});
if ($("#suz_agreementControl").length > 0) {
var defCountryId = $('#suz_countryID').val();
// 初期国設定
// Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/ipAddressCountryId/",
data: {},
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
if (data && defCountryId != data['countryId']) {
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/nonrwd/getFormList/",
data: { countryId: data['countryId'], stateId: $("#suz_stateID").val(), token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value"), rwd: document.getElementById("suz-responsive") != null },
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
suz_resetForm(data); // フォーム再生成
// プライバシー確認表示
$('#suz_agreementControl').html(data['agreementControl']);
suz_showRegisterTopBottomGuide();
},
function() {
suz_showRegisterTopBottomGuide();
});
}
},
function() {
suz_showRegisterTopBottomGuide();
});
}
// 郵便番号入力
// ⇒市名自動入力
$("table.Registration").on('blur', '#suz_zipCode', function(ev) {
//Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/getCityName/",
data: {
countryId: $("select[name='countryID']").val(),
fieldName: $(this).attr('name'),
fieldValue: $(this).val(),
token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value")
},
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
var cityName = $("input[name='cityName']");
if (data['status'] == 0) {
cityName.val(data['cityName']);
suz_callRegValidator('cityName', cityName.val());
}
},
function(req, stat, err) {
if (req.status == 401) {
window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp";
return false;
}
alert(err);
return false;
});
});
});
// 前方項目チェック
function suz_checkPrev(trgt) {
trgt.parents('tr').prevAll('tr').each(function() {
suz_checkEntryItem($(this));
});
}
// 後方項目チェック
function suz_checkFollowing(trgt) {
trgt.parents('tr').nextAll('tr').each(function() {
suz_checkEntryItem($(this));
});
}
// 項目チェック
function suz_checkEntryItem(trgt) {
if (trgt.hasClass("suzChecked")) { // チェック済み
return true;
}
var prevItem = trgt.find(":text,:password,:radio,select");
if (prevItem.length == 2) { // パスワード表示対応
if (prevItem[0].style.display == 'none') {
suz_callRegValidator(prevItem[1].name, prevItem[1].value);
} else {
suz_callRegValidator(prevItem[1].name, prevItem[0].value);
}
return true;
} else if (prevItem.length == 1) {
suz_callRegValidator(prevItem.attr('name'), prevItem.attr('value'));
return true;
}
prevItem = trgt.find(":checkbox");
suz_callRegValidator(prevItem.attr('name'), prevItem.prop('checked') ? 'on' : 'off');
}
// ドメイン取得
function suz_getCurrentDomain() {
return (typeof kpi_currentDomain == "undefined") ? kpi_originalDomain : kpi_currentDomain;
}
// チェック処理呼出
function suz_callRegValidator(fldNm, fldVal) {
var trgtTr = $("#suz_tr_" + fldNm);
//Ajax通信
$.ajax({
url: suz_getCurrentDomain() + "/ajax/registrationAjax/validator/",
data: { fieldName: fldNm, fieldValue: encodeURIComponent(fldVal), token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value") },
dataType: "jsonp",
jsonp: "callback",
scriptCharset: "UTF-8"
}).then(function(data) {
if (data['message']) { // Errorの場合
trgtTr.removeClass("ProperRow");
trgtTr.addClass("ErrorRow");
trgtTr.find("p").html(data['message']);
trgtTr.find("p").parent().css('display', 'block');
} else { // OKの場合
trgtTr.removeClass("ErrorRow");
trgtTr.addClass("ProperRow");
trgtTr.find("p").html("");
trgtTr.find("p").parent().css('display', 'none');
}
trgtTr.addClass("suzChecked")
},
function(req, stat, err) {
if (req.status == 401) {
window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp";
return false;
}
alert(err);
return false;
});
}
// パスワード表示切替設定
function suz_showPassword() {
$('.suzPwdViewMode').showPassword({
linkClass: 'showPasswordLink', //Class to use for the toggle link
linkText: $('.suzShowPassword').html(), //Text for the link
showPasswordLinkText: $('.suzHidePassword').html(), //Text for the link when password is not masked
showPasswordInputClass: 'passwordShowing', //Class for the text input that will show the password
linkRightOffset: 0, //Offset from the right of the parent
linkTopOffset: 0 //Offset from the top of the parent
});
$('.passwordShowing').addClass('CustomText');
}
// formSubmit制限(複数のサブミットボタンが存在するフォームではエンターキーによるサブミットを制限する)
function suz_submitRestriction() {
// 複数Submit存在時のチェック用フィルタ関数
var suz_formfilter = function() { return $(this).find("input[type='submit']").length > 1; };
$("#ContentsArea form").filter(suz_formfilter).each(function() {
// input要素のtype属性:text,password,radio,checkboxに対してエンターキーsubmit制限
$(this).find("input[type=text],input[type=password],input[type=radio],input[type=checkbox]")
.keypress(function(ev) {
if ((ev.which && ev.which === 13) || (ev.keyCode && ev.keyCode === 13)) {
return false;
}
});
});
}
// ガイド表示(Top/Bottom)
function suz_showRegisterTopBottomGuide() {
var incFlPath = suz_getCurrentDomain() + "/register/entry/register";
if (document.getElementById('suz_profileTopGuide') != null) {
incFlPath = suz_getCurrentDomain() + "/my-keyence/edit-profile/edit";
}
if ($('#suz_agreementControl').html() !== '') {
$('#suz_registerTopGuide, #suz_profileTopGuide').load(incFlPath + '/topGuide_' + $('#suz_agreementControl').html() + '.html', function() {
$('#suz_registerBottomGuide, #suz_profileBottomGuide').load(incFlPath + '/bottomGuide_' + $('#suz_agreementControl').html() + '.html', function() {
$('#suz_registerTopGuide .CustomCheckbox, #suz_registerBottomGuide .CustomCheckbox, #suz_profileTopGuide .CustomCheckbox, #suz_profileBottomGuide .CustomCheckbox').checkbox({
view: true
, uiClass: 'CustomCheckbox'
, labelClass: 'UIElm-check-label'
, checkedClass: 'checked'
, disabledClass: 'disabled'
});
if ($('#suz_agreementState').html() !== '') {
suz_linkedCheckBox('#as_agreeBoxCheked input.CustomCheckbox', 'checkOn');
}
suz_checkBoxDecision(); // サブミットボタン制御
suz_privacyModal(); // プライバシーモーダル表示設定
});
});
} else {
// 表示用言語による制御
if ($('#suz_dspLanguage').html() != null && $('#suz_dspLanguage').html() !== '') {
// 表示用言語が設定されている場合
// 「topGuide_言語ID.html」を表示する。
var topGuideFileName = incFlPath + '/topGuide_' + $('#suz_dspLanguage').html() + '.html';
var bottomGuideFileName = incFlPath + '/bottomGuide_' + $('#suz_dspLanguage').html() + '.html';
} else {
// 表示用言語が未設定の場合
var topGuideFileName = incFlPath + '/topGuide.html';
var bottomGuideFileName = incFlPath + '/bottomGuide.html';
}
// 韓国語表示時の特殊制御
setKRCheckboxControl();
$('#suz_registerTopGuide, #suz_profileTopGuide').load(topGuideFileName, function() {
$('#suz_registerBottomGuide, #suz_profileBottomGuide').load(bottomGuideFileName, function() {
suz_checkBoxDecision(); // サブミットボタン制御
suz_privacyModal(); // プライバシーモーダル表示設定
});
});
}
}
// 韓国語表示時の特殊制御
// 韓国語表示時に国選択で韓国以外を選択した場合に「topGuide_ko-KR.html」を表示するが、そのチェックボックスを有効にするための制御
function setKRCheckboxControl() {
// 表示言語判断
if ($('#suz_dspLanguage').html() == 'ko-KR') {
$('#suz_registerTopGuide .CustomCheckbox, #suz_registerBottomGuide .CustomCheckbox, #suz_profileTopGuide .CustomCheckbox, #suz_profileBottomGuide .CustomCheckbox').checkbox({
view: true
, uiClass: 'CustomCheckbox'
, labelClass: 'UIElm-check-label'
, checkedClass: 'checked'
, disabledClass: 'disabled'
});
}
}
//プライバシー子チェック制御
suz_privacyCheckFlg = false; // プライバシーチェックイベント制御フラグ
function suz_linkedCheckBox(checkBoxes, onOff) {
suz_privacyCheckFlg = true;
$(checkBoxes).each(function() {
$(this).checkbox(onOff, $(this).attr('id'));
});
suz_privacyCheckFlg = false;
}
//プライバシーチェックによるサブミットボタン制御
function suz_checkBoxDecision() {
var maxCheckbox = $('#as_agreeBoxCheked dd span.CustomCheckbox').length;
var checkedCheckbox = $('#as_agreeBoxCheked dd span.checked').length;
if (maxCheckbox == checkedCheckbox) {
$('#as_agreeBoxCheked_btn').css({ opacity: '1' }).removeClass('checkOff');
$('#as_agreeBoxCheked_btn input').attr('disabled', false);
} else {
$('#as_agreeBoxCheked_btn').css({ opacity: '0.3' }).addClass('checkOff');
$('#as_agreeBoxCheked_btn input').attr('disabled', true);
}
}
// プライバシーモーダル表示設定
function suz_privacyModal() {
$('a.Modal').kpi_modalbox({
speed: kpi_usersettings.ModalOpenSpd,
initialWidth: "450px",
maxWidth: $(window).width() - 60,
initialHeight: "600px",
maxHeight: $(window).height() - 60,
onOpen: function() { $('#kpi_modalbox').removeClass('ModalLarge'); },
onComplete: function() {
$('#kpi_boxClose').focus();
if ($('.TabSwitching').length) $('.TabSwitching').tabChange();
if ($('table.Stripe').length) $('table.Stripe tbody').find('tr:odd').addClass('EvenRow');
if ($("#DownloadList").length || ($("#DownloadListLicenseSoftware").length || $("#DownloadListLicenseCad").length)) kpi_cartObj.callbackFromModalWindow($(this).prev().children("input").attr("id")); //For Cart
}
});
}
//password assistance
function suz_pwdAssistanceSubmit() {
var suzApiUrl;
if (typeof kpi_currentDomain == "undefined") {
if (typeof kpi_originalDomain == "undefined") {
suzApiUrl = "";
} else {
suzApiUrl = kpi_originalDomain;
}
} else {
suzApiUrl = kpi_currentDomain;
}
var submitForm = $('#suz-pwdAssistanceLink').closest('form');
submitForm.attr('action', suzApiUrl + '/user/passwordAssistance/');
submitForm.submit();
}
//escape html
function suz_escapeHtml(s) {
if (s) {
return s.replace(/[&'`"<>]/g, function(match) {
return {
'&': '&',
"'": ''',
'`': '`',
'"': '"',
'<': '<',
'>': '>',
}[match]
});
}
return "";
}