﻿// Analysis Quiz Javascript
// copyright 20th December 2004 - 13th May 2005, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration

function displayResult(cor) {
document.write('<div style="font-size:14px;"><b>You have completed the quiz.<\/b><\/div><blockquote><span style="font-size:16px;"> <br \/> <br \/> <br \/> <br \/><\/span><\/blockquote><div><a href="'+analPage+'?cor='+cor+'">Click Here for Your Result</a><\/div>');
}

var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
   var pos = parms[i].indexOf('=');
     if (pos > 0) {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos+1);
      qsParm[key] = val;
      }
   }
}
qsParm['questnum'] = 0;
qsParm['cor'] = 0;
qs();
var questnum = qsParm['questnum'];
var cor = qsParm['cor'];cor=cor%475;

function checkAnswer(e,b,g){
var a = -1; var x = Math.floor(g/b); // x = bdca
for (var i=0; i<e.c.length; i++) {if (e.c[i].checked) {a = i;}}
if (a == -1) {
alert("You must select an answer");
return false;
}
var b = new Array();
b[1] = Math.floor(x/1000); x -= b[1]*1000;
b[3] = Math.floor(x/100); x -= b[3]*100;
b[2] = Math.floor(x/10); b[0] = x - b[2]*10;
cor += b[a];
var www = self.location.href.lastIndexOf('?');
var thispage = self.location.href;
if (www != -1) thispage = self.location.href.substr(0,www);
questnum++;
var p = Math.floor((Math.random() * 8) + 2);
var m = (p * 475) +cor;
top.location = thispage + '?questnum='+ questnum +'&cor='+m;
return false;
}

function result(cor) {
var lo = 0, hi = 0;
for (var i=0;i < quiz.length;i++) {
var f = quiz[i].split('~');
lo += parseInt(f[7]); hi += parseInt(f[8]);
}
return Math.round((cor - lo) * 100 / (hi - lo));
}

var quiz = new Array(); var r = 0;
var analPage = 'quizanalysis.html';
quiz[r++] =('268668~86~My age is?~Less than 20.~20-29.~30-39~40-49~1~4');
quiz[r++] =('77882~59~The first day of my last period was?~0-2 weeks ago.~2-4 weeks ago.~4-5 weeks ago.~5-6 weeks ago.~0~3');
quiz[r++] =('26809~20~I think I may have gotten pregnant:~during my period.~within 1 week of my period.~1-2 weeks after the first day of my period.~within 2-3 weeks after the first day of my period.~0~4');
quiz[r++] =('19763~89~My periods are:~Regular.~Irregular.~~~0~2');
quiz[r++] =('282466~91~For birth control I use:~Nothing.~Withdrawal (pull out).~The Pill or DepoProvera (the shot) or tubal ligation.~The Pill but sometimes I miss a pill.~0~4');
quiz[r++] =('11107~50~I have nausea.~Yes~No~~~0~2');
quiz[r++] =('16652~50~I have been vomiting.~Yes~No~~~0~3');
quiz[r++] =('4223~38~I have breast tenderness.~Yes~No~~~0~1');
quiz[r++] =('7557~68~I need to urinate more often.~Yes~No~~~0~1');
quiz[r++] =('88664~42~I have gained weight recently.~Yes~No~~~1~2');

var tblsz = quiz.length;
document.write('<table align="center" cellpadding="3" width="350" border="2" bgcolor="#FDF1FA"><tr>');
if (questnum < quiz.length) {
var f = quiz[questnum].split('~');
document.write('<td align="left"><form name="myForm"><div style="font-size:16px;">Question: '+f[2]+'</div><blockquote><span style="font-size:14px;">\n');
document.write('<input type="radio" name="c" value="0" /> '+f[3]+'<br />\n');
document.write('<input type="radio" name="c" value="1" /> '+f[4]+'<br />\n');
if (f[5] != '') document.write('<input type="radio" name="c" value="2" /> '+f[5]+'<br />\n');
if (f[6] != '') document.write('<input type="radio" name="c" value="3" /> '+f[6]+'<\/span><\/blockquote>\n');
document.write('<div align="right"><input type="button" value="Next Question" onclick="checkAnswer(myForm,'+f[1]+','+f[0]+');return false;" /><\/div><\/form>\n');
} else {
document.write('<td align="center">\n');
document.write('<form name="myForm">');
displayResult(result(cor));
document.write('<\/form>\n');}
document.write('<\/td><\/tr><\/table>\n');

