$(document).ready(function(){
    $('.b-menu li').hover(
        function(){
            $(this).addClass('hover');
        }, 
        function(){
            $(this).removeClass('hover');
        }
    );
	$("#typebtn").click(function (e) {
        $("#typelist").toggle();
        e.preventDefault();
    });
    $(".typeitem").click(function (e) {
        value=$(this).attr('title');
        $("#type").attr('value',value);
        $("#nametype").html(value);
        $("#typelist").toggle();
        e.preventDefault();
    });
    $(".typeitem").mouseover(function (e) {        
        
        e.preventDefault();
    });
	
	$("#typebtn2").click(function (e) {
        $("#typelist2").toggle();
        e.preventDefault();
    });
    $(".typeitem2").click(function (e) {
        value=$(this).attr('title');
        $("#type2").attr('value',value);
        $("#nametype2").html(value);
        $("#typelist2").toggle();
        e.preventDefault();
    });
    $(".typeitem").mouseover(function (e) {        
        
        e.preventDefault();
    });
    //Обработка типа платежа
    switch($('.payments select[name=payments]').attr('value')){
    	case 'Кредитная карта':
    		$('.creditCard').show();
    		$('.creditCard input').each(function(){
    			$(this).attr('check',true);
    		});
    		$('.creditCard select').each(function(){
    			$(this).attr('check',true);
    		});
	    	break;
    	case 'Credit Card':
    		$('.creditCard').show();
    		$('.creditCard input').each(function(){
    			$(this).attr('check',true);
    		});
    		$('.creditCard select').each(function(){
    			$(this).attr('check',true);
    		});
	    	break;
    	default:
    		$('.creditCard').hide();
			$('.creditCard input').each(function(){
				$(this).attr('check',false);
			});
			$('.creditCard select').each(function(){
				$(this).attr('check',false);
			});
    }
    
    
    $('#payments').change(function(){
        switch($('.payments select[name=payments]').val()){
	    	case 'Кредитная карта':
	    		$('.creditCard').show();
	    		$('.creditCard input').each(function(){
	    			$(this).attr('check',true);
	    		});
	    		$('.creditCard select').each(function(){
	    			$(this).attr('check',true);
	    		});
	    		break;
	    	case 'Credit Card':
	    		$('.creditCard').show();
	    		$('.creditCard input').each(function(){
	    			$(this).attr('check',true);
	    		});
	    		$('.creditCard select').each(function(){
	    			$(this).attr('check',true);
	    		});
	    		break;
	    	default:
	    		$('.creditCard').hide();
				$('.creditCard input').each(function(){
					$(this).attr('check',false);
				});
				$('.creditCard select').each(function(){
					$(this).attr('check',false);
				});
        }    	
    });
    
    $('.bronShort input').each(function(){
    	$(this).click(function(){
    		$(this).attr('value','');
    	});
	});

    $('.bronFull input').each(function(){
    	$(this).click(function(){
    		$(this).attr('value','');
    	});
	});

    $('.bronFull textarea').each(function(){
    	$(this).click(function(){
    		$(this).attr('value','');
    	});
	});
    
    $('.b-form input').each(function(){
    	$(this).click(function(){
    		$(this).attr('value','');
    	});
	});

    $('.b-form textarea').each(function(){
    	$(this).click(function(){
    		$(this).attr('value','');
    	});
	});

    //Нажатие кнопки на маленькой форме бронирования
    $('.shortBtn')
		.unbind('click')
		.bind('click', function(e){		
			e.preventDefault();
			//Запоминаем элемент
			_this = this;
			//Разделители
			var inputDelimeter = "&&&";
			var namesDelimeter = "|||";
			var parameters = "";
			$('.bronShort input').each(function(){
				parameters = parameters+$(this).attr('name')+namesDelimeter+$(this).attr('value')+inputDelimeter;
			});
			$('.selectInput').each(function(){
				parameters = parameters+$(this).attr('name')+namesDelimeter+$(this).html()+inputDelimeter;
			});
			//Собираем все инпуты
			//Отправляем данные находящиеся в инпутах
			$.ajax({
				url: "/scripts/bronShort.php",
				global: false,
				type: "POST",
				data: ({params: parameters}),
				dataType: "html",
				success: function(html){
					//alert($(_this).attr('action'));
					window.location.href = $(_this).attr('action');
					//alert(html);
				}
			});
		});
    //Нажатие кнопки на большой форме бронирования
    $('.fullBtn')
		.unbind('click')
		.bind('click', function(e){		
			e.preventDefault();
			//Запоминаем элемент
			_this = this;
			//Разделители
			var inputDelimeter = "&&&";
			var namesDelimeter = "|||";
			var parameters = "";
			$('.bronFull input').each(function(){
				parameters = parameters+$(this).attr('name')+namesDelimeter+$(this).val()+namesDelimeter+$(this).attr('realname')+inputDelimeter;
			});
			$('.bronFull select').each(function(){
				parameters = parameters+$(this).attr('name')+namesDelimeter+$(this).val()+namesDelimeter+$(this).attr('realname')+inputDelimeter;
			});
			$('.bronFull textarea').each(function(){
				parameters = parameters+$(this).attr('name')+namesDelimeter+$(this).val()+namesDelimeter+$(this).attr('realname')+inputDelimeter;
			});
			//Собираем все инпуты
			//Отправляем данные находящиеся в инпутах
			$('.bronFull').html('<div style="margin-left: 17em;"><img border="0" src="/images/loading.gif"></div>');
			$.ajax({
				url: "/scripts/bronFull.php",
				global: false,
				type: "POST",
				data: ({params: parameters}),
				dataType: "html",
				success: function(html){
					//alert(html);
					$('.bronFull').html($('.okmessage').html());
				}
			});
		})
	;});

