home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Spanish 3 / ProOne-MultimediaSpanishIII-WinMac.bin / pc / span3web / verbfr.js < prev    next >
Text File  |  1998-04-19  |  5KB  |  218 lines

  1. var verbForms;            // the verb forms
  2. var instruction;        // the instructions for this exercise
  3. var instrRef;            // instruction reference number
  4. var    currProblem;        // which verb form are we on?
  5.  
  6. function SetWords( wArray, startPos )
  7. {
  8.     var i;
  9.  
  10.     for (i=2; i<SetWords.arguments.length; i++)
  11.     {
  12.         wArray[startPos + i - 2] = SetWords.arguments[i];
  13.     }
  14. }
  15.  
  16. function SetNumeric( nArray, n )
  17. {
  18.     var i;
  19.     
  20.     for (i=0; i < n; i++)
  21.     {
  22.         nArray[i] = i;
  23.     }
  24. }
  25.  
  26. function GetInstrRef( n )
  27. {
  28.     var i;
  29.     
  30.     for (i = instrRef.length-1; i >=0; i--)
  31.     {
  32.         if (n >= instrRef[i])
  33.         {
  34.             return i;
  35.         }
  36.     }
  37.     return 0;
  38. }
  39.  
  40. function Shuffle( nArray, startAt, n )
  41. {
  42.     var i, j, swap;
  43.     
  44.     for (i = startAt; i < startAt + n; i++)
  45.     {
  46.         j = startAt + Math.round(Math.random() * (n - 1));
  47.         swap = nArray[i];
  48.         nArray[i] = nArray[j];
  49.         nArray[j] = swap;
  50.     }
  51. }
  52.  
  53. /*******************************************************************************
  54.     Split words from string str into a word array (wordArr).
  55.     Words are delimited by the delim argument.
  56.     
  57.     Returns the number of words that were split out.
  58.  
  59.     Note: this function is here because not all browsers have Javascript's
  60.     "split" function enabled.
  61. *******************************************************************************/
  62. function SplitWords( str, delim, wordArr )    // for browsers not having a "split" function
  63. {
  64.     var fromPos, toPos, n;
  65.     
  66.     n = 0;
  67.     fromPos = 0;
  68.     toPos = str.indexOf( delim, 0 );
  69.     while (toPos >= 0)
  70.     {
  71.         wordArr[n++] = str.substring( fromPos, toPos );
  72.         fromPos = toPos + 1;
  73.         while (str.charAt( fromPos ) == ' ')
  74.         {
  75.             fromPos++;
  76.         }
  77.         toPos = str.indexOf( delim, fromPos );
  78.     }
  79.     /* take last word on line and store it */
  80.     wordArr[n++] = str.substring( fromPos, str.length );
  81.     return n;
  82. }
  83.  
  84. function LoadSound(name)
  85. {
  86.     var     d;
  87.     
  88.     d = top.soundFrame.document;
  89.     d.open();
  90.     d.writeln("<html><head></head><body bgcolor=\"#ffffff\">");
  91.     d.writeln("<center>");
  92.     if (navigator.appVersion.indexOf("Mac") == -1)
  93.     {
  94.         d.writeln("<embed src=\"" + name + "\" autostart=\"true\" ");
  95.         d.writeln(" width=\"144\" height=\"15\" controls=\"smallconsole\">");
  96.     }
  97.     else
  98.     {
  99.         d.writeln("<embed src=\"" + name + "\" width=\"144\" height=\"24\" autoplay=\"true\"",
  100.             " autostart=\"true\" controls=\"smallconsole\">");
  101.     }
  102.     d.writeln("</center>");
  103.     d.writeln("</body></html>");
  104.     d.close();
  105. }
  106.  
  107.  
  108. function PlayVerb( n )
  109. {
  110.     var dest;
  111.  
  112.     dest = waveOffset + n;
  113.     dest = soundDir + dest + ".wav";
  114.     LoadSound( dest );
  115. }
  116.  
  117. function WriteProblem( n )
  118. {
  119.     var    i;
  120.     var    doc;
  121.     var verb;
  122.     var pronoun;
  123.     
  124.     pronoun = new Array( 6 );
  125.     pronoun[0] = "yo";
  126.     pronoun[2] = "tú";
  127.     pronoun[4] = "él<br>ella<br>usted";
  128.     pronoun[1] = "nosotros";
  129.     pronoun[3] = "";
  130.     pronoun[5] = "ellos<br>ellas<br>ustedes";
  131.  
  132.     doc = top.problemFrame.document;
  133.     
  134.     doc.open();
  135.  
  136.     doc.writeln("<html><head></head><body bgcolor='#ffffff'>");
  137.     doc.writeln("<div align='center'><img src='pics/barflgs.gif' width='514' height='16'><p>");
  138.     doc.writeln(instruction[GetInstrRef(n)]);
  139.  
  140.     doc.writeln("<hr>");
  141.     
  142.     doc.writeln("<table width='70%'>");
  143.     verb = new Array( 7 );
  144.     nChoices = SplitWords( verbForms[n], "|", verb );
  145.     doc.writeln("<tr><td colspan='4' align='center'>" + verb[6] + "</td></tr>");
  146.     
  147.     doc.writeln("<tr><td align='right'>" + pronoun[0] + "</td><td>" + verb[0] + "</td>");
  148.     doc.writeln("<td align='right'>" + pronoun[1] + "</td><td>" + verb[1] + "</td></tr>");
  149.  
  150.     doc.writeln("<tr><td align='right'>" + pronoun[2] + "</td><td>" + verb[2] + "</td>");
  151.     doc.writeln("<td><br></td><td><br></tr>");
  152.  
  153.     doc.writeln("<tr><td align='right'>" + pronoun[4] + "</td><td>" + verb[4] + "</td>");
  154.     doc.writeln("<td align='right'>" + pronoun[5] + "</td><td>" + verb[5] + "</td></tr>");
  155.  
  156.     doc.writeln("</table><p>");
  157.     doc.write("<a href='javascript:top.PlayVerb(top.currProblem)'>");
  158.     doc.writeln("<img src=\"pics/speaker.gif\" border=0 alt=\"[Speaker]\"></a>");
  159.     doc.writeln("</div>");
  160.  
  161.     if (currProblem == 0)
  162.     {
  163.         top.naviFrame.location.href = (maxProblem == 1) ? "vbutnX.htm" : "vverbN.htm";
  164.     }
  165.     else if (currProblem != maxProblem-1)
  166.     {
  167.         top.naviFrame.location.href = "vverbBN.htm";
  168.     }
  169.     else
  170.     {
  171.         top.naviFrame.location.href = "vverbB.htm";
  172.     }
  173.     doc.writeln("</body></html>");
  174.     doc.close();
  175. }
  176.  
  177. function GoNext()
  178. {
  179.     if (currProblem < maxProblem-1)
  180.     {
  181.         nTries = 0;
  182.         currProblem++;
  183.         WriteProblem( currProblem );
  184.     }
  185.     else
  186.     {
  187.         window.status = "You are already on the last set."
  188.     }
  189. }
  190.  
  191. function GoBack()
  192. {
  193.     if (currProblem != 0)
  194.     {
  195.         currProblem--;
  196.         WriteProblem( currProblem );
  197.     }
  198.     else
  199.     {
  200.         window.status = "You are already on the first set."
  201.     }
  202. }
  203.  
  204. function GoIndex()
  205. {
  206.     top.location.href = lessonURL + top.location.search;
  207. }
  208.  
  209.  
  210. function Setup()
  211. {
  212.     currProblem = 0;
  213.     verbForms = new Array( maxProblem );
  214.  
  215.     Initialize();
  216.     WriteProblem(0);
  217. }
  218.