// ************************************************
// This file has been written by David Domingues
// you are free to use it and change it as you need
// but i will ask you to keep this header on the file
// and never remove it.
// comMarkSystem downloaded at http://www.webrickco.com
// webrickco@gmail.com
// ************************************************
// JavaScript Document
function calculateInterval(rest, itemnbr)
{
   step = 1 / (itemnbr-1);
   for (j=0;j<itemnbr;j++)
   {
      if (rest >= step * j && rest <= step * (j+1))
      {
         if ((rest - step * j) > (step*(j+1) - rest))
         {
            return (j + 1)
         }
         else {
            return j
         }
      }
   }
}
function createMarks(MARK,PARAM,note)
{
   if (note.substr(0,note.indexOf("%")) > 0) {
      wnote1=note.substr(0,note.length-1) + "/" + "100";
   } else {
      wnote1 = note;
   }
   wnote = wnote1.substr(0,wnote1.indexOf("/")); 
   wref = parseInt(wnote1.substr(wnote1.indexOf("/")+1,wnote1.length),10);     
   wpercent = wnote / wref;
   wtotalelement = parseInt(PARAM['basemarks'],10) * MARK.length;
   wtotalfilledelement = wtotalelement * wpercent;

   for (i=1;i<=parseInt(PARAM['basemarks'],10);i++)
   {
      if (i <= parseInt(wpercent * parseInt(PARAM['basemarks'],10))) {
         document.write("<IMG SRC="+MARK[MARK.length - 1]+" alt=\""+note+"\" title=\""+note+"\">");
      }
      if (i == parseInt(wpercent * parseInt(PARAM['basemarks'],10)) + 1) {
         rest = wpercent * parseInt(PARAM['basemarks'],10) - parseInt(wpercent * parseInt(PARAM['basemarks'],10));
         result = calculateInterval(rest, MARK.length);
         document.write("<IMG SRC="+MARK[result]+" alt=\""+note+"\">");
      }
      if (i > parseInt(wpercent * parseInt(PARAM['basemarks'],10)) + 1) {
         document.write("<IMG SRC="+MARK[0]+" alt=\""+note+"\">");
      }
   }
   document.write("&nbsp;");
   document.write(note);

} 