//----------------------------------------------------------  Check Current Issue
function checkans() {

question=document.form.question.value  //no. of question 
choose=document.form.choose.value  // no. of choose of each question 

ansstring=""
ansstringarray=new Array(question)
err=""
      for (q=1;q<=question; q++){
	    checkeachchoose(q)
        ansstring=""
        
        // Handle "True/False" questions
        if(document.getElementById("qtype").getAttribute("value") == "TF"){
          current_question = document.getElementById("q" + q);
          options = current_question.firstChild.childNodes;
          numOfOptions = options.length;
          
          // Skip first child in array, which is the question and not the options
          for (x = 1; x < numOfOptions; x++) {
            trueBox = document.getElementById("q." + q + "." + x + ".T");
            falseBox = document.getElementById("q." + q + "." + x + ".F");
            if (trueBox.checked == true){
              ansstring += "T, "
            }
            else if(falseBox.checked == true) {
              ansstring += "F, "
            }
          }
          
          if(ansstring.length == 3 * (numOfOptions - 1)){
            answerField = document.getElementsByName("q" + q);
            
            // Remove the comma and space at the end of the string
            ansstring = ansstring.substr(0, ansstring.length - 2);
            answerField[0].setAttribute("value", ansstring);
          }
          else {
            err=err+"Question "+q+"\n";
          }
        }
        
        // Handle essay questions
        else if(document.getElementById("qtype").getAttribute("value") == "ES"){          
          dummystring="document.form.q"+q+".value";
            
          // check if textarea is empty
          if (eval(dummystring)=="") {
            err=err+"Question "+q+"\n";
          }
        }
        
        // Handle multiselect and single best questions
        else {
          answered = 0;
          for (i=0;i<=qc-1; i++) {
            dummystring="document.form.q"+q+"["+i+"]";
            if (eval(dummystring+".checked")==true) {
              ansstring=ansstring+eval(dummystring+".value")
              answered = 1;
            }
          }
          
          if (answered) {
            ansstringarray[q-1]=ansstring;
          }
          else {
            err=err+"Question "+q+"\n";
          }
        }
	  }
	  
      if (err!="") {alert("Please answer following question : \n\n"+err);return false}else{return true}
}


//---------------------------------------- popup large image
function popphoto(fname) {
fname=fname+""
fno=fname.lastIndexOf(".")
newpath=fname.substr(0,fno)+"_big"+fname.substr(fno)

popimage=window.open("","popwindow","width=650,height=510")
popimage.document.open()
popimage.document.write("<script language='Javascript'>\n function rephoto() { \n window.resizeTo(document.photo.width+50,document.photo.height+60) \n  window.focus()  \n } \n <\/script> \n ")
popimage.document.write("<html><body  link='#000000' vlink='#000000' alink='#000000' onload='rephoto()'><center><a href='javascript:;' onclick='window.close()'><img src='"+newpath+"' border='3' name='photo' id='photo'></a></center></body></html>")
popimage.document.close()
popimage.window.focus()
}


//----------------------
function checkeachchoose(q) {
choosearray=choose.split(",")
qc=choosearray[q-1]
return qc
}

//-----------------------
function splitans() {
correctans=ans.split("/")
}
