function getPlatform()
{
  if (navigator.platform.indexOf("Win32") != -1)
    return "Windows";
  else if (navigator.platform.indexOf("Linux") != -1)
    return "Linux";
  else if (navigator.userAgent.indexOf("Mac OS X") != -1)
    return "MacOSX";
  else if (navigator.platform.indexOf("Mac") != -1)
    return "Mac";
  return "Other";
}

var gWin32DownloadLink = "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/0.9.3/FirefoxSetup-0.9.3.exe";
var gLinuxDownloadLink = "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/0.9.3/firefox-0.9.3-i686-linux-gtk2+xft-installer.tar.gz";
var gMacOSDownloadLink = "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/0.9.3/firefox-0.9.3-mac.dmg.gz";
var gWin32DownloadSize = "(4.7MB)";
var gLinuxDownloadSize = "(8.1MB)"
var gMacOSDownloadSize = "(8.6MB)";

function writeNewDownloadsSidebar()
{
	document.writeln("<div class=\"download\">");
  // Show the dynamic links
  var platform = getPlatform();
  if (platform == "Mac")
    document.writeln("  <a href=\"\">MacOS 9 and earlier are not supported<\/a>");
  else {
    switch (platform) {
    case "Windows":
      document.writeln("    <h3><a href=\"/products/firefox/download.html?" + escape(gWin32DownloadLink) + "\" id=\"downloadLink\">Download Now!</a></h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Windows, English " + gWin32DownloadSize + "<\/span><\/span>");
      break;
    case "Linux":
      document.writeln("    <h3><a href=\"/products/firefox/download.html?" + escape(gLinuxDownloadLink) + "\" id=\"downloadLink\">Download Now!</a></h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Linux, English " + gLinuxDownloadSize + "<\/span><\/span>");
      break;
    case "MacOSX":
      document.writeln("    <h3><a href=\"/products/firefox/download.html?" + escape(gMacOSDownloadLink) + "\" id=\"downloadLink\">Download Now!</a></h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">MacOS X, English " + gMacOSDownloadSize + "<\/span><\/span>");
      break;
    default:
      document.writeln("    <h3><a href=\"/products/firefox/releases/#download\" id=\"downloadLink\">Download Now!</a></h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Undetermined<\/span><\/span>");
      break;
    }
  }
  document.writeln("    <\/div>");
  // box displaying CD link
  document.writeln("    <div class=\"shop\">");
  document.writeln("    Or, get  <a href=\"http://www.mozillastore.com/products/software/cd\">Firefox on a CD</a> from the <a href=\"http://www.mozillastore.com/\">Mozilla Store</a>.");
  document.writeln("    <\/div>");
}

function writeDownloadsSidebar()
{
  // Show the dynamic links
  document.writeln("<ul id=\"nav\">");
  document.writeln("  <li id=\"smartDownloadLink\">");

  var platform = getPlatform();
  if (platform == "Mac")
    document.writeln("  <a href=\"\">MacOS 9 and earlier are not supported<\/a>");
  else {
    switch (platform) {
    case "Windows":
      document.writeln("    <a href=\"/products/firefox/download.html?" + escape(gWin32DownloadLink) + "\" id=\"downloadLink\"><strong id=\"downloadText\">Download Now!<\/strong><br>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Windows, English<\/span><\/span>");
      break;
    case "Linux":
      document.writeln("    <a href=\"/products/firefox/download.html?" + escape(gLinuxDownloadLink) + "\" id=\"downloadLink\"><strong id=\"downloadText\">Download Now!<\/strong><br>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Linux, English<\/span><\/span>");
      break;
    case "MacOSX":
      document.writeln("    <a href=\"/products/firefox/download.html?" + escape(gMacOSDownloadLink) + "\" id=\"downloadLink\"><strong id=\"downloadText\">Download Now!<\/strong><br>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">MacOS X, English<\/span><\/span>");
      break;
    default:
      document.writeln("    <a href=\"/products/firefox/releases/#download\" id=\"downloadLink\"><strong id=\"downloadText\">Download Now!<\/strong><br>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Undetermined<\/span><\/span>");
      break;
    }
  }
  document.writeln("    <\/a>");
  document.writeln("  <\/li>");
  document.writeln("  <li id=\"othersystems\">");
  document.writeln("    <a href=\"/products/firefox/releases/#download\">Other Systems and Languages<\/a>");
  document.writeln("  <\/li>");
  document.writeln("  <li id=\"sysreq\">");
  document.writeln("    <a href=\"/products/firefox/system-requirements.html\">System Requirements<\/a>");
  document.writeln("  <\/li>");
  document.writeln("<\/ul>");
}

function writeDownloadsFrontpage()
{
	document.writeln("<div class=\"download\">");
  // Show the dynamic links
  var platform = getPlatform();
  if (platform == "Mac")
    document.writeln("  <a href=\"\">MacOS 9 and earlier are not supported<\/a>");
  else {
    switch (platform) {
    case "Windows":
      document.writeln("    <h3><a href=\"/products/firefox/download.html?" + escape(gWin32DownloadLink) + "\" id=\"downloadLink\"><strong class=\"downloadText\">Free Download<\/strong><\/a><\/h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Windows, English " + gWin32DownloadSize + "<\/span><\/span>");
      break;
    case "Linux":
      document.writeln("   <h3><a href=\"/products/firefox/download.html?" + escape(gLinuxDownloadLink) + "\" id=\"downloadLink\"><strong class=\"downloadText\">Free Download<\/strong><\/a><\/h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Linux, English " + gLinuxDownloadSize + "<\/span><\/span>");
      break;
    case "MacOSX":
      document.writeln("    <h3><a href=\"/products/firefox/download.html?" + escape(gMacOSDownloadLink) + "\" id=\"downloadLink\"><strong class=\"downloadText\">Free Download<\/strong><\/a><\/h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">MacOS X, English " + gMacOSDownloadSize + "<\/span><\/span>");
      break;
    default:
      document.writeln("    <h3><a href=\"/products/firefox/releases/#download\" id=\"downloadLink\"><strong class=\"downloadText\">Free Download</strong></a></h3>");
      document.writeln("    <span id=\"configParent\">for <span id=\"configuration\">Undetermined<\/span><\/span><\/a><\/h3>");
      break;
    }
  }
  document.writeln("    <\/div>");
  // box displaying CD link
  document.writeln("    <div class=\"extrainfo\">");
  document.writeln("    <a href=\"http://www.mozillastore.com/products/software/cd\" id=\"shopLink\"><span class=\"front-link\">or get Firefox on CD</span><\/a>");
  document.writeln("    <\/div>");
  
}

function startDownload()
{
  if (url != -1)
    location.href = url;
}

function writeDownloadsPage()
{
  url = unescape(location.search);
  if (url.length > 1) {
    url = url.substr(1);
    if (!/^http:\/\/ftp\.([a-z]{2}\.)?mozilla\.org\/pub\/mozilla\.org\/[-\w.\/\+]*$/.test(url))
      url = -1;
  } else
    url = -1;

  if (url != -1) {
    document.writeln("<h2>Now Downloading...<\/h2><p>Your Firefox download should begin in a moment. ");
    setTimeout("startDownload()", 2000);
    document.write("If nothing happens, <a href=\"" + url + "\">try this link<\/a>.<br><br>");
  }
  else {
    document.writeln("<h2>Download Firefox<\/h2>");
    document.writeln("<p>Click one of the following links to start the download.<\/p>");
    document.writeln("<ul><li><a href=\"" + gWin32DownloadLink + "\">Windows<\/a> <\/li>");
    document.writeln("<li><a href=\"" + gLinuxDownloadLink + "\">Linux<\/a><\/li>");
    document.writeln("<li><a href=\"" + gMacOSDownloadLink + "\">Mac OS X<\/a><\/li>");
    document.writeln("<li><a href=\"releases/#download\">Other Operating Systems<\/a><\/li>");
    document.writeln("<li><a href=\"releases/#externalcontrib\">Other Languages<\/a><\/li>");
    document.writeln("<li><a href=\"system-requirements.html\">System Requirements<\/a><\/li><\/ul>");
  }
}

