common.js 5.45 KB
/* common */
$(document).ready(function () {
    if ($('.mask').length > 0) {
        $(".mask").mask("8 (999) 999-99-99");
    }
    //$('input, select').styler();
    var ff;
    $('input[type=text]').focus(function () {
        if ($(this).attr('data-place') == $(this).val()) {
            $(this).val('');
        }
        $(this).addClass('ac');
    });
    $('input[type=text]').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('data-place'));
        }
        $(this).removeClass('ac');
    });
    $('textarea').focus(function () {
        if ($(this).attr('data-place') == $(this).val()) {
            $(this).val('');
        }
        $(this).addClass('ac');
    });
    $('textarea').blur(function () {
        ff = $(this).attr('data-place');
        if ($(this).val().length == 0) {
            $(this).val(ff);
        }
        $(this).removeClass('ac');
    });
    function ress() {
        $('.sl-con').width($('.ct').width() + 30);
        if ($(window).width() < 651) {
            $('.sl-con').width($('.ct').width() + 16);
        }
        else if ($(window).width() < 961) {
            $('.sl-con').width($('.ct').width() + 24);
        }
    }

    ress();
    $(window).resize(function () {
        ress();
    });
    $(window).load(function () {
        ress();
    });
    $(window).load(function () {
        $('input[type=text]').each(function () {
            $(this).attr('data-place', $(this).val());
        });
        $('textarea').each(function () {
            $(this).attr('data-place', $(this).val());
        });
    });
    $('.sl1').slick({
        arrows: false,
        slidesToShow: 4,
        draggable: false,
        responsive: [
            {
                breakpoint: 652,
                settings: {
                    slidesToShow: 2,
                    slidesToScroll: 2,
                    draggable: true,
                    dots: true,
                    adaptiveHeight: true
                }
            }
        ]
    });
    $('.sl2').slick({
        arrows: false,
        dots: true,
        adaptiveHeight: true
    });
    $('.sl3').slick({
        arrows: false,
        dots: true,
        adaptiveHeight: true
    });
    $('.sl-con .item-poss a').fancybox({
        helpers: {
            overlay: {
                locked: false
            },
            media: {},
            buttons: {}
        }
    });
    function test1() {
        var mac = navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) ? true : false;
        if (mac) {
            $('.ord1,.ord2,.ord3,.form1 input[type=submit]').addClass('ac');
        }
    }

    test1();
});
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '100%',
        width: '100%',
        videoId: $('#player').attr('dt'),
        events: {
            'onReady': function () {
                player.playVideo();
                player.stopVideo();
            }
        }
    });
}
$('.play1 span').click(function (e) {
    e.preventDefault();
    $(this).parent().fadeOut(200);
    player.playVideo();
});
var overlay = $('#overlay');

$(overlay).click(function () {
    closemodal('callback');
    closemodal('bid');
});

$('.ord1').click(function (e) {
    e.preventDefault();
    callmodal('callback');
});
$('.ord2, .ord3').click(function (e) {
    e.preventDefault();
    callmodal('bid');
});

$('.modal-close-xray').click(function () {
    closemodal($(this).parents('.modal').attr('id'));
});
function callmodal(id) {
    overlay.removeClass('hidden');
    $('#' + id).removeClass('hidden');
}

function closemodal(id) {
    overlay.addClass('hidden');
    $('#' + id).addClass('hidden');
}

$('.arrow-up').click(function () {
    var nearInput = $(this).siblings('input');
    var val = $(nearInput).val();
    val = time(val, 'up');
    $(nearInput).val(val);
});
$('.arrow-down').click(function () {
    var nearInput = $(this).siblings('input');
    var val = ($(nearInput)).val();
    val = time(val, 'down');
    $(nearInput).val(val);
});

function time(number, type) {
    number = number.toString();
    var date = '25.06.2014 ' + number.toString();
    var d = new Date();
    var time = date.replace(/^(\d+)\.(\d+)\./, '$2/$1/');
    d.setTime(Date.parse(time));
    if (type == 'down') {
        d.setMinutes(d.getMinutes() - 90);
    } else {
        d.setMinutes(d.getMinutes() - 30);
    }
    return d.toLocaleTimeString().substr(0, 5);
}

$('#callback-form').submit(function(e){
    e.preventDefault();
    send('callback-form');
});
$('#order-form').submit(function(e){
    e.preventDefault();
    send('order-form');
});

function send(form){
    $.ajax({
        url: '/handler.php',
        type: "POST",
        dataType: "json",
        data: $("#" + form).serialize(),
        success: function (response) {
            if (response.type == 'success_send') {
                $('#'+form).find('input').prop("disabled", true);
                alert(response.text)
            }
            if (response.type == 'error_name') {
                alert(response.text)
            }
            if (response.type == 'error_email') {
                alert(response.text)
            }
            if (response.type == 'error_phone') {
                alert(response.text)
            }
        }
    });

}