﻿function save_cookie(newvalue) {
    var name = "NewCityID";
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 31));
    set_cookie(name, newvalue, expires);
}
function set_cookie(name, value, expires) {
    if (!expires) {
        expires = new Date();
    }
    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}
$(function() {
    //setPhoneNew(currentCityID);
    $(".niceRadio").removeClass("link-radio-on");
    //$("#rb_" + currentCityID).removeClass("link-radio-off").addClass("link-radio-on");

    //disable redirect to search page
    $(":text").keypress(function(ev) {
        var allow = $(this).attr("allowenter");
        if (!allow && ev.keyCode == 13) {
            ev.preventDefault();
        }
    });
});

var cityPopup;
$(function() {
    cityPopup = $('#select_city');

    cityPopup.mouseleave(function() {
        hideCityPopup();
    });

    $('.select_city_center a').click(function(ev) {
        var on = 'link-radio-on';
        var off = 'link-radio-off';

        $('.select_city_center a.link-radio-on').removeClass(on).addClass(off);
        var a = $(this);

        a.removeClass(off).addClass(on);
        var id = a.attr("value");
        //setPhoneNew(id);

        var url = window.location.href.toLowerCase();
        var ua = url.indexOf("5ok.com.ua") > 0;

        if (ua && id != 42 || !ua && id == 42) {
            save_cookie(id);
        }

        hideCityPopup();
    });
});

function hideCityPopup() {
    cityPopup.fadeOut('slow');
}
