// Either or Quiz Engine written by Rob Manuel 2002
// More stuff at www.b3ta.co.uk
//
// Rejigged with CSS stretchy stuff 2006
//
// Then extended to support the 'Tranny or Granny' quiz with photo reveals in 2007
//
// Want to use this code / format?
// For fun: Credit me.
// Commercial: Pay me.

var score=0;


function randomanswers()
{

i=0;
	while (i++<topsize)
	{
	if (Math.random() > .5)
     {eval("document.quizform.s" + i + "[0].checked=true");}
     else
     {eval("document.quizform.s" + i + "[1].checked=true");}

	}
	check(i-1);
}

function buildpromo()
{
document.write('<a href="http://www.amazon.co.uk/exec/obidos/ASIN/1905548281/rofl-21">Buy the \'B3ta Sick Joke\' book</a><br><small><small>Compiled by Rob Manuel (author of this quiz)</small></small>');

}


function morequizzes()
{
var x = '<a href="../trannyorgranny/">Tranny or Granny</a><br><a href="../femaleorshemale/">Female or Shemale</a><br><a href="../femaleorshemale2/">Female or Shemale 2</a><br><a href="../femaleorshemale3/">Female or Shemale 3</a><br><a href="../gash-or-tash/">Gash or Tash</a><br><a href="../man-milk-or-moo-milk/">Man Milk or Moo Milk</a><br><a href="../funnelortunnel/">Funnel or Tunnel</a><br><a href="../hecatorshecat/">He-cat or She-cat</a><br><a href="../gayorstraight/">Gay or Straight</a><br><a href="../hacker-or-spacker/">Hacker or Spacker</a>';
return x;
}



function ResetQuiz()
{
var count=0;
while (count++<topsize)
 {
 eval("document.a"+count+".src='../includes/none.gif'");
 eval("document.l"+count+".src='../includes/none.gif'");
 eval("document.quizform.s" + count + "[0].disabled=false");
 eval("document.quizform.s" + count + "[1].disabled=false");
 eval("document.quizform.s" + count + "[0].checked=false");
 eval("document.quizform.s" + count + "[1].checked=false");

 }
}

function checkindividual(item)
{
var ret="";

     if ((eval("document.quizform.s" + item + "[0].checked")) ==  answer[item])
     {ret="<br><img src='../includes/tick.gif'>";}
     else
     {ret="<br><img src='../includes/cross.gif'>";}

     if (answer[item])
        {ret=ret+"<br><img src='arrow1.gif'>";}
        else
        {ret=ret+"<br><img src='arrow2.gif'>";}

  return (ret);

}

function check(item)
{

// This checks ALL the questions, whether you've answered them or not

var count=0;
var finished=0;
score=0;

while (count++<topsize)

  {

  if ((eval("document.quizform.s" + count + "[0].checked")) ||
     (eval("document.quizform.s" + count + "[1].checked")))

    {
     if ((eval("document.quizform.s" + count + "[0].checked")) ==  answer[count])
     {score++;eval("document.a"+count+".src='../includes/tick.gif'");}
     else
     {eval("document.a"+count+".src='../includes/cross.gif'");}

     eval("document.quizform.s" + count + "[0].disabled='true'");
     eval("document.quizform.s" + count + "[1].disabled='true'");

     if (answer[count])
        {eval("document.l"+count+".src='arrow1.gif'");}
        else
        {eval("document.l"+count+".src='arrow2.gif'");}
     finished++; 
    }

  }


switch (quiztype)
{
case (quiztype = 1):
if (finished==topsize)
	{var z=setTimeout(endscreen(),1000);}
break
case (quiztype = 2):
bigreveal(item,finished);
break
} 


}


function bigreveal(item,finished)
{
showpopup();
document.getElementById('popup').innerHTML ="<div onClick='javascript:hidebigreveal("+finished+");'><div class='popupinner'><a href='javascript:hidebigreveal("+finished+");'>Next question</a>"+checkindividual(item)+"</div><img src='r"+item+".jpg' width='300'></div>";
}

function hidebigreveal(finished)
{
hidepopup();

if (finished==topsize)
{
endscreen();
}

}


function endscreen()
{
document.getElementById('popup').innerHTML ="<p><b>"+texty[score]+"</b><p>You scored "+score+"/"+topsize+"<p><a href='javascript:ResetQuiz();history.go(0);'>Play again?</a><p>Or try these other quizzes:<br>"+morequizzes();
showpopup();
}

function showpopup()
{
document.getElementById('quiz').style.opacity = .40;
document.getElementById('popupcontainer').style.visibility = "visible";
}

function hidepopup()
{
document.getElementById('quiz').style.opacity = .999;
document.getElementById('popupcontainer').style.visibility = "hidden";
}



function buildbottomline()
{
document.write('Like the quiz? Sign up for the B3ta newsletter. Send a blank email to <a href="b3ta-subscribe@yahoogroups.com">b3ta-subscribe@yahoogroups.com</a> or read the <a href="http://www.b3ta.com/newsletter/latest/">lastest issue</a>.');
}

function buildscreen()
{
var order = new Array();
i=0;
while (i++<topsize)
{
order[i-1]=i;
}
 order.shuffle();

i=0;
while (i++<topsize)
{
document.write('<div class="box">');
//document.write(order[i-1]);
document.write('<img src="'+order[i-1]+'.jpg" width="150" height="150" width="150" align="left">');
document.write('<input type="radio" id=top'+order[i-1]+' onClick="check('+order[i-1]+')" name="s'+order[i-1]+'" value="'+option1+'">&nbsp;<label for="top'+order[i-1]+'">'+option1+'</label><br>');
document.write('<input type="radio"  id=bot'+order[i-1]+' onClick="check('+order[i-1]+')" name="s'+order[i-1]+'" value="'+option2+'">&nbsp;<label for="top'+order[i-1]+'">'+option2+'</label><br>');
document.write('<img src="../includes/none.gif" name="a'+order[i-1]+'"><br>');
document.write('<img src="../includes/none.gif" name="l'+order[i-1]+'" width="86" height="62">');
document.write('<br clear="all">');
document.write('</div>');
}
}


function buildinstructions()
{
document.write ('Look at each image. Click the circles to select '+option1+' or '+option2+'.');
}


function playmusic(midiorswf)
{

if (midiorswf == 'midi')
	{
		var MSIE=navigator.userAgent.indexOf("MSIE"); 
		var NETS=navigator.userAgent.indexOf("Netscape"); 
		var OPER=navigator.userAgent.indexOf("Opera"); 
		if((MSIE>-1) || (OPER>-1)) { 
		document.write('<BGSOUND SRC=music.mid LOOP=1>'); 
		} else { 
		document.write('<EMBED SRC=music.mid AUTOSTART=TRUE '); 
		document.write('HIDDEN=true VOLUME=60 LOOP=NO>');
		} 
    }
    else
    {
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"');
    document.write('WIDTH=1 HEIGHT=1>');
    document.write('<PARAM NAME=movie VALUE="music.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="music.swf" quality=high bgcolor=#FFFFFF  WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
    document.write('</OBJECT>');
    }
}



// Shuffle function via http://4umi.com/web/javascript/array.htm

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};