document.oncontextmenu=new Function("return false");


function login(){
	document.location = ""; }


var ans = new Array;
var yourtry = new Array;
var thisscore = 0;
var x;
var secsAllowed=999;
var count=10;
var choice=4;
var username;
var email;


ans[1]="A";
ans[2]="C";
ans[3]="A";
ans[4]="D";
ans[5]="D";
ans[6]="C";
ans[7]="C";
ans[8]="D";
ans[9]="B";
ans[10]="A";


for (x=1;x<=count;x++) yourtry[x]="";


function storetry(question, answer){
		yourtry[question] = answer;
}


function getscore(){
var y;
thisscore = 0;
setCookie('save', 'false', 365);
	for (y=1;y<=count;y++)
	{
       if (yourtry[y] =="")
			{
			 alert("Bitte JEDE Frage beantwortn");
			 return(false);
			}
	   else if (yourtry[y] == ans[y]) thisscore++;
	}
	alert("Dein Ergebnis: " + Math.round(thisscore/count*100)+"%");
	return(true);
}


function showerrors(){
var h;
var v =145+((count-thisscore)*20);
h = "top=0,left=0,width=180,";
h = h + "height=" + v;
h = h + ",scrollbars=1";
var i;
var newwin;
	newwin = window.open("", "", h);
 	newwin.document.write("<FONT size=4><B>Your Error(s)...</B><BR><BR>");
	for(i = 1; i<= count;i++){
         		if (yourtry[i] != ans[i]){
			newwin.document.write("\n   Frage: " + i);
			newwin.document.write("<BR>");
		}
    }
	newwin.document.write("<BR><B>Have another try...</B><BR><BR></FONT>");
	newwin.document.write('<BUTTON onclick="window.close()">Close</BUTTON>');
}


function refresh(){
	document.location.reload();
	document.quizform.reset();
}


function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}


function savequiz(){
setCookie('quizuser',document.quizform.name.value,365);
setCookie('QuizID',document.quizform.ID.value,365);
setCookie('save', 'true', 365);
for (x=1; x<=count;x++)	setCookie('q'+x, yourtry[x], 365);
}


function setCookie(NameOfCookie, value, expiredays){
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
	}


function docookies(){
var con;
username=getCookie('username');
email=getCookie('email');
if (username==null) {
          alert('Please log in');
		window.location = "";
		}
	else {
		document.quizform.name.value = username;
	if ((getCookie('QuizID') == document.quizform.ID.value) && (getCookie('save')== 'true') && (getCookie('quizuser') == document.quizform.name.value))
	{
		con = confirm('Saved quiz found. OK to continue, Cancel to restart.');
		if (con) getsave();
	}
		}
}


function getsave() {
var c;
var found = false;
var y = 0;
var ch = 0;
	for(x=1; x<=count;x++) {
		found = false;
		c = getCookie('q'+x);
		yourtry[x] = c;
		while(found ==false){
		if ((document.quizform.elements[y].value == c) && (document.quizform.elements[y].type == "radio"))
			{
			document.quizform.elements[y].checked = true;
			found = true;
			}
			y=y+1;
			ch=ch+1;
		}
		y = y + choice-ch;
		ch=0;
		}
}

