

function Question() {
 this.question=Question.arguments[0]
 var n=Question.arguments.length
 this.answers = new Array(n-2)
 for(var i=1; i<n-1; ++i) this.answers[i-1]=Question.arguments[i]
 this.correctAnswer=Question.arguments[n-1]
}


function createCookierpj(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookierpj(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function eraseCookierpj(name)
{
	createCookie(name,"",-1);
}



function readCookie() {
 numberOfQuestions=0
 cookie=document.cookie
 useranswers=readCookierpj("userAnswers")
 isWritten = readCookierpj("isWritten")
 //alert("Hello " + useranswers);
}

function getNumberValue(s,n) {
 s=removeBlanks(s)
 var pairs=s.split(";")
 for(var i=0;i<pairs.length;++i) {
  var pairSplit=pairs[i].split("=")
  if(pairSplit[0]==n) {
   if(pairSplit.length>1) return parseInt(pairSplit[1])
   else return 0
  }
 }
 return 0
}


function removeBlanks(s) {
 var temp=""
 for(var i=0;i<s.length;++i) {
  var c=s.charAt(i)
  if(c!=" ") temp += c
 }
 return temp
}

function askNextQuestion() {
/*document.writeln("<H4 ALIGN='CENTER'>"+qa[currentQuestion].question+ (currentQuestion + 1) +"</H4>")*/
 displayAnswers()
}

function displayAnswers() {
 
if (currentQuestion > 0) {
 document.writeln("<tr align='center'>")
 document.writeln("<td align='left' valign='top' width='150' cellpadding=5>")
 document.writeln('<FORM NAME="gobackForm">')
 document.writeln('<INPUT TYPE="BUTTON" NAME="previous" VALUE="Vorherige Frage" onClick="goBackward();">')
 document.writeln('</FORM>')
document.writeln("</td>")
} else {
 document.writeln("<tr align='center'>")
 document.writeln("<td align='left' valign='top' width='150'cellpadding=5>")
 document.writeln('<FORM NAME="gobackForm">')
 document.writeln('<INPUT TYPE="BUTTON" NAME="previous" VALUE=" Vorherige Frage" onClick="goBackward();" disabled>')
 document.writeln('</FORM>')
document.writeln("</td>")
}



 document.writeln('<FORM NAME="answerForm">')
 document.writeln('<H4 ALIGN="CENTER"><td align="center" width=428>')

 for(var ii=0;ii<qa[currentQuestion].answers.length;++ii) {
  // if the associated useranswer character matches, we mark it selected.
   if (useranswers.charAt(currentQuestion) == ii) {
	document.writeln('<INPUT TYPE="RADIO" NAME="answer" checked>'+qa[currentQuestion].answers[ii])
  } else {
  	document.writeln('<INPUT TYPE="RADIO" NAME="answer">'+qa[currentQuestion].answers[ii])  
  }
 } //end for


	if (currentQuestion < quizLength -1) { 
		document.writeln("<td align='right' valign='top' width='150'>")
		document.writeln('<INPUT TYPE="BUTTON" NAME="continue" VALUE="Nächste Frage" onClick="goForward()">')
		document.writeln("</td>")
	} else {
		document.writeln("<td align='right' valign='top' width='150'>")
		document.writeln('<INPUT TYPE="BUTTON" NAME="continue" VALUE="Quiz beenden" onClick="goForward()">')
		document.writeln("</td>")
	}


	document.writeln("<tr>")
	document.writeln("<td colspan=3 align=center>")
	if (qi[currentQuestion] != "") {
		document.writeln('<br \><img src="' + qi[currentQuestion] + '">');  
	} 
	if (qt[currentQuestion] != "") {
		document.writeln('<br \>'+qt[currentQuestion]+'<br \>');  
	}
	


 document.writeln('</H4></td>')
 document.writeln('</FORM>')
}
 
function calculateCompleted() {
var completecount=0;
 var i = quizLength;
 
 var newuseranswers="";
 //march through the useranswerstring and count the number of 0 and 1
  for (j=0; j<i; j++) {
   if ((useranswers.charAt(j) == 0) || (useranswers.charAt(j) == 1)) {
		completecount++;
   }//if
  }  //for
  //debug- sreturn(completecount);
  return Math.round((completecount/i)*100);
}

function goBackward() {
 var numAnswers=qa[currentQuestion].answers.length
 //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for
writeAnswer();
location="quiztest.html?qnum=" + (currentQuestion - 1);
}




function goForward() {
 var numAnswers=qa[currentQuestion].answers.length
  //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for
 
 
 writeAnswer(); 
 useranswers=readCookierpj("userAnswers");
  if (currentQuestion < (quizLength - 1)) { 
location="quiztest.html?qnum=" + (currentQuestion + 1);
 } else {
	 		var answerStringS = "";
		for (i=0; i < quizLength; i++) {
		
			var userans2=useranswers.charAt(i);
			switch(userans2)
			{
				case '0':
				 answerStringS += "Phishing"
				 break    
				case '1':
				 answerStringS += "Legitim"
				 break 
				case '2':
				 answerStringS += "Keine Antwort"
				 break
			}
			if (i != (quizLength-1)) {
				answerStringS += ","
			}
		
		}
		createCookierpj('answerString',answerStringS,7);
	if (writeResults == "true") {
		isWritten = readCookierpj("isWritten")
		if (isWritten == "0") {
		   location=processlocation;
		} else {
		   location="results.html"
		}

//	   location="process.asp"
	} else {
	   location="results.html"
	}
 }
} //function goForward



function createanstr() {
 var numAnswers=qa[currentQuestion].answers.length
  //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for
 
 writeAnswer(); 
 useranswers=readCookierpj("userAnswers");

	 		var answerStringS = "";
		for (i=0; i < quizLength; i++) {
		
			var userans2=useranswers.charAt(i);
			switch(userans2)
			{
				case '0':
				 answerStringS += "Phishing,"
				 break    
				case '1':
				 answerStringS += "Legitim,"
				 break 
				case '2':
				 answerStringS += "Keine Antwort,"
				 break
			}
		
		}// for
		createCookierpj('answerString',answerStringS,7);

		
	if (writeResults == "true") {
		isWritten = readCookierpj("isWritten")
		if (isWritten == "0") {
		   location=processlocation
		} else {
		   location="results.html"
		}
//	   location="process.asp"
	} else {
	   location="results.html"
	}
 
}

function writeprogress() {
 /*var numAnswers=qa[currentQuestion].answers.length
  //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for*/

 /*writeAnswer(); 
 useranswers=readCookierpj("userAnswers");*/

 document.writeln("<tr align=center>")
 document.writeln("<td colspan=3>")

		for (i=0; i < quizLength; i++) {
		
			var userans=useranswers.charAt(i);
			switch(userans)
			{
				case '0':
				if (i == currentQuestion) {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/highlight"+i+".gif' border='0'></a>");
				}
				else {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/filled"+i+".gif' border='0'></a>"); }
				 break 
				case '1':
				if (i == currentQuestion) {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/highlight"+i+".gif' border='0'></a>");
				}
				else {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/filled"+i+".gif' border='0'></a>"); }
				 break 
				case '2':
				if (i == currentQuestion) {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/highlight"+i+".gif' border='0'></a>");
				}
				else {
				 document.write("<a onclick='jumptopage("+i+")'><img src='/phishing/images/hallow"+i+".gif' border='0'></a>"); }
				 break
			}
			}
 document.writeln("</tr>")
 document.writeln("</td>")
 
}
 

/*function writenumbers() {
 var numAnswers=qa[currentQuestion].answers.length
  //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for	
	
		for (i=1; i <= quizLength; i++) {
			if (i == currentQuestion +1) {
				 document.write("&nbsp;&nbsp;<small><strong><font color='#d4c520'>"+i+"</font></strong></small>&nbsp;&nbsp;&nbsp;");
			}
			else {
				 document.write("&nbsp;&nbsp;<small><strong>"+i+"</strong></small>&nbsp;&nbsp;&nbsp;");
			}
		}
 
}*/

function jumptopage(temp) {
 var numAnswers=qa[currentQuestion].answers.length
  //figure out the users's answer
 for(var jj=0;jj<numAnswers;++jj) {
  if(document.answerForm.elements[jj].checked) {
		userchoice=jj;
  } //if
 } //for	
	
var thispage = temp;
 writeAnswer(); 
 useranswers=readCookierpj("userAnswers");
location="quiztest.html?qnum=" + (thispage);
 	
}
 



function writeAnswer() {
  updateCookie(userchoice);
}


function updateCookie(userchoice) {
 var newuseranswers="";
  for (j=0; j<quizLength; j++) {
   if (j != currentQuestion) {
	 //debug alert("character " + j + " useranswers = " + useranswers.charAt(j));
	 newuseranswers += useranswers.charAt(j);
   } else {
	 //debug alert(" blah blah character " + j + " useranswers = " + userchoice);
	 newuseranswers += userchoice;
   }
  }  //for
  createCookierpj('userAnswers',newuseranswers,7);
}


function getUrlVar() {
  var qs = location.search.substring(1);
  var nv = qs.split('&');
   for(i = 0; i < nv.length; i++)
  {
    eq = nv[i].indexOf('=');
    url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
  }

		//var whynumber = parseInt(url['whynum']);	
}


function graphit(thepercent){
  barlength=100
  document.write('<img src="./images/poll.gif" width="'+((thepercent/100)*barlength)+'" height="15">')
}



