﻿function InitEditablesValues() {
    repCs = $('.auto_replace');
    for (var i = 0; i < repCs.length; i++)
        $(repCs[i]).val(Tip[$(repCs[i]).attr('name')]);
}


$(function() {
    InitEditablesValues();

    $('.auto_replace').focus(function() {
        var objItem = $(this);
        if (objItem.val() == Tip[objItem.attr('name')]) $(this).val("");
    });

    $('.auto_replace').blur(function() {
        var objItem = $(this);
        if (objItem.val() == "") $(this).val(Tip[objItem.attr('name')]);
    });

    $('#bookingForm_Date').datepicker({
        showOn: 'button',
        buttonImage: '/Frontend/Images/Centrumturist/BookPanel/calendar.png',
        buttonImageOnly: true,
        minDate: new Date(),
        dateFormat: "dd/mm/yy"
    });



    $('#goto_online_booking').click(function() {
        var date = $('#bookingForm_Date').datepicker('getDate');
        var dateStr = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();//$('#bookingForm_Date').val();
        if (dateStr == Tip.DateTime) {
            var date = new Date();
            dateStr = date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
        }

        var count = $('#passengers').val();
        if (count == Tip.TipCount) {
            count = 0;
        }

        var from_addr = $('#from').val();
        var to_addr = $('#to').val();

        var onlineBookingUrlP = $('#page_url').val();
        onlineBookingUrlP = onlineBookingUrlP.split('?');
        var onlineBookingUrl = onlineBookingUrlP[0];
        onlineBookingUrl += '?';
        onlineBookingUrl += 'adult=' + encodeURI(count) + "&";
        onlineBookingUrl += 'departure=' + encodeURI(dateStr) + "&";
        onlineBookingUrl += 'isCruis=' + encodeURI(($('#returnTrue').attr('checked') ? 1 : 0)) + "&";
        onlineBookingUrl += 'from=' + encodeURI((from_addr == Tip.Address ? "" : from_addr)) + "&";
        onlineBookingUrl += 'to=' + encodeURI((to_addr == Tip.Address ? "" : to_addr));
        if (onlineBookingUrlP.length > 1) {
            onlineBookingUrl += "&" + onlineBookingUrlP[1];
        }
        window.location = onlineBookingUrl;
    });
});