var _jssStartingFrom_en = 'Starting at: ';
var _jssStartingFrom_fr = '&Agrave; partir de : ';

function rewards_airRewardChart_sortCountries(stateBox)
{
  var countrySelect = stateBox;
  
  var selectedIndex = countrySelect.selectedIndex;
  var selectedCode = null;
  if(selectedIndex > 2)
  {
    selectedCode = countrySelect.options[selectedIndex].value;
  }
  
  // Sort the countries, skipping the first five elements because they
  // aren't part of the list of countries
  for(var i = 5; i < countrySelect.options.length; i++)
  {
    var min = i;
    var j = 0;
    for(j = i + 1; j < countrySelect.options.length; j++)
    {
      if( countrySelect.options[j].text < countrySelect.options[min].text )
        min = j;
    }
    var temp = new Option(countrySelect.options[min].text, countrySelect.options[min].value, countrySelect.options[min].defaultSelected, countrySelect.options[min].selected);
    countrySelect.options[min] = new Option(countrySelect.options[i].text, countrySelect.options[i].value, countrySelect.options[i].defaultSelected, countrySelect.options[i].selected);
    countrySelect.options[i] = temp;
  }
  
  for(var i = 5; i < countrySelect.options.length; i++)
  {
    if(countrySelect.options[i].value == selectedCode)
    {
      countrySelect.selectedIndex = i;
      return;
    }
  }
}


function initComboBox(){

	//If no origin country is selected, disable all the combo boxes and the view chart button
	if ($('originCountry').value == ''){
		$('originState').disabled = true;
		$('destinationCountry').disabled = true;
		$('destinationState').disabled = true;
		
		//Disable the view chart button and set the proper classname
		$('viewRewardChartButton').disabled = true;
		$('viewRewardChartButton').className = 'action-button-disabled';
	}
	else{ 
		//First we clear its content before adding the new one
		//We arbitraily set it to 54 due to some strange behaviour when cleaning the box
		//At most 52 states + 2 first that never gets removed = 54 	
		for(var i = 2; i < 54; i++)
		{
			$('originState').options[2] = null;
		}		
	
		if ($('originCountry').value == 'CA' || $('originCountry').value == 'US'){
			// Load and enable the origin state
			rewards_airRewardChart_loadStates($('originCountry').value, $('originState'), selectedOriginState);
			$('originState').disabled = false;
			
			//Disable the view chart button and set the proper classname because a state/province must be selected
			$('viewRewardChartButton').disabled = true;
			$('viewRewardChartButton').className = 'action-button-disabled';			
		}
		else{
			//Keep it disable
			$('originState').disabled = true;
			
			//Enable the view chart button and set the proper classname
			$('viewRewardChartButton').disabled = false;
			$('viewRewardChartButton').className = 'action-button';				
		}
		
		//Enable destination boxes
		$('destinationCountry').disabled = false;
		
		if ($('destinationCountry').value == 'US' || $('destinationCountry').value == 'CA'){
			$('destinationState').disabled = false;	
		}
	}
}

/*
 * Created by Michael Daniaux
 * The 10th may 2007
 *
 * Modified by Sochea MEAS
 * 31/10/2007
 */
function rewards_airRewardChart_originCountryOnChange(){
	initComboBox();
}

/*
 * Created by Michael Daniaux
 * The 10th may 2007
 *
 * Modified by Sochea MEAS
 * 31/10/2007
 */
function rewards_airRewardChart_destinationCountryOnChange()
{
	//First we clear its content before adding the new one
	//We arbitraily set it to 54 due to some strange behaviour when cleaning the box
	//At most 52 states + 2 first that never gets removed = 54 	
	for(var i = 2; i < 54; i++)
	{
		$('destinationState').options[2] = null;
	}	

	if ($('destinationCountry').value == 'CA' || $('destinationCountry').value == 'US'){
		// Load and enable the origin state
		rewards_airRewardChart_loadStates($('destinationCountry').value, $('destinationState'), selectedDestinationState);		
	}
	else{
		$('destinationState').disabled = true;	
	}	
}

function rewards_airRewardChart_loadStates(countryCode, stateWidget, selected)
{
  var stateSelect = stateWidget;
  
  // Add options to the select
  var optionNum = 2;
  var list = airRewardChartStateInfo;
 
 	if (countryCode != ""){
	  for(var i = 0; i < list.length; i++)
	  {
	    // Only get states for the correct country
	    if(list[i].countryCode == countryCode)
	    {
	      stateSelect.options[optionNum] = new Option(list[i].text, list[i].stateCode);
	      
	      if (list[i].stateCode == selected){
	      	stateSelect.options[optionNum].selected = true;
	      }
	      
	      optionNum ++;
	    }
	  }

  	rewards_airRewardChart_sortStates(stateWidget);
  
  	stateSelect.disabled = false;
  }
}

function rewards_airRewardChart_sortStates(stateWidget)
{
  var stateSelect = stateWidget;
  var selectedIndex = stateSelect.selectedIndex;
  var selectedCode = null;
  if(selectedIndex > 2)
  {
    selectedCode = stateSelect.options[selectedIndex].value;
  }
  
  // Sort the states, skipping the first two elements because they
  // aren't part of the list of countries
  for(var i = 2; i < stateSelect.options.length; i++)
  {
    var min = i;
    var j = 0;
    for(j = i + 1; j < stateSelect.options.length; j++)
    {
      if( stateSelect.options[j].text < stateSelect.options[min].text )
        min = j;
    }
    var minOption = stateSelect.options[min];
    var currentOption = stateSelect.options[i];
    var temp = new Option(minOption.text, minOption.value, minOption.defaultSelected, minOption.selected);
    stateSelect.options[min] = new Option(currentOption.text, currentOption.value, currentOption.defaultSelected, currentOption.selected);
    stateSelect.options[i] = temp;
  }
  
  for(var i = 2; i < stateSelect.options.length; i++)
  {
    if(stateSelect.options[i].value == selectedCode)
    {
      stateSelect.selectedIndex = i;
      return;
    }
  }
}

function rewards_airRewardChart_selectState(originStateBox, originStateCode)
{
  if(originStateCode == null || originStateCode == "")
    return;
  
  var stateSelect = originStateBox;
  
  stateSelect.selectedIndex = 0;
  for(var i = 0; i < stateSelect.options.length; i++)
  {
    if(stateSelect.options[i].value == stateCode)
    {
      stateSelect.selectedIndex = i;
      return;
    }
  }
}

function rewards_airRewardChart_originStateOnChange(){
	//Let's determine whether we enable or disable the view chart button
	if ($('originState').value == ''){
		//Origin state is empty
		
		//Disable the view chart button and set the proper classname because a state/province must be selected
		$('viewRewardChartButton').disabled = true;
		$('viewRewardChartButton').className = 'action-button-disabled';		
	}
	else{
		//Enable the view chart button and set the proper classname
		$('viewRewardChartButton').disabled = false;
		$('viewRewardChartButton').className = 'action-button';		
	}
	
}

function rewards_airRewardChart_onSubmit()
{
	
  //Append a reload variable that is set to true this situation occurs when we view the chart
  //THIS has some effects on the generation of the request - BE CAREFUL if u want to decomment that line 
  // document.AirRewardChartForm.originState.name = "";
  var reloadHiddenElement = document.createElement("input");
  reloadHiddenElement.setAttribute("type", "hidden");
  reloadHiddenElement.setAttribute("name", "reload");
  reloadHiddenElement.setAttribute("value", "true");
  document.AirRewardChartForm.appendChild(reloadHiddenElement);
	
  // If the state select is disabled, set a hidden field value with
  // the state select name and value of ""
  var stateSelect = document.AirRewardChartForm.originState;
  if(stateSelect.disabled)
  {
    var hiddenName = stateSelect.name;
    document.AirRewardChartForm.originState.name = "";
    var hiddenElement = document.createElement("input");
    hiddenElement.setAttribute("type", "hidden");
    hiddenElement.setAttribute("name", hiddenName);
    hiddenElement.setAttribute("value", "");
    document.AirRewardChartForm.appendChild(hiddenElement);
  }

	//RT#141305 - Submit Canada by default
	var destCountry = document.getElementById('destinationCountry');
	if (destCountry.selectedIndex == 0) {
		destCountry.selectedIndex = 2;
	}  

}

function rewards_airRewardChart_toggleACClassicAvenue(spanObj)
{
  // If they've clicked on the one that is already being displayed, ignore it
  if(spanObj.className != "classic-avenue-link")
    return;
  
  rewards_airRewardChart_setACClassicAvenue(spanObj.id == "classic_link")
}

function rewards_airRewardChart_setACClassicAvenue(showClassic)
{
  // If the air reward chart table isn't being displayed, bail out of the function
  if( document.getElementById("classic_link") == null )
    return;
  
  var spanObj = null;
  var otherSpanObj = null;
  if(showClassic)
  {
    spanObj = document.getElementById("classic_link");
    otherSpanObj = document.getElementById("avenue_link");
  }
  else
  {
    spanObj = document.getElementById("avenue_link");
    otherSpanObj = document.getElementById("classic_link");
  }
  
  // Toggle the class of the classic and avenue title so that the other
  // one is now clickable
  spanObj.className = "classic-avenue-plain";
  otherSpanObj.className = "classic-avenue-link";

  rewards_airRewardChart_showHideColumns();
}

function rewards_airRewardChart_showHideColumns()
{
  var table = document.getElementById('AirRewardTable');
  var rows = table.getElementsByTagName('TR');

  // Show/Hide the data
  for(var i = 1; i < rows.length; i++)
  {
    var rowObj = rows[i];
    // Filter rows that aren't visible
    if(rowObj.style.display != 'none')
    {
      // Only process rows that are countries or states
      if((rowObj.id.indexOf('ZONE_COUNTRY') == 0 || rowObj.id.indexOf('COUNTRY_STATE') == 0))
      {
        rewards_airRewardChart_showHideColumnsInRow(rowObj);
      }
      // Classic/Avenue: Only process rows that are zones, countries or states
      if( rowObj.id.indexOf('ZONE_COUNTRY')    == 0 ||
          rowObj.id.indexOf('COUNTRY_STATE')   == 0 ||
          rowObj.id.indexOf('ZONE')            == 0 ||
          rowObj.id.indexOf('COUNTRY_AS_ZONE') == 0    )
      {
        rewards_airRewardChart_showHideClassicAvenueColumn(rowObj);
      }
    }
  }
}


function rewards_airRewardChart_showHideColumnsInRow(rowObj)
{
  var economy = document.AirRewardChartForm.economy.checked;
  var business = document.AirRewardChartForm.business.checked;
  var first = document.AirRewardChartForm.first.checked;

  var tds = rowObj.getElementsByTagName('TD');

  var startingFrom = _jssStartingFrom_en;
  if( currentLanguage == 'fr')
    startingFrom = _jssStartingFrom_fr;

  
  // Skip the column for the expand/collapse icon and the country/state name
  for(var j = 2; j < tds.length; j++)
  {
    // Create the mileage string
    var spans = tds[j].getElementsByTagName('SPAN');
    var fieldsFilledIn = false;
    var econStr  = '-';
    var busStr   = '-';
    var firstStr = '-';
    for(var k = 0; k < spans.length; k++)
    {
      if(spans[k].id.indexOf('ECONOMY') != -1)
      {
        econStr = spans[k].innerHTML;
        if(spans[k].innerHTML.length > 0) fieldsFilledIn = true;
      }
      else if(spans[k].id.indexOf('BUSINESS') != -1)
      {
        busStr = spans[k].innerHTML;
        if(spans[k].innerHTML.length > 0) fieldsFilledIn = true;
      }
      else if(spans[k].id.indexOf('FIRST') != -1)
      {
        firstStr = spans[k].innerHTML;
        if(spans[k].innerHTML.length > 0) fieldsFilledIn = true;
      }
    }
    
    var slash = false;
    var tdText = '';
    
    if(fieldsFilledIn)
    {
      if(economy)
      {
        tdText += econStr;
      }
      if(business)
      {
        if(economy)               tdText += ' / ';
        tdText += busStr;
      }
      if(first)
      {
        if(economy || business)   tdText += ' / ';
        tdText += firstStr;
      }
    }
    
    if (j==3){ // ClassicPlus
    	spans[spans.length - 1].innerHTML = startingFrom + econStr;
    } else {
    	spans[spans.length - 1].innerHTML = tdText;
    }
  }
}

function rewards_airRewardChart_showHideClassicAvenueColumn(rowObj)
{
  var showClassic = rewards_airRewardChart_isClassicColumnShowing();
  
  var tds = rowObj.getElementsByTagName('TD');
  
  // Skip the column for the expand/collapse icon and the country/state name
  for(var j = 2; j < tds.length; j++)
  {
    if( tds[j].id.indexOf('AIR_CANADA_AVENUE') != -1 )
    {
      tds[j].style.display = showClassic ? 'none' :   '';
    }
    else if( tds[j].id.indexOf('AIR_CANADA_CLASSIC') != -1 )
    {
      tds[j].style.display = showClassic ?   ''   : 'none';
    }
  }
}

function rewards_airRewardChart_getColCount(economy, business, first)
{
  var colCount = 0;
  if(economy)  colCount ++;
  if(business) colCount ++;
  if(first)    colCount ++;
  return colCount;
}

function rewards_airRewardChart_isClassicColumnShowing()
{
  return (document.getElementById("classic_link").className == "classic-avenue-plain");
}

function rewards_airRewardChart_showComment(event, currentLanguage, imgObj)
{
  var content = document.getElementById('ExceptionsDialogContent');
  
  var comment = null;
  var current = imgObj.previousSibling;
  while(current != null)
  {
    if(current.tagName == 'SPAN' && current.id != null && current.id.indexOf('COMMENT') != -1)
    {
      if(currentLanguage == "en" && current.id.indexOf('_EN') != -1)
      {
        comment = current.innerHTML;
      }
      else if(currentLanguage == "fr" && current.id.indexOf('_FR') != -1)
      {
        comment = current.innerHTML;
      }
    }
    current = current.previousSibling;
  }
  
  if(comment == null)
  {
    debug('rewards_airRewardChart_showComment(): Couldnt find COMMENT span for currentLanguage ('+currentLanguage+')');
    return;
  }
  
  content.innerHTML = comment;
  showDialog('ExceptionsDialog', event, 10, 15);
  hideIn('ExceptionsDialog', 2000);
}

function rewards_airRewardChart_expandFirstTableRow(mileageURL)
{
  var table = document.getElementById('AirRewardTable');
  if(table == null)
    return;
  var rows = table.getElementsByTagName('TR');
  
  for(var i = 1; i < rows.length; i++)
  {
    if(rows[i].id.match(/^ZONE_[A-Za-z]+$/))
    {
      var code = rows[i].id.substr(5);
      rewards_airRewardChart_expandCollapseNode(code, true, mileageURL+'?destZone='+code);
      return;
    }
    else if(rows[i].id.match(/^COUNTRY_AS_ZONE_[A-Za-z]+$/))
    {
      var countryAsZoneStr = "COUNTRY_AS_ZONE_";
      var code = rows[i].id.substr(countryAsZoneStr.length);
      rewards_airRewardChart_expandCollapseNode(code, false, mileageURL+'?destCountry='+code);
      return;
    }
  }
}

function rewards_airRewardChart_expandCollapseNode(code, isZone, url)
{
  var img = null;
  if(isZone)
    img = document.getElementById("ZONE_" + code + "_Image");
  else
    img = document.getElementById("COUNTRY_" + code + "_Image");
  
  var lastSlash = img.src.lastIndexOf("/");
  if(lastSlash == -1)
  {
    debug("rewards_airRewardChart_expandCollapseZone(): Couldn't find last slash for image directory. Has image url changed?");
    return;
  }
  
  var directory = img.src.substr(0, lastSlash);
  var fileName = img.src.substr(lastSlash + 1);
  var newFileName = "";
  
  // If the node is collapsed, expand it
  if(fileName == "icon_+.gif")
  {
    // If the zone or country hasn't already been loaded
    // Send a request for the mileage from the origin to
    // each country in the destination zone or
    // each state in the destination country
    // (depending on whether this is a request for a destination zone or country)
    if( !rewards_airRewardChart_isZoneCountryLoaded(code, isZone) )
    {
      setTimeout('rewards_airRewardChart_loadDestinationMileage(\''+url+'\', '+isZone+')', 0);
    }
    rewards_airRewardChart_showHideRow(code, isZone, true);
    newFileName = "icon_-.gif";
  }
  else
  {
    rewards_airRewardChart_showHideRow(code, isZone, false);
    newFileName = "icon_+.gif";
  }
  
  // Toggle the image
  img.src = directory + "/" + newFileName;
}

function rewards_airRewardChart_showHideRow(code, isZone, show)
{
  var table = document.getElementById('AirRewardTable');
  var rows = table.getElementsByTagName('TR');
  
  var prefix = null;
  if(isZone)  prefix = 'ZONE_COUNTRY_';
  else        prefix = 'COUNTRY_STATE_';
  for(var i = 0; i < rows.length; i++)
  {
    if(rows[i].id.indexOf(prefix + code + "_") == 0)
    {
      rows[i].style.display = show ? '' : 'none';
      
      if(show)
      {
        rewards_airRewardChart_showHideColumnsInRow(rows[i]);
        rewards_airRewardChart_showHideClassicAvenueColumn(rows[i]);
      }
    }
  }
}


function rewards_airRewardChart_loadDestinationMileage(url, isZoneRQ)
{
  // Turn the mouse cursor into an hourglass
  document.body.style.cursor = "wait";
  
  if (window.XMLHttpRequest) // Non-IE browsers
  {
    var xmlreq = new XMLHttpRequest();
    xmlreq.open("GET", url, true);
    xmlreq.onreadystatechange=
      function()
      {
        if (xmlreq.readyState==4)
        {
          rewards_airRewardChart_writeDestinationMileage(xmlreq.responseText, isZoneRQ);
        }
      }
    xmlreq.send(null);
  }
  else if (window.ActiveXObject) // IE
  {
    var xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
    xmlreq.open("GET", url, true);
    xmlreq.onreadystatechange=
      function()
      {		 
        if (xmlreq.readyState==4)
        {
          rewards_airRewardChart_writeDestinationMileage(xmlreq.responseText, isZoneRQ);
        }
      }
    xmlreq.send();
  }
}


// Array storing zones/countries whose mileage data has already
// been retrieved from the server
var rewards_airRewardChart_loadedZoneCountries = new Array();

function rewards_airRewardChart_isZoneCountryLoaded(code, isZone)
{
  for(var i = 0; i < rewards_airRewardChart_loadedZoneCountries.length; i++)
  {
    var zoneCountry = rewards_airRewardChart_loadedZoneCountries[i];
    
    if(isZone && zoneCountry.indexOf('Zone'+code) != -1)
      return true;
    if(!isZone && zoneCountry.indexOf('Country'+code) != -1)
      return true;
  }
  return false;
}

function rewards_airRewardChart_setZoneCountryLoaded(code, isZone)
{
  var zoneCountry = null;
  if(isZone)
    zoneCountry = 'Zone'+code;
  else
    zoneCountry = 'Country'+code;
  
  var length = rewards_airRewardChart_loadedZoneCountries.length;
  rewards_airRewardChart_loadedZoneCountries[length] = zoneCountry;
}

function rewards_airRewardChart_writeDestinationMileage(responseText, isZoneRQ)
{
  var scriptOpenTagStartPos = responseText.indexOf("<script");
  var scriptOpenTagEndPos = responseText.indexOf(">", scriptOpenTagStartPos);
  var scriptCloseTagStartPos = responseText.indexOf("</script", scriptOpenTagEndPos);
  var jsOnly = responseText.substring(scriptOpenTagEndPos + 1, scriptCloseTagStartPos);

  if(scriptOpenTagStartPos == -1 || scriptCloseTagStartPos == -1)
    debug("rewards_airRewardChart_writeDestinationMileage(): Invalid response from xDist: Could not find &lt;script&gt; or &lt;/script&gt; tag");

  eval(jsOnly);

  for(var i = 0; i < zones.length; i++)
  {
    rewards_airRewardChart_setTableValues(zones[i], isZoneRQ);
  }
  
  rewards_airRewardChart_showHideColumns();
  
  // Turn the mouse cursor from an hourglass back into the default
  document.body.style.cursor = "default";
}


function rewards_airRewardChart_setTableValues(arZone, isZoneRQ)
{
  var zoneCode = arZone.code;

  // For each country in the zone
  for(var i = 0; i < arZone.countries.length; i++)
  {
    var arCountry = arZone.countries[i];
    var countryCode = arCountry.code;

    // If this is a request for a destination zone, create a row for each
    // country in the response
    if(isZoneRQ)
    {
      var rowId = 'ZONE_COUNTRY_' + zoneCode + "_" + countryCode;
      rewards_airRewardChart_setTableRowValues(rowId, arCountry);
    }
    // If this is a request for a destination country, create a row for each
    // state in the response
    else
    {
      for(var j = 0; arCountry.states != null && j < arCountry.states.length; j++)
      {
        var arState = arCountry.states[j];
        var stateCode = arState.code;
        var rowId = 'COUNTRY_STATE_' + countryCode + "_" + stateCode;
        rewards_airRewardChart_setTableRowValues(rowId, arState);
      }
      rewards_airRewardChart_setZoneCountryLoaded(arCountry.code, isZoneRQ);
    }
  }
  
  if(isZoneRQ)
    rewards_airRewardChart_setZoneCountryLoaded(zoneCode, isZoneRQ);

}

function rewards_airRewardChart_setTableRowValues(rowId, arCountryState)
{
  var tableRow = document.getElementById(rowId);
  // If the table row is not defined, bail out
  if(tableRow == null)
  {
    return;
  }
  
  var tds = tableRow.getElementsByTagName("TD");
  
  
  // Skip the first two TD elements
  var tdNum = 2;
  // For each airline in the country/state
  for(var airlineNum = 0; arCountryState.airlines != null && airlineNum < arCountryState.airlines.length; airlineNum++)
  {
    var arAirline = arCountryState.airlines[airlineNum];
    var arClasses = arAirline.classes;
    
    var spans = tds[tdNum].getElementsByTagName('SPAN');
    // For each class in the airline
    for(var i = 0; arClasses != null && i < arClasses.length; i++)
    {
      if(arClasses[i].mileage == null || arClasses[i].mileage == 0)
// change here for dynamic
        spans[i].innerHTML = '-';
      else
        spans[i].innerHTML = arClasses[i].mileage / 1000;
    }


    // Add the english/french comments associated with this country/state
    // if the airline is Air Canada
    if(arCountryState.comments != null && (arAirline.code == "CLASSIC" || arAirline.code == "AVENUE"))
    {
      for(var i = 0; i < spans.length; i++)
      {
        // Check if the span is a comments span and get the language if it is.
        if( spans[i].id.indexOf("COMMENTS") != -1 )
        {
          var language = "";
          if( spans[i].id.indexOf("_EN") != -1 )
            language = "en";
          else if( spans[i].id.indexOf("_FR") != -1 )
            language = "fr";
          
          for(var j = 0; j < arCountryState.comments.length; j++)
          {
            if(arCountryState.comments[j].language == language)
              spans[i].innerHTML = arCountryState.comments[j].comment;
          }
          
          // Make the image visible
          var imgs = tds[tdNum].getElementsByTagName('IMG');
          if(imgs.length > 0)
            imgs[0].style.display = '';
        }
      }
    }
    
    tdNum ++;
  }
}


function AirRewardsZone(code, countries)
{
  this.code = code;
  this.countries = countries;
}

function AirRewardsCountry(code, states, airlines, comments)
{
  this.code = code;
  this.states = states;
  this.airlines = airlines;
  this.comments = comments;
}

function AirRewardsState(code, airlines, comments)
{
  this.code = code;
  this.airlines = airlines;
  this.comments = comments;
}

function AirRewardsAirline(code, classes)
{
  this.code = code;
  this.classes = classes;
}

function AirRewardsClass(code, mileage)
{
  this.code = code;
  this.mileage = mileage;
}

function AirRewardsComment(language, comment)
{
  this.language = language;
  this.comment = comment;
}

/*
 * Created by Michael Daniaux
 * The 10th may 2007
 */
function rewards_newAirRewardChart_showComment(event, currentLanguage, imgObj)
{
  var content = document.getElementById('ExceptionsDialogContent');
  
  var comment = null;
  var current = imgObj.previousSibling;
  while(current != null)
  {
    if(current.tagName == 'DIV' && current.id != null && current.id.indexOf('COMMENT') != -1)
    {
        comment = current.innerHTML;
    }
    current = current.previousSibling;
  }
  
  if(comment == null)
  {
    debug('rewards_newAirRewardChart_showComment(): Couldnt find COMMENT DIV');
    return;
  }
  
  content.innerHTML = comment;
  showDialog('ExceptionsDialog', event, 10, 15);
  hideIn('ExceptionsDialog', 2000);
}

function rewards_newAirRewardChart_expandCollapse(code, isZone)
{
  
  //alert("rewards_newAirRewardChart_expandCollapse :" + code + " " + isZone);
  
  var img = null;
  if(isZone)
    img = document.getElementById("NEW_ZONE_" + code + "_Image");
  else
    img = document.getElementById("NEW_COUNTRY_" + code + "_Image");
  
  var lastSlash = img.src.lastIndexOf("/");
  if(lastSlash == -1)
  {
    debug("rewards_airRewardChart_expandCollapseZone(): Couldn't find last slash for image directory. Has image url changed?");
    return;
  }
  
  var directory = img.src.substr(0, lastSlash);
  var fileName = img.src.substr(lastSlash + 1);
  var newFileName = "";
  
  //alert("fileName :" + fileName);

  var box = null;
  if(isZone)
    box = document.getElementById("NEW_ZONE_" + code + "_BOX");
  else
    box = document.getElementById("NEW_COUNTRY_" + code + "_BOX");
  
  // If the node is collapsed, expand it
  if(fileName == "icon_plus.gif")
  {
    // If the zone or country hasn't already been loaded
    // Send a request for the mileage from the origin to
    // each country in the destination zone or
    // each state in the destination country
    // (depending on whether this is a request for a destination zone or country)
    
    //if( !rewards_airRewardChart_isZoneCountryLoaded(code, isZone) )
    //{
    //  setTimeout('rewards_airRewardChart_loadDestinationMileage(\''+url+'\', '+isZone+')', 0);
    //}
    //rewards_airRewardChart_showHideRow(code, isZone, true);
    
    
    box.style.display='';
    
    newFileName = "icon_minus.gif";
    
  }
  else
  {
    
    //rewards_airRewardChart_showHideRow(code, isZone, false);
    box.style.display='none';
    newFileName = "icon_plus.gif";
    
    
  }
  
  // Toggle the image
  img.src = directory + "/" + newFileName;
}

