
var QTxt
var QPic
var QAns1
var QAns2
var QAns3
var QAns4
var QAnsNum

var Mode
var CheckAnswerText
  
var QuizPage
var QuizName
var QuizIntroText
var QuizAdImage
var QuizTimeout
var	QuizSponsorName = ""
var	QuizSponsorEmail = ""
var	QuizSponsorWebsite = ""
var	QuizSponsorText = ""
var	QuizSponsorBanner = ""
  
QTxt  = new Array	
QPic  = new Array
QAns1 = new Array
QAns2 = new Array
QAns3 = new Array
QAns4 = new Array
QAnsNum = new Array	

function MouseOver(Msg)
{
	window.status=Msg; 
	return true;
}

function NewWindow(URL, Title)
{  
	return window.open(URL, Title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=350');	
}

function WriteSponsorHeader1()
{
	if (QuizSponsorName != "")
	{
		document.write('<table><tr><td align="left" valign="top" width="12"></td><td valign="center" class="quizhdr"><table border="0" cellpadding="0" cellspacing="0"><tr><td class="gentext" bgcolor="#FF9900" ><center>');
		if (QuizSponsorWebsite != "")
		{
			document.write('This Quiz sponsored by <A HREF="http://',QuizSponsorWebsite,'">',QuizSponsorName,'</A>');
		}
		else
		{
			document.write('This Quiz sponsored by <b>',QuizSponsorName,'</b>');
		}
		document.write('</center>');
		
		if (QuizSponsorText != "")
		{
			document.write('<table border="0" cellpadding="0" cellspacing="0"><tr><td width="15" bgcolor="#FF9900">&nbsp;</td><td align="left" valign="center" class="gentext" bgcolor="#FFFFFF">');
			document.write(QuizSponsorText)
			document.write('</td><td width="15" bgcolor="#FF9900">&nbsp;</td></tr></table>'); 
		}
		
		document.write('<center>');
		if (QuizSponsorEmail != "")
		{
			document.write('<A HREF="mailto:',QuizSponsorEmail,'">email ',QuizSponsorName,'</A>');
		}
		document.write('</center></td></tr></table></td></tr></table>');
	}	
}

function WriteFooter1(dynstem, dyndir)
{

	dyndir = ""

	document.write('<table width="100%"><tr><td><hr></td></tr></table>');     
  document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%" >');
  document.write('	<tr><td  valign="top" align="center" width="115" class="copyright">');
  document.write('		© Copyright 2001,2009<br>Magnasoft Ltd.');
  document.write('		<br>All Rights Reserved.');
  document.write('		<br><A HREF="mailto:quizmaster@magnasoft.co.uk">email QuizMaster</A>');
  document.write('    </td>'); 
  document.write('    <td valign="top" align="right" class="container" NOWRAP> ');
  document.write(' 		<table>');
  document.write('			<tr><td valign="top" align="center" height="90" class="container">');
	if ((QuizSponsorWebsite != "") && (QuizSponsorBanner != ""))
	{
		document.write('					<a href="','http://',QuizSponsorWebsite,'"> <img src="',dynstem,dyndir,QuizSponsorBanner,'" WIDTH="470" HEIGHT="61"></a>');
	}
	else
	{
		document.write('					<a href="','http://www.stonekits.co.uk"> <img src="',dynstem,dyndir,'graphics/skbanra.gif" alt="Fun with Stone at www.stonekits.co.uk" WIDTH="470" HEIGHT="61"></a>');
	}
	document.write('			</td></tr>');
  document.write('		</table>');
  document.write('		</td>');
  document.write('  </tr>'); 
  document.write('</table>');
}  

function WriteHeader1(dynstem, dyndir, ThisTopNavbarItem, ThisLEPageIndex, FeatureImage, BannerImage)
{
var TopNavbarItemName;
var TopNavbarItemLink;

	dyndir = ""
		
	TopNavbarItemName = new Array(5)
	TopNavbarItemLink = new Array(5)

	TopNavbarItemName[0] = "Home"
	TopNavbarItemLink[0] = dynstem + "default.asp"

	TopNavbarItemName[1] = "About QuizU"
	TopNavbarItemLink[1] = dynstem + "about.htm"

	TopNavbarItemName[2] = "Mobile QuizU"
	TopNavbarItemLink[2] = dynstem + "quizuwap.htm"

	TopNavbarItemName[3] = "Scoreboard"
	TopNavbarItemLink[3] = dynstem + "score.htm"

	//TopNavbarItemName[4] = "Quiz Club"
	//TopNavbarItemLink[4] = dynstem + "quizclub.htm"

	//TopNavbarItemName[5] = "My QuizU"
	//TopNavbarItemLink[5] = dynstem + "myquizu.htm"

	TopNavbarItemName[4] = "Terms"
	TopNavbarItemLink[4] = dynstem + "terms.htm"

	document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%" ><tr>');

	// 21/4/2009 changed to 145 from 115
	document.write('<td  valign="top" align="middle" width="115">');

	document.write('<blockquote><br>'); 

	// 21/4/2009 changed to 145 from 115
	document.write('<img src="',dynstem,dyndir,'graphics/quizu.jpg" alt="QuizU Logo" WIDTH="115" HEIGHT="115">');

	document.write('</blockquote>'); 

	document.write('</td>'); 

  document.write('<td valign="top" align="right"  class="container" NOWRAP colspan=2>');

	document.write('<span class="topnavbar">&nbsp;');

	var NavbarItem;

	for ( var TopNavbarItem = 0; TopNavbarItem < TopNavbarItemName.length; TopNavbarItem++ )
	{	
  	if (TopNavbarItem != ThisTopNavbarItem)
		{					 
			NavbarItem = '<a class="topnavbarlink" href="';
			NavbarItem = NavbarItem + TopNavbarItemLink[TopNavbarItem];
			NavbarItem = NavbarItem + '" title="';
			NavbarItem = NavbarItem + TopNavbarItemName[TopNavbarItem];
			NavbarItem = NavbarItem + '" onMouseOver="return MouseOver(';
			NavbarItem = NavbarItem + "'" + TopNavbarItemName[TopNavbarItem] + "'";
			NavbarItem = NavbarItem + ')" onMouseOut="return MouseOver(';
			NavbarItem = NavbarItem + "''";
			NavbarItem = NavbarItem + ')">';
			NavbarItem = NavbarItem + TopNavbarItemName[TopNavbarItem];
			NavbarItem = NavbarItem + '</a>';
			document.write(NavbarItem);
    }
		else
		{ 				 
			document.write('<span class="topnavbarthisitem">',TopNavbarItemName[TopNavbarItem],'</span>'); 
		}

		if (TopNavbarItem != TopNavbarItemName.length)	document.write('&nbsp;|&nbsp;');
  }

	document.write('&nbsp;</span>');
	document.write('<br>');

	document.write('<table><tr><td valign="center" height="90" class="container">');
	WriteLinkExchangeCode(ThisLEPageIndex); 	 	
	document.write('</td></tr></table>');

	//document.write('<img src="',dynstem,dyndir,'dynalog.asp?LogOid=',ThisTopNavbarItem,'&LogOSeq=0&LogOSubSeq=0" alt="" WIDTH="1" HEIGHT="1">');
	document.write('<img src="',dynstem,dyndir,'dynalog.asp?LogOid=',ThisTopNavbarItem,'&LogOSeq=0&LogOSubSeq=',GetSearchParm('quizinc'),'" alt="" WIDTH="1" HEIGHT="1">');
	
	document.write('</td></tr>');
 	 
	document.write('</table>');

	document.write('<table width="100%"><tr><td><hr></td></tr></table>');
} 

//
// "Internal" function to return the decoded value of a Search parm
//
function getSearchParmVal (offset) {
  var endstr = document.location.search.indexOf ("&", offset);
  if (endstr == -1)
    endstr = document.location.search.length;
  return unescape(document.location.search.substring(offset, endstr));
}

//
//  Function to return the value of a parm specified by "name".
//    name - String object containing the parm name.
//    returns - String object containing the parm value, or null if
//      the parm does not exist.
//
function GetSearchParm (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.location.search.length;
	var i = 1;
 
	while (i < clen) {
    var j = i + alen;
    if (document.location.search.substring(i, j) == arg)
		  return getSearchParmVal (j);
		i = document.location.search.indexOf("&", i) + 1;
    if (i == 0) break; 
  }
  return null;
}


function strToZero(anyval)
{ 
	anyval = ""+anyval 
  if ( (anyval.substring(0,1) < "0") || (anyval.substring(0,1) > "9") )
	{ 
  	anyval = "0" 
  } 
  return eval(anyval) 
} 
 

function WriteLinkExchangeCode(ThisLEPageIndex)
{
  var vbCrLf = "\n";
  var LEURL;
	var graphicsdir="";
	
	if (ThisLEPageIndex != 0) 
  {
  //LEURL = 'leader.linkexchange.com';
  //if (document.location.host == 'localhost')	LEURL = 'localhost';
  
  //document.write('<!-- BEGIN LINKEXCHANGE CODE -->'); 
  //document.write(vbCrLf);
  //document.write('<center><iframe src="http://',LEURL,'/',ThisLEPageIndex,'/X1367983/showiframe?" width=468 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no>');
  //document.write(vbCrLf);
  //document.write('<center><a href="http://',LEURL,'/',ThisLEPageIndex,'/X1367983/clickle" target="_top"><img width=468 height=60 border=0 ismap alt="" src="http://',LEURL,'/',ThisLEPageIndex,'/X1367983/showle?"></a></iframe><br><a href="http://',LEURL,'/',ThisLEPageIndex,'/X1367983/clicklogo" target="_top"><img src="http://',LEURL,'/',ThisLEPageIndex,'/X1367983/showlogo?" width=468 height=16 border=0 ismap alt=""></a><br></center>');
  //document.write(vbCrLf);
  //document.write("<!-- END LINKEXCHANGE CODE -->");
  //document.write(vbCrLf);
  	if (document.location.host == "localhost") graphicsdir = "/quizuprod";
		document.write('<img src="',graphicsdir,'/graphics/quizubnr.gif" alt="The best quizes are here at QuizU" WIDTH="470" HEIGHT="61">');
	}
	else
	{
		if (document.location.host == "localhost") graphicsdir = "/quizuprod";
		document.write('<img src="',graphicsdir,'/graphics/quizubnr.gif" alt="The best quizes are here at QuizU" WIDTH="470" HEIGHT="61">');
  }
}

function WriteSubHead1()
{
var now = new Date();
var mod

	mod = ((now.getTime())%7);
	
	if ( mod == 0 )
	{
		gSubHead = 0;
   	document.write("What do you Know?");
	}

	if ( mod == 1 )
	{     
		gSubHead = 1;
   	document.write("Quizzes on your Mobile Phone?");
	}

	if ( mod == 2 )
	{     
		gSubHead = 2;
   	document.write("Got a Website? Want a Quiz?");
	}

	if ( mod == 3 )
	{     
		gSubHead = 3;
   	document.write("Featured Quiz - 'Lord of the Rings - People'");
	}

	if ( mod == 4 )
	{     
		gSubHead = 4;
   	document.write("Featured Jokes - 'Cross-breed Comics'");
	}

	if ( mod == 5 )
	{     
		gSubHead = 5;
   	document.write("Got a Website? Want a Quiz?");
	}
	
	if ( mod == 6 )
	{     
		gSubHead = 6;
   	document.write("Featured Quiz - 'True or False 5'");
	}

}

function WriteSubHead2()
{
 	if ( gSubHead == 0 ) document.write("Try a Quiz and Find Out!");
	     
  if ( gSubHead == 1 ) document.write('Try our WAP site. <a href="quizuwap.htm">Click here</a> for details.');	

  if ( gSubHead == 2 ) document.write('QuizU can help. <a href="linkopts.htm">Press here</a> for info.');

  if ( gSubHead == 3 ) document.write('<a href="quiztpl3.htm?quizinc=qinc3301.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Try the Featured Quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
	
  if ( gSubHead == 4 ) document.write('<a href="quiztpl4.htm?quizinc=qinc4402.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Laugh at the Featured Jokes</span><img src="graphics\\tryquiz.gif" border=0></a>');
	
  if ( gSubHead == 5 ) document.write('QuizU can help. <a href="linkopts.htm">Press here</a> for info.');

  if ( gSubHead == 6 ) document.write('<a href="quiztpl3.htm?quizinc=qinc3137.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Try the Featured Quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
}

function WriteSubHead3()
{
 	if ( gSubHead == 1 ) document.write("Try a Quiz and Find Out!");
	     
  if ( gSubHead == 2 ) document.write('Try our WAP site. <a href="quizuwap.htm">Click here</a> for details.');	

  if ( gSubHead == 3 ) document.write('QuizU can help. <a href="linkopts.htm">Press here</a> for info.');

  if ( gSubHead == 4 ) document.write('<a href="quiztpl3.htm?quizinc=qinc3301.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Try the Featured Quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
	
  if ( gSubHead == 5 ) document.write('<a href="quiztpl4.htm?quizinc=qinc4402.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Laugh at the Featured Jokes</span><img src="graphics\\tryquiz.gif" border=0></a>');
	
  if ( gSubHead == 6 ) document.write('QuizU can help. <a href="linkopts.htm">Press here</a> for info.');

  if ( gSubHead == 0 ) document.write('<a href="quiztpl3.htm?quizinc=qinc3137.js"><img src="graphics\\tryquiz.gif" border=0><span class="largetext">Try the Featured Quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
}
			

function WriteAns1(dc)
{ 
var i;

dc.write('<table class="container"><tr><td>');
                                           
dc.write('<form NAME="answerform" ACTION="" METHOD="POST">');
  
dc.write('<table CELLPADDING=5>');
 
for (i=0; i < QTxt.length; i++) 
{ 
	 WriteAnswer(dc, i)
}
  
dc.write('</table>');
  
dc.write('<table class="container"><tr><td class="instruction">');
dc.write('<a href="JavaScript:window.close(document)" title="Close this Window" onmouseover="return MouseOver(', "'Close this Window'"        ,')" onmouseout="return MouseOver(', "''" ,')">Press here</a> to <b>close this window</b>.') 
dc.write('</td></tr></table>');
                                                                                                          
dc.write('</form>');
 
dc.write('</td></tr></table>');
  
} 
 
function WriteAnswer(dc, n)
{
var Line;

	dc.write("<TR>");

	if (QPic[n] == "") 
	{
		Line = "<TD COLSPAN=2 CLASS=question>" + (n+1) + ". " + QTxt[n] + "</TD>";
  }
	else
  {
		Line = "<TD CLASS=question>" + (n+1) + ". " + QTxt[n] + "</TD><TD CLASS=question>" + QPic[n] + "</TD>"
  }
	dc.write(Line)

	Line = '<TD><TABLE BORDER=1><TR><TD CLASS=options>'
	
	if (QAnsNum[n] == 1) Line = Line + '1.&nbsp;' + QAns1[n];
	if (QAnsNum[n] == 2) Line = Line + '2.&nbsp;' + QAns2[n];
	if (QAnsNum[n] == 3) Line = Line + '3.&nbsp;' + QAns3[n];
	if (QAnsNum[n] == 4) Line = Line + '4.&nbsp;' + QAns4[n];

	dc.write(Line)

	dc.write("</TD></TR></TABLE></TD></TR>")
}


function WriteQuiz1(dc)
{ 
var i;

dc.write('<table class="container"><tr><td>');
                                           
dc.write('<form NAME="questionform" ACTION="" METHOD="POST">');
  
dc.write('<table CELLPADDING=5>');
 
for (i=0; i < QTxt.length; i++) 
{ 
	 WriteQuestion(dc, i)
}
  
dc.write('</table>');

dc.write('<table class="container"><tr><td class="instruction">');
dc.write('<a href="JavaScript:CheckAnswers(document)" title="Check your Answers" onmouseover="return MouseOver(', "'Check your Answers'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>check your answers</b>.') 
dc.write('</td></tr></table>');

dc.write('</form>');
 
dc.write('</td></tr></table>');
  
}


function WriteQuiz2(dc)
{ 
var i;

dc.write('<table class="container"><tr><td>');
                                           
dc.write('<form NAME="questionform" ACTION="" METHOD="POST">');
  
dc.write('<table CELLPADDING=5>');

now = new Date();

i = (now.getTime())%QTxt.length;
 
WriteQuestion2(dc, i) 

dc.write('</table>');

dc.write('</form>');
 
dc.write('</td></tr></table>');
  
} 


function WriteQuiz3(dc)
{ 
var quizetime;
var quizans;
var quizquestion;
var quizinc;
var qstart = new Date();
var morequestions;

quizquestion = GetSearchParm("quizquestion");
if (quizquestion == null) quizquestion = 0;

quizetime = GetSearchParm("quizetime");
if (parseInt(quizquestion) == 0) quizetime = 0;
 
quizans = GetSearchParm("quizans");
if (quizquestion == "0") quizans = "";

quizinc = GetSearchParm("quizinc");

dc.write('<table class="container"><tr><td>');
                                           
dc.write('<form NAME="questionform" ACTION="quiztpl3.htm" METHOD="GET">');

dc.write('<input type="hidden" name="qstart" value="' + qstart.getTime() + '">');

dc.write('<input type="hidden" name="quizetime" value="' + quizetime + '">');

dc.write('<input type="hidden" name="quizans" value="' + quizans + '">');

dc.write('<input type="hidden" name="quizinc" value="' + quizinc + '">');

dc.write('<input type="hidden" name="quizquestion" value="' + (parseInt(quizquestion)+1) + '">');

dc.write('<input type="hidden" name="thisquestion" value="' + parseInt(quizquestion) + '">');
  
dc.write('<table CELLPADDING=5>');
 
morequestions = WriteQuestion3(dc, quizquestion); 

dc.write('</table>');

if (morequestions == true)
{
	dc.write('<p><a href="javascript:CalcTimeCheckAnswerAndSubmit()"><img src="graphics\\tryquiz.gif" border=0><span class="gentext">Next Question</span><img src="graphics\\tryquiz.gif" border=0></a>');
	dc.write('</form>');
}
else
{
	dc.write('</form>');		

	dc.write('<form target="QuizAnswers" name="answers" action="quizans1.htm" method="GET">')
  dc.write('<table><tr><td bgcolor="#d1b2ff">')
	dc.write('<font size="2" face="verdana">');
	dc.write('<a href="JavaScript:NewWindow(' + "''" + ',' + "'" + "QuizAnswers" + "'" + ');document.answers.submit();" title="See the Correct Answers" onmouseover="return MouseOver(', "'See the Correct Answers'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>see the correct answers</b>.') 
  dc.write('</font>')
	dc.write('</td></tr></table>')
	dc.write('<input type="hidden" name="quizinc" value="',GetSearchParm('quizinc'),'">')
	dc.write('</form>') 

	dc.write('<p><a href="default.asp"><img src="graphics\\tryquiz.gif" border=0><span class="gentext">Try another quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
}

 
dc.write('</td></tr></table>');

return morequestions;
  
} 


function WriteQuiz4(dc)
{ 
var i;
var morequestions;

quizquestion = GetSearchParm("quizquestion");
if (quizquestion == null) quizquestion = 0;

quizinc = GetSearchParm("quizinc");


dc.write('<table class="container"><tr><td>');
                                           
dc.write('<form NAME="questionform" ACTION="quiztpl4.htm" METHOD="GET">');

dc.write('<input type="hidden" name="quizinc" value="' + quizinc + '">');

dc.write('<input type="hidden" name="quizquestion" value="' + (parseInt(quizquestion)+1) + '">');
  
dc.write('<table CELLPADDING=5>');

morequestions = WriteQuestion4(dc, quizquestion) 

dc.write('</table>');

if (morequestions == true)
{
	dc.write('<p><a href="javascript:document.questionform.submit();"><img src="graphics\\tryquiz.gif" border=0><span class="gentext">Next Question</span><img src="graphics\\tryquiz.gif" border=0></a>');
	dc.write('</form>');
}
else
{
	dc.write('</form>');		
	dc.write('<p><a href="default.asp"><img src="graphics\\tryquiz.gif" border=0><span class="gentext">Try another quiz</span><img src="graphics\\tryquiz.gif" border=0></a>');
}

dc.write('</form>');
 
dc.write('</td></tr></table>');
  
}
  
 
function CalcTimeCheckAnswerAndSubmit()
{
var qend = new Date();
var qetime = qend.getTime() - document.questionform.qstart.value;

	document.questionform.quizetime.value = parseInt(document.questionform.quizetime.value) + qetime;

	CheckAnswer3(document, document.questionform.thisquestion.value);

	document.questionform.submit();	
} 
 
 
function WriteQuestion(dc, n)
{
var Line;

	dc.write("<TR>");

	if (QPic[n] == "") 
	{
		Line = "<TD COLSPAN=2 CLASS=question>" + (n+1) + ". " + QTxt[n] + "</TD>";
  }
	else
  {
		Line = "<TD CLASS=question>" + (n+1) + ". " + QTxt[n] + "</TD><TD CLASS=question>" + QPic[n] + "</TD>"
  }
	dc.write(Line)

	Line = '<TD><TABLE BORDER=1><TR><TD CLASS=options><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=1>1.&nbsp;' + QAns1[n]

	if (QAns2[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=2>2.&nbsp;' + QAns2[n]
	}
	
	if (QAns3[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=3>3.&nbsp;' + QAns3[n]
  }

	if (QAns4[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=4>4.&nbsp;' + QAns4[n]
  }

	dc.write(Line)

	dc.write("</TD></TR></TABLE></TD></TR>")
}
 
function WriteQuestion2(dc, n)
{
var Line;
var ShowAnswer = '<P><span class="instruction"><a href="JavaScript:CheckAnswer2(document,' + n + ')" title="Select the Correct Answer" onmouseover="return MouseOver(' + "'" + 'Select the Correct Answer' + "'" + ')" onmouseout="return MouseOver(' + "''" + ')">Press here</a> to <b>select the correct answer</b>.</span>';

	dc.write("<TR>");

	if (QPic[n] == "") 
	{
		Line = "<TD COLSPAN=2 CLASS=question>" + QTxt[n];
		Line = Line + ShowAnswer;
		Line = Line + "</TD>";
  }
	else
  {
		Line = "<TD CLASS=question>" + QTxt[n] + ShowAnswer + "</TD><TD CLASS=question>" + QPic[n] + "</TD>"
  }
	dc.write(Line)

	Line = '<TD><TABLE BORDER=1><TR><TD CLASS=options><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=1><SPAN ID="Ans1">1.&nbsp;' + QAns1[n] + "</SPAN>"

	if (QAns2[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=2><SPAN ID="Ans2">2.&nbsp;' + QAns2[n] + "</SPAN>"
	}
	
	if (QAns3[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=3><SPAN ID="Ans3">3.&nbsp;' + QAns3[n] + "</SPAN>"
  }

	if (QAns4[n] != "")
	{
		Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=4><SPAN ID="Ans4">4.&nbsp;' + QAns4[n] + "</SPAN>"
  }

	dc.write(Line)

	dc.write("</TD></TR></TABLE></TD></TR>")
}

 
function WriteQuestion3(dc, n)
{
var Line;
var CorrectAnswerCount = 0;

	dc.write("<TR>");

	if (n < QTxt.length)
	{
		if (QPic[n] == "") 
		{
			Line = "<TD COLSPAN=2 CLASS=question>(" + (parseInt(n)+1) + "/" + QTxt.length + ") " + QTxt[n];
			Line = Line + "</TD>";
  	}
		else
  	{
			Line = "<TD CLASS=question>(" + (parseInt(n)+1) + "/" + QTxt.length + ") " + QTxt[n] + "</TD><TD CLASS=question>" + QPic[n] + "</TD>"
  	}
		dc.write(Line)
	
		Line = '<TD><TABLE BORDER=1><TR><TD CLASS=options><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=1><SPAN ID="Ans1">1.&nbsp;' + QAns1[n] + "</SPAN>"

		if (QAns2[n] != "")
		{
			Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=2><SPAN ID="Ans2">2.&nbsp;' + QAns2[n] + "</SPAN>"
		}
		
		if (QAns3[n] != "")
		{
			Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=3><SPAN ID="Ans3">3.&nbsp;' + QAns3[n] + "</SPAN>"
  	}
	
		if (QAns4[n] != "")
		{
			Line = Line + '<BR><INPUT TYPE=RADIO NAME="QAns' + n + '" VALUE=4><SPAN ID="Ans4">4.&nbsp;' + QAns4[n] + "</SPAN>"
  	}
		
		dc.write(Line)
	
		dc.write("</TD></TR></TABLE></TD></TR>")

		return true;
	}
	else
	{	
		Line = "<TD COLSPAN=2 CLASS=question><big><b>End of Quiz!</b></big>";
		dc.write(Line)

		for ( n=0; n < dc.questionform.quizans.value.length; n++)
		{
			if (dc.questionform.quizans.value.charAt(n) != "0")
			{
				CorrectAnswerCount ++;
			}
		}

		Line = "<p>You took " + parseInt(dc.questionform.quizetime.value)/1000 + " seconds to answer the questions";

		if (parseInt(CorrectAnswerCount) == 1)
		{
			Line = Line + "<br>and you got " + CorrectAnswerCount + " answer correct.";
		}
		else
		{
			Line = Line + "<br>and you got " + CorrectAnswerCount + " answers correct.";
		}
		dc.write(Line)
			

		Line = "</TD>";
		dc.write(Line)

		dc.write("</TR>")
		
		UpdateScoreBoard(QTxt.length, CorrectAnswerCount);

		return false;	
	}
}


function ShowAnswer(dc)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		dc.all.item('punchline').style.display= "block";
	}
	else
	{
		dc.punchline.visibility = "show";
	}			
}
 
function WriteQuestion4(dc, n)
{
var Line;
var ShowAnswer = '<P><span class="instruction"><a href="JavaScript:ShowAnswer(document);" title="Show the Punchline" onmouseover="return MouseOver(' + "'" + 'Show the Punchline' + "'" + ')" onmouseout="return MouseOver(' + "''" + ')">Press here</a> to <b>show the punchline</b>.</span>';
 
	dc.write("<TR>");

	if (n < QTxt.length)
	{
		if (QPic[n] == "") 
		{
			Line = "<TD COLSPAN=2 CLASS=question>" + QTxt[n];
			Line = Line + ShowAnswer;
			Line = Line + "</TD>";
 		}
		else
 		{
			Line = "<TD CLASS=question>" + QTxt[n] + ShowAnswer + "</TD><TD CLASS=question>" + QPic[n] + "</TD>";
 		}
		dc.write(Line);
		
		Line = '</TR><TR><TD CLASS=question>';
	  if (navigator.appName == "Microsoft Internet Explorer")
	  {
			Line = Line + '<DIV ID="punchline" POSITION="relative" STYLE="display: none"><P>' + QAns1[n] + '</DIV>';
	  }
	  else
	  {
			Line = Line + '<ILAYER NAME="punchline" VISIBILITY="hide"><P>' + QAns1[n] + '</ILAYER>';
	  }			
		Line = Line + '</TD>';
		
		dc.write(Line);
	
		dc.write("</TR></TABLE></TD></TR>");
		
		return true;
	}
	else
	{	
		Line = "<TD COLSPAN=2 CLASS=question><big><b>Sorry. No more jokes in this section!</b></big>";
		dc.write(Line)

		Line = "</TD>";
		dc.write(Line)

		dc.write("</TR>")

		return false;	
	}

}


function CheckAnswers(dc)
{
var CorrectAnswerText;
var CorrectAnswerCount;
var n; 
var c;
var wa;
 
	CorrectAnswerCount = 0

	CorrectAnswerList = ""
	CorrectAnswerText = ""

	for ( n = 0; n < QTxt.length; n++)
	{ 
		c = 0;
	  if (eval("dc.questionform.QAns"+ n +"[" + 0 + "].checked")) c = 1;
    if (QAns2[n] != "")
		{
	  	if (eval("dc.questionform.QAns"+ n +"[" + 1 + "].checked")) c = 2;
		}
    if (QAns3[n] != "")
		{
	  	if (eval("dc.questionform.QAns"+ n +"[" + 2 + "].checked")) c = 3;
    }
		if (QAns4[n] != "")
		{
	  	if (eval("dc.questionform.QAns"+ n +"[" + 3 + "].checked")) c = 4;
		}
		if (c == QAnsNum[n]) 
    {
			CorrectAnswerCount = CorrectAnswerCount + 1
			if (CorrectAnswerCount > 1) CorrectAnswerText = CorrectAnswerText + ',&nbsp;'
			CorrectAnswerText = CorrectAnswerText + (n+1)
		}  
		
	}
  		
	if (CorrectAnswerCount == 0) 
	{
  	CheckAnswerText = "Sorry. You have no correct answers." 
  }
  else
	{
	  if (CorrectAnswerCount == 1)
	  {
  	  CheckAnswerText = "You have " + CorrectAnswerCount + " correct answer." 
		  CheckAnswerText = CheckAnswerText + "<p>The question you answered correctly was: " + CorrectAnswerText
    }
    else
		{
	    if (CorrectAnswerCount == QTxt.length)
	    {
  	    CheckAnswerText = "Well Done. All your answers were correct." 
      }
	    else
      {
		    CheckAnswerText = "You have " + CorrectAnswerCount + " correct answers."
		    CheckAnswerText = CheckAnswerText + "<p>The questions you answered correctly were: " + CorrectAnswerText 
	    }
		}
	}

	UpdateScoreBoard(QTxt.length, CorrectAnswerCount);	

	wa = NewWindow("", 'QuizAnswers');	
	wa.document.close();
	wa.document.write("<body>");

	wa.document.write('<script language="JavaScript">');

	wa.document.write('function MouseOver(Msg)');
	wa.document.write('{');
	wa.document.write('	window.status=Msg;');
	wa.document.write('	return true;');
	wa.document.write('}');

	wa.document.write('</script>');

  wa.document.write('<center><img src="graphics/quizu.jpg" alt="QuizU Logo" height="115" width="115">');

	wa.document.write('<font face="verdana" color="#003399">');
  wa.document.write('<h3>', QuizName, '</h3>');
	wa.document.write('</font>');

	wa.document.write('<font face="verdana">');
	wa.document.write(CheckAnswerText);

  wa.document.write('<p>');

	if (CorrectAnswerCount != QTxt.length)
  {
		wa.document.write('<form name="answers" action="quizans1.htm" method="GET">')
    wa.document.write('<table><tr><td bgcolor="#d1b2ff">')
		wa.document.write('<font size="2" face="verdana">');
		wa.document.write('<a href="JavaScript:document.answers.submit();" title="See the Correct Answers" onmouseover="return MouseOver(', "'See the Correct Answers'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>see the correct answers</b>.') 
    wa.document.write('</font>')
		wa.document.write('</td></tr></table>')
		wa.document.write('<input type="hidden" name="quizinc" value="',GetSearchParm('quizinc'),'">')
		wa.document.write('</form>') 
  }
	else
	{
		wa.document.write('<table><tr><td bgcolor="#d1b2ff">')
		wa.document.write('<font size="2" face="verdana">');
		wa.document.write('<a href="JavaScript:window.close(document)" title="Close this Window" onmouseover="return MouseOver(', "'Close this Window'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>close this window</b>.') 
  	wa.document.write('</font>')
		wa.document.write('</td></tr></table>')		
	}
	
	wa.document.write('</font>');

	wa.document.write("</center>"); 
	
	wa.document.write("</body>");
}



function CheckAnswer2(dc, i)
{
var CorrectAnswerText;
var CorrectAnswerCount;
var n; 
var c;
var wa;
 
	CorrectAnswerCount = 0

	CorrectAnswerList = ""
	CorrectAnswerText = ""

	n = i;	 
	c = 0;
  if (eval("dc.questionform.QAns"+ n +"[" + 0 + "].checked")) c = 1;
  if (QAns2[n] != "")
	{
  	if (eval("dc.questionform.QAns"+ n +"[" + 1 + "].checked")) c = 2;
	}
  if (QAns3[n] != "")
	{
  	if (eval("dc.questionform.QAns"+ n +"[" + 2 + "].checked")) c = 3;
  }
	if (QAns4[n] != "")
	{
  	if (eval("dc.questionform.QAns"+ n +"[" + 3 + "].checked")) c = 4;
	}
	if (c == QAnsNum[n]) 
  {
		CorrectAnswerCount = CorrectAnswerCount + 1
		if (CorrectAnswerCount > 1) CorrectAnswerText = CorrectAnswerText + ',&nbsp;'
		CorrectAnswerText = CorrectAnswerText + (n+1)
	}
	dc.forms[0].elements[QAnsNum[n]-1].checked = "true";		
  		
	if (CorrectAnswerCount == 0) 
	{
  	CheckAnswerText = "Sorry. Your answer wasn't correct. The correct answer has now been selected." 
  }
  else
	{
    CheckAnswerText = "Well Done. Your answer was correct." 
	}
	alert(CheckAnswerText);
}



function CheckAnswer3(dc, i)
{
var CorrectAnswerText;
var CorrectAnswerCount;
var n; 
var c;
var wa;
 
	CorrectAnswerCount = 0

	CorrectAnswerList = ""
	CorrectAnswerText = ""

	n = i;	 
	c = 0;
			
  if (eval("dc.questionform.QAns"+ n +"[" + 0 + "].checked")) c = 1;
  if (QAns2[n] != "")
	{
		if (eval("dc.questionform.QAns"+ n +"[" + 1 + "].checked")) c = 2;
	}
	if (QAns3[n] != "")
	{
  	if (eval("dc.questionform.QAns"+ n +"[" + 2 + "].checked")) c = 3;
  }
	if (QAns4[n] != "")
	{
  	if (eval("dc.questionform.QAns"+ n +"[" + 3 + "].checked")) c = 4;
	}

	if (c == QAnsNum[n]) 
  {
		CorrectAnswerCount = CorrectAnswerCount + 1
		if (CorrectAnswerCount > 1) CorrectAnswerText = CorrectAnswerText + ',&nbsp;'
		CorrectAnswerText = CorrectAnswerText + (n+1)
	}
			
	if (CorrectAnswerCount == 0) 
	{
		dc.questionform.quizans.value = dc.questionform.quizans.value + "0";
	}
  else
	{
		dc.questionform.quizans.value = dc.questionform.quizans.value + c;
	}		
}


function QuizSponsor(Name, Email, Website, Text, Banner)
{
// if website & banner are both non-blank the footer banner 
// will be replaced by the specified banner.
// the banner should be located in the the graphics directory

		QuizSponsorName = Name;
		QuizSponsorEmail = Email;
		QuizSponsorWebsite = Website;
		QuizSponsorText = Text;
		QuizSponsorBanner = Banner;
}


function QuizHeader(Name, IntroText, AdImage)
{
		QuizName = Name;
		QuizIntroText = IntroText;
		QuizAdImage = AdImage;
		// nb use AdImage as timeout if numeric
		// timeout is in milliseconds 
		if (strToZero(AdImage) != 0)
		{
			QuizTimeout = parseInt(AdImage);
		}
		else
		{
			QuizTimeout = 0;
		}
}


function QuizQuestion(i, Txt, Pic, Ans1, Ans2, Ans3, Ans4, AnsNum)
{

	QTxt[i] = Txt;
	QPic[i] = Pic;
	QAns1[i] = Ans1;
	QAns2[i] = Ans2;
	QAns3[i] = Ans3;
	QAns4[i] = Ans4;
	QAnsNum[i] = AnsNum;

}

function TryQuiz(sel)
{
	var s;
  var n;
	
	n = ElementNo(sel);
	
	if (n != -1) 
	{	
		s = document.quizzes.elements[n];	
		// document.location.replace(s.options[s.selectedIndex].value); 
		//document.quizzes.action = s.options[s.selectedIndex].value;
		document.quizzes.quizinc.value = s.options[s.selectedIndex].value;
    document.quizzes.action = "quiztpl1.htm";
    document.quizzes.submit();
	}
	else
	{
		alert('Quiz ' + sel + ' cannot be found. Please contact the QuizMaster.');
	}
}

/* */
/* input - a button (or other element with a name) */
/* the name is of the format TryXXXXXXX */
/* */
/* we strip off the Try and use the rest of the string as the */
/* name of a Select element whose selected field defines the  */
/* page we need to display next. */
/* */
function TryThisQuiz(t)
{
	var s;
  var n;
	var sel;

	sel = new String;

	sel = t.name;
	
	sel = sel.substring(3, sel.length);

	n = ElementNo(sel);
	
	if (n != -1) 
	{	
		s = document.quizzes.elements[n];	
		document.quizzes.quizinc.value = s.options[s.selectedIndex].value;
    document.quizzes.action = "quiztpl1.htm";
    document.quizzes.submit();
	}
	else
	{
		alert('Quiz ' + sel + ' cannot be found. Please contact the QuizMaster.');
	}
}

/* */
/* input - a button (or other element with a name) */
/* the name is of the format TryXXXXXXX */
/* */
/* we strip off the Try and use the rest of the string as the */
/* name of a Select element whose selected field defines the  */
/* page we need to display next. */
/* */
function TryThisQuizN(sel)
{
	var s;
  var n;
	var selName;
	
	selName = new String;
	
	selName = sel;

	n = ElementNo(selName);
	
	if (n != -1) 
	{	
		s = document.quizzes.elements[n];	
		document.quizzes.quizinc.value = s.options[s.selectedIndex].value;
		document.quizzes.action = "quiztpl1.htm"; // default template
		// update template for special quiz types
		if (document.quizzes.quizinc.value.substring(0,5) == "qinc3")	document.quizzes.action = "quiztpl3.htm";
		if (document.quizzes.quizinc.value.substring(0,5) == "qinc4")	document.quizzes.action = "quiztpl4.htm";
		
		document.quizzes.submit();
	}
	else
	{
		alert('Quiz ' + sel + ' cannot be found. Please contact the QuizMaster.');
	}
}

function ElementNo(name)
{
	for (i = 0; i < document.quizzes.elements.length; i++)
	{
    if ((document.quizzes.elements[i].name) == name) return(i);
  }
	
	return(-1);
}

function UpdateScoreBoard(QTxtlength, CorrectAnswerCount)
{	
var expdate = new Date ();
var CAs;
var PAs;
var Qs;
	
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (366 * 24 * 60 * 60 * 1000)); // 366 days from now 

	CAs = GetCookie("CAs");
	CAs = eval(CAs) + eval(CorrectAnswerCount);
	SetCookie ("CAs", CAs, expdate,"/");

	PAs = GetCookie("PAs");
	PAs = eval(PAs) + eval(QTxtlength);
	SetCookie ("PAs", PAs, expdate,"/");

	Qs = GetCookie("Qs");
	Qs = eval(Qs) + 1;
	SetCookie ("Qs", Qs, expdate,"/");
}

function ClearScoreboard()
{
	var expdate = new Date ();
  
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (366 * 24 * 60 * 60 * 1000)); // 366 days from now 

	SetCookie ("CAs", 0, expdate,"/");

	SetCookie ("PAs", 0, expdate,"/");

	SetCookie ("Qs", 0, expdate,"/");
}

function NewOnlineQuote(dc)
{
var QuotationText;

	QuotationText = new Array(9)

	QuotationText[0] = "<p><cite>'Why does a round pizza come in a square box?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[1] = "<p><cite>'What disease did cured ham actually have?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[2] = "<p><cite>'Why is it that people say they slept like a baby when babies wake up every two hours?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[3] = "<p><cite>'Why do people pay to go up tall buildings and then put money in binoculars to look at things on the ground?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[4] = "<p><cite>'If corn oil is made from corn, and vegetable oil is made from vegetables, what is baby oil made from?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[5] = "<p><cite>'Why does someone believe you when you say there are four billion stars, but check when you say the paint is wet?'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[6] = "<p><cite>'The statistics on sanity is that one out of every four persons are suffering from some sort of mental illness. Think of your three best friends. If they are okay, then its you!'</cite>&nbsp;&nbsp;<b>Anon</b>";
	QuotationText[7] = "<p><cite>'What is better than presence of mind in a railway accident? Absence of body.'</cite>&nbsp;&nbsp;<b>Punch</b>";
	QuotationText[8] = "<p><cite>'It's a recession when your neighbour loses his job: it's a depression when you lose yours.'</cite>&nbsp;&nbsp;<b>Harry S Truman (1884-1972)</b>";
	
	now = new Date();
		
	OnlineQuote(dc, QuotationText[(now.getTime())%9]);
}

function OnlineQuote(dc, QuotationText)
{var wa;

	wa = NewWindow('','OnlineQuote');

	wa.document.close();
	wa.document.write("<body>");

	wa.document.write('<script language="JavaScript">');


	wa.document.write('function MouseOver(Msg)');
	wa.document.write('{');
	wa.document.write('	window.status=Msg;');
	wa.document.write('	return true;');
	wa.document.write('}');

	wa.document.write('</script>');

    wa.document.write('<center>');

	wa.document.write('<img src="graphics/quizu.jpg" alt="QuizU Logo" height="115" width="115">');

	wa.document.write('<font face="verdana" color="#CC3300">');
	wa.document.write(QuotationText);
	wa.document.write('</font>');

	wa.document.write('<p><table><tr><td bgcolor="#d1b2ff">')
	wa.document.write('<font size="2" face="verdana">');
	wa.document.write('<a href="JavaScript:window.close(document)" title="Close this Window" onmouseover="return MouseOver(', "'Close this Window'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>close this window</b>.') 
  	wa.document.write('</font>')
	wa.document.write('</td></tr></table>')		

	wa.document.write("</center>"); 
	
	wa.document.write("</body>");
}
function Links(dc)
{
	WriteLinksWindow(dc);
}

function WriteLinksWindow(dc)
{var wa;

	wa = NewWindow('','Links');

	wa.document.close();
	wa.document.write("<body>");

	wa.document.write('<script language="JavaScript">');


	wa.document.write('function MouseOver(Msg)');
	wa.document.write('{');
	wa.document.write('	window.status=Msg;');
	wa.document.write('	return true;');
	wa.document.write('}');

	wa.document.write('</script>');

    wa.document.write('<center>');

	wa.document.write('<img src="graphics/quizu.jpg" alt="QuizU Logo" height="115" width="115">');

	wa.document.write('<font face="verdana" color="rgb(0,51,153)" size="+1">');

	wa.document.write('<p><br><b>Links</b>'); 

  	wa.document.write('</font>')

	wa.document.write('<font face="verdana" color="rgb(0,0,0)">');
	
	wa.document.write('<p>You might like the following websites which also offer quizzes:'); 

	wa.document.write('<p><a  target="linkWindow" href="http://www.usefultrivia.com/" title="UsefulTrivia.Com" onmouseover="');
	wa.document.write("return MouseOver('UsefulTrivia.Com')");
	wa.document.write('">UsefulTrivia.Com</a>');
	
	wa.document.write('</font>');

	wa.document.write('<p><table><tr><td bgcolor="#d1b2ff">')
	wa.document.write('<font size="2" face="verdana">');
	wa.document.write('<a href="JavaScript:window.close(document)" title="Close this Window" onmouseover="return MouseOver(', "'Close this Window'" ,')" onmouseover="return MouseOver(', "''" ,')">Press here</a> to <b>close this window</b>.') 
  	wa.document.write('</font>')
	wa.document.write('</td></tr></table>')		

	wa.document.write("</center>"); 
	
	wa.document.write("</body>");
}

//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
