/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Gabrielle Gayheart */

//create an array of whatever size you send it

function createarray(len) {
  this.length = len;
  for (var i = 0; i < len + 1; i++) {
    this[i] = 0;
  }
  return this;
}

// mult is either kb, mb, gb
// form is the number array

function calculate(form, mult) {
  // multiplier for the internet connection speeds
  //to add calculations, multiply connection speed times 1,000, divide by eight; then divide by 1024
  // (kbs*1000/8)/1024)
  var arraysize = 8; //change this number if you add other speeds
  multiplier = new createarray(arraysize);
    multiplier[0] = "3.5156";
    multiplier[1] = "6.8360";
    multiplier[2] = "7.8125";
    multiplier[3] = "31.25";
    multiplier[4] = "62.5";
    multiplier[5] = "73.2421";
    multiplier[6] = "189.6973";
    multiplier[7] = "549.3164";

  //checks to see if 0 is not the value
  if (form.size.value != 0) {
    //does the math
    for (var j = 0; j < arraysize; j++) {
      var tottime = (mult * parseFloat(form.size.value)) / multiplier[j];
      mod = tottime % 3600;
      form[j + "h"].value= Math.floor(tottime / 3600);
      form[j + "m"].value= Math.floor(mod / 60);
      form[j + "s"].value= Math.floor(tottime % 60);
    }
  } else {
    //default the result to 0
    for (var k = 0; k < arraysize; k++) {
      form[k+"h"].value=0;
      form[k+"m"].value=0;
      form[k+"s"].value=0;
    }
  }
}

