$(function () { var ddls; if (!Array.prototype.filter) { Array.prototype.filter = function (fun /*, thisp */) { "use strict"; if (this === null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun !== "function") throw new TypeError(); var res = []; var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t) { var val = t[i]; // in case fun mutates this if (fun.call(thisp, val, i, t)) res.push(val); } } return res; }; } //欄位名對應 var fields = { 'cOrder_SN': '訂單編號', 'cProduct_Type': '預購機型', 'Product_Size': '容量', 'cProductModel_ID': '顏色', 'cProduct_IMEI': '手機IMEI', 'cProduct_SN': '手機S/N', 'cLinkage_ID': '取貨通路', 'cBookStore_ID': '取貨門市', 'cUser_Identification_En': '身分證字號/居留證號碼', 'cUser_Nationality': '籍別', 'cUser_Name_En': '姓名', 'cUser_Sex': '性別', 'cUser_EMail_En': 'E-mail', 'cUser_Birthday': '出生日期', 'cUser_Phone_En': '手機號碼', 'cUsed_Brand': '手機品牌', 'cUsed_Model': '手機型號', 'cUsed_Other': '其他手機品牌/型號', 'cIsAppend': '您是否為預註冊活動消費者', 'cAppend1_SN': '限量加碼禮序號', 'county': '縣市', 'district': '鄉鎮區域', 'zipcode': '贈品寄送地址', 'cUser_Address': '贈品寄送地址', 'cIsExchange': '是否同意主辦單位得將本人之個人資料提供活動小組作為預購禮配送之用', 'cIsOK': '我同意本活動辦法及規定', 'cStoreAgree': '指定門市排隊禮數量有限,系統依照訂購完成時間(Setp.5)判斷是否符合排隊禮資格', 'cUser_CancelTxt': '取消原因', 'cReservation_SDate': '取機日期', 'cReservation_ID': '取機時段', 'cIsTradeIn': '是否參與舊機換新機活動', 'cIsCopyData': '是否需要舊機資料轉移至新機服務', 'cIsTransfer': '請問您是否參加iPhone轉入Galaxy 跨系統 LINE 線上轉移預約服務', 'validCode': '驗證碼' }; //回上一步 $(".btt-back:visible > a").click(function () { var url = $(this).attr("href"); var uo = $("input[name=uo]").val(); if (url.indexOf('#') > 0) { location.replace(url.replace(/#/, "?uo=" + encodeURIComponent(uo) + "#")); } else { location.replace(url + "?uo=" + encodeURIComponent(uo)); } return false; }); //計時器 if (id('timerBox')) { var timer1 = $('.timer1').startTimer({ elementContainer: 'span', onComplete: function (e) { location.replace('pay_cancel.aspx'); } }); timer1.trigger('start'); } //step1 通路 if (id('aBtn')) { //$("select[name=cLinkage_ID]").change(function () { //取貨通路 // $("input[name=cStore_Address]").val(''); // $("select[name=cCity],select[name=cBookStore_ID]").find('option:not(:eq(0))').remove(); // if ($("select[name=cLinkage_ID]").val() !== "") { // $('select[name=cCity_Temp] option[data-l=' + $("select[name=cLinkage_ID]").val() + ']').clone().appendTo('select[name=cCity]'); // } //}); $("select[name=cCity]").change(function () { //縣市 $("input[name=cStore_Address]").val(''); $("select[name=cBookStore_ID]").find('option:not(:eq(0))').remove(); if ($("select[name=cCity]").val() !== "") { $('select[name=cStore_Temp] option[data-c=' + $("select[name=cCity]").val() + ']').clone().appendTo('select[name=cBookStore_ID]'); //$('select[name=cStore_Temp] option[data-l=' + $("select[name=cLinkage_ID]").val() + '][data-c=' + $("select[name=cCity]").val() + ']').clone().appendTo('select[name=cBookStore_ID]'); } }); $("select[name=cBookStore_ID]").change(function () { //門市 //var addr = $("select[name=cBookStore_ID] option:selected").data("r"); $("select[name=cLinkage_ID]").val($("select[name=cBookStore_ID] option:selected").data("l")); $("input[name=cStore_Address]").val($("select[name=cBookStore_ID] option:selected").data("r")); }); $("#aBtn").click(function () { var url = $(this).data("href"); if (!checkEmpty() || !checkFormat()) { e.preventDefault(); e.stopPropagation(); return false; } else { $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); } else { location.replace(url + "?uo=" + encodeURIComponent(data.objectz)); } }, "json"); } return false; }); } //step2 產品與顏色 if (id('bBtn')) { //console.log('bbtn'); $('dt,dd').removeClass('select'); // $("dt.pmodel[data-t='4']:eq(0)").css("width", "100%"); //watch第一個預設寬度 // $("dt.pmodel[data-t='4']:last-child").css("width", "100%"); //watch第一個預設寬度 $("input[name=Product_Type]").click(function () { $("input[name=Product_Model], input[name=Product_Size], input[name=Product_Color]").prop('checked', false); $("input[name=cProductModel_ID],input[name=cProductSeries_ID],input[name=cProductItem_ID]").val(''); var ptype = $("input[name=Product_Type]:checked").val(); $("dt.pmodel, dt.pcapa, dt.pcolor").removeClass('select').addClass("hide"); $("dt.pmodel[data-t='" + ptype + "']").removeClass("hide"); var pmodel = $("dt.pmodel[data-t='" + ptype + "']").find("input[name=Product_Model]:enabled:first").val(); //console.log(pmodel); $("dt.pcapa[data-t='" + ptype + "'][data-m='" + pmodel + "']").removeClass("hide"); var psize = $("dt.pcapa[data-t='" + ptype + "'][data-m='" + pmodel + "']").find("input[name=Product_Size]:enabled:first").val(); $("dd.pcolor").removeClass('select').addClass("hide"); $("dd.pcolor[data-t='" + ptype + "'][data-m='" + pmodel + "'][data-s='" + psize + "']").removeClass("hide"); var pimg = $("dd.pcolor[data-s='" + psize + "']").find("input[name=Product_Color]:enabled:first").data("img"); $(".productimg").attr("src", pimg); $('.precapa span').addClass('hide'); if (ptype == '4') {//, .btnbox a , .btnbox a:eq(1) $('.precapa span:eq(1)').removeClass('hide'); } else { $('.precapa span:eq(0)').removeClass('hide'); } $('.main_phone').css({ "width": "90%", "transform": "translateX(0)", "padding-left": "10%" }); $("dt.ptype").removeClass('select'); $(this).parent().addClass('select'); }); $("input[name=Product_Model]").click(function () { $("input[name=Product_Size], input[name=Product_Color]").prop('checked', false); $("input[name=cProductModel_ID],input[name=cProductSeries_ID],input[name=cProductItem_ID]").val(''); var pmodel = $("input[name=Product_Model]:checked").val(); var ptype = $("input[name=Product_Model]:checked").parent().data('t'); //console.log('choose model...' + ptype + '--' + pmodel); //if ($("input[name=Product_Type]:checked").val() === undefined) { // $("input[name=Product_Type]").filter("[value='" + ptype + "']").prop('checked', true).parent().addClass('select'); //} $("dt.pcapa").removeClass('select').addClass("hide"); $("dt.pcapa[data-t='" + ptype + "'][data-m='" + pmodel + "']").removeClass("hide"); var psize = $("dt.pcapa[data-t='" + ptype + "'][data-m='" + pmodel + "']").find("input[name=Product_Size]:enabled:first").val(); $("dd.pcolor").removeClass('select').addClass("hide"); $("dd.pcolor[data-s='" + psize + "']").removeClass("hide"); var pimg = $("dd.pcolor[data-s='" + psize + "']").find("input[name=Product_Color]:enabled:first").data("img"); $(".productimg").attr("src", pimg); $("dt.pmodel").removeClass('select'); $(this).parent().addClass('select'); }); $("input[name=Product_Size]").click(function () { var psize = $("input[name=Product_Size]:checked").val(); var ptype = $("input[name=Product_Size]:checked").parent().data('t'); var pmodel = $("input[name=Product_Size]:checked").parent().data('m'); //console.log('choose size...' + ptype + '--' + pmodel + '--' + psize); //if ($("input[name=Product_Type]:checked").val() === undefined) { // $("input[name=Product_Type]").filter("[value='" + ptype + "']").prop('checked', true).parent().addClass('select'); //} if ($("input[name=Product_Model]:checked").val() === undefined) { $("input[name=Product_Model]").filter("[value='" + pmodel + "']").prop('checked', true).parent().addClass('select'); } $("input[name=Product_Color]").prop('checked', false); $("input[name=cProductItem_ID]").val(''); $("dd.pcolor").removeClass('select').addClass("hide"); $("dd.pcolor[data-s='" + psize + "']").removeClass("hide"); var pimg = $("dd.pcolor[data-s='" + psize + "']").find("input[name=Product_Color]:enabled:first").data("img"); $(".productimg").attr("src", pimg); $("dt.pcapa").removeClass('select'); $(this).parent().addClass('select'); }); $("input[name=Product_Color]").click(function () { var pcolor = $("input[name=Product_Color]:checked").val(); //var ptype = $("input[name=Product_Color]:checked").parent().data('t'); var pmodel = $("input[name=Product_Color]:checked").parent().data('m'); var psize = $("input[name=Product_Color]:checked").parent().data('s'); //var pseries = $("input[name=Product_Color]:checked").parent().data('e'); $("input[name=cProductItem_ID]").val(pcolor); $("input[name=cProductModel_ID]").val(psize); // $("input[name=cProductSeries_ID]").val(pseries); //$("input[name=cProduct_Type]").val(ptype); //console.log('choose color...' + ptype + '--' + pmodel + '--' + psize + '--' + pcolor); if ($("input[name=Product_Size]:checked").val() !== psize) { $("dt.pcapa").removeClass('select'); $("input[name=Product_Size]").filter("[value='" + psize + "']").prop('checked', true).parent().addClass('select'); } if ($("input[name=Product_Model]:checked").val() !== pmodel) { $("dt.pmodel").removeClass('select'); $("input[name=Product_Model]").filter("[value='" + pmodel + "']").prop('checked', true).parent().addClass('select'); } //if ($("input[name=Product_Type]:checked").val() !== ptype) { // $("dt.ptype").removeClass('select'); // $("input[name=Product_Type]").filter("[value='" + ptype + "']").prop('checked', true).parent().addClass('select'); //} //var pimg = $("input[name=Product_Color]:checked").data("img"); //console.log($("input[name=Product_Color]:checked").data("img")); $(".kv_product").addClass("hidekv"); $(".productimg").attr("src", $("input[name=Product_Color]:checked").data("img")); $("dd.pcolor").removeClass('select'); $(this).parent().addClass('select'); }); if ($("input[name=cProductItem_ID]").val() !== "") { $("input[name=Product_Color][value=" + $("input[name=cProductItem_ID]").val() + "]").prop("checked", true); $("dd.pcolor[data-s='" + $("input[name=Product_Color]:checked").parent().data('s') + "']").removeClass("hide"); $("dt.pcapa[data-m='" + $("input[name=Product_Color]:checked").parent().data('m') + "']").removeClass("hide"); $("dt.pmodel[data-t='" + $("input[name=Product_Color]:checked").parent().data('t') + "']").removeClass("hide"); $("input[name=Product_Color]:checked").trigger("click"); } else { //還沒選 var ptype = $("input[name=cProduct_Type]").val(); $("dt.pmodel[data-t='" + ptype + "']").removeClass("hide"); var pmodel = $("input[name=Product_Model]:enabled:first").val(); if (pmodel === undefined) pmodel = $("input[name=Product_Model]:first").val(); $("dt.pcapa[data-t='" + ptype + "'][data-m='" + pmodel + "']").removeClass("hide"); var psize = $("input[name=Product_Size]:enabled:first").val(); if (psize === undefined) psize = $("input[name=Product_Size]:first").val(); $("dd.pcolor[data-s='" + psize + "']").removeClass("hide"); } $("#bBtn").click(function (e) { var url = $(this).data("href"); if ($("input[name=cProductItem_ID]").val() === "") { alert("請確實選擇產品(容量/顏色)"); e.preventDefault(); e.stopPropagation(); return false; } else { $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); } else { location.replace(url + "?uo=" + encodeURIComponent(data.objectz)); } }, "json"); } return false; }); } //step3 資料 if (id('cBtn')) { $("input[name=cUser_Birthday]").attr('readonly', true).datepicker({ changeMonth: true, changeYear: true, showMonthAfterYear: true, clearBtn: true, yearRange: "-80:+0", monthRange: "-6:+6", format: "yyyy/mm/dd", defaultViewDate: "-18y", startDate: "-80y", endDate: "-6y" }); $('#twzipcode').twzipcode({ readonly: true }); //手機品牌 $("select[name=cUsed_Brand]").change(function () { if ($("select[name=cUsed_Brand]").val() !== "") { $("select[name=cUsed_Model]").attr('required', true); var t = $('select[name=cUsed_Brand] option:selected').data("t"); //console.log(t); if (t === "X") { $("input[name=cUsed_Other]").val($("input[name=cUsed_Other]").data("d")).removeClass('hide').attr('required', true); $("select[name=cUsed_Model]").val('').find('option:not(:eq(0))').remove().end().removeAttr('required').attr('disabled', true); } else { $("input[name=cUsed_Other]").val($("input[name=cUsed_Other]").data("d")).removeAttr("required").addClass('hide'); $("select[name=cUsed_Model]").find('option:not(:eq(0))').remove().end().removeAttr("disabled").attr('required', true); if ($("select[name=cUsed_Brand]").val() !== "") { $('select[name=cUsed_Temp] option[data-m=' + $("select[name=cUsed_Brand]").val() + ']').clone().appendTo('select[name=cUsed_Model]'); $("select[name=cUsed_Temp]").find('option:last').clone().appendTo('select[name=cUsed_Model]'); } } } else { $("select[name=cUsed_Model]").removeAttr('required'); } }); if ($("select[name=cUsed_Brand]").val() !== "") { $("select[name=cUsed_Brand]").trigger('change'); } $("select[name=cUsed_Model]").change(function () { //手機品牌 var t = $('select[name=cUsed_Model] option:selected').data("t"); if (t === "X") { $("input[name=cUsed_Other]").val($("input[name=cUsed_Other]").data("d")).removeClass('hide').attr('required', true); } else { $("input[name=cUsed_Other]").val($("input[name=cUsed_Other]").data("d")).addClass('hide').attr('required', false); } }); if ($("select[name=cUsed_Model]").val() !== "") { $("select[name=cUsed_Model]").trigger('change'); } //加碼禮確認 $("input[name=cIsAppend]").click(function () { //console.log($("input[name=cIsAppend]:checked").val()); if ($("input[name=cIsAppend]:checked").val() === "1") {//有 $(".adhbox").removeClass('hide'); $(".adhbox input, .adhbox select").attr('required', true); //$("input[name=cAppend1_SN],input[name=cUser_Address],select[name=district]").attr('required', true); } else { $(".adhbox input, .adhbox select").removeAttr('required'); // $("input[mame=cAppend1_SN],input[name=cUser_Address],select[name=district]").removeAttr('required'); $(".adhbox input, .adhbox select").val(''); $('#twzipcode').twzipcode('reset'); $(".adhbox").addClass('hide'); } }); if ($("input[name=cIsAppend]").is(':checked')) { $("input[name=cIsAppend]:checked").trigger('click'); } // $("#c3Btn").click(function (e) { e.preventDefault(); var lbCloseAni = new TimelineMax(); lbCloseAni.to($('.lb'), .3, { opacity: 0, ease: Linear.easeNone }) .to($('.lb'), .3, { css: { zIndex: -1 } }); $("select[name=cCity]").val(''); $('body').css({ 'overflow': '', 'position': '' }); return false; }); $("#c2Btn").click(function (e) { e.preventDefault(); $("#cBtn").trigger('click'); }); //原c1Btn跳提示換門市, 就不問了 $("#cBtn, #c1Btn").click(function (e) { var url = $(this).data("href"); if (!checkEmpty() || !checkFormat()) { e.preventDefault(); e.stopPropagation(); return false; } else { $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { setTimeout(function () { alert(data.message); // 延遲一些顯示 }, 500); $('html').removeClass('loadingz'); } else { if ($("input[name=mode]").val() === "C") { if (url.indexOf('#') > 0) { location.replace(url.replace(/#/, "?uo=" + encodeURIComponent(data.objectz) + "#")); } else { location.replace(url + "?uo=" + encodeURIComponent(data.objectz)); } } else { location.replace("index.aspx"); } } }, "json"); } return false; }); } //step4 確認後送出 if (id('dBtn')) { $("#dBtn").click(function (e) { if (!checkEmpty() || !checkFormat()) { e.preventDefault(); e.stopPropagation(); return false; } else { $("#d1Btn").trigger('click'); //$('.libtn').trigger('click'); } return false; }); $("#eBtn").click(function (e) { var url = $(this).data("href"); $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { if (data.status == -99) { location.replace("pay_cancel.aspx?uo=" + encodeURIComponent(data.objectz)); } else { alert(data.message); $('html').removeClass('loadingz'); } } else { location.replace(url + "?uo=" + encodeURIComponent(data.objectz)); } }, "json"); return false; }); } // step5 失敗重送 if (id('gBtn')) { $("#gBtn").click(function () { $('html').addClass('loadingz'); location.replace("pay_form.aspx?uo=" + encodeURIComponent($(this).attr('data-n'))); return false; }); } //查詢 if (id('sBtn')) { $("#iconV").click(function () { $("#imgV").attr("src", "api/ajax_captcha.ashx?r=" + Math.random()); return false; }); $("#sBtn").click(function (e) { if (!checkEmpty() || !checkFormat()) { e.preventDefault(); e.stopPropagation(); return false; } else { var url = $(this).data("href"); $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); $("#imgV").attr("src", "api/ajax_captcha.ashx?r=" + Math.random()); } else { if (url.indexOf('#') > 0) { location.replace(url.replace(/#/, "?uo=" + encodeURIComponent(data.objectz) + "#")); } else { location.replace(url + "?uo=" + encodeURIComponent(data.objectz)); } } }, "json"); } return false; }); } //刪除或取消訂單 //預約取機時段 if (id('xBtn') || id('iBtn')) { //依日期換時段 $(document).on("change", "select[name=cReservation_SDate]", function () { //$("select[name=cReservation_SDate]").change(function (e) { //確定日期 if ($("select[name=cReservation_SDate]").val() == '') { $("dl.time dd").empty().append("請先選擇日期"); } else { var s = $('select[name=cReservation_SDate] option:selected').data("s"); //選擇狀態 //console.log(s); if (s === 'N') { //不可選 $(this).closest('.chooseday').nextUntil('.no_open').addClass('hide'); $('#lbResbox .no_open').removeClass('hide'); $('#lbResbox .btnbox ').addClass('hide'); } else { $(this).closest('.chooseday').nextUntil('.no_open').removeClass('hide'); $('#lbResbox .no_open').addClass('hide'); $('#lbResbox .btnbox ').removeClass('hide'); $("input[name=mode]").val('B'); $.post("/api/ajax_booking.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { //swalz.fire("", data.message, "error"); alert(data.message); } else { $("dl.time dd").empty().append(data.objectz); } $('html').removeClass('loadingz'); }, "json"); } } return false; }); //if ($("select[name=cReservation_SDate]").attr("data-o") !== null) { // $("select[name=cReservation_SDate]").val($("select[name=cReservation_SDate]").attr("data-o")).trigger('change'); //} $(document).on("click", "#iBtn", function () { //$("#iBtn").click(function (e) { //確定送出 if (!checkEmpty() || !checkFormat()) { e.preventDefault(); e.stopPropagation(); return false; } else { $("input[name=mode]").val('C'); $('html').addClass('loadingz'); $.post("api/ajax_booking.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); } else { $("span.rmsg").empty().append(data.message); $("#lbResbox .btn_x").addClass('hide'); $("#iBtn").closest('.form').addClass('hide'); $("#iBtn").closest('.form').next().removeClass('hide'); $('html').removeClass('loadingz'); } }, "json"); } return false; }); $(document).on("click", "#jBtn", function () { //$('#jBtn').click(function () { //重新預約 $(this).closest('.reserve_finish').addClass('hide'); $(this).closest('.reserve_finish').prev().removeClass('hide'); }); //詳情內容顯示 $('.information').find('.listtable').find('.more').each(function () { $(this).click(function () { var osn = $(this).data('o'); $("input[name=uo]").val($(this).data('u')); //使用者識別 $("input[name=cBookStore_ID]").val($(this).data('b')); //門市 $("input[name=cOriginal_ID]").val($(this).data('r')); //預約時段 $("input[name=mode]").val('L'); //載入取機 $.post("/api/ajax_booking.ashx", $("#form1").serialize(), function (data) { if (data.status <= 0) { swalz.fire(data.message, "", "error"); if (data.status === -9) { location.replace('check1.aspx'); } } else { $(".lreBox").empty().html(data.objectz); } }, "json"); $('.information .detailcontent').fadeOut(); $('.information').find('#' + osn).slideDown('slow'); }) }) //console.log("xBtn"); $("#xBtn").click(function () { if ($(this).data("n") === undefined) { // //console.log("刪除訂單"); if ($("select[name=cUser_CancelTxt]").val() === undefined) { alert('[訂單取消原因]請確實選擇'); e.preventDefault(); e.stopPropagation(); return false; } else { $("input[name=mode]").val('R'); $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", $("#form1").serialize(), function (data) { if (data.status < 0) { alert("系統忙碌中,請稍後再刪除訂單。"); $('html').removeClass('loadingz'); } else { alert("您已成功刪除訂單。"); location.reload(); } }, "json"); } } else { var uo = $(this).data("n"); if (confirm('提醒您,若您取消本次交易,您的登錄資料將一同取消。')) { $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", { mode: "X", uo: uo }, function (data) { if (data.status < 0) { alert("系統忙碌中,請稍後再取消本次交易。"); $('html').removeClass('loadingz'); } else { alert("您已成功取消本次交易。"); location.replace("index.aspx"); } }, "json"); } } return false; }); //登出 $(".oBtn").click(function () { var url = $(this).data("href"); $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", { mode: "O", uo: $("input[name=uo]").val() }, function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); } else { location.replace(url); } }, "json"); return false; }); } //取消 pop if (id('pBtn')) { //$("#pBtn").click(function () { // $("#cancel-order").modal(); // return false; //}); } //取消(登出) if (id('oBtn')) { $("#oBtn").click(function () { var url = $(this).data("href"); $('html').addClass('loadingz'); $.post("api/ajax_preorder.ashx", { mode: "O", uo: $("input[name=uo]").val() }, function (data) { if (data.status < 0) { alert(data.message); $('html').removeClass('loadingz'); } else { location.replace(url); } }, "json"); return false; }); } //檢查格式 function checkFormat() { var message = ''; $('input[data-validate],textarea[data-validate]').each(function (index, element) { // new RegExp('ab+c', 'i'); var regexp = new RegExp($(element).data('validate'), 'i'); var value = $(element).val(); if (value != '') { if (!regexp.test(value)) { message = fields[element.name] + '的格式不正確,請重新輸入'; return false; } } }); if (message !== '') { alert(message); message = ''; return false; } else { return true; } } //檢查未填的欄位 function checkEmpty() { var flag = true; var obj = '', message = ''; $('input[required]:not([type=radio]):not([type=checkbox]),select[required],textarea[required]').each(function (index, element) { if ($(element).val() === '') { if (element.tagName.toLowerCase() === 'select') { if ($(element).data("f") !== undefined) { message = '請選擇' + $(element).data("f"); } else { message = '請選擇' + fields[element.name]; } } else { if (fields[element.name] === undefined) { message = '請填寫' + $(element).attr("placeholder"); } else { message = '請填寫' + fields[element.name]; } } obj = element.name; flag = false; return false; } }); if (flag) { $('[type=radio][required],[type=checkbox][required]').each(function (index, element) { var group = $(element).attr('name'); if ($('[name=' + group + ']:checked').length === 0) { message = '請確實選擇:' + fields[group]; obj = group; } }); } if (message !== '') { //console.log(message); alert(message); $("[name=" + obj + "]").focus(); message = ''; return false; } else { return true; } } }); // 更換圖檔名稱 function replacePhoto(newPath) { $(".slide .slide-move img").each(function () { var newSrc = $(this).attr('src').replace(/_[a-d]{1}_/, newPath); $(this).attr('src', newSrc); //console.log($(this).attr('src')); }); $('.preview img').attr('src', $('.preview img').attr('src').replace(/_[a-d]{1}_/, newPath)); } //----------------------------必備--------------------------------------------------------------------- function id(DOM) { return document.getElementById(DOM); } function className(DOM) { return document.getElementsByClassName(DOM); } function getParam(name, dvalue) { var AllVars = window.location.search.substring(1); var Vars = AllVars.split("&"); for (i = 0; i < Vars.length; i++) { var Var = Vars[i].split("="); if (Var[0] === name) return Var[1]; } return dvalue; } function trims(s) { return s.replace(/(^[\s]*)|([\s]*$)/g, ""); } //----------------------------驗證--------------------------------------------------------------------- function isChinese(s) { //var patrn = /^[\u4E00-\u9FA5\uF900-\uFA2D]{1,4}$/; //return patrn.test(s); if (s.length < 2) { return false; } else { return true; } } /*! * Datepicker for Bootstrap v1.8.0 (https://github.com/uxsolutions/bootstrap-datepicker) * * Licensed under the Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ ! function (a) { "function" == typeof define && define.amd ? define(["jquery"], a) : a("object" == typeof exports ? require("jquery") : jQuery) }(function (a, b) { function c() { return new Date(Date.UTC.apply(Date, arguments)) } function d() { var a = new Date; return c(a.getFullYear(), a.getMonth(), a.getDate()) } function e(a, b) { return a.getUTCFullYear() === b.getUTCFullYear() && a.getUTCMonth() === b.getUTCMonth() && a.getUTCDate() === b.getUTCDate() } function f(c, d) { return function () { return d !== b && a.fn.datepicker.deprecated(d), this[c].apply(this, arguments) } } function g(a) { return a && !isNaN(a.getTime()) } function h(b, c) { function d(a, b) { return b.toLowerCase() } var e, f = a(b).data(), g = {}, h = new RegExp("^" + c.toLowerCase() + "([A-Z])"); c = new RegExp("^" + c.toLowerCase()); for (var i in f) c.test(i) && (e = i.replace(h, d), g[e] = f[i]); return g } function i(b) { var c = {}; if (q[b] || (b = b.split("-")[0], q[b])) { var d = q[b]; return a.each(p, function (a, b) { b in d && (c[b] = d[b]) }), c } } var j = function () { var b = { get: function (a) { return this.slice(a)[0] }, contains: function (a) { for (var b = a && a.valueOf(), c = 0, d = this.length; c < d; c++) if (0 <= this[c].valueOf() - b && this[c].valueOf() - b < 864e5) return c; return -1 }, remove: function (a) { this.splice(a, 1) }, replace: function (b) { b && (a.isArray(b) || (b = [b]), this.clear(), this.push.apply(this, b)) }, clear: function () { this.length = 0 }, copy: function () { var a = new j; return a.replace(this), a } }; return function () { var c = []; return c.push.apply(c, arguments), a.extend(c, b), c } }(), k = function (b, c) { a.data(b, "datepicker", this), this._process_options(c), this.dates = new j, this.viewDate = this.o.defaultViewDate, this.focusDate = null, this.element = a(b), this.isInput = this.element.is("input"), this.inputField = this.isInput ? this.element : this.element.find("input"), this.component = !!this.element.hasClass("date") && this.element.find(".add-on, .input-group-addon, .btn"), this.component && 0 === this.component.length && (this.component = !1), this.isInline = !this.component && this.element.is("div"), this.picker = a(r.template), this._check_template(this.o.templates.leftArrow) && this.picker.find(".prev").html(this.o.templates.leftArrow), this._check_template(this.o.templates.rightArrow) && this.picker.find(".next").html(this.o.templates.rightArrow), this._buildEvents(), this._attachEvents(), this.isInline ? this.picker.addClass("datepicker-inline").appendTo(this.element) : this.picker.addClass("datepicker-dropdown dropdown-menu"), this.o.rtl && this.picker.addClass("datepicker-rtl"), this.o.calendarWeeks && this.picker.find(".datepicker-days .datepicker-switch, thead .datepicker-title, tfoot .today, tfoot .clear").attr("colspan", function (a, b) { return Number(b) + 1 }), this._process_options({ startDate: this._o.startDate, endDate: this._o.endDate, daysOfWeekDisabled: this.o.daysOfWeekDisabled, daysOfWeekHighlighted: this.o.daysOfWeekHighlighted, datesDisabled: this.o.datesDisabled }), this._allow_update = !1, this.setViewMode(this.o.startView), this._allow_update = !0, this.fillDow(), this.fillMonths(), this.update(), this.isInline && this.show() }; k.prototype = { constructor: k, _resolveViewName: function (b) { return a.each(r.viewModes, function (c, d) { if (b === c || a.inArray(b, d.names) !== -1) return b = c, !1 }), b }, _resolveDaysOfWeek: function (b) { return a.isArray(b) || (b = b.split(/[,\s]*/)), a.map(b, Number) }, _check_template: function (c) { try { if (c === b || "" === c) return !1; if ((c.match(/[<>]/g) || []).length <= 0) return !0; var d = a(c); return d.length > 0 } catch (a) { return !1 } }, _process_options: function (b) { this._o = a.extend({}, this._o, b); var e = this.o = a.extend({}, this._o), f = e.language; q[f] || (f = f.split("-")[0], q[f] || (f = o.language)), e.language = f, e.startView = this._resolveViewName(e.startView), e.minViewMode = this._resolveViewName(e.minViewMode), e.maxViewMode = this._resolveViewName(e.maxViewMode), e.startView = Math.max(this.o.minViewMode, Math.min(this.o.maxViewMode, e.startView)), e.multidate !== !0 && (e.multidate = Number(e.multidate) || !1, e.multidate !== !1 && (e.multidate = Math.max(0, e.multidate))), e.multidateSeparator = String(e.multidateSeparator), e.weekStart %= 7, e.weekEnd = (e.weekStart + 6) % 7; var g = r.parseFormat(e.format); e.startDate !== -(1 / 0) && (e.startDate ? e.startDate instanceof Date ? e.startDate = this._local_to_utc(this._zero_time(e.startDate)) : e.startDate = r.parseDate(e.startDate, g, e.language, e.assumeNearbyYear) : e.startDate = -(1 / 0)), e.endDate !== 1 / 0 && (e.endDate ? e.endDate instanceof Date ? e.endDate = this._local_to_utc(this._zero_time(e.endDate)) : e.endDate = r.parseDate(e.endDate, g, e.language, e.assumeNearbyYear) : e.endDate = 1 / 0), e.daysOfWeekDisabled = this._resolveDaysOfWeek(e.daysOfWeekDisabled || []), e.daysOfWeekHighlighted = this._resolveDaysOfWeek(e.daysOfWeekHighlighted || []), e.datesDisabled = e.datesDisabled || [], a.isArray(e.datesDisabled) || (e.datesDisabled = e.datesDisabled.split(",")), e.datesDisabled = a.map(e.datesDisabled, function (a) { return r.parseDate(a, g, e.language, e.assumeNearbyYear) }); var h = String(e.orientation).toLowerCase().split(/\s+/g), i = e.orientation.toLowerCase(); if (h = a.grep(h, function (a) { return /^auto|left|right|top|bottom$/.test(a) }), e.orientation = { x: "auto", y: "auto" }, i && "auto" !== i) if (1 === h.length) switch (h[0]) { case "top": case "bottom": e.orientation.y = h[0]; break; case "left": case "right": e.orientation.x = h[0] } else i = a.grep(h, function (a) { return /^left|right$/.test(a) }), e.orientation.x = i[0] || "auto", i = a.grep(h, function (a) { return /^top|bottom$/.test(a) }), e.orientation.y = i[0] || "auto"; else; if (e.defaultViewDate instanceof Date || "string" == typeof e.defaultViewDate) e.defaultViewDate = r.parseDate(e.defaultViewDate, g, e.language, e.assumeNearbyYear); else if (e.defaultViewDate) { var j = e.defaultViewDate.year || (new Date).getFullYear(), k = e.defaultViewDate.month || 0, l = e.defaultViewDate.day || 1; e.defaultViewDate = c(j, k, l) } else e.defaultViewDate = d() }, _events: [], _secondaryEvents: [], _applyEvents: function (a) { for (var c, d, e, f = 0; f < a.length; f++) c = a[f][0], 2 === a[f].length ? (d = b, e = a[f][1]) : 3 === a[f].length && (d = a[f][1], e = a[f][2]), c.on(e, d) }, _unapplyEvents: function (a) { for (var c, d, e, f = 0; f < a.length; f++) c = a[f][0], 2 === a[f].length ? (e = b, d = a[f][1]) : 3 === a[f].length && (e = a[f][1], d = a[f][2]), c.off(d, e) }, _buildEvents: function () { var b = { keyup: a.proxy(function (b) { a.inArray(b.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1 && this.update() }, this), keydown: a.proxy(this.keydown, this), paste: a.proxy(this.paste, this) }; this.o.showOnFocus === !0 && (b.focus = a.proxy(this.show, this)), this.isInput ? this._events = [ [this.element, b] ] : this.component && this.inputField.length ? this._events = [ [this.inputField, b], [this.component, { click: a.proxy(this.show, this) }] ] : this._events = [ [this.element, { click: a.proxy(this.show, this), keydown: a.proxy(this.keydown, this) }] ], this._events.push([this.element, "*", { blur: a.proxy(function (a) { this._focused_from = a.target }, this) }], [this.element, { blur: a.proxy(function (a) { this._focused_from = a.target }, this) }]), this.o.immediateUpdates && this._events.push([this.element, { "changeYear changeMonth": a.proxy(function (a) { this.update(a.date) }, this) }]), this._secondaryEvents = [ [this.picker, { click: a.proxy(this.click, this) }], [this.picker, ".prev, .next", { click: a.proxy(this.navArrowsClick, this) }], [this.picker, ".day:not(.disabled)", { click: a.proxy(this.dayCellClick, this) }], [a(window), { resize: a.proxy(this.place, this) }], [a(document), { "mousedown touchstart": a.proxy(function (a) { this.element.is(a.target) || this.element.find(a.target).length || this.picker.is(a.target) || this.picker.find(a.target).length || this.isInline || this.hide() }, this) }] ] }, _attachEvents: function () { this._detachEvents(), this._applyEvents(this._events) }, _detachEvents: function () { this._unapplyEvents(this._events) }, _attachSecondaryEvents: function () { this._detachSecondaryEvents(), this._applyEvents(this._secondaryEvents) }, _detachSecondaryEvents: function () { this._unapplyEvents(this._secondaryEvents) }, _trigger: function (b, c) { var d = c || this.dates.get(-1), e = this._utc_to_local(d); this.element.trigger({ type: b, date: e, viewMode: this.viewMode, dates: a.map(this.dates, this._utc_to_local), format: a.proxy(function (a, b) { 0 === arguments.length ? (a = this.dates.length - 1, b = this.o.format) : "string" == typeof a && (b = a, a = this.dates.length - 1), b = b || this.o.format; var c = this.dates.get(a); return r.formatDate(c, b, this.o.language) }, this) }) }, show: function () { if (!(this.inputField.prop("disabled") || this.inputField.prop("readonly") && this.o.enableOnReadonly === !1)) return this.isInline || this.picker.appendTo(this.o.container), this.place(), this.picker.show(), this._attachSecondaryEvents(), this._trigger("show"), (window.navigator.msMaxTouchPoints || "ontouchstart" in document) && this.o.disableTouchKeyboard && a(this.element).blur(), this }, hide: function () { return this.isInline || !this.picker.is(":visible") ? this : (this.focusDate = null, this.picker.hide().detach(), this._detachSecondaryEvents(), this.setViewMode(this.o.startView), this.o.forceParse && this.inputField.val() && this.setValue(), this._trigger("hide"), this) }, destroy: function () { return this.hide(), this._detachEvents(), this._detachSecondaryEvents(), this.picker.remove(), delete this.element.data().datepicker, this.isInput || delete this.element.data().date, this }, paste: function (b) { var c; if (b.originalEvent.clipboardData && b.originalEvent.clipboardData.types && a.inArray("text/plain", b.originalEvent.clipboardData.types) !== -1) c = b.originalEvent.clipboardData.getData("text/plain"); else { if (!window.clipboardData) return; c = window.clipboardData.getData("Text") } this.setDate(c), this.update(), b.preventDefault() }, _utc_to_local: function (a) { if (!a) return a; var b = new Date(a.getTime() + 6e4 * a.getTimezoneOffset()); return b.getTimezoneOffset() !== a.getTimezoneOffset() && (b = new Date(a.getTime() + 6e4 * b.getTimezoneOffset())), b }, _local_to_utc: function (a) { return a && new Date(a.getTime() - 6e4 * a.getTimezoneOffset()) }, _zero_time: function (a) { return a && new Date(a.getFullYear(), a.getMonth(), a.getDate()) }, _zero_utc_time: function (a) { return a && c(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate()) }, getDates: function () { return a.map(this.dates, this._utc_to_local) }, getUTCDates: function () { return a.map(this.dates, function (a) { return new Date(a) }) }, getDate: function () { return this._utc_to_local(this.getUTCDate()) }, getUTCDate: function () { var a = this.dates.get(-1); return a !== b ? new Date(a) : null }, clearDates: function () { this.inputField.val(""), this.update(), this._trigger("changeDate"), this.o.autoclose && this.hide() }, setDates: function () { var b = a.isArray(arguments[0]) ? arguments[0] : arguments; return this.update.apply(this, b), this._trigger("changeDate"), this.setValue(), this }, setUTCDates: function () { var b = a.isArray(arguments[0]) ? arguments[0] : arguments; return this.setDates.apply(this, a.map(b, this._utc_to_local)), this }, setDate: f("setDates"), setUTCDate: f("setUTCDates"), remove: f("destroy", "Method `remove` is deprecated and will be removed in version 2.0. Use `destroy` instead"), setValue: function () { var a = this.getFormattedDate(); return this.inputField.val(a), this }, getFormattedDate: function (c) { c === b && (c = this.o.format); var d = this.o.language; return a.map(this.dates, function (a) { return r.formatDate(a, c, d) }).join(this.o.multidateSeparator) }, getStartDate: function () { return this.o.startDate }, setStartDate: function (a) { return this._process_options({ startDate: a }), this.update(), this.updateNavArrows(), this }, getEndDate: function () { return this.o.endDate }, setEndDate: function (a) { return this._process_options({ endDate: a }), this.update(), this.updateNavArrows(), this }, setDaysOfWeekDisabled: function (a) { return this._process_options({ daysOfWeekDisabled: a }), this.update(), this }, setDaysOfWeekHighlighted: function (a) { return this._process_options({ daysOfWeekHighlighted: a }), this.update(), this }, setDatesDisabled: function (a) { return this._process_options({ datesDisabled: a }), this.update(), this }, place: function () { if (this.isInline) return this; var b = this.picker.outerWidth(), c = this.picker.outerHeight(), d = 10, e = a(this.o.container), f = e.width(), g = "body" === this.o.container ? a(document).scrollTop() : e.scrollTop(), h = e.offset(), i = [0]; this.element.parents().each(function () { var b = a(this).css("z-index"); "auto" !== b && 0 !== Number(b) && i.push(Number(b)) }); var j = Math.max.apply(Math, i) + this.o.zIndexOffset, k = this.component ? this.component.parent().offset() : this.element.offset(), l = this.component ? this.component.outerHeight(!0) : this.element.outerHeight(!1), m = this.component ? this.component.outerWidth(!0) : this.element.outerWidth(!1), n = k.left - h.left, o = k.top - h.top; "body" !== this.o.container && (o += g), this.picker.removeClass("datepicker-orient-top datepicker-orient-bottom datepicker-orient-right datepicker-orient-left"), "auto" !== this.o.orientation.x ? (this.picker.addClass("datepicker-orient-" + this.o.orientation.x), "right" === this.o.orientation.x && (n -= b - m)) : k.left < 0 ? (this.picker.addClass("datepicker-orient-left"), n -= k.left - d) : n + b > f ? (this.picker.addClass("datepicker-orient-right"), n += m - b) : this.o.rtl ? this.picker.addClass("datepicker-orient-right") : this.picker.addClass("datepicker-orient-left"); var p, q = this.o.orientation.y; if ("auto" === q && (p = -g + o - c, q = p < 0 ? "bottom" : "top"), this.picker.addClass("datepicker-orient-" + q), "top" === q ? o -= c + parseInt(this.picker.css("padding-top")) : o += l, this.o.rtl) { var r = f - (n + m); this.picker.css({ top: o, right: r, zIndex: j }) } else this.picker.css({ top: o, left: n, zIndex: j }); return this }, _allow_update: !0, update: function () { if (!this._allow_update) return this; var b = this.dates.copy(), c = [], d = !1; return arguments.length ? (a.each(arguments, a.proxy(function (a, b) { b instanceof Date && (b = this._local_to_utc(b)), c.push(b) }, this)), d = !0) : (c = this.isInput ? this.element.val() : this.element.data("date") || this.inputField.val(), c = c && this.o.multidate ? c.split(this.o.multidateSeparator) : [c], delete this.element.data().date), c = a.map(c, a.proxy(function (a) { return r.parseDate(a, this.o.format, this.o.language, this.o.assumeNearbyYear) }, this)), c = a.grep(c, a.proxy(function (a) { return !this.dateWithinRange(a) || !a }, this), !0), this.dates.replace(c), this.o.updateViewDate && (this.dates.length ? this.viewDate = new Date(this.dates.get(-1)) : this.viewDate < this.o.startDate ? this.viewDate = new Date(this.o.startDate) : this.viewDate > this.o.endDate ? this.viewDate = new Date(this.o.endDate) : this.viewDate = this.o.defaultViewDate), d ? (this.setValue(), this.element.change()) : this.dates.length && String(b) !== String(this.dates) && d && (this._trigger("changeDate"), this.element.change()), !this.dates.length && b.length && (this._trigger("clearDate"), this.element.change()), this.fill(), this }, fillDow: function () { if (this.o.showWeekDays) { var b = this.o.weekStart, c = "