jQuery(document).ready(function() { // Scroll jQuery(window).scroll(function(){ if (jQuery(window).scrollTop() == 0) { jQuery('body').removeClass('scroll'); jQuery('body').addClass('no-scroll'); } else { jQuery('body').addClass('scroll'); jQuery('body').removeClass('no-scroll'); } }); }); function scrollTo(item) { if(typeof(item) != 'undefined' && item.length && jQuery(item) != null && jQuery('header') != null) { jQuery('html, body').animate({ scrollTop: jQuery(item).offset().top - (jQuery('header').innerHeight() + 30) }, 500); } } /*Base64*/ function DecodeBase64(input) { try { return decodeURIComponent(escape(window.atob( input ))); } catch (ex) { return ''; } }; function EncodeBase64(input) { try { return window.btoa(unescape(encodeURIComponent( input ))); } catch (ex) { return ''; } }; function EncodeUTF8(input) { return unescape(encodeURIComponent(input)); } function EncodeHEX(input) { return EncodeUTF8(input).split("").map(function(e) { return e.charCodeAt(0).toString(16) }).join(""); } function GetHash(key) { const items = window.location.hash.replaceAll('#', '').split('&'); let dic = []; for (i = 0; i < items.length; i++) { try { const k = items[i].substr(0, items[i].indexOf('=')); const v = items[i].substr(items[i].indexOf('=') + 1); if (k == key) { value = decodeURI(v.replaceAll('+', ' ').toString()); if (value.startsWith('b64')) { value = value.toString().replaceAll('*', '='); value = DecodeBase64(value.substring(3)); value = value.toString().replaceAll('+', ' '); } return value; } } catch(ex) { } } return null; } function SetHash(key, value) { const items = window.location.hash.replaceAll('#', '').split('&'); let dic = []; let hash = ''; let found = false; if (value != undefined && value != null) { value = value.toString().replaceAll('=', '*'); value = value.toString().replaceAll(' ', '+'); } for (i = 0; i < items.length; i++) { dic = items[i].split('='); if (dic.length == 2 && dic[0] == key) { found = true; if (value != undefined && value != null) { hash = hash + key + '=' + value + '&'; } } else if (dic.length == 2) { if (dic[1] != null && dic[1] != 'null') { hash = hash + dic[0] + '=' + dic[1] + '&'; } } } if (!found) { if (value != undefined && value != null) { hash = hash + key + '=' + value + '&'; } } window.location.hash = hash; } function ImageNotFound(img) { img.src = '/assets/images/blank.jpg'; } var atria = { mainURL: 'https://spimobiliaria.com.br', sell: 4, sellExtra: 0, rent: 2, rentExtra: 0, bookmarks: { Sell: [], SellExtra: [], Rent: [], RentExtra: [] }, countBookmarks: function() { try { return atria.bookmarks.Sell.length + atria.bookmarks.SellExtra.length + atria.bookmarks.Rent.length + atria.bookmarks.RentExtra.length; } catch(ex) { return 0; } }, saveBookmarks: function() { try { let marks = ''; if (atria.sell != 0) { for (let i = 0; i < atria.bookmarks.Sell.length; i++) { marks += atria.sell + ',' + atria.bookmarks.Sell[i] + '|'; } } if (atria.sellExtra != 0) { for (let i = 0; i < atria.bookmarks.SellExtra.length; i++) { marks += atria.sellExtra + ',' + atria.bookmarks.SellExtra[i] + '|'; } } if (atria.rent != 0) { for (let i = 0; i < atria.bookmarks.Rent.length; i++) { marks += atria.rent + ',' + atria.bookmarks.Rent[i] + '|'; } } if (atria.rentExtra != 0) { for (let i = 0; i < atria.bookmarks.RentExtra.length; i++) { marks += atria.rentExtra + ',' + atria.bookmarks.RentExtra[i] + '|'; } } window.store.set('bookmarks', marks); } catch(ex) { } }, clearBookmarks: function() { window.store.set('bookmarks', ''); atria.bookmarks = { Sell: [], SellExtra: [], Rent: [], RentExtra: [] }; }, addBookmark: function(negotiationType, realtyId) { if (!atria.hasBookmark(negotiationType, realtyId)) { switch (parseInt(negotiationType)) { case atria.sell: default: atria.bookmarks.Sell.push(realtyId); break; case atria.sellExtra: atria.bookmarks.SellExtra.push(realtyId); break; case atria.rent: atria.bookmarks.Rent.push(realtyId); break; case atria.rentExtra: atria.bookmarks.RentExtra.push(realtyId); break; } } atria.saveBookmarks(); }, hasBookmark: function(negotiationType, realtyId) { let found = false; switch (parseInt(negotiationType)) { case atria.sell: default: for (let i = 0; i < atria.bookmarks.Sell.length; i++) { if (atria.bookmarks.Sell[i] == realtyId) { found = true; break; } } break; case atria.sellExtra: for (let i = 0; i < atria.bookmarks.SellExtra.length; i++) { if (atria.bookmarks.SellExtra[i] == realtyId) { found = true; break; } } break; case atria.rent: for (let i = 0; i < atria.bookmarks.Rent.length; i++) { if (atria.bookmarks.Rent[i] == realtyId) { found = true; break; } } break; case atria.rentExtra: for (let i = 0; i < atria.bookmarks.RentExtra.length; i++) { if (atria.bookmarks.RentExtra[i] == realtyId) { found = true; break; } } break; } return found; }, removeBookmark: function(negotiationType, realtyId) { let found = -1; switch (parseInt(negotiationType)) { case atria.sell: default: for (let i = 0; i < atria.bookmarks.Sell.length; i++) { if (atria.bookmarks.Sell[i] == realtyId) { found = i; break; } } break; case atria.sellExtra: for (let i = 0; i < atria.bookmarks.SellExtra.length; i++) { if (atria.bookmarks.SellExtra[i] == realtyId) { found = i; break; } } break; case atria.rent: for (let i = 0; i < atria.bookmarks.Rent.length; i++) { if (atria.bookmarks.Rent[i] == realtyId) { found = i; break; } } break; case atria.rentExtra: for (let i = 0; i < atria.bookmarks.RentExtra.length; i++) { if (atria.bookmarks.RentExtra[i] == realtyId) { found = i; break; } } break; } if (found != -1) { switch (parseInt(negotiationType)) { case atria.sell: default: atria.bookmarks.Sell.splice(found, 1); break; case atria.sellExtra: atria.bookmarks.SellExtra.splice(found, 1); break; case atria.rent: atria.bookmarks.Rent.splice(found, 1); break; case atria.rentExtra: atria.bookmarks.RentExtra.splice(found, 1); break; } } atria.saveBookmarks(); }, loadBookmarks: function() { atria.bookmarks = { Sell: [], SellExtra: [], Rent: [], RentExtra: [] }; try { if (GetHash('bookmarks') != null) { let bookmarks = DecodeBase64(GetHash('bookmarks')); window.store.set('bookmarks', bookmarks); } } catch(ex) { } try { let bookmarks = window.store.get('bookmarks'); for (let i = 0; i < bookmarks.split('|').length; i++) { let tuple = bookmarks.split('|')[i]; if (tuple.length == 0) continue; let nt = parseInt(tuple.split(',')[0]); let id = tuple.split(',')[1]; switch (parseInt(nt)) { case atria.sell: default: atria.bookmarks.Sell.push(id); break; case atria.sellExtra: atria.bookmarks.SellExtra.push(id); break; case atria.rent: atria.bookmarks.Rent.push(id); break; case atria.rentExtra: atria.bookmarks.RentExtra.push(id); break; } } } catch(ex) { atria.clearBookmarks(); } }, parseObject: function (item, html, prefix, sulfix) { if (html == undefined || html == null) { return ''; } if (prefix != undefined && prefix != null) { prefix = '%' + prefix; } else { prefix = '%'; } if (sulfix != undefined && sulfix != null) { sulfix = sulfix + '%'; } else { sulfix = '%'; } let col = null; for (col in item) { try { html = html.replaceAll(prefix + col + sulfix, item[col]); } catch(ex) { console.log({html, col, ex}); throw ex; } } return html; }, formatMoney: function(val, c, d, t) { var n = val, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); } } String.prototype.replaceAll = function(de, para){ let str = this; let pos = str.indexOf(de); while (pos > -1){ str = str.replace(de, para); pos = str.indexOf(de); } return (str); }