// Author: Todd Markelz
//
// Joga.com Companion specific install functions

/**
 * Check if user has Firefox 1.5+
 * Display error message inline with link to upgrade
 */
function isFF15() {
  var match = navigator.userAgent.match(/Firefox\/([\d\.]+)/);
  var valid = match && parseFloat(match[1]) >= 1.5;

  if (!valid) {
    document.getElementById('ff15').style.display='block';
  }
  if (valid == null) valid = false;

  return valid;
}

/**
 * Decide which file to serve the user based on browser and OS
 */
function chooseInstall() {
  var match = navigator.userAgent.match(/Firefox\/([\d\.]+)/);
  var os = checkOS(['win']);
  var install = 'xpi';	//By default serve xpi
 
  if (os[0] && match==null) {
    //If user is on Win with any non-Firefox browser serve exe
    install = 'exe';
  }
 
  return install;
}

/**
 * Wrapper for the default check function that triggers a check for Firefox 1.5+
 */
function callCheck() {
  var valid = isFF15();
  if (valid) {
    return check('https://addons.mozilla.org/google/joga_companion.html', 'http://dl.google.com/firefox/joga/companion.xpi', 'http://toolbar.google.com/googly.gif', 'Joga.com Companion', 'Joga.com Companion requires Firefox 1.5 or later.\n\nWould you like to download the latest version of Firefox?', '../../');
  }
  else {
    return valid;
  }
}