/* Russian (UTF-8) initialisation for the jQuery UI date picker plugin. */
/* Written by Andrew Stromnov (stromnov@gmail.com). */
jQuery(function($){
        $.datepicker.regional['ru'] = {
                closeText: 'Закрыть',
                prevText: '&#x3c;Пред',
                nextText: 'След&#x3e;',
                currentText: 'Сегодня',
                yearRange: "1910:2012",
                showYearNavigation:true,
                monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
                'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
                monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
                'Июл','Авг','Сен','Окт','Ноя','Дек'],
                dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
                dayNamesShort: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
                dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
                dateFormat: 'dd.mm.yy', firstDay: 1,
                changeYear: true,
				readonly:true,
                //minDate: new Date(),
                isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['ru']);
});

function declOfNum(number, titles) {
  cases = [2, 0, 1, 1, 1, 2];  
  return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
  
    /* callback */
function callback_function()
{
  $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
  });
  $('.modal-callback .button input').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_callback.php", $(".modal-callback form").serialize(),
          function(data){
                $('.css-style').html(data);
        });
  });
}

function order_callback_php ()
{
        //$('.order-callback-js').click(function (e) {
          //$.modal(data, {  opacity: 90  });
          //$.modal.opacity=90;
         // alert("test-callback");
        // e.preventDefault();

                $.get( 'modal/modal_success.html', function(data){
                  $.modal(data, {
                        autoPosition: false,
                        opacity: 90,
                        onClose: modalOnClose,
                        onOpen: modalOnOpen,
                        onShow: function(dialog){callback_function();}
                  });
                });
          $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
        //});
}

function modalOnOpen(dialog) {
        //Animate the open of the popup
        dialog.overlay.fadeIn('fast', function() {
                dialog.container.fadeIn('fast', function() {
                        dialog.data.hide().slideDown('fast');
                });
        });
}
function modalOnClose(dialog) {
        //Animates the closing of the dialogs
   dialog.data.fadeOut('fast', function() {
           dialog.container.slideUp('fast', function() {
                   dialog.overlay.fadeOut('fast', function() {
                           $.modal.close();
                   });
           });
   });
}

$(document).ready(function(){
    // datapicker
	$(".reg-finish").click( function(e) {
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$(".modal-registration form").submit();
     });
	
	$(".excur-finish").click( function(e) {
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$(".modal-excursion form").submit();
     });
	
	$(".trans-finish").click( function(e) {
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$(".modal-transport form").submit();
     });

	$('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
	//$('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
	
	$(".captcha-num a").click(function (e) {
		e.preventDefault();
		var img_id = ".captcha-num img";
		var timestamp = new Date().getTime();
		var img_src = $(img_id).attr("src").split("?")[0] + "?" + timestamp;
		$.ajax({
			type: "GET",
			url: img_src,
			success: function(msg){$(img_id).attr('src',img_src);}
		});
	});

	
    $('#hostel-date-in').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange12});
    $('#hostel-date-out').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange12});
    function customRange12(input) {
        var input_id = input.id;
                
                if ($("#hostel-date-in").datepicker("getDate")) date=$("#hostel-date-in").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-in"){return {maxDate: $("#hostel-date-out").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-out"){return {minDate: date, maxDate: null};}
    }
     
    $('#tour-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
    $('#tour-date-search').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
    $('#birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});

    $(".form-hostel-services span.link").click(function () {
      $(".form-hostel-services").toggleClass("services-full");
      $(".form-hostel-services").toggleClass("services-short");
      return false;
    });

    $(".contest-types .text table p.archive-link a").click(function () {
      $(this).toggleClass("active");
      $(this).parent().next('ul').toggle('fast');
      return false;
    });
	
	$(".form-hostel-services input").click(function(){
		var int="";
		
		$(".form-hostel-services input").each(function(){
		   if ($(this).attr("checked")==true) 
		   {
			  int++;
			  // alert($(this).attr("value"));
		   }
		});
		
		if (int)	$(".form-hostel-services .selected").html("Выбрано услуг: "+int);
		else	$(".form-hostel-services .selected").html("");
	});

	/*$(".form-hostel-services label").click(function(){
		//$("input[id^='service-']").each(function(){
		alert("att");	
	});*/


    // blox height
    function mainBoxHeighEqual() {
        var height1 = $('#main-2-row .main-right-box').height();
        var height2 = $('#main-2-row .main-left-box').height();
        var difference = height1 - height2;
        if (difference > 0){
            $('#main-2-row .main-left-box .all').css('margin-bottom', difference/2 + 'px');
            $('#main-2-row .main-left-box .all').css('margin-top', difference/2 + 'px');
        }
        if (difference < 0){$('#main-2-row .main-right-box .contest-list').css('padding-bottom', difference);}
    }
    mainBoxHeighEqual();
	
    $(".hostel-search select").msDropDown();
    $(".hostels-search select").msDropDown();
    $(".news-sort select").msDropDown();
    $(".contest-sort select").msDropDown();
    $(".cabinet-sort select").msDropDown();
    $(".hostels-rating-sort select").msDropDown();
    $(".group-form select").msDropDown();
    $(".cabinet-settings-form select").msDropDown();
    $(".tour-search-form select").msDropDown();
    $(".tickets-order select").msDropDown();
    $(".hostels-tour-order select").msDropDown();
	$(".count-number select").msDropDown();

    /* Tickets destination change */
    $('.change a').click(function (e) {
      e.preventDefault();
      var from = $('#ticket-from').val();
      var to = $('#ticket-to').val();
      $('#ticket-from').val(to);
      $('#ticket-to').val(from);
    });

    /* Map */
    function map_markers() {
      $(".modal-box .map .s").hover(
        function () {
          num = $(this).attr("alt");
          $('.map .m[alt="'+ num +'"]').addClass('active');
        },
        function () {
          num = $(this).attr("alt");
          $('.map .m[alt="'+ num +'"]').removeClass('active');}
      );
    }

    /* Search map hover */
    $(".map-list table td").hover(
      function () {$(this).parent().addClass('active');},
      function () {$(this).parent().removeClass('active');}
    );

    /* Hostel price by date */
    //$('#date-start').datepicker({beforeShow: customRangeHostel, altField: '#date-start-alt', altFormat: '<i>D</i> dd.mm.yy'});
   // $('#date-end').datepicker({beforeShow: customRangeHostel, altField: '#date-end-alt', altFormat: '<i>D</i> dd.mm.yy'});
    function customRangeHostel(input) {
        var input_id = input.id;
                
                if ($("#date-start").datepicker("getDate"))     date=$("#date-start").datepicker("getDate");
                else    date=new Date();

        if (input_id == "date-start"){return {maxDate: $("#date-end").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "date-end"){return {minDate: date, maxDate: null};}
    }
    //$('.date-start').click(function () {
    //  $('#date-start').datepicker('show');
    //});
    $("#date-start").change( function() {
      date = $('#date-start-alt').val();
      $('.date-start').html(date);
    });
    //$('.date-end').click(function () {$('#date-end').datepicker('show');});
    $("#date-end").change( function() {date = $('#date-end-alt').val();$('.date-end').html(date);});

    //$('.hostel-date-count').click(function (e) {
    //  e.preventDefault();
    //  var href = $(this).attr('href');
    //  var block_height = $('.single-hostel-prices .ajax-content').height();
    //  $('.single-hostel-prices h2').fadeOut("fast");
    //  $('.single-hostel-prices form').fadeOut("fast");
    //  $('.single-hostel-prices > p').fadeOut("fast");
    //  $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
    //    $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
    //    $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
    //    $('.single-hostel-prices .ajax-content').fadeIn('fast', function() {
    //      $.post(href, $("#hostel-price-period").serialize(),
    //      function(data){
    //        $('.single-hostel-prices h2').fadeIn("fast");
    //        $('.single-hostel-prices form').fadeIn("fast");
    //        $('.single-hostel-prices > p').fadeIn("fast");
    //        $('.single-hostel-prices .ajax-content').html(data);
    //        hostel_order_js();
    //      });
    //    });
    //  });
    //});

    function date_search(formdata) {
      var block_height = $('.single-hostel-prices .ajax-content').height();
      $('.single-hostel-prices h2').fadeOut("slow");
      $('.single-hostel-prices form').fadeOut("slow");
      $('.single-hostel-prices > p').fadeOut("slow");
      $('.single-hostel-prices .ajax-content').fadeOut('slow', function() {
        $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
        $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
        $('.single-hostel-prices .ajax-content').fadeIn('slow', function() {
         //alert($("#hostel-date-in").attr("value"));
         // $.post('modal/hostel-price.php', $("#hostel-price-period").serialize(),
		$.post('modal/roomprice_by_date.php', formdata,
          function(data){
            $('.single-hostel-prices h2').fadeIn("slow");
            $('.single-hostel-prices form').fadeIn("slow");
            $('.single-hostel-prices > p').fadeIn("slow");
            $('.single-hostel-prices .ajax-content-box').html(data);
            hostel_order_js();
          });
             
          $.post('modal/new-cperiod.php', $("#hostel-price-period").serialize(),
          function(data){
            $('.single-hostel-prices .period').html(data);
          });
		  
          $.post('modal/get_some.php?special=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.special').html(data);
          });
		  
		  $.post('modal/get_some.php?info=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.info').html(data);
          });
		  
		  $.post('modal/get_some.php?text=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.hostel-date-count').html(data);
          });
		  
		  $('.modal-date .button a').click(function (e) {
			e.preventDefault();
			
			formdata=$(".newdates").serialize();
			
			$.modal.close();
			$('#simplemodal-overlay').fadeOut('normal');
			$('html, body').animate({scrollTop: $(".single-hostel-prices").offset().top - 100}, 200);
			
			date_search(formdata);
                
      	});
		  
        });
      });
    }

    /* date hostel */
    function date_hostel_function() {
      $('#date-start').val($("#hostel-date-in").val());
          $('#date-end').val($("#hostel-date-out").val());
          
          if ($("#hostel-date-in").datepicker("getDate"))       date=$("#hostel-date-in").datepicker("getDate");
          else  date=new Date();
          
      $('#hostel-date-in').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange, minDate: new Date() });
      $('#hostel-date-out').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange, minDate: date});
          
      function customRange(input) {
                var input_id = input.id;
                
                if ($("#hostel-date-in").datepicker("getDate")) date=$("#hostel-date-in").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-in"){return {maxDate: $("#hostel-date-out").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-out"){return {minDate: date, maxDate: null};}
      }
       
                $('#date-start').val($("#hostel-date-in").val());
                $('#date-end').val($("#hostel-date-out").val());
          
      $("#hostel-date-in").change( function() {
        $('#date-start').val($("#hostel-date-in").val());
      });
      $("#hostel-date-out").change( function() {
        $('#date-end').val($("#hostel-date-out").val());
      });
         
      $('.modal-date .button a').click(function (e) {
        e.preventDefault();
		
		formdata=$(".newdates").serialize();
		
        $.modal.close();
        $('#simplemodal-overlay').fadeOut('normal');
        $('html, body').animate({scrollTop: $(".single-hostel-prices").offset().top - 100}, 200);
        
                date_search(formdata);
                
      });
    }
     
    $('.hostel-date-count').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          //'modal/modal_date.php'
          //alert(href);
      $.get(href, function(data){
        $.modal(data, {
          opacity: 90,
          autoPosition: false,
          onOpen: modalOnOpen,
          onClose: modalOnClose,
          onShow: function(dialog){
		  date_hostel_function();
			}
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });

    /* tour prices */
    $('.single-hostel-prices .price-type a').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          //alert(href);
      var block_height = $('.single-hostel-prices .ajax-content').height();
          
      $('.single-hostel-prices .price-type').fadeOut("fast");
      $('.single-hostel-prices > p').fadeOut("fast");
      $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
        $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
        $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
        $('.single-hostel-prices .ajax-content').fadeIn('fast', function() {
          $.get(href, function(data){
            $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
              $('.single-hostel-prices .price-type').fadeIn("fast");
              $('.single-hostel-prices > p').fadeIn("fast");
              $('.single-hostel-prices .ajax-content').fadeIn("fast");
              $('.single-hostel-prices .ajax-content').html(data);
              tour_order_js();
            });
          });
        });
      });
      $('.single-hostel-prices .price-type a').show();
      $('.single-hostel-prices .price-type h2').hide();
      $(this).prev().show();
      $(this).hide();
    });

    /* ajax search */
        
    /*$('.hostels-search form.hostel-search-form .button').click(function (e) {
      e.preventDefault();
      var block_height = 100;
      $('.hostel-search-box').fadeOut('fast', function() {
        $('.hostel-search-box .paginator').remove();
        $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
        $('.hostel-search-box .preloader').height(block_height);
        $('.hostel-search-box').fadeIn('fast', function() {
          $.post("modal/modal_search_result.php", $(".hostels-search form.hostel-search-form").serialize(),
            function(data){
              $('.hostel-search-box').fadeOut('fast', function() {
                text = $('.hostel-search-box').html(data);
                $('.hostel-search-box').fadeIn('fast');
                hostel_order_js();
                ajax_search_prev();
                ajax_search_next();
              });
            });
        });
      });
    });

    function ajax_search_prev() {
      $('.hostel-search-box .paginator .paginator-prev').click(function (e) {
        e.preventDefault();
        var block_height = 100;
        $('.hostel-search-box').fadeOut('fast', function() {
          $('.hostel-search-box .paginator').remove();
          $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
          $('.hostel-search-box .preloader').height(block_height);
          $('.hostel-search-box').fadeIn('fast', function() {
            $.post("modal/modal_search_result.php?page=prev", $(".hostels-search form.hostel-search-form").serialize(),
              function(data){
                $('.hostel-search-box').fadeOut('fast', function() {
                  text = $('.hostel-search-box').html(data);
                  $('.hostel-search-box').fadeIn('fast');
                  hostel_order_js();
                  ajax_search_prev();
                  ajax_search_next();
                });
              });
          });
        });
      });
    }
    ajax_search_prev();

    function ajax_search_next() {
      $('.hostel-search-box .paginator .paginator-next').click(function (e) {
        e.preventDefault();
        var block_height = 100;
        $('.hostel-search-box').fadeOut('fast', function() {
          $('.hostel-search-box .paginator').remove();
          $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
          $('.hostel-search-box .preloader').height(block_height);
          $('.hostel-search-box').fadeIn('fast', function() {
            $.post("modal/modal_search_result.php?page=next", $(".hostels-search form.hostel-search-form").serialize(),
              function(data){
                $('.hostel-search-box').fadeOut('fast', function() {
                  text = $('.hostel-search-box').html(data);
                  $('.hostel-search-box').fadeIn('fast');
                  hostel_order_js();
                  ajax_search_prev();
                  ajax_search_next();
                });
              });
          });
        });
      });
    }
    ajax_search_next();*/

    /* excursion description */
    $('.excursion-table table tr.closed .excursion a').click(function (e) {
      e.preventDefault();
      var base = $(this).parents('tr');
      var href = $(this).attr('href');
          
      if ($(base).hasClass('active1')) {
        $('.excursion-table table tr.active2 td div.slide').slideUp('slow', function() {
          $('.excursion-table table tr.active2').remove();
          $('.excursion-table table tr.active1').addClass('closed').removeClass('active1');
        });
      }
      else {
          $('.excursion-table table tr.active2').remove();
          $('.excursion-table table tr.active1').addClass('closed').removeClass('active1');
          $(base).addClass('active1').removeClass('closed');
                  
          $.get(href, function(data){
            $(base).after(data);
            $('.excursion-table table tr.active2 td div.slide').slideDown("slow");
            order_callback_js();
          });
      }
    });

    /* best offers ajax */
    $('.best-offers .more a').click(function (e) {
      e.preventDefault();
      var str = $(this).text();
      var href = "modal/bestoffers.php";
          var this_id=$(this).attr('id');
          
      var block_height = $('#offers-list').height();
      $('.best-offers h3 span').text(str);
      $('#offers-list').fadeOut('fast', function() {
        $('#offers-list').html("<div class=\"preloader\"></div>");
        $('#offers-list .preloader').height(block_height);
        $('#offers-list').fadeIn('slow', function() {
          
                  $.post(href, { id:this_id }, function(data){
            $('#offers-list').fadeOut('slow', function() {
              $('#offers-list').html(data);
              $('#offers-list').fadeIn(data);
              mainBoxHeighEqual();
              //alert("Data Loaded: " + data);
            });
          });
        });
      });
      mainBoxHeighEqual();
    });

    /* contest vote */
    $('.contest-sidebar a.vote-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
      $.get(href, function(data){
        $('.contest-sidebar .rating span').html(data);
        $('.contest-sidebar a.vote-js').hide();
      });
    });
    $('.custom-box a.vote-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
      var data = $.ajax({url:href,type:"GET",async: false}).responseText;
      $(this).prev().html(data);
      $(this).hide();
    });

    /* metro map */
    function metromap_function() {
      map_markers();
      $('.metromap-modal .m').click(function (e) {
        e.preventDefault();
        var metro_id = $(this).attr('alt');
        $('#hostel-metro').val(metro_id);
        $("#hostel-metro").msDropDown();
        $.modal.close();
      });
    }
    $('.metro-map-js').click(function (e) {
      e.preventDefault();
      $.get( 'modal/modal_metromap.html', function(data){
        $.modal(data, {
          opacity: 90,
          autoPosition: false,
          onOpen: modalOnOpen,
          onClose: modalOnClose,
          onShow: function(dialog){metromap_function()}
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });

    /* callback */
    function callback_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
      $('.modal-callback .button input').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_callback.php", $(".modal-callback form").serialize(),
          function(data){
            $('.css-style').html(data);
        });
      });
    }
     
    function order_callback_js () {
    $('.order-callback-js').click(function (e) {
          //$.modal(data, {  opacity: 90  });
          //$.modal.opacity=90;
         // alert("test-callback");
      e.preventDefault();
        $.get( 'modal/modal_callback.php', function(data){
          $.modal(data, {
            autoPosition: false,
            opacity: 90,
            onClose: modalOnClose,
            onOpen: modalOnOpen,
            onShow: function(dialog){callback_function();}
          });
        });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
    }
    order_callback_js();
        
    /* login */
    function login_function() {
	   service_info();
		
      $(".modal-registration select").msDropDown();
          
      $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          //$('#p-birthday').datepicker({minDate:});
          
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-login .button .go-registration').click(function (e) {
        e.preventDefault();
        $('.modal-login').hide();
        $('.modal-registration').show();
      });
         
          $('.modal-login a.go-passrecall').click(function (e) {
        e.preventDefault();
        $('.modal-login').hide();
        $('.modal-recall').show();
      });
         
      $('.modal-login .button .login-enter').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_login.php", $(".modal-login form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
          $('.modal-recall .button .recall-enter').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_recall.php", $(".modal-recall form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
      $('.modal-registration .button a').click(function (e) {
        e.preventDefault();
                //alert("asd");
        $.post("modal/modal_registration.php", $(".modal-registration form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
    }
     
    $('.login-js').click(function (e) {
      e.preventDefault();
        $.get( 'modal/modal_login.html', function(data){
          $.modal(data, {
            autoPosition: false,
            opacity: 90,
            onClose: modalOnClose,
            onOpen: modalOnOpen,
            onShow: function(dialog){login_function();}
          });
        });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
       
    $('.registration-js').click(function (e) {
      e.preventDefault();
          
                  $(document).ready(function(){
                        $.get( 'modal/modal_login.html', function(data){
                          $.modal(data, {
                                autoPosition: false,
                                opacity: 90,
                                onClose: modalOnClose,
                                onOpen: modalOnOpen,
                                onShow: function(dialog){
                                  login_function();
                                  $('.modal-login').hide();
                                  $('.modal-registration').show();
                                }
                                
                          });
                        });
                });
                  
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
       
        $('.logout').click(function (e) {
      e.preventDefault();
          
       $.post("modal/logout.php", { exit:1 },
          function(data){
                        $('.logout').html(data);
       });
    });
       
      $(".modal-registration select").msDropDown();
 
    /* response */
    function response_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-response .button a').click(function (e) {
        e.preventDefault();
		
		$('.modal-response .wrapper').attr("style","display:none");
		$('.modal-response .preload').html("<div class=\"preloader\"></div>");
		
        $.post("modal/modal_test_response.php", $(".modal-response form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
    }
     
    $('.new-response-js').click(function (e) {
      e.preventDefault();
        		
      var href = $(this).attr('href');
          //alert(href);
      $.get( href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            response_function();
            $(".hostel-response-bar", dialog.container[0]).slider({
              range: "min",
              value: 5,
              min: 1,
              max: 10,
              slide: function(event, ui) {
                var hostelval = ui.value;
                var showval = $(this).next('.hostel-response-val');
                $(showval).text(hostelval);
                $(showval).next('.hostel-val').val(hostelval);
              }
            });
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200)
        });
        
    /* tour-response */
    function resptour_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-response .button a').click(function (e) {
        e.preventDefault();
		
		$('.modal-response .wrapper').attr("style","display:none");
		$('.modal-response .preload').html("<div class=\"preloader\"></div>");
				
        $.post("modal/modal_test_resptour.php", $(".modal-response form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
    }
     
         //   resptour_function();
            $(".hostel-response-bar").slider({
              range: "min",
              value: 5,
              min: 1,
              max: 10,
              slide: function(event, ui) {
                var hostelval = ui.value;
                var showval = $(this).next('.hostel-response-val');
                $(showval).text(hostelval);
                $(showval).next('.hostel-val').val(hostelval);
              }
            });
  
        
    /* visa business */
    function visa_b_period() {
      visaduration = $('#visa-duration').val();
      if (visaduration.length > 0 && $('#visa-date-from').val().length > 0) {
          now = new Date();
          $('#visa-date-to').datepicker('setDate', visaduration);
          date_to = $('#visa-date-to').datepicker( 'getDate' ).getTime();
          date_from = $('#visa-date-from').datepicker( 'getDate' ).getTime();
          next_s = date_from - now.getTime() + date_to;
          next = new Date();
          next.setTime(next_s);
          $('#visa-date-to').datepicker('setDate', next);
          $('.visa-date-js').html($('#visa-date-to').val());
      }
      else {$('.visa-date-js').html(' ');}
    }
    function visa_b_function() {
      service_info();
      order_service_checkboxes();
      $(".modal-visa-business select").msDropDown();
          
          $('.modal-visa-business p.date input#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          
    $('#p-passport-from').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange2});
    $('#p-passport-to').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange2});
 
    function customRange2(input) {
        var input_id = input.id;
                
                if ($("#p-passport-to").datepicker("getDate")) date=$("#p-passport-to").datepicker("getDate");
                else date=new Date();
                
        if (input_id == "p-passport-from"){return {minDate: null, maxDate:new Date()};}
        if (input_id == "p-passport-to"){return {minDate: $("#p-passport-from").datepicker("getDate"), maxDate: null};}
    }
      
          $('.child-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, maxDate:new Date()});
          
      $('.modal-visa-business p.date input#visa-date-from').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate: new Date()});
          
      $('#visa-date-to').datepicker();
      $("#visa-duration_child a").click(function () {visa_b_period();});
      $("#visa-date-from").change( function() {visa_b_period();});
      $("#children-count_child a").click(function () {
        needed_number = $('#children-count').val();
        current_children = $("form .children-info-item:visible");
        all_children = $("form .children-info-item");
        current_number = current_children.size();
        if (needed_number > 0) {
          if (needed_number < current_number) {
            $(current_children).each(function( intIndex){
              if (intIndex >= needed_number) {
                $(this).hide();
                $("form .children-info-item:hidden input").val("");}
            });
          }
          if (needed_number > current_number) {
            $(all_children).each(function(intIndex){
              if (intIndex < needed_number) {$(this).show();}});
          }
        }
        else {
          $("form .children-info-item input").val("");
          $(current_children).hide();
        }
      });
      $('.modal-visa-business .button a').click(function (e) {
        e.preventDefault();
                
        $.post("modal/modal_test_b_visa.php", $(".modal-visa-business form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }
     
    /* visa tour */
    function visa_t_function() {
      service_info();
      order_service_checkboxes();
      $(".modal-visa-tour select").msDropDown();
          
      $('.modal-visa-tour p.date input#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('.modal-visa-tour p.date input#visa-date-from').datepicker({beforeShow:customRangeTTVisa, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('.modal-visa-tour p.date input#visa-date-to').datepicker({beforeShow:customRangeTTVisa, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
      //$('#visa-date-from').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
          
          function customRangeTTVisa(input) {
                var input_id = input.id;
                //alert(input_id);
                if ($("#visa-date-from").datepicker("getDate")) date=$("#visa-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "visa-date-from"){return {maxDate: $("#visa-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "visa-date-to"){return {minDate: date, maxDate: null};}
      }
       
     $(".modal-visa-tour .next-js").click(function (e) {
        e.preventDefault();
        $(".modal-visa-tour").hide();
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
        $(".modal-finish-order").show();
      });
         
      $('.modal-visa-tour .button a').click(function (e) {
        e.preventDefault();
                
        $(".modal-finish-order form .hidden-data").html("");
        data = $(".modal-visa-tour form").html();
        $(".modal-finish-order form .hidden-data").html(data);
                
        $.post("modal/modal_test_t_visa.php", $(".modal-visa-tour form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
             
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }
     
    /* order service checkboxes */
    function order_service_checkboxes() {
     
         /*$("input.service-visa").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-visa').val('1');
          $('input.service-visa').attr('checked', true);
          //$('.modal-breadcrumbs .visa').show();
          //$('.modal-breadcrumbs .finish b').html(3);
        }
        else {
          $('#hidden-service-visa').val('0');
          $('input.service-visa').attr('checked', false);
          $('.modal-breadcrumbs .visa').hide();
          $('.modal-breadcrumbs .finish b').html(2);
        }
      });*/
          
      $("input.service-tour").click( function() {
        if($(this).is(':checked')) {
          $('#hidden-service-tour').val('1');
          $('input.service-tour').attr('checked', true);
        }
        else {
          $('#hidden-service-tour').val('0');
          $('input.service-tour').attr('checked', false);
        }
      });
      $("input.service-hostel").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-hostel').val('1');
          $('input.service-hostel').attr('checked', true);
        }
        else {
          $('#hidden-service-hostel').val('0');
          $('input.service-hostel').attr('checked', false);
        }
      });
      $("input.service-ins").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-ins').val('1');
          $('input.service-ins').attr('checked', true);
        }
        else {
          $('#hidden-service-ins').val('0');
          $('input.service-ins').attr('checked', false);
        }
      });
      $("input.service-transport").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-transport').val('1');
          $('input.service-transport').attr('checked', true);
        }
        else {
          $('#hidden-service-transport').val('0');
          $('input.service-transport').attr('checked', false);
        }
      });
      $("input.service-ticket").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-ticket').val('1');
          $('input.service-ticket').attr('checked', true);
        }
        else {
          $('#hidden-service-ticket').val('0');
          $('input.service-ticket').attr('checked', false);
        }
      });
      $("input.service-excursion").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-excursion').val('1');
          $('input.service-excursion').attr('checked', true);
        }
        else {
          $('#hidden-service-excursion').val('0');
          $('input.service-excursion').attr('checked', false);
        }
      });
      $("#service-subscribe").click( function() {
        if($(this).is(':checked')){$('#hidden-service-subscribe').val('1');}
        else {$('#hidden-service-subscribe').val('0');}
      });
    }
     
    /* order links */
    function order_links(type) {
                
        $(".next-js").click( function(e) {
			e.preventDefault();
			if($('.modal-hostel').is(':visible')){
				$('.modal-box').hide();
				$('.modal-visa-tour').show();
				$('.modal-breadcrumbs .item').removeClass('active');
				$('.modal-breadcrumbs .visa').addClass('active');
			} else if($('.modal-visa-tour').is(':visible')){
				$('.modal-box').hide();
				$('.modal-finish-order').show();
				$('.modal-breadcrumbs .item').removeClass('active');
				$('.modal-breadcrumbs .finish').addClass('active');
			} else if($('.modal-tour').is(':visible')){
				$('.modal-box').hide();
				$('.modal-visa-tour').show();
				$('.modal-breadcrumbs .item').removeClass('active');
				$('.modal-breadcrumbs .visa').addClass('active');
			}
			
        /*if($('.service-visa').is(':checked')){
            $('.modal-box').hide();
            $('.modal-visa-tour').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .visa').addClass('active');
        }
        else {
            $('.modal-box').hide();
            $('.modal-finish-order').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .finish').addClass('active');
        }
      });*/
        
	/*
                $.post("modal/modal_order_"+type+"_test.php?order=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });
    */    
                 /* if ($('.service-visa').is(':checked'))
                  {
                        $.post("modal/modal_order_"+type+"_test.php?visa=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });
                  }
                  else
                  {
                   
                  }*/
          });
        
	
     /* $(".finish-js").click( function() {
                $.post("modal/modal_order_"+type+"_test.php?last=1&from_order=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                });
      });*/
    

      $(".finish-js").click( function(e) {
			e.preventDefault();
			$(".modal-box").hide();
			$(".modal-finish-order").show();	  
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .finish').addClass('active');
     });
	  

 	
	/*
          $(".finish-js-visa").click( function() {
                                                  
                        $.post("modal/modal_order_"+type+"_test.php?last=1&from_visa=1", $(".wrapper form.visa").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });
          });
      */
	  
      $("a.go-hostel").click( function(e) {
 			e.preventDefault();
           $('.modal-box').hide();
            $('.modal-hostel').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .hostel').addClass('active');
      });
         
      $("a.go-excursion").click( function(e) {
 			e.preventDefault();
            $('.modal-box').hide();
            $('.modal-excursion').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .excursion').addClass('active');
      });
         
      $("a.go-transport").click( function(e) {
 			e.preventDefault();
            $('.modal-box').hide();
            $('.modal-transport').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .transport').addClass('active');
      });
      $("a.go-tour").click( function(e) {
 			e.preventDefault();
            $('.modal-box').hide();
            $('.modal-tour').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .tour').addClass('active');
      });
      $("a.prev-js").click( function(e) {
 			e.preventDefault();
      });
	  
	$("a.go-visa").click( function(e) {
 			e.preventDefault();
            $('.modal-box').hide();
            $('.modal-visa-tour').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .visa').addClass('active');
      });
	  
	  $("a.delete").click( function(e) {
			e.preventDefault();
			$(this).parent("li").remove();
      });

    }
    /* order service list */
    function service_info() {
      $(".add-service label").click( function(e) {
          //e.preventDefault();
          if ($(this).hasClass('active')) {
            //$(this).removeClass('active');
            //$('.service-info').slideUp("fast");
			e.preventDefault();
			$('.add-service label.active').removeClass('active');
			$('.service-info').slideUp("fast");
          } else {
            var title = $(this).html();
            var text = $(this).next('small').html();
            $(".add-service label.active").removeClass('active');
            $(this).addClass('active');
            if($('.service-info').is(':hidden')) {
              $('.service-info strong').html(title);
              $('.service-info p.description').html(text);
              $('.service-info').slideDown("fast");
            } else {
              $('.service-info').slideUp('fast', function() {
                $('.service-info strong').html(title);
                $('.service-info p.description').html(text);
                $('.service-info').slideDown('fast');
              });
            }
          }
      });
     $(".service-info .link a").click( function(e) {
		
			e.preventDefault();
			$('.add-service label.active').removeClass('active');
			$('.service-info').slideUp("fast");
		
      });
    }
	//service_info();
    
	/* order */
    function order_function(type) {
      order_service_checkboxes();
      order_links(type);
          //order_links();
      service_info();
          
      $(".modal-box select").msDropDown();
      $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, maxDate:new Date()});
      $('#excursion-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#tour-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#tour-date-search').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#transport-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#visa-date-from').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#visa-date-to').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
          
      function customRangeMVisa(input) {
                var input_id = input.id;
                
                if ($("#visa-date-from").datepicker("getDate")) date=$("#visa-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "visa-date-from"){return {maxDate: $("#visa-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "visa-date-to"){return {minDate: date, maxDate: null};}
      }
       
      $('#hostel-date-from').datepicker({beforeShow: customRangeMHostel, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, altField: '#h-datein-alt', altFormat: '@'});
      $('#hostel-date-to').datepicker({beforeShow: customRangeMHostel, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, altField: '#h-dateout-alt', altFormat: '@'});
      
          function customRangeMHostel(input) {
                var input_id = input.id;
                
                if ($("#hostel-date-from").datepicker("getDate"))       date=$("#hostel-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-from"){return {maxDate: $("#hostel-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-to"){return {minDate: date, maxDate: null};}
      }

    /* booking form date period */
    $('.modal-hostel .date input').change(function() {
      date_in = parseInt($("#h-datein-alt").val());
      date_out = parseInt($("#h-dateout-alt").val());
	  
      if (date_in > 0 && date_out > 0) {
        days_count = ((date_out - date_in)/(86400000));
        $(".quant-day").html('<em>' + days_count + '</em>' +declOfNum(days_count, [' ночь', ' ночи', ' ночей']));
      }
    });
    
 		
       $(".modal-box .count-number a").click(function () {
        needed_number = $('.modal-box:visible .count-number select').val();
        current_children = $(".modal-box:visible .counts .count-item:visible");
        all_children = $(".modal-box:visible .counts .count-item");
        current_number = current_children.size();
        if (needed_number > 0) {
          if (needed_number < current_number) {
            $(current_children).each(function( intIndex){
              if (intIndex >= needed_number) {$(this).hide();}
            });
          }
          if (needed_number > current_number) {
            $(all_children).each(function(intIndex){
              if (intIndex < needed_number) {$(this).show();}});
          }
        }
        else {$(current_children).hide();}
      });
         
      // finish order ajax
          //$('.modal')
          
      $('.modal-finish-order .button a.finish-js').click(function (e) {
        e.preventDefault();
		$('.modal-finish-order .wrapper').attr("style","display:none");
		$('.modal-finish-order .preload').html("<div class=\"preloader\"></div>");
		
        $('.hidden-data form').html("");
        visa = $('.modal-visa-tour form').html();
        $('.hidden-data form').append(visa);
        used = $('form.used').html();
        $('.hidden-data form').append(used);
        services = $('.services-box').html();
        $('.hidden-data form').append(services);
                                
                
         $.post("modal/modal_order_"+type+"_test.php?send=1", $(".wrapper form.form-last").serialize(),
          function(data){
            $('.css-style').html(data);
        });
           
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }

	
	
	 /*
    function hostel_order_js() {
    $('.hostel-order-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
          
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-visa-tour .prev-js').addClass('go-hostel');
            $('.modal-box').hide();
            $('.modal-hostel').show();
            $('.modal-breadcrumbs .hostel').show().addClass('active');
            $('.modal-hostel form').addClass('used');
            $('input.service-hostel').attr('checked', true);
            $('#hidden-service-hostel').val('1');
                        
            order_function("hostel");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    hostel_order_js();
	*/
	
	    function hostel_order_js() {
            $('.modal-hostel').show();
			$('.modal-visa-tour .prev-js').addClass('go-hostel');
            $('.modal-finish-order .prev-js').removeClass('go-hostel');
            $('.modal-finish-order .prev-js').addClass('go-visa');
            $('.modal-breadcrumbs .hostel').addClass('active');
		 order_function("hostel");
	}
	hostel_order_js();

	function hotel_order_js() {
    $('.hotel-order-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
          
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-visa-tour .prev-js').addClass('go-hostel');
            $('.modal-box').hide();
            $('.modal-hostel').show();
            $('.modal-breadcrumbs .hostel').show().addClass('active');
            $('.modal-hostel form').addClass('used');
            $('input.service-hostel').attr('checked', true);
            $('#hidden-service-hostel').val('1');
                        
            order_function("hotel");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    hotel_order_js();


    function excursion_order_js() {
            $('.modal-box').hide();
            $('.modal-excursion').show();
            $('.modal-breadcrumbs .excursion').show().addClass('active');
            $('.modal-excursion form').addClass('used');
            $('.modal-visa-tour .prev-js').addClass('go-excursion');
            $('.modal-breadcrumbs .excursion b').html(1);
            $('#hidden-service-excursion').val('1');
            $('input.service-excursion').attr('checked', true);
                        
            order_function("excursion");
    }

    function tour_order_js() {
            $('.modal-box').hide();
            $('.modal-tour').show();
            $('.modal-breadcrumbs .tour').addClass('active');
            $('.modal-visa-tour .prev-js').addClass('go-tour');
            $('.modal-finish-order .prev-js').addClass('go-visa');
            $('.modal-tour form').addClass('used');
            $('.modal-breadcrumbs .tour b').html(1);
            $('input.service-tour').attr('checked', true);
            $('#hidden-service-tour').val('1');
                        
            order_function("tour");
    }


    function transport_order_js() {
            $('.modal-transport form').addClass('used');
            $('input.service-transport').attr('checked', true);
            $('#hidden-service-transport').val('1');
                        
            order_function("transport");
    }

	if ($("div").hasClass("hostel-order")) {
		hostel_order_js() ;
	} else if ($("div").hasClass("tour-order")) {
		tour_order_js();
	} else if ($("div").hasClass("modal-transport")) {
		transport_order_js();
	} else if ($("div").hasClass("modal-excursion")) {
		excursion_order_js();
	} else if ($("div").hasClass("modal-visa-business")) {
		visa_b_function();
	} else if ($("div").hasClass("modal-visa-tour")) {
		visa_t_function();
	}

    function modalOnOpen(dialog) {
        //Animate the open of the popup
        dialog.overlay.fadeIn('fast', function() {
            dialog.container.fadeIn('fast', function() {
                dialog.data.hide().slideDown('fast');
            });
        });
    }
    function modalOnClose(dialog) {
        //Animates the closing of the dialogs
       dialog.data.fadeOut('fast', function() {
           dialog.container.slideUp('fast', function() {
               dialog.overlay.fadeOut('fast', function() {
                   $.modal.close();
               });
           });
       });
    }

    if ($.browser.msie && $.browser.version.substr(0,1)<8) {
      $(".content-page .news-single ul li").prepend("<span class=\"marker\"> </span>");
    }


    //$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook',slideshow:5000});
	//$("a[rel^='prettyPhoto[2]']").prettyPhoto();

		
	/* Custom select */
    $(".room-booking select").msDropDown();
    $(".room-price select").msDropDown();
    $("#hotel-search-form .msdropdown").msDropDown();
	$(".recreation-search-form .msdropdown").msDropDown();
    
    /* form validation recreation search */
    if($('#hotel-search-form .recreation-search-form form').length) {
      $("#hotel-search-form .recreation-search-form form").validate();
    }
    /* form validation contact */
    if($('form.contact-form').length) {
      //$("form.contact-form").validate();
    }
    /* form validation booking */
    if($('form.booking-form').length) {
      //$("form.booking-form").validate();
    }
    
    /* prettyphoto gallery */
   /* if($('.hotel-photos').length) {
      $(".hotel-photos a[rel^='prettyPhoto[gallery']").prettyPhoto({theme: 'light_rounded', allowresize: false});
    }*/
  
    /* datepicker */
	
      $('#form-booking-date-in').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange});
      $('#form-booking-date-out').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange});
	  
      function customRange(input) {
		  
		  if ($("#form-booking-date-in").datepicker("getDate")) date=$("#form-booking-date-in").datepicker("getDate");
		  else    date=new Date();

          var input_id = input.id;
          if (input_id == "form-booking-date-in"){return {maxDate: $("#form-booking-date-out").datepicker("getDate"), minDate:new Date() };}
          if (input_id == "form-booking-date-out"){return {minDate: date, maxDate:null};}
      }
      
    /* booking form datepicker */
    if ($('form.booking-form').length) {
      $('#h-datein').datepicker({showOn: 'both', buttonImage: 'img/common/calendar-large.png', buttonImageOnly: true, beforeShow: customRangeBooking, altField: '#h-datein-alt', altFormat: '@'});
      $('#h-dateout').datepicker({showOn: 'both', buttonImage: 'img/common/calendar-large.png', buttonImageOnly: true, beforeShow: customRangeBooking, altField: '#h-dateout-alt', altFormat: '@'});
    }
    function customRangeBooking(input) {
		 
	  if ($("#h-datein").datepicker("getDate")) date=$("#h-datein").datepicker("getDate");
	  else    date=new Date();
	
      var input_id = input.id;
      if (input_id == "h-datein") {return {maxDate: $("#h-dateout").datepicker("getDate"), minDate:new Date()};}
      if (input_id == "h-dateout") {return {minDate: date, maxDate:null};}
    }
    
    /* booking form date period */
    $('.hotel-booking-box .booking-period .date').change(function() {
      date_in = parseInt($("#h-datein-alt").val());
      date_out = parseInt($("#h-dateout-alt").val());
	  
      if (date_in > 0 && date_out > 0) {
        days_count = ((date_out - date_in)/(86400000));
        $(".booking-period .days-count").html('= ' + days_count +declOfNum(days_count, [' ночь', ' ночи', ' ночей']));
      }
    });
    
    if ($('form.booking-form .booking-rooms').length) {$("form.booking-form .booking-rooms .msdropdown").msDropDown();}
    	
    function booking_form_delete() {
      $('.hotel-booking-box .booking-rooms .booking-room-type .delete').click(function (e) {
        e.preventDefault();
		var	count=1;
        
		base = $(this).parents('.booking-room-type');
		 
		$(base).slideUp('slow', function() {
          $(base).remove();
		  change_summ();
		  $(".booking-rooms .booking-room-type .part-left span").each(function(intIndex){
			//alert($(this).html());
			$(this).html(count++);
		  });
		  
        });
      });
    }
    booking_form_delete();
    
    function booking_form_add() {
      $('.hotel-booking-box .room-total .add-room').click(function (e) {
        e.preventDefault();
        var block_num = 1;
		var number = 1;
		
		parent_form=$(this).parents("form");
		
		//if ($(parent_form).hasClass("base"))	alert("base");
		
        $(".hotel-booking-box .booking-rooms .booking-room-type").each(function(intIndex){
          block_num = parseInt($(this).attr("id").replace('booking-room-type-', '')) + 1;
        });
		
		$(".booking-rooms .booking-room-type .part-left span").each(function(intIndex){
		  number++;
		});
		
        text = $('.hotel-booking-box .booking-hidden .booking-room-type').html();
		
        $('.hotel-booking-box .rooms-box').append('<div class="booking-room-type" id="booking-room-type-' + block_num + '">' + text + '</div>');
        $("#booking-room-type-" + block_num).hide();
        $("#booking-room-type-" + block_num + " .hotel-type label").attr("for", "hotel-type-" + block_num);
        $("#booking-room-type-" + block_num + " .hotel-type select").attr("id", "hotel-type-" + block_num);
        $("#booking-room-type-" + block_num + " .hotel-type select").attr("name", "room-types[" + block_num + "]");
        $("#booking-room-type-" + block_num + " .hotel-people-count label").attr("for", "hotel-people-count-" + block_num);
        $("#booking-room-type-" + block_num + " .hotel-people-count select").attr("id", "hotel-people-count-" + block_num);
        $("#booking-room-type-" + block_num + " .hotel-people-count select").attr("name", "room-people-count[" + block_num + "]");
        $("#booking-room-type-" + block_num + " .part-left p span").html(number);
        $("#booking-room-type-" + block_num).slideDown();
        $("#booking-room-type-" + block_num + " .msdropdown").msDropDown();
		
		if ($(parent_form).hasClass("base"))
		{
			booking_form_delete();
			change_beds_list_base();
			change_one_price_base();
			change_summ();
			pipol_count_change_base();
		}
		else
		{
			booking_form_delete();
			change_beds_list();
			change_one_price();
			change_summ();
			pipol_count_change();
		}
      });
    }
    booking_form_add();
    
    /* Different color of rows */
    $("#header .contacts dl:even").addClass("odd");
    $(".popular-hotels-list ul li:odd").addClass("even");
    $(".in-content-right .services li:even").addClass("odd");
    //$(".hotel-search .search-result table tr:odd").addClass("odd");
    $(".hotel-rooms table.room-price-date tr.top:even").addClass("even");
    $(".hotel-rooms table.room-price-month tr.top:even").addClass("even");
    
    /* Room price details */
    function roomprice_details(base_id) 
	{
		if (base_id)
		{
			$('#'+base_id+' .room-booking table td a.more').click(function (e) {
				e.preventDefault();
				var base = "";
			
				base = $(this).parents('#' + base_id + ' tr');
			
				$(base).addClass('current');
			
				if ($(base).hasClass('active')) 
				{
					$(".room-price .room-booking tr.current .singletwin").attr("style","");
					$(".room-price .room-booking tr.current .how").attr("style","");  
				
					$('.room-price .room-booking tr.current .price-month-box').slideUp('slow', function() {
						$(base).removeClass('active');
					});
				}
				else 
				{
					$(base).addClass('active');
				
					thisbase=$(".room-price .room-booking tr.current .singletwin");
					thishow=$(".room-price .room-booking tr.current .how");
				
					$('.room-price .room-booking tr.current .price-month-box').slideDown('slow',function() {
						thisbase.attr("style","display:block;");
						thishow.attr("style","display:block;");
					});  
				}
			
				$(base).removeClass('current');
			});
		}
		else
		{
			$('.room-price .room-booking table td a.more').click(function (e) {
				e.preventDefault();
				var base = "";
			
				base = $(this).parents('tr');
			
				$(base).addClass('current');
			
				if ($(base).hasClass('active')) 
				{
					$(".room-price .room-booking tr.current .singletwin").attr("style","");
					$(".room-price .room-booking tr.current .how").attr("style","");  
				
					$('.room-price .room-booking tr.current .price-month-box').slideUp('slow', function() {
						$(base).removeClass('active');
					});
				}
				else 
				{
					$(base).addClass('active');
				
					thisbase=$(".room-price .room-booking tr.current .singletwin");
					thishow=$(".room-price .room-booking tr.current .how");
				
					$('.room-price .room-booking tr.current .price-month-box').slideDown('slow',function() {
						thisbase.attr("style","display:block;");
						thishow.attr("style","display:block;");
					});  
				}
			
				$(base).removeClass('current');
			});
		}
    }
    roomprice_details();
	
	function hover_singletwin()
	{
		$(".singletwin a").hover(
			function(){
				if ($(this).attr("class")!="active")	$(this).addClass("hover");
			},
			function(){
				if ($(this).attr("class")!="active")	$(this).removeClass("hover");
			}
		);
	}
	hover_singletwin();
	
	function hover_singletwindate()
	{
		$(".singletwin-date a").hover(
			function(){
				if ($(this).attr("class")!="active")	$(this).addClass("hover");
			},
			function(){
				if ($(this).attr("class")!="active")	$(this).removeClass("hover");
			}
		);
	}
	hover_singletwindate();

	// single-twin show
	function load_singletwin()
	{
		var base="";

			$('.singletwin a').click(function (e) {
			e.preventDefault();
			
			if ($(".week").attr("value")=="1")
			{
				parent_class="tr";
				even_check="";
			}
			else
			{
				parent_class=".room-price";
				even_check="tr";
			}
			
			aclass = $(this).parents("span").attr("class");
			base = $(this).parents(parent_class);
			parent_class=$(this).parents(".prices-box");
			parent_base=$(this).parents(".room-price");
			
			if ($(parent_class).hasClass("housing"))	{	 filename="housing_newtable";	}
			else	{	filename="newtable";	}
			
			if ($(parent_base).hasClass("base"))	filename="allobjects_newtable";
			
			$(base).addClass('current');

			$(".current .singletwin a").removeClass('active');
			$(".current .singletwin a").removeClass('hover');
			$(".current .singletwin ."+aclass+" a").addClass('active');
			
			loader_height=$(".current .price-month-box").height();
			
			$('.current .price-month-box').fadeOut('fast',function() { 				
				if ($(".current "+even_check).hasClass("even"))	// tr 
				{
					$('.current .price-month-box').html('<div class="preloader-gray">&nbsp;</div>');
					$('.current .preloader-gray').height(loader_height);
					$('.current .singletwin').height(loader_height-136);
				}
				else
				{
					$('.current .price-month-box').html('<div class="preloader-box">&nbsp;</div>');
					$('.current .preloader-box').height(loader_height);
					$('.current .singletwin').height(loader_height-136);
				}
				
				week=$(".current .week").attr("value");
				
				if (week)
				{
					m1=$(".room-month").attr("value");
					y1=$(".room-year").attr("value");
				}
				else
				{
					m1=$(".current .room-month").attr("value");
					y1=$(".current .room-year").attr("value");
				}
				
				hotelid=$(".hotel-id").attr("value");
				objectid=$(".object-id").attr("value");
				roomid=$(".current .room-id").attr("value");
				//if ($(".current .roomid").attr("value"))	roomid=$("tr.current .roomid").attr("value");
				//else	roomid=$(".current .room-id").attr("value");
				
				$(".room-booking .st").attr("value",aclass);				
				
				$('.current .price-month-box').fadeIn('fast',function() {
					$('.current .price-month-box').fadeOut('fast',function() { 
							$.post("modal/"+filename+".php",
								   		{"hotel-id":hotelid,
										"room-month":m1,
										"room-year":y1,
										"room-id":roomid,
										"week":week,
										"st":aclass,
										"object-id":objectid},
									function(data){
										//$(".room-booking").serialize()
										$('.current .price-month-box').html(data); 
										//$('tr.current .price-month-box').height(loader_height);
										$('.current .price-month-box').fadeIn('fast',function() { $(base).removeClass('current');  });
							});
					});
				});
			});
		 });
	}
	load_singletwin();
	
	// single-twin date show
	function load_singletwindate()
	{
		var base="";
		$('.singletwin-date a').click(function (e) {
			e.preventDefault();
			
			/*if ($(".week").attr("value")=="1")
			{
				parent_class="tr";
				even_check="";
			}
			else
			{
				parent_class=".room-price";
				even_check="tr";
			}*/
			
			aclass = $(this).parents("p").attr("class");
			base=$(this).parents(".room-price");
			parent_base=$(this).parents(".prices-box");

			if ($(base).hasClass("base"))	filename="newtable_date_base";
			else	filename="newtable_date";
			
			if ($(parent_base).hasClass("housing"))	filename="housing_date";

			$(base).addClass('current');

			$(".current .singletwin-date a").removeClass('active');
			$(".current .singletwin-date a").removeClass('hover');
			$(".current .singletwin-date ."+aclass+" a").addClass('active');
			
			loader_height=$(".current .room-price-date").height();
			
			$('.current .room-price-date').fadeOut('fast',function() { 				
				
				$('.current .room-price-date').width('75%');
				$('.current .room-price-date').html('<div class="preloader-box">&nbsp;</div>');
				$('.current .preloader-box').height(loader_height);
				
				hotelid=$(".current .hotel-id").attr("value");
				roomid=$(".current .room-id").attr("value");
				datein=$(".current .date-in").attr("value");
				dateout=$(".current .date-out").attr("value");		
				objectid=$(".current .object-id").attr("value");		
				
				$('.current .room-price-date').fadeIn('fast',function() {
					$('.current .room-price-date').fadeOut('fast',function() { 
							$('.current .room-price-date').width('');
							
							$.post("modal/"+filename+".php",{
								   			"hotel-id":hotelid,
											"room-id":roomid,
										 	"date-in":datein,
											"date-out":dateout,
											"st":aclass,
											"object-id":objectid
											},
									function(data){
										$('.current .room-price-date').html(data); 
										base_select=".current .room-price-date select";

										$('.current .room-price-date').fadeIn('fast',function() { 
											$(base_select).msDropDown();
											$(base).removeClass('current');  
										});
							});
					});
				});
			});
		 });
	}
	load_singletwindate();
    
	//	rooms list changes
	function change_beds_list(){
		$('form.hotel .hotel-type .ddChild a').click(function (e) {
			e.preventDefault();
			
			room = $(this).html();
			parent = $(this).parents('.booking-room-type');

			$(parent).addClass('current');
			
			block_num = parseInt($(parent).attr("id").replace('booking-room-type-', ''));
			
			$('.current .hotel-people-count').fadeOut('slow',function() {
				$.post("modal/pipol_list.php",{roomname:room,count:block_num,hotelid:$(".hotel-id").attr("value")},function(data){
					$('.current .hotel-people-count').html(data); 
					$(".current .hotel-people-count select").msDropDown();
					$(".current #hotel-people-count-"+block_num+"_msdd").width(49);
					$(".current #hotel-people-count-"+block_num+"_child").width(47);
					$('.current .hotel-people-count').fadeIn('slow',function() { $(parent).removeClass('current');  });
				});
			});
		});
	}
	change_beds_list();
	
	//	rooms list changes
	function change_beds_list_base(){
		$('form.base .hotel-type .ddChild a').click(function (e) {
			e.preventDefault();
			
			room = $(this).html();
			parent = $(this).parents('.booking-room-type');

			$(parent).addClass('current');
			
			block_num = parseInt($(parent).attr("id").replace('booking-room-type-', ''));
			
			$('.current .hotel-people-count').fadeOut('slow',function() {
				$.post("modal/pipol_list_base.php",{roomname:room,count:block_num,hotelid:$(".hotel-id").attr("value")},function(data){
					$('.current .hotel-people-count').html(data); 
					$(".current .hotel-people-count select").msDropDown();
					
					//if ($(".current #hotel-people-count-"+block_num+"_child").height()>155)	height=155;
					//else	height=$(".current #hotel-people-count-"+block_num+"_child").height();
					
					//alert(height);
					$(".current #hotel-people-count-"+block_num+"_msdd").width(49);
					$(".current #hotel-people-count-"+block_num+"_child").width(47);
					
					$('.current .hotel-people-count').fadeIn('slow',function() { $(parent).removeClass('current');  });
				});
			});
		});
	}
	change_beds_list_base();

	
	function change_one_price()
	{
		$('.hotel-type .ddChild a').click(function (e) {
			e.preventDefault();
		
			room = $(this).html();
		
			parent = $(this).parents('.booking-room-type');
		
			$(parent).addClass('current');
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
		  
			days_count = ((dateout - datein)/(86400));
			
			$('.current .room-price').fadeOut('slow',function() {
				$('.current .room-price').html("&nbsp;"); 
				$.post("modal/price.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count},function(data){
					$('.current .room-price').html(data); 
					change_summ();
					$('.current .room-price').fadeIn('slow',function() { $(parent).removeClass('current'); pipol_count_change();  });
				});
			});
		});
	}
	change_one_price();
	
	function change_one_price_base()
	{
		$('.hotel-type .ddChild a').click(function (e) {
			e.preventDefault();
		
			room = $(this).html();
		
			parent = $(this).parents('.booking-room-type');
		
			$(parent).addClass('current');
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
		  
			days_count = ((dateout - datein)/(86400));
			
			$('.current .room-price').fadeOut('slow',function() {
				$('.current .room-price').html("&nbsp;"); 
				$.post("modal/price_base.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count},function(data){
					$('.current .room-price').html(data); 
					change_summ();
					$('.current .room-price').fadeIn('slow',function() { $(parent).removeClass('current'); pipol_count_change_base();  });
				});
			});
		});
	}
	change_one_price_base();
	
	function	change_all_prices()
	{	
		$('.hotel-booking-box form.hotel .booking-period .date').change(function (e) {															   
			e.preventDefault();
			
			var count = 0;
			var	array = new Array;
			
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
			//alert(dateout);
			if(datein!=-1 && dateout!=-1)
			{
				days_count = ((dateout - datein)/(86400));
			  
				$('.rooms-box .booking-room-type').each(function(){						
					id=$(this).attr("id");
					
					array[count++]=$("#"+id+" .textTitle").html();
				});
				
				$(".rooms-box").fadeOut('slow',function() {
					//height=$(".rooms-box").height();
					
					//$('.rooms-box').html('<div class="upload">&nbsp;</div>');
					//$('.rooms-box .upload').height(height);
														
					$.post("modal/price_block.php",$("form.booking-form").serialize(),function(data){ 
						$(".rooms-box").html(data);
						$(".rooms-box").fadeIn('slow',function(){ 
							change_summ(); 
							$(".rooms-box .hotel-people-count select").msDropDown();
							$(".rooms-box .hotel-type select").msDropDown();
							
							change_one_price();
							pipol_count_change();
							change_beds_list();
							booking_form_delete();
							
							room=$(".booking-hidden #hotel-type-bookingnum #1").html();
							$.post("modal/price.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count},function(data){
								$(".booking-hidden .room-price").html(data); 
							});
						});
					});
				});
			}
		});
	}
	change_all_prices();
	
	function	change_all_prices_base()
	{	
		$('.hotel-booking-box form.base .booking-period .date').change(function (e) {															   
			e.preventDefault();
			
			var count = 0;
			var	array = new Array;
			
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
			//alert(dateout);
			if(datein!=-1 && dateout!=-1)
			{
				days_count = ((dateout - datein)/(86400));
			  
				$('.rooms-box .booking-room-type').each(function(){						
					id=$(this).attr("id");
					
					array[count++]=$("#"+id+" .textTitle").html();
				});
				
				$(".rooms-box").fadeOut('slow',function() {
					//height=$(".rooms-box").height();
					
					//$('.rooms-box').html('<div class="upload">&nbsp;</div>');
					//$('.rooms-box .upload').height(height);
														
					$.post("modal/price_block_base.php",$("form.booking-form").serialize(),function(data){ 
						$(".rooms-box").html(data);
						$(".rooms-box").fadeIn('slow',function(){ 
							change_summ(); 
							$(".rooms-box .hotel-people-count select").msDropDown();
							$(".rooms-box .hotel-type select").msDropDown();
							
							change_one_price_base();
							pipol_count_change_base();
							change_beds_list_base();
							booking_form_delete();
							
							room=$(".booking-hidden #hotel-type-bookingnum #1").html();
							$.post("modal/price_base.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count},function(data){
								$(".booking-hidden .room-price").html(data); 
							});
						});
					});
				});
			}
		});
	}
	change_all_prices_base();
	
	function	change_summ()
	{
		var summa=0;
		//var old_summa=0;
		
		//old_summa=parseInt($(".compact-sum strong").html());
		
		$('.rooms-box .booking-room-type .room-price strong').each(function(){
			price=$(this).html();
			
			summa+=parseInt(price);
		});
	
		 $(".compact-sum strong").html(summa);
	}
	
	function	pipol_count_change()
	{
		$(".hotel-people-count .ddChild a").click(function(e){
			e.preventDefault();
			
			pipol=$(this).html();
			parent = $(this).parents('.booking-room-type');
		
			room = $("#"+$(parent).attr("id")+" .textTitle").html();
		
			$(parent).addClass('current');
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
		  
			days_count = ((dateout - datein)/(86400));
			
			$('.current .room-price').fadeOut('slow',function() {
				$('.current .room-price').html("&nbsp;"); 
				$.post("modal/price.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count,pipol:pipol},function(data){
					$('.current .room-price').html(data); 
					change_summ();
					$('.current .room-price').fadeIn('slow',function() { $(parent).removeClass('current');  });
				});
			});
		});
	}
	pipol_count_change();
	
	function	pipol_count_change_base()
	{
		$(".hotel-people-count .ddChild a").click(function(e){
			e.preventDefault();
			
			pipol=$(this).html();
			parent = $(this).parents('.booking-room-type');
		
			room = $("#"+$(parent).attr("id")+" .textTitle").html();
		
			$(parent).addClass('current');
			datein=parseInt($("#h-datein-alt").attr("value"))/1000;
			dateout=parseInt($("#h-dateout-alt").attr("value"))/1000;
		  
			days_count = ((dateout - datein)/(86400));
			
			$('.current .room-price').fadeOut('slow',function() {
				$('.current .room-price').html("&nbsp;"); 
				$.post("modal/price_base.php",{datein:datein,dateout:dateout,roomname:room,hotelid:$(".hotel-id").attr("value"),nights:days_count,pipol:pipol},function(data){
					$('.current .room-price').html(data); 
					change_summ();
					$('.current .room-price').fadeIn('slow',function() { $(parent).removeClass('current');  });
				});
			});
		});
	}
	pipol_count_change_base();
	
    /* SEARCH more */
    $('#hotel-search-form .search-more a').click(function (e) {
      e.preventDefault();
      $('#hotel-search-form .search-more-box').slideToggle();
      $('#hotel-search-form .search-more a span').toggleClass("hidden");
      $("#hotel-search-form .search-more-box select.msdropdown").msDropDown();
    });
    
    /* input tips */
    function phone_tip() {
      if($('.phone-code-tip').length) {
        if ($('.phone-code-tip').val() == '') {$('.phone-code-tip').addClass('phone-code-tip-active');}
        else {$('.phone-code-tip').removeClass('phone-code-tip-active');}
      }
      if($('.phone-tip').length) {
        if ($('.phone-tip').val() == '') {$('.phone-tip').addClass('phone-tip-active');}
        else {$('.phone-tip').removeClass('phone-tip-active');}
      }
    }
    phone_tip();
    $(".phone-code-tip").focus(function() {$('.phone-code-tip').removeClass('phone-code-tip-active');}).blur(function() {phone_tip();});
    $(".phone-tip").focus(function() {$('.phone-tip').removeClass('phone-tip-active');}).blur(function() {phone_tip();});
    
    /* SEARCH change city */
    function highlight_city(){
      checked_input = $(".hotel-city input:checked").val();
      base = $(".hotel-city input:checked").parents("span.radio");
      if ($(base).hasClass("radio-active").toString() == 'false') {
        $(".hotel-city span.radio").removeClass("radio-active");
        $(base).addClass("radio-active");
      }
      $("#hotel-search-form p.hotel-metro").hide();
      $("#hotel-search-form p.hotel-district").hide();
	  $("#hotel-search-form p.hotel-surround").hide();
	  
      $("#hotel-search-form p.metro-" + checked_input ).show();
      $("#hotel-search-form p.district-" + checked_input ).show();
	  $("#hotel-search-form p.surround-" + checked_input ).show();
	  
      $("#hotel-search-form select.msdropdown").msDropDown();
	  
	  if ($(".radio-active input").attr("value")=="msk")
	  {
			$("#search-hotel-title-msk").attr("value",$("#search-hotel-title-spb").attr("value"));
			$("#search-hotel-title-spb").hide();
			$("#search-hotel-title-msk").show();
	  }
	  else
	  {
		  	$("#search-hotel-title-spb").attr("value",$("#search-hotel-title-msk").attr("value"));
			$("#search-hotel-title-msk").hide();
			$("#search-hotel-title-spb").show();
	  }
    }
    highlight_city();
	
    $(".hotel-city span.radio label").click(function(){
      $(".hotel-city span.radio").removeAttr("checked");
      $('#' + $(this).attr("for")).attr("checked", "checked");
      highlight_city();
    });
	
	/* SEARCH change region */
    function highlight_region(){
	  checked_input = $(".recr-region input:checked").val();
	  //alert(checked_input);
      base = $(".recr-region input:checked").parents("span.radio");
      if ($(base).hasClass("radio-active").toString() == 'false') {
        $(".recr-region span.radio").removeClass("radio-active");
        $(base).addClass("radio-active");
      }
      
	  $("#hotel-search-form p.recr-district").hide();
      $("#hotel-search-form p.recr-dest").hide();
	  //$("#hotel-search-form p.hotel-surround").hide();
	  
      $("#hotel-search-form p.distr-" + checked_input ).show();
      $("#hotel-search-form p.dest-" + checked_input ).show();
	  //$("#hotel-search-form p.surround-" + checked_input ).show();
	  
      $("#hotel-search-form select.msdropdown").msDropDown();
    }
    highlight_region();
	
    $(".recr-region span.radio label").click(function(){
      $(".recr-region span.radio").removeAttr("checked");
      $('#' + $(this).attr("for")).attr("checked", "checked");
      highlight_region();
    });
    
    /* SEARCH change center */
    function highlight_center(){
      checked_input = $(".hotel-center input:checked").val();
      base = $(".hotel-center input:checked").parents("span.radio");
      if ($(base).hasClass("radio-active").toString() == 'false') {
        $(".hotel-center span.radio").removeClass("radio-active");
        $(base).addClass("radio-active");
      }
    }
	
    highlight_center();
    $(".hotel-center span.radio label").click(function(){
      //$(".hotel-center span.radio").removeAttr("checked");
      $('#' + $(this).attr("for")).attr("checked", "checked");
      highlight_center();}
    );
    
    /* SEARCH Switch tabs to hotel */
    $('#hotel-search-form .hotel-title').click(function (e) {
      e.preventDefault();
      if ($('#hotel-search-form .hotel-title').hasClass("active")){ }
      else {
        $('#hotel-search-form h2').removeClass("active");
        $(this).addClass("active");
        $('#hotel-search-form .form-box').removeClass("active");
        $('#hotel-search-form .hotel-search-form').addClass("active");
        $("#hotel-search-form select.msdropdown").msDropDown();
      }
    });
    
    /* SEARCH Switch tabs to recreation */
    $('#hotel-search-form .recreation-title').click(function (e) {
      e.preventDefault();
      if ($('#hotel-search-form .recreation-title').hasClass("active")){ }
      else {
        $('#hotel-search-form h2').removeClass("active");
        $(this).addClass("active");
        $('#hotel-search-form .form-box').removeClass("active");
        $('#hotel-search-form .recreation-search-form').addClass("active");
		$(".recreation-search-form select.msdropdown").msDropDown();
      }
    });
    
    /* BEST OFFERS menu */
    $('#best-offers .tabs-titles li').click(function (e) {
      e.preventDefault();
      if ($(this).hasClass("active")){ }
      else {
        $('#best-offers .tabs-titles li').removeClass("active");
        $(this).addClass("active");
      }
    });
    
    /* BEST OFFERS Switch tabs */
    $('#best-offers .tabs-titles li').click(function (e) {
      e.preventDefault();
      var block_height = $("#best-offers .ajax-content").height();
      var href = $(this).children("a").attr('href');
      $("#best-offers .tabs-titles li").removeClass("active");
      $(this).addClass("active");
      $('#best-offers .ajax-content').fadeOut('slow', function() {
        $('#best-offers .ajax-content').html('<div class="preloader-box">&nbsp;</div>');
        $('#best-offers .ajax-content .preloader-box').height(block_height);
        $('#best-offers .ajax-content').fadeIn('slow', function() {
          $.get(href,
            function(data){
              $('#best-offers .ajax-content').fadeOut('slow', function() {
                text = $('#best-offers .ajax-content').html(data);
                $('#best-offers .ajax-content').fadeIn('slow');
                offers_types();
              });
            });
        });
      });
    });
    
    /* BEST OFFERS Switch types */
    function offers_types() {
      $('#best-offers .tabs-content li').not(".all").click(function (e) {
        e.preventDefault();
        var block_height = $("#best-offers .ajax-content").height();
        var href = $(this).children("a").attr('href');
        $("#best-offers .tabs-content li").removeClass("active");
        $(this).addClass("active");
        $('#best-offers .ajax-content').fadeOut('slow', function() {
          $('#best-offers .ajax-content').html('<div class="preloader-box">&nbsp;</div>');
          $('#best-offers .ajax-content .preloader-box').height(block_height);
          $('#best-offers .ajax-content').fadeIn('slow', function() {
            $.get(href,
              function(data){
                $('#best-offers .ajax-content').fadeOut('slow', function() {
                  text = $('#best-offers .ajax-content').html(data);
                  $('#best-offers .ajax-content').fadeIn('slow');
                  offers_types();
                });
              });
          });
        });
      });
    }
    offers_types();
    
    /* BEST RECREATION menu */
    $('#best-offers-recreations .tabs-titles li').click(function (e) {
      e.preventDefault();
      if ($(this).hasClass("active")){ }
      else {
        $('#best-offers-recreations .tabs-titles li').removeClass("active");
        $(this).addClass("active");
      }
    });
    
    /* BEST RECREATION Switch tabs */
    $('#best-offers-recreations .tabs-titles li').click(function (e) {
      e.preventDefault();
      var block_height = $("#best-offers-recreations .ajax-content").height();
      var href = $(this).children("a").attr('href');
      $("#best-offers-recreations .tabs-titles li").removeClass("active");
      $(this).addClass("active");
      $('#best-offers-recreations .ajax-content').fadeOut('slow', function() {
        $('#best-offers-recreations .ajax-content').html('<div class="preloader-box">&nbsp;</div>');
        $('#best-offers-recreations .ajax-content .preloader-box').height(block_height);
        $('#best-offers-recreations .ajax-content').fadeIn('slow', function() {
          $.get(href,
            function(data){
              $('#best-offers-recreations .ajax-content').fadeOut('slow', function() {
                text = $('#best-offers-recreations .ajax-content').html(data);
                $('#best-offers-recreations .ajax-content').fadeIn('slow');
                recreations_types();
              });
            });
        });
      });
    });
    
    /* BEST RECREATION Switch types */
    function recreations_types() {
      $('#best-offers-recreations .tabs-content li').not(".all").click(function (e) {
        e.preventDefault();
        var block_height = $("#best-offers-recreations .ajax-content").height();
        var href = $(this).children("a").attr('href');
        $("#best-offers-recreations .tabs-content li").removeClass("active");
        $(this).addClass("active");
        $('#best-offers-recreations .ajax-content').fadeOut('slow', function() {
          $('#best-offers-recreations .ajax-content').html('<div class="preloader-box">&nbsp;</div>');
          $('#best-offers-recreations .ajax-content .preloader-box').height(block_height);
          $('#best-offers-recreations .ajax-content').fadeIn('slow', function() {
            $.get(href,
              function(data){
                $('#best-offers-recreations .ajax-content').fadeOut('slow', function() {
                  text = $('#best-offers-recreations .ajax-content').html(data);
                  $('#best-offers-recreations .ajax-content').fadeIn('slow');
                  recreations_types();
                });
              });
          });
        });
      });
    }
    recreations_types();
    
    /* DATES CHANGE CUSTOM RANGE */
      function customRange2(input) {
		var date="";  
		var base = $(this).parents('.room-price').attr('id');
		
		if ($('#' + base + " .date-in").datepicker("getDate"))	date=$('#' + base + " .date-in").datepicker("getDate");
		else date=new Date;  
        
        if ($(input).hasClass('date-in')){return {maxDate: $('#' + base + " .date-out").datepicker("getDate"), minDate:new Date};}
        if ($(input).hasClass('date-out')){return {minDate: date, maxDate: null};}
      }
    
    /* DATES CHANGE SHOW */
    function dates_change_show(base_id) {
      $('.dates-change span').click(function (e) {
        e.preventDefault();
		var base = "";

        if (base_id)	base = $(this).parents('#' + base_id + '').attr('id');
	    else	base = $(this).parents('.room-price').attr('id');
		
		
        $("#" + base + ' .dates-change-form').slideToggle('slow', function() {
          $('#' + base + ' .dates-change-form input').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange2});
        });
      });
    }
    dates_change_show();
    
    /* DATES CHANGE RESET */
	function dates_change_reset() {
		$('.dates-change .reset a').click(function (e) {
			e.preventDefault();
			
			parent_class=$(this).parents(".prices-box");
			parent_base=$(this).parents(".room-price");
			
			if ($(parent_class).hasClass("housing"))	{	 filename="housing";	}
			else if ($(parent_class).hasClass("objects"))	{	 filename="objects";	}
			else	{	filename="dates";	}
			
			if ($(parent_base).hasClass("base"))	filename="allobjects";
			
			var base = $(this).parents('.room-price');
			$('#'+$(base).attr("id")+' .dates-change-form input').val('');
			
			$(base).addClass("current");
			
			loader_height=$(".current .price-month-box").height();
			
			object=$('.current  .object-id').attr("value");
			array = $('.current .ajax-content-box form').serialize()+"&object-id="+object;
			
			//dropdown=$(".current .ajax-content-box select").attr("id");
			
			$('.current .ajax-content-box ').fadeOut('slow',function() {	
				
				$('.current .ajax-content-box').html('<div class="preloader-box">&nbsp;</div>');
				$('.current .preloader-box').height(loader_height);
				//$('.current .singletwin').height(loader_height-136);
				
				$('.current .ajax-content-box ').fadeIn('slow',function() {
					$('.current .ajax-content-box ').fadeOut('slow',function() {
																			 
						$.post("modal/"+filename+"_delete.php",array, function(data){
							$(".current .ajax-content-box").html(data);
							
							$(".current .ajax-content-box").fadeIn('slow',function() {
								//alert($(".current .ajax-content-box select").attr("id"));
							
								$(".current .ajax-content-box select").msDropDown();
								
								dates_change_month_next();
								dates_change_month_prev();
								dates_change_select();
								dates_change_show($(base).attr("id"));
								dates_change_reset();
								roomprice_details($(base).attr("id"));
								load_singletwin();
								hover_singletwin();
								dates_change_submit();
								
								$(base).removeClass("current");
							});
							
						});
						
					});
				});
			});
		});
	}
    dates_change_reset();
    
    /* DATES CHANGE Submit */
    function dates_change_submit() {
      $('.dates-change .accept a').click(function (e) {
        e.preventDefault();
        var base = $(this).parents('.room-price').attr('id');
		//alert($('#' + base + ' .date-in').attr("value"));
        
		if ($('#' + base + ' .date-in').attr("value")!="" && $('#' + base + ' .date-out').attr("value")!="")
		{
			load_price_by_date(base);
		}
      });
    }
    dates_change_submit();
    
    /* DATES CHANGE MONTH PREV*/
    function dates_change_month_prev() {
		//alert("prev");
      $('.current-date a.prev').click(function (e) {
        e.preventDefault();
        var prev_month = -1;
        var prev_year = -1;
        var base = $(this).parents('.room-price').attr('id');
        var current_month = parseInt($('#' + base + ' .room-month').val());
        var first_month = parseInt($('#' + base + ' .room-month option:first').val());
        var current_year = parseInt($('#' + base + ' .room-year').val());
        var first_year = parseInt($('#' + base + ' .room-year option:first').val());
        if (current_month > first_month) {
          $('#' + base + ' .room-month option').each(function(){
            if (this.value < current_month) {prev_month = this.value;}
          });
          prev_year = current_year;
        }
        else {
          if (current_year > first_year) {
            $('#' + base + ' .room-year option').each(function(){
              if (this.value < current_year) {prev_year = this.value;}
              prev_month = parseInt($('#' + base + ' .room-month option:last').val());
            });
          }
        }
        if (prev_month > 0 && prev_year > 0){
          $('#' + base + ' .room-month').val(prev_month);
          $('#' + base + ' .room-year').val(prev_year);
          load_price_by_month(base);
		 // dates_change_select();
		  hover_singletwin();
          $('#' + base + ' .current-date select').msDropDown();
        }
      });
    }
    dates_change_month_prev();
    
    /* DATES CHANGE MONTH NEXT */
    function dates_change_month_next() {
      $('.current-date a.next').click(function (e) {
        e.preventDefault();
        var next_month = -1;
        var next_year = -1;
        var base = $(this).parents('.room-price').attr('id');
        var current_month = parseInt($('#' + base + ' .room-month').val());
        var last_month = parseInt($('#' + base + ' .room-month option:last').val());
        var current_year = parseInt($('#' + base + ' .room-year').val());
        var last_year = parseInt($('#' + base + ' .room-year option:last').val());
        if (current_month < last_month) {
          next_month =  parseInt($('#' + base + ' .room-month option:selected').next().val());
          next_year = current_year;
        }
        else {
          if (current_year < last_year) {
            next_year =  parseInt($('#' + base + ' .room-year option:selected').next().val());
            next_month = parseInt($('#' + base + ' .room-month option:first').val());
          }
        }
        if (next_month > 0 && next_year > 0){
          $('#' + base + ' .room-month').val(next_month);
          $('#' + base + ' .room-year').val(next_year);
          load_price_by_month(base);
		  //dates_change_select();
		  hover_singletwin();
          $('#' + base + ' .current-date select').msDropDown();
        }
      });
    }
    dates_change_month_next();
    
    /* DATES CHANGE SELECT */
    function dates_change_select() {
      $('.current-date .ddChild a').click(function () {
        var base = $(this).parents('.room-price').attr('id');
        load_price_by_month(base);
      });
    }
    dates_change_select();
    
    /* AJAX ROOM PRICE BY MONTH */
    function load_price_by_month(base_id) {
	  
	  parent_class=$('#' + base_id + '').parents(".prices-box");
	  parent_main=$('#'+base_id+'');
	  	  
	  if ($(parent_class).hasClass("services"))	
	  {
		  filename="services";
	  }
	  else if ($(parent_class).hasClass("housing"))	
	  {
		  filename="housing";
	  }
	  else if ($(parent_class).hasClass("objects"))	
	  {
		  filename="objects";
	  }
	  else	filename="roomprice";
	  
	  if ($(parent_main).hasClass("base"))	
	  {
		  filename="allobjects";
	  }
	  
	  //alert(base_id);
      loader_height = $('#' + base_id + ' .room-price-table-box').height();
      if (loader_height < 80) {loader_height = 80;}
      $('#' + base_id + ' .room-price-table-box .ajax-content').fadeOut('slow', function() {
        $('#' + base_id + ' .room-price-table-box .ajax-content').html('<div class="preloader-box">&nbsp;</div>');
        $('#' + base_id + ' .room-price-table-box .preloader-box').height(loader_height);
        $('#' + base_id + ' .room-price-table-box .ajax-content').fadeIn('slow', function() {
            $.post("modal/"+filename+"_by_month.php", $('#' + base_id + ' form').serialize(), function(data){
                $('#' + base_id + ' .room-price-table-box .ajax-content').fadeOut('slow', function() {
                  text = $('#' + base_id + ' .room-price-table-box .ajax-content').html(data);
                  $('#' + base_id + ' .room-price-table-box .ajax-content').fadeIn('slow');
                  $('#' + base_id + ' table select').msDropDown();
				  //alert(base_id);
                  roomprice_details(base_id);
				  dates_change_select();
				  hover_singletwin();
				  load_singletwin();
                });
              });
          });
      });
    }
	
    /* AJAX ROOM PRICE BY DATE */
    function load_price_by_date(base_id) {
	  var	array=$('#' + base_id + ' form').serialize()+"&object-id="+$('#' + base_id + ' form .object-id').attr("value");
	  
	  parent_base=$('#' + base_id + '').parents(".prices-box");
	  
	  if ($('#' + base_id + '').hasClass("base"))
	  {
		 filename="baseprice";
	  }
	  else
	  {
		 filename="roomprice";
	  }
	  
	  if ($(parent_base).hasClass("housing"))	 filename="housing";
	  if ($(parent_base).hasClass("objects"))	 filename="objects";
	 
      loader_height = $('#' + base_id ).height();
      $('#' + base_id + ' .ajax-content-box').fadeOut('slow', function() {
        $('#' + base_id + ' .ajax-content-box').html('<div class="preloader-box">&nbsp;</div>');
        $('#' + base_id + ' .preloader-box').height(loader_height);
        $('#' + base_id + ' .ajax-content-box').fadeIn('slow', function() {
            $.post("modal/"+filename+"_by_date.php", array, function(data){
                $('#' + base_id + ' .ajax-content-box').fadeOut('slow', function() {
                  text = $('#' + base_id + ' .ajax-content-box').html(data);
                  
				  $('#' + base_id + ' .ajax-content-box').fadeIn('slow');
                  $('#' + base_id + ' table select').msDropDown();	//
				  
				  $('#' + base_id + ' table select').each(function(){$("#"+$(this).attr("id")+"").msDropDown();});
				  
                  dates_change_submit();
                  dates_change_reset();
				 // hover_singletwin();
				  hover_singletwindate();
                  dates_change_show(base_id);
				  load_singletwindate();
				  
                });
              });
          });
      });
    }

});
/* jQuery.fx.off = true; */

