// JavaScript Document
function check_cc_month(){
	var right_now = new Date();	
	var yr = right_now.getFullYear();
	var m = right_now.getMonth()+1;
	var response = "";
	if(document.Form1.CardExpYear.options[document.Form1.CardExpYear.selectedIndex].value == yr){
		//display months >= then current month
		response = "<select name='CardExpMonth' id='select4'>";
			for(var i=m;i<13;i++){
				response += "<option value='";
				response += i;
				response += "'>";
				response += i;
				response += "</option>";	
			}
		response += "</select>";
	}else{
		//display all months
		response = "<select name='CardExpMonth' id='select4'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select>";
	}
	if(document.getElementById('month_cage')!=null){
		document.getElementById('month_cage').innerHTML = response;
	}
}
function updateCost(){
	//NEED TO CHECK FOR ARRIVAL AND DEPARTURE FLIGHTS ONLY
	if(document.Form1.arrivalNumInParty.value==""){
		var arrive_num = 0;
	}else{
		var arrive_num = document.Form1.arrivalNumInParty.value;
	}
	if(document.Form1.DepartureNumInParty.value==""){
		var depart_num = 0;
	}else{
		var depart_num = document.Form1.DepartureNumInParty.value;
	}
	if(document.getElementById('rates')!=null){
		if(document.Form1.rates.options[document.Form1.rates.selectedIndex].value==""){
			var rate = 0;
		}else{
			var rate = document.Form1.rates.options[document.Form1.rates.selectedIndex].value;
		}
	}
	if(document.getElementById('serv_charge')!=null){
		if(document.Form1.serv_charge.value==""){
			var serv_charge = 0;
		}else{
			var serv_charge = (document.Form1.serv_charge.value/100);
		}
	}
	if(document.getElementById('fuel_charge')!=null){
		if(document.Form1.fuel_charge.value==""){
			var fuel_charge = 0;
		}else{
			var fuel_charge = (document.Form1.fuel_charge.value/100);
		}
	}
	//THE USER SELECTED AN ARRIVAL ONLY OPTION
	if(document.Form1.arrival_only.options[document.Form1.arrival_only.selectedIndex].value=="yes"){
    if(document.Form1.rates.selectedIndex==1){
      //selected per person one way (1), leave number in party the same
    }else if(document.Form1.rates.selectedIndex==2){
      //selected private town car (3), if number in the party is greater then 3, then double
      if(arrive_num>3){
        arrive_num = Math.ceil(arrive_num/3);
      }else{
        arrive_num = 1;
      }
    }else if(document.Form1.rates.selectedIndex==3){
      //selected private executive van service(8)
      if(arrive_num>8){
        arrive_num = Math.ceil(arrive_num/8);
      }else{
        arrive_num = 1;
      }
    }
    var total_serv_charge = (arrive_num*rate) * serv_charge;
		var total_fuel_charge = (arrive_num*rate) * fuel_charge;
		var total_cost = (arrive_num*rate) + total_serv_charge + total_fuel_charge;
	}else if(document.Form1.departure_only.options[document.Form1.departure_only.selectedIndex].value=="yes"){
		if(document.Form1.rates.selectedIndex==1){
      //selected per person one way (1), leave number in party the same
    }else if(document.Form1.rates.selectedIndex==2){
      //selected private town car (3), if number in the party is greater then 3, then double
      if(depart_num>3){
        depart_num = Math.ceil(depart_num/3);
      }else{
        depart_num = 1;
      }
    }else if(document.Form1.rates.selectedIndex==3){
      //selected private executive van service(8)
      if(depart_num>8){
        depart_num = Math.ceil(depart_num/8);
      }else{
        depart_num = 1;
      }
    }
    var total_serv_charge = (depart_num*rate) * serv_charge;
		var total_fuel_charge = (depart_num*rate) * fuel_charge;
		var total_cost = (depart_num*rate) + total_serv_charge + total_fuel_charge;
	}else{
		if(document.getElementById('rates')!=null){
			if(document.Form1.rates.selectedIndex==1){
				//selected per person one way (1), leave number in party the same
			}else if(document.Form1.rates.selectedIndex==2){
				//selected private town car (3), if number in the party is greater then 3, then double
				if(arrive_num>3){
					arrive_num = Math.ceil(arrive_num/3);
				}else{
					arrive_num = 1;
				}
				if(depart_num>3){
					depart_num = Math.ceil(depart_num/3);
				}else{
					depart_num = 1;
				}
			}else if(document.Form1.rates.selectedIndex==3){
				//selected private executive van service(8)
				if(arrive_num>8){
					arrive_num = Math.ceil(arrive_num/8);
				}else{
					arrive_num = 1;
				}
				if(depart_num>8){
					depart_num = Math.ceil(depart_num/8);
				}else{
					depart_num = 1;
				}
			}
		}
		var total_serv_charge = ((arrive_num*rate) + (depart_num*rate)) * serv_charge;
		var total_fuel_charge = ((arrive_num*rate) + (depart_num*rate)) * fuel_charge;
		var total_cost = ((arrive_num*rate) + (depart_num*rate)) + total_serv_charge + total_fuel_charge;
	}
	document.Form1.total_cost.value = formatCurrency(total_cost);
}
function other_updateCost(){
	//NEED TO CHECK FOR ARRIVAL AND DEPARTURE FLIGHTS ONLY
	if(document.Form1.arrivalNumInParty.value==""){
		var arrive_num = 0;
	}else{
		var arrive_num = document.Form1.arrivalNumInParty.value;
	}
	if(document.Form1.DepartureNumInParty.value==""){
		var depart_num = 0;
	}else{
		var depart_num = document.Form1.DepartureNumInParty.value;
	}
	if(document.Form1.rates.options[document.Form1.rates.selectedIndex].value==""){
		var rate = 0;
	}else{
		var rate = document.Form1.rates.options[document.Form1.rates.selectedIndex].value;
	}
	if(document.Form1.serv_charge.value==""){
		var serv_charge = 0;
	}else{
		var serv_charge = (document.Form1.serv_charge.value/100);
	}
	if(document.Form1.fuel_charge.value==""){
		var fuel_charge = 0;
	}else{
		var fuel_charge = (document.Form1.fuel_charge.value/100);
	}
	//THE USER SELECTED AN ARRIVAL ONLY OPTION
	if(document.Form1.arrival_only.options[document.Form1.arrival_only.selectedIndex].value=="yes"){
    if(document.Form1.rates.selectedIndex==0 || document.Form1.rates.selectedIndex==3 || document.Form1.rates.selectedIndex==6){
      //selected per person one way (1), leave number in party the same
    }else if(document.Form1.rates.selectedIndex==1 || document.Form1.rates.selectedIndex==4 || document.Form1.rates.selectedIndex==7){
      //selected private town car (3), if number in the party is greater then 3, then double
      if(arrive_num>3){
        arrive_num = Math.ceil(arrive_num/3);
      }else{
        arrive_num = 1;
      }
    }else if(document.Form1.rates.selectedIndex==2 || document.Form1.rates.selectedIndex==5 || document.Form1.rates.selectedIndex==8){
      //selected private executive van service(8)
      if(arrive_num>8){
        arrive_num = Math.ceil(arrive_num/8);
      }else{
        arrive_num = 1;
      }
    }
    var total_serv_charge = (arrive_num*rate) * serv_charge;
		var total_fuel_charge = (arrive_num*rate) * fuel_charge;
		var total_cost = (arrive_num*rate) + total_serv_charge + total_fuel_charge;
	}else if(document.Form1.departure_only.options[document.Form1.departure_only.selectedIndex].value=="yes"){
		if(document.Form1.rates.selectedIndex==0 || document.Form1.rates.selectedIndex==3 || document.Form1.rates.selectedIndex==6){
      //selected per person one way (1), leave number in party the same
     }else if(document.Form1.rates.selectedIndex==1 || document.Form1.rates.selectedIndex==4 || document.Form1.rates.selectedIndex==7){
      //selected private town car (3), if number in the party is greater then 3, then double
      if(depart_num>3){
        depart_num = Math.ceil(depart_num/3);
      }else{
        depart_num = 1;
      }
     }else if(document.Form1.rates.selectedIndex==2 || document.Form1.rates.selectedIndex==5 || document.Form1.rates.selectedIndex==8){
      //selected private executive van service(8)
      if(depart_num>8){
        depart_num = Math.ceil(depart_num/8);
      }else{
        depart_num = 1;
      }
    }
    var total_serv_charge = (depart_num*rate) * serv_charge;
		var total_fuel_charge = (depart_num*rate) * fuel_charge;
		var total_cost = (depart_num*rate) + total_serv_charge + total_fuel_charge;
	}else{
	  if(document.Form1.rates.selectedIndex==0 || document.Form1.rates.selectedIndex==3 || document.Form1.rates.selectedIndex==6){
      //selected per person one way (1), leave number in party the same
     }else if(document.Form1.rates.selectedIndex==1 || document.Form1.rates.selectedIndex==4 || document.Form1.rates.selectedIndex==7){
      //selected private town car (3), if number in the party is greater then 3, then double
      if(arrive_num>3){
        arrive_num = Math.ceil(arrive_num/3);
      }else{
        arrive_num = 1;
      }
      if(depart_num>3){
        depart_num = Math.ceil(depart_num/3);
      }else{
        depart_num = 1;
      }
     }else if(document.Form1.rates.selectedIndex==2 || document.Form1.rates.selectedIndex==5 || document.Form1.rates.selectedIndex==8){
      //selected private executive van service(8)
      if(arrive_num>8){
        arrive_num = Math.ceil(arrive_num/8);
      }else{
        arrive_num = 1;
      }
      if(depart_num>8){
        depart_num = Math.ceil(depart_num/8);
      }else{
        depart_num = 1;
      }
    }
		var total_serv_charge = ((arrive_num*rate) + (depart_num*rate)) * serv_charge;
		var total_fuel_charge = ((arrive_num*rate) + (depart_num*rate)) * fuel_charge;
		var total_cost = ((arrive_num*rate) + (depart_num*rate)) + total_serv_charge + total_fuel_charge;
	}
	document.Form1.total_cost.value = formatCurrency(total_cost);
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function updateHotelText(){
	var hotel_name = document.Form1.HotelName.options[document.Form1.HotelName.selectedIndex].id;
	var hotel_time = document.Form1.HotelName.options[document.Form1.HotelName.selectedIndex].title;
	document.getElementById('hotel_text').innerHTML = "<em>Please schedule to leave <u><b>"+hotel_name+"</b></u> approximately "+hotel_time+" hours prior to departure</em>";
	
	/*var hotel_name = document.Form1.HotelName.options[document.Form1.HotelName.selectedIndex].id;
	document.getElementById('hotel_text').innerHTML = "<em>Please schedule to leave <u><b>"+hotel_name+"</b></u> approximately 3 hours prior to departure</em>";*/
}
function matchAirline_arrival(){
	document.Form1.DepartureAirline.value = document.Form1.ArrivalAirline.value;
}
function matchAirline_departure(){
	//document.Form1.ArrivalAirline.value = document.Form1.DepartureAirline.value;
}
function matchAirports_arrival(){
	document.Form1.DepartureAirport.selectedIndex = document.Form1.ArrivalAirport.selectedIndex;
}
function matchAirports_departure(){
	//document.Form1.ArrivalAirport.selectedIndex = document.Form1.DepartureAirport.selectedIndex;
}
function ArrivalmatchNumInParty(){
	document.Form1.DepartureNumInParty.value = document.Form1.arrivalNumInParty.value;
}
function DeparturematchNumInParty(){
	document.Form1.arrivalNumInParty.value = document.Form1.DepartureNumInParty.value;
}
function updateArrivalDepart(){
	if(document.Form1.arrival_only.options[document.Form1.arrival_only.selectedIndex].value=="yes"){
		//disable departure fields
		arrivalDisable();
	}else if(document.Form1.arrival_only.options[document.Form1.arrival_only.selectedIndex].value=="no"){
		//enable departure fields
		arrivalEnable();
	}
	if(document.Form1.departure_only.options[document.Form1.departure_only.selectedIndex].value=="yes"){
		//disable arrival fields
		departureDisable();
	}else if(document.Form1.departure_only.options[document.Form1.departure_only.selectedIndex].value=="no"){
		//enable arrival fields
		departureEnable();
	}
}
function arrivalDisable(){
	document.Form1.DepartureMonth.disabled="disabled";
	document.Form1.DepartureDay.disabled="disabled";
	document.Form1.DepartureYear.disabled="disabled";
	document.Form1.DepartureAirport.disabled="disabled";
	document.Form1.DepartureAirline.disabled="disabled";
	document.Form1.DepartureFlightNum.disabled="disabled";
	document.Form1.DepartureHour.disabled="disabled";
	document.Form1.DepartureMinute.disabled="disabled";
	document.Form1.DepartureAMPM.disabled="disabled";
	document.Form1.DepartureNumInParty.disabled="disabled";
	document.Form1.departure_only.disabled="disabled";
}
function arrivalEnable(){
	document.Form1.DepartureMonth.disabled="";
	document.Form1.DepartureDay.disabled="";
	document.Form1.DepartureYear.disabled="";
	document.Form1.DepartureAirport.disabled="";
	document.Form1.DepartureAirline.disabled="";
	document.Form1.DepartureFlightNum.disabled="";
	document.Form1.DepartureHour.disabled="";
	document.Form1.DepartureMinute.disabled="";
	document.Form1.DepartureAMPM.disabled="";
	document.Form1.DepartureNumInParty.disabled="";
	document.Form1.departure_only.disabled="";
}
function departureDisable(){
	document.Form1.ArrivalMonth.disabled="disabled";
	document.Form1.ArrivalDay.disabled="disabled";
	document.Form1.ArrivalYear.disabled="disabled";
	document.Form1.ArrivalAirport.disabled="disabled";
	document.Form1.ArrivalAirline.disabled="disabled";
	document.Form1.ArrivalFlightNum.disabled="disabled";
	document.Form1.ArrivalHour.disabled="disabled";
	document.Form1.ArrivalMinute.disabled="disabled";
	document.Form1.ArrivalAMPM.disabled="disabled";
	document.Form1.arrivalNumInParty.disabled="disabled";
	document.Form1.arrival_only.disabled="disabled";
}
function departureEnable(){
	document.Form1.ArrivalMonth.disabled="";
	document.Form1.ArrivalDay.disabled="";
	document.Form1.ArrivalYear.disabled="";
	document.Form1.ArrivalAirport.disabled="";
	document.Form1.ArrivalAirline.disabled="";
	document.Form1.ArrivalFlightNum.disabled="";
	document.Form1.ArrivalHour.disabled="";
	document.Form1.ArrivalMinute.disabled="";
	document.Form1.ArrivalAMPM.disabled="";
	document.Form1.arrivalNumInParty.disabled="";
	document.Form1.arrival_only.disabled="";
}

