var post_search_src = '';
var post_flights = false;
var post_hotel = false;
var post_car = false;
var post_vacation = false;
var search_info = '';
var search_title = 'Search Results';
var deal_airport_code1 = '';
var deal_airport_code2 = '';
var deal_city = '';
function showTab(){
	
	var step = document.search_form.step.value;
	
	switch(step) {
		
		case "flights":
			var auto_populate = false;
			document.search_form.searchtype.value = 'air';
			roundTrip();
			flights_layer.style.visibility = 'visible';
			hotels_layer.style.visibility = 'hidden';
			cars_layer.style.visibility = 'hidden';
			vacations_layer.style.visibility = 'hidden';
			group_booking_off.style.visibility = 'hidden';
			group_booking_off.style.display = 'none';
			group_booking_on.style.visibility = 'hidden';
			group_booking_on.style.display = 'none';
			va_hotel_rooms.style.visibility = 'hidden';
			if(document.search_form.fl_city1.value == document.search_form.default_fl_city1.value && document.search_form.va_city1.value != document.search_form.default_va_city1.value) {
				document.search_form.fl_city1.value = document.search_form.va_city1.value;
				auto_populate = true;
			}
			
			if(document.search_form.fl_city2.value == document.search_form.default_fl_city2.value && document.search_form.ca_city1.value != document.search_form.default_ca_city1.value) {
				document.search_form.fl_city2.value = document.search_form.ca_city1.value;
				auto_populate = true;
			} else if(document.search_form.fl_city2.value == document.search_form.default_fl_city2.value && document.search_form.va_city2.value != document.search_form.default_va_city2.value) {
				document.search_form.fl_city2.value = document.search_form.va_city2.value;
				auto_populate = true;
			}
			
			if(document.search_form.fl_date1.value == document.search_form.default_fl_date1.value && document.search_form.ho_date1.value != document.search_form.default_ho_date1.value) {
				document.search_form.fl_date1.value = document.search_form.ho_date1.value;
				auto_populate = true;
			} else if(document.search_form.fl_date1.value == document.search_form.default_fl_date1.value && document.search_form.ca_date1.value != document.search_form.default_ca_date1.value) {
				document.search_form.fl_date1.value = document.search_form.ca_date1.value;
				auto_populate = true;
			} else if(document.search_form.fl_date1.value == document.search_form.default_fl_date1.value && document.search_form.va_date1.value != document.search_form.default_va_date1.value) {
				document.search_form.fl_date1.value = document.search_form.va_date1.value;
				auto_populate = true;
			}
			
			if(document.search_form.fl_date2.value == document.search_form.default_fl_date2.value && document.search_form.ho_date2.value != document.search_form.default_ho_date2.value) {
				document.search_form.fl_date2.value = document.search_form.ho_date2.value;
				auto_populate = true;
			} else if(document.search_form.fl_date2.value == document.search_form.default_fl_date2.value && document.search_form.ca_date2.value != document.search_form.default_ca_date2.value) {
				document.search_form.fl_date2.value = document.search_form.ca_date2.value;
				auto_populate = true;
			} else if(document.search_form.fl_date2.value == document.search_form.default_fl_date2.value && document.search_form.va_date2.value != document.search_form.default_va_date2.value) {
				document.search_form.fl_date2.value = document.search_form.va_date2.value;
				auto_populate = true;
			}
			
			if(document.search_form.current_adults.value != '')  document.search_form.fl_adults.value = document.search_form.current_adults.value;
			if(document.search_form.current_children.value != '')  document.search_form.fl_children.value = document.search_form.current_children.value;
			break;
			
		case "hotels":
			var auto_populate = false;
			document.search_form.searchtype.value = 'hotel';
			groupBooking();
			flights_layer.style.visibility = 'hidden';
			hotels_layer.style.visibility = 'visible';
			cars_layer.style.visibility = 'hidden';
			vacations_layer.style.visibility = 'hidden';
			va_hotel_rooms.style.visibility = 'hidden';
			
			if(document.search_form.ho_date1.value == document.search_form.default_ho_date1.value && document.search_form.fl_date1.value != document.search_form.default_fl_date1.value) {
				document.search_form.ho_date1.value = document.search_form.fl_date1.value;
				auto_populate = true;
			} else if(document.search_form.ho_date1.value == document.search_form.default_ho_date1.value && document.search_form.va_date1.value != document.search_form.default_va_date1.value) {
				document.search_form.ho_date1.value = document.search_form.va_date1.value;
				auto_populate = true;
			} else if(document.search_form.ho_date1.value == document.search_form.default_ho_date1.value && document.search_form.ca_date1.value != document.search_form.default_ca_date1.value) {
				document.search_form.ho_date1.value = document.search_form.ca_date1.value;
				auto_populate = true;
			}
			
			if(document.search_form.ho_date2.value == document.search_form.default_ho_date2.value && document.search_form.fl_date2.value != document.search_form.default_fl_date2.value) {
				document.search_form.ho_date2.value = document.search_form.fl_date2.value;
				auto_populate = true;
			} else if(document.search_form.ho_date2.value == document.search_form.default_ho_date2.value && document.search_form.va_date2.value != document.search_form.default_va_date2.value) {
				document.search_form.ho_date2.value = document.search_form.va_date2.value;
				auto_populate = true;
			} else if(document.search_form.ho_date2.value == document.search_form.default_ho_date2.value && document.search_form.ca_date2.value != document.search_form.default_ca_date2.value) {
				document.search_form.ho_date2.value = document.search_form.ca_date2.value;
				auto_populate = true;
			}
			
			if(document.search_form.current_adults.value != '')  document.search_form.ho_adults.value = document.search_form.current_adults.value;
			if(document.search_form.current_children.value != '')  document.search_form.ho_children.value = document.search_form.current_children.value;
			//document.search_form.ho_rooms_no_group.value = document.search_form.ho_rooms.value;
			break;
			
		case "cars":
			document.search_form.searchtype.value = 'car';
			flights_layer.style.visibility = 'hidden';
			hotels_layer.style.visibility = 'hidden';
			cars_layer.style.visibility = 'visible';
			vacations_layer.style.visibility = 'hidden';
			group_booking_off.style.visibility = 'hidden';
			group_booking_off.style.display = 'none';
			group_booking_on.style.visibility = 'hidden';
			group_booking_on.style.display = 'none';
			va_hotel_rooms.style.visibility = 'hidden';
			
			if(document.search_form.ca_city1.value == document.search_form.default_ca_city1.value && document.search_form.fl_city2.value != document.search_form.default_fl_city2.value) {
				document.search_form.ca_city1.value = document.search_form.fl_city2.value;
			} else if(document.search_form.ca_city1.value == document.search_form.default_ca_city1.value && document.search_form.va_city2.value != document.search_form.default_va_city2.value) {
				document.search_form.ca_city1.value = document.search_form.va_city2.value; 
			}
			
			if(document.search_form.ca_date1.value == document.search_form.default_ca_date1.value && document.search_form.fl_date1.value != document.search_form.default_fl_date1.value) {
				document.search_form.ca_date1.value = document.search_form.fl_date1.value;
			} else if(document.search_form.ca_date1.value == document.search_form.default_ca_date1.value && document.search_form.va_date1.value != document.search_form.default_va_date1.value) {
				document.search_form.ca_date1.value = document.search_form.va_date1.value;
			} else if(document.search_form.ca_date1.value == document.search_form.default_ca_date1.value && document.search_form.ho_date1.value != document.search_form.default_ho_date1.value) {
				document.search_form.ca_date1.value = document.search_form.ho_date1.value;
			}
			
			if(document.search_form.ca_date2.value == document.search_form.default_ca_date2.value && document.search_form.fl_date2.value != document.search_form.default_fl_date2.value) {
				document.search_form.ca_date2.value = document.search_form.fl_date2.value;
			} else if(document.search_form.ca_date2.value == document.search_form.default_ca_date2.value && document.search_form.va_date2.value != document.search_form.default_va_date2.value) {
				document.search_form.ca_date2.value = document.search_form.va_date2.value;
			} else if(document.search_form.ca_date2.value == document.search_form.default_ca_date2.value && document.search_form.ho_date2.value != document.search_form.default_ho_date2.value) {
				document.search_form.ca_date2.value = document.search_form.ho_date2.value;
			}
			break;
			
		case "vacations":
			VacationHotelRooms();
			
			document.search_form.searchtype.value = 'vacation';
			flights_layer.style.visibility = 'hidden';
			hotels_layer.style.visibility = 'hidden';
			cars_layer.style.visibility = 'hidden';
			vacations_layer.style.visibility = 'visible';
			group_booking_off.style.visibility = 'hidden';
			group_booking_off.style.display = 'none';
			group_booking_on.style.visibility = 'hidden';
			group_booking_on.style.display = 'none';
			
			if(document.search_form.va_city1.value == document.search_form.default_va_city1.value && document.search_form.fl_city1.value != document.search_form.default_fl_city1.value) {
				document.search_form.va_city1.value = document.search_form.fl_city1.value;
				auto_populate = true;
			}
			
			if(document.search_form.va_city2.value == document.search_form.default_va_city2.value && document.search_form.ca_city1.value != document.search_form.default_ca_city1.value) {
				document.search_form.va_city2.value = document.search_form.ca_city1.value;
				auto_populate = true;
			} else if(document.search_form.va_city2.value == document.search_form.default_va_city2.value && document.search_form.fl_city2.value != document.search_form.default_fl_city2.value) {
				document.search_form.va_city2.value = document.search_form.fl_city2.value;
				auto_populate = true;
			}
			
			if(document.search_form.va_date1.value == document.search_form.default_va_date1.value && document.search_form.fl_date1.value != document.search_form.default_fl_date1.value) {
				document.search_form.va_date1.value = document.search_form.fl_date1.value;
				auto_populate = true;
			} else if(document.search_form.va_date1.value == document.search_form.default_va_date1.value && document.search_form.ho_date1.value != document.search_form.default_ho_date1.value) {
				document.search_form.va_date1.value = document.search_form.ho_date1.value;
				auto_populate = true;
			} else if(document.search_form.va_date1.value == document.search_form.default_va_date1.value && document.search_form.ca_date1.value != document.search_form.default_ca_date1.value) {
				document.search_form.va_date1.value = document.search_form.ca_date1.value;
				auto_populate = true;
			}
			
			if(document.search_form.va_date2.value == document.search_form.default_va_date2.value && document.search_form.fl_date2.value != document.search_form.default_fl_date2.value) {
				document.search_form.va_date2.value = document.search_form.fl_date2.value;
				auto_populate = true;
			} else if(document.search_form.va_date2.value == document.search_form.default_va_date2.value && document.search_form.ho_date2.value != document.search_form.default_ho_date2.value) {
				document.search_form.va_date2.value = document.search_form.ho_date2.value;
				auto_populate = true;
			} else if(document.search_form.va_date2.value == document.search_form.default_va_date2.value && document.search_form.ca_date2.value != document.search_form.default_ca_date2.value) {
				document.search_form.va_date2.value = document.search_form.ca_date2.value;
				auto_populate = true;
			}
			
			if(document.search_form.current_adults.value != '')  document.search_form.va_adults.value = document.search_form.current_adults.value;
			if(document.search_form.current_children.value != '')  document.search_form.va_children.value = document.search_form.current_children.value;
			if(document.search_form.ho_rooms.value != '')  document.search_form.va_rooms.value = document.search_form.ho_rooms.value;
			break;
			
		default:
			document.search_form.searchtype.value = 'air';
			flights_layer.style.visibility = 'visible';
			hotels_layer.style.visibility = 'hidden';
			cars_layer.style.visibility = 'hidden';
			vacations_layer.style.visibility = 'hidden';
			group_booking_off.style.visibility = 'hidden';
			group_booking_off.style.display = 'none';
			group_booking_on.style.visibility = 'hidden';
			group_booking_on.style.display = 'none';
			break;

	}
}

function updateCauseResults() {
	switch(document.search_form.searchtype.value) {
		case "air":
			if(post_flights == true)  showResults();
			break;
			
		case "hotel":
			if(post_hotel == true)  showResults();
			break;
			
		case "car":
			if(post_car == true)  showResults();
			break;
			
		case "vacation":
			if(post_vacation == true)  showResults();
			break;
			
	}
}

function showResults() {
	var src = document.search_form.default_src.value;
	var errors = 0;	
	
	switch(document.search_form.searchtype.value) {
	
		case "air":
								
			// error_fl_city1
			if(document.search_form.fl_city1.value == '' || document.search_form.fl_city1.value == document.search_form.default_fl_city1.value)  {
				errors++;
				document.search_form.fl_city1.value = document.search_form.default_fl_city1.value;
				document.getElementById("error_fl_city1").innerHTML = "<strong>Departing From</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_fl_city1").innerHTML = "<strong>Departing From</strong>";
			}
			
			// error_fl_date1
			if(document.search_form.fl_date1.value == '' || document.search_form.fl_date1.value == document.search_form.default_fl_date1.value)  {
				errors++;
				document.search_form.fl_date1.value = document.search_form.default_fl_date1.value;
				document.getElementById("error_fl_date1").innerHTML = "<strong>Departure Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_fl_date1").innerHTML = "<strong>Departure Date</strong>";
			}
			
			// error_fl_city2
			if(document.search_form.fl_city2.value == '' || document.search_form.fl_city2.value == document.search_form.default_fl_city2.value)  {
				errors++;
				document.search_form.fl_city2.value = document.search_form.default_fl_city2.value;
				document.getElementById("error_fl_city2").innerHTML = "<strong>Traveling To</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_fl_city2").innerHTML = "<strong>Traveling To</strong>";
			}
			
			// error_fl_date2
			if(document.search_form.fl_flighttype[0].checked == true) {
				if(document.search_form.fl_date2.value == '' || document.search_form.fl_date2.value == document.search_form.default_fl_date2.value)  {
					errors++;
					document.search_form.fl_date2.value = document.search_form.default_fl_date2.value;
					document.getElementById("error_fl_date2").innerHTML = "<strong>Returning Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
				} else {
					document.getElementById("error_fl_date2").innerHTML = "<strong>Returning Date</strong>";
				}
			} else {
				document.search_form.fl_date2.value = document.search_form.default_fl_date2.value;
			}
			
			if(errors == 0) {
				document.getElementById("fl_error_msg").innerHTML = "";
				var query_string = '';
				query_string += '&cause_id=' + document.search_form.cause_id.value;
				query_string += '&searchtype=air';
				if(document.search_form.fl_flighttype[0].checked == true) {
					query_string += '&flighttype=' + document.search_form.fl_flighttype[0].value;
				} else {
					query_string += '&flighttype=' + document.search_form.fl_flighttype[1].value;
				}
				query_string += '&city1=' + document.search_form.fl_city1.value;
				query_string += '&date1=' + document.search_form.fl_date1.value;
				query_string += '&city2=' + document.search_form.fl_city2.value;
				query_string += '&date2=' + document.search_form.fl_date2.value;
				query_string += '&adults=' + document.search_form.fl_adults.value;
				query_string += '&children=' + document.search_form.fl_children.value;
				
				//src = 'http://www.bookingwiz.com/BWIAB/air.asp?bwib_id=bweiqtd&process=referrer&fm_mic=auupprs&fm_datecalc=0&process_tiles=1&process_errors=1' + query_string;
				src = '/search-results.php?search_query=' + php_urlencode('http://www.bookingwiz.com/xml_redirect.asp?fm_mic=auupprs&fm_datecalc=0&fm_xml=1&fm_xml_popup=1&fm_xml_url=&singleMenu=air' + query_string);
				post_flights = true;
				
				var search_city1 = document.search_form.fl_city1.value;
				search_city1 = search_city1.substr(1,3);
				search_city1 = search_city1.toUpperCase();
				
				var search_city2 = document.search_form.fl_city2.value;
				search_city2 = search_city2.substr(1,3);
				search_city2 = search_city2.toUpperCase();
				
				search_info = search_city1 + ' to ' + search_city2 + '<br>' + document.search_form.fl_date1.value + ' - ' + document.search_form.fl_date2.value;
				deal_airport_code1 = getAirportCode(document.search_form.fl_city1.value);
				deal_airport_code2 = getAirportCode(document.search_form.fl_city2.value);
				deal_city = '';
			} else {
				document.getElementById("fl_error_msg").innerHTML = "<div class=\"searchFormError\" style=\"padding-left:10px;padding-right:10px;padding-top:6px;padding-bottom:0px;\">Please correct the items below in red</div>";
				post_flights = false;
				search_info = '';
			}
			
			search_title = 'Flight Results';
			break;
			
		case "hotel":
		
			// error_ho_city1
			if(document.search_form.ho_city1.value == '' || document.search_form.ho_city1.value == document.search_form.default_ho_city1.value)  {
				errors++;
				document.search_form.ho_city1.value = document.search_form.default_ho_city1.value;
				document.getElementById("error_ho_city1").innerHTML = "<strong>Destination City</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_ho_city1").innerHTML = "<strong>Destination City</strong>";
			}
			
			// error_ho_date1
			if(document.search_form.ho_date1.value == '' || document.search_form.ho_date1.value == document.search_form.default_ho_date1.value)  {
				errors++;
				document.search_form.ho_date1.value = document.search_form.default_ho_date1.value;
				document.getElementById("error_ho_date1").innerHTML = "<strong>Check-In Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_ho_date1").innerHTML = "<strong>Check-In Date</strong>";
			}
						
			// error_ho_date2
			if(document.search_form.ho_date2.value == '' || document.search_form.ho_date2.value == document.search_form.default_ho_date2.value)  {
				errors++;
				document.search_form.ho_date2.value = document.search_form.default_ho_date2.value;
				document.getElementById("error_ho_date2").innerHTML = "<strong>Check-Out Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_ho_date2").innerHTML = "<strong>Check-Out Date</strong>";
			}
			
			if(errors == 0) {
				document.getElementById("ho_error_msg").innerHTML = "";
				var query_string = '';
				query_string += '&cause_id=' + document.search_form.cause_id.value;
				query_string += '&searchtype=hotel';
				query_string += '&city1=' + document.search_form.ho_city1.value;
				query_string += '&date1=' + document.search_form.ho_date1.value;
				query_string += '&date2=' + document.search_form.ho_date2.value;
				query_string += '&adults=' + document.search_form.ho_adults.value;
				query_string += '&children=' + document.search_form.ho_children.value;
				
				/*
				if(document.search_form.ho_group.checked == true) {
					query_string += '&hotel_group=1';
					query_string += '&rooms=' + document.search_form.ho_rooms.value;
					query_string += '&hotel_event=' + document.search_form.ho_event.value;
				} else {
					query_string += '&hotel_group=0';
					query_string += '&rooms=' + document.search_form.ho_rooms.value;
					query_string += '&hotel_event=0';
				}
				*/
				
				src = '/search-results.php?search_query=' + php_urlencode('http://www.bookingwiz.com/xml_redirect.asp?fm_mic=auupprs&fm_datecalc=0&fm_xml=1&fm_xml_popup=1&fm_xml_url=&singleMenu=hotel' + query_string);
				post_hotel = true;
				
				var search_city1 = document.search_form.ho_city1.value;
				search_city1 = search_city1.replace(', United States', '');
				//search_city1 = search_city1.toUpperCase();
				search_city1 = search_city1.substring(0, 55);
				
				search_info = search_city1 + '<br>' + document.search_form.ho_date1.value + ' - ' + document.search_form.ho_date2.value;
				
				deal_airport_code1 = '';
				deal_airport_code2 = '';
				deal_city = php_urlencode(document.search_form.ho_city1.value);
			} else {
				document.getElementById("ho_error_msg").innerHTML = "<div class=\"searchFormError\" style=\"padding-left:10px;padding-right:10px;padding-top:6px;padding-bottom:0px;\">Please correct the items below in red</div>";
				post_hotel = false;
				search_info = '';
			}
			search_title = 'Hotel Results';
			break;
			
		case "car":

			// error_ca_city1
			if(document.search_form.ca_city1.value == '' || document.search_form.ca_city1.value == document.search_form.default_ca_city1.value)  {
				errors++;
				document.search_form.ca_city1.value = document.search_form.default_ca_city1.value;
				document.getElementById("error_ca_city1").innerHTML = "<strong>Pick-Up City</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_ca_city1").innerHTML = "<strong>Pick-Up City</strong>";
			}
			
			// error_ca_date1
			if(document.search_form.ca_date1.value == '' || document.search_form.ca_date1.value == document.search_form.default_ca_date1.value)  {
				errors++;
				document.search_form.ca_date1.value = document.search_form.default_ca_date1.value;
				document.getElementById("error_ca_date1").innerHTML = "<strong>Pick-Up Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_ca_date1").innerHTML = "<strong>Pick-Up Date</strong>";
			}
						
			// error_ca_date2
			if(document.search_form.ca_date2.value == '' || document.search_form.ca_date2.value == document.search_form.default_ca_date2.value)  {
				errors++;
				document.search_form.ca_date2.value = document.search_form.default_ca_date2.value;
				document.getElementById("error_ca_date2").innerHTML = "<strong>Drop-Off Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_ca_date2").innerHTML = "<strong>Drop-Off Date</strong>";
			}
			
			if(errors == 0) {
				document.getElementById("ca_error_msg").innerHTML = "";
				var query_string = '';
				query_string += '&cause_id=' + document.search_form.cause_id.value;
				query_string += '&searchtype=car';
				query_string += '&city1=' + document.search_form.ca_city1.value;
				query_string += '&date1=' + document.search_form.ca_date1.value;
				query_string += '&time1=' + document.search_form.ca_date1.value;
				query_string += '&date2=' + document.search_form.ca_date2.value;
				query_string += '&time2=' + document.search_form.ca_time2.value;

				src = '/search-results.php?search_query=' + php_urlencode('http://www.bookingwiz.com/xml_redirect.asp?fm_mic=auupprs&fm_datecalc=0&fm_xml=1&fm_xml_popup=1&fm_xml_url=&singleMenu=car' + query_string);	
				post_car = true;

				var search_city1 = document.search_form.ca_city1.value;
				search_city1 = search_city1.substr(1,3);
				search_city1 = search_city1.toUpperCase();
				
				search_info = search_city1 + '<br>' +  document.search_form.ca_date1.value + ' - ' + document.search_form.ca_date1.value;
				
				deal_airport_code1 = getAirportCode(document.search_form.ca_city1.value);
				deal_airport_code2 = getAirportCode(document.search_form.ca_city1.value);
				
				if(deal_airport_code1 == '')  deal_city = php_urlencode(document.search_form.ca_city1.value);
				else deal_city = '';
			} else {
				document.getElementById("ca_error_msg").innerHTML = "<div class=\"searchFormError\" style=\"padding-left:10px;padding-right:10px;padding-top:6px;padding-bottom:0px;\">Please correct the items below in red</div>";
				post_car = false;
				search_info = '';
			}
			
			search_title = 'Car Rental Results';
			break;
			
		case "vacation":

			// error_va_city1
			if(document.search_form.va_city1.value == '' || document.search_form.va_city1.value == document.search_form.default_va_city1.value)  {
				errors++;
				document.search_form.va_city1.value = document.search_form.default_va_city1.value;
				document.getElementById("error_va_city1").innerHTML = "<strong>Departing From</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_va_city1").innerHTML = "<strong>Departing From</strong>";
			}
			
			// error_va_date1
			if(document.search_form.va_date1.value == '' || document.search_form.va_date1.value == document.search_form.default_va_date1.value)  {
				errors++;
				document.search_form.va_date1.value = document.search_form.default_va_date1.value;
				document.getElementById("error_va_date1").innerHTML = "<strong>Departure Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_va_date1").innerHTML = "<strong>Departure Date</strong>";
			}
			
			// error_va_city2
			if(document.search_form.va_city2.value == '' || document.search_form.va_city2.value == document.search_form.default_va_city2.value)  {
				errors++;
				document.search_form.va_city2.value = document.search_form.default_va_city2.value;
				document.getElementById("error_va_city2").innerHTML = "<strong>Traveling To</strong>&nbsp;&nbsp;<span class=\"searchFormError\">** Required Field</span>";
			} else {
				document.getElementById("error_va_city2").innerHTML = "<strong>Traveling To</strong>";
			}
			
			// error_va_date2
			if(document.search_form.va_date2.value == '' || document.search_form.va_date2.value == document.search_form.default_va_date2.value)  {
				errors++;
				document.search_form.va_date2.value = document.search_form.default_va_date2.value;
				document.getElementById("error_va_date2").innerHTML = "<strong>Returning Date</strong>&nbsp;<span class=\"searchFormError\">*</span>";
			} else {
				document.getElementById("error_va_date2").innerHTML = "<strong>Returning Date</strong>";
			}

			if(errors == 0) {
			
				var va_search_type = '';
				if(document.search_form.va_search_type[0].checked == true) {
					va_search_type = document.search_form.va_search_type[0].value;
				} else if(document.search_form.va_search_type[1].checked == true) {
					va_search_type = document.search_form.va_search_type[1].value;
				} else if(document.search_form.va_search_type[2].checked == true) {
					va_search_type = document.search_form.va_search_type[2].value;
				} else if(document.search_form.va_search_type[3].checked == true) {
					va_search_type = document.search_form.va_search_type[3].value;
				}

				document.getElementById("va_error_msg").innerHTML = "";
				var query_string = '';
				query_string += '&cause_id=' + document.search_form.cause_id.value;
				query_string += '&searchtype=' + va_search_type;
				query_string += '&city1=' + document.search_form.va_city1.value;
				query_string += '&date1=' + document.search_form.va_date1.value;
				query_string += '&city2=' + document.search_form.va_city2.value;
				query_string += '&date2=' + document.search_form.va_date2.value;
				query_string += '&adults=' + document.search_form.va_adults.value;
				query_string += '&children=' + document.search_form.va_children.value;
				
				src = '/search-results.php?search_query=' + php_urlencode('http://www.bookingwiz.com/xml_redirect.asp?fm_mic=auupprs&fm_datecalc=0&fm_xml=1&fm_xml_popup=1&fm_xml_url=&singleMenu=' + va_search_type + query_string);
				post_vacation = true;
				
				var search_city1 = document.search_form.va_city1.value;
				search_city1 = search_city1.substr(1,3);
				search_city1 = search_city1.toUpperCase();
				
				var search_city2 = document.search_form.va_city2.value;
				search_city2 = search_city2.substr(1,3);
				search_city2 = search_city2.toUpperCase();

				search_info = search_city1 + ' to ' + search_city2 + '<br>' + document.search_form.va_date1.value + ' - ' + document.search_form.va_date2.value;
				
				deal_airport_code1 = getAirportCode(document.search_form.va_city1.value);
				deal_airport_code2 = getAirportCode(document.search_form.va_city2.value);
				deal_city = '';
			} else {
				document.getElementById("va_error_msg").innerHTML = "<div class=\"searchFormError\" style=\"padding-left:10px;padding-right:10px;padding-top:6px;padding-bottom:0px;\">Please correct the items below in red</div>";
				post_vacation = false;
				search_info = '';
			}
			
			search_title = 'Packages Results';
			break;
		}	
	
		if(document.search_form.cause_id.value == '') {
		
			var search_index = 0;
			var i = 0;
			do {
				search_index = Math.floor(Math.random() * document.choose_a_cause.cause_id.options.length - 1) + 1;
				if(i > 2) break;
				i++;
			} while(search_index == 0 || search_index >= document.choose_a_cause.cause_id.options.length - 1)
			
			document.choose_a_cause.cause_id.selectedIndex = search_index;
			document.search_form.cause_id.value = document.choose_a_cause.cause_id.options[search_index].value;
			currentSearchStep();
		}
	
		var query = '';
		for(i=0;i < document.search_form.elements.length; i++) {
			
			if(document.search_form.elements[i].name == 'current_src' || document.search_form.elements[i].name == 'default_src' || document.search_form.elements[i].name == 'default_fl_city1' || document.search_form.elements[i].name == 'default_fl_city2' || document.search_form.elements[i].name == 'default_fl_date1' || document.search_form.elements[i].name == 'default_fl_date2' || document.search_form.elements[i].name == 'default_ho_city1' || document.search_form.elements[i].name == 'default_ho_date1' || document.search_form.elements[i].name == 'default_ho_date2' || document.search_form.elements[i].name == 'default_ca_city1' || document.search_form.elements[i].name == 'default_ca_date1' || document.search_form.elements[i].name == 'default_ca_date2' || document.search_form.elements[i].name == 'fl_city1_code' || document.search_form.elements[i].name == 'fl_city2_code' || document.search_form.elements[i].name == 'ho_city1_code' || document.search_form.elements[i].name == 'ca_city1_code') {
				query += '';
			} else {
				if(document.search_form.elements[i].type == "radio" && document.search_form.elements[i].checked) {
					query += '&' + document.search_form.elements[i].name + '=' + document.search_form.elements[i].value;
				} else if(document.search_form.elements[i].type == "checkbox") {
					if(document.search_form.elements[i].checked)  query += '&' + document.search_form.elements[i].name + '=' + document.search_form.elements[i].value;
					else query += '&' + document.search_form.elements[i].name + '=';
				} else if(document.search_form.elements[i].type != "radio")  {
					
					if(document.search_form.elements[i].value == 'mm/dd/yyyy' || document.search_form.elements[i].value == 'city or airport code')  query += '&' + document.search_form.elements[i].name + '=';
					else  query += '&' + document.search_form.elements[i].name + '=' + document.search_form.elements[i].value;
				}
			}
		}
		
		// Send Info
		if(src != document.search_form.default_src.value)  post_search_src = '/post-search.php?method=GET' + query;

		document.search_form.current_src.value = src;
			
		if(src != document.search_form.default_src.value) {
			document.getElementById("search_results").innerHTML = '<div align=\"center\" class=\"copyDark\" style=\"padding-top:50px;\"><h2>Searching...</h2></div>';
			document.getElementById("dealsMiddle").innerHTML = '<div align=\"center\" style=\"padding-top:100px;\"><h1>Loading Deals...</h1></div>';
			ajaxFunction("GET", src, 'search_results'); 
			currentSearchStep();
			showDeals();
		}
}

function showDeals(airport_code) {
	ajaxFunction("GET", '/get-deals.php?airport_code1=' + deal_airport_code1 + '&airport_code2=' + deal_airport_code2 + '&city=' + deal_city, 'dealsMiddle');
}

function getAirportCode(airport_code_str) {

	var airport = '';
	
	if(airport_code_str.charAt(0) == '(') {
		airport = airport_code_str.substr(1,3);
		return airport;
	} else {
		return '';
	}
}

function runTrackingScript(tracking_query) {
	ajaxFunction("GET", post_search_src + tracking_query, null);
}

function fieldFocus(id, code, searchtype) {
	var width = 385;
	if(searchtype == 'cause')  {
		_chars = 1;
		width = 226;
	}
	id.value='';
	clearHelpText(id);
	initSmartBox(id, code, searchtype, 10, width);
}

function ajaxFunction(method, server_script, element_id) {
	var xmlhttp;
	if(window.XMLHttpRequest){
  	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp=new XMLHttpRequest();
  } else if (window.ActiveXObject) {
  	// code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } else { 
		alert("Your browser does not support XMLHTTP!");
	} xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
			switch(element_id) {
				case 'search_results':
					
					var search_results = xmlhttp.responseText;
					if(search_results.charAt(0) != '*') {
						if(document.search_form.default_src.value == '/donation-causes.html') {
							if(document.search_form.current_src.value != document.search_form.default_src.value) {
								document.getElementById("search_title").innerHTML = "<h1 class=\"searchResults\">" + search_title + "</h1>";
							} else {
								document.getElementById("box_title").innerHTML = "<h1 class=\"searchResults\">" + search_title + "</h1>";
								document.getElementById("search_results").innerHTML = '<div align=\"center\" class=\"copyDark\" style=\"padding-top:130px;\"><h2>Please enter search<br>parameters</h2></div>';
							}
						} else if(document.search_form.default_src.value == '/featured-cause.html?cause_id=' + document.search_form.cause_id.value) {
							document.getElementById("search_title").innerHTML = "<h1 class=\"searchResults\">" + search_title + "</h1>";
						}
						
						if(document.search_form.cause_name.value != "")  document.getElementById("search_results_charity").innerHTML = "Your Cause:&nbsp;&nbsp;" + document.search_form.cause_name.value + "";
						else document.getElementById("search_results_charity").innerHTML = "Your Cause:&nbsp;&nbsp;" + document.choose_a_cause.cause_id.options[document.choose_a_cause.cause_id.selectedIndex].text + "";
						
						document.getElementById("search_results_divider").innerHTML = "<img src=\"/images/donationtravel/box-2-divider.gif\" width=\"221\" height=\"1\" border=\"0\">";
						document.getElementById("search_results_info").innerHTML = search_info;
						document.getElementById("search_results").innerHTML = search_results;
					} else {
						document.getElementById("search_results").innerHTML = '<div align=\"center\" style=\"padding-top:0px;\"><h1>Oops!</h1><div align=\"center\" style=\"padding-top:15px;width:200px;\">We were unable to find any results for your search.<br><br>Please check your trip information and try again.</div></div>';
						document.getElementById("search_title").innerHTML = '&nbsp;';
						document.getElementById("search_results_charity").innerHTML = '&nbsp;';
						document.getElementById("search_results_divider").innerHTML = '&nbsp;';
						document.getElementById("search_results_info").innerHTML = '&nbsp;';
					}
					break;
					
				case 'dealsMiddle':
					document.getElementById("dealsMiddle").innerHTML = xmlhttp.responseText;
					break;
			}
  	}
	}
	xmlhttp.open(method, server_script, true);
	xmlhttp.send(null);
}

function groupBooking() {
	/*
	if(document.search_form.ho_group.checked == true) {
		group_booking_off.style.visibility = 'hidden';
		group_booking_off.style.display = 'none';
		group_booking_on.style.visibility = 'visible';
		group_booking_on.style.display = '';
		document.search_form.ho_rooms.value = document.search_form.ho_rooms_group.value;
	} else {
	*/
		group_booking_off.style.visibility = 'visible';
		group_booking_off.style.display = '';
		group_booking_on.style.visibility = 'hidden';
		group_booking_on.style.display = 'none';
		document.search_form.ho_rooms.value = document.search_form.ho_rooms_no_group.value;
	//}
}

function roundTrip() {

	if(document.search_form.fl_flighttype[0].checked == true) {
		return_date.style.visibility = 'visible';
		return_date_calendar.style.visibility = 'visible';
	} else {
		return_date.style.visibility = 'hidden';
		return_date_calendar.style.visibility = 'hidden';
	}
}

function VacationHotelRooms() {
	if(document.search_form.va_search_type[0].checked == true) {
		va_hotel_rooms.style.visibility = 'visible';
	} else if(document.search_form.va_search_type[1].checked == true) {
		va_hotel_rooms.style.visibility = 'visible';
	} else {
		va_hotel_rooms.style.visibility = 'hidden';
	}
}

function currentSearchStep() {
	
	//if(document.choose_a_cause.cause_id.value == '**')  document.location.href = '/contact-us/index.html?subject=Add+My+Cause';
	var search_step = 'one';
	
	if(document.search_form.cause_id.value != "undefined" && document.search_form.cause_id.value > 0) search_step = 'two';
	
	switch(document.search_form.searchtype.value) {
		case "air":
			if(post_flights == true)  search_step = 'three';
			break;
			
		case "hotel":
			if(post_hotel == true)  search_step = 'three';
			break; 
			
		case "car":
			if(post_car == true)  search_step = 'three';
			break;
			
		case "vacation":
			if(post_vacation == true)  search_step = 'three';
			break;
	}


	switch(search_step) {
		case "one":
			document.getElementById("leftColumn").style.background = "url(/images/donationtravelV3/left-column-background-over.png)";
			document.getElementById("leftColumn").style.backgroundRepeat = "no-repeat";
			document.getElementById("stepOne").style.background = "url(/images/donationtravelV3/1-yellow.png)";
			document.getElementById("stepOne").style.backgroundRepeat = "no-repeat";
			document.getElementById("middleColumn").style.background = "url(/images/donationtravelV3/middle-column-background.png)";
			document.getElementById("stepTwo").style.background = "url(/images/donationtravelV3/2-gray.png)";
			document.getElementById("stepTwo").style.backgroundRepeat = "no-repeat";
			document.getElementById("rightColumn").style.background = "url(/images/donationtravelV3/right-column-background.png)";
			document.getElementById("stepThree").style.background = "url(/images/donationtravelV3/3-gray.png)";
			document.getElementById("stepThree").style.backgroundRepeat = "no-repeat";
			break;
			
		case "two":
			document.getElementById("leftColumn").style.background = "url(/images/donationtravelV3/left-column-background.png)";
			document.getElementById("leftColumn").style.backgroundRepeat = "no-repeat";
			document.getElementById("stepOne").style.background = "url(/images/donationtravelV3/1-gray.png)";
			document.getElementById("stepOne").style.backgroundRepeat = "no-repeat";
			document.getElementById("middleColumn").style.background = "url(/images/donationtravelV3/middle-column-background-over.png)";
			document.getElementById("stepTwo").style.background = "url(/images/donationtravelV3/2-yellow.png)";
			document.getElementById("stepTwo").style.backgroundRepeat = "no-repeat";
			document.getElementById("rightColumn").style.background = "url(/images/donationtravelV3/right-column-background.png)";
			document.getElementById("stepThree").style.background = "url(/images/donationtravelV3/3-gray.png)";
			document.getElementById("stepThree").style.backgroundRepeat = "no-repeat";
			break;
			
		case "three":
			document.getElementById("leftColumn").style.background = "url(/images/donationtravelV3/left-column-background.png)";
			document.getElementById("leftColumn").style.backgroundRepeat = "no-repeat";
			document.getElementById("stepOne").style.background = "url(/images/donationtravelV3/1-gray.png)";
			document.getElementById("stepOne").style.backgroundRepeat = "no-repeat";
			document.getElementById("middleColumn").style.background = "url(/images/donationtravelV3/middle-column-background.png)";
			document.getElementById("stepTwo").style.background = "url(/images/donationtravelV3/2-gray.png)";
			document.getElementById("stepTwo").style.backgroundRepeat = "no-repeat";
			document.getElementById("rightColumn").style.background = "url(/images/donationtravelV3/right-column-background-over.png)";
			document.getElementById("stepThree").style.background = "url(/images/donationtravelV3/3-yellow.png)";
			document.getElementById("stepThree").style.backgroundRepeat = "no-repeat";
			break;
	}
}


function php_urlencode(str) {
	
	str = escape(str);
	return str.replace(/[*+\/@]|%20/g,
		function (s) {
			switch (s) {
				case "*": s = "%2A"; break;
				case "+": s = "%2B"; break;
				case "/": s = "%2F"; break;
				case "@": s = "%40"; break;
				case "%20": s = "+"; break;
			}
			return s;
		}
	);
}