allpics = ["8711","6411","5556","0123","7767","8722","4474","9751","9657","2887","3339","0454","8041","9967","6696","1024","1241","2462","2379","1667","4343","2132","9846","3371","7677","0988","0411","6281","5100","5209","8846","4332","4831","8312","6314","9356","7446","8189","3587","9455","0122","7654","8777"];

nextpic = new Image();
allpics_rnd = new Array();
piccount=0;
var gebi=function(pf){return document.getElementById(pf)};
msg='';

for (i=0;i<allpics.length;i++){
dr = (Math.random()*10>5)?1:-1;
ps = Math.round(Math.random()*(allpics.length-1));
	while (allpics[ps]=="0"){
		ps+=dr;
		if(ps<0){ps=allpics.length-1;}
		if(ps>allpics.length-1){ps=0;}
	}
allpics_rnd[i] = allpics[ps];
allpics[ps]="0";
}



showNext(0);


function showNext(prl){

gebi('next').style.display="none";

gebi('form').reset();

	if (prl) {
		gebi('vipic').src = nextpic.src;
	} else {
		gebi('vipic').src = allpics_rnd[0]+".jpg";
	}

piccount++;
picPreload();
}

function picPreload(){
	if (piccount<allpics.length){nextpic.src = allpics_rnd[piccount]+".jpg";}
}


function showResults(){

mch1=(allpics_rnd[piccount-1].charAt(0)%2==gebi('ei').selectedIndex)?1:(gebi('ei').selectedIndex==2)?0:10;
mch2=(allpics_rnd[piccount-1].charAt(1)%2==gebi('sn').selectedIndex)?1:(gebi('sn').selectedIndex==2)?0:10;
mch3=(allpics_rnd[piccount-1].charAt(2)%2==gebi('tf').selectedIndex)?1:(gebi('tf').selectedIndex==2)?0:10;
mch4=(allpics_rnd[piccount-1].charAt(3)%2==gebi('jp').selectedIndex)?1:(gebi('jp').selectedIndex==2)?0:10;

mch=mch1+mch2+mch3+mch4;

if(mch>=10){msg=' This is incorrect! Try again...';}
if(mch==0){msg=' ...';}
if(mch==1){msg=' Well done, you\'re on the right track!';}
if(mch==2){msg=' Good choice, keep it coming!';}
if(mch==3){msg=' Fantastic, just one more to go!';}
if(mch==4){msg=' Congratulations, you\'ve got it right!';}
if(piccount==allpics.length && mch==4){msg+=' This was the last picture.';}

gebi('restext').value = msg;

if(mch==4 && piccount<allpics.length){gebi('next').style.display="block"};
}