
digits = new Array()
for (i = 0; i <= 20; i++) {
 var inm = "img/dig/"+i+".png";
 digits[i] = new Image(37,24);
 digits[i].src = inm;
}

 op = new Image(22,12)
 op.src = "img/dig/op2.gif";

var iCount = 0;
var iSong = 0;
var iNumber = 0;
var prev = -1;
var allsong = new Array;
var result = 0;

function switchMelody(res){
  if (iSong < 8) {

    var send = res;
    if ((res > -1) && (iSong == 0)) return;
    if ((send == -1) && (iSong > 0)) return;
    iCount = 0;
    if (iSong == 0) setInterval("count()",1000);
    if (res == (prev+1)) result = result+1;
    iSong = iSong+1;




     var rn = randomNum(49)+1;
    allsong[iSong] = rn;
    if (iSong > 1) {
      for (i = 1; i < iSong; i++) {
        if (allsong[iSong] == allsong[i]) {
          rn = randomNum(49)+1;
          allsong[iSong] = rn;
          i=1 }
        }
    }


    var SoundFile = "img/mid/lev1/"+(rn)+".mid";
    var fnx = new Array()    
    fnx[0] =  randomNum(149)+1;
    while (fnx[0] == rn)  fnx[0] = randomNum(149)+1;
    fnx[1] =  randomNum(149)+1;
    while (fnx[1] == rn)  fnx[1]= randomNum(149)+1;
	while (fnx[1] == fnx[0])  fnx[1]= randomNum(149)+1;
    fnx[2] =  randomNum(149)+1;
    while (fnx[2] == rn)  fnx[2]= randomNum(149)+1;
	while (fnx[2] == fnx[0])  fnx[2]= randomNum(149)+1;
    while (fnx[2] == fnx[1])  fnx[2]= randomNum(149)+1;
	fnx[3] =  randomNum(149)+1;
    while (fnx[3] == rn)  fnx[3]= randomNum(149)+1;
	while (fnx[3] == fnx[0])  fnx[3]= randomNum(149)+1;
    while (fnx[3] == fnx[1])  fnx[3]= randomNum(149)+1;
	while (fnx[3] == fnx[2])  fnx[3]= randomNum(149)+1;
	fnx[4] =  randomNum(149)+1;
    while (fnx[4] == rn)  fnx[3]= randomNum(149)+1;
	while (fnx[4] == fnx[0])  fnx[4]= randomNum(149)+1;
    while (fnx[4] == fnx[1])  fnx[4]= randomNum(149)+1;
	while (fnx[4] == fnx[2])  fnx[4]= randomNum(149)+1;
	while (fnx[4] == fnx[3])  fnx[4]= randomNum(149)+1;
    
    var ln = randomNum(5)-1;
    while (prev == ln) ln = randomNum(5)-1;
    fnx[ln] = rn;
    prev = ln;
    document.getElementById("s1").innerHTML = (title[fnx[0]]);
    document.getElementById("s2").innerHTML = (title[fnx[1]]);
    document.getElementById("s3").innerHTML = (title[fnx[2]]);
    document.getElementById("s4").innerHTML = (title[fnx[3]]);
    document.getElementById("s5").innerHTML = (title[fnx[4]]); 
    
    if (iSong == 1) document.images['op1'].src = op.src;
    if (iSong == 2) document.images['op2'].src = op.src;
    if (iSong == 3) document.images['op3'].src = op.src;
    if (iSong == 4) document.images['op4'].src = op.src;
    if (iSong == 5) document.images['op5'].src = op.src;
    if (iSong == 6) document.images['op6'].src = op.src;
    if (iSong == 7) document.images['op7'].src = op.src;
    document.images['cf'].src = digits[15].src;
    document.getElementById("eq").innerHTML = "<img src='img/dig/eq.gif' border=0 alt='karaoke equalizer'>";
    document.all.changetrack.src = (SoundFile);
}
else {
 document.getElementById("eq").innerHTML = "<img src='img/dig/equalizer.gif' border=0 alt='karaoke equalizer'>";
 document.images['cf'].src = digits[0].src;
 document.all.changetrack.src = "";
 if (result == 7) {
   document.images['fin'].src = "img/dig/job.gif";
   document.getElementById("wyn").innerHTML = "<span style='font-size:10pt;'><font color='white'><b><i>You guess all 7 songs.</i></b></font></span>"; 
   document.images['level'].src = "img/dig/lev20.gif"; }
 else {
   document.images['fin'].src = "img/dig/result.gif";
 document.getElementById("wyn").innerHTML = "<span style='font-size:10pt;'><font color='white'><b><i>You guess " + result + " of 7 songs.</i></b></font></span>"; }
}


}


function randomNum(max) {
  var rNum=NaN
  while (isNaN(rNum)) {
    rNum=Math.floor(Math.random()*(max))
  }
  return rNum+1
}

function count() {
 if (iSong < 8) {
 iCount=iCount+1;
 var curr = 15 - iCount;
 
if (iCount < 16) {
 document.images['cf'].src = (digits[curr]).src; }

 
 if (iCount >= 16) {
   document.all.changetrack.src = "";
   document.images['cf'].src = digits[0].src;
   document.getElementById("eq").innerHTML = "<img src='img/dig/equalizer.gif' border=0 alt='karaoke equalizer'>"; 
}
 if (iCount >= 18) {  
  iCount = 0;
  document.images['cf'].src = digits[0].src;
  switchMelody(8);
 }  
}
}

function SubmitForm() {
 document.forms[0].posit.value=7; 
 document.forms[0].submit();
}
