sfiles=new Array('1.txt/120','2.txt/120','3.txt/120')

availableSfiles=sfiles.length
maxGoes=3
theseGoes=0



ok=null
function check(obj){
message=""
ename=obj.name.value
if (ename=="") message+="Please enter your name \n\r";

em=obj.email.value
if (em=="") message+="Please enter your email address \n\r";

estaddr=obj.staddress.value
if (estaddr=="") message+="Please enter your street address \n\r";

etown=obj.post_town.value
if (etown=="") message+="Please enter your postal town \n\r";

epostcode=obj.post_code.value
if (epostcode=="") message+="Please enter your postal code \n\r";

ephone=obj.phone.value
if (ephone=="") message+="Please enter your phone number \n\r";

if (message!="") {
     alert("To proceed further : \n\r\n\r"+message)
ok=false
     return false
     }
     //alert("now here")
     
  at=(em.indexOf("@")!=-1)
  dot=(em.indexOf(".")!=-1) 
  ok=(at && dot)
  if(!ok){
  alert(em+"\n\rThis email address doesn't look right - please check")
  
  return false
  } 
     ok=(confirm("You have entered\n\r\n\rName : "+ename+"\n\rEmail : "+em
+"\n\rAddress : "+estaddr
+"\n\rTown : "+etown
+"\n\rPost Code : "+epostcode
+"\n\rPhone number : "+ephone
+"\n\r\n\rIs this data correct?"))
  
     if (ok==false) {
     alert("Please enter the correct information")
return false
     }
//else {return true}
}

winprops="width=900,height=600,scrollbars=yes,resizable=yes"

function testWin(){
winTest=open('test.htm','',winprops)
}


function testGo(obj) {
check(obj)
if(!ok) return false
//alert(ok)
if(theseGoes>=maxGoes) {
          alert("you have used all the test files permitted")
          return            
          }

// get random sound file
else{
theseGoes+=1
//for (j=1;j<=maxGoes;j++){
             availableSfiles-=1
             r=(Math.random()*availableSfiles)+0.5  //random no. generator rounding to nearest integer
             x=Math.round(r)-1  //reduce by 1
//alert ("r is "+r+" : x is "+x)
             testEntry=sfiles[x]   
             slashPoint= testEntry.indexOf("/")                          // find slash division between filename and allowed time
             testFile=testEntry.substring(0,slashPoint)             //dissect out file name
             testTime=testEntry.substring(slashPoint+1)          // dissect out allowed time for test
alert(x+"  "+testEntry+" "+testFile+" "+testTime)
             sfiles.splice(x,1)  // take out that element from the array -
             sfiles.push(testEntry)   // and reinsert it at the end of the array so it cannot be accessed more than once
document.client.sfile.value=testFile
document.client.stime.value=testTime

             testWin()             
}
}

