var UserAgent = navigator.userAgent.toLowerCase();
var isIE = ((UserAgent.indexOf("msie") != -1) && (UserAgent.indexOf("opera") == -1) && (UserAgent.indexOf("webtv") == -1)); 
var isGecko = (UserAgent.indexOf("gecko") != -1);
var isOpera = (UserAgent.indexOf("Opera") != -1);
var isDesconhecido = (!(isIE || isGecko || isOpera));
var tplinicial = 'servicos';
var ServicosHide = true;
var InstitucionalHide = true;
var AeronavesHide = true;
var recebendoTexto = false;
var ajaxSupport = (getXMLHttp() ? true : false );
var msgNoAjax = 'Your current browser does not support AJAX!';
var returnRunURL = '';
var aPreImagens = new Array();
var totImagensLer = 0;
var imagensLidas = 0;
var aImgsSlideShow = new Array();
aImgsSlideShow[aImgsSlideShow.length] = 'img/servicos/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/aeronaves/manutencao/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/falecomario/topolimpo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/institucional/missao/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/institucional/sobre/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/institucional/instinfraestrutura/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/institucional/ambiental/topo.jpg';
aImgsSlideShow[aImgsSlideShow.length] = 'img/institucional/docs/topo.jpg';
var mnOn = 'mnHome';

function ltrim( s )
{
  return s.replace( /^\s*/, "" );
}

function rtrim( s )
{
  return s.replace( /\s*$/, "" );
}

function trim( s )
{
  return rtrim(ltrim(s));
}

function isFunction(a)
{
    return typeof a == 'function';
}

function isNull(a)
{
    return typeof a == 'object' && !a;
}

function isNumber(a)
{
    return typeof a == 'number' && isFinite(a);
}

function isObject(a)
{
    return (a && typeof a == 'object') || isFunction(a);
}

function isArray(a)
{
   return (a.constructor.toString().indexOf("Array") != -1)
}

function isString(a)
{
    return typeof a == 'string';
}

function isBoolean(a)
{
    return typeof a == 'boolean';
}

function isUndefined(a)
{
    return typeof a == 'undefined';
}

function getCheckedValue(radioObj)
{
  if(!radioObj) {return "";}
  var radioLength = radioObj.length;
  if(radioLength == undefined)
  {
    if(radioObj.checked) {return radioObj.value;}
    else {return "";}
  }
  for(var i = 0; i < radioLength; i++)
  {
    if(radioObj[i].checked)
    {
      return radioObj[i].value;
    }
  }
  return "";
}

function setCheckedValue(radioObj, newValue)
{
  if(!radioObj) {return;}
  var radioLength = radioObj.length;
  if(radioLength == undefined)
  {
    radioObj.checked = (radioObj.value == newValue.toString());
    return;
  }
  for(var i = 0; i < radioLength; i++)
  {
    radioObj[i].checked = false;
    if(radioObj[i].value == newValue.toString())
    {
      radioObj[i].checked = true;
    }
  }
}

function opacity(id, opacStart, opacEnd, millisec)
{
  var speed = Math.round(millisec / 100);
  var timer = 0;
  if(opacStart > opacEnd)
  {
    for(i = opacStart; i >= opacEnd; i--)
    {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
  else if(opacStart < opacEnd)
  {
    for(i = opacStart; i <= opacEnd; i++)
    {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
}

function changeOpac(opacity, id)
{
  var object = document.getElementById(id).style; 
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
}

function getElementHeight(id)
{
  if (document.all)
  {
    var obj = document.all[id];
  }
  else if (document.getElementById)
  {
    var obj = document.getElementById(id);
  }
  if (isOpera)
  { 
    return obj.style.pixelHeight;
  }
  else
  {
    return obj.offsetHeight;
  }
}

function getElementWidth(id)
{
  if (document.all)
  {
    var obj = document.all[id];
  }
  else if (document.getElementById)
  {
    var obj = document.getElementById(id);
  }
  if (isOpera)
  { 
    return obj.style.pixelWidth;
  }
  else
  {
    return obj.offsetWidth;
  }
}

function getElemById(Elem)
{
  if (document.all)
  {
    return document.all[Elem];
  }
  else (document.getElementById)
  {
    return document.getElementById(Elem);
  }
}

function getElementLeft(Elem)
{
  var elem = getElemById(Elem);
  if (elem != null)
  {
    return (getLeft(elem));
  }
  else
  {
    return 0;
  }
}

function getLeft(elem)
{
  if (isObject(elem))
  {
    xPos = elem.offsetLeft;
    tempEl = elem.offsetParent;
    while (tempEl != null)
    {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
  }
  else
  {
    return 0;
  }
}

function getElementTop(Elem)
{
  var elem = getElemById(Elem);
  if (elem != null)
  {
    return getTop(elem);
  }
  else
  {
    return 0;
  }
}

function getTop(elem)
{
  if (isObject(elem))
  {
    yPos = elem.offsetTop;
    tempEl = elem.offsetParent;
    while (tempEl != null)
    {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
  }
  else
  {
    return 0;
  }
}

function getAvailableHeight()
{
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return (myHeight);
}

function getAvailableWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return (myWidth);
}

function showHide(nmObj)
{
  var obj = getElemById(nmObj);
  if (obj.style.display == 'none')
  {
    if (isIE)
    {
      obj.style.display = 'block';
    }
    else
    {
      obj.style.display = 'table-row';
    }
  }
  else
  {
    obj.style.display = 'none';
  }
}

function show(nmObj)
{
  var obj = getElemById(nmObj);
  if (isIE)
  {
    obj.style.display = 'block';
  }
  else
  {
    obj.style.display = 'table-row';
  }
}

function hide(nmObj)
{
  var obj = getElemById(nmObj);
  obj.style.display = 'none';
}

function carregando(estado, percent)
{
/*
  var oBaseCarregando = getElemById('baseCarregando');
  oBaseCarregando.style.left = getElementLeft('conteudo')+'px';
  oBaseCarregando.style.top = getElementTop('tblMenu')+'px';
  oBaseCarregando.style.height = parseInt(getElementHeight('tblMenu')+getElementHeight('conteudo')+getElementHeight('sombrabase')+getElementHeight('copyright'))+'px';
  oBaseCarregando.style.width = getElementWidth('conteudo')+'px';
  var oIfCarregando = getElemById('ifCarregando');
  var oDivCarregando = getElemById('divCarregando');
  if (isBoolean(estado) && estado)
  {
    ServicosHide = true;
    smServicosHide(false);
    InstitucionalHide = true;
    smInstitucionalHide(false);
    AeronavesHide = true;
    smAeronavesHide(false);
    oBaseCarregando.style.display = 'block';
    oBaseCarregando.style.visibility = 'visible';
    oDivCarregando.style.display = 'block';
    oDivCarregando.style.visibility = 'visible';
    
    oIfCarregando.style.top = oDivCarregando.style.top;
    oIfCarregando.style.left = oDivCarregando.style.left;
    oIfCarregando.style.width = oDivCarregando.style.width;
    oIfCarregando.style.height = oDivCarregando.style.height;
    oIfCarregando.style.zIndex = oDivCarregando.style.zIndex - 1;
    oIfCarregando.style.display = 'block';
    oIfCarregando.style.visibility = 'visible';
    
    opacity('baseCarregando', 0, 50, 100);
    oDivCarregando.style.top =  (parseInt(getElementTop('baseCarregando'))+parseInt((getElementHeight('baseCarregando') - getElementHeight('divCarregando'))/2))+'px';
    oDivCarregando.style.left = (parseInt(getElementLeft('baseCarregando'))+parseInt((getElementWidth('baseCarregando') - getElementWidth('divCarregando'))/2))+'px';
    if (document.all)
    {
      document.all['progresso'].innerHTML = ((percent) ? '0%' : '');
    }
    else (document.getElementById)
    {
      document.getElementById('progresso').innerHTML = ((percent) ? '0%' : '');
    }
  }
  else
  {
    if (document.all)
    {
      document.all['progresso'].innerHTML = ((percent) ? '0%' : '');
    }
    else (document.getElementById)
    {
      document.getElementById('progresso').innerHTML = ((percent) ? '0%' : '');
    }
    oIfCarregando.style.display = 'none';
    oIfCarregando.style.visibility = 'hidden';
    oDivCarregando.style.display = 'none';
    oDivCarregando.style.visibility = 'hidden';
    opacity('baseCarregando', 50, 0, 500);
    window.setTimeout('hideBaseCarregando();', 500);
    iniInputs();
  }
*/
}

function hideBaseCarregando()
{
  var oTblMenu = getElemById('tblMenu');
  oTblMenu.style.display = 'block';
  oTblMenu.style.visibility = 'visible';
  var oSombrabase = getElemById('sombrabase');
  oSombrabase.style.visibility = 'visible';
  var oCopyright = getElemById('copyright');
  oCopyright.style.visibility = 'visible';
  var oBaseCarregando = getElemById('baseCarregando');
  oBaseCarregando.style.display = 'none';
  oBaseCarregando.style.visibility = 'hidden';
}

function getXMLHttp()
{
  if (window.XMLHttpRequest)
  {// (IE7.0+/FF/Safari/Opera7.6+)
    return new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {// ActiveX (IE5.x, IE5.5+ & IE6/MSXML2+)
   // Obtém-se o Objeto ActiveX mais recente
    try
    { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); }
    catch(e)
    {
      try
      { return new ActiveXObject('Msxml2.XMLHTTP.5.0'); }
      catch(e)
      {
        try
        { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); }
        catch(e)
        {
          try
          { return new ActiveXObject('MSXML2.XMLHTTP.3.0'); }
          catch(e)
          {
            try
            { return new ActiveXObject('Msxml2.XMLHTTP'); }
            catch(e)
            {
              try
              // ActiveX (IE5+/MSXML1)
              { return new ActiveXObject('Microsoft.XMLHTTP'); }
              catch(e)
              // IE5.01 não suporta
              { return false; }
            }
          }
        }
      }
    }
  }
  return false;
}

function createQuery(form)
{
  var oForm = getElemById(form);
  var elements = oForm.elements;
  var pairs = new Array();
  for (var i = 0; i < elements.length; i++)
  {
    if (elements[i].type.toLowerCase() == "radio")
    {
      if ((name = elements[i].name) && (value = getCheckedValue(elements[i])))
      {
        pairs.push(name + '=' + encodeURIComponent(value));
      }
    }
    else
    {
      if ((name = elements[i].name) && (value = elements[i].value))
      {
        pairs.push(name + '=' + encodeURIComponent(value));
      }
    }
  }
  return pairs.join('&');
}

function sendPOST(url, form)
{
  var xmlHttp = getXMLHttp();
  if (xmlHttp)
  {
    xmlHttp.onreadystatechange = function()
    {
      if (xmlHttp.readyState == 4)
      {
        if (xmlHttp.status == 200)
        {
          returnGetHtml = unescape(xmlHttp.responseText);
          if (returnGetHtml != '')
          {
            var contexto = returnGetHtml.split('<^>');
            preLerImagens(contexto[0], contexto[1]);
            contexto[0] = '';
            contexto[1] = '';
          }
          recebendoTexto = false;
        }
        else
        {
          carregando(false, true);
          recebendoTexto = false;
          alert('Has a problem with this requisition\n('+xmlHttp.status+' - '+xmlHttp.statusText+')');
        }
      }
    }
    carregando(true, true);
    var oForm = getElemById(form);
    oForm.action = url;
    if (isGecko)
    {
      xmlHttp.open('POST', url, true);
    }
    else
    {
      xmlHttp.open('POST', url, false);
    }
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-1');
    xmlHttp.send(createQuery(form));
  }
  else
  {
    alert(msgNoAjax);
  }
}

function getHtml(url)
{
  if (!recebendoTexto)
  {
    recebendoTexto = true;
    var returnGetHtml = '';
    var xmlHttp = getXMLHttp();
    if (xmlHttp)
    {
      xmlHttp.onreadystatechange=function()
      {
        if (xmlHttp.readyState == 4)
        {
          if (xmlHttp.status == 200)
          {
            returnGetHtml = unescape(xmlHttp.responseText);
            if (returnGetHtml != '')
            {
              var contexto = returnGetHtml.split('<^>');
              preLerImagens(contexto[0], contexto[1]);
              contexto[0] = '';
              contexto[1] = '';
            }
            recebendoTexto = false;
          }
          else
          {
            carregando(false, true);
            recebendoTexto = false;
            alert('Has a problem with this requisition\n('+xmlHttp.status+' - '+xmlHttp.statusText+')');
          }
        }
      }
      carregando(true, true);
      if (isGecko)
      {
        xmlHttp.open("GET", url, true);
      }
      else
      {
        xmlHttp.open("GET", url, false);
      }
      xmlHttp.send(null);
    }
    else
    {
      alert(msgNoAjax);
    }
  }
  else
  {
    alert('Please wait, processing ...');
  }
}

function preLerImagens(imgs, html)
{
  var aImagens = imgs.split('<|>');
  totImagensLer = aImagens.length;
  imagensLidas = 0;
  aPreImagens = new Array();
  for (var i = 0; i < aImagens.length; i++)
  {
    aPreImagens[i] = new Image(100,100);
    aPreImagens[i].onabort = function()
    {
      fimPreLerImagens(html);
    };
    aPreImagens[i].onerror = function()
    {
      imagensLidas++;
      mostrarProgresso(parseInt((imagensLidas * 100) / totImagensLer)+'%');
      fimPreLerImagens(html);
    };
    aPreImagens[i].onload = function()
    {
      imagensLidas++;
      mostrarProgresso(parseInt((imagensLidas * 100) / totImagensLer)+'%');
      fimPreLerImagens(html);
    };
    aPreImagens[i].src = aImagens[i];
  }
}

function fimPreLerImagens(html)
{
  if (imagensLidas >= totImagensLer)
  {
    if (document.all)
    {
      document.all['conteudo'].innerHTML = html;
    }
    else (document.getElementById)
    {
      document.getElementById('conteudo').innerHTML = html;
    }
    aPreImagens = new Array();
    carregando(false, true);
  }
}

function mostrarProgresso(percentual)
{
  if (document.all)
  {
    document.all['progresso'].innerHTML = percentual;
  }
  else (document.getElementById)
  {
    document.getElementById('progresso').innerHTML = percentual;
  }
}

function evr(txt)
{
  var oIFEVR = getElemById('ifEVR');
  var ml = 'mailto:'+txt+'@voerio.com';
  if (isIE)
  {
    oIFEVR.document.location.replace(ml);
  }
  else
  {
    oIFEVR.src = ml;
  }
}

function rd(doc)
{
  var oIFEVR = getElemById('ifEVR');
  var em = '';
  em += 'mailto:';
  em += 'atendimento';
  em += '@voerio.com?subject=Requisicao de documento publico: '+doc;
  if (isIE)
  {
    oIFEVR.document.location.replace(em);
  }
  else
  {
    oIFEVR.src = em;
  }
}

function smServicosShow()
{
  ServicosHide = false;
}

function smServicosHide(inicio)
{
  if (ServicosHide)
  {
    var oSmServicos = getElemById('smServicos');
    oSmServicos.style.display = 'none';
  }
  else if (inicio)
  {
    ServicosHide = true;
    window.setTimeout('smServicosHide(false);', 150);
  }
}

function smInstitucionalShow()
{
  InstitucionalHide = false;
}

function smInstitucionalHide(inicio)
{
  if (InstitucionalHide)
  {
    var oSmInstitucional = getElemById('smInstitucional');
    oSmInstitucional.style.display = 'none';
  }
  else if (inicio)
  {
    InstitucionalHide = true;
    window.setTimeout('smInstitucionalHide(false);', 150);
  }
}

function institucional()
{
  if (InstitucionalHide)
  {
    InstitucionalHide = false;
    var oSmInstitucional = getElemById('smInstitucional');
    oSmInstitucional.style.top = (30+getElementTop('mnInstitucional'))+'px';
    oSmInstitucional.style.left = (getElementLeft('mnInstitucional')-155)+'px';
    oSmInstitucional.style.display = 'block';
  }
}

function smAeronavesShow()
{
  AeronavesHide = false;
}

function smAeronavesHide(inicio)
{
  if (AeronavesHide)
  {
    var oSmAeronaves = getElemById('smAeronaves');
    oSmAeronaves.style.display = 'none';
  }
  else if (inicio)
  {
    AeronavesHide = true;
    window.setTimeout('smAeronavesHide(false);', 150);
  }
}


function servicos()
{
  if (ServicosHide)
  {
    ServicosHide = false;
    var oSmServicos = getElemById('smServicos');
    oSmServicos.style.top = (30+getElementTop('mnServicos'))+'px';
    oSmServicos.style.left = getElementLeft('mnServicos')+'px';
    oSmServicos.style.display = 'block';
  }
}

function aeronaves()
{
  if (AeronavesHide)
  {
    AeronavesHide = false;
    var oSmAeronaves = getElemById('smAeronaves');
    oSmAeronaves.style.top = (30+getElementTop('mnAeronaves'))+'px';
    oSmAeronaves.style.left = (getElementLeft('mnAeronaves')-110)+'px';
    oSmAeronaves.style.display = 'block';
  }
}

function overCargas()
{
  var oDsCargas = getElemById('dsCargas');
  oDsCargas.style.color = '#000000';

  var oImgCargas = getElemById('imgCargas');
  oImgCargas.src = 'img/servicos/cargo_o.jpg';
}

function outCargas()
{
  var oDsCargas = getElemById('dsCargas');
  oDsCargas.style.color = '#979797';

  var oImgCargas = getElemById('imgCargas');
  oImgCargas.src = 'img/servicos/cargo_u.jpg';
}

function overTickets()
{
  var oDsCargas = getElemById('dsTickets');
  oDsCargas.style.color = '#000000';
  
   oImgTickets = getElemById('imgTickets');
   oImgTickets.src = 'img/servicos/passageiro_o.jpg';
}

function outTickets()
{
  var oDsCargas = getElemById('dsTickets');
  oDsCargas.style.color = '#979797';
  
   oImgTickets = getElemById('imgTickets');
   oImgTickets.src = 'img/servicos/passageiro_u.jpg';
}

function addEvent(obj, type, fn)
{
  if (obj.attachEvent)
  {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function () {obj['e'+type+fn](window.event);};
    obj.attachEvent('on'+type, obj[type+fn]);
  }
  else
  {
    obj.addEventListener(type, fn, false);
  }
}

function removeEvent(obj, type, fn)
{
  if (obj.detachEvent)
  {
    obj.detachEvent('on'+type, obj[type+fn]);
    obj[type+fn] = null;
  }
  else
  {
    obj.removeEventListener(type, fn, false);
  }
}

function inputOn()
{
  this.className = 'inputOn';
}

function inputOut()
{
  this.className = 'inputOut';
}

function iniInputs()
{
  var inptxts = document.getElementsByTagName('input');
  if ((inptxts) && (inptxts.length>0))
  {
    for (var i = 0; i < inptxts.length; ++i)
    {
      if (inptxts[i].type == "text")
      {
        inptxts[i].className = 'inputOut';
        addEvent(inptxts[i], 'focus', inputOn)
        addEvent(inptxts[i], 'blur', inputOut)
        inptxts[i].style.verticalAlign = 'middle';
        inptxts[i].style.textAlign = 'left';
        inptxts[i].style.height = '15px';
      }
    }
  }
  var inptxts = document.getElementsByTagName('textarea');
  if ((inptxts) && (inptxts.length>0))
  {
    for (var i = 0; i < inptxts.length; ++i)
    {
      inptxts[i].className = 'inputOut';
      addEvent(inptxts[i], 'focus', inputOn)
      addEvent(inptxts[i], 'blur', inputOut)
      inptxts[i].style.verticalAlign = 'top';
      inptxts[i].style.textAlign = 'justify';
    }
  }
  var inptxts = document.getElementsByTagName('select');
  if ((inptxts) && (inptxts.length>0))
  {
    for (var i = 0; i < inptxts.length; ++i)
    {
      inptxts[i].className = 'inputOut';
      addEvent(inptxts[i], 'focus', inputOn)
      addEvent(inptxts[i], 'blur', inputOut)
      inptxts[i].style.height = '20px';
      inptxts[i].style.verticalAlign = 'middle';
      inptxts[i].style.textAlign = 'left';
      inptxts[i].style.height = '15px';
    }
  }
}

function menuOver(nmObj)
{
  var oMnHome = getElemById('mnHome');
  var oMnFalecomario = getElemById('mnFalecomario');
  var oMnServicos = getElemById('mnServicos');
  var oMnInstitucional = getElemById('mnInstitucional');
  var oMnAeronaves = getElemById('mnAeronaves');
  var oMnIntranet = getElemById('mnIntranet');
  oMnHome.src='img/menu/home_'+((nmObj=='mnHome') ? 'o' : 'u')+'.gif';
  oMnFalecomario.src='img/menu/falecomario_'+((nmObj=='mnFalecomario') ? 'o' : 'u')+'.gif';
  oMnServicos.src='img/menu/servicos_'+((nmObj=='mnServicos') ? 'o' : 'u')+'.gif';
  oMnInstitucional.src='img/menu/institucional_'+((nmObj=='mnInstitucional') ? 'o' : 'u')+'.gif';
  oMnAeronaves.src='img/menu/aeronaves_'+((nmObj=='mnAeronaves') ? 'o' : 'u')+'.gif';
  oMnIntranet.src='img/menu/intranet_'+((nmObj=='mnIntranet') ? 'o' : 'u')+'.gif';
}

function menuOut(nmObj)
{
  var oMnHome = getElemById('mnHome');
  var oMnFalecomario = getElemById('mnFalecomario');
  var oMnServicos = getElemById('mnServicos');
  var oMnInstitucional = getElemById('mnInstitucional');
  var oMnAeronaves = getElemById('mnAeronaves');
  var oMnIntranet = getElemById('mnIntranet');
  oMnHome.src='img/menu/home_'+(((nmObj=='mnHome' && nmObj==mnOn) || mnOn=='mnHome') ? 'o' : 'u')+'.gif';
  oMnFalecomario.src='img/menu/falecomario_'+(((nmObj=='mnFalecomario' && nmObj==mnOn) || mnOn=='mnFalecomario') ? 'o' : 'u')+'.gif';
  oMnServicos.src='img/menu/servicos_'+(((nmObj=='mnServicos' && nmObj==mnOn) || mnOn=='mnServicos') ? 'o' : 'u')+'.gif';
  oMnInstitucional.src='img/menu/institucional_'+(((nmObj=='mnInstitucional' && nmObj==mnOn) || mnOn=='mnInstitucional') ? 'o' : 'u')+'.gif';
  oMnAeronaves.src='img/menu/aeronaves_'+(((nmObj=='mnAeronaves' && nmObj==mnOn) || mnOn=='mnAeronaves') ? 'o' : 'u')+'.gif';
  oMnIntranet.src='img/menu/intranet_'+(((nmObj=='mnIntranet' && nmObj==mnOn) || mnOn=='mnIntranet') ? 'o' : 'u')+'.gif';
}

function setMenu(nmObj)
{
  mnOn = nmObj;
  var oMnHome = getElemById('mnHome');
  var oMnFalecomario = getElemById('mnFalecomario');
  var oMnServicos = getElemById('mnServicos');
  var oMnInstitucional = getElemById('mnInstitucional');
  var oMnAeronaves = getElemById('mnAeronaves');
  var oMnIntranet = getElemById('mnIntranet');
  oMnHome.src='img/menu/home_'+((nmObj=='mnHome') ? 'o' : 'u')+'.gif';
  oMnFalecomario.src='img/menu/falecomario_'+((nmObj=='mnFalecomario') ? 'o' : 'u')+'.gif';
  oMnServicos.src='img/menu/servicos_'+((nmObj=='mnServicos') ? 'o' : 'u')+'.gif';
  oMnInstitucional.src='img/menu/institucional_'+((nmObj=='mnInstitucional') ? 'o' : 'u')+'.gif';
  oMnAeronaves.src='img/menu/aeronaves_'+((nmObj=='mnAeronaves') ? 'o' : 'u')+'.gif';
  oMnIntranet.src='img/menu/intranet_'+((nmObj=='mnIntranet') ? 'o' : 'u')+'.gif';
}

function go_home()
{
  setMenu('mnHome');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=servico&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=servico&ajax=off');
  }
}

function go_falecomario()
{
  setMenu('mnFalecomario');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=falecomario&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=falecomario&ajax=off');
  }
}

function go_servicos()
{
  setMenu('mnServicos');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=servicos&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=servicos&ajax=off');
  }
}

function go_servicoscargas()
{
  go_acmiservicos();
}

function go_servicospassageiros()
{
  go_acmiservicos();
}

function go_acmiservicos()
{
  setMenu('mnServicos');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=acmiservicos&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=acmiservicos&ajax=off');
  }
}

function go_acmimodalidades()
{
  setMenu('mnServicos');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=acmimodalidades&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=acmimodalidades&ajax=off');
  }
}

function go_acmivantagens()
{
  setMenu('mnServicos');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=acmivantagens&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=acmivantagens&ajax=off');
  }
}

function go_acmiformulario()
{
  setMenu('mnServicos');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=acmiformulario&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=acmiformulario&ajax=off');
  }
}

function go_instmissao()
{
  setMenu('mnInstitucional');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=instmissao&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=instmissao&ajax=off');
  }
}

function go_instsobre()
{
  setMenu('mnInstitucional');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=instsobre&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=instsobre&ajax=off');
  }
}

function go_instinfraestrutura()
{
  setMenu('mnInstitucional');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=instinfraestrutura&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=instinfraestrutura&ajax=off');
  }
}

function go_instambiental()
{
  setMenu('mnInstitucional');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=instambiental&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=instambiental&ajax=off');
  }
}

function go_instdocs()
{
  setMenu('mnInstitucional');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=instdocs&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=instdocs&ajax=off');
  }
}

function go_tabalheconosco()
{
  var url = 'http://www.gd9rh.com.br/form.php?to=cvautsitevoerio@gd9rh.com.br';
  var cWidth = 750;
  var cHeight = 600;
  var cLeft = 0;
  var cTop = 0;
  if (isIE)
  { //Internet Explorer
    window.open(url,'CorretorOnLine','width='+cWidth+'px,height='+cHeight+'px,left='+cLeft+'px,top='+cTop+'px, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes');
  }
  else
  { //Netscape
    window.open(url,'CorretorOnLine','width='+cWidth+'px,height='+cHeight+'px,screenX='+cLeft+'px,screenY='+cTop+'px, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, titlebar("Corretor On-Line"), modal=no');
  }
}

function go_aeronavesdescricao()
{
  setMenu('mnAeronaves');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=aeronavesdescricao&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=aeronavesdescricao&ajax=off');
  }
}

function go_aeronavesareadeuso()
{
  setMenu('mnAeronaves');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=aeronavesareadeuso&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=aeronavesareadeuso&ajax=off');
  }
}

function go_aeronavesmanutencao()
{
  setMenu('mnAeronaves');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl=aeronavesmanutencao&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl=aeronavesmanutencao&ajax=off');
  }
}

function go_intranet()
{
  carregando(true, false);
  document.location.replace('http://www.voerio.com/controle/');
}

function slideShow(ind)
{
  if (isIE)
  {
    ind = (isNumber(ind) ? ind : 0);
    ind = (((ind>=0) && (ind<=(aImgsSlideShow.length - 1))) ? ind : 0);
    var imgTopo = new Object();
    if (document.all)
    {
      imgTopo = document.all['imgTopo'];
    }
    else (document.getElementById)
    {
      imgTopo = document.getElementById('imgTopo');
    }
    if (imgTopo)
    {
      imgTopo.filters.item(0).Apply();
      imgTopo.src = aImgsSlideShow[ind];
      imgTopo.filters.item(0).Play();
      ind++;
      setTimeout('slideShow('+ind+');', 5000);
    }
    else
    {
      setTimeout('slideShow(0);', 2000);
    }
  }
}

function ajustaJanela()
{
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth,screen.availHeight);
  var h = parseInt(getAvailableHeight()-20);
  var w = getAvailableWidth();
  var otdWindow = getElemById('tdWindow');
  if (otdWindow.style.height != (h+'px'))
  {
    otdWindow.style.height = h+'px';
  }
  if (otdWindow.style.width != (w+'px'))
  {
    otdWindow.style.width = w+'px';
  }
  var otdBody = getElemById('tdBody');
  if (otdBody.style.height != otdWindow.style.height)
  {
    otdBody.style.height = otdWindow.style.height;
  }
//  var oLogo = getElemById('logo');
//  oLogo.style.top = getElementTop('mainContent')+'px';
//  oLogo.style.left = getElementLeft('mainContent')+'px';
}

function iniciaJanela()
{
  ajustaJanela();
  menuOut('mnHome');
  if (ajaxSupport)
  {
    getHtml('rio.php?tpl='+tplinicial+'&ajax=on');
  }
  else
  {
    carregando(true, false);
    document.location.replace('rio.php?tpl='+tplinicial+'&ajax=off');
  }
}

function validaDados()
{
  var oAeronave = getElemById('aeronave');
  var sAeronave = getCheckedValue(oAeronave);
  var oNome = getElemById('nome');
  var sNome = trim(oNome.value);
  var oEmpresa = getElemById('empresa');
  var sEmpresa = trim(oEmpresa.value);
  var oTelefonecontato = getElemById('telefonecontato');
  var sTelefonecontato = trim(oTelefonecontato.value);
  var oEmail = getElemById('email');
  var sEmail = trim(oEmail.value);
  var isEmailValid = true;
  var iSize = sEmail.length;
  var i = 1;
  while ((i < iSize) && (sEmail.charAt(i) != "@")) { i++ }
  if ((i >= iSize) || (sEmail.charAt(i) != "@"))
  { isEmailValid = false; }
  if (isEmailValid)
  {
    while ((i < iSize) && (sEmail.charAt(i) != ".")) { i++ }
    if ((i >= iSize - 1) || (sEmail.charAt(i) != "."))
    { isEmailValid = false; }
  }
  var oQt = getElemById('qt');
  if ((oQt.value > 0) || validaItinerario())
  {
    var ok0 = (sAeronave != '');
    var ok1 = (sNome != '');
    var ok2 = (sEmpresa != '');
    var ok3 = (sTelefonecontato != '');
    var ok4 = ((sEmail != '') && isEmailValid);
    if (ok0)
    {
      if (!ok1) { oNome.focus(); } else
      {
        if (!ok2) { oEmpresa.focus(); } else
        {
          if (!ok3) { oTelefonecontato.focus(); } else
          {
            if (!ok4) { oEmail.focus(); } else
            {
              return true;
            }
          }
        }
      }
    }
    if (!(ok0&&ok1&&ok2&&ok3&&ok4))
    {
      carregando(false, false);
      alert('The fields "Aircraft", "Name", "Company", "Contact Phone Number" and "e-mail" are obligatory, please fill them correctly!');
    }
  }
  carregando(false, false);
  return false;
}

function validaItinerario()
{
  var oFrmACMI = getElemById('frmACMI');
  var oDia = getElemById('dia');
  var oMes = getElemById('mes');
  var oAno = getElemById('ano');
  var oOrigem = getElemById('origem');
  var origem = trim(oOrigem.value);
  var oDestino = getElemById('destino');
  var destino = trim(oDestino.value);
  var oHora = getElemById('hora');
  var oMinuto = getElemById('minuto');
  var ok1 = (oMes[oMes.selectedIndex].text != '--------');
  var ok2 = (oDia[oDia.selectedIndex].text != '--');
  var ok3 = (oAno[oAno.selectedIndex].text != '----');
  var ok4 = (origem.length > 0);
  var ok5 = (destino.length > 0);
  var ok6 = (oHora[oHora.selectedIndex].text != '--');
  var ok7 = (oMinuto[oMinuto.selectedIndex].text != '--');
  if (!ok1) { oMes.focus(); } else
  {
    if (!ok2) { oDia.focus(); } else
    {
      if (!ok3) { oAno.focus(); } else
      {
        if (!ok4) { oOrigem.focus(); } else
        {
          if (!ok5) { oDestino.focus(); } else
          {
            if (!ok6) { oHora.focus(); } else
            {
              if (!ok7) { oMinuto.focus(); } else
              {
                return true;
              }
            }
          }
        }
      }
    }
  }
  if (!(ok1&&ok2&&ok3&&ok4&&ok5&&ok6&&ok7))
  {
    carregando(false, false);
    alert('Please fill all the itinerary\'s fields.');
  }
  carregando(false, false);
  return false;
}

function sendformacmi()
{
  carregando(true, false);
  if (validaDados())
  {
    var oAcao = getElemById('acao');
    oAcao.value = 'send';
    if (ajaxSupport)
    {
      sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI');
    }
    else
    {
      var oFrmACMI = getElemById('frmACMI');
      oFrmACMI.submit();
    }
  }
}

function adicionarItinerario()
{
  carregando(true, false);
  if (validaItinerario())
  {
    var oAcao = getElemById('acao');
    oAcao.value = 'adicionar';
    if (ajaxSupport)
    {
      sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI')
    }
    else
    {
      var oFrmACMI = getElemById('frmACMI');
      oFrmACMI.submit();
    }
  }
}

function deletarItinerario(id)
{
  var okdel = confirm("Confirma a exclusão desse itinerário?")
  if (okdel)
  {
    carregando(true, false);
    var oAcao = getElemById('acao');
    oAcao.value = 'deletar';
    var oID = getElemById('itinerarioID');
    oID.value = id;
    if (ajaxSupport)
    {
      sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI');
    }
    else
    {
      var oFrmACMI = getElemById('frmACMI');
      oFrmACMI.submit();
    }
  }
}

function editarItinerario(id)
{
  carregando(true, false);
  var oAcao = getElemById('acao');
  oAcao.value = 'editar';
  var oID = getElemById('itinerarioID');
  oID.value = id;
  if (ajaxSupport)
  {
    sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI');
  }
  else
  {
    var oFrmACMI = getElemById('frmACMI');
    oFrmACMI.submit();
  }
}

function salvarEdicao()
{
  carregando(true, false);
  var oAcao = getElemById('acao');
  oAcao.value = 'salvar';
  if (ajaxSupport)
  {
    sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI');
  }
  else
  {
    var oFrmACMI = getElemById('frmACMI');
    oFrmACMI.submit();
  }
}

function cancelarEdicao()
{
  carregando(true, false);
  var oAcao = getElemById('acao');
  oAcao.value = 'show';
  var oID = getElemById('itinerarioID');
  oID.value = '';
  if (ajaxSupport)
  {
    sendPOST('rio.php?tpl=acmiformulario&ajax=on', 'frmACMI');
  }
  else
  {
    var oFrmACMI = getElemById('frmACMI');
    oFrmACMI.submit();
  }
}

function selAreaDeUso(img, pathmg)
{
  var oImg = getElemById(img);
  oImg.src = pathmg;
}

/*function setLinguagem(lg, page)
{
  var href = window.location.href.split("/");
  var url = 'http://';
  if (href.length>1)
  {
    url += href[2];
  }
  if (href.length>3)
  {
    url += '/'+href[3];
  }
  url += '/'+lg+'/'+page;
  document.location.replace(url);
}*/
function setLinguagem(lg, page)
{
	
  var href = window.location.href.split("/");
  var url = 'http://';
  if (href.length>1)
  {
   url += href[2];
   //alert('if href > 1: '+url);
  }
  else (href.length>3)
  {
   url += '/';
   //alert('if href > 3: '+url);
  }
  //alert(url);
  url += '/'+lg+'/'+page;
  //alert('formada: '+url);
  document.location.replace(url);
}

window.onload = function() { iniInputs(); };

