// getDate and built the date fields here
var d=new Date()
var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"

today=weekday[d.getDay()];

var topFlight=1;// how many times to run thru validation
$(document).ready(function() {
	$('input:checkbox[@name="sameasbilling"]').click(function(){
		$('input[@name="fname"]').val($('input[@name="fname2"]').val()); //= ;
		$('input[@name="lname"]').val($('input[@name="lname2"]').val()); //= ;
	});
	$('input:radio[@name^=customer_data]').click(function(){
		var whichRadio = $(this).val();
		$(this).parent('div').next().children('.option_'+whichRadio).show().siblings().hide();
	});
	$('.rsn').click(function(){
		$('#Reason_4').hide('slow');
		$('#otherreason').remove();
	});
	$('.rsn4').click(function(){
	  var newcontent="<text"+"area name='otherreason' id='otherreason' cols='50' rows='5'></text"+"area>";
		$('#Reason_4').append(newcontent).show('slow');
	});
		
	$("a[id^='flight_add']").click(function(){
		var suffix = $(this).attr('class');
		$(this).hide().next().show();
		//
		//
		
		$('#flite_F1').clone()
		.find('*').each(function(){   
			this.id = this.id.substring(0 ,this.id.lastIndexOf('_F')+1) + suffix; 
			this.name = String(this.name).substring(0 ,String(this.name).lastIndexOf('_F')+1) + suffix;
		})
		.end().find('input:text').each(function(){
			if(this.name.substring(0,11) == "ticket_num_") { 
			  if(suffix=="F2") {
					$(this).attr("tabindex","23"); 
				} else if(suffix=="F3") {
				  $(this).attr("tabindex","33");
				} else if(suffix=="F4") {
				  $(this).attr("tabindex","43"); 
				}
				
				$(this).val("016");
			} else {
				$(this).val('');
			}
		})
		.end().find("#flight_num_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","24"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","34"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","44"); 
			}
		})
		.end().find("#origin_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","25"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","35"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","45"); 
			}
		})
		.end().find("#dest_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","26"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","36"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","46"); 
			}
		})
		.end().find("#month_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","27"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","37"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","47"); 
			}
		})
		.end().find("#day_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","28"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","38"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","48"); 
			}
		})
		.end().find("#year_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","29"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","39"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","49"); 
			}
		})
		.end().find("#Seat_num_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","30"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","40"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","50"); 
			}
		})
		.end().find("#seat_type_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","31"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","41"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","51"); 
			}
		})
		.end().find("#receipt_num_"+suffix).each(function() {
		  if(suffix=="F2") {
				$(this).attr("tabindex","32"); 
			} else if(suffix=="F3") {
			  $(this).attr("tabindex","42"); 
			} else if(suffix=="F4") {
			  $(this).attr("tabindex","52"); 
			}
		})
		.end()
		.attr('id','flite_'+suffix).addClass('dashTop')
		.find('.title').html('Flight '+suffix.substr(1,1)).end()
		.insertAfter($(this));
		$('input:radio[@name^=customer_data]').click(function(){
			var whichRadio = $(this).val();
			$(this).parent('div').next().children('.option_'+whichRadio).show().siblings().hide();
		});
		$('#customer_data_1_'+suffix).attr("checked", "checked").parent('div').next().children('.option_1').show().siblings().hide();

		$href = $('#lookupOrg_'+suffix).attr('href');
		$('#lookupOrg_'+suffix).attr('href',$href.split("_")[0]+"_"+suffix+$href.split("_")[1].substring(2));
		$href = $('#lookupDes_'+suffix).attr('href');
		$('#lookupDes_'+suffix).attr('href',$href.split("_")[0]+"_"+suffix+$href.split("_")[1].substring(2));
		topFlight++;
		return false
	});
});

// Now begin local validation for fields
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/gi,"") };
//
// Error messages
var tktError = "Please enter a valid 13-digit ticket number (e.g. 0160987654321). This number can be found on your travel itinerary.\n";
//
var msg="";
var flt_data="";
var sum_data="";
function validate(f) {
	msg="";flt_data="";sum_data="";
	if (!f.fname2.value){msg+="Please enter the Passenger's First name.\n";}
	if (!f.lname2.value){msg+="Please enter the Passenger's Last name.\n";}
	//MP
	if ($('#MP_num').val()){
	 if (!validateMP($('#MP_num').val())) {msg+="Please enter a valid 11-digit Mileage Plus number.\n";}
	}
	//phone validate
	if (!f.phoneAC.value || !f.phonePrefix.value || !f.phone.value){msg+="Please enter your Phone number, including area code.\n";}
	// email validate
	if(!f.email.value) {msg+="Please enter your Email address.\n";}
	else if (!validateEml(f.email.value)){msg+="The Email address you entered is invalid. Please re-enter your Email address.\n"}
// check first name BILLING
	var fname = f.fname.value;
	if(!fname) {msg+="Please enter the Billing First name.\n"} // check for empty form elements
	else {
		fname = fname.trim();//leading trailing
		f.fname.value = fname;//put it back
		if(/[^a-zA-Z ]{1,40}$/.test(fname)) msg+="First name should only contain letters.\n"; // check for empty form elements
	}
	// check last name BILLING
	var lname = f.lname.value;
	if(!lname) {msg+="Please enter the Billing Last name.\n"} // check for empty form elements
	else {
		lname = lname.trim();//leading trailing
		f.lname.value = lname;//put it back
		if(/[^a-zA-Z ]{1,40}$/.test(lname)) msg+="Last name should only contain letters.\n"; // check for empty form elements
	}
	//
//build up event string 	
  sum_data = $('#pax_num option:selected').val() + "|"+ $("input[@name='refund_reason']:checked").val() +"|";
//start with F1

for (var qq=1; qq <= topFlight; qq++) {
 //for each
	if ($("#customer_data_1_F"+qq).is(":checked")) {
		searchValue = $("#ticket_num_F"+qq).val().replace(/\D/g, "");
		$('#ticket_num_F'+qq).val(searchValue);//put it back
		if (validateTicket(searchValue, qq)){flt_data+=searchValue+"|||"};
	}
	else if ($("#customer_data_2_F"+qq).is(":checked")) {
		searchValue = $("#flight_num_F"+qq).val().replace(/\D/g, "");
		$('#flight_num_F'+qq).val(searchValue);//put it back
		re = /^[0-9]{1,4}$/;
		if(!searchValue){msg+="Please enter a valid UA flight number for Flight "+qq+".\n";}
		else if (!re.test(searchValue)){msg+="Please enter a valid 1 to 4-digit UA flight number "+qq+".\n";}
		else {flt_data+="|"+searchValue+"||"}
	}
	else if ($("#customer_data_3_F"+qq).is(":checked")) {
		var org = $('#origin_F'+qq).val();
		var des = $('#dest_F'+qq).val();
		if(!org){msg+="Please enter the origin city or airport code for Flight "+qq+".\n";}
		if(!des){msg+="Please enter the destination city or airport code for Flight "+qq+".\n";}
		if (org == des){msg+="The Origin and Destination cannot be the same for Flight "+qq+".\n"}
		else if (org && des){flt_data+="||"+org+"-"+des+"|"}
	}
	
	var r1val = $("#receipt_num_F1").val();
	var r2val = $("#receipt_num_F2").val();
	var r3val = $("#receipt_num_F3").val();
	var r4val = $("#receipt_num_F4").val();
		
	if(r1val!="") {
	  if(validateReceipt(r1val,qq)==true) {
			if((typeof r2val != "undefined") && (r2val != "")) {
			  if(validateReceipt(r2val,qq)==true) {
					$('#address1').val(r1val+"."+r2val);
				}
			} else {
				$('#address1').val(r1val+".NULL");
			}
		}
	} else {
	  if((typeof r2val != "undefined") && (r2val != "")) {
		  if(validateReceipt(r2val,qq)==true) {
				$('#address1').val("NULL."+r2val);
			}
		} else {
		  $('#address1').val("NULL.NULL");
		}
	}
	
	if((typeof r3val != "undefined") && (r3val!="")) {
		if(validateReceipt(r3val,qq)==true) {
			if(r4val!="" && r4val!="undefined") {
				if(validateReceipt(r4val,qq)==true) {
					$('#address2').val(r3val+"."+r4val);
				}
			} else {
				$('#address2').val(r3val+".NULL");
			}
		}
	} else {
	  if((typeof r4val != "undefined") && (r4val!="")) {
			if(validateReceipt(r4val,qq)==true) {
				$('#address2').val("NULL."+r4val);
			}
		}
	}
	
	//validate date
	var mm = $('#month_F'+qq).val();
	var dd = $('#day_F'+qq).val();
	var yy = $('#year_F'+qq).val();

	if(!mm || mm=="Mon" ){msg+="Please select a Month for Flight "+qq+".\n";}
	if(!dd || dd=="Day"){msg+="Please select a Day for Flight "+qq+".\n";}
	if(!yy || yy=="Yr"){msg+="Please select a Year for Flight "+qq+".\n";}
	//
	if (mm && dd && yy ){ //produce a date validate 400 days
		var tripDate = new Date(yy,mm-1,dd);
		var delta = Math.round((d - tripDate)/1000/60/60/24);//convert milliseconds to days
		if(delta > 399){
		msg+="We cannot accept refund requests that are beyond 400 days old.\n";
		} else if(delta < 0){
		msg+="Please check the travel date for Flight "+qq+". The date appears to be in the future.\n";

		} else {flt_data+=mm+"/"+dd+"/"+yy+"|";}
	}
	flt_data+=$('#Seat_num_F'+qq).val()+"|" + $('#seat_type_F'+qq).find('option:selected').val()+"|";
}//end for each

//reason validate 
if (!$("input[@name='refund_reason']:checked").val()){msg+="Please choose a refund reason.";}
if ($("input[@name='refund_reason']:checked").val()=="OTHER" && !document.coreg.otherreason.value){msg+="Please provide a brief description to support your refund request.";}
// Run message output
if (msg) {
	msg='Please Supply the Following:\n\n' + msg;
	alert(msg);
	return false;
	} else {
		var zEmail = buildEmail();
		 $.ajax({
			type: "POST",
			url: zEmail,
      complete: function(msg){
				senditall(f);
			}
		});
	//return true;
	}
}
function senditall(f){
 //Build up the URL for coReg string submit
 var urlString = "http://www.unitedoffers.com/el/coReg.p_Process";
 for (i=0; i< f.length-1; i++) {
    var g = f.elements[i];
    if (g.name.charAt(0) != "x" && g.value != null && g.value != "") { 
      if (g.name == "access_type" 
	   || g.name == "vendor_id"
	   || g.name == "campaign_id" 
	   || g.name == "banner_id"  
	   || g.name == "env_id" 
	   || g.name == "user_status" 
           || g.name == "targetURL"
           || g.name == "failureURL"
           || g.name == "fname"
           || g.name == "fname2"
           || g.name == "lname"
           || g.name == "lname2"
					 || g.name == "address1"
					 || g.name == "address2"
					 || g.name == "city"
					 || g.name == "state"
					 || g.name == "zip"
					 || g.name == "country"
           || g.name == "hphone"
           || g.name == "aphone"
           || g.name == "email") 
        {
				if (i==0){urlString+= "?"}else{urlString+="&"};
					urlString += g.name+ "=" + escape(g.value);
        }
     }
  }//end forloop
	urlString += "&hphone=" + f.phoneAC.value + f.phonePrefix.value + f.phone.value;
 urlString += "&vuser=" + f.MP_num.value+"|"+ flt_data+ Math.round((Math.random()*99999)+1); 

if ($("input[@name='refund_reason']:checked").val() == "OTHER") sum_data+= escape(f.otherreason.value);
if (sum_data.length > 100) sum_data.length = 100;
 urlString += "&canswer=" + sum_data;
  //alert("flight data: "+flt_data+"\nurlstring: "+urlString+"\ncanswer: "+sum_data);

	// submit window to destination
  document.location.href=urlString;
	//console.log(urlString);
}

function validateTicket(searchValue, flightNum) {
		if (!/^\d{13}$/.test(searchValue)){
			msg+="Please enter a valid 13-digit ticket number (e.g. 0160987654321) for Flight "+flightNum+".\n"; 
			return false;
		}	else if (searchValue.substr(0,3) != "016") {
			msg+="Ticket number must begin with '016.'"+flightNum+"\n";
			return false
	} else {
		return true
	}
}
function validateReceipt(searchValue, flightNum) {
		if (!/^\d{13}$/.test(searchValue)){
			msg+="Please enter a valid 13-digit receipt number (e.g. 0160123456789) for Flight "+flightNum+".\n"; 
			return false;
		}	else if (searchValue.substr(0,3) != "016") {
			msg+="Receipt number must begin with '016.'"+flightNum+"\n";
			return false
	} else {
		return true
	}
}
function validateMP(MPNO){
	if (!/^\d{11}$/.test(MPNO) ) {return false;}
	var factor = [5,4,3,2,7,6,5,4,3,2]; var check = 0;
	for (var digit = 0; digit < 10; digit++)
		check += MPNO.charAt(digit) * factor[digit];
	check = (((11 - (check % 11)) % 11) % 10);
	return (check == MPNO.charAt(10));
	
}
function validateEml(str) {
//	re = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.{1}[a-zA-Z]{2,6}$");
	re = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]{0,4}[a-zA-Z]$/;
	return (re.test(str));
}

function buildEmail() {
  var f = document.coreg;
	
	var from_address = "";
	var subject = "";
	var body = "";
	var to_address 	= "";
			
	//from_address = escape(f.email.value);
	if (from_address=="") { from_address="seat_purchase_refund_form@united.com"; }
	subject = escape("Seat purchase refund request");
	to_address = escape("web-refunds-tvlopt@united.com");
	//to_address = escape("shelby.smull@united.com");
	//to_address = escape("karin.lieber@united.com");
	
	body = "United.com Seat purchase refund request\r\n";
	body += "\r\n--Passenger info--";
	body += "\r\n\tName: " + f.fname2.value + " " + f.lname2.value;
	body += "\r\n\tMP Number: " + f.MP_num.value;
	body += "\r\n\tNum Passengers: " + f.pax_num.value;
	body += "\r\n";
	body += "\r\n--Billing info--";
	body += "\r\n\tName: " + f.fname.value + " " + f.lname.value;
	body += "\r\n\tPhone: " + "("+f.phoneAC.value+")"+f.phonePrefix.value+"-"+f.phone.value;
	if(f.aphone.value!="") { body += " ext. " + f.aphone.value; }
	body += "\r\n\tEmail: " + f.email.value;
	body += "\r\n";
	if(f.refund_reason[3].checked) {
		body += "\r\nRefund reason: OTHER\r\n"+f.otherreason.value;
	} else {
	  if(f.refund_reason[0].checked) {
			body += "\r\nRefund reason: "+f.refund_reason[0].value;
		} else if(f.refund_reason[1].checked) {
		  body += "\r\nRefund reason: "+f.refund_reason[1].value;
		} else if(f.refund_reason[2].checked) {
		  body += "\r\nRefund reason: "+f.refund_reason[3].value;
		}
	}
	
	body += "\r\n";
	body += "\r\n--Flight info (Flight 1)--";
	var sType, iType;
	if(f.customer_data_F1[0].checked) {
	  sType="Ticket #";
		iType=1;
	} else if(f.customer_data_F1[1].checked) {
	  sType="Flight #";
		iType=2;
	} else if(f.customer_data_F1[2].checked) {
	  sType="From - To";
		iType=3;
	}
	
	body += "\r\n\tInfo type: " + sType
	if(iType==1) {
	  body += "\r\n\tTicket #: " + f.ticket_num_F1.value;
		if(f.receipt_num_F1.value!="") { body += "\r\n\tReceipt #: " + f.receipt_num_F1.value; }
		body += "\r\n\tTravel Date: " + f.month_F1.value + "/" + f.day_F1.value + "/" + f.year_F1.value;
		body += "\r\n\tSeat #: " + f.Seat_num_F1.value;
		body += "\r\n\tSeat Location: " + f.seat_type_F1.value;
	}
	if(iType==2) {
	  body += "\r\n\tUA Flight #: " + f.flight_num_F1.value;
		if(f.receipt_num_F1.value!="") {
			body += "\r\n\tReceipt #: " + f.receipt_num_F1.value;
		}
		body += "\r\n\tTravel Date: " + f.month_F1.value + "/" + f.day_F1.value + "/" + f.year_F1.value;
		body += "\r\n\tSeat #: " + f.Seat_num_F1.value;
		body += "\r\n\tSeat Location: " + f.seat_type_F1.value;
	}
	if(iType==3) {
	  body += "\r\n\tFlight Origin: " + f.origin_F1.value;
		body += "\r\n\tFlight Destination: " + f.dest_F1.value;
		if(f.receipt_num_F1.value!="") {
			body += "\r\n\tReceipt #: " + f.receipt_num_F1.value;
		}
		body += "\r\n\tTravel Date: " + f.month_F1.value + "/" + f.day_F1.value + "/" + f.year_F1.value;
		body += "\r\n\tSeat #: " + f.Seat_num_F1.value;
		body += "\r\n\tSeat Location: " + f.seat_type_F1.value;
	}
	
	if(topFlight>1) {
		body += "\r\n";
		body += "\r\n--Flight info (Flight 2)--";
		if(document.getElementById("customer_data_1_F2").checked) {
		  sType="Ticket #";
			iType=1;
		} else if(document.getElementById("customer_data_2_F2").checked) {
		  sType="Flight #";
			iType=2;
		} else if(document.getElementById("customer_data_3_F2").checked) {
		  sType="From - To";
			iType=3;
		}
		
		body += "\r\n\tInfo type: " + sType
		if(iType==1) {
		  body += "\r\n\tTicket #: " + f.ticket_num_F2.value;
			if(f.receipt_num_F2.value!="") { body += "\r\n\tReceipt #: " + f.receipt_num_F2.value; }
			body += "\r\n\tTravel Date: " + f.month_F2.value + "/" + f.day_F2.value + "/" + f.year_F2.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F2.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F2.value;
		}
		if(iType==2) {
		  body += "\r\n\tUA Flight #: " + f.flight_num_F2.value;
			if(f.receipt_num_F2.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F2.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F2.value + "/" + f.day_F2.value + "/" + f.year_F2.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F2.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F2.value;
		}
		if(iType==3) {
		  body += "\r\n\tFlight Origin: " + f.origin_F2.value;
			body += "\r\n\tFlight Destination: " + f.dest_F2.value;
			if(f.receipt_num_F2.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F2.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F2.value + "/" + f.day_F2.value + "/" + f.year_F2.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F2.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F2.value;
		}
	}
	
	if(topFlight>2) {
		body += "\r\n";
		body += "\r\n--Flight info (Flight 3)--";
		if(document.getElementById("customer_data_1_F3").checked) {
		  sType="Ticket #";
			iType=1;
		} else if(document.getElementById("customer_data_2_F3").checked) {
		  sType="Flight #";
			iType=2;
		} else if(document.getElementById("customer_data_3_F3").checked) {
		  sType="From - To";
			iType=3;
		}
		
		body += "\r\n\tInfo type: " + sType
		if(iType==1) {
		  body += "\r\n\tTicket #: " + f.ticket_num_F3.value;
			if(f.receipt_num_F3.value!="") { body += "\r\n\tReceipt #: " + f.receipt_num_F3.value; }
			body += "\r\n\tTravel Date: " + f.month_F3.value + "/" + f.day_F3.value + "/" + f.year_F3.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F3.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F3.value;
		}
		if(iType==2) {
		  body += "\r\n\tUA Flight #: " + f.flight_num_F3.value;
			if(f.receipt_num_F3.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F3.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F3.value + "/" + f.day_F3.value + "/" + f.year_F3.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F3.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F3.value;
		}
		if(iType==3) {
		  body += "\r\n\tFlight Origin: " + f.origin_F3.value;
			body += "\r\n\tFlight Destination: " + f.dest_F3.value;
			if(f.receipt_num_F3.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F3.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F3.value + "/" + f.day_F3.value + "/" + f.year_F3.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F3.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F3.value;
		}
	}	
	
	if(topFlight>3) {
		body += "\r\n";
		body += "\r\n--Flight info (Flight 4)--";
		if(document.getElementById("customer_data_1_F4").checked) {
		  sType="Ticket #";
			iType=1;
		} else if(document.getElementById("customer_data_2_F4").checked) {
		  sType="Flight #";
			iType=2;
		} else if(document.getElementById("customer_data_3_F4").checked) {
		  sType="From - To";
			iType=3;
		}
		
		body += "\r\n\tInfo type: " + sType
		if(iType==1) {
		  body += "\r\n\tTicket #: " + f.ticket_num_F4.value;
			if(f.receipt_num_F4.value!="") { body += "\r\n\tReceipt #: " + f.receipt_num_F4.value; }
			body += "\r\n\tTravel Date: " + f.month_F4.value + "/" + f.day_F4.value + "/" + f.year_F4.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F4.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F4.value;
		}
		if(iType==2) {
		  body += "\r\n\tUA Flight #: " + f.flight_num_F4.value;
			if(f.receipt_num_F4.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F4.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F4.value + "/" + f.day_F4.value + "/" + f.year_F4.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F4.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F4.value;
		}
		if(iType==3) {
		  body += "\r\n\tFlight Origin: " + f.origin_F4.value;
			body += "\r\n\tFlight Destination: " + f.dest_F4.value;
			if(f.receipt_num_F4.value!="") {
				body += "\r\n\tReceipt #: " + f.receipt_num_F4.value;
			}
			body += "\r\n\tTravel Date: " + f.month_F4.value + "/" + f.day_F4.value + "/" + f.year_F4.value;
			body += "\r\n\tSeat #: " + f.Seat_num_F4.value;
			body += "\r\n\tSeat Location: " + f.seat_type_F4.value;
		}
	}
	
	
	var action = "";
	// send an email messsage and then redirect to a jump link, that will
	// take the user to the orphan page.
	action = "http://www.united.com/ualweb/cda/form/processor.jsp?locPageId=" + 3524 + "&to_address=" + to_address + "&from_address=" + from_address + "&subject=" + subject + "&body=" + escape(body);	
	return action;
}