home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Neil's C++ Stuff
/
2015-03-neilstuff.zip
/
cpp
/
tyk.js
< prev
next >
Wrap
Text File
|
2015-03-14
|
4KB
|
105 lines
//****************************************************************************
//****************************************************************************
// Client JS for "Test Your Knowledge" Form
//****************************************************************************
//****************************************************************************
var js_iseed = 0, js_iseed1 = 0, js_iseed2 = 0, formnum = 0;
var answ = new Array(6);
var scratch = "", j = 0, k = 0;
var goodmsg = "Right on!";
var badmsg = "Try again!";
var childbub=0; // child bubble
var bTime; // bubble timer ID
var bubblei=0;// desired bubble
var bubblecfg = false;
var bmsg=0; // index of current bubble:
var mdata;
function config_bubble() { }
function tyk(question, ans1, ans2, ans3, ans4, cans, explanation)
{
formnum++;
answ[0]=ans1; answ[1]=ans2; answ[2]=ans3; answ[3]=ans4; answ[4]=cans;
for (var i = 0; i < 10; i++)
{
j = random(5);
if (j > 4) alert("ack!");
scratch = answ[j];
answ[j] = "";
k = j;
while (answ[k] == "")
k = random(5);
answ[j] = answ[k];
answ[k] = scratch;
}
for (var i = 0; i < 5; i++)
if (answ[i] == cans) k = i;
document.write
(
"<CENTER><TABLE BORDER=0 CELLBORDER=0 CELLSPACING=0 CELLPADDING=0>"+
"<TD ALIGN=CENTER>"+
"<TABLE WIDTH=570 BORDER=0 CELLBORDER=0 CELLSPACING=0 CELLPADDING=0>"+
"<TR><TD COLSPAN=3 WIDTH=570 HEIGHT=54>"+
"<IMG SRC=tyk_gfx/top_title.GIF WIDTH=570 HEIGHT=54></TD></TR>"+
"<TR><TD WIDTH=32 HEIGHT=135>"+
"<IMG SRC=tyk_gfx/left_q.GIF WIDTH=32 HEIGHT=135></TD>"+
"<TD WIDTH=505 HEIGHT=135 BGCOLOR=FFFFFF>"+
"<IMG SRC=tyk_gfx/blank.GIF WIDTH=505 HEIGHT=1><BR>"+
"<FORM NAME=ex" + formnum + ">" + question + "</TD>" +
"<TD WIDTH=33 HEIGHT=135>"+
"<IMG SRC=tyk_gfx/right_q.GIF WIDTH=32 HEIGHT=135></TD></TR>"+
"<TR><TD COLSPAN=3 WIDTH=570 HEIGHT=12>"+
"<IMG SRC=tyk_gfx/middle_div.GIF WIDTH=570 HEIGHT=12></TR></TABLE>"+
"<TABLE WIDTH=570 BORDER=0 CELLBORDER=0 CELLSPACING=0 CELLPADDING=0>"+
"<TR><TD ROWSPAN=2 WIDTH=42 HEIGHT=200>"+
"<IMG SRC=tyk_gfx/left_bot.GIF WIDTH=42 HEIGHT=200></TD>"+
"<TD WIDTH=496 HEIGHT=182 BGCOLOR=FFFFFF>"
);
for (var i = 0; i < 5; i++)
document.write("<INPUT TYPE=RADIO NAME=exchc>" + answ[i] + "<BR>");
document.write
(
"<CENTER><INPUT TYPE=BUTTON VALUE='Am I Right?' ONCLICK=\"(document.ex" + formnum + ".exchc[" + k + "].checked)?alert('" + goodmsg
);
if (explanation != "") { document.write("\\n\\n" + explanation); }
document.write
(
"'):alert(badmsg);\"></CENTER></FORM></TD>" +
"<TD ROWSPAN=2 WIDTH=32 HEIGHT=200>"+
"<IMG SRC=tyk_gfx/right_bot.GIF WIDTH=32 HEIGHT=200></TD></TR>"+
"<TR><TD WIDTH=496 VALIGN=BOTTOM BGCOLOR=FFFFFF>"+
"<IMG SRC=tyk_gfx/middle_bot.GIF WIDTH=496 HEIGHT=9></TD></TR>"+
"<TR><TD COLSPAN=3 WIDTH=570 HEIGHT=9>"+
"<IMG SRC=tyk_gfx/bottom.GIF WIDTH=570 HEIGHT=9></TD></TR></TABLE>" +
"</TD></TABLE></CENTER>"
);
}
// ripped this function from a script on www.javascripts.com, can't remember
// the original script or author, sorry
function random(n)
{
var js_mult1=3141
var js_mult2=5821
var js_m1=100000000
var js_m2=10000
if (js_iseed == 0)
{
now = new Date()
js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600
}
js_iseed1 = js_iseed / js_m2
js_iseed2 = js_iseed % js_m2
var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) * js_m2 + (js_iseed2 * js_mult2)) % js_m1
js_iseed = (tmp + 1) % js_m1
return (Math.floor((js_iseed/js_m1) * n))
}