///////////////////////////////////////////////////////////////////////////////
// BROWSER PLATFORM
///////////////////////////////////////////////////////////////////////////////
function Platform ()
{
  this._type    = "Browser";
  this._count   = 0;
  this._version = "1.0.2.0";
}

Platform.prototype._type;
Platform.prototype._version;
Platform.prototype._count;


///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getType = function () 
{
  return this._type;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getVersion = function () 
{
  return this._version;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getElementById = function (elementId, element) 
{ 
  return document.getElementById (elementId);
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setTitle = function (elementId, title) 
{
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.title = title;
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setText = function (elementId, text, element) 
{
  if (element == null)
  { 
    element = this.getElementById (elementId);
  }
  
  if (element != null)
  {
    element.textContent = text;
    element.innerText = text;
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getText = function (elementId) 
{ 
  var text = "";    
  var element = this.getElementById (elementId);
  if (element != null)
  {
    text = element.innerText;
    if (text == undefined)
    {
      text = element.textContent;
    }
  }
    
  return text;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setValue = function (elementId, value) 
{
  var element = this.getElementById (elementId);
  if (element != null)
  {
    if ((elementId == "flightDayEdit") || (elementId == "flightMonthEdit"))
    {
      if (value == "")
      {
        element.selectedIndex = 0;
      }
      else
      {
        element.selectedIndex = parseInt (value, 10);
      }
    }
    else
    {
      element.value = value;
    }
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getValue = function (elementId) 
{ 
  var value = "";    
  var element = this.getElementById (elementId);
  if (element != null)
  {
    if ((elementId == "flightDayEdit") || (elementId == "flightMonthEdit"))
    {
      var index = element.selectedIndex;
      if (index == 0)
      {
        value = "";
      }
      else
      {
        value = String (index);
      }
    }
    else
    {
      value = element.value;
    }
  }
    
  return value;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setHRef = function (elementId, hRef) 
{ 
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.href = hRef;
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setCursor = function (elementId, cursor) 
{ 
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.cursor = cursor;
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setEnabled = function (elementId, enabled) 
{ 
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.enabled = enabled;
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setFocus = function (elementId) 
{ 
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.focus ();
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setVisible = function (elementId, visible) 
{ 
  var element = this.getElementById (elementId);
  if (element != null)
  {
    element.style.visibility = visible ? "visible" : "hidden";
  }
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getVisible = function (elementId) 
{ 
  var visible = true;    

  var element = this.getElementById (elementId);
  if (element != null)
  {
    visible = (element.style.visibility == "visible");
  }
    
  return visible;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setGadgetCaption = function (title) 
{
  document.title = title;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.getCookie = function (c_name) 
{
  var c_value = "";
  if (document.cookie.length > 0)
  {
    c_start = document.cookie.indexOf (c_name + "=");
    if (c_start != -1)
    { 
      c_start = c_start + c_name.length + 1;
      c_end   = document.cookie.indexOf (";", c_start);
      
      if (c_end == -1)
      {
        c_end = document.cookie.length;
      }
      
      c_value = unescape (document.cookie.substring (c_start, c_end));
    } 
  }
  
  return c_value;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setCookie = function (c_name, c_value)
{
  var exdate = new Date();
  exdate.setDate (exdate.getDate () + 365);

  document.cookie = c_name + "=" + escape (c_value) +
    ";expires=" + exdate.toGMTString ();
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.createRotChar = function (posX, parentDiv, offsetX, offsetY, height, width, size, cx, cy, bgColor, fgColor)
{
  var d = document.createElement('div');
  parentDiv.appendChild (d);

  d.style.position        = 'absolute';
  d.style.backgroundColor = bgColor;
  d.style.height          = height;
  d.style.width           = width;
  d.style.margin          = 0;
  d.style.left            = offsetX + posX * (width + 1);
  d.style.top             = offsetY;
  
  d.id = 'div' + String (this._count);

  this._labelElem = document.createElement ('span');
  d.appendChild (this._labelElem);
  
  this._labelElem.style.fontFamily = 'Courier New';
  this._labelElem.style.fontWeight = 'bold';
  this._labelElem.style.fontSize   = size;
  this._labelElem.style.color      = fgColor;
  this._labelElem.style.left       = cx;
  this._labelElem.style.top        = cy;
  
  this._labelId = 'label' + String (this._count);
  this._labelElem.id = this._labelId;

  this._count++;
  
  return this._labelElem;
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.addButton = function (id, clickHandler, imgSrc, left, top)
{
  var docBody = document.getElementById ("docBody");

  docBody.style.backgroundRepeat = 'no-repeat';
  docBody.style.backgroundImage  = 'url(images/background.png)';
  
  var d = document.createElement ('div');
  
  d.style.backgroundRepeat = 'no-repeat';
  d.style.backgroundImage  = 'url(images/' + imgSrc + ')';
  
  d.style.position = 'absolute';
  d.style.left     = left;
  d.style.top      = top;
  d.style.width    = '30px';
  d.style.height   = '30px';
  d.style.zIndex   = 1;
  d.id             = 'img_' + id;

  var content = document.getElementById ("gadgetContent");
  content.appendChild (d);
      
  var e = document.createElement ('a');
  
  e.id             = id;
  e.target         = '_blank';
  e.onclick        = eval (clickHandler);
  e.style.position = 'absolute';
  e.style.left     = left;
  e.style.top      = top;
  e.style.width    = '25px';
  e.style.height   = '25px';
  e.style.cursor   = 'pointer';
  e.style.zIndex   = 3;

  content.appendChild (e);
  
  return e;          
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.addLight = function (id, clickHandler, imgSrc, left, top)
{
  return this.addButton (id, clickHandler, imgSrc, left, top);
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.addListItem = function (listCtrl, text, value)
{
  var opt = document.createElement ("OPTION");
  opt.text  = text;
  opt.value = value;
  listCtrl.options.add (opt, listCtrl.options.length);
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.showAlert = function (heading, source, snippet, url)
{
}
///////////////////////////////////////////////////////////////////////////////
Platform.prototype.onMouseOver = function () 
{
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.onMouseOut = function () 
{
}

///////////////////////////////////////////////////////////////////////////////
Platform.prototype.setLayout = function ()
{
}

