function createArray(n) {

//  creates an array of size n

this.length = n;
for (var i = 0; i < n+1; i++) this[i] = 0; 
return this

} // end of createArray


function calculateSpeed(form, mult) {

// calculates connection speed 
// filesize - number inputed by the user in the calculator
// mult - multiplier : 1 for KB and 1024 for MB
// formula for coefficient is (KBs*1000/8)/1024

coeff = new createArray(7); 	// array of coefficients 

coeff[0] = "1.7578125"; 	// coefficient for 14.4 KBs (14.4 * 1000/8)/1024
coeff[1] = "3.515625"; 		// coefficient for 28.8 KBs (28.8 * 1000/8)/1024
coeff[2] = "4.1015625"; 	// coefficient for 33.6 KBs (33.6 * 1000/8)/1024
coeff[3] = "6.8359375"; 	// coefficient for 56.0 KBs (56.0 * 1000/8)/1024
coeff[4] = "7.8125"; 		// coefficient for ISDN (64KBs) (64 * 1000/8)/1024
coeff[5] = "15.625"; 		// coefficient for ISDN (128KBs) (128 * 1000/8)/1024
coeff[6] = "189.6973"; 		// coefficient for T1 (1.554Mbs) (128 * 1000/8)/1024

// if the filesize entry is not a number or a NULL, default the entry and all the output values to zero

if (isNaN(form.filesize.value) || form.filesize.value == null || form.filesize.value.length == 0) {
	window.alert("You have entered an invalid value. Input was reset to 0.");
	form.filesize.value = 0;
	for (var i = 0; i < 7; i ++) {
		form[i+"h"].value=0;
		form[i+"m"].value=0;
		form[i+"s"].value=0;
	}
}
		
// if the filesize entry is not 0 do the math
for (var i = 0; i < 7; i++) {
	
	var totaltime = (mult * parseFloat(form.filesize.value))/coeff[i];
	mod = totaltime % 3600;
	form[i+"h"].value = Math.floor(totaltime/3600); // number of hours
	form[i+"m"].value = Math.floor(mod/60); // number of hours	
	form[i+"s"].value = Math.floor(totaltime%60); // number of hours
	
	} // enf of calculateSpeed
}