/* In order, these are the characters that will be used as labels for each possible
 * answer for a question, each separated by a |. These may include HTML tags to
 * apply different formatting for choice labels if desired.
 * The default configuration allows for 26 different possible answers for each question.
 */
labels = "a.|b.|c.|d.|e.|f.|g.|h.|i.|j.|k.|l.|m.|n.|o.|p.|q.|r.|s.|t.|u.|v.|w.|x.|y.|z.";

/* NO MODIFICATIONS BELOW HERE */
questions = new Array();
questionnum = -1;
possibleanswers = new Array();
answers = new Array();

function Question(question){
	questionnum++;
	questions[questionnum] = question;
	possibleanswers[questionnum] = new Array();
}

function CorrectChoice(choice){
	WrongChoice(choice);
	answers[questionnum] = choice;
}

function WrongChoice(choice){
	var choicenumber = possibleanswers[questionnum].length;
	possibleanswers[questionnum][choicenumber] = choice;
}

function Asplit(str,seperator){
var arraya = new Array();
var first = 0;

if(str.charAt(str.length) != seperator)
  {
  str += seperator;
  }

for(var i=0;i<str.length;i++)
  {
  if(str.charAt(i) == seperator)
    {
    second = i;
    arraya[arraya.length] = str.substring(first,second);
    first = second;
    }
  }

for(var i=0;i<arraya.length;i++)
  {
  if(arraya[i].charAt(0) == seperator)
    {
    arraya[i] = arraya[i].substring(1,arraya[i].length);
    }
  }

return arraya;
}

function check(){
radios = new Array();
results = new Array();
correct = 0;
total = questions.length;
wrong = new Array();
var thisCorrect;

for(i=0;i<total;i++)
  {
  radios[i] = document.theform.elements["num"+(i+1)];
  thisCorrect = false;

  for(d=0;d<radios[i].length;d++)
    {
    if(radios[i][d].checked == 1)
      {
      results[i] = radios[i][d].value;
      if(results[i] == answers[i])
        {
        correct++;
        thisCorrect = true;
        }
      }
    }
  if(thisCorrect == false)
    {
    wrong[wrong.length] = i;
    }
  }

percent = Math.round(correct / total * 100).toString();
str = "<HTML><HEAD><TITLE>Sonuçlar</TITLE></HEAD><BODY>";

if(percent == 100)
  {
  str += "Tebrikler! Tam puan aldınız!";
  }
else
  {
  str += "Başarınız %"+percent+"olmuştur. bir daha ki sefere biraz daha gayret lütfen. ";

  if(confirm("% "+percent+" başarılı oldunuz. Hangi sorularda hata yaptığınızı görmek istermisiniz?"))
    {
    str += "Aşağıdaki soruları yanlış cevapladınız:<BR><BR>";

    for(i=0;i<wrong.length;i++)
      {
      str += "<B>Soru no "+(wrong[i]+1)+": "+questions[wrong[i]]+"</B><BR>Doğru cevap <B>"+answers[wrong[i]]+"</B><BR>Sizin tercihiniz ise <B>"+results[wrong[i]]+" seçeneği olmuştu.</B><BR><BR>";
      }
    }
  }

str += "<FORM ACTION=\"\" onSubmit=\"return false;\"><CENTER><INPUT TYPE=button VALUE='Pencereyi Kapat' onClick=\"self.close();\"></CENTER></FORM></BODY></HTML>";
win = window.open("","win", "height=300,width=620,scrollbars=yes,resizable=yes");
win.document.write(str);
}
