$(document).ready(function() {
$(document).click(function(e) {
var target = $(e.target);
var my_acc_menu = $('#my_acc_dropdown');
if((target.attr('id') != 'my_acc' && target.attr('id') != 'my_acc_arrow') && my_acc_menu.is(':visible')) {
my_acc_menu.hide();
}
if(target.parent('ul#mainnav li').length == 0) {
$(".mainnav_sub").hide();
}
});
$(document).on('click', '#my_acc', function() {
$('#my_acc_dropdown').toggle();
});
$(document).on('click', '#mainnav li a', function() {
$(".mainnav_sub").hide();
$(this).parent().find(".mainnav_sub").toggle();
});
$(document).on('click', '#close_ie8_msg', function() {
$("#ie8").hide();
$.ajax({
type: "GET",
url: "/scripts/ie8.php",
cache: false,
dataType: "html"
});
})
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
return pattern.test(emailAddress);
}
function get_gmap_icon()
{
var img;
if(arguments.length > 0)
{
if(arguments[0] == 1)
{
img = "/img/marker/house.png";
}
else if(arguments[0] == 2)
{
img = "/img/marker/condominium.png";
}
else if(arguments[0] == 3)
{
img = "/img/marker/apartment.png";
}
else if(arguments[0] == 4)
{
img = "/img/marker/home_with_apartments.png";
}
else if(arguments[0] == 5)
{
img = "/img/marker/land.png";
}
else if(arguments[0] == 6)
{
img = "/img/marker/shared_accommodation.png";
}
else if(arguments[0] == 7)
{
img = "/img/marker/studio.png";
}
else if(arguments[0] == 8)
{
img = "/img/marker/apartment_building.png";
}
else
{
img = "/img/marker.png";
}
}
else
{
img = "/img/marker.png";
}
return img;
}
function initialize(lat, lng, property_type) {
var bmLatlng = new google.maps.LatLng(32.321098, -64.764838);
var listingLatlng = new google.maps.LatLng(lat, lng);
var image = get_gmap_icon(property_type);
var mapOptions = {
center: bmLatlng,
scrollwheel: false,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: listingLatlng,
map: map,
title: "My-Bermuda-House",
icon: image
});
google.maps.event.trigger(map, 'resize');
}
function select_agent(t)
{
var a_id;
if(t == 's')
{
a_id = $('#agent_id').val();
}
if(t == 'r')
{
a_id = $('input[name=agent_id]:checked', '#form-select-agent').val();
}
if(a_id !== undefined)
{
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: "/scripts/select_agent.php",
data: { agent_id: a_id, listing_id: $('#listing_id').val()},
success: function(data) {
if(data['success'] == '1')
{
$('#agent_info').html(data['success_html']);
}
}
});
return false;
}
}
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$(function() {
$('.property-image').imageloader(
{
background: true
}
);
});
$(document).on('click', '#g_images_photo', function(event) {
event.preventDefault();
blueimp.Gallery($('#images-img a'), $('#blueimp-gallery').data());
});
$(document).on('click', '#g_images_btn', function(event) {
event.preventDefault();
blueimp.Gallery($('#images-img a'), $('#blueimp-gallery').data());
});
$(document).on('click', '#g_fp_btn', function(event) {
event.preventDefault();
blueimp.Gallery($('#images-fp a'), $('#blueimp-gallery-fp').data());
});
$(document).on('click', '#g_pp_btn', function(event) {
event.preventDefault();
blueimp.Gallery($('#images-pp a'), $('#blueimp-gallery-pp').data());
});
$(document).on('shown.bs.modal', '#modal-map', function(e) {
var element = $(e.relatedTarget);
var data = element.data("gmap").split(',')
initialize(data[0], data[1], data[2]);
});
$(document).on('hidden.bs.modal', '#modal-calculator', function() {
$('#success-calculator').html('');
});
$(document).on('shown.bs.modal', '#modal-calculator', function() {
$(document).on('click', '#btn-calculator', function(e){
e.preventDefault();
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: '/calculator.php',
data: $('#form-calculator').serialize(),
success: function(data){
if(data['success'] == '1')
{
$('#success-calculator').html(data['success_html']);
}
else if(data['success'] == '0')
{
$.each(data['err_arr'], function(k, v){
$('#' + k).addClass('error');
});
}
}
});
return false;
});
});
$(document).on('shown.bs.modal', '#modal-questions', function() {
$('#user_email').val('');
$('#user_pass').val('');
$(document).on('click', '#btn-questions', function(e){
e.preventDefault();
$('#btn-questions').prop("disabled", true);
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: '/questions.php',
data: $('#form-questions').serialize(),
success: function(data){
if(data['success'] == '1')
{
$('#form-questions').hide();
$('#btn-questions').hide();
$('#thanks-questions').removeClass('hidden');
$('#error-questions').addClass('hidden');
}
else
{
if(data['err'].length > 0)
{
$('#btn-questions').prop( "disabled", false);
}
var err_msg_html = '';
for(var i = 0; i < data['err_msg'].length; i++) {
err_msg_html += '
' + data['err_msg'][i] + '';
}
err_msg_html = '';
$('#error-questions').removeClass('hidden');
$('#error-msg-questions').html(err_msg_html);
$('input').removeClass('error');
for(var i = 0; i < data['err'].length; i++) {
err_msg_html = '' + data['err'][i] + '';
$('#' + data['err'][i]).addClass('error');
}
}
}
});
return false;
});
$(document).on('change', '#agent_id', function(e){
select_agent('s');
});
$(document).on('input', '#user_email', function(e){
if(isValidEmailAddress($('#user_email').val())){
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: "/scripts/user_check.php",
data: 'e=' + $('#user_email').val(),
success: function(data) {
if(data['user_active'] == '1')
{
$('.existing-user').removeClass('hide');
$('.new-user').addClass('hide');
}
else if(data['user_active'] == '0')
{
$('#form-questions').hide();
$('#btn-questions').hide();
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
$('#inactive-questions').removeClass('hidden');
}
else if(data['user_active'] == '-1')
{
$('.existing-user').addClass('hide');
$('.new-user').removeClass('hide');
}
}
});
return false;
}
else
{
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
}
});
});
$(document).on('hidden.bs.modal', '#modal-questions', function() {
location.reload();
});
$(document).on('shown.bs.modal', '#modal-appointment', function() {
$('#user_email').val('');
$('#user_pass').val('');
$(document).on('click', '#btn-appointment', function(e){
e.preventDefault();
$('#btn-appointment').prop("disabled", true);
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: '/appointment.php',
data: $('#form-appointment').serialize(),
success: function(data){
if(data['success'] == '1')
{
$('#form-appointment').hide();
$('#btn-appointment').hide();
$('#thanks-appointment').removeClass('hidden');
$('#error-appointment').addClass('hidden');
}
else
{
if(data['err'].length > 0)
{
$('#btn-appointment').prop( "disabled", false);
}
var err_msg_html = '';
for(var i = 0; i < data['err_msg'].length; i++) {
err_msg_html += '' + data['err_msg'][i] + '';
}
err_msg_html = '';
$('#error-appointment').removeClass('hidden');
$('#error-msg-appointment').html(err_msg_html);
$('input').removeClass('error');
for(var i = 0; i < data['err'].length; i++) {
err_msg_html = '' + data['err'][i] + '';
$('#' + data['err'][i]).addClass('error');
}
}
}
});
return false;
});
$(document).on('change', '#agent_id', function(e){
select_agent('s');
});
$(document).on('input', '#user_email', function(e){
if(isValidEmailAddress($('#user_email').val())){
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: "/scripts/user_check.php",
data: 'e=' + $('#user_email').val(),
success: function(data) {
if(data['user_active'] == '1')
{
$('.existing-user').removeClass('hide');
$('.new-user').addClass('hide');
}
else if(data['user_active'] == '0')
{
$('#form-appointment').hide();
$('#btn-appointment').hide();
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
$('#inactive-appointment').removeClass('hidden');
}
else if(data['user_active'] == '-1')
{
$('.existing-user').addClass('hide');
$('.new-user').removeClass('hide');
}
}
});
return false;
}
else
{
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
}
});
});
$(document).on('hidden.bs.modal', '#modal-appointment', function() {
location.reload();
});
$(document).on('shown.bs.modal', '#modal-offer', function() {
$('#user_email').val('');
$('#user_pass').val('');
$(document).on('click', '#btn-offer', function(e){
e.preventDefault();
$('#btn-offer').prop("disabled", true);
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: '/offer.php',
data: $('#form-offer').serialize(),
success: function(data){
if(data['success'] == '1')
{
$('#form-offer').hide();
$('#btn-offer').hide();
$('#thanks-offer').removeClass('hidden');
$('#error-offer').addClass('hidden');
}
else
{
if(data['err'].length > 0)
{
$('#btn-offer').prop( "disabled", false);
}
var err_msg_html = '';
for(var i = 0; i < data['err_msg'].length; i++) {
err_msg_html += '' + data['err_msg'][i] + '';
}
err_msg_html = '';
$('#error-offer').removeClass('hidden');
$('#error-msg-offer').html(err_msg_html);
$('input').removeClass('error');
for(var i = 0; i < data['err'].length; i++) {
err_msg_html = '' + data['err'][i] + '';
$('#' + data['err'][i]).addClass('error');
}
}
}
});
return false;
});
$(document).on('change', '#agent_id', function(e){
select_agent('s');
});
$(document).on('input', '#user_email', function(e){
if(isValidEmailAddress($('#user_email').val())){
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: "/scripts/user_check.php",
data: 'e=' + $('#user_email').val(),
success: function(data) {
if(data['user_active'] == '1')
{
$('.existing-user').removeClass('hide');
$('.new-user').addClass('hide');
}
else if(data['user_active'] == '0')
{
$('#form-offer').hide();
$('#btn-offer').hide();
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
$('#inactive-offer').removeClass('hidden');
}
else if(data['user_active'] == '-1')
{
$('.existing-user').addClass('hide');
$('.new-user').removeClass('hide');
}
}
});
return false;
}
else
{
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
}
});
});
$(document).on('hidden.bs.modal', '#modal-appointment', function() {
location.reload();
});
$(document).on('shown.bs.modal', '#modal-email', function() {
$('#user_email').val('');
$('#user_pass').val('');
$(document).on('click', '#btn-email', function(e){
e.preventDefault();
$('#btn-email').prop("disabled", true);
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: '/email_listing.php',
data: $('#form-email').serialize(),
success: function(data){
if(data['success'] == '1')
{
$('#email_entered').html($('#to').val());
$('#form-email').hide();
$('#btn-email').hide();
$('#thanks-email').removeClass('hidden');
$('#error-email').addClass('hidden');
}
else if(data['success'] == '0')
{
$('#btn-email').prop("disabled", false);
var err_msg_html = '';
for(var i = 0; i < data['err_msg'].length; i++) {
err_msg_html += '' + data['err_msg'][i] + '';
}
err_msg_html = '';
$('#error-email').removeClass('hidden');
$('#error-msg-email').html(err_msg_html);
$('input').removeClass('error');
for(var i = 0; i < data['err'].length; i++) {
err_msg_html = '' + data['err'][i] + '';
$('#' + data['err'][i]).addClass('error');
}
}
}
});
return false;
});
$(document).on('input', '#user_email', function(e){
if(isValidEmailAddress($('#user_email').val())){
$.ajax({
type: 'POST',
dataType: 'json',
cache: false,
url: "/scripts/user_check.php",
data: 'e=' + $('#user_email').val(),
success: function(data) {
if(data['user_active'] == '1')
{
$('.existing-user').removeClass('hide');
$('.new-user').addClass('hide');
}
else if(data['user_active'] == '0')
{
$('#form-offer').hide();
$('#btn-offer').hide();
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
$('#inactive-offer').removeClass('hidden');
}
else if(data['user_active'] == '-1')
{
$('.existing-user').addClass('hide');
$('.new-user').removeClass('hide');
}
}
});
return false;
}
else
{
$('.existing-user').addClass('hide');
$('.new-user').addClass('hide');
}
});
});
$(".nano").nanoScroller({ iOSNativeScrolling: true });
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$(".nano").nanoScroller({ iOSNativeScrolling: true });
})
$(document).on('click', '#add_me_btn', function() {
window.location = $(this).attr('rel');
});
$(document).on('click', '.teaser_btn', function() {
window.location = '/members/' + $(this).attr('id');
});
$(".agent_select_radio").change(function()
{
select_agent('r');
});
$(document).on('shown.bs.modal', '#modal-video', function() {
$('#listing-video').trigger('play');
});
$(document).on('hidden.bs.modal', '#modal-video', function() {
$('#listing-video').trigger('pause');
});
});