
$(document).ready(function(){
	
	$('input.room-trigger').click(function(){
			$('.stay-total-value').html(formatPrice(parseFloat($('.stay-total-value').html())-parseFloat($('.room-total-value').html())+parseFloat($(this).next().val())));
			$('.room-total-value').html(formatPrice(parseFloat($(this).next().val())));
	});
	
	
	$('input.addition-trigger').click(function(){
		if($(this).is(':checked')){
			$('.stay-total-value').html(formatPrice(parseFloat($('.stay-total-value').html())+parseFloat($(this).next().val())));
			$('.addition-to-show-'+$(this).next().next().html()).show();
		} else {
			$('.stay-total-value').html(formatPrice(parseFloat($('.stay-total-value').html())-parseFloat($(this).next().val())));
			$('.addition-to-show-'+$(this).next().next().html()).hide();
		}
		
	});
	$('select.addition-trigger').change(function(){
		if(!this.addedPriceToRemove) this.addedPriceToRemove = 0;
		$('.stay-total-value').html(formatPrice(parseFloat($('.stay-total-value').html())+(parseFloat($(this).val())*parseFloat($(this).next().val()))-this.addedPriceToRemove));
		this.addedPriceToRemove = parseFloat($(this).val())*parseFloat($(this).next().val());
		if($(this).val()) $('.addition-to-show-'+$(this).next().next().html()).show();
		else $('.addition-to-show-'+$(this).next().next().html()).hide();
		$('.addition-to-show-'+$(this).next().next().html()+' .price').html(formatPrice($(this).val()*parseFloat($(this).next().val())));
	});
	
});


function formatPrice(n) {
   if (n.toFixed) {
      n = n.toFixed(2);
   } else {
      n = n.toString();
      if (n.indexOf('.') < 0) n += '.00';
      if (n.indexOf('.') == n.length-2) n += '0';
   }
   return n;
}

var firsttime;

function validator() {
  if (firsttime == "Y") {
    alert("Please wait, your payment is being processed.");
    return (false);
  }
  firsttime = "Y";
  return (true);
}

