var key = 1;
var time = 6000;
var contents = "";
var checkit = " - ";
var shp=new Array("C","C#","D","D#","E","F","F#","G","G#","A","A#","B");
var flt=new Array("C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","Cb");
var adj = new Array("nv","nv",2,4,5,7,9,11,"nv",14,"nv",17,"nv",21); //nv is no value
var adjminor = new Array("nv","nv",2,3,5,7,8,10,"nv",14,"nv",17,"nv",20); //nv is no value
function doit(i){
var index = document.keys.time.selectedIndex;
time = document.keys.time[index].value;
time = time.valueOf();
var keytype = document.keys.majmin.selectedIndex;
keyindex = document.keys.majmin[keytype].value;
if (i == 1){
for (k=0;k < 12;k++){
  if (document.notes.elements[k].checked){
     checkit = document.notes.elements[k].value;
  }
}
if (key == -1){
reply = o+" in the key of "+shp[s]+" "+keyindex+" is <b>"+shp[ans]+"</b>. You chose <b>"+checkit+"</b>";
}else{
reply = o+" in the key of "+flt[s]+" "+keyindex+" is <b>"+flt[ans]+"</b>. You chose <b>"+checkit+"</b>";
}
contents = "<div align='center' style='font-family:verdana;font-size:13px;padding-top:30px;'>";
contents += reply+"<br /><br />Click GO to try again</div>";
document.getElementById('lesson1quiz').innerHTML = contents;
checkit = " - ";
//r = eval("newwin.document");
//r.write("<body bgcolor=#dddddd><br><br>");
//r.write("<div align=center style='font-family:verdana;font-size:13px;'>");
//r.write(reply+"<br /><br />");
//r.write("<form><input type=button value=Close ");
//r.write("onClick='javascript:window.close()'></form></div>");
//r.close();
return;
}
s = Math.round((Math.random()*11)).valueOf(); //value used to select a scale
o = Math.round((Math.random()*13)).valueOf(); //value used to select a member of the scale
if (o < 2){o=2;}
if (o == 8){o=7;}
if (o == 10){o=9;}
if (o == 12){o=13;}
if (keyindex == "major"){
	var d = adj[o];
}else{
	var d = adjminor[o];
}
if (key == 1){
  if ((s==0)||(s==3)||(s==5)||(s==8)||(s==10)){ //for sharp keys: adjust if s points to  c, d#, f, g#, a#
    s++;
  }
  ans = s+d;
  if ((ans > 11)&&(ans < 24)){ans -= 12;}
  if (ans > 23){ans -= 24;}
}else{
   if ((s==2)||(s==4)||(s==7)||(s==9)){ //for flat keys: adjust if s points to d, e, g, a
    s--;
  }
  ans = s+d;
  if ((ans > 11)&&(ans < 24)){ans -= 12;}
  if (ans > 23){ans -= 24;}
}
//newwin = window.open("","win1","width=375,height=200");
//newwin.document.write("<html><head><title>test</title></head>");
//newwin.document.write("<body bgcolor=#dddddd>");
//w = eval("newwin.document");
//w.write("<form name=notes>");
//w.write("<table align=center width=350><tr><td align=center colspan=12>");
contents = "<form name=notes>";
contents += "<table align='center' width='350'><tr><td align='center' colspan='12'>";
contents += "<br><br><div style='font-family:verdana;font-size:12px;'>";
if (key == 1 && !(keyindex == "minor" && ((s == 2) || (s == 7) ))){
contents += o+" in the key of "+shp[s]+" "+keyindex+" is: </div><br></td></tr>";
contents += "<tr><td><input type=radio name=note value=C><br>C</td>";
contents += "<td><input type=radio name=note value=C#><br>C#</td>";
contents += "<td><input type=radio name=note value=D><br>D</td>";
contents += "<td><input type=radio name=note value=D#><br>D#</td>";
contents += "<td><input type=radio name=note value=E><br>E</td>";
contents += "<td><input type=radio name=note value=F><br>F</td>";
contents += "<td><input type=radio name=note value=F#><br>F#</td>";
contents += "<td><input type=radio name=note value=G><br>G</td>";
contents += "<td><input type=radio name=note value=G#><br>G#</td>";
contents += "<td><input type=radio name=note value=A><br>A</td>";
contents += "<td><input type=radio name=note value=A#><br>A#</td>";
contents += "<td><input type=radio name=note value=B><br>B</td>";
}else{
contents += o+" in the key of "+flt[s]+" "+keyindex+" is: </div><br></td></tr>";
contents += "<tr><td><input type=radio name=note value=C><br>C</td>";
contents += "<td><input type=radio name=note value=Db><br>Db</td>";
contents += "<td><input type=radio name=note value=D><br>D</td>";
contents += "<td><input type=radio name=note value=Eb><br>Eb</td>";
contents += "<td><input type=radio name=note value=E><br>E</td>";
contents += "<td><input type=radio name=note value=F><br>F</td>";
contents += "<td><input type=radio name=note value=Gb><br>Gb</td>";
contents += "<td><input type=radio name=note value=G><br>G</td>";
contents += "<td><input type=radio name=note value=Ab><br>Ab</td>";
contents += "<td><input type=radio name=note value=A><br>A</td>";
contents += "<td><input type=radio name=note value=Bb><br>Bb</td>";
contents += "<td><input type=radio name=note value=Cb><br>Cb</td>";
}
contents += "</tr><tr><td align=center colspan=12><br>";
contents += "<div style='font-family:verdana;font-size:11px'>";
contents += "Answer will arrive in "+time/1000+" seconds. Please wait.</div></td>";
contents += "</tr></table>";
contents += "<br></form>";
document.getElementById('lesson1quiz').innerHTML = contents;
//w.write("</body></html>");
//w.close();
key = key*-1; //key value alternates each time go is pushed. 1 = sharps key -1 - flats key
start_it = window.setTimeout('doit(1)',time);
}
