var NUM_DOMESTIC = 26;

function cancelAmendBooking(pacificflag) {
	if(typeof(bookingScenario)=="undefined")bookingScenario="scenario_normal";
  	var er = '';
  	er += 'timestamp=' + getiTDTimeStamp();
	er += '&request_type=cancelBooking&locale=' + getLocale();
	if ((bookingScenario == 'scenario_iTDSplitImp')&&(pacificflag=="isPacific"||pacificflag=="nzPacific")){
		er = getiTDURL(getLocale(), 'iTDtasmanCOM') + "?" + er
	}else{
		er = getiTDURL(getLocale()) + "?" + er
	}
	
	var A = "This online service is temporarily unavailable.\n\nPlease contact Air New Zealand Reservations on ";
	var B = "\nto make amendments to your booking.";
	var MAU = A + "13 24 76" + B;
	var MNZ = A + "0800 737 000" + B;
	switch (bookingScenario) {
	
		case 'scenario_normal': 
			canceliTDNow(er); 
			break;
		case 'scenario_iTDRedemptionsDown': 
			canceliTDNow(er); 
			break;
		case 'scenario_iTDDown':
			if(getLocale() == "en_NZ"){
				alert(MNZ);
			}else{
				alert(MAU);				
			}	
			break;
		case 'scenario_iTDDownNZ':
			if(getLocale() == "en_NZ"){
				alert(MNZ);
			}else{
				canceliTDNow(er); 			
			}	
			break;
		case 'scenario_iTDDownAU':
			if(getLocale() == "en_AU"){
				alert(MAU);
			}else{
				canceliTDNow(er); 			
			}	
			break;
		case 'scenario_iTDTasDown':
			canceliTDNow(er); 
			break;
		case 'scenario_iTDPacDown':
			canceliTDNow(er); 
			break;
		case 'scenario_iTDPacTasDown':
			if((pacificflag=="isPacific"||pacificflag=="nzPacific")){
				if(getLocale() == "en_NZ"){
					alert(MNZ);
				}else{
					alert(MAU);				
				}			
			}else{
				canceliTDNow(er); 
			}
			break;
		case 'scenario_iTDTasDownNZ':	
			canceliTDNow(er); 
			break;
		case 'scenario_iTDTasDownAU':
			canceliTDNow(er); 
			break;
		case 'scenario_iTDPacTasDownNZ':
			if((pacificflag=="isPacific"||pacificflag=="nzPacific")&&getLocale() == "en_NZ"){
				alert(MNZ);		
			}else{
				canceliTDNow(er); 
			}
			break;
		case 'scenario_iTDPacTasDownAU':
			if((pacificflag=="isPacific"||pacificflag=="nzPacific")&&getLocale() == "en_AU"){
				alert(MAU);		
			}else{
				canceliTDNow(er); 
			}
			break;
		case 'scenario_iTDPacDownNZ':
			if((pacificflag=="isPacific"||pacificflag=="nzPacific")&&getLocale() == "en_NZ"){
				alert(MNZ);		
			}else{
				canceliTDNow(er); 
			}
			break;
		case 'scenario_iTDPacDownAU':
			if((pacificflag=="isPacific"||pacificflag=="nzPacific")&&getLocale() == "en_AU"){
				alert(MAU);		
			}else{
				canceliTDNow(er); 
			}
			break;
		case 'scenario_iTDSplitImp': 
			canceliTDNow(er); 
			break;	
		default: 
			canceliTDNow(er); 
			break;
	}	
}

	function bookiTDNow(theiTDurl,templocale){
		if(isPDA){
			if(getLocale()=="en_AU") alert(aupdamessage);
			else alert(nzpdamessage);	
		}else{
			winPop = window.open(theiTDurl, 'iTD', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=808,height=610,left=0,top=0');
			winPop.focus();
			if(bookingScenario=="scenario_iTDRedemptionsDown")popNoAPD(templocale);
		}
	}
	function canceliTDNow(theiTDurl){
		if(isPDA){
			if(getLocale()=="en_AU") alert(aupdamessage);
			else alert(nzpdamessage);	
		}else{
			winPop = window.open(theiTDurl, 'iTD', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=808,height=610,left=0,top=0');
			winPop.focus();
		}	
	}
	
	function wrapText(theText) {return '<table border="0" width="180" cellspacing="3" class="bgLightBlue"><tr><td align="center" class="Message"><br>' + theText + '</td></tr></table>';}	
		
	function getID(the_code) {
		switch (the_code) {
		case "AKL": return 0;
		case "KKE": return 1;
		case "BHE": return 2;
		case "CHC": return 3;
		case "DUD": return 4;
		case "GIS": return 5;
		case "HLZ": return 6;
		case "HKK": return 7;
		case "IVC": return 8;
		case "KAT": return 9;
		case "NPE": return 10;
		case "NSN": return 11;
		case "NPL": return 12;
		case "OAM": return 13;
		case "PMR": return 14;
		case "ZQN": return 15;
		case "ROT": return 16;
		case "TUO": return 17;
		case "TRG": return 18;
		case "TIU": return 19;
		case "WKA": return 20;
		case "WAG": return 21;
		case "WLG": return 22;
		case "WSZ": return 23;
		case "WHK": return 24;
		case "WRE": return 25;
		case "ADL": return 26;
		case "BNE": return 27;
		case "CNS": return 28;
		case "MEL": return 29;
		case "PER": return 30;
		case "SYD": return 31;
		case "NLK": return 32;
		case "APW": return 33;
		case "NAN": return 34;
		case "RAR": return 35;
		case "TBU": return 36;		
		case "IUE": return 37;		
		case "VLI": return 38;
		default : return '';
		}		
	}
		
	function getPrice(index, dept_city, dest_city) {
		var city1id = getID(dept_city);
		var city2id = getID(dest_city);
		if ((city1id > city2id) && (city1id<NUM_DOMESTIC)){
			tempvar = city2id;
			city2id = city1id;
			city1id = tempvar;
		}

		var ret_value = p_l[city1id][city2id][index-1];

		if (ret_value==null) ret_value='';
		return ret_value;
	}
	
	function roundUp(val){return Math.ceil(val);}	
	
	var the_dept_city = '';
	var the_dest_city = '';
	var the_fare_type = '';	
	
	function wrapEsaverText(theText) {
		return '<p align="center"><font class="Message">' + theText + '</font></p>';
	}

	function fn_express_city_select(calctype) {
		var msg = '', err = '';
		var return_price = 0;
		var oneway_price = 0;
		var return_tax = 0;
		var oneway_tax = 0;
		var sT = false; //showtaxes
		var includeTaxes = false; 
		var fareCalc = document.getElementById('fareCalc');
		var notch = document.getElementById('notch');
		var fareP = document.getElementById('fareP');
		var fareBot = document.getElementById('fareBot');
		var fareBotP = document.getElementById('fareBotP');
		var fPText = document.getElementById('fPText');

		fareCalc.style.width = '222px';
		notch.className= 'ssNotchS';
		fareP.style.display = 'none';
		fareBot.style.display = 'block';
		fareBotP.style.display = 'none';
				
		the_dept_city = document.frmVisible.elements["departure.point"].value;
		the_dest_city = document.frmVisible.elements["arrival.point"].value;
		the_fare_type = document.frmVisible.elements["fare.type"].value;
		
		sT = (getID(the_dept_city) >= NUM_DOMESTIC) || (getID(the_dest_city) >= NUM_DOMESTIC);
		includeTaxes = sT;
		
		if ((the_dept_city!=null) && (the_dept_city!='') && (the_dept_city == the_dest_city)) {
			err = 'Your destination cannot be the same as your point of origin.\n\nPlease change your request and search again.';
			alert(err);
		} else {
			if ((the_dept_city!='') && (the_dest_city !='')) {			
				//calculate one way price
				oneway_price = getPrice(1, the_dept_city, the_dest_city);
				
				//calculate tax is needed
				if(sT) oneway_tax = getPrice(2, the_dept_city, the_dest_city);
				if(sT) return_tax = getPrice(3, the_dept_city, the_dest_city);
				
			    if(oneway_price == "nr"){ //"nr" stands for "not ready";
 					err = 'Prices still loading. Please wait for page to finish loading – then try again.';
 					alert(err);
				}else{
					if (the_fare_type=='oneway') {
						if(sT && includeTaxes) {
							var online_price = oneway_price + oneway_tax;
							msg = formatLHSExpressOWPrice(online_price, null);
						} else if(sT) {
							msg = formatLHSExpressOWPrice(oneway_price, oneway_tax);
						} else {
							msg = formatLHSExpressOWPrice(oneway_price, null);		
						}
					} else {
						if(sT && includeTaxes){
							var online_price = (oneway_price * 2) + return_tax;
							msg = formatLHSExpressReturnPrice(online_price, null );
						} else if(sT){
							var online_price = (oneway_price) * 2;
							msg = formatLHSExpressReturnPrice(online_price, return_tax );
						}else{					
							var online_price = (oneway_price) * 2;		
							msg = formatLHSExpressReturnPrice(online_price, null);
						}
					}
				}
				if (msg == ''){
					err = 'There are no flights between the selected locations.\n\nPlease change locations and search again.';
					alert(err);
				}
			}
		}
		
		if (msg != ''){
			//styles of fare calculator
			fareCalc.style.width = '325px';
			notch.className= 'ssNotchW';
			fareP.style.display = 'block';
			fareBot.style.display = 'none';
			fareBotP.style.display = 'block';
	
			var h = 94;//height of fPText
		
			if (!cantUseLayers()) {
				if ((obj=MM_findObj("lhs_price_text"))!=null){
					obj.innerHTML = msg;
					if(fPText.clientHeight<94)
						fPText.style.paddingTop = h-fPText.clientHeight +'px';
					
				}
			} else {
				var NSLayer = document.layers["lhs_price_text_ns"];
				NSLayer.document.open();	
				NSLayer.document.write(msg);
				NSLayer.document.close();		
			}
		}		
	}
	
	function formatLHSExpressReturnPrice(online_price, thetaxvalue) {
		var ret_value = '';		
		if (online_price > 0) {
			ret_value = formatcalc("return airfare", online_price, thetaxvalue)
		}
		return ret_value;
	}
	
	function formatLHSExpressOWPrice(oneway_price, thetaxvalue) {
		var ret_value = '';	
		if (oneway_price > 0) {
			ret_value = formatcalc("one way airfare", oneway_price, thetaxvalue)
		}
		return ret_value;
	}

	function formatcalc(triptypetext, thetripvalue, thetaxesandcharges){
		formatcalcret_value = "";
		var roundedtaxes = roundUp(thetaxesandcharges);
		var roundedtripvalue = roundUp(thetripvalue);
		
		var o_msg = triptypetext + '<br />from<br /><div class="farePrice"><span class="fareDol">$</span>';
		o_msg += roundedtripvalue;
		o_msg += '</div><br />';
		if(typeof(thetaxesandcharges)!="undefined" && thetaxesandcharges!=null)o_msg += '<p>Plus airport &amp; govt costs</p><span class="farePrice2">$' + roundedtaxes + '</span>';
		else o_msg += '<p>&nbsp;<br />&nbsp;</p><span class="farePrice2">&nbsp;</span>';
		
		return o_msg;
	}
	

	function fn_express_city_select_airpoints(calctype) {

		var msg = '', err='';
		var return_price = 0;
		var oneway_price = 0;
		var return_tax = 0;
		var oneway_tax = 0;
		var sT = false; //showtaxes
		var fareCalc = document.getElementById('fareCalc');
		var notch = document.getElementById('notch');
		var fareP = document.getElementById('fareP');
		var fareBot = document.getElementById('fareBot');
		var fareBotP = document.getElementById('fareBotP');
		var fPText = document.getElementById('fPText');

		fareCalc.style.width = '222px';
		notch.className= 'ssNotchS';
		fareP.style.display = 'none';
		fareBot.style.display = 'block';
		fareBotP.style.display = 'none';
		
		the_dept_city = document.frmVisible.elements["departure.point"].value;
		the_dest_city = document.frmVisible.elements["arrival.point"].value;
		the_fare_type = document.frmVisible.elements["fare.type"].value;
		
		sT = (getID(the_dept_city) >= NUM_DOMESTIC) || (getID(the_dest_city) >= NUM_DOMESTIC);
		
		if ((the_dept_city!=null) && (the_dept_city!='') && (the_dept_city == the_dest_city)) {
			err = 'You have chosen the same city for departure and destination!\n\nPlease choose again';
			alert(err);
		} else {
			if ((the_dept_city!='') && (the_dest_city !='')) {			
				
				oneway_price = getPrice(1, the_dept_city, the_dest_city);
				
				//calculate tax is needed
				if(sT) oneway_tax = getPrice(2, the_dept_city, the_dest_city);
				if(sT) return_tax = getPrice(3, the_dept_city, the_dest_city);
				
			    if(oneway_price == "nr"){
					//"nr" stands for "not ready";
 					err = 'Prices still loading. Please wait for page to finish loading – then try again.';
 					alert(err);
				}else{
					if (the_fare_type=='oneway') {
						if(sT)
							msg = formatLHSExpressAirPointsPrice(the_fare_type, oneway_price, oneway_tax);		
						else
							msg = formatLHSExpressAirPointsPrice(the_fare_type, oneway_price, null);		
					} else {
						var online_price = parseInt((oneway_price) * 2);	
						if(sT)			
							msg = formatLHSExpressAirPointsPrice(the_fare_type, online_price, return_tax);
						else
							msg = formatLHSExpressAirPointsPrice(the_fare_type, online_price, null);
					}
				}
				if (msg == '')
				{
					err = 'Air New Zealand does not currently operate flights between these ports.\n\nPlease choose another option.';
					alert(err);
				}
			}
		}
		
		if(msg != '')
		{
			//styles of fare calculator
			fareCalc.style.width = '325px';
			notch.className= 'ssNotchW';
			fareP.style.display = 'block';
			fareBot.style.display = 'none';
			fareBotP.style.display = 'block';

			var h = 94;//height of fPText
			
			if (!cantUseLayers()) {
				if ((obj=MM_findObj("lhs_price_text"))!=null){
					obj.innerHTML = msg;
					
					//safari
					if (checkIt('safari')) browser = 'Safari'
					if (browser=='Safari'){
						if(fPText.clientHeight<94)
							fPText.style.paddingTop = h-fPText.clientHeight +'px';
						var airpoint_dollar = document.getElementById('airpoint_dollar');
						
						airpoint_dollar.style.left = '10px';
						airpoint_dollar.style.top = '14px';
					}
				}
			} else {
				var NSLayer = document.layers["lhs_price_text_ns"];
				NSLayer.document.open();	
				NSLayer.document.write(msg);
				NSLayer.document.close();				
			}
		}
	}
	
function formatLHSExpressAirPointsPrice(triptypetext, online_price, thetaxesandcharges) {
	var ret_value = '';
	if (online_price > 0) {
		var roundedprice = roundUp(online_price);
		var roundedtaxesandcharges = roundUp(thetaxesandcharges);
		//EM 24-10-02
		var online_msg = triptypetext + ' airfare<br />from<br /><div class="farePrice"><span class="fareDol"><img src="/NR/AirNZ/images/fff_airpointsdollar.gif" id="airpoint_dollar" width="10" height="11" alt="Airpoints Dollar. " title="Airpoints Dollar. " /></span>';
		online_msg += roundedprice;
		online_msg += '<span class="fareAst">*</span></div><br />';
		if(typeof(thetaxesandcharges)!="undefined" && thetaxesandcharges!=null)
			online_msg += '<p>Plus taxes &amp; surcharges</p><span class="farePrice2">$' + roundedtaxesandcharges + '</span>';
		else online_msg += '<p>&nbsp;<br />&nbsp;</p><span class="farePrice2">&nbsp;</span>';
		ret_value = online_msg;
	}
	return ret_value;
}
	
	
function getiTDTimeStamp(){
	var dDate = new Date();
	var formatteddate = new String(dDate.getFullYear());
	if (dDate.getDate() < 10) var thedays = new String("0" + dDate.getDate());
	else var thedays = new String(dDate.getDate());
	if (dDate.getMonth() < 9) var themonth = new String("0" + (dDate.getMonth()+1));
	else var themonth = new String((dDate.getMonth()+1));
	if (dDate.getHours() < 10) var thehours = new String("0" + dDate.getHours());
	else var thehours = new String(dDate.getHours());
	if (dDate.getMinutes() < 10) var themins = new String("0" + dDate.getMinutes());
	else var themins = new String(dDate.getMinutes());
	if (dDate.getSeconds() < 10) var thesecs = new String("0" + dDate.getSeconds());
	else var thesecs = new String(dDate.getSeconds());
	formatteddate += themonth + thedays + thehours + ":" + themins + ":" + thesecs;
	return formatteddate;
}

var arrMonths = [
	  ["ENE","1"],
      ["FEB","2"],
      ["MAR","3"],
      ["ABR","4"],
      ["MAYO","5"],
      ["JUN","6"],
      ["JUL","7"],
      ["AGO","8"],
      ["SEP","9"],
      ["OCT","10"],
      ["NOV","11"],
      ["DIC","12"]
];
var serviceClassesGetThere = [
    ["coach", "Economy: turista"],
    ["coach", "Economy"],
    ["business", "Business"]
]

function isgtclass(theclassvariable){
	classrtnval = false;
	for(k=0;k<serviceClassesGetThere.length;k++){
		if(theclassvariable.toUpperCase() == serviceClassesGetThere[k][1].toUpperCase())classrtnval = true;
	}
	return classrtnval;
}