function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById(iframeName);
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto";   
    var docHt = getDocHeight(iframeWin.document);
    if (docHt) iframeEl.style.height = docHt + 50 + "px";
  }
}

function goSetHeight() 
{
  if (parent == window) return;
  else parent.setIframeHeight('contentIFrame');
}
function goSetResultsHeight()
{
  parent.parent.setIframeHeight('contentIFrame');
}

function adjustResultHt(numResults)
{
  if(numResults >= 5)
  {
    parent.document.getElementById('airResults').style.height = "150px";
  }
  else if(numResults == 4)
  {
    parent.document.getElementById('airResults').style.height = "126px";
  }
  else if(numResults == 3)
  {
    parent.document.getElementById('airResults').style.height = "101px";
  }
  else if(numResults == 2)
  {
    parent.document.getElementById('airResults').style.height = "76px";
  }
  else if(numResults == 1)
  {
    parent.document.getElementById('airResults').style.height = "48px";
  }
}

function airportSearch()
{
  var selection = document.getElementById('airCriteria').value;
  var url = "http://www.safetypilotclub.com/AirportID.php";

  document.getElementById('resultsSpan').style.display = "block";
  goSetHeight();
  if(selection == "ID")
  {
    url = url + "?airCriteria=ID&airportID=";
    url = url + document.getElementById('airportID').value;
    document.getElementById('airResults').src = url;
  }
  else if(selection == "CityState")
  {
    url = url + "?airCriteria=CityState&airCity=";
    url = url + document.getElementById('airCity').value;
    url = url + "&airState=";
    url = url + document.getElementById('airState').value;
    document.getElementById('airResults').src = url;
  }
  else if(selection == "Name")
  {
    url = url + "?airCriteria=Name&airName=";
    url = url + document.getElementById('airName').value;
    document.getElementById('airResults').src = url;
  }
  goSetHeight();
}

function dispAirportResults()
{
  parent.document.getElementById('resultsSpan').style.display = "block";
  goSetResultsHeight();
}

function airportSelect()
{
  var selection = document.getElementById('airCriteria').value;
  if(selection == "ID")
  {
    document.getElementById('airResults').src = '';
    document.getElementById('CityStateSpan').style.display = "none";
    document.getElementById('NameSpan').style.display = "none";
    document.getElementById('IDSpan').style.display = "block";
    document.getElementById('buttonSpan').style.display = "block";
    document.getElementById('resultsSpan').style.display = "none";
  }
  else if(selection == "CityState")
  {
    document.getElementById('airResults').src = '';
    document.getElementById('CityStateSpan').style.display = "block";
    document.getElementById('NameSpan').style.display = "none";
    document.getElementById('IDSpan').style.display = "none";
    document.getElementById('buttonSpan').style.display = "block";
    document.getElementById('resultsSpan').style.display = "none";
  }
  else if(selection == "Name")
  {
    document.getElementById('airResults').src = '';
    document.getElementById('CityStateSpan').style.display = "none";
    document.getElementById('NameSpan').style.display = "block";
    document.getElementById('IDSpan').style.display = "none";
    document.getElementById('buttonSpan').style.display = "block";
    document.getElementById('resultsSpan').style.display = "none";
  }
  else
  {
    document.getElementById('CityStateSpan').style.display = "none";
    document.getElementById('NameSpan').style.display = "none";
    document.getElementById('IDSpan').style.display = "none";
    document.getElementById('buttonSpan').style.display = "none";
    document.getElementById('resultsSpan').style.display = "none";
    document.getElementById('airResults').src = '';
  }
  goSetHeight();
}

function setAirport(id)
{
  parent.document.getElementById('airportVal').value = id;
  return;
}

function setAirport1(id)
{
	parent.document.getElementById('airportVal').value = id;
	return;
}


function getcookie(cookiename) 
{
  var cookiestring=""+document.cookie;
  var index1=cookiestring.indexOf(cookiename);
  if (index1==-1 || cookiename=="") return ""; 
  var index2=cookiestring.indexOf(';',index1);
  if (index2==-1) index2=cookiestring.length; 
  return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
var newwindow;
function popInfo(url)
{
	newwindow=window.open(url,'name','height=350,width=465');
	if (window.focus) {newwindow.focus()}
}
function Go()
{
  return;
}
function GoTo()
{
  var url = this.LinkTxt;
  document.getElementById('contentIFrame').src = url;
  //updateActivity();
  return;
}
function GoToURL(URL)
{
  document.getElementById('contentIFrame').src = URL;
  return;
}
function GoToURLSubmit(URL)
{
  document.getElementById('contentIFrame').src = URL;
  return;
}
function constructLoginURL()
{
  var loginURL = "login.php?user=" + document.frmLogin.user.value + "&pass=" + document.frmLogin.pass.value;
  GoToURL(loginURL);
  return;
}
function constructLogoutURL()
{
  var logoutURL = "logout.php?user=" + document.frmLogin.user.value;
  GoToURL(logoutURL);
  return;
}
function trim(sString) 
{
  while (sString.substring(0,1) == ' ')
  {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}
