<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Flight Status"
             title_url="http://www.flightstats.com/?utm_source=c228b59beca1b817:-1eba8de7:117657780a7:-2590&amp;utm_medium=cpc&amp;utm_campaign=bashennekamgadget"
             author="Bas Hennekam."
             author_email="bashennekam@gmail.com"
             author_location="Utrecht, the Netherlands"
             category="tools"
             description="Track a single flight and see the current status, delays and other flight information. The results are shown inside the gadget, so you don't have to leave iGoogle."
             screenshot="http://gadgets.bashennekam.nl/flight/google_gadget_flight_screen.png"
             thumbnail="http://gadgets.bashennekam.nl/flight/google_gadget_flight_thumb.png" 
             height="50">
<Require feature="dynamic-height"/> 
<Require feature="setprefs"/>
<Require feature="analytics"/>
</ModulePrefs>

<UserPref name="flAirline" display_name="Airline Code" datatype="string"/>
<UserPref name="flFlightNumber" display_name="Flight Number" datatype="string"/>
<UserPref name="flDeparture" display_name="Departure Date" datatype="string"/>

<Content type="html">
<![CDATA[
<!-- ALm6fM0RXjIRw_RQM6JeaKqQaXx4pFP2GhrocylVk9oGnNG0tZi5QaxKFjZeH5KsRcoyrt1vetdiE-iNUqi51SdKr41xIPIVHY9ywjV5x2VN1JhOErKzgwULL88neeYWypDG2qe18mQpopLAy-648OuQv2JuP0bCu_bss_YJ-yC06A8__87G_N7_sSsR2cPkpSgB-pAa1tdG -->

<script language="Javascript" type="text/javascript">
_IG_Analytics("UA-3622119-2", "/GadgetFlight/load");
  
var flPrefs = new _IG_Prefs(__MODULE_ID__);  
var flAirline = flPrefs.getString('flAirline');
var flFlightNumber = flPrefs.getString('flFlightNumber');
var flDeparture = flPrefs.getString('flDeparture');
var flSuggestAirlineCodeResults = 5;
  
function showFlightInfo(airlinecode, flightnumber, departuredate, refresh) {
  var statusres, statustbl, statusrow;
  var departres, departtbl, departrow;  
  var arrivalres, arrivaltbl, arrivalrow;
  var arrivalbool = false;
  var departbool = false;
  
  var url = 'http://www.flightstats.com/go/rss/flightStatusByFlight.do';
  url += '?guid=c228b59beca1b817:-1eba8de7:117657780a7:-2590';
  url += '&airlineCode=' + airlinecode;
  url += '&flightNumber=' + flightnumber;
  url += '&departureDate=' + departuredate;
  
  _gel('flError').style.display = 'none';
  //_gel('flResults').style.display = 'none'; 
  _gel('flLoading').style.display = '';
  
  _IG_AdjustIFrameHeight();
  
  _IG_FetchXmlContent(url, function (response) {
     if (response == null || typeof(response) != "object" || response.firstChild == null) {
        //No results
        showResults(false);        
        return;
     } else {
        if(response.getElementsByTagName("item").length == 0) {
          //No results
          showResults(false);
        } else {  
          //Results
          var html = '';
          var itemList = response.getElementsByTagName("item");
          for(i=0;i<itemList.length;i++) {
            var item = itemList[0];
            var title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
            var description = item.getElementsByTagName("description")[0].firstChild.nodeValue;
            var link = item.getElementsByTagName("link")[0].firstChild.nodeValue;
            
            description = description.replace(/a href/gi, 'a target="_BLANK" href');                
            description = description.replace(/Departure/gi, '<div class="resultDeparture"><div class="resultHead">Departure<\/div><div class="resultInfo">Airport: ');
            description = description.replace(/Arrival:/gi, '<\/div><\/div><div class="resultArrival"><div class="resultHead">Arrival<\/div><div class="resultInfo">Airport: ');
            description = description.replace(/More Details at FlightStats.com/gi, '<\/div><\/div>');                
            description = description.replace(/Track this flight in real-time at FlightStats.com/gi, '');
            description = description.replace(/<br\/>/gi, '');
            description = description.replace(/Scheduled:/gi, '<br\/>Scheduled:');
            description = description.replace(/Actual:/gi, '<br\/>Actual:');
            description = description.replace(/Estimated:/gi, '<br\/>Estimated:');
            description = description.replace(/Terminal:/gi, '<br\/>Terminal:');
            description = description.replace(/Gate:/gi, '<br\/>Gate:');
            description = description.replace(/.do\?/gi, '.do\?utm_source=c228b59beca1b817:-1eba8de7:117657780a7:-2590&utm_medium=cpc&utm_campaign=bashennekamgadget&');
            
            if(title != 'Error') {
              html += '<img class="plane" src="http://gadgets.bashennekam.nl/flight/google_gadget_flight_plane.gif" />';
              html += '<div class="resultItem">';
              html += '<div class="resultMoreInfo"><a target="_blank" href="' + link + '&utm_source=c228b59beca1b817:-1eba8de7:117657780a7:-2590&utm_medium=cpc&utm_campaign=bashennekamgadget"><img src="http://hosting.gmodules.com/ig/gadgets/file/111235031415052608966/google_gadget_picasa_popup.gif" /></a></div>';
            } else {
              html += '<div class="resultItemError">';
            }            
            html += '<div class="resultTitle">' + title + '</div>';
            html += '<div class="resultDescription">' + description + '</div>';            
            html += '<\/div>';
          }
          
          //Source
          html += '<div class="resultFlightStats">';
          html += 'source: ';
          html += '<a href="http://www.flightstats.com/?utm_source=c228b59beca1b817:-1eba8de7:117657780a7:-2590&utm_medium=cpc&utm_campaign=bashennekamgadget" target="_blank">';
          html += '<img src="http://gadgets.bashennekam.nl/flight/google_gadget_flight_stats.gif" />';
          html += 'http://www.flightstats.com</a>';
          html += '</div>';
  
          _gel('flResults').innerHTML = html;
          showResults(true);
        }
      }
      
      _IG_AdjustIFrameHeight();      
    
    }, { refreshInterval: 300 });
}
  
function loadPrefs() {
  _gel('airlineCode').value = flAirline;
  _gel('flightNumber').value = flFlightNumber;
  _gel('departureDate').value = flDeparture;
  
  _IG_AdjustIFrameHeight();
  
  if(flAirline.length != 0 && flFlightNumber.length != 0 && flDeparture.length != 0) 
  {
    showFlightInfo(flAirline, flFlightNumber, flDeparture);
  }
  else
  {
    resetFlightInfo();
  }
}
  
function setPrefs(airline, flight, departure) {
  flPrefs.set("flAirline", airline);
  flPrefs.set("flFlightNumber", flight);
  flPrefs.set("flDeparture", departure);
}
  
function resetFlightInfo() {
  var today = new Date();
  var day = today.getDate();
  day = (day < 10) ? '0' + day : day;
  var month = today.getMonth()+1;
  month = (month < 10) ? '0' + month : month;
  var year = today.getFullYear();
  
  _gel('airlineCode').value = '';
  _gel('flightNumber').value = '';  
  _gel('departureDate').value = year + '-' + month + '-' + day;
  
  _gel('flResults').style.display = 'none';
  _gel('flError').style.display = 'none';
  
  _IG_AdjustIFrameHeight();
  
  setPrefs('', '', '');
}

function showResults(value) {
  _gel('flResults').style.display = (value) ? '' : 'none';
  _gel('flError').style.display = (value) ? 'none' : '';
  _gel('flLoading').style.display = 'none';
}
  
function searchFlightInfo() {
  var airlinecode = _gel('airlineCode').value;
  var flightnumber = _gel('flightNumber').value;
  var departuredate = _gel('departureDate').value;
  
  setPrefs(airlinecode, flightnumber, departuredate);
  
  showFlightInfo(airlinecode, flightnumber, departuredate);
}

function suggestAirlineCode(search) {
  var url = 'http://www.flightstats.com/go/Suggest/airlineSuggestProcess.do';
  url += '?desiredResults=' + flSuggestAirlineCodeResults;
  url += '&searchSubstring=' + search;
}
</script>
  
<style type="text/css">
body, th, td, span, div, form, input {
  font-family: Arial;
  font-size: 8pt;
}
 
img {
  border: none;
}
  
.plane {
  float: left;
  margin-top: 1px;
}

a:link, a:visited {
  text-decoration: none;
  color: #00008D;
}
            
a:hover {
  text-decoration: underline;
}
    
#flResults {
  width: 100%;  
}

.resultItem {
  padding: 5px;
  border-left: solid 20px #CCCCCC;
  border-top: solid 1px #7AA5D6;
  background-color: #EEEEEE;
}
  
.resultItemError {
  padding: 5px;
  border-left: solid 20px #FF9793;
  border-top: solid 1px #7AA5D6;
  background-color: #FFEBEA;  
}
  
.resultTitle {
  font-weight: bold;
}

.resultDescription {
  color: #333333;
  overflow: auto;
}

.resultHead {
  color: #3366CC;
  font-weight: bold;
}

.resultDeparture {
  width: 49%;
  float: left;
}

.resultArrival {  
  width: 49%;
  float: right;
}
  
.resultInfo {
  margin-left: 5px;  
}
  
.resultFlightStats {
  width: 100%;
  text-align: right;
  color: #666666;
  margin-top: 2px;
}

.resultMoreInfo {
  position: absolute;
  right: 5px;
}
  
#flError {
  width: 100%;
  font-weight: bold;
  text-align: center;
  background-color: #FF9793;
  padding: 2px;
}
  
#flLoading {
  width: 100%;
  font-weight: bold;
  text-align: center;
  background-color: #FAD163;
  padding: 2px;
}
  
.menu {
  width: 100%;
  padding: 0px;
  margin: 0px;
  border-collapse: collapse;
  background-color: #C3D9FF;  
}
  
.menuText {
  font-weight: bold;
  text-align: center;
}
  
#airlineCode, #flightNumber, #departureDate {
  color: #666666;
  padding: 0px;
}
</style>

<!--[if IE]>
<style type="text/css">
.resultDescription {
  color: #333333;
  overflow: visible;
  height: 50px;
}
</style>
<![endif]-->

<table class="menu">
  <tr>
    <td>&nbsp;</td>
    <td width="35" class="menuText">Airline</td>
    <td width="30" class="menuText"><input type="text" value="" id="airlineCode" size="1" /></td>
    <td width="35" class="menuText">Flight</td>
    <td width="30" class="menuText"><input type="text" value="" id="flightNumber" size="1" /></td>
    <td width="35" class="menuText">Departure</td>
    <td width="40" class="menuText"><input type="text" value="" id="departureDate" size="8" /></td>
    <td width="30" class="menuText"><input type="button" value="Go" onClick="searchFlightInfo()" /></td>
    <td width="30" class="menuText"><input type="button" value="Reset" onClick="resetFlightInfo()" /></td>
    <td>&nbsp;</td>
  </tr>
</table>

<div id="flLoading" style="display:none">Loading...</div>
<div id="flResults" style="display:none"></div>
<div id="flError" style="display:none">Unknown error!</div>

<script language="Javascript" type="text/javascript">
loadPrefs();
</script>

]]>
</Content>
</Module>





































