$(function() { var userAgent; var queryList; var ipAddressValue; var ruleId; var securityId; function getHeader() { var sid = aes_decrypt2(localStorage.getItem("sid")); var header = JSON.parse('{"sid":"'+sid+'","code":0,"Content-Type":"application/json"}'); return header; } function getQuery() { var query = {}; var search = location.search; var searchSplit = search.split('?'); if(searchSplit[1] !== undefined) { var items = searchSplit[1].split('&'); items.forEach(function (currentItem){ var searchArr = currentItem.split('='); query[searchArr[0]] = searchArr[1]; }); } return query; }; function CommonObj(ip, userAgent, query) { this.machineNo = ""; this.ipAddress = ip; this.osType = userAgent.osTypeValue; this.model = "web"; this.deviceVersion = userAgent.deviceVersion; this.appVersion = userAgent.appVersion; this.deviceType = userAgent.deviceType; this.apType = 2; this.browser = userAgent.browserValue; this.memberId = ""; this.domain = location.hostname; this.utmSource = query['utm_source'] ||''; if (this.utmSource==='' && query['gclid']) this.utmSource="gclid"; this.utmMedium = query['utm_medium'] || ''; this.utmCampaign = query['utm_campaign'] || ''; this.utmCode = query['utm_code'] || ''; this.requestor = 1; this.utmContent = query['utm_content'] || '';; this.utmTerm = query['utm_term'] || '';; this.sinyiGroup = 1; }; function callPolicy() { var commonDataPolicy = new CommonObj(ipAddressValue, userAgent, queryList); commonDataPolicy.siteName = 'sinyi'; commonDataPolicy.retType = 0;//2服務條款 1隱私權 0服務條款和隱私權 commonDataPolicy.securityName = 'sinyiprivacy'; var commonDataStf = JSON.stringify(commonDataPolicy); $.ajax({ url: 'https://sinyiwebapi.sinyi.com.tw/bypass/getSitePolicy.php', method: 'POST', headers: getHeader(), crossDomain: true, dataType: "json", data: commonDataStf, success: function(data){ var ruleContent = data.content.ruleContent; var securityContent = data.content.securityContent; ruleId = data.content.ruleId; securityId = data.content.securityId; return data; } }); }; function getIp(){ $.ajax({ url:'https://api.ipify.org', method: 'get', success: function(ip){ ipAddressValue = ip; callPolicy(); } }); }; function getUserAgent(){ var parser = new UAParser(); var result = parser.getResult(); var deviceVersion; var appVersion; var deviceType; switch (result.os.name) { case 'Android': osTypeValue = 7; break; case 'iOS': osTypeValue = 8; break; case 'Windows': osTypeValue = 9; break; case 'MAC': osTypeValue = 10; break; case 'Linux': osTypeValue = 11; break; default: osTypeValue = 12; break; } switch (result.browser.name) { case 'Chrome': browserValue = 8; break; case 'IE': browserValue = 9; break; case 'Firefox': browserValue = 10; break; case 'Safari': browserValue = 11; break; case 'Opera': browserValue = 12; break; case 'Edge': browserValue = 13; break; default: browserValue = 12; break; } switch (result.device.type) { case 'mobile': deviceType = 1; break; case 'table': deviceType = 2; break; default: deviceType = 3; break; } deviceVersion = result.os.name + result.os.version; appVersion = result.browser.version; return { 'osTypeValue': osTypeValue, 'browserValue':browserValue, 'deviceVersion': deviceVersion, 'appVersion': appVersion, 'deviceType': deviceType } }; function checkData() { var name=""; var gender=""; var phoneNumber=""; var location = ""; var city=""; var zipCode=""; var address=""; var contactTime=""; var content=""; var privacyCheck=""; var commonDataToLandlord=""; var verifyCode=""; var patt = /^[09]{2}[0-9]{8}$/; var returnValue = true; var msg = ""; var cookie = decrypt_js(getCookie('rand')); if($(".surroundings-content").eq(0).is(":visible")){ rwdmodel="PC"; } if($(".surroundings-content").eq(1).is(":visible")){ rwdmodel="M"; } if(rwdmodel=="PC"){ if( $("#theForm input[name='name']").val() == "") { msg += "【您的姓名】欄位,為必填欄位!\n"; returnValue = false; } if( $("#theForm input[name='sex']:checked").val() === undefined) { returnValue = false; } if( $("#theForm input[name='tel']").val() === '') { msg += "【手機號碼】欄位,未填或格式不正確。\n"; returnValue = false; } if( $('#theForm select[name="city"]').val() === '' || $('#theForm select[name="dist"]').val() === '' || $('#theForm input[name="address"]').val() === '' ) { msg += "【出租地址】欄位,為必填欄位!\n"; returnValue = false; } // if(address[0].indexOf(" ") != -1) { // msg += "【出租地址】欄位,不可有空白!\n"; // returnValue = false; // } if( $("#theForm input[name='verifycode']").val() === '') { msg += "【驗證碼】欄位,為必填欄位!\n"; returnValue = false; } if( $("#theForm input[name='verifycode']").val() !== '') { if( $("#theForm input[name='verifycode']").val() !== cookie) { msg += "驗證碼錯誤!\n"; returnValue = false; } } if(!($('#cbagree').prop('checked'))) { msg += "請確認您已閱讀並同意本站【服務條款】與【隱私聲明】,謝謝!"; returnValue = false; } name = $("#theForm [name='name']").val(); gender = $('#theForm [name="sex"]:checked').val(); phoneNumber = $("#theForm [name='tel']").val(); city = $("#theForm [name='city']").val(); zipCode = $("#theForm [name='dist']").val(); address = $("#theForm [name='address']").val(); contactTime = $('#theForm [name="date"]').val(); content = $("#theForm [name='content']").val(); privacyCheck = $('#cbagree').prop('checked'); } if(rwdmodel=="M"){ if( $("#theFormM input[name='name']").val() == "") { msg += "【您的姓名】欄位,為必填欄位!\n"; returnValue = false; } if( $("#theFormM input[name='sex']:checked").val() === undefined) { returnValue = false; } if( $("#theFormM input[name='tel']").val() === '') { msg += "【手機號碼】欄位,未填或格式不正確。\n"; returnValue = false; } if( $('#theFormM select[name="city"]').val() === '' || $('#theFormM select[name="dist"]').val() === '' || $('#theFormM input[name="address"]').val() === '' ) { msg += "【出租地址】欄位,為必填欄位!\n"; returnValue = false; } // if(address[0].indexOf(" ") != -1) { // msg += "【出租地址】欄位,不可有空白!\n"; // returnValue = false; // } if( $("#theFormM input[name='verifycode']").val() === '') { msg += "【驗證碼】欄位,為必填欄位!\n"; returnValue = false; } if( $("#theFormM input[name='verifycode']").val() !== '') { if( $("#theFormM input[name='verifycode']").val() !== cookie ) { msg += "驗證碼錯誤!\n"; returnValue = false; } } if(!($('#cbagree').prop('checked'))) { msg += "請確認您已閱讀並同意本站【服務條款】與【隱私聲明】,謝謝!"; returnValue = false; } name = $("#theFormM [name='name']").val(); gender = $('#theFormM [name="sex"]:checked').val(); phoneNumber = $("#theFormM [name='tel']").val(); city = $("#theFormM [name='city']").val(); zipCode = $("#theFormM [name='dist']").val(); address = $("#theFormM [name='address']").val(); contactTime = $('#theFormM [name="date"]').val(); content = $("#theFormM [name='content']").val(); privacyCheck = $('#cbagree').prop('checked'); } commonDataToLandlord = new CommonObj(ipAddressValue, userAgent, queryList); commonDataToLandlord.name = name; commonDataToLandlord.phoneNumber = phoneNumber; commonDataToLandlord.gender = gender; commonDataToLandlord.location = { "cityId": city, "zipCode": zipCode, "address": address }; commonDataToLandlord.contactTime = contactTime; commonDataToLandlord.content = content; commonDataToLandlord.contentType = 1; commonDataToLandlord.countryCode = 'tw'; commonDataToLandlord.policies = [ { "policyType": 1 , "ruleId": securityId, "agree": privacyCheck }, { "policyType":2, "ruleId": ruleId, "agree":privacyCheck } ]; var commonDataToLandlordStf = JSON.stringify(commonDataToLandlord); var patt_TW = /^09[0-9]{8}$/; var patt_CN = /^1[3-9][0-9]{9}$/; var patt_HK = /^[0-9]{8}$/; var mobile_SHA = ''; if(commonDataToLandlord.phoneNumber.indexOf('88609') !== -1) { mobile_SHA = '886' + commonDataToLandlord.phoneNumber.substr(4,9); }else { if(patt_TW.test(commonDataToLandlord.phoneNumber)){ mobile_SHA = '886' + commonDataToLandlord.phoneNumber.replace(/^./, ''); }else if(patt_CN.test(commonDataToLandlord.phoneNumber)){ mobile_SHA = '86' + commonDataToLandlord.phoneNumber; }else if(patt_HK.test(commonDataToLandlord.phoneNumber)){ mobile_SHA = '852' + commonDataToLandlord.phoneNumber; }else { mobile_SHA = commonDataToLandlord.phoneNumber; } } if(returnValue){ $(".loading_bg").addClass("start"); $(".loading").addClass("start"); $.ajax({ url: 'https://sinyiwebapi.sinyi.com.tw/bypass/rent/rentSendMsg.php', method: 'POST', headers: getHeader(), crossDomain: true, dataType: "json", data: commonDataToLandlordStf, success: function(rep){ // console.log(rep); if(rep.retCode == 200) { $(".loading_bg").removeClass("start"); $(".loading").removeClass("start"); $(".surroundings-content").css("display", "none"); $(".surroundings-content-1").css("display", "block"); $(".sub-title").hide(); $(".surroundings-content-1 .ok").show(); $(".surroundings-content-1 .fail").hide(); $(window).scrollTop("0"); localStorage.setItem('fbconversionid', CryptoJS.SHA256(mobile_SHA).toString(CryptoJS.enc.Hex)); }else { $(".surroundings-content").css("display", "none"); $(".surroundings-content-1").css("display", "block"); $(".sub-title").hide(); $(".surroundings-content-1 .ok").hide(); $(".surroundings-content-1 .fail").show(); } } }); }else{ alert(msg); } }; function getCookie(cookieName) { var name = cookieName + "="; var ca = document.cookie.split(';'); for(var i=0; i