var flask = null;
// catches vers <4 browsers

// GENERIC BROWSER DETECTION SCRIPT
function isNet4() {
  appName = navigator.appName;
  appLongVer = navigator.appVersion;
  appVer = appLongVer.substring(0, 1);
  if ((appName == "Netscape") && (appVer <= 4)) return true;
  return false;
}
function isNet6() {
  appName = navigator.appName;
  appLongVer = navigator.appVersion;
  appVer = appLongVer.substring(0, 1);
  if ((appName == "Netscape") && (appVer >= 5)) return true;
  return false;
}
function isIE() {
  appName = navigator.appName;
  appLongVer = navigator.appVersion;
  appVer = appLongVer.substring(0, 1);
  if ((appName == "Microsoft Internet Explorer") && (appVer >= 4)) return true;
  return false;
}

var isNav, isIE;
  if(parseInt(navigator.appVersion) >= 4){
    if(navigator.appName == "Netscape"){
      isNav = true;
    }
    else{
      isIE = true;
    }
  }

  function keyPress(evt){
    if(isNav){
      if((evt.which > 31 && evt.which < 48) || (evt.which > 57) ) {
         return false;
      }
    }
    else {
      if(window.event.keyCode < 48 || window.event.keyCode > 57) {
        window.event.returnValue = false;
      }
    }
  }

//This function controls submitting the miles balance form on top of the each page when a non-numeric number entered.
function submitMiles(form) {
    if(form.milesBalance.value > 0) {
      form.submit();
    }
  }

// SCRIPT TO CONTROL OPENING AND CLOSING AND ROLLOVERS FOR LEFT HAND NAV AND LEFT HAND SUBNAV
function openNav(groupNum) {
  var navGroupPref = "navGroup";

  // open selected group
  if (getHtmlElem(navGroupPref + groupNum).style.display == 'block') {
    getHtmlElem(navGroupPref + groupNum).style.display = "none";
  } else {
    getHtmlElem(navGroupPref + groupNum).style.display = "block";
  }

  // hide other groups
  var i = 1;
  while (getHtmlElem(navGroupPref + i) != null) {
    if (String(i) != groupNum) {
      getHtmlElem(navGroupPref + i).style.display = "none";
    }
    i++;
  }
}

function getHtmlElem(id) {
  if (isNet6()) {
    return document.getElementById(id);
  } else if (isIE()) {
    return document.all(id);
  } else {
    return document.getElementById(id);
  }
  return null;
}

// SCRIPT TO SET THE RELEVANT LEFT HAND NAV LINK TO HIGHLIGHTED
function setPageLink(selTab,selTxt) {

  if (isNet4()) return;
  flask = selTab;
  var tst = /^tab[0-9a-zA-Z]+_[0-9a-zA-Z]+$/;
  var str = selTab;
  var selectedTab = document.getElementById(selTab);
  var selectedTxt = document.getElementById(selTxt);
  alert(selectedTxt);
  if(selectedTxt != null){
    selectedTxt.style.color = "navy";
  }  
}



//	NEW POP-UP WINDOWS: CHECKS FOR MAC IE FOR SIZE INCONTINUITY
function new_openWindow(URL, StWidth, StHeight, scroll, resize, name){
  //var agent = navigator.userAgent.toLowerCase();
  var dimensionsSTAN = 'width=' + StWidth + ',height=' + StHeight;
  var dimensionsMCIE = 'width=' + (StWidth - 15) + ',height=' + (StHeight - 14);
  var winProperties = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=' + resize;

  if (checkBrowser()){
    window.open(URL, 'name', winProperties +','+ dimensionsSTAN).focus();
  } else {
    window.open(URL, 'name', winProperties +','+ dimensionsMCIE).focus();
  }
}

function checkBrowser(){
    var version  = parseFloat(navigator.appVersion);
    var minVIE = 4.0;
    var minVNS = 4.0;
    var suitableBrowser = false;

    if (navigator.appName.indexOf('Netscape') != -1) {
      if (version >= minVNS){
      suitableBrowser = true;
      }
    }
    else if ((navigator.appName.indexOf('Microsoft') != -1)&&(navigator.appVersion.indexOf('Macintosh') == -1)) {
      if(version >= minVIE){
      suitableBrowser = true;
      }
    }
    return(suitableBrowser);
  }


//	POP-UP WINDOWS
function remoteWindow(URL, width, height, scroll, resize, name) {
  // set window size
  var agent=navigator.userAgent.toLowerCase();
  var dimensions = 'width=' + width + ',height=' + height;
  var winProperties = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=' + resize;

  //location of popup
  // winProperties += ",top=0,left=0,";
  winProperties += ",top="+((screen.height-height)/2)+",left="+((screen.width-width)/2)+ ",";
  remote = window.open(URL, name, winProperties +','+ dimensions);

  //	create opener reference if browser doesn't do it
  if (remote.opener == null) {
    remote.opener = self;
  }

  //	bring remote to top if supported
  if(agent.indexOf("msie 3") == -1) {
    remote.focus();
  }
}

// HREF - CLEAR DOTTED LINE (IE ONLY)
function clearMe() {
  if(this.blur)this.blur();
}

// Function to enable explicit form submission via enter key
function submitFormViaEnterKey(field, event) {
  var keyCode;
  if (window.event) {
    keyCode = window.event.keyCode;
  } else if (event) {
    keyCode = event.which;
  } else {
    return true;
  }

  if (keyCode == 13) {
    field.form.submit();
    return false;
  } else {
    return true;
  }

}

// MAC PRINT FIX SCRIPT: THIS FUNCTION WILL PRINT OUT THE PAGE ON A PC AND PUT UP AN ALERT ON A MAC
function platDetect() {
  if ((navigator.appVersion.indexOf("Mac") != -1)) {
    alert("For Mac-users:\rPress 'APPLE' and 'P' to print this page");
  } else {
    printWindow();
  }
}

function printWindow(){
  browserVersion = parseInt(navigator.appVersion)
  if (browserVersion >= 4) window.print()
}


// EOF

