var showPC1and2 = "no";
var showCashPrices = false;
var counter = 0;
function setShowCashPrices(showCash) {
  showCashPrices = showCash;
}

/**
 * creates the destination list based on selected departure port
 */
function createDestinationList(isInitialList) {
  var searchForm = document.getElementById('searchAgainForm');
  var origBox = searchForm.departAirportRef;
  var destBox = searchForm.destinationAirportRef;
  var origIndex = eval(origBox.selectedIndex);
  var orig = eval(origBox.options[ origIndex ].value);
  destBox.length = 0;
  if (!isInitialList) {
    destBox.options[0] = new Option('Please select');
    destBox.options[0].value = '';
  }
  if (orig != null) {
    for (var i = 0; i < orig.length; i++) {
      destBox.length += 1;
      destBox.options[destBox.length - 1] = new Option(eval('desc' + orig[i]));
      destBox.options[destBox.length - 1].value = orig[i];
      if (isInitialList && (orig[i] == destCode )) {
        destBox.options[destBox.length - 1].selected = true;
      }
    }
  }
  if (!isInitialList) {
    disableSearchAgainButton();
  }
}

/**
 * enable the search again button after change of value in searcg again form element
 */
function enableSearchAgainButton() {
  isSubmitAllowed = true;
  document.getElementById('searchAgainButton').src = '/images/buttons/LOZ_search-again02.gif';
  document.getElementById('searchAgainButton').className= 'pointerCursor';
}

function disableSearchAgainButton() {
  isSubmitAllowed = false;
  obj = document.getElementById('searchAgainButton');
  if( obj != null ) {
    obj.src = '/images/buttons/LOZ_search-again02_OFF.gif';
    obj.className= 'defaultCursor';
  }
}

/**
 * check the flag and submit the form if apporpriate
 */
function submitSearchAgainForm() {
  if( isSubmitAllowed ) {
    var searchForm = document.getElementById('searchAgainForm');
    searchForm.submit();
    disableSearchAgainButton();
  }
}

/**
 * updates the total summary box while calendar inbound dates are being selected
 */
function updateTotalSummaryBox( selDate, isWizard, showPC1_2 ) {
  var dateArray 	= selDate.split("-");
  var inbound		= "day_" + dateArray[0] + dateArray[1] + dateArray[2];
  var outbound		= selectedOutboundPrices;
  var newHTML 		= new Array();
  var newHTMLString = '';
  newHTML.push( 'Prices per adult (return)<br>\n' );
  newHTML.push( '<span class="txtBoldBlu">' + (outbound[0] + eval(inbound)[0]) +' miles</span><br>\n' );
  if( showPC1_2 == "hide" ) {
  	newHTML.push( '<div id="tot_SummaryDetails" style="display: none;">' );
  } else {
  	newHTML.push( '<div id="tot_SummaryDetails">' );
  }
  if( outbound[1] != 0 && eval(inbound)[1] != 0 && outbound[2] != 0 && eval(inbound)[2] != 0 ) {
  	newHTML.push( 'or ' + (outbound[1] + eval(inbound)[1]) + ' miles + &pound;' + roundTo2Decs(outbound[2] + eval(inbound)[2]) + '<br>\n' );
  }
  if( outbound[3] != 0 && eval(inbound)[3] != 0 && outbound[4] != 0 && eval(inbound)[4] != 0 ) {
    newHTML.push( 'or ' + (outbound[3] + eval(inbound)[3]) + ' miles + &pound;' + roundTo2Decs(outbound[4] + eval(inbound)[4]) + '<br>\n' );
  }
  newHTML.push( '</div>' );
  if( showCashPrices && outbound[5] != 0 && eval(inbound)[5] != 0 ) {
    if(!(isWizard)) {
      newHTML.push( 'or &pound;' + roundTo2Decs(outbound[5] + eval(inbound)[5]) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em></a><br>\n' );
    } else {
      newHTML.push( 'or &pound;' + roundTo2Decs(outbound[5] + eval(inbound)[5]) + ' <em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em><br>\n' );
    }

  }
  newHTML.push( '<br class="spacey3">\n' );
  newHTML.push( "Including airline taxes, fees <br>and charges\n" );
  newHTMLString = newHTML.join('');
  document.getElementById('totalsSummary').innerHTML = newHTMLString;
  var voucherInfo = document.getElementById("voucherInfo");
  if( voucherInfo != null ) { voucherInfo.style.display = ""; }
}

/**
 * rounds the given value to decimal places
 */
function roundTo2Decs(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

/**
 * enable the get flight buttons once the outbound and inbound dates have been selected
 */
function enableGetFlightsButton() {
  //isGetFlightsSubmitAllowed = true;
  if(document.layers) {
    document.images['getFlightsImg'].src = '/images/buttons/LOZ_get-flights01.gif';
  }else {
    document.getElementById('getFlightsImg').src = '/images/buttons/LOZ_get-flights01.gif';
    document.getElementById('getFlightsImg').className= 'pointerCursor';
  }
}

/**
 * disable the get flight buttons once the flight results are displayed
 */
function disableGetFlightsButton() {
  //isGetFlightsSubmitAllowed = false;
  document.getElementById('getFlightsImg').src = '/images/buttons/LOZ_get-flights01_OFF.gif';
  document.getElementById('getFlightsImg').className= 'defaultCursor';
}

/**
 * constructs an array of tabs to be displayed based upon user search criteria, always shows
 * adults and total tabs, optionally shows child and infant tab.
 */
function showTabs() {
  var tabsStringArray = new Array();
  var tabsHTMLString = '';

  tabsStringArray.push('<a href="javascript:void(0);" onClick="javascript:showFares(\'adult\');">');
  tabsStringArray.push('<img src="/images/tabs/tab_adult_on.gif" width="45" height="24" alt="Adult" border="0" id="adultTab">');
  tabsStringArray.push('</a>');
  if( numOfChildren > 0 ) {
    tabsStringArray.push('<a href="javascript:void(0);" onClick="javascript:showFares(\'child\');">');
    tabsStringArray.push('<img src="/images/tabs/tab_child_off.gif" width="44" height="24" alt="Child" border="0" id="childTab">');
    tabsStringArray.push('</a>');
  }
  if( numOfInfants > 0 ) {
    tabsStringArray.push('<a href="javascript:void(0);" onClick="javascript:showFares(\'infant\');">');
    tabsStringArray.push('<img src="/images/tabs/tab_infant_off.gif" width="44" height="24" alt="Infant" border="0" id="infantTab">');
    tabsStringArray.push('</a>');
  }
  tabsStringArray.push('<a href="javascript:void(0);" onClick="javascript:showFares(\'total\');">');
  tabsStringArray.push('<img src="/images/tabs/TAB_total02_off.gif" width="44" height="24" alt="Total" border="0" id="totalTab">');
  tabsStringArray.push('</a>');

  if( numOfChildren == 0 ) { // add a spacer to maintain appropriate width
    tabsStringArray.push('<img src="/images/common/1px_blu_w44.gif" width="44" height="24" alt="">');
  }

  if( numOfInfants == 0 ) {
    tabsStringArray.push('<img src="/images/common/1px_blu_w44.gif" width="44" height="24" alt="">');
  }
  tabsStringArray.push('<img src="/images/common/1px_blu_w44.gif" width="44" height="24" alt="">');

  tabsHTMLString = tabsStringArray.join('');
  return tabsHTMLString;
}

function showNewTabs() {
	  var allTabArray = new Array();
	  if (activeTab == 'adult') {
	    allTabArray.push('<li class="end sel" id="adultTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
	    allTabArray.push('Adult</a></li>');
	    if( numOfChildren > 0 ) {
	      allTabArray.push('<li id="childTab">');
	      allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
	      allTabArray.push('Child</a></li>');
	    }
	    if( numOfInfants > 0 ) {
	      allTabArray.push('<li id="infantTab">');
	      allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
	      allTabArray.push('Infant</a></li>');
	    }
	    allTabArray.push('<li id="totalTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
	    allTabArray.push('Total</a></li>');
	  } else if ( activeTab == 'child' && numOfChildren > 0 ) {
	    allTabArray.push('<li id="adultTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
	    allTabArray.push('Adult</a></li>'); 
	    allTabArray.push('<li class="end sel" id="childTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
	    allTabArray.push('Child</a></li>');
	    if( numOfInfants > 0 ) {
	      allTabArray.push('<li id="infantTab">');
	      allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
	      allTabArray.push('Infant</a></li>');
	    }
	    allTabArray.push('<li id="totalTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
	    allTabArray.push('Total</a></li>');
	  } else if( activeTab == 'infant' && numOfInfants > 0 ) {
	    allTabArray.push('<li id="adultTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
	    allTabArray.push('Adult</a></li>');
	    if( numOfChildren > 0 ) {
	      allTabArray.push('<li id="childTab">');
	      allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
	      allTabArray.push('Child</a></li>');
	    }
	     allTabArray.push('<li class="end sel" id="infantTab">');
	     allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
	     allTabArray.push('Infant</a></li>');
	    allTabArray.push('<li id="totalTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
	    allTabArray.push('Total</a></li>');
	  } else if (activeTab == 'total') {
	    allTabArray.push('<li id="adultTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
	    allTabArray.push('Adult</a></li>');
	    if( numOfChildren > 0 ) {
	     allTabArray.push('<li id="childTab">');
	     allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
	     allTabArray.push('Child</a></li>');
	    }
	    if( numOfInfants > 0 ) {
	     allTabArray.push('<li id="infantTab">');
	     allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
	     allTabArray.push('Infant</a></li>');
	    }
	    allTabArray.push('<li class="end sel" id="totalTab">');
	    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
	   allTabArray.push('Total</a></li>');
	  }
	   var newHTMLString 	= '';
	   newHTMLString = allTabArray.join('');
	  return newHTMLString;
}

function showNewFares( option, isWizard ) {
  var outboundId 	= getOutboundFlightId();
  var inboundId		= getInboundFlightId();

  if( option == 'adult' ) {
    activeTab = 'adult';
    displayNewTotals("outboundAdultPrices_"+outboundId, "inboundAdultPrices_"+inboundId, isWizard); 	

  } else if ( option == 'child' && numOfChildren > 0 ) {
    activeTab = 'child';
    displayNewTotals("outboundChildPrices_"+outboundId, "inboundChildPrices_"+inboundId, isWizard);

  } else if ( option == 'infant' && numOfInfants > 0 ) {
    activeTab = 'infant';
    displayNewTotals("outboundInfantPrices_"+outboundId, "inboundInfantPrices_"+inboundId, isWizard);
  } else if ( option == 'total' ) {
    activeTab 			= 'total';
    var newHTML 		= new Array();
    var newHTMLString 	= '';
    var totalsSummary 	= document.getElementById("totalsBox");
    newHTML.push( '<ul><li class="prom">' + calcTotals(outboundId,inboundId,0) +' miles</li>\n' );
    var pc1Miles = calcTotals(outboundId,inboundId,1);
    var pc1Cash = calcTotals(outboundId,inboundId,2);
    if( pc1Miles != 0 && pc1Cash != 0 ) {
    	newHTML.push( '<li>or ' + pc1Miles + ' miles + &pound;' + roundTo2Decs(pc1Cash) + '</li>' );
    }
    var pc2Miles = calcTotals(outboundId,inboundId,3);
    var pc2Cash = calcTotals(outboundId,inboundId,4);
    if( pc2Miles != 0 && pc2Cash != 0 ) {
    	newHTML.push( '<li>or ' + pc2Miles + ' miles + &pound;' + roundTo2Decs(pc2Cash) + '</li>' );
    }
    
    if(eval("outboundAdultPrices_"+outboundId)[5] != 0 && eval("inboundAdultPrices_"+inboundId)[5] != 0 ) {
      if(!(isWizard)) {
        newHTML.push( '<li>or &pound;' + roundTo2Decs( calcTotals(outboundId, inboundId, 5) ) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( calcTotals(outboundId,inboundId,6) ) + ' miles</em></a></li>' );
      } else {
        newHTML.push( '<li>or &pound;' + roundTo2Decs( calcTotals(outboundId, inboundId, 5) ) + ' <em>and receive ' + Math.floor( calcTotals(outboundId,inboundId,6) ) + ' miles</em></li>' );
      }

    }
    newHTML.push( '</ul>');
    newHTML.push( '</div>' );
    newHTMLString = newHTML.join(''); 
    totalsSummary.innerHTML = newHTMLString;
  }
  displayNewMessage(option);
  changeCss(option);
}

function displayNewTotals(inbound, outbound, isWizard) {
  var newHTML 			= new Array();
  var newHTMLString 	= '';
  var totalsSummary 	= document.getElementById("totalsBox");
  newHTML.push( '<ul><li class="prom">' + (eval(outbound)[0] + eval(inbound)[0]) +' miles</li>' );
  if( eval(outbound)[1] != 0 && eval(inbound)[1] != 0 && eval(outbound)[2] != 0 && eval(inbound)[2] != 0) {
  	newHTML.push( '<li>or ' + (eval(outbound)[1] + eval(inbound)[1]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[2] + eval(inbound)[2]) + '</li>' );
  }
  if( eval(outbound)[3] != 0 && eval(inbound)[3] != 0 && eval(outbound)[4] != 0 && eval(inbound)[4] != 0 ) {
  	newHTML.push( '<li>or ' + (eval(outbound)[3] + eval(inbound)[3]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[4] + eval(inbound)[4]) + '</li>' );
  }
  newHTML.push( '</div>' );
  if( showCashPrices && eval(outbound)[5] != 0 && eval(inbound)[5] != 0 ) {
    if(!(isWizard)) {
      newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em></a><br>\n' );
    } else {
        newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em><br>\n' );
    }
  }
  newHTML.push( '</ul>');
  newHTMLString = newHTML.join(''); 
  totalsSummary.innerHTML = newHTMLString;
}

function changeCss(option){
var allTab = document.getElementById("allTab");
var allTabArray = new Array();
if (option == 'adult') {
  allTabArray.push('<li class="end sel" id="adultTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
  allTabArray.push('Adult</a></li>');
  if( numOfChildren > 0 ) {
    allTabArray.push('<li id="childTab">');
    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
    allTabArray.push('Child</a></li>');
  }
  if( numOfInfants > 0 ) {
    allTabArray.push('<li id="infantTab">');
    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
    allTabArray.push('Infant</a></li>');
  }
  allTabArray.push('<li id="totalTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
  allTabArray.push('Total</a></li>');
} else if ( option == 'child' && numOfChildren > 0 ) {
  allTabArray.push('<li id="adultTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
  allTabArray.push('Adult</a></li>'); 
  allTabArray.push('<li class="end sel" id="childTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
  allTabArray.push('Child</a></li>');
  if( numOfInfants > 0 ) {
    allTabArray.push('<li id="infantTab">');
    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
    allTabArray.push('Infant</a></li>');
  }
  allTabArray.push('<li id="totalTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
  allTabArray.push('Total</a></li>');
} else if( option == 'infant' && numOfInfants > 0 ) {
  allTabArray.push('<li id="adultTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
  allTabArray.push('Adult</a></li>');
  if( numOfChildren > 0 ) {
    allTabArray.push('<li id="childTab">');
    allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
    allTabArray.push('Child</a></li>');
  }
   allTabArray.push('<li class="end sel" id="infantTab">');
   allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
   allTabArray.push('Infant</a></li>');
  allTabArray.push('<li id="totalTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
  allTabArray.push('Total</a></li>');
} else if (option == 'total') {
  allTabArray.push('<li id="adultTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'adult\');">');
  allTabArray.push('Adult</a></li>');
  if( numOfChildren > 0 ) {
   allTabArray.push('<li id="childTab">');
   allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'child\');">');
   allTabArray.push('Child</a></li>');
  }
  if( numOfInfants > 0 ) {
   allTabArray.push('<li id="infantTab">');
   allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'infant\');">');
   allTabArray.push('Infant</a></li>');
  }
  allTabArray.push('<li class="end sel" id="totalTab">');
  allTabArray.push('<a href="javascript:void(0);" onClick="javascript:showNewFares(\'total\');">');
 allTabArray.push('Total</a></li>');
}
 var newHTMLString 	= '';
 newHTMLString = allTabArray.join(''); 
 allTab.innerHTML = newHTMLString;
}

function displayNewMessage(option) {
var newHTML 			= new Array();
  var newHTMLString 	= '';
  var totalsSummary 	= document.getElementById("pTypeMsg");
if( option == 'adult' ) {
    newHTML.push( 'Prices per adult (return)');
  } else if ( option == 'child' && numOfChildren > 0 ) {
    newHTML.push( 'Prices per child (return)');
  } else if ( option == 'infant' && numOfInfants > 0 ) {
    newHTML.push( 'Prices per infant (return)');
  } else if ( option == 'total' ) {
    newHTML.push( 'Total for all travellers (return)\n' );
    
}
newHTML.push( '<span>Including airline taxes, fees &amp; charges</span><a href="javascript:gotoFareRules();" class="emph">Fare rules</a>');
	newHTMLString = newHTML.join(''); 
 totalsSummary.innerHTML = newHTMLString;
}

function gotoFareRules() {
    var formObj = document.forms.findADealFlightResultsForm;
    formObj.performAction.value = 'showFareRules';
    formObj.submit();
  }

/**
 * testing
 */
function displayTabs( currentTab ) {
  switch( currentTab ) {
    case( currentTab == "adult" ):
  }
}

/**
 * helper to switch off any tabs that may be on
 */
function turnOffAllTabs() {
  document.images['adultTab'].src = '/images/tabs/tab_adult_off.gif';
  if( numOfChildren > 0 ) { document.images['childTab'].src = '/images/tabs/tab_child_off.gif'; }
  if( numOfInfants > 0 ) { document.images['infantTab'].src = '/images/tabs/tab_infant_off.gif'; }
  document.images['totalTab'].src = '/images/tabs/TAB_total02_off.gif';
}

function syncTotalSummaryBox( inbound, outbound, isWizard ) {
  var newHTML 			= new Array();
  var newHTMLString 	= '';

  newHTML.push( 'Prices per adult (return)<br>\n' );
  newHTML.push( '<span class="txtBoldBlu">' + (eval(outbound)[0] + eval(inbound)[0]) +' miles</span><br>\n' );
  if( showPC1and2 == "no" ) {
  	newHTML.push( '<div id="tot_SummaryDetails" style="display: none;">' );
  } else {
  	newHTML.push( '<div id="tot_SummaryDetails">' );
  }
  if( eval(outbound)[1] != 0 && eval(inbound)[1] != 0 && eval(outbound)[2] != 0 && eval(inbound)[2] != 0 ) {
  	newHTML.push( 'or ' + (eval(outbound)[1] + eval(inbound)[1]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[2] + eval(inbound)[2]) + '<br>\n' );
  }
  if( eval(outbound)[3] != 0 && eval(inbound)[3] != 0 && eval(outbound)[4] != 0 && eval(inbound)[4] != 0 ) {
  	newHTML.push( 'or ' + (eval(outbound)[3] + eval(inbound)[3]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[4] + eval(inbound)[4]) + '<br>\n' );
	}
  newHTML.push( '</div>' );
  if( showCashPrices && eval(outbound)[5] != 0 && eval(inbound)[5] != 0 ) {
    if(!(isWizard)) {
      newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em></a><br>\n' );
    } else {
      newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em><br>\n' );
    }

  }
  newHTML.push( '<br class="spacey3">\n' );
  newHTML.push( "Including airline taxes, fees <br>and charges\n" );
  newHTMLString = newHTML.join('');
  document.getElementById('totalsSummary').innerHTML = newHTMLString;
}

/**
 * display totals beneath the flight results
 */
function displayTotals( message, inbound, outbound, isWizard) {
  var newHTML 			= new Array();
  var newHTMLString 	= '';
  var totalsSummary 	= document.getElementById("totalsBox");

  newHTML.push( message+'<br>\n' );
  newHTML.push( '<span class="txtBoldBlu">' + (eval(outbound)[0] + eval(inbound)[0]) +' miles</span><br>\n' );
  if( showPC1and2 == "no" ) {
  	newHTML.push( '<div id="tot_BottomTabs" style="display:none;">' );
  } else {
  	newHTML.push( '<div id="tot_BottomTabs">' );
  }
  if( eval(outbound)[1] != 0 && eval(inbound)[1] != 0 && eval(outbound)[2] != 0 && eval(inbound)[2] ) {
  	newHTML.push( 'or ' + (eval(outbound)[1] + eval(inbound)[1]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[2] + eval(inbound)[2]) + '<br>\n' );
  }
  if( eval(outbound)[3] != 0 && eval(inbound)[3] != 0 && eval(outbound)[4] != 0 && eval(inbound)[4] ) {
  	newHTML.push( 'or ' + (eval(outbound)[3] + eval(inbound)[3]) + ' miles + &pound;' + roundTo2Decs(eval(outbound)[4] + eval(inbound)[4]) + '<br>\n' );
  }
  newHTML.push( '</div>' );
  if( showCashPrices && eval(outbound)[5] != 0 && eval(inbound)[5] != 0 ) {
    if(!(isWizard)) {
      newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em></a><br>\n' );
    } else {
        newHTML.push( 'or &pound;' + roundTo2Decs(eval(outbound)[5] + eval(inbound)[5]) + ' <em>and receive ' + Math.floor( eval(outbound)[6] + eval(inbound)[6] ) + ' miles</em><br>\n' );
    }
  }
  newHTMLString = newHTML.join('');
  totalsSummary.innerHTML = newHTMLString;
}

/**
 * return the selected outbound flight id from the flight results
 */
function getOutboundFlightId() {
  var outboundFlightObj 	= document.forms.findADealFlightResultsForm.outboundFlightId;
  var oFlightId			= 0;
  if( outboundFlightObj.length == undefined ) {
	oFlightId = outboundFlightObj.value;
  } else {
	for( var i = 0; i < outboundFlightObj.length; i++ ) {
   	  if (document.forms.findADealFlightResultsForm.outboundFlightId[i].checked) {
        oFlightId = document.forms.findADealFlightResultsForm.outboundFlightId[i].value;
      }
    }
  }
  return oFlightId;
}

/**
 * return the selected inbound flight id from the flight results
 */
function getInboundFlightId() {
  var inboundFlightObj	= document.forms.findADealFlightResultsForm.inboundFlightId;
  var iFlightId			= 0;
  if( inboundFlightObj.length == undefined ) {
	iFlightId = inboundFlightObj.value;
  } else {
	for( var i = 0; i < inboundFlightObj.length; i++ ) {
   	  if (document.forms.findADealFlightResultsForm.inboundFlightId[i].checked) {
        iFlightId = document.forms.findADealFlightResultsForm.inboundFlightId[i].value;
      }
    }
  }
  return iFlightId;
}

/**
 * main function to display the totals based on user selection
 */
function showFares( option, isWizard ) {
  var outboundId 	= getOutboundFlightId();
  var inboundId		= getInboundFlightId();
  turnOffAllTabs();

  if( option == 'adult' ) {
    document.images['adultTab'].src = '/images/tabs/tab_adult_on.gif';
    activeTab = 'adult';
    displayTotals( 'Prices per adult (return)', "outboundAdultPrices_"+outboundId, "inboundAdultPrices_"+inboundId, isWizard);
  	syncTotalSummaryBox( "outboundAdultPrices_"+outboundId, "inboundAdultPrices_"+inboundId, isWizard);

  } else if ( option == 'child' && numOfChildren > 0 ) {
    document.images['childTab'].src = '/images/tabs/tab_child_on.gif';
    activeTab = 'child';
    displayTotals( 'Prices per child (return)', "outboundChildPrices_"+outboundId, "inboundChildPrices_"+inboundId, isWizard);

  } else if ( option == 'infant' && numOfInfants > 0 ) {
    document.images['infantTab'].src = '/images/tabs/tab_infant_on.gif';
    activeTab = 'infant';
    displayTotals( 'Prices per infant (return)', "outboundInfantPrices_"+outboundId, "inboundInfantPrices_"+inboundId, isWizard);

  } else if ( option == 'total' ) {
    document.images['totalTab'].src = '/images/tabs/TAB_total02_on.gif';
    activeTab 			= 'total';
    var newHTML 		= new Array();
    var newHTMLString 	= '';
    var totalsSummary 	= document.getElementById("totalsBox");

    newHTML.push( 'Total for all travellers (return)<br>\n' );
    newHTML.push( '<span class="txtBoldBlu">' + calcTotals(outboundId,inboundId,0) +' miles</span><br>\n' );
    if( showPC1and2 == "no" ) {
    	newHTML.push( '<div id="tot_BottomTabs" style="display:none;">' );
    } else {
    	newHTML.push( '<div id="tot_BottomTabs">' );
    }
    var pc1Miles = calcTotals(outboundId,inboundId,1);
    var pc1Cash = calcTotals(outboundId,inboundId,2);
    if( pc1Miles != 0 && pc1Cash != 0 ) {
    	newHTML.push( 'or ' + pc1Miles + ' miles + &pound;' + roundTo2Decs(pc1Cash) + '<br>\n' );
    }
    var pc2Miles = calcTotals(outboundId,inboundId,3);
    var pc2Cash = calcTotals(outboundId,inboundId,4);
    if( pc2Miles != 0 && pc2Cash != 0 ) {
    	newHTML.push( 'or ' + pc2Miles + ' miles + &pound;' + roundTo2Decs(pc2Cash) + '<br>\n' );
    }
    newHTML.push( '</div>' );
    if( showCashPrices && eval("outboundAdultPrices_"+outboundId)[5] != 0 && eval("inboundAdultPrices_"+inboundId)[5] != 0 ) {
      if(!(isWizard)) {
        newHTML.push( 'or &pound;' + roundTo2Decs( calcTotals(outboundId, inboundId, 5) ) + ' <a href="collect/milesback/collect-miles-on-your-travel" target="_blank" class="link02"><em>and receive ' + Math.floor( calcTotals(outboundId,inboundId,6) ) + ' miles</em></a><br>\n' );
      } else {
        newHTML.push( 'or &pound;' + roundTo2Decs( calcTotals(outboundId, inboundId, 5) ) + ' <em>and receive ' + Math.floor( calcTotals(outboundId,inboundId,6) ) + ' miles</em><br>\n' );
      }

    }
    newHTMLString = newHTML.join('');
    totalsSummary.innerHTML = newHTMLString;
  }
}

/**
 * returns the total value for each element for the totals tab, ignoring zero prices, as these payment options will not be offered.
 */
function calcTotals( o, i, index ) {
  var outbound 		= "outboundAdultPrices_"+o;
  var inbound 		= "inboundAdultPrices_"+i;
  var outboundC 	= "outboundChildPrices_"+o;
  var inboundC 		= "inboundChildPrices_"+i;
  var outboundI 	= "outboundInfantPrices_"+o;
  var inboundI 		= "inboundInfantPrices_"+i;
  var total			= 0;

  if( eval(outbound)[index] == 0 || eval(inbound)[index] == 0 ) {
    return 0;
  }else {
    total += (eval(outbound)[index] + eval(inbound)[index]) * numOfAdults;
  }

  if( numOfChildren > 0 ) {
    if( eval(outboundC)[index] == 0 || eval(inboundC)[index] == 0 ) {
      return 0;
    }else {
      total += (eval(outboundC)[index] + eval(inboundC)[index]) * numOfChildren;      
    }
  }

  if( numOfInfants > 0 ) {
    if( eval(outboundI)[index] == 0 || eval(inboundI)[index] == 0 ) {
      return 0;
    }else {
      total += (eval(outboundI)[index] + eval(inboundI)[index]) * numOfInfants;     
    }
  }
  return total;
}

/**
 * submit the flight selection
 */
function submitFlightSelection() {
  var formObj = document.forms.findADealFlightResultsForm;
  formObj.performAction.value = '';
  formObj.submit();
}

/**
 * called after a page had been loaded to check if the summary box needs to be populated with prices
 */
function isDisplaySummryBox(isWizard) {
  if( typeof selectedOutboundPrices != 'undefined' ) {
    if( selectedOutboundPrices != null && selectedOutboundPrices.length > 0 && selectedInboundDayID != null && selectedInboundDayID.length > 0 ) {
      var tmpD = selectedInboundDayID.split('_');
      updateTotalSummaryBox( tmpD[0],isWizard);
    }
  }
}

function loadNewURL( theURL ) {
  document.location.href = theURL;
}

function swapStepOneImg() {
  if(document.layers) {
    document.images['stepOneImg'].src = '/images/homeshop/IMGT_step01_ON.gif';
  }else {
    var obj = document.getElementById('stepOneImg');
    if( obj != null ) { obj.src = '/images/homeshop/IMGT_step01_ON.gif'; }
  }
}

function showHideTotalsPC1and2() {
	if( anyElementsVisible('div','ob') || anyElementsVisible('div','ib') ) {
		showHideElement('tot_BottomTabs', 'show');
		showHideElement('tot_SummaryDetails', 'show');
		showPC1and2 = "yes";
	} else {
		showHideElement('tot_BottomTabs', 'hide');
		showHideElement('tot_SummaryDetails', 'hide');
		showPC1and2 = "no";
	}
}

function showPricingOptionsDealsPage() {
  showHideMultipleElements("div", "tot", "show");
  showHideMultipleElements("div", "ob", "show");
  showHideMultipleElements("div", "ib", "show");
  obj = document.getElementById('globalSwitch');
  if( obj != null ) {
    obj.innerHTML = '<a class="link02" href="javascript:void(0);" onClick="hidePricingOptionsDealsPage();">Hide price options</a>';
  }
  showPC1and2 = "yes";
  changeAllSwitches('span', 'switch_ob', 'Hide price options');
  changeAllSwitches('span', 'switch_ib', 'Hide price options');
  var globalSetting	= document.forms.findADealFlightResultsForm.globalSwitchSetting;
 	globalSetting.value = "show";
}

function hidePricingOptionsDealsPage() {
  showHideMultipleElements("div", "tot", "hide");
  showHideMultipleElements("div", "ob", "hide");
  showHideMultipleElements("div", "ib", "hide");
  obj = document.getElementById('globalSwitch')
  if( obj != null ) {
  	obj.innerHTML = '<a class="link02" href="javascript:void(0);" onClick="showPricingOptionsDealsPage();">View all price options</a>';
  }
  showPC1and2 = "no";
  changeAllSwitches('span', 'switch_ob', 'More price options');
  changeAllSwitches('span', 'switch_ib', 'More price options');
  var globalSetting	= document.forms.findADealFlightResultsForm.globalSwitchSetting;
  globalSetting.value = "hide";
}

var showGlobalSwitch = false;

function hideGlobalPricingSwitch() {
	if( !showGlobalSwitch  ) {
		switchElementVisibility('globalSwitchRow');
	}
}

function enableCurrentStepImage( step ) {
  var stepOne = document.getElementById('stepOneImage');
  var stepTwo = document.getElementById('stepTwoImage');
  var stepThree = document.getElementById('stepThreeImage');

  if( step == 1 ) {
    if( stepOne != null )   { stepOne.src = '/images/homeshop/IMGT_step01_ON.gif'; }
    if( stepTwo != null )   { stepTwo.src = '/images/homeshop/IMGT_step02_OFF.gif'; }
    if( stepThree != null ) { stepThree.src = '/images/homeshop/IMGT_step03_OFF.gif'; }
  } else if( step == 2 ) {
    if( stepOne != null )   { stepOne.src = '/images/homeshop/IMGT_step01_OFF.gif'; }
    if( stepTwo != null )   { stepTwo.src = '/images/homeshop/IMGT_step02_ON.gif'; }
    if( stepThree != null ) { stepThree.src = '/images/homeshop/IMGT_step03_OFF.gif'; }
  } else {
    if( stepOne != null )   { stepOne.src = '/images/homeshop/IMGT_step01_OFF.gif'; }
    if( stepTwo != null )   { stepTwo.src = '/images/homeshop/IMGT_step02_OFF.gif'; }
    if( stepThree != null ) { stepThree.src = '/images/homeshop/IMGT_step03_ON.gif'; }
  }
}

