///////////////////////////////////////////////////////////////////////////////
// OPTIONS
///////////////////////////////////////////////////////////////////////////////
function Options ()
{
  this._optionShowDeparture = false;
  this._optionShowClock     = false;
  
  this._optionAirlineCode   = "";
  this._optionFlightNumber  = "";
  this._optionAirportCode   = "";
  this._optionFlightDay     = "";
  this._optionFlightMonth   = "";

  this.loadSettings ();
}

Options.prototype._optionShowDeparture;
Options.prototype._optionShowClock;

Options.prototype._optionAirlineCode;
Options.prototype._optionFlightNumber;
Options.prototype._optionAirportCode;
Options.prototype._optionFlightDay;
Options.prototype._optionFlightMonth;

///////////////////////////////////////////////////////////////////////////////
Options.prototype.loadSettings = function () 
{
  var searchStr = g_platform.getCookie ("flightData");

  this._optionShowDeparture = (this.getItem (searchStr, "showDeparture") == "true") ? true : false;
  this._optionShowClock     = (this.getItem (searchStr, "showClock"    ) == "true") ? true : false;
  this._optionAirlineCode   = (this.getItem (searchStr, "airlineCode"  ));
  this._optionFlightNumber  = (this.getItem (searchStr, "flightNumber" ));
  this._optionAirportCode   = (this.getItem (searchStr, "airportCode"  ));
  this._optionFlightDay     = (this.getItem (searchStr, "flightDay"    ));
  this._optionFlightMonth   = (this.getItem (searchStr, "flightMonth"  ));
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.saveSettings = function (mid) 
{
  var searchStr = "";
   
  searchStr += "showDeparture#"  + (this._optionShowDeparture ? "true" : "false");
  searchStr += ";showClock#"     + (this._optionShowClock     ? "true" : "false");
  
  searchStr += ";airlineCode#"   + this._optionAirlineCode;
  searchStr += ";flightNumber#"  + this._optionFlightNumber;
  searchStr += ";airportCode#"   + this._optionAirportCode;
  searchStr += ";flightDay#"     + this._optionFlightDay;
  searchStr += ";flightMonth#"   + this._optionFlightMonth;

  g_platform.setCookie ("flightData", searchStr);
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getItem = function (searchStr, itemName) 
{
  var sArgs = searchStr.slice(0).split(';');
  r = '';
  for (var i = 0; i < sArgs.length; i++)
  {
    if (sArgs[i].slice(0,sArgs[i].indexOf('#')) == itemName)
    {
      r = sArgs[i].slice(sArgs[i].indexOf('#')+1);
      break;
    }
  }
  
  return (r.length > 0 ? r.split(',') : '')
}
      
///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionShowDeparture = function () 
{
  return this._optionShowDeparture;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionShowDeparture = function (show) 
{
  this._optionShowDeparture = show;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionShowClock = function () 
{
  return this._optionShowClock;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionShowClock = function (show) 
{
  this._optionShowClock = show;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionAirlineCode = function () 
{
  return this._optionAirlineCode;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionAirlineCode = function (airlineCode) 
{
  this._optionAirlineCode = airlineCode;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionFlightNumber = function () 
{
  return this._optionFlightNumber;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionFlightNumber = function (flightNumber) 
{
  this._optionFlightNumber = flightNumber;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionAirportCode = function () 
{
  return this._optionAirportCode;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionAirportCode = function (airportCode) 
{
  this._optionAirportCode = airportCode;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionFlightDate = function () 
{
  return this.convertToDate (this.getOptionFlightDay   (),
                             this.getOptionFlightMonth ());
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionFlightDate = function (flightDate) 
{
  SetOptionFlightDay   (flightDate.split ("-")[2]);
  SetOptionFlightMonth (flightDate.split ("-")[1]);
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionFlightDay = function () 
{
  return this._optionFlightDay;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionFlightDay = function (flightDay) 
{
  this._optionFlightDay = flightDay;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.getOptionFlightMonth = function () 
{
  return this._optionFlightMonth;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.setOptionFlightMonth = function (flightMonth) 
{
  this._optionFlightMonth = flightMonth;
}

///////////////////////////////////////////////////////////////////////////////
Options.prototype.convertToDate = function (day, month) 
{
  var flightDate = "";
  if ((day != "") && (month != ""))
  {
    var now  = new Date ();
    var year = String (now.getFullYear ());

    flightDate += year + "-";

    if (month < 10)
    {
      flightDate += "0";
    }

    flightDate += month + "-";
    
    if (day < 10)
    {
      flightDate += "0";
    }

    flightDate += day;
  }
  
  return flightDate;
}

