$(function () { $('#gift_codes').change(function() { var txt = $(this).val(); txt = txt.replace(/ /g,""); txt = toHalfWidth(txt); var obj = txt.match(/[\r\na-zA-Z0-9]/g); if (obj) { txt=obj.join(''); txt=txt.toUpperCase(); } $(this).val(txt); }); $('#amount').change(function(){ var txt = $(this).val(); var han = txt.replace(/[A-Za-z0-9]/g,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}); $(this).val(han); var rate = 0; auto_calc(); }); $('[name=tel]').change(function() { var txt = $(this).val(); var han = txt.replace(/[A-Za-z0-9]/g,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}); han = han.replace(/[^-0-9]/g, ''); $(this).val(han); auto_calc(); }); $('[name=account_number]').change(function() { var txt = $(this).val(); var han = txt.replace(/[A-Za-z0-9]/g,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}); han = han.replace(/[^0-9]/g, ''); $(this).val(han); }); $('[name=expiration_date]').change(function() { var txt = $(this).val(); var han = txt.replace(/[A-Za-z0-9]/g,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}); han = han.replace(/[^0-9]/g, ''); $(this).val(han); }); $('[name=card_kind]').change(function() { auto_calc(); }); $('[name=payment_course]').change(function() { auto_calc(); }); $('[name=account_name]').change(function() { var txt = $(this).val(); var han = txt.replace(/[ぁ-ん]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) + 0x60); }); $(this).val(han); }); $('[name=kind]').click(toggle_corpname); $('#submit_button').click(function () { var email = $('#email').val(); var email_confirm = $('#email_confirm').val(); if (email != email_confirm) { alert('EmailとEmail(確認)の内容が異なっています。EmailとEmail(確認) には同じ内容を入力してください。'); } else { $('#fm').submit(); } }); toggle_corpname(); }); function toHalfWidth(strVal){ var halfVal = strVal.replace(/[!-~]/g, function( tmpStr ) { return String.fromCharCode( tmpStr.charCodeAt(0) - 0xFEE0 ); } ); return halfVal.replace(/”/g, "\"") .replace(/’/g, "'") .replace(/‘/g, "`") .replace(/¥/g, "\\") .replace(/ /g, " "); } function auto_calc() { var data = {}; data.tel = $('[name=tel]').val(); data.form_key = $('[name=form_key]').val(); data.par = $('#amount').val(); data.ticket_type = $('[name=card_kind]:checked').val(); if (!data.ticket_type) { data.ticket_type = $('[name=card_kind]').val(); } data.payment_course = $('[name=payment_course]:checked').val(); if (!data.payment_course) { data.payment_course = $('[name=payment_course]').val(); } $.ajax({ type: "POST", url: "/ajax/calc.json", dataType : 'json', data: data, success: function( res ) { sales_amount = parseInt(res.sales_amount, 10); if (isNaN(sales_amount)) { sales_amount = "-"; } else if (sales_amount < 0) { sales_amount = "-"; } else { sales_amount = String(sales_amount).replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); } $(".purchase_amount_label").text(sales_amount); $(".application_status_label").text(""); if (res.is_first_application) { $(".application_status_label").text(" (初回取引対象です)"); } }, error: function( res ) { $(".purchase_amount_label").text("-"); } }); }