///
' + tempCateError + '
'); $(staffCateLsit).each(function (k) { var cusDDLI = $('' + tempNoError + '
'); //tempNoError $(ccstaffNoInput).appendTo(ccstaffNoDiv); $(ccstaffNoDiv).appendTo(staffItemDiv); $(errorNo).appendTo(ccstaffNoDiv); }); function removeStaffItem() { $(".removeStaff").each(function (n) { console.log("here"); $(this).bind("click", function () { console.log("click"); $(this).parent(".staffItem").remove(); if ($(".staffItem").length == 1) { console.log("L:", $(".staffItem").length); $(".removeStaff").addClass("hidden"); } else { console.log("LB:", $(".staffItem").length); } }); }); } function selectNewStaffDD(num) { $("#staff-cate-dropdown" + num + "-list li").each(function (m) { console.log("here"); $(this).find('a').bind("click", function () { console.log("id:", "#staff-cate-dropdown" + m + "-list li"); $("#staff-cate-dropdown" + num + "-list li").find('a').removeClass('selected'); $("#staff-cate-dropdown" + num + "-list li").eq(m).find('a').addClass('selected'); var textValue = $("#staff-cate-dropdown" + num + "-list li").eq(m).find('a').text(); $("#staff-cate-dropdown" + num + " span").text(textValue); $("#staff-cate-dropdown" + num + "-list").removeClass("opened"); $("#staff-cate-dropdown" + num + "-list").attr("aria-hidden", true); $("#staff-cate-dropdown" + num).attr("aria-expanded", false); }); }); } //select Offer type Val $("#office-type-dropdown-list li").each(function (i) { $("#office-type-dropdown-list li").eq(i).bind("click", function () { if ($(this).find("a").attr("data-value") == "NotYetDecided") { $(".officeTypeDetail").addClass("disabled"); } else { $(".officeTypeDetail").removeClass("disabled"); officeLocation == true; } }); }); //select industry Val $("#industry-dropdown-list li").each(function (i) { $("#industry-dropdown-list li").eq(i).bind("click", function () { if ($(this).find("a").attr("data-value") == "NotYetDecided") { $(".ccindustryDetail").addClass("disabled"); } else { $(".ccindustryDetail").removeClass("disabled"); } }); }); //Estimation Calculate $(".estimateBtn span").bind("click", function () { var validForm = true; var tandCValid = true; var officeTypeValid = true; var sizeValid = true; var indValid = true; var cateValid = true; var staffNoValid = true; var childValid = true; $('.m-form__error').hide(0); pushStaffArrayFn(); officeSizeVal = $("#size").val(); //checkbox valid if ($(".agreeNoticeWrapper").find('input').attr('required') && !$(".agreeNoticeWrapper").find('input').is(':checked')) { // console.log("a") $(".agreeNoticeWrapper").find('.m-form__error').show(0); tandCValid = false; } else { // console.log("b") $(".agreeNoticeWrapper").find('.m-form__error').hide(0); tandCValid = true; } //Office Type valid if ($("#office-type-dropdown-list li").find(".selected").attr("data-value") == "" || $("#office-type-dropdown-list li").find(".selected").attr("data-value") == undefined) { $(".ccofficeType").find('.m-form__error').show(0); officeTypeValid = false; } else { $(".ccofficeType").find('.m-form__error').hide(0); officeTypeValid = true; if ($("#office-type-dropdown-list li").find(".selected").attr("data-value") != "NotYetDecided") { //Location Valid if (officeLocationVal == "" || officeLocationVal == undefined) { $(".cclocation").find('.m-form__error').show(0); officeTypeValid = false; } else { $(".cclocation").find('.m-form__error').hide(0); officeTypeValid = true; } //Size valid if (officeSizeVal == "" || officeSizeVal == undefined) { $(".ccsize").find('.m-form__error').show(0); sizeValid = false; } else { if (officeSizeVal == 0) { $(".ccsize").find('.m-form__error').show(0); sizeValid = false; } else { $(".ccsize").find('.m-form__error').hide(0); sizeValid = true; } if ($("#size").val().length > 6) { $(".ccsize").find('.m-form__error').show(0); sizeValid = false; } } } } //Industry valid if ($("#industry-dropdown-list li").find(".selected").attr("data-value") == "" || $("#industry-dropdown-list li").find(".selected").attr("data-value") == undefined) { $(".ccindustry").find('.m-form__error').show(0); indValid = false; } else { // var cateValid = false; // var staffNoValid = false; indValid = true; var cateValidNo = 0; var staffNoValidNo = 0; if ($("#industry-dropdown-list li").find(".selected").attr("data-value") != "NotYetDecided") { $(".staffItem").each(function (i) { var currentCate = $(".staffItem").eq(i).find("ul .selected").attr("data-value"); var currentNoStaff = $(".staffItem").eq(i).find(".ccstaffNo .m-form__field").val(); if (currentCate == "" || currentCate == undefined) { $(".staffItem").eq(i).find(".errorCate").show(0); cateValidNo++; // console.log($(".staffItem").eq(i).find(".errorCate").attr("class")) } if (currentNoStaff == "" || currentNoStaff == undefined) { $(".staffItem").eq(i).find(".errorNo").show(0); staffNoValidNo++; // console.log($(".staffItem").eq(i).find(".errorNo").attr("class")) } else { if (currentNoStaff == 0) { $(".staffItem").eq(i).find(".errorNo").show(0); staffNoValidNo++; } if ($(".staffItem").eq(i).find(".ccstaffNo .m-form__field").val().length > 4) { $(".staffItem").eq(i).find(".errorNo").show(0); staffNoValidNo++; } } }); if (cateValidNo > 0) { cateValid = false; } if (staffNoValidNo > 0) { staffNoValid = false; } } } //No. of Children if ($("#children-dropdown-list li").find(".selected").attr("data-value") == "" || $("#children-dropdown-list li").find(".selected").attr("data-value") == undefined) { $(".schoolChildren").find('.m-form__error').show(0); childValid = false; } if (tandCValid && officeTypeValid && sizeValid && indValid && cateValid && staffNoValid && childValid) { var formData = { officeType: $("#office-type-dropdown-list li").find(".selected").attr("data-value"), officeLocation: officeLocationVal, officeSize: officeSizeVal, industryVal: $("#industry-dropdown-list li").find(".selected").attr("data-value"), staffArrayVal: staffArray, childNum: $("#children-dropdown-list li").find(".selected").attr("data-value") }; var lang = $('html').attr('lang'); $.ajax({ url: apiDomain + "?q=services/session/session_token", type: "get", dataType: "text", crossDomain: true, xhrFields: { withCredentials: true }, error: function (jqXHR, textStatus, errorThrown) { //alert(errorThrown); }, success: function (token) { window.sessionToken = token; $.ajax({ type: 'post', url: apiDomain + '/' + lang + '/api/cost-calculate', data: JSON.stringify(formData), contentType: "application/json; charset=utf-8", traditional: true, headers: { 'X-CSRF-Token': window.sessionToken }, success: function (data) { calculatorData = JSON.stringify(data); genEstimateResult(data); $(".estimationContent").addClass("active"); $(".costCalculatorContent").addClass("hidden"); $('html, body').animate({ scrollTop: 0 }, 500); } }); } }); } else { $('html, body').animate({ scrollTop: 0 }, 500); } }); function genEstimateResult(result) { // console.log("resultArray:", result) // console.log(operatingCost); //Operating Cost var operatingCostHkd = result['hkd']['operating_cost']; var operatingCostUsd = result['usd']['operating_cost']; // console.log("operatingCostUsd:", operatingCostUsd); if (operatingCostHkd && operatingCostUsd) { // console.log("opCost.tostring:", operatingCostUsd['10th'].toLocaleString()); $('.opCostHK h3').text(operatingCostHkd['10th'].toLocaleString() + " - " + operatingCostHkd['90th'].toLocaleString()); $('.opCostHK h4 span').text(operatingCostHkd['median'].toLocaleString()); $('.opCostUS h3').text(Math.round(operatingCostUsd['10th']).toLocaleString() + " - " + Math.round(operatingCostUsd['90th']).toLocaleString()); $('.opCostUS h4 span').text(Math.round(operatingCostUsd['median']).toLocaleString()); } else { $('.opCostHK h3').text('Not yet decided'); $('.opCostHK h4').text('Not yet decided'); $('.opCostUS h3').text('Not yet decided'); $('.opCostUS h4').text('Not yet decided'); } //Setup Cost $('.setCostHK h3').text(result['hkd']['setup_cost']['min'].toLocaleString() + " - " + result['hkd']['setup_cost']['max'].toLocaleString()); $('.setCostUS h3').text(Math.round(result['usd']['setup_cost']['min']).toLocaleString() + " - " + Math.round(result['usd']['setup_cost']['max']).toLocaleString()); //Cost of Living var totalCLHK = result['hkd']['living_cost']['total']; var totalCLUS = result['usd']['living_cost']['total']; // console.log("totalCLUS:", totalCLUS); // console.log("totalCLUS.toLocaleString():", totalCLUS.toLocaleString()); $('.costLivingHK h3').text(totalCLHK.toLocaleString()); $('.costLivingUS h3').text(Math.round(totalCLUS).toLocaleString()); //Education // console.log("eduCostUS:", result['usd']['education_cost']['min']); // console.log("eduCostUS.toLocaleString():", result['usd']['education_cost']['min'].toLocaleString()); $('.eduCostHK h3').text(result['hkd']['education_cost']['min'].toLocaleString() + " - " + result['hkd']['education_cost']['max'].toLocaleString()); $('.eduCostUS h3').text(Math.round(result['usd']['education_cost']['min']).toLocaleString() + " - " + Math.round(result['usd']['education_cost']['max']).toLocaleString()); // $('.generateCost__submit').attr("data-key", result['key']); $('#generateCostForm').find('input[name=ccr-key]').val(result['key']); } function pushStaffArrayFn() { staffArray = []; var industry = $("#industry-dropdown-list li").find(".selected").attr("data-value"); if (industry && industry !== 'NotYetDecided') { $(".staffItem").each(function (i) { staffArray.push({ // category: $("#staff-cate-dropdown" + i + "-list li").find(".selected").attr("data-value"), // number: $("#staffNo" + i).val() category: $(this).find("ul li .selected").attr("data-value"), number: $(this).find(".ccstaffNo input").val() }); }); } } // For generate the file $('.generateCost__submit').attr('tabindex', 0); $('.generateCost__submit').on('click', function (e) { contactusFormSubmitG(e); }); $(document).on('keydown', "#generateCostForm input", function (e) { if (e.keyCode == 13) { contactusFormSubmitG(e); } }); function contactusFormSubmitG(e) { var isError = false; e.preventDefault(); $('.checkbox-with-desc').each(function () { var input = $(this).find('input'); if (input.attr('required') && !input.is(':checked')) { isError = true; $(this).find('.error-msg').show(0); } else { $(this).find('.error-msg').hide(0); } }); var result = checkValidation({ targetForm: "generateCostForm" }); if ($("#m-industry-dropdown-list li").find(".selected").attr("data-value") == "" || $("#m-industry-dropdown-list li").find(".selected").attr("data-value") == undefined) { $(".mIndustry").find('.m-form__error').show(0); isError = true; } else { $(".mIndustry").find('.m-form__error').hide(0); } if (result && !isError) { // $('.generateCost__submit').off(); $('.generateCost__message').remove(); var lang = $('html').attr('lang'); var requestPage = apiDomain + '/' + lang + '/api/cost-calculate-export'; var formData = $('#generateCostForm').serialize() + '&calData=' + calculatorData; sendDownloadRequest(requestPage, formData); // $('.generateCost__submit').addClass('hidden') // $('').appendTo($('.generateCost__submit').parents('.m-form__section')); } } function padStart(str, length, char) { if (str.length < length) { for (var i = 0; i < (length - str.length); i++) { str = char + str; } } return str; } function sendDownloadRequest(requestPage, formData) { $.ajax({ method: "POST", url: requestPage, //dataType : 'jsonp', data: formData, crossDomain: true, xhrFields: { withCredentials: true }, headers: { 'X-CSRF-Token': window.sessionToken }, xhrFields: { responseType: 'blob' // to avoid binary data being mangled on charset conversion }, success: function (blob, status, xhr) { var now = new Date(); var ddmmyyyy = padStart(String(now.getDate()), 2, '0') + padStart(String(now.getMonth() + 1), 2, '0') + now.getFullYear(); var hhmm = padStart(String(now.getHours()), 2, '0') + padStart(String(now.getMinutes()), 2, '0'); var filename = 'Hong-Kong-Setup-Cost-Estimation-Report-' + ddmmyyyy + '-' + hhmm + '.xlsx'; if (navigator.msSaveOrOpenBlob) { navigator.msSaveOrOpenBlob(blob, filename); } else { var URL = https://www.investhk.gov.hk/sites/all/themes/investhk/js/window.URL || window.webkitURL; var downloadUrl = URL.createObjectURL(blob); // use HTML5 a[download] attribute to specify filename var a = document.createElement("a"); // safari doesn't support this yet a.href = downloadUrl; a.download = filename; document.body.appendChild(a); a.click(); } } }); } // not allow number for input $(document).on('keydown', '#m-lastName, #m-firstName', function (e) { if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) { return false; } }); //mouseenter the infomation icon var isMobile = false; //initiate as false // device detection if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) isMobile = true; // console.log("isMobile:", isMobile) if (isMobile) { $('.officeTypeInfo').on('click', function (e) { $(".custom-dropdown ul").removeClass("opened"); $(".custom-dropdown ul").attr("aria-hidden", true); $(".custom-dropdown a").attr("aria-expanded", false); if ($(".infoIcon").hasClass("active")) { e.stopPropagation(); $(".infoIcon").removeClass("active"); } else { e.stopPropagation(); $(".infoIcon").addClass("active"); } }); } else { $('.officeTypeInfo').on('mouseleave', function (e) { e.stopPropagation(); $(".infoIcon").removeClass("active"); }); $('.officeTypeInfo').on('mouseenter', function (e) { e.stopPropagation(); $(".infoIcon").addClass("active"); }); } $("#office-type-dropdown").on('click', function () { $(".infoIcon").removeClass("active"); }); // $('.officeTypeInfo').on('mouseleave', function (e) { // e.stopPropagation(); // $(".infoIcon").removeClass("active"); // }); // $('.officeTypeInfo').on('mouseenter', function (e) { // e.stopPropagation(); // $(".infoIcon").addClass("active"); // }); // $('.officeTypeInfo').on('mouseleave', function (e) { // e.stopPropagation(); // $(".infoIcon").removeClass("active"); // }); $(".bkToCostCalInput span").bind("click", function () { $(".estimationContent").removeClass("active"); $(".costCalculatorContent").removeClass("hidden"); }); });