docs: add script for 32/64-bit bundle downloads

Change-Id: I502e4ced8ac30cc19bf321e7a586f28244bf1294
diff --git a/tools/droiddoc/templates-sdk/sdkpage.cs b/tools/droiddoc/templates-sdk/sdkpage.cs
index 1e3a728..170231f 100644
--- a/tools/droiddoc/templates-sdk/sdkpage.cs
+++ b/tools/droiddoc/templates-sdk/sdkpage.cs
@@ -92,7 +92,7 @@
     <td><?cs var:ndk.win_bytes ?> bytes</td>
     <td><?cs var:ndk.win_checksum ?></td>
   </tr>
-  <tr class="alt-color">
+  <tr>
     <td>Mac OS X (intel)</td>
     <td>
   <a onClick="return onDownload(this)"
@@ -207,31 +207,49 @@
       <th>MD5 Checksum</th>
   </tr>
   <tr>
-    <td>Windows</td>
+    <td>Windows 32-bit</td>
     <td>
-  <a onClick="return onDownload(this)" id="win-bundle"
-     href="http://dl.google.com/android/<?cs var:sdk.win_bundle_download ?>"><?cs var:sdk.win_bundle_download ?></a>
+  <a onClick="return onDownload(this)" id="win-bundle32"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.win32_bundle_download ?>"><?cs var:sdk.win32_bundle_download ?></a>
     </td>
-    <td><?cs var:sdk.win_bundle_bytes ?> bytes</td>
-    <td><?cs var:sdk.win_bundle_checksum ?></td>
-  </tr>
-  <tr class="alt-color">
-    <td>Mac OS X (intel)</td>
-    <td>
-  <a onClick="return onDownload(this)" id="mac-bundle"
-     href="http://dl.google.com/android/<?cs var:sdk.mac_bundle_download ?>"><?cs var:sdk.mac_bundle_download ?></a>
-    </td>
-    <td><?cs var:sdk.mac_bundle_bytes ?> bytes</td>
-    <td><?cs var:sdk.mac_bundle_checksum ?></td>
+    <td><?cs var:sdk.win32_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.win32_bundle_checksum ?></td>
   </tr>
   <tr>
-    <td>Linux 32/64-bit (x86)</td>
+    <td>Windows 64-bit</td>
     <td>
-  <a onClick="return onDownload(this)" id="linux-bundle"
-     href="http://dl.google.com/android/<?cs var:sdk.linux_bundle_download ?>"><?cs var:sdk.linux_bundle_download ?></a>
+  <a onClick="return onDownload(this)" id="win-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.win64_bundle_download ?>"><?cs var:sdk.win64_bundle_download ?></a>
     </td>
-    <td><?cs var:sdk.linux_bundle_bytes ?> bytes</td>
-    <td><?cs var:sdk.linux_bundle_checksum ?></td>
+    <td><?cs var:sdk.win64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.win64_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td><nobr>Mac OS X 64-bit</nobr></td>
+    <td>
+  <a onClick="return onDownload(this)" id="mac-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.mac64_bundle_download ?>"><?cs var:sdk.mac64_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.mac64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.mac64_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td>Linux 32-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="linux-bundle32"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.linux32_bundle_download ?>"><?cs var:sdk.linux32_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.linux32_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.linux32_bundle_checksum ?></td>
+  </tr>
+  <tr>
+    <td>Linux 64-bit</td>
+    <td>
+  <a onClick="return onDownload(this)" id="linux-bundle64"
+     href="http://dl.google.com/android/adt/<?cs var:sdk.linux64_bundle_download ?>"><?cs var:sdk.linux64_bundle_download ?></a>
+    </td>
+    <td><?cs var:sdk.linux64_bundle_bytes ?> bytes</td>
+    <td><?cs var:sdk.linux64_bundle_checksum ?></td>
   </tr>
   </table>
 
@@ -263,8 +281,8 @@
     <td><?cs var:sdk.win_installer_bytes ?> bytes</td>
     <td><?cs var:sdk.win_installer_checksum ?></td>
   </tr>
-  <tr class="alt-color">
-    <td>Mac OS X (intel)</td>
+  <tr>
+    <td>Mac OS X</td>
     <td>
   <a onclick="return onDownload(this)" id="mac-tools" href="http://dl.google.com/android/<?cs
 var:sdk.mac_download
@@ -274,7 +292,7 @@
     <td><?cs var:sdk.mac_checksum ?></td>
   </tr>
   <tr>
-    <td>Linux (i386)</td>
+    <td>Linux</td>
     <td>
   <a onclick="return onDownload(this)" id="linux-tools" href="http://dl.google.com/android/<?cs
 var:sdk.linux_download
@@ -302,20 +320,20 @@
   }
 
   var os;
-  var $bundlelink;
+  var bundlename;
   var $toolslink;
 
   if (navigator.appVersion.indexOf("Win")!=-1) {
     os = "Windows";
-    $bundlelink = $('#win-bundle');
+    bundlename = '#win-bundle';
     $toolslink = $('#win-tools');
   } else if (navigator.appVersion.indexOf("Mac")!=-1) {
     os = "Mac";
-    $bundlelink = $('#mac-bundle');
+    bundlename = '#mac-bundle';
     $toolslink = $('#mac-tools');
   } else if (navigator.appVersion.indexOf("Linux")!=-1) {
     os = "Linux";
-    $bundlelink = $('#linux-bundle');
+    bundlename = '#linux-bundle';
     $toolslink = $('#linux-tools');
   }
 
@@ -325,47 +343,45 @@
     /* set up primary adt download button */
     $('#download-bundle-button').show();
     $('#download-bundle-button').append("Download the SDK <br/><span class='small'>ADT Bundle for " + os + "</span>");
-    $('#download-bundle-button').click(function() {return onDownloadBouncer(this,true);}).attr('href', $bundlelink.attr('href'));
+    $('#download-bundle-button').click(function() {return onDownload(this,true,true);}).attr('href', bundlename);
 
     /* set up sdk tools only button */
     $('#download-tools-button').show();
     $('#download-tools-button').append("Download the SDK Tools for " + os);
-    $('#download-tools-button').click(function() {return onDownload(this,false);}).attr('href', $toolslink.attr('href'));
+    $('#download-tools-button').click(function() {return onDownload(this,true);}).attr('href', $toolslink.attr('href'));
   } else {
     $('.pax').show();
   }
-
-
-  function onDownloadBouncer(link, button) {
-  
-    if (navigator.userAgent.indexOf("WOW64") != -1 || 
-        navigator.userAgent.indexOf("Win64") != -1 ) {
-
-        $("#naMessage").show();
-        $("#warningCancel").click(function() {
-          $('#naMessage').hide();
-          onDownload(link,button);
-        });
-        $("#warningOk").click(function() {
-          $('#naMessage').hide();
-          onDownload($("#download-tools-button").get(),false);
-        });
-        return false;
-      } else {
-        return onDownload(link,button);      
-      }
-  }
   
   
-  function onDownload(link, button) {
-
+  function onDownload(link, button, bundle) {
+  
+    /* set text for download button */
     if (button) {
       $("#downloadForRealz").html($(link).text());
     } else {
       $("#downloadForRealz").html("Download " + $(link).text());
+    }
+    
+    /* if it's a bundle, show the 32/64-bit picker */
+    if (bundle) {
+      $("#downloadForRealz").attr('bundle','true');
+      if ($("#downloadForRealz").text().indexOf("Mac") == -1) {
+        $("p#bitpicker").show();
+      } else {
+        /* mac is always 64 bit, so set it checked */
+        $("p#bitpicker input[value=64]").attr('checked', true);
+      }
+      /* save link name until the bit version is chosen */
+      $("#downloadForRealz").attr('name',$(link).attr('href'));
+    } else {
+      /* if not using bundle, set download button to ignore bitpicker and set url */
+      $("#downloadForRealz").attr('bundle','false');
+      $("#downloadForRealz").attr('href',$(link).attr('href'));
+      /* set picker checked as a fake default */
+      $("p#bitpicker input[value=64]").attr('checked', true);
       $("a#next-link").html("Setting Up an Existing IDE").attr('href',toRoot + 'sdk/installing/index.html');
     }
-    $("#downloadForRealz").attr('href',$(link).attr('href'));
 
     $("#tos").fadeIn('fast');
     $("#landing").fadeOut('fast');
@@ -376,7 +392,18 @@
 
 
   function onAgreeChecked() {
-    if ($("input#agree").is(":checked")) {
+    /* verify that the TOS is agreed and a bit version is chosen */
+    if ($("input#agree").is(":checked") && $("#bitpicker input:checked").length) {
+      
+      /* if downloading the bundle */
+      if ($("#downloadForRealz").attr('bundle')) {
+        /* construct the name of the link we want based on the bit version */
+        linkId = $("a#downloadForRealz").attr("name") + $("#bitpicker input:checked").val();
+        /* set the real url for download */
+        $("a#downloadForRealz").attr("href", $(linkId).attr("href"));
+      }
+      
+      /* reveal the download button */
       $("a#downloadForRealz").removeClass('disabled');
     } else {
       $("a#downloadForRealz").addClass('disabled');
@@ -384,15 +411,15 @@
   }
 
   function onDownloadForRealz(link) {
-    if ($("input#agree").is(':checked')) {
+    if ($("input#agree").is(':checked') && $("#bitpicker input:checked").length) {
       $("div.sdk-terms").slideUp();
       $("#sdk-terms-form,.sdk-terms-intro").fadeOut('slow');
       $("#next-steps").fadeIn('slow');
       $("h1#tos-header").text('Get Ready to Code!');
       return true;
     } else {
-      $("label#agreeLabel").parent().stop().animate({color: "#258AAF"}, 200,
-        function() {$("label#agreeLabel").parent().stop().animate({color: "#222"}, 200)}
+      $("label#agreeLabel,#bitpicker input").parent().stop().animate({color: "#258AAF"}, 200,
+        function() {$("label#agreeLabel,#bitpicker input").parent().stop().animate({color: "#222"}, 200)}
       );
       return false;
     }