	$(document).ready(function() {
			
		$('.emailer').mailto();

						
			$("#datepicker").datepicker({
				onSelect: function(dateText, inst) { 
					var date = $(this).val(); 
					tripDate = " on "+date+".";
					sumarize();	
				 }
			});
			$("#Book").validate({
				/*submitHandler: function(form) {
       				// do other stuff for a valid form
   					form.submit();
   				}*/
			});	
			$("#Inquiry").validate({
				/*submitHandler: function(form) {
       				// do other stuff for a valid form
   					form.submit();
   				}*/
			});	
			
			
			
			// variables for Price Calcuations:
				var nightPrice = 175;
				var basePrice = 0;
				var Triplength = 0;
				var Nights = 0;
				var nightsLodging = "";
				var lodging = true;
				var NumberInParty = 1;
				var Discount = 1; // 1 = no discount, .9 = 10% discount etc..
				var taxRate = 1.09;
				var subTotal = 0;
				var sumTotal = 0;
				var depositTotal;

			//variables for Trip Summary
				var tripName; 
				var tripDays;
				var tripDate;
				var tripPartysize = "for 1 person ";
				var	discountMsg = "";

				
				
			function sumarize(){
				// calculate price & display Total
					if (Triplength != 4){ 
						if (Triplength == 0){ Nights = 0 } 
						else { Nights = Triplength-1; }
						subTotal = Discount*(NumberInParty*(basePrice * Triplength)+(Nights * nightPrice));
						sumTotal = Math.round(taxRate*(Discount*(NumberInParty*(basePrice * Triplength)+(Nights * nightPrice)))*100)/100 ;
					
					 
					
						if($('#Deposit').is(':checked')){ 
							depositTotal = sumTotal;
						} else {
							depositTotal = Math.round((sumTotal/2)*100)/100;	
						};
				
						$("#sumTotal").text(sumTotal);
						$("#subTotal").text(subTotal);
						$("#depositTotal").text(depositTotal);
						
						//update summary text:
						$("#sumDays").html(tripDays);
						$("#sumTrip").text(tripName);
						$("#sumLodging").html(nightsLodging);
						$("#sumPartysize").html(tripPartysize);	
						$("#sumDate").html(tripDate);	
						$("#sumDiscount").html(discountMsg);
						$("#superTotal").val(sumTotal);
						$("#superdepositTotal").val(depositTotal);
						
					} else { 
						Nights = 0;
						$("#sumDays").html("Custom Trip");
						$("#sumTrip").text("");
						$("#sumLodging").html("");
						$("#sumPartysize").html("");
						$("#sumDate").html("");

						$("#sumTotal").html("? <br/>We'd love to help plan your custom trip. <br/>Please submit your details and we'll reply promptly. <br/>Feel free to call us at 208.818.9408");  
						$("#superTotal").val('custom');

					}
					
				
					
			};				

			// this function is triggered when the Trip Selection drop down is changed.	
			  $("#Trip").change(function() 
			    { 	
					
					// set base price based on which trip was chosen:
 					tripName = $(this).val(); 
 					
					if ( tripName == "Cat Skiing Trip" ){
						basePrice = 325;
					} else if ( tripName == "Guided Ski Touring Trip" ){
						basePrice = 225;
					} else if ( tripName == "Guided Ski Snowshoeing Trip" ){
						basePrice = 125;
						$('#TripLength1').attr('checked', true);
						Triplength = 1;
						$('#datepicker').focus();
						tripDays = "Half Day"
						
					} else if ( tripName == "Avalanche Awareness Course" ){
						basePrice = 200; 
						$('#TripLength1').attr('checked', true);
						Triplength = 1;
						$('#datepicker').focus();
					}
					
					sumarize();
					
			    }); 

			// this function is triggered when a "How many days?" radio button is clicked.
			$("input:radio[@name=TripLength]").click(function() { 

	    		// set trip length based on which radio button was clicked.
				var triplengthval = $(this).val(); 
				Triplength = parseInt(triplengthval);
				
				//update summary text:
				var tripDaysNumString = String(Triplength);
				tripDays = "<b>"+tripDaysNumString+ "</b> Day "						
					
				// if the trip is longer than 1 day - show the lodge in our yurt checkbox and update var for summary text:
				if (Triplength > 1 && lodging == true){
					$("#yurtTitle").css("display","block");
					
					Nights = Triplength-1;
					nightsLodging = ", <b>"+Nights+"</b> Nights Lodging ";
					$("#lodgingBoo").val('true');
					
				} else {
					nightsLodging = "";
					$("#lodgingBoo").val('false');
				};
				
				sumarize();	
			}); 
			
			//triggered when date is chosen
			$("#datepicker").blur(function(){
				var date = $(this).val(); 
				tripDate = " on "+date+".";
				sumarize();	
			});
			
			// this function is triggered when "number in party" is changed
			 $("#NumberInParty").blur(function () {
				var Num = $(this).val(); 
				NumberInParty =(parseInt(Num));
				if (isNaN(NumberInParty)==true){
					NumberInParty = 0;
				}
				//update summary text
				var partysizeNumString = String(Num);
				if (NumberInParty == 1){
					tripPartysize = " for <b>"+partysizeNumString + "</b> person";
				} else {
					tripPartysize = " for <b>"+partysizeNumString + "</b> people";
				}

					
				sumarize();	
				
    		});

			//discount code
			$("#Discount").blur(function () {
								
				var Code = $(this).val(); 
				var upCode = Code.toUpperCase();
				var DiscountCode = $.trim(upCode);
				if (DiscountCode == 'STUDENT' ){
					Discount = .9;
					discountMsg = "<b class='red'> - 10% Student Discount</b><br/>"
				} else if (DiscountCode == 'RETURNING' && NumberInParty > 1){
					Discount = .9;
					discountMsg = "<b class='red'> - 10% Returning Customer Discount</b><br/>"
				} else {
					Discount = 1;
					discountMsg = "";
				}
				
				sumarize();
			});
			
			$('#Yurt').click(function(){
				if($('#Yurt').is(':checked')){ 
					nightPrice = 175;
					nightsLodging = ", <b>"+Nights+"</b> Nights Lodging ";
					lodging = true;
				 } else {
					nightPrice = 0;
					nightsLodging = "";
					lodging = false;
				};

				sumarize();
			});
		/*	
			$('#idResident').click(function(){	
				
				if($('#idResident').is(':checked')){ 
					taxRate=1.06; 
				 } else {
					taxRate=1;
				};
				sumarize();
			});
		*/
		$('#Deposit').click(function(){	
			sumarize();
		});
		
		$("#Payment").change(function() {
			paymentType = $(this).val(); 
			if (paymentType == "Check"){
				$("#paymentMsg").html("Make your check out to Peak Adventures<br/>for the amount below and mail it to:<br/>Peak Adventures P.O. Box 215 Cataldo, ID 83810<br/>Please review your order below and submit your information by clicking the Submit button.");
			} else if (paymentType == "Credit Card") {
				$("#paymentMsg").html("<label class='title' for='ccType'>Credit Card Type<em class='req'>*</em></label><select id='ccType' name='ccType' class='field select' title='Credit Card Type' tabindex='16'>	<option value=''>Credit Card Type</option><option value='Visa'>Visa</option>	<option value='MasterCard'>MasterCard</option>	<option value='Discover'>Discover</option></select><label class='title' id='ccNameLabel' for='ccName'>Name on Credit Card<em class='req'>*</em></label><input id='ccName' name='ccName' type='text' class='field text required' value=''  tabindex='16' /><label class='title' id='ccLabel' for='cc'>Credit Card #<em class='req'>*</em></label><input id='cc' name='cc' type='text' class='field text required creditcard' value=''  tabindex='17' /><label class='title' id='ccExpLabel' for='ccExp'>Credit Card Expiration Date<em class='req'>*</em></label> <input id='ccExp' name='ccExp' type='text' class='field text required' value='' tabindex='18' /><label class='title' id='ccSecurityCodeLabel' for='ccSecurityCode'>3 Digit Security Code<em class='req'>*</em></label><input id='ccSecurityCode' name='ccSecurityCode' type='text' class='field text required' value='' tabindex='19' /><label class='title' id='ccaddress1Label' for='ccaddress1'>Billing Address<em class='req'>*</em></label><input id='ccaddress1' name='ccaddress1' type='text' class='field text required' value='' tabindex='20' /><label class='title' id='ccaddress2Label' for='ccaddress2'>Billing Address</label><input id='ccaddress2' name='ccaddress2' type='text' class='field text' value='' tabindex='21' /><label class='title' id='cccityLabel' for='cccity'>City<em class='req'>*</em></label><input id='cccity' name='cccity' type='text' class='field text required' value='' tabindex='22' /><label class='title' id='ccstateLabel' for='ccstate'>State/Province<em class='req'>*</em></label><input id='ccstate' name='ccstate' type='text' class='field text required' value='' tabindex='23' /><label class='title' id='cczipLabel' for='cczip'>Zip/Postal Code<em class='req'>*</em></label><input id='cczip' name='cczip' type='text' class='field text required' value='' tabindex='24' /><label class='title' id='cccountryLabel' for='cccountry'>Country<em class='req'>*</em></label><input id='cccountry' name='cccountry' type='text' class='field text required' value='' tabindex='25' /><br/><div id='instructions'>Please review your order below and upon submit Peak Adventures will finalize your payment.</div>");
			} else if (paymentType == "Google Checkout") {
				$("#paymentMsg").html("We will be offering this as a payment option soon, in the meantime, please pay by check or credit card.");
			} else if (paymentType == "Paypal") {
				$("#paymentMsg").html("We will be offering this as a payment option soon, in the meantime, please pay by check or credit card.");
			}
		});
	
		$('#How').change(function(){	
			Howdidyouhear = $(this).val();
			if (Howdidyouhear == "Other"){
				$("#HowOther").css('display','block');	
				$('#HowOther').focus();
			}
		});
		$('#Where').change(function(){	
			Whereesledoyouski = $(this).val();
			if (Whereesledoyouski == "Other"){
				$("#WhereOther").css('display','block');	
				$('#WhereOther').focus();
			}
		});
			
	});