/* Для специального JS-кода конкретных пректов */
/*function show_checkboxes()
 {
 $('.contact_form_div .checkbox_wrapper').hide();
 if( $("#m_apartm").val() == '0' )
 {
 $("#m_apartm_single_3200_block, #m_apartm_single_3600_block").show();
 }
 if( $("#m_apartm").val() == '1' )
 {
 $("#m_apartm_double_3800_block, #m_apartm_double_4600_block").show();
 }
 }*/

function update_price()
{
	var price = 0;
	if($("#m_single_1_count").val()*1 !== NaN &&  $("#m_single_1_count").val()*1 !== undefined && $("#m_single_1_count").val()*1 >= 0)
	{
		price += $("#m_single_1_count").val()*3200;
	}

	if($("#m_single_2_count").val()*1 !== NaN &&  $("#m_single_2_count").val()*1 !== undefined && $("#m_single_2_count").val()*1 >= 0)
	{
		price += $("#m_single_2_count").val()*3600;
	}

	if($("#m_single_better_count").val()*1 !== NaN &&  $("#m_single_better_count").val()*1 !== undefined && $("#m_single_better_count").val()*1 >= 0)
	{
		price += $("#m_single_better_count").val()*3800;
	}

	if($("#m_single_2_rooms_count").val()*1 !== NaN &&  $("#m_single_2_rooms_count").val()*1 !== undefined && $("#m_single_2_rooms_count").val()*1 >= 0)
	{
		price += $("#m_single_2_rooms_count").val()*4600;
	}

	if($("#m_single_de_luxe_count").val()*1 !== NaN &&  $("#m_single_de_luxe_count").val()*1 !== undefined && $("#m_single_de_luxe_count").val()*1 >= 0)
	{
		price += $("#m_single_de_luxe_count").val()*4900;
	}

	if($("#m_double_count").val()*1 !== NaN &&  $("#m_double_count").val()*1 !== undefined && $("#m_double_count").val()*1 >= 0)
	{
		price += $("#m_double_count").val()*4900;
	}

	if($("#m_double_2_count").val()*1 !== NaN &&  $("#m_double_2_count").val()*1 !== undefined && $("#m_double_2_count").val()*1 >= 0)
	{
		price += $("#m_double_2_count").val()*5500;
	}

	if($("#m_double_de_luxe_count").val()*1 !== NaN &&  $("#m_double_de_luxe_count").val()*1 !== undefined && $("#m_double_de_luxe_count").val()*1 >= 0)
	{
		price += $("#m_double_de_luxe_count").val()*5900;
	}

	//alert(price);
	$("#reserv_summary_price").html(price);
}

$(document).ready( function()
{
	/*show_checkboxes();
	 $("#m_apartm").change(function(){
	 show_checkboxes();
	 })*/

	update_price();

	$("#m_single_1_count, #m_single_2_count, #m_single_better_count, #m_single_2_rooms_count, #m_single_de_luxe_count, #m_double_count, #m_double_2_count, #m_double_de_luxe_count").keyup( function()
	{
		update_price()
	})
	$("#m_card_no").keypress( function(key)
	{
		//alert(key.keyCode);
		if(key.keyCode == 0)
		{
			if( key.charCode >= 48 && key.charCode <= 57 )
			{
				var text = $(this).val() + '' + (key.charCode-48) ;
				var text2 = '';
				
				var len = text.length;
				for(var i=0; i<len; i++)
				{
					if( ( Math.floor(i/4) === i % 4 + 1 ) && i !== 0)
					{						
						text2 += '-';
						
					}
					
					if(text.charAt(i) != '-')
					{
						text2 += text.charAt(i);
					}
				}
				$(this).val(text2);
				//if()
			}
			return false;
		}
	});
	
	$("#rooms_order_table tr td[class!=static]:first-child").addClass('first_td');
	$("#rooms_order_table tr td[class!=static]:last-child").addClass('last_td');
	/*$("#m_secure_enter").change(function(){
	 if($(this).attr('checked') === false)
	 {
	 $("#m_card_no, #m_card_keeper_name").attr('type','text');
	 }
	 else
	 $("#m_card_no, #m_card_keeper_name").attr('type','password');
	 })*/
})
