/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
function getCookieAccaunt(name) {
    var pattern = RegExp(name + "=.[^;]*")
    matched = document.cookie.match(pattern)
    if (matched) {
        var cookie = matched[0].split('=')
        return cookie[1]
    }
    return false
}

$(function () {

    if ($("[data-reveal][id='alert-maintenece-banner']").length == 1) {
        $("[data-reveal][id='alert-maintenece-banner']").foundation('open');
        $(document).on('closed.zf.reveal', $("[data-reveal][id='alert-maintenece-banner']"), function () {

            set_cookie(working_time_cookie, "1", "");


        });

    }

    var hasUserLogged = getCookieAccaunt('sso_client_token_suprimmoclient');
    if ($("#fav_count").length == 1) {
        $.post('/get_wish.php', {'cmd': 'get_wish_count', 'additional': hasUserLogged}, function (data) {
            var count = parseInt(data);
            if (count > 0) {
                $('#fav_count').html(data);
                $("#show_wish_panel").show();
            } else {
                $('#fav_count').text('');
                $("#show_wish_panel").hide();
            }
        })
    }
    if ($('.property-fav').length == 1) {
        var IID = $('.property-fav').prop('rel');
        $.post('/get_wish.php', {'cmd': 'get_wish_property', 'IID': IID, 'additional': hasUserLogged}, function (data) {
            $('.property-fav>span').html(data[0]).foundation();
            $('.property-fav')
                    .removeClass('add_fav')
                    .removeClass('del_fav')
                    .addClass(data[1])
                    .prop('title', data[2]);
            new Foundation.Tooltip($('.property-fav'));


        })
    }

    if ($('.search-fav').length > 0) {
        var IDS = new Array();
        $('.search-fav').each(function (i, v) {
            IDS.push($(v).prop('rel'));
        })
        if (IDS.length > 0) {
            $.post('/get_wish.php', {'cmd': 'get_wish_search', 'IDS': JSON.stringify(IDS), 'additional': hasUserLogged}, function (data) {
                $.each(data, function (i, v) {
                    var _this = $(".search-fav[rel='" + i + "']");
                    $(_this)
                            .removeClass('add_fav')
                            .removeClass('del_fav')
                            .addClass(v[1])
                            .prop('title', v[2])
                            .html(v[0])
                            .foundation();
                    new Foundation.Tooltip(_this);
                })
            })
        }
    }
    if ($("#counter_prop").length == 1) {
        var data = {};
        data.country_id = country_id;
        $.ajax({
            url: site_url_q_search + 'counter_properties.php',
            type: 'post',
            dataType: 'html',
            timeout: 20000,
            data: data,
            error: function () {

            },
            success: function (html) {

                $("#counter_prop>.h2").html(html);
            }
        });

    }

})