var fw_currentScreen = 1;
var contactDirect = false;
var contactProceed = false;
var checkedDirect = Array();
var checkedProceed = Array();
var numAirlinesChecked = 0;

var fw_main_change_type = '';

var showingFlights = false;
var showingHotels = false;
var showingCars = false;

var num_fw_fb = 2;
var num_fw_hc = 2;

var flightsWildcard = false;

var fw_fb_from = Array("", "");
var fw_fb_to = Array("", "");
var fw_fb_date = Array("dd/mm/yyyy", "dd/mm/yyyy");
var fw_fb_airline = Array("", "");
var fw_fb_time = Array("", "");
var fw_fb_time_ampm = Array("am", "am");
var fw_fb_type = Array("current", "new");

var fw_hc_city = Array("", "");
var fw_hc_hotel = Array("", "");
var fw_hc_datein = Array("dd/mm/yyyy", "dd/mm/yyyy");
var fw_hc_dateout = Array("dd/mm/yyyy", "dd/mm/yyyy");
var fw_hc_time = Array("", "");
var fw_hc_time_ampm = Array("am", "am");
var fw_hc_type = Array("hotel", "car");
var fw_hc_control = Array("", "");

function fw_super_populate_flights()
{
	num_fw_fb = 2;
	fw_fb_from = Array("", "");
	fw_fb_to = Array("", "");
	fw_fb_date = Array("dd/mm/yyyy", "dd/mm/yyyy");
	fw_fb_airline = Array("", "");
	fw_fb_time = Array("", "");
	fw_fb_time_ampm = Array("am", "am");
	fw_fb_type = Array("current", "new");
	
	for(var i = 1; i < numAirlinesChecked && (num_fw_fb - 1) <= numAirlinesChecked; i++)
	{
		fw_fb_from[num_fw_fb] = "";
		fw_fb_date[num_fw_fb] = "dd/mm/yyyy";
		fw_fb_airline[num_fw_fb] = "";
		fw_fb_to[num_fw_fb] = "";
		fw_fb_time[num_fw_fb] = "";
		fw_fb_time_ampm[num_fw_fb] = "am";
		fw_fb_type[num_fw_fb] = "new";
		num_fw_fb++;
	}

	var currentPointer = 0;
	for(var i = 0; i < num_fw_fb; i++)
	{
		if(fw_fb_type[i] == "new")
		{
			fw_fb_airline[i] = checkedProceed[currentPointer++];
		}
	}
}

function fw_validate_form(vv)
{
	if(fw_fb_from[vv] == "")
	{alert("Please provide a departure city for all flights"); return false;}
	if(fw_fb_to[vv] == "")
	{alert("Please provide a destination city for all flights"); return false;}
	if(fw_fb_date[vv] == "" || fw_fb_date[vv] == "dd/mm/yyyy")
	{alert("Please provide a date for all flights"); return false;}
	if(fw_fb_airline[vv] == "")
	{alert("Please provide an airline for all flights"); return false;}
	if(fw_fb_time[vv] == "")
	{alert("Please provide a time for all flights"); return false;}
	return true;
}

function fw_validate_form_hc(vv)
{
	
	if(fw_hc_city[vv] == "")
	{alert("Please provide a city for all " + fw_hc_type[vv] + " bookings"); return false;}
	
	if(fw_hc_hotel[vv] == "" && fw_hc_type[vv] == "car")
	{alert("Please provide a company for all " + fw_hc_type[vv] + " bookings"); return false;}
	
	if(fw_hc_hotel[vv] == "" && fw_hc_type[vv] == "hotel")
	{alert("Please provide a hotel for all " + fw_hc_type[vv] + " bookings"); return false;}
	
	if(fw_hc_datein[vv] == "" || fw_hc_datein[vv] == "dd/mm/yyyy")
	{alert("Please provide a date for all " + fw_hc_type[vv] + " bookings"); return false;}
	
	if(fw_hc_dateout[vv] == "" || fw_hc_dateout[vv] == "dd/mm/yyyy")
	{alert("Please provide a date for all " + fw_hc_type[vv] + " bookings"); return false;}
	
	if(fw_hc_control[vv] == "")
	{alert("Please choose to change/cancel action for each " + fw_hc_type[vv] + " booking"); return false;}

	
	return true;
}

function fw_changeToScreen(vv)
{
	if(vv == "fromConfirm")
	{
		vv = "listflights";
		if(showingHotels || showingCars)
		{
			vv = "listhotelcars";
			$("#fw_current_hotels").html(fw_hc_draw("hotel"));
			$("#fw_current_cars").html(fw_hc_draw("car"));
			fw_date_annoy();
		}
	}
	if(vv == "listflights")
	{
		$("#fw_current_flights").html(fw_draw("current"));
		$("#fw_new_flights").html(fw_draw("new"));
		fw_date_annoy();
	}

	$('#screen-' + fw_currentScreen).fadeOut(function(){$('#screen-' + vv).fadeIn(function(){if(jQuery.browser.msie){this.style.removeAttribute('filter');}});fw_currentScreen = vv;if(jQuery.browser.msie){this.style.removeAttribute('filter');}});	

	if(vv == "1")
		$('#fw_top_tip').fadeIn();
	else
		$('#fw_top_tip').fadeOut();
	
}

function fw_validate(vv)
{
	switch(vv)
	{
		case 1:
				
			contactDirect = false;
			contactProceed = false;
			flightsWildcard = false;
			checkedDirect = Array();
			checkedProceed = Array();
			numAirlinesChecked = 0;
			
			showingFlights = false;
			showingHotels = false;
			showingCars = false;
			
			
			if(!($("input[name=fw_change_flights]:checked").val()||$("input[name=fw_change_hotels]:checked").val()||$("input[name=fw_change_cars]:checked").val()))
			{
				alert("Please choose which booking you wish to change.\nFlights, Hotel Stay or Car Rental.");
				break;
			}
			if(!($("input[name=fw_change_flights]:checked").val()||$("input[name=fw_change_hotels]:checked").val()) && $("input[name=fw_change_cars]:checked").val())
			{
				fw_changeToScreen("contactdirect-cars");
				break;
			}
			
			var JQTT = false;
			var NotJQTT = false;
			
			if($("input[name=fw_change_flights]:checked").val())
			{
				showingFlights = true;

				$("#fw_airline_qantas:checked").each(function(){contactProceed = true; NotJQTT = true; checkedProceed[checkedProceed.length] = "Qantas"; numAirlinesChecked++; });

				$("#fw_airline_jetstar:checked").each(function(){contactDirect = true; JQTT = true;  checkedDirect[checkedDirect.length] = "Jetstar"; checkedProceed[checkedProceed.length] = "Jetstar"; numAirlinesChecked++; });
				$("#fw_airline_virgin:checked").each(function(){contactDirect = true; NotJQTT=true; checkedDirect[checkedDirect.length] = "Virgin Australia"; checkedProceed[checkedProceed.length] = "Virgin Australia"; numAirlinesChecked++; });
				$("#fw_airline_tiger:checked").each(function(){contactDirect = true; JQTT=true; checkedDirect[checkedDirect.length] = "Tiger Airways"; checkedProceed[checkedProceed.length] = "Tiger Airways"; numAirlinesChecked++; });
				$("#fw_airline_airasia:checked").each(function(){contactDirect = true; JQTT=true; checkedDirect[checkedDirect.length] = "Air Asia"; checkedProceed[checkedProceed.length] = "Air Asia"; numAirlinesChecked++; });
				$("#fw_airline_strat:checked").each(function(){contactDirect = true; JQTT=true; checkedDirect[checkedDirect.length] = "Strategic Airlines"; checkedProceed[checkedProceed.length] = "Strategic Airlines"; numAirlinesChecked++; });

				$("#fw_airline_rex:checked").each(function(){contactProceed = true; NotJQTT = true; checkedProceed[checkedProceed.length] = "Rex"; numAirlinesChecked++; });
				$("#fw_airline_other:checked").each(function(){contactProceed = true; NotJQTT = true; checkedProceed[checkedProceed.length] = "other"; numAirlinesChecked++; flightsWildcard = true;});

				if(contactDirect == false && contactProceed == false)
				{
					alert("Please choose at least one airline");
					break;
				}
			}

			if(contactDirect && numAirlinesChecked == 1 && !($("input[name=fw_change_hotels]:checked").val()||$("input[name=fw_change_cars]:checked").val()))
			{
				var rtn = checkedDirect[0];
				
				
				if(rtn == "Jetstar")
					rtn += " - <b>131 538</b> (+61 3 8341 4901 from overseas)";
				else if(rtn == "Virgin Australia")
					rtn += " - <b>136 789</b> (+61 7 3295 2296 from overseas) <br /> If you wish to book a flight using a credit with Virgin Australia, you need to contact Virgin Australia directly";
				else if(rtn == "Tiger Airways")
					rtn += " - <b>please visit the Tiger Airways' website</b>";
				else if(rtn == "Strategic Airlines")
					rtn += " - <b>135 320</b> (+61 7 3169 3980  from overseas)";
				else if(rtn == "Air Asia")
	     rtn += " - <b>please visit the Air Asia website</b>";
				
				

				$("#fw_please_contact").html(rtn);
				
				
				
				fw_changeToScreen("contactdirect");
				break;
			}
			
			var rtn = "";
			
			
			/* Checks for Flights */
			if($("input[name=fw_change_flights]:checked").val())
			{
				for(var i = 0; i < checkedProceed.length; i++)
				{
					if(i > 0 && (i != checkedProceed.length - 1))
						rtn += ", ";
					else if(i > 0 && (i == checkedProceed.length - 1))
						rtn += " and ";
					rtn += "" + checkedProceed[i] + "";
				}
				rtn += " flight";
				if(checkedProceed.length > 1)
					rtn += "s";
			}
				
			/* Checks for Hotels */
			
			if($("input[name=fw_change_hotels]:checked").val())
			{
				showingHotels = true;
				if(rtn != "" && $("input[name=fw_change_cars]:checked").val())
					rtn += ", "
				else if(rtn != "")
					rtn += " and ";
				rtn += "hotel stay";
				
				if(!showingFlights)
					$(".fw_book_replacement").hide();
				else
					$(".fw_book_replacement").show();
			}
			else
			{
				$(".fw_book_replacement").show();
			}

			/* Checks for Cars */
			if($("input[name=fw_change_cars]:checked").val())
			{
				showingCars = true;
				rtn += " and car rental";
			}			
			
			$("#fw-choosetype-changedates-help").html("Select this option to change your " + rtn + " to a different date or time.");
			$("#fw-choosetype-canceltrip-help").html("Select this option to cancel your " + rtn + ".");
			$(".fw-travelsnippet").html(rtn);
			
			//Implementing VV2 #2
			if(showingFlights)
			{
				if(JQTT && !NotJQTT)
				{
					$(".fw_book_replacement").hide();
				}
				else
					$(".fw_book_replacement").show();
			}
			
			//Implementing VV2 #3
			if($("input[name=fw_airline_virgin]:checked").val())
			{
				$("#fw_rebook_text").html("Select this option to book a replacement flight, using a credit from a previously cancelled trip. <b>If you wish to book a flight using a credit with Virgin Australia (including Pacific Blue or Polynesian Blue), you need to contact Virgin Australia directly</b>");
			}
			else
			{
				$("#fw_rebook_text").html("Select this option to book a replacement flight, using a credit from a previously cancelled trip.");
			}
			
			fw_changeToScreen("choosetype");
			break;
		
		case 'choosetype':
		
			fw_main_change_type = '';
		
			if(!$("input[name=fw_choose_type]:checked").val())
			{
				alert("Please select what type of change you wish to make.");
				break;
			}
			fw_main_change_type= $("input[name=fw_choose_type]:checked").val();
			
			if(fw_main_change_type == "book_replacement" && (showingHotels || showingCars))
			{
				var carHotelString = "hotel";
				if(!showingHotels)
					carHotelString = "car";
				else if(showingCars)
					carHotelString = "hotel/car";
				if(confirm("Credits are not applicable for " + carHotelString + " bookings, only flights. Are you sure you wish to proceed with only flight changes?"))
				{
					if(!showingFlights)
					{
						fw_changeToScreen("1");
						break;
					}
					showingHotels = false;
					showingCars = false;
					
					$('#fw_change_hotels').attr('checked', false);
					$('#fw_change_cars').attr('checked', false);

				}
				else
				{
					break;
				}
			}
			
			fw_changeToScreen("whenyoufly");
			
			
			if(fw_main_change_type == "change_dates")
			{
				$(".fw_typeSpiel").html("changing");
				fw_super_populate_flights();
			}
			if(fw_main_change_type == "book_replacement")
				$(".fw_typeSpiel").html("travelling");
			if(fw_main_change_type == "cancel_trip")
			{
				$(".fw_typeSpiel").html("cancelling");
				fw_super_populate_flights();
			}

			break;
			
		case 'whenyoufly':
		
			if(!$("input[name=fw_when_travel]:checked").val())
			{
				alert("Please select when you wish to travel.");
				break;
			}
			else if($("input[name=fw_when_travel]:checked").val() == 'now')
			{
				/* Must contact them NOW! */
				
				if(!flightsWildcard)
				{
					$(".fw-call-other").hide();
					for(var i = 0; i < checkedProceed.length; i++)
					{
						var currentAirline = checkedProceed[i];
						switch(currentAirline)
						{
							case "Qantas": $(".fw-call-qantas").show(); break;
							case "Jetstar": $(".fw-call-jetstar").show(); break;
							case "Virgin Australia": $(".fw-call-virgin-blue").show(); break;
							case "Tiger Airways": $(".fw-call-tiger-airways").show(); break;
							case "Rex": $(".fw-call-rex").show(); break;
						}
					}
				}
				else
				{
					$(".fw-call-other").show();
				}
				if(showingCars)
					$(".fw-call-cars").show();
				else
					$(".fw-call-cars").hide();
				if(showingHotels)
					$(".fw-call-hotels").show();			
				else
					$(".fw-call-hotels").hide();
				
				fw_changeToScreen("iflynow");
				break;
			}
			
			
			/* DO ALL MAJOR CHANGES NOW!!! */
			
			if(showingFlights)
				$(".fw_show_if_flights").show();
			else
				$(".fw_show_if_flights").hide();
			if(showingHotels || showingCars)
				$("#fw_show_if_hotelscars").show();
			else
				$("#fw_show_if_hotelscars").hide();
				
			if(showingHotels && showingCars)
				$(".fw_listflights_changecarhotel").html("hotel stay and car rental");
			else if(showingHotels)
				$(".fw_listflights_changecarhotel").html("hotel stay");
			else if(showingCars)
				$(".fw_listflights_changecarhotel").html("car rental");
				
			if(showingHotels) $("#fw_show_if_hotel").show(); else $("#fw_show_if_hotel").hide();
			if(showingCars) $("#fw_show_if_car").show(); else $("#fw_show_if_car").hide();
							
			
			fw_changeToScreen("details");
		
			break;	
			
	
		case 'details' :
		
			if(true) //Remove after testing
			{
				if($("#fw_name").val() == "")
				{
					alert("Please provide a name"); break;
				}
				if($("#fw_email").val() == "")
				{
					alert("Please provide an email address"); break;
				}
				if(!isValidEmailAddress($("#fw_email").val()))
				{
					alert("Please provide a valid email address"); break;
				}
				if($("#fw_phone_day").val() == "" && $("#fw_phone_night").val() == "" && $("#fw_mobile").val() == "")
				{
					alert("Please provide a phone number"); break;
				}
				
				
				if($("#fw_allpasschange").val() == "NO" && $("#fw_passtochange").val() == "")
				{
					alert("Please provide passenger details"); break;
				}
			}
			if(showingFlights)
			{
				if ($("input[name=fw_change_flights_all]:checked").val() ) {

					if($("input[name=fw_change_flights_all]:checked").val() == "ALL" || fw_main_change_type != "change_dates")
					{
						$("#fw_current_flights").css("height", "0px");
						$("#fw_new_flights").css("height", "350px");
						$("#fw_current_flights_container").hide();
						$("#fw_current_flights_container_num").show();
					}
					else
					{
						$("#fw_current_flights").css("height", "160px");
						$("#fw_new_flights").css("height", "160px");

						$("#fw_current_flights_container").show();
						$("#fw_current_flights_container_num").hide();
					}
					
					if (!$("input[name=fw_intldom]:checked").val() ) 
					{	
						alert("Please choose where your trip is to."); break;
					}					
					
					if(fw_main_change_type == "change_dates")
						$(".fw_newFlightsSpiel").html("Please list the new flights you would like to take?");
					if(fw_main_change_type == "book_replacement")
						$(".fw_newFlightsSpiel").html("What flights would you like to book?");
					if(fw_main_change_type == "cancel_trip")
						$(".fw_newFlightsSpiel").html("What flights would you like to cancel?");					

					

					fw_changeToScreen("listflights");
					break;
				}
				alert("Please choose if you are changing all flights.");
				break;
			}
			$("#fw_current_hotels").html(fw_hc_draw("hotel"));
			$("#fw_current_cars").html(fw_hc_draw("car"));
			fw_date_annoy();
			fw_changeToScreen("listhotelcars");
			break;
			
		case 'listflights' :
			fw_save();
			
			
			//Validate all
			if($("input[name=fw_change_flights_all]:checked").val() != "ALL" && fw_main_change_type == "change_dates")
			{
				rtn += '<div class="fw_confirm_box">From: ';
				for(var i = 0; i < num_fw_fb; i++)
				{
					if(fw_fb_type[i] == "current")
					{
						if(!fw_validate_form(i))
							return;
					}
				}
			}
			for(var i = 0; i < num_fw_fb; i++)
			{
				if(fw_fb_type[i] == "new")
				{
					if(!fw_validate_form(i))
							return;
				}
			}
	
			if(showingHotels || showingCars)
			{
				if ($("input[name=fw_change_carhotel]:checked").val() ) {
					if($("input[name=fw_change_carhotel]:checked").val() == "NO")
					{
						$("#fw_current_hotels").html(fw_hc_draw("hotel"));
						$("#fw_current_cars").html(fw_hc_draw("car"));
						fw_date_annoy();
						fw_changeToScreen("listhotelcars");
					}
					else
					{
						fw_confirm();
						fw_changeToScreen("confirmation");
					}
					break;
				}
				else
				{
					if(showingHotels && showingCars)
						alert("Would you like to change your hotel stay and car rental?"); 
					else if(showingHotels)
						alert("Would you like to change your hotel stay?"); 
					else if(showingCars)
						alert("Would you like to change your car rental?"); 
						
					break;
					
				}
			}
			fw_confirm();
			fw_changeToScreen("confirmation");
			break;
			
		case 'listhotelcars' :
			fw_hc_save();
			if(showingHotels)
			{
				//insert validation here
				for(var i = 0; i < num_fw_hc; i++)
				{
					if(fw_hc_type[i] == "hotel")
					{
						if(!fw_validate_form_hc(i))
							return;
					}
				}
			}
			if(showingCars)
			{
				for(var i = 0; i < num_fw_hc; i++)
				{
					if(fw_hc_type[i] == "car")
					{
						if(!fw_validate_form_hc(i))
							return;
					}
				}
			}
			fw_confirm();
			fw_changeToScreen("confirmation");
			
			break;
				
	}
}

function togglePassengerChange()
{
	if($("#fw_allpasschange").val() == "YES")
	{
		$(".fw_passenger_change_td").each(function(){$(this).css("visibility", "hidden");});
	}
	else
	{
		$(".fw_passenger_change_td").each(function(){$(this).css("visibility", "visible");});
	}
}

function fw_draw(type)
{
	var rtn = "<table>";
	var currentCount = 0;
	
	for(var i = 0; i < num_fw_fb; i++)
	{
		if(fw_fb_type[i] == type)
			currentCount++;
	}
	
	for(var i = 0; i < num_fw_fb; i++)
	{
		if(fw_fb_type[i] == type)
		{	
		
			var theId = "fw_flights_date_" + i;
			var theValue = fw_fb_date[i];
			var startingDate = new Date()
			if($("input[name=fw_when_travel]:checked").val() == "soon")
				startingDate.setDate(startingDate.getDate()+1)
			else
				startingDate.setDate(startingDate.getDate()+3)
			if(theValue == "" || theValue == "dd/mm/yyyy")
			{
				theValue = "";
				if(startingDate.getDate() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getDate() + 1) + "/";
				if(startingDate.getMonth() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getMonth() + 1) + "/";
				theValue += (startingDate.getFullYear());
			}

			var selectString = '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_dd" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
				for(var dayi = 1; dayi <= 31; dayi++)
				{
					selectString += "<option value='";
					if(dayi < 10)
						selectString += 0;
					selectString += dayi + "'>" + dayi + "</option>";
				}
			selectString += "</select>";

			var d = new Date();
			var themonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
			var startMonth = d.getMonth();

			selectString += '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_mmyyyy" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
			for(var monthi = 0; monthi < 12; monthi++)
			{
				var theYear = d.getFullYear()
				actualMonth = (startMonth + monthi)%12 + 1;
				if(startMonth + monthi >= 12)
					theYear++;
				selectString += "<option value='";
				if(actualMonth < 10)
					selectString += 0;
				selectString += actualMonth + "/" + theYear + "'>" + themonths[actualMonth - 1] + " " + theYear + "</option>";
			}
			selectString += "</select> <input id='" + theId + "' type='hidden' class='fw_flights_textbox_date' origId='" + theId + "' onChange='updateDateReverse(\"" + theId + "\");' value='" + theValue + "' />";
		
		
		
			rtn += "<tr><td>From</td>";
				rtn += "<td><select name='fw_flights_from_" + i + "' id='fw_flights_from_" + i + "' origvalue='" + fw_fb_from[i] + "' class='fw_flights_dest_select'></select>";
			rtn += "<td>Date</td>";
				rtn += "<td>" + selectString + "</td>";
			rtn += "<td>Airline</td>";
			
			if(numAirlinesChecked == 1 && !flightsWildcard)
			{
				// Hidden field
				rtn += "<td><input type='hidden' name='fw_flights_airline_" + i + "' id='fw_flights_airline_" + i + "' value='" + checkedProceed[0] + "' class='fw_flights_textbox' />" + checkedProceed[0] + "</td>";
			}
			else if(flightsWildcard)
			{
				// Text Input	
				rtn += "<td><input type='text' name='fw_flights_airline_" + i + "' id='fw_flights_airline_" + i + "' value='" + fw_fb_airline[i] + "' class='fw_flights_textbox' /></td>";
			}
			else
			{
				// Select
				rtn += "<td><select name='fw_flights_airline_" + i + "' id='fw_flights_airline_" + i + "' class='fw_flights_textbox'>";
				for(var j = 0; j < numAirlinesChecked; j++)
				{
					rtn += "<option value='" + checkedProceed[j] + "' ";
					if((fw_fb_airline[i] == "" && j == 0) || fw_fb_airline[i] == checkedProceed[j])
						rtn += " selected";
					rtn += ">" + checkedProceed[j] + "</option>";
				}
				rtn += "</select></td>";
			}
				
				checkedProceed
			
			
			rtn += "<td></td></tr><tr><td>To</td>";
				rtn += "<td><input type='text' name='fw_flights_to_" + i + "' id='fw_flights_to_" + i + "' value='" + fw_fb_to[i] + "' class='fw_flights_textbox' /></td>";
			rtn += "<td>Time</td>";
				rtn += "<td><input type='text' name='fw_flights_time_" + i + "' id='fw_flights_time_" + i + "' value='" + fw_fb_time[i] + "' class='fw_flights_textbox_time' /></td>";
				rtn += "<td><select name='fw_flights_time_ampm_" + i + "' id='fw_flights_time_ampm_" + i + "' >";
					rtn += "<option value='am' ";
						if(fw_fb_time_ampm[i] == 'am')
							rtn += ' selected';
					rtn += ">am</option><option value='pm' ";
						if(fw_fb_time_ampm[i] == 'pm')
							rtn += ' selected';
					rtn += ">pm</option>";
				
				rtn +="</select></td>";
				
			rtn += "<td>";
			
			if(currentCount > 1)
				rtn += "<a href='#' onClick='fw_removeFlight(" + i + "); return false'>remove</a>";
			
			rtn += "</td></tr><tr><td colspan='6'>&nbsp;</td></tr>";
		}
	}	
	rtn += "</table><a href='#' onClick='fw_addFlight(\"" + type + "\"); return false'>Add another flight</a>";
	return rtn;
}

function fw_save()
{
	for(var i = 0; i < num_fw_fb; i++)
	{
		fw_fb_from[i] = $("#fw_flights_from_" + i).val(); 
		fw_fb_date[i] = $("#fw_flights_date_" + i).val();
		fw_fb_airline[i] = $("#fw_flights_airline_" + i).val();
		fw_fb_to[i] = $("#fw_flights_to_" + i).val();
		fw_fb_time[i] = $("#fw_flights_time_" + i).val();
		fw_fb_time_ampm[i] = $("#fw_flights_time_ampm_" + i).val();
	}
}


function fw_remove(vv)
{
	fw_fb_from.splice(vv,1);
	fw_fb_date.splice(vv,1);
	fw_fb_airline.splice(vv,1);
	fw_fb_to.splice(vv,1);
	fw_fb_time.splice(vv,1);
	fw_fb_time_ampm.splice(vv,1);
	fw_fb_type.splice(vv,1);
	num_fw_fb--;
}


function fw_drawNow()
{
	$("#fw_current_flights").html(fw_draw("current"));
	$("#fw_new_flights").html(fw_draw("new"));
	fw_date_annoy();
}

function fw_date_annoy()
{
	$(".fw_flights_textbox_date").each(function(){
			$(this).focus(function(){
				if($(this).val() == "dd/mm/yyyy"){
					$(this).val("");
				}
			});
			if($("input[name=fw_when_travel]:checked").val() == "soon")
				$(this).datepicker({minDate: ' +1d', showOn: 'button', buttonImage: 'http://www.webjet.com.au/images/calendar.gif', buttonImageOnly: true, dateFormat: 'dd/mm/yy'});
			else
				$(this).datepicker({minDate: ' +3d', showOn: 'button', buttonImage: 'http://www.webjet.com.au/images/calendar.gif', buttonImageOnly: true, dateFormat: 'dd/mm/yy'});
			updateDateReverse($(this).attr("origId"));
	});
	
	
	
	$(".fw_flights_dest_select").each(function(){
			if($(this).attr("origvalue") != "" && $(this).attr("origvalue").length != 3)
			{
				var tmpValue = $(this).attr("origvalue");
				$(this).parent().html("<input type='text' name='" + $(this).attr("name") + "' id='" + $(this).attr("name") + "' value='" + tmpValue + "' class='fw_flights_textbox' />");
			}
			$(this).html($("#fw_all_city_dropdown_options").html());
			if($(this).attr("origvalue") != "")
				$(this).val($(this).attr("origvalue"));
			$(this).change(function(){
				if($(this).val() == "OTHER")
				{
					$(this).parent().html("<input type='text' name='" + $(this).attr("name") + "' id='" + $(this).attr("name") + "' value='' class='fw_flights_textbox' />");
				}
			});

	});
	
	$('.ui-datepicker-trigger').css("margin-bottom", "-6px");
}

function fw_removeFlight(vv)
{
	var currentType = fw_fb_type[vv];
	fw_save();
	fw_remove(vv);
	fw_drawNow();
}

function fw_addFlight(vv){
	fw_save();
	fw_fb_from[num_fw_fb] = "";
	fw_fb_date[num_fw_fb] = "dd/mm/yyyy";
	fw_fb_airline[num_fw_fb] = "";
	fw_fb_to[num_fw_fb] = "";
	fw_fb_time[num_fw_fb] = "";
	fw_fb_time_ampm[num_fw_fb] = "am";
	fw_fb_type[num_fw_fb] = vv;
	num_fw_fb++;
	fw_drawNow();
}

function fw_hc_draw(type)
{
	var rtn = "<table>";
	var currentCount = 0;
	for(var i = 0; i < num_fw_hc; i++)
	{
		if(fw_hc_type[i] == type)
			currentCount++;
	}
	
	for(var i = 0; i < num_fw_hc; i++)
	{
		if(fw_hc_type[i] == type)
		{
			var CheckIn = "Check-in";
			var CheckOut = "Check-out";
			var Hotel = "Hotel";
			var typestay = "hotel stay";
			if(type == "car")
			{
				CheckIn = "Pick-up";
				CheckOut = "Drop-off";
				Hotel = "Company";
				typestay = "car rental";
			}
			
			rtn += "<tr><td colspan='4'>";
			
			
			var theId = "fw_hc_datein_" + i
			var theValue = fw_hc_datein[i];
			var startingDate = new Date()
			if($("input[name=fw_when_travel]:checked").val() == "soon")
				startingDate.setDate(startingDate.getDate()+1)
			else
				startingDate.setDate(startingDate.getDate()+3)
			if(theValue == "" || theValue == "dd/mm/yyyy")
			{
				theValue = "";
				if(startingDate.getDate() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getDate() + 1) + "/";
				if(startingDate.getMonth() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getMonth() + 1) + "/";
				theValue += (startingDate.getFullYear());
			}

			var selectString = '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_dd" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
				for(var dayi = 1; dayi <= 31; dayi++)
				{
					selectString += "<option value='";
					if(dayi < 10)
						selectString += 0;
					selectString += dayi + "'>" + dayi + "</option>";
				}
			selectString += "</select>";

			var d = new Date();
			var themonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
			var startMonth = d.getMonth();

			selectString += '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_mmyyyy" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
			for(var monthi = 0; monthi < 12; monthi++)
			{
				var theYear = d.getFullYear()
				actualMonth = (startMonth + monthi)%12 + 1;
				if(startMonth + monthi >= 12)
					theYear++;
				selectString += "<option value='";
				if(actualMonth < 10)
					selectString += 0;
				selectString += actualMonth + "/" + theYear + "'>" + themonths[actualMonth - 1] + " " + theYear + "</option>";
			}
			selectString += "</select> <input id='" + theId + "' type='hidden' class='fw_flights_textbox_date' origId='" + theId + "' onChange='updateDateReverse(\"" + theId + "\");' value='" + theValue + "' />";

			
			
							
			if(fw_main_change_type != "cancel_trip")
			{
				rtn += '<input type="radio" name="fw_hc_changecancel_' + i + '" id="fw_hc_changecancel_' + i + '" value="change" ';
				if(fw_hc_control[i] == "change")
					rtn += 'checked';
				rtn += '/> <b>Change</b> - please change my ' + typestay + ' to the following <br />';
				rtn += '<input type="radio" name="fw_hc_changecancel_' + i + '" id="fw_hc_changecancel_' + i + '" value="cancel" ';
				if(fw_hc_control[i] == "cancel")
					rtn += 'checked';
				rtn += '/> <b>Cancel</b> - please cancel the following ' + typestay + ' stay<br />';
			}
			else
			{
				rtn += '<input type="radio" name="fw_hc_changecancel_' + i + '" id="fw_hc_changecancel_' + i + '" value="cancel" ';
						rtn += 'checked';
				rtn += '/> <b>Cancel</b> - please cancel the following ' + typestay + ' stay';
			}
			
			rtn += "</td></tr>";
		
			rtn += "<tr><td>City:</td>";
				rtn += "<td><input type='text' name='fw_hc_city_" + i + "' id='fw_hc_city_" + i + "' value='" + fw_hc_city[i] + "' class='fw_flights_textbox' /></td>";
			rtn += "<td>" + CheckIn + "</td>";
				rtn += "<td>" + selectString + "</td>";
				
			if(type == "car")
			{
				rtn += "<td>Time</td>";
				rtn += "<td><input type='text' name='fw_hc_time_" + i + "' id='fw_hc_time_" + i + "' value='" + fw_hc_time[i] + "' class='fw_flights_textbox_time' /></td>";
				rtn += "<td><select name='fw_hctime_ampm_" + i + "' id='fw_hc_time_ampm_" + i + "' >";
					rtn += "<option value='am' ";
						if(fw_hc_time_ampm[i] == 'am')
							rtn += ' selected';
					rtn += ">am</option><option value='pm' ";
						if(fw_hc_time_ampm[i] == 'pm')
							rtn += ' selected';
					rtn += ">pm</option>";
				
				rtn +="</select></td></tr>";
			}
			
				
			rtn += "<tr><td>" + Hotel + "</td>";
				rtn += "<td><input type='text' name='fw_hc_hotel_" + i + "' id='fw_hc_hotel_" + i + "' value='" + fw_hc_hotel[i] + "' class='fw_flights_textbox' /></td>";



			theId = "fw_hc_dateout_" + i
			theValue = fw_hc_dateout[i];
			startingDate = new Date()
			if($("input[name=fw_when_travel]:checked").val() == "soon")
				startingDate.setDate(startingDate.getDate()+1)
			else
				startingDate.setDate(startingDate.getDate()+3)
			if(theValue == "" || theValue == "dd/mm/yyyy")
			{
				theValue = "";
				if(startingDate.getDate() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getDate() + 1) + "/";
				if(startingDate.getMonth() + 1 < 10)
					theValue += "0";
				theValue += (startingDate.getMonth() + 1) + "/";
				theValue += (startingDate.getFullYear());
			}

			selectString = '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_dd" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
				for(var dayi = 1; dayi <= 31; dayi++)
				{
					selectString += "<option value='";
					if(dayi < 10)
						selectString += 0;
					selectString += dayi + "'>" + dayi + "</option>";
				}
			selectString += "</select>";

			d = new Date();
			themonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
			startMonth = d.getMonth();

			selectString += '<select style="padding: 2px 3px; font-size: 11px; margin-top: -3px" id="' + theId + '_mmyyyy" name="' + theId + '" onChange="updateDate(\'' + theId + '\');"> ';
			for(var monthi = 0; monthi < 12; monthi++)
			{
				var theYear = d.getFullYear()
				actualMonth = (startMonth + monthi)%12 + 1;
				if(startMonth + monthi >= 12)
					theYear++;
				selectString += "<option value='";
				if(actualMonth < 10)
					selectString += 0;
				selectString += actualMonth + "/" + theYear + "'>" + themonths[actualMonth - 1] + " " + theYear + "</option>";
			}
			selectString += "</select> <input id='" + theId + "' type='hidden' class='fw_flights_textbox_date' origId='" + theId + "' onChange='updateDateReverse(\"" + theId + "\");' value='" + theValue + "' />";


			rtn += "<td>" + CheckOut + "</td>";
				rtn += "<td>" + selectString + "</td>";
				
			rtn += "<td>";
			
			if(currentCount > 1)
				rtn += "<a href='#' onClick='fw_removeHC(" + i + "); return false'>remove</a>";
			
			rtn += "</td></tr><tr><td colspan='6'>&nbsp;</td></tr>";
		}
	}	
	rtn += "</table><a href='#' onClick='fw_hc_add(\"" + type + "\"); return false'>Add another " + typestay + "</a>";
	return rtn;
}


function fw_confirm()
{
	$("#fw_confirm_name").html("");
	$("#fw_confirm_email").html("");
	$("#fw_confirm_number").html("");
	$("#fw_confirm_mobilenumber").html("");
	$("#fw_confirm_bookingnumber").html("");
	$("#fw_confirm_passengers").html("");
	
	$("#fw_confirm_changedetails").html("");	
	
	$("#fw_confirm_flights").html("");
	$("#fw_confirm_hotels").html("");
	$("#fw_confirm_cars").html("");
	
	$("#fw_confirm_name").html($("#fw_name").val());
	$("#fw_confirm_email").html($("#fw_email").val());
	var phoneGiven = "";
	if($("#fw_phone_day").val() != "")
		phoneGiven = $("#fw_phone_day").val() + " (day)";
	if($("#fw_phone_night").val() != "")
	{
		if(phoneGiven != "")
			phoneGiven += "<br>";
		phoneGiven += $("#fw_phone_night").val() + " (night)";
	}
	if(phoneGiven == "")
		phoneGiven = "<i>Not Provided - use mobile</i>";
	$("#fw_confirm_number").html(phoneGiven);

		
	$("#fw_confirm_mobilenumber").html($("#fw_mobile").val());
	$("#fw_confirm_bookingnumber").html($("#fw_booking_number").val());
	$("#fw_confirm_passengers").html($("#fw_passtochange").val());
	if($("#fw_allpasschange").val() == "YES")
		$("#fw_confirm_passengers").html("All passengers");
		
	var rtn = "";	
	if(showingFlights)
	{
		if($("input[name=fw_change_flights_all]:checked").val() == "ALL")
			rtn += "All flights<Br />";
		else
			rtn += "Selected flights<Br />";
	}
	if(showingHotels || showingCars)
	{
		var hc_string = ""; 
		if(showingHotels && showingCars)
			hc_string = "Hotel stay<br>Car rental";
		else if(showingHotels)
			hc_string = "Hotel stay";
		else if(showingCars)
			hc_string = "Car rental";
		rtn += hc_string;
	}
	$("#fw_confirm_changedetails").html(rtn);
	
	var acfc = '<span>Domestic flights:</span> (Typically $100-$200 per person)';
	$("#fw-charge-cap").removeOption(/./);
		var myOptions = {
			"100" : "AUD $100 ",
			"150" : "AUD $150 ",
			"200" : "AUD $200 "
		};
		if(showingFlights && $("input[name=fw_intldom]:checked").val() == "international")
	 {
		  acfc = '<span>International flights:</span> (Typically $300-$500 per person)';
		  myOptions = {
 	   "300" : "AUD $300 ",
 	   "400" : "AUD $400 ",
 	   "500" : "AUD $500 "
	   };
	 }
	$("#fw_charge_cap_text").html(acfc);
	$("#fw-charge-cap").addOption(myOptions, false);
	
	
	
	if(fw_main_change_type == "cancel_trip" || showingFlights==false)
	{
		$("#fw_fee_cap").hide();
	}
	else
	{
		$("#fw_fee_cap").show();
	}

	
	rtn = "<h3>Flights</h3>";
	if(showingFlights)
	{
		if($("input[name=fw_change_flights_all]:checked").val() != "ALL" && fw_main_change_type == "change_dates")
		{
			rtn += '<div class="fw_confirm_box">From: ';
			for(var i = 0; i < num_fw_fb; i++)
			{
				if(fw_fb_type[i] == "current")
				{
					rtn += '<div class="fw_confirm_box_sub">' + fw_fb_from[i] + ' to ' + fw_fb_to[i]  + '<br>' + fw_fb_date[i] + ' at ' + fw_fb_time[i] + ' ' + fw_fb_time_ampm[i] + '<br>Flying ' + fw_fb_airline[i] + '</div>';
				}
			}

			rtn += '</div>';
		}
		if(fw_main_change_type == "change_dates")
			rtn += '<div class="fw_confirm_box">To: ';
		if(fw_main_change_type == "book_replacement")
			rtn += '<div class="fw_confirm_box">Book: ';
		if(fw_main_change_type == "cancel_trip")
			rtn += '<div class="fw_confirm_box">Cancel: ';
		
		for(var i = 0; i < num_fw_fb; i++)
		{
			if(fw_fb_type[i] == "new")
			{
				rtn += '<div class="fw_confirm_box_sub">' + fw_fb_from[i] + ' to ' + fw_fb_to[i]  + '<br>' + fw_fb_date[i] + ' at ' + fw_fb_time[i] + ' ' + fw_fb_time_ampm[i] + '<br>Flying ' + fw_fb_airline[i] + '</div>';
			}
		}
		
		rtn += '</div>';
		$("#fw_confirm_flights").html(rtn);
	}
	
	rtn = "<h3>Hotel Stay</h3>";
	if(showingHotels)
	{

		if(!showingFlights ||  $("input[name=fw_change_carhotel]:checked").val() == "NO")
		{
			for(var i = 0; i < num_fw_hc; i++)
			{
				if(fw_hc_type[i] == "hotel")
				{
					rtn += '<div class="fw_confirm_box" style="clear: left"> ';

					if(fw_hc_control[i] == "change")
						rtn += "Change ";
					else
						rtn += "Cancel ";

					rtn += '<div class="fw_confirm_box_sub">' + fw_hc_city[i] + ': ' + fw_hc_hotel[i] + '<br>Check in: ' + fw_hc_datein[i] + ' <br>Check out: ' + fw_hc_dateout[i] + '</div>';

					rtn += '</div>';
				}
			}
		}
		else if(showingFlights)
		{
			rtn = "Hotel stay to be changed in line with the flights arrangements.";
		}

		
		$("#fw_confirm_hotels").html(rtn);
	}
	rtn = "<h3>Car Rental</h3>";
	if(showingCars)
	{
		if(!showingFlights ||  $("input[name=fw_change_carhotel]:checked").val() == "NO")
		{
			for(var i = 0; i < num_fw_hc; i++)
			{
				if(fw_hc_type[i] == "car")
				{

					rtn += '<div class="fw_confirm_box" style="clear: left"> ';

					if(fw_hc_control[i] == "change")
						rtn += "Change ";
					else
						rtn += "Cancel "

						rtn += '<div class="fw_confirm_box_sub">' + fw_hc_city[i] + ': ' + fw_hc_hotel[i] + '<br>Pick up: ' + fw_hc_datein[i] + ' at ' + fw_hc_time[i] + ' ' + fw_hc_time_ampm[i] + '<br>Drop off: ' + fw_hc_dateout[i] + '</div>';

					rtn += '</div>';
				}
			}
		}
		else if(showingFlights)
		{
			rtn = "Car rental to be changed in line with the flights arrangements.";
		}

		$("#fw_confirm_cars").html(rtn);
	}
	
}



function fw_hc_save()
{
	for(var i = 0; i < num_fw_hc; i++)
	{
		fw_hc_city[i] = $("#fw_hc_city_" + i).val();
		fw_hc_datein[i] = $("#fw_hc_datein_" + i).val();
		fw_hc_dateout[i] = $("#fw_hc_dateout_" + i).val();
		fw_hc_hotel[i] = $("#fw_hc_hotel_" + i).val();
		if(fw_hc_type[i] != "hotel")
		{
			fw_hc_time[i] = $("#fw_hc_time_" + i).val();
			fw_hc_time_ampm[i] = $("#fw_hc_time_ampm_" + i).val();
		}
		fw_hc_control[i] = "";
		if($("input[name=fw_hc_changecancel_" + i + "]:checked").val() == "cancel")
			fw_hc_control[i] = "cancel";
		if($("input[name=fw_hc_changecancel_" + i + "]:checked").val() == "change")
			fw_hc_control[i] = "change";
	}
}


function fw_hc_remove(vv)
{
	fw_hc_city.splice(vv,1);
	fw_hc_datein.splice(vv,1);
	fw_hc_dateout.splice(vv,1);
	fw_hc_hotel.splice(vv,1);
	fw_hc_time.splice(vv,1);
	fw_hc_time_ampm.splice(vv,1);
	fw_hc_type.splice(vv,1);
	fw_hc_control.splice(vv,1);
	num_fw_hc--;
}


function fw_hc_drawNow()
{
	$("#fw_current_hotels").html(fw_hc_draw("hotel"));
	$("#fw_current_cars").html(fw_hc_draw("car"));
	fw_date_annoy();
}

function fw_removeHC(vv)
{
	var currentType = fw_hc_type[vv];
	fw_hc_save();
	fw_hc_remove(vv);
	fw_hc_drawNow();
}

function fw_hc_add(vv){
	fw_hc_save();
	fw_hc_city[num_fw_hc] = "";
	fw_hc_datein[num_fw_hc] = "dd/mm/yyyy";
	fw_hc_dateout[num_fw_hc] = "dd/mm/yyyy";
	fw_hc_hotel[num_fw_hc] = "";
	fw_hc_time[num_fw_hc] = "";
	fw_hc_time_ampm[num_fw_hc] = "am";
	fw_hc_type[num_fw_hc] = vv;
	num_fw_hc++;
	fw_hc_drawNow();
}


function fw_checkFlightsChecked(vv)
{
	if(vv.checked)
	{
		$("#fw_change_flights").attr("checked", true);
	}
	else
	{
		var isChecked = false;
		$(".fw_airline_box").each(function()
		{
			if($(this).attr("checked"))
			{
				isChecked = true;
			}
		});
		if(!isChecked)
			$("#fw_change_flights").attr("checked", false);
	}
}

function fw_checkFlightsCheckedAll(vv)
{
	if(!vv.checked)
	{
		$(".fw_airline_box").each(function()
		{
			$(this).attr("checked", false)
		});
	}
}

function fw_submit_form()
{
	if(true)
	{
		var to = "http://mailgate.server-mail.com/cgi-bin/mailgate";
		to = "http://sandbox/echo/email.php";
		//to = "http://www.webjet.com.au/sandbox/echo/email.php";
    		to = "http://www.webjet.com.au/sandbox/echo/test.php";
		var pArray = Array();
		pArray["recipient"] = "default";
		pArray["redirect"] = "http://www.webjet.com.au";
		//pArray["is_test"] = "true";
		
		pArray["subject"] = "Domestic - FLIGHT CHANGE REQUEST";
		
		if(fw_main_change_type == "change_dates")
			pArray["redirect"] = "http://www.webjet.com.au/about/form-change-request-thank-you";
		
		if(fw_main_change_type == "cancel_trip")
			pArray["redirect"] = "http://www.webjet.com.au/about/form-cancel-request-thank-you";
		
		if(fw_main_change_type == "book_replacement")
			pArray["redirect"] = "http://www.webjet.com.au/about/form-use-my-credit-request-thank-you";

		//pArray["field1"] = "This is the first field";
		//pArray["field2"] = "This is the second field";
		//pArray["field2"] = "This is the second field";
		
		var urgent = false;
		if($("input[name=fw_when_travel]:checked").val() == "soon")
			urgent = true;
		
		if(urgent)
			pArray["Urgent"] = "URGENT! TRAVELLING IN THE NEXT THREE DAYS";
				
		pArray["Request Type"] = fw_main_change_type;
		pArray["Trip To"] = $("input[name=fw_intldom]:checked").val();	
		
		if(showingFlights)
		{
			if($("input[name=fw_intldom]:checked").val() == "domestictrans")
			{
				pArray["subject"] = "Domestic - FLIGHT CHANGE REQUEST";
				if(urgent)
					pArray["subject"] = "Domestic - URGENT FLIGHT CHANGE REQUEST DEPARTING WITHIN 3 DAYS";
			}
			else
			{
				pArray["subject"] = "International - FLIGHT CHANGE REQUEST";
				if(urgent)
					pArray["subject"] = "International - URGENT FLIGHT CHANGE REQUEST DEPARTING WITHIN 3 DAYS";
			}
		
		}
		else
		{
			pArray["subject"] = "HOTEL CHANGE REQUEST";
			if(urgent)
				pArray["subject"] = "URGENT HOTEL CHANGE REQUEST CHECKING IN WITHIN 3 DAYS";
		}	
		
		
				
		var rtn = "";	
		if(showingFlights)
		{
			if($("input[name=fw_change_flights_all]:checked").val() == "ALL")
				rtn += "All flights\n";
			else
				rtn += "Selected flights\n";
		}
		if(showingHotels || showingCars)
		{
			var hc_string = ""; 
			if(showingHotels && showingCars)
				hc_string = "Hotel stay\nCar rental";
			else if(showingHotels)
				hc_string = "Hotel stay";
			else if(showingCars)
				hc_string = "Car rental";
			rtn += hc_string;
		}
		pArray["What to change"] = rtn;
		
		
		
		pArray["Passenger Name"] = $("#fw_name").val();
		pArray["Passenger Email"] = $("#fw_email").val();
		
		var phoneGiven = "";
		if($("#fw_phone_day").val() != "")
			phoneGiven = $("#fw_phone_day").val() + " (day)";
		if($("#fw_phone_night").val() != "")
		{
			if(phoneGiven != "")
				phoneGiven += "\n";
			phoneGiven += $("#fw_phone_night").val() + " (night)";
		}
		if(phoneGiven == "")
			phoneGiven = "Not Provided - use mobile";		
		
		pArray["Phone"] = phoneGiven;
		pArray["Mobile"] = $("#fw_mobile").val();
		pArray["Booking Number"] = $("#fw_booking_number").val();
		if($("#fw_allpasschange").val() == "YES")
			pArray["All Passengers"] = "Yes";
		else
		{
			pArray["All Passengers"] = "No";
			pArray["Only change passengers"] = $("#fw_passtochange").val();
		}
		
				
			
			
			if(showingFlights)
			{
				rtn = "";
				if($("input[name=fw_change_flights_all]:checked").val() != "ALL" && fw_main_change_type == "change_dates")
				{
					rtn += 'From: \n';
					for(var i = 0; i < num_fw_fb; i++)
					{
						if(fw_fb_type[i] == "current")
						{
							rtn += '' + fw_fb_from[i] + ' to ' + fw_fb_to[i]  + '\n' + fw_fb_date[i] + ' at ' + fw_fb_time[i] + ' ' + fw_fb_time_ampm[i] + '\nFlying ' + fw_fb_airline[i] + '\n\n';
						}
					}
					rtn += '\n';
				}
				if(fw_main_change_type == "change_dates")
					rtn += 'To: \n';
				if(fw_main_change_type == "book_replacement")
					rtn += 'Rebook: \n';
				if(fw_main_change_type == "cancel_trip")
					rtn += 'Cancel: \n';
				
				for(var i = 0; i < num_fw_fb; i++)
				{
					if(fw_fb_type[i] == "new")
					{
							rtn += '' + fw_fb_from[i] + ' to ' + fw_fb_to[i]  + '\n' + fw_fb_date[i] + ' at ' + fw_fb_time[i] + ' ' + fw_fb_time_ampm[i] + '\nFlying ' + fw_fb_airline[i] + '';
					}
				}
				pArray["Flights"] = rtn;
			}
			
			if(showingHotels)
			{
				rtn = "";
				if(!showingFlights ||  $("input[name=fw_change_carhotel]:checked").val() == "NO")
				{
					for(var i = 0; i < num_fw_hc; i++)
					{
						if(fw_hc_type[i] == "hotel")
						{

							if(fw_hc_control[i] == "change")
								rtn += "Change ";
							else
								rtn += "Cancel ";

							rtn += '' + fw_hc_city[i] + ': ' + fw_hc_hotel[i] + '\nCheck in: ' + fw_hc_datein[i] + ' \nCheck out: ' + fw_hc_dateout[i] + '';

							rtn += '\n\n';
						}
					}
				}
				else if(showingFlights)
				{
					rtn = "Please change in line with flights.";
				}
		
				
				pArray["Hotels"] = rtn;
			}
			if(showingCars)
			{
				rtn = "";
				if(!showingFlights ||  $("input[name=fw_change_carhotel]:checked").val() == "NO")
				{
					for(var i = 0; i < num_fw_hc; i++)
					{
						if(fw_hc_type[i] == "car")
						{


							if(fw_hc_control[i] == "change")
								rtn += "Change ";
							else
								rtn += "Cancel "

								rtn += '' + fw_hc_city[i] + ': ' + fw_hc_hotel[i] + '\nPick up: ' + fw_hc_datein[i] + ' at ' + fw_hc_time[i] + ' ' + fw_hc_time_ampm[i] + '\nDrop off: ' + fw_hc_dateout[i] + '';

							rtn += '\n\n';
						}
					}
				}
				else if(showingFlights)
				{
					rtn = "Please change in line with flights.";
				}
		
				pArray["Car Rentals"] = rtn;
		}
		
		
		if(showingFlights)
		pArray["Charge cap per passenger"] = $("#fw-charge-cap").val();
		pArray["Additional Comments"] = $("#fw_additional_comments").val();
		
		
		var myForm = document.createElement("form");
		myForm.method = "post";
		myForm.action = to;
		if (pArray) {
		    for (var k in pArray) {
			var myInput = document.createElement("input");
			myInput.setAttribute("name", k);
			myInput.setAttribute("type", 'hidden');
			myInput.setAttribute("value", pArray[k]);
			myForm.appendChild(myInput);
		    }
		}
		document.body.appendChild(myForm);
		myForm.submit();
		document.body.removeChild(myForm);
	}
}

function updateDate(theId)
{
	var newDate = $('#' + theId + '_dd').val() + "/" + $('#' + theId + '_mmyyyy').val();
	$('#' + theId).val(newDate);
}

function updateDateReverse(theId)
{
	var theVal = $('#' + theId).val();
	if(theVal == '')
		return;
	$('#' + theId + '_dd').val(theVal.substring(0, 2))
	$('#' + theId + '_mmyyyy').val(theVal.substring(3))
}



function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

jQuery(document).ready(function($){
//fw_submit_form();
//	$("#fw_booking_number").val("asdf");
//	fw_changeToScreen("bookingdetails");
});
