Download Time Calculator.
Hey alle sammen.. jeg har lidt problemer med dette script, så håber at der er nogle der kan hjælpe mig med det..altså det virkede fint indtil at jeg satte nogle flere mulighedder på (dem til 1 Mbit og der over)
Her er det så... Ps ved godt at det er lidt rodet..
<HTML>
<HEAD>
<STYLE>
<!--
H1, H2, H3, H4, H5, H6 { color: green }
-->
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript Applet and hide from old browsers -----
var i; // iterator for loops
var subHelpTopicText; // Stores string with subhelp Topic Help Text.
var filesizebits = 0; // Filesize in bits to calculate.
var sizeunit = "bytes"; // Unit of measurement of filesize to calculate.
var sizenum = 8; // Number of results to calculate.
var hposition = ""; // Field hours position in Form.
var mposition = ""; // Field minutes position in Form.
var sposition = ""; // Field seconds position in Form.
function MakeArray(n) {
// array initialization function
this.length = n;
for (i=1; i<=n; i++) {
this[i] = 0;
}
return this;
}
bps = new MakeArray(sizenum); // bits per second.
// initialize the array
bps[1] = "14400";
bps[2] = "28800";
bps[3] = "33600";
bps[4] = "56000";
bps[5] = "64000";
bps[6] = "128000";
bps[7] = "512000";
bps[8] = "1024000";
bps[9] = "2048000";
bps[10] = "4096000";
bps[11] = "10240000";
bps[12] = "102400000";
bps[13] = "1024000000";
function clear_all(form) {
// Change board when button is clicked - Restart.
for (i=1; i<=sizenum; i++) {
hposition = "dl" + i + "h";
mposition = "dl" + i + "m";
sposition = "dl" + i + "s";
form[hposition].value = "";
form[mposition].value = "";
form[sposition].value = "";
}
sizeunit = "bytes";
form.getUserUnit[0].click();
filesizebits = 0;
form.size.value = "";
return;
}
function clear_output(form) {
// Clear output when a field receives focus.
for (i=1; i<=sizenum; i++) {
hposition = "dl" + i + "h";
mposition = "dl" + i + "m";
sposition = "dl" + i + "s";
form[hposition].value = "";
form[mposition].value = "";
form[sposition].value = "";
}
return;
}
function calculate(form) {
// Calculate when button is clicked.
var temp_input = form.size.value; // Get and validate input.
if( (temp_input == null) || (temp_input == "") || (temp_input.length == 0) ){
temp_input = "0";
}
if (isNumber2(temp_input)) {
getRadioButtons(form);
// Calculate and write calculated output to the form.
for (i=1; i<=sizenum; i++) {
var filedltimesec = Math.round( filesizebits / bps[i] );
//alert(filedltimesec + " seconds");
var hourmod = filedltimesec % (60*60); // Modulus.
var HH = Math.floor( filedltimesec / (60*60) );
var MM = Math.floor( hourmod / 60 );
var SS = Math.floor( filedltimesec % 60 ); // Modulus.
hposition = "dl" + i + "h";
mposition = "dl" + i + "m";
sposition = "dl" + i + "s";
form[hposition].value = HH;
form[mposition].value = MM;
form[sposition].value = SS;
}
} else {
alert("ERROR Input: '" + temp_input + "' - Not Allowed. / FEJL indtastning: '" + temp_input + "' - Ikke tilladt.");
form.size.focus();
form.size.select();
}
return;
}
function isNumber2(inputString) {
// Test input for being a number
// with only one period (.) as a valid decimal separator.
if ( (inputString == null) || (inputString == "") ) {
// - always allow a value of nothing (zero).
return (true);
}
var period = false; // Decimal separator found.
for (i=0; i<inputString.length; i++) {
if ( inputString.charAt(i) == "." ) {
// Allow the period (.) as a valid decimal separator.
if ( period == false ) {
// Decimal separator found.
period = true;
} else {
// More than one decimal separator found.
return (false);
}
}
if ( (inputString.charAt(i) < "0") && (inputString.charAt(i) != ".") ) {
return (false);
}
if ( (inputString.charAt(i) > "9") && (inputString.charAt(i) != ".") ) {
return (false);
}
}
return (true);
}
function getRadioButtons(form) {
// This function takes the data from the form's radio buttons and
// sorts out which unit to converse to bits.
clear_output(form); // Clear output when a field receives focus.
// Loops through the radio buttons finding out which one is selected.
for (var i=0; i<3; i++) {
if (form.getUserUnit[i].checked==1) {
sizeunit=form.getUserUnit[i].value;
}
}
// Series of if else statements, sorts out which unit to
// converse to bits.
filesizebits = 0;
var temp_input = form.size.value;
if( (temp_input == null) || (temp_input == "") || (temp_input.length == 0) ){
temp_input = "0";
}
if ( (sizeunit == "bytes") && (isNumber2(temp_input)) ) {
filesizebits = (8/1) * temp_input;
}else if ( (sizeunit == "kilobytes") && (isNumber2(temp_input)) ) {
filesizebits = (8/1) * (((Math.pow(2,10))/1) * temp_input);
}else if ( (sizeunit == "megabytes") && (isNumber2(temp_input)) ) {
filesizebits = (8/1) * (((Math.pow(2,20))/1) * temp_input);
}
//alert(filesizebits + " bits");
return;
}
subHelpTopicText = new MakeArray(2);
// initialize the array
subHelpTopicText[1] = "ISDN: Integrated Services Digital Network.";
subHelpTopicText[2] = "ADSL: Asymmetric Digital Subscriber Line.";
function subHelpTopic(subHelpTopicNumber)
{
// Show alert dialog box with subhelp Topic Help Text.
alert(subHelpTopicText[subHelpTopicNumber]);
return;
}
function doOnLoad()
{
return;
}
// - End of JavaScript code and done hiding -->
</SCRIPT>
</HEAD>
<HR>
<NOSCRIPT>
<H3>Sorry! / Beklager!</H3>
<P>You must have a script-capable browser to
view this document correctly. / Du skal benytte en
script-egnet browser for at se dette dokument korrekt.</P>
<P>This means, that this page requires Netscape 2.0 or higher, or
Internet Explorer 3.0 or higher. / Dette betyder, at
denne side kræver Netscape 2.0 eller nyere eller
Internet Explorer 3.0 eller nyere.</P>
</NOSCRIPT>
<A NAME="Download_Time_Calc"> </A>
<H3>File Download Time Calculator / Fil Download-tid regnemaskine</H3>
<P ALIGN="LEFT">Enter a number of the chosen unit of measurement in
the input field and select the chosen unit of measurement, then click
on the "Calculate / Beregn" button. Use only the period (.) as
a valid decimal separator. / Skriv et tal for den valgte
måleenhed i indtastningsfeltet og vælg valgt
måleenhed, klik herefter på "Calculate / Beregn"
knappen. Brug kun punktum (.) som en gyldig decimal separator.</P>
<P ALIGN="LEFT">"Restart / Genstart" resets to calculate
again. / "Restart / Genstart" nulstiller for
fornyet beregning.</P>
<FORM>
<P ALIGN=CENTER VALIGN=MIDDLE>
<TABLE BORDER="6" BGCOLOR="#D3D3D3" ALIGN="CENTER" CELLSPACING="2" CELLPADDING="3">
<!-- row # 1 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>Enter file size: / <BR>Indtast fil størrelse: </B>
</TD>
<TD COLSPAN="3">
<INPUT NAME="size" VALUE="" onFocus="clear_output(this.form)">
</TD>
</TR>
<!-- row # 2 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>Select unit of measurement: / <BR>Vælg måleenhed: </B>
</TD>
<TD COLSPAN="3">
<INPUT TYPE=radio NAME='getUserUnit' VALUE='bytes' CHECKED
onClick='getRadioButtons(this.form)'>bytes
<INPUT TYPE=radio NAME='getUserUnit' VALUE='kilobytes'
onClick='getRadioButtons(this.form)'>kilobytes
<INPUT TYPE=radio NAME='getUserUnit' VALUE='megabytes'
onClick='getRadioButtons(this.form)'>megabytes
</TD>
</TR>
<!-- row # 3 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<INPUT TYPE="button" VALUE="Restart / Genstart"
onClick="clear_all(this.form)">
</TD>
<TD COLSPAN="3">
<INPUT TYPE="button" VALUE="Calculate / Beregn"
onClick="calculate(this.form);">
</TD>
</TR>
<!-- row # 4 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD BGCOLOR="#FFFFFF">
<B>Estimated File Download Time* by: / <BR>Anslået fil download-tid* ved: </B>
</TD>
<TD>
<B>hours /<BR>timer</B>
</TD>
<TD>
<B>minutes /<BR>minutter</B>
</TD>
<TD>
<B>seconds /<BR>sekunder</B>
</TD>
</TR>
<!-- row # 5 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>14,400 bps</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl1h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl1m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl1s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 6 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>28,800 bps</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl2h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl2m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl2s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 7 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>33,600 bps</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl3h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl3m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl3s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 8 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>56 Kbps</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl4h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl4m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl4s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 9 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>64K ISDN</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl5h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl5m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl5s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 10 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>128K ISDN</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl6h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl6m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl6s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 11 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>512K ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 12 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>1 Mbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 13 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>2 Mbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 14 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>4 Mbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 15 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>10 Mbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 16 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>100 Mbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 17 -->
<TR ALIGN="CENTER" VALIGN="MIDDLE">
<TD>
<B>1 Gbit ADSL</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7h" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7m" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
<TD>
<INPUT TYPE="text" NAME="dl7s" SIZE="4"
onFocus="this.blur()"
onSubmit="return false" >
</TD>
</TR>
<!-- row # 18 -->
<TR ALIGN="LEFT" VALIGN="MIDDLE">
<TD COLSPAN="4">
<B>*) Please note: Prevailing network conditions may affect these
times. /<BR>*) Bemærk venligst: Almindelige netværk
betingelser kan påvirke disse tider.</B>
</TD>
</TR>
</TABLE>
</P>
</FORM>
<HR>
</BODY>
</HTML>
