
$(document).ready(function(){
	$('.mtxt').hide();
	
	$('.menu > li > a[rel="submenu"]').click(function(){
		$obj=$(this).parent();
		$obj.addClass('sel');
		$obj.children('.submenu').show(100);
		return false;
	});

	$('.menu > li').mouseleave(function(){
		$(this).removeClass('sel');
		$(this).children('.submenu').fadeOut(200);
	});
	
	$('.photogalitems > div > div.item > div > a').click(function(){
		$('#photodiv > a > img:first').fadeOut(200,function(){
			$('#photodiv > a > img:first').load(function(){$(this).fadeIn(300)});
		});
		setTimeout('photogal_load_photo("'+this.rel+'","'+this.href+'");',200); 
		return false;
	});

});

function photogal_load_photo(p_id,p_href)
{
	$("#photodiv > a > img:first").attr("src",p_href);
	$("#photocomment").html($('#photo_'+p_id).attr('title'));
	$("#photodiv > a").unbind('click');
	$("#photodiv > a").click(function(){
		$('#photo_'+p_id).click();
		return false;
	});
}

function calculate_price(mess1,mess2,mess3,mess4)
{
	$('#totalprice').html('');
	obj=document.inp_form;
	if(obj.date_from.value == '' || obj.date_to.value == '')
		alert(mess1);
	else
	{
		var res=$.ajax({
		  url: "/calculate.php?room="+obj.room.value+"&livetype="+obj.livetype.value+"&date_from="+obj.date_from.value+"&date_to="+obj.date_to.value+"&transfer_income="+(obj.transfer_income.checked?'on':'')+"&transfer_outcome="+(obj.transfer_outcome.checked?'on':'')+"&promocode="+obj.promocode.value,
		  dataType:  'json',
		  async: false,
		  success: function(data){
				if(data['summ'] != '0')
				{
					$('#totalprice').html('<span>'+mess2+'</span><br>'+data['summ']+' '+mess4);
					$('#book_contact').slideDown(300);
					obj.price.value=data['summ']+' руб.';
					$('#pricecomment').html(data['promotext']);
					//obj.price_clear.value=res;
				}
				else
				{
					$('#totalprice').html('<span><b>'+mess3+'</b></span>');
					$('#book_contact').slideUp(100);
					obj.price.value='';
					$('#pricecomment').html();
					//obj.price_clear.value='';
				}		  	
		  }
		});		
	}

}

function choose_paytype(objb)
{
		obj=document.paytype_form;
	
		var res=$.ajax({
		  url: "/paymethod.php?id="+obj.id.value+"&key="+obj.key.value+"&paytype="+obj.paytype.value,
		  dataType: "text",
			async: false
		}).responseText;
		
		if(res == '1')
		{
			if(obj.paytype.value == 'sber')
				$('#sber').slideDown(300);
	
			if(obj.paytype.value == 'card')
				$('#card').slideDown(300);
	
			if(obj.paytype.value == 'mb')
				document.location='/pay/?'+obj.id.value+'&'+obj.key.value;
				
			obj.paytype.disabled=true;
			objb.disabled=true;
		}
		else
			alert("Произошла ошибка\nError");
}


function calc_initRange()
{
	$(document).ready(function(){
		$('body').append('<div style="display: none;"><img id="calc_calImg" src="/radmin/DateRange/calbtn.gif" alt="Calendar" class="calcpop"></div>');

		$('#startPicker,#endPicker').datepick({ 
		    onSelect: calc_customRange, showTrigger: '#calc_calImg', yearRange: 'c-2:c+2', minDate: 0, maxDate: +700});  

	});
}

function calc_customRange(dates)
{ 
   if (this.id == 'startPicker') { 
   		if(dates[0])
   		 dates[0].setDate(dates[0].getDate()+1);
       $('#endPicker').datepick('option', 'minDate', dates[0] || null); 
   } 
   else { 
   		if(dates[0])
   	   dates[0].setDate(dates[0].getDate()-1);
       $('#startPicker').datepick('option', 'maxDate', dates[0] || null); 
   }
}	
