
function mySort(item1, item2)
{
  if (item1 >  item2) return  1;
  if (item1 <  item2) return -1;
  if (item1 == item2) return  0;
}	

function write_row (i,row_name,mydata1,mydata2) {

document.write("<div id='" + row_name + "_whole_row'>");

document.write("<div>");
document.write("<span class='question'>");
document.write(i+1, ". ", mydata1);
document.write("</span>");
document.write("</div>");

document.write("<div width='100'>");
document.write("<form>");

document.write("<input id='" + row_name + "_btn' class='short-button' value='show answer' type='button' onclick='toggle_visible(\"" + row_name + "\")' />");

document.write("&#160;<input class='std-button' value='remove entire question' type='button' onclick='remove(\"" + row_name + "\")' />");
                                     
document.write("</form>");
document.write("</div>");

document.write("<div id='" + row_name + "'>");
document.write("<span class='answer'>");
document.write(mydata2);
document.write("</span>");
document.write("</div>");

document.write("<hr />");

document.write("</div>");

}

function hide_answer (row_name) {
  //document.getElementById(row_name).style.visibility="hidden";
  document.getElementById(row_name).style.display="none";  
}

function remove (row_name) {
  div_name = row_name + "_whole_row";
  document.getElementById(div_name).style.display="none";
}

function show_all(nbr_of_questions) {
  for (i=0; i<nbr_of_questions; i++)
   {
   row_name = "row" + i;
   button_name = row_name + "_btn";
   document.getElementById(row_name).style.display="block";
   document.getElementById(row_name).style.visibility="visible"; 
   document.getElementById(button_name).value = "hide answer";
   }
}

function hide_all(nbr_of_questions) {
  for (i=0; i<nbr_of_questions; i++)
  {
  row_name = "row" + i;
  button_name = row_name + "_btn"; 
  document.getElementById(row_name).style.display="none";
  document.getElementById(button_name).value = "show answer";
  }
}

function toggle_visible (row_name) {

   var button_name = row_name + "_btn"; 

   if (document.getElementById(row_name).style.display=="none")
     { document.getElementById(row_name).style.display="block";
       document.getElementById(row_name).style.visibility="visible"; 
       document.getElementById(button_name).value = "hide answer";
     }
   else 
     { document.getElementById(row_name).style.display="none";
       document.getElementById(button_name).value = "show answer";
     }   
}

