// Fig. 26.XX : tipInformation.wmls
// result of transformation

extern function start()
{

   // each tip's info
   var allTipInfo1, allTipInfo2, allTipInfo3, 
       allTipInfo4, allTipInfo5, allTipInfo6, 
       allTipInfo7; 
   var oneTipInfo;  // one tip
   var imageName;   // name of image
        
            
oneTipInfo = "GPP"  + 
   "|" + "Good Programming Practices call the student&amp;
      apos;s attention to techniques that help produce 
         better programs." + "|" + "goodProgramming";

allTipInfo1 = oneTipInfo;
            
oneTipInfo = "CPE"  + 
   "|" + "Students learning a language tend to make certain 
      kinds of errors frequently. Focusing on these Common 
         Programming Errors helps students avoid making the 
	    same errors." + "|" + "programmingError";

allTipInfo2 = oneTipInfo;
            
oneTipInfo = "LAF"  + 
   "|" + "We provide Look-and-Feel Observations to highlight 
      graphical user interface conventions. These observations 
         help students design their own graphical user 
	    interfaces to conform with industry norms." + 
	       "|" + "lookAndFeel";

allTipInfo3 = oneTipInfo;
            
oneTipInfo = "PERF"  + 
   "|" + "Performance Tips highlight opportunities for 
      improving program performance." +
         "|" + "perf";

allTipInfo4 = oneTipInfo;
            
oneTipInfo = "PORT"  + 
   "|" + "Organizations that develop software must often 
      produce versions customized to a variety of computers 
        and operating systems. These tips offer suggestions to 
	   make your applications more portable." +
              "|" + "portability";

allTipInfo5 = oneTipInfo;
            
oneTipInfo = "SET"  + 
   "|" + "The Software Engineering Observations highlight 
      techniques, architectural issues and design issues, 
         etc. that affect the architecture and construction 
	    of software systems, especially large-scale 
	       systems." + "|" + "softwareEngineering";

allTipInfo6 = oneTipInfo;
            
oneTipInfo = "TAD"  + 
   "|" + "Most of these tips tend to be observations about 
      capabilities and features that prevent bugs from getting 
         into programs in the first place." +
            "|" + "testingDebugging";

allTipInfo7 = oneTipInfo;
              

      // generate a random number
      var randomNum = Float.floor( 1 + 
         Lang.random( 6 ) );
      var correctTip;
      var tipName;
      var tipDescription;
      var tipTemp;

      // get the correct tip's info
      if ( randomNum == 1 ) {
         correctTip = allTipInfo1;
         allTipInfo1 = "$";
      }
      else if ( randomNum == 2 ) {
         correctTip = allTipInfo2;
         allTipInfo2 = "$";
      }
      else if ( randomNum == 3 ) {
         correctTip = allTipInfo3;
         allTipInfo3 = "$";
      }
      else if ( randomNum == 4 ) {
         correctTip = allTipInfo4;
         allTipInfo4 = "$";
      }
      else if ( randomNum == 5 ) {
         correctTip = allTipInfo5;
         allTipInfo5 = "$";
      }
      else if ( randomNum == 6 ) {
         correctTip = allTipInfo6;
         allTipInfo5 = "$";
      }
      else if ( randomNum == 7 ) {
         correctTip = allTipInfo7;
         allTipInfo7 = "$";
      }

      // get correct tip's name
      tipName = String.elementAt( 
         correctTip, 0, "|" );

      // remove it from the sting
      tipTemp = String.removeAt( 
         correctTip, 0, "|" );

      // get correct tip's description
      tipDescription = String.elementAt( 
         tipTemp, 0, "|" );

      // remove it from the string
      tipTemp = String.removeAt( 
         correctTip, 0, "|" );

      // set the correct tip's image name
      imageName = "WAP/images/" + 
         String.elementAt( tipTemp, 1, "|" ) + 
            ".wbmp";     

      // set all variables as browser variables
      WMLBrowser.setVar( "name", tipName );
      WMLBrowser.setVar( 
         "description", tipDescription );
      WMLBrowser.setVar( "image", imageName );

      var counter = 1; // used in the while loop

      // the number generated here will be the 
      // position of the correct option
      var rightAnswer = Float.floor( 1 +
         Lang.random( 4 ) );

      var counter2 = 0;
      var position;

      // generate a random number
      var randomTipNum; 
      var selectTips;
      var random1;
      var random2;
      var random3;
      var used0 = false, used1 = false, 
         used2 = false, used3 = false, 
         used4 = false, used5 = false, 
         used6 = false, used7 = false;

      // create a string of the answers
      while ( position <= 4 ){
         randomTipNum = 
            Float.floor( 1 + Lang.random( 7 ) );
         
         if ( position == rightAnswer &&
            used0 == false ) {
            used0 = true;
              selectTips = 
                 selectTips + tipName + "|";
         }
         if ( 1 == randomTipNum && 
            used1 == false && 
                              allTipInfo1 != "$" ) {
            used1 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo1, 0, "|" ) + "|";
         }
         else if ( 2 == randomTipNum && 
            used2 == false && 
                              allTipInfo2 != "$" ) {
            used2 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo2, 0, "|" ) + "|";
         }
         else if ( 3 == randomTipNum && 
            used3 == false && 
                              allTipInfo3 != "$" ) {
            used3 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo3, 0, "|" ) + "|";
         }
         else if ( 4 == randomTipNum && 
            used4 == false && 
                              allTipInfo4 != "$" ) {
            used4 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo4, 0, "|" ) + "|";
         }
         else if ( 5 == randomTipNum && 
            used5 == false && 
                              allTipInfo5 != "$" ) {
            used5 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo5, 0, "|" ) + "|";
         }
         else if ( 6 == randomTipNum && 
            used6 == false && 
                              allTipInfo6 != "$" ) {
            used6 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo6, 0, "|" ) + "|";
         }
         else if ( 7 == randomTipNum && 
            used7 == false && 
                              allTipInfo7 != "$" ) {
            used7 = true;
            selectTips = selectTips +
               String.elementAt( 
                  allTipInfo7, 0, "|" ) + "|";
         }
 
         // increment the counter
         position = 
            String.elements( selectTips, "|" );
      }
      
      var Answer1, Answer2, Answer3, Answer4;

      // split the string to get the three values
      Answer1 = String.elementAt( 
         selectTips, 0, "|" );
      tipTemp = String.removeAt( 
         selectTips, 0, "|" );
      Answer2 = String.elementAt( 
         tipTemp, 0, "|" );
      tipTemp = String.removeAt( 
         tipTemp, 0, "|" );
      Answer3 = String.elementAt( 
         tipTemp, 0, "|" );
      tipTemp = String.removeAt( 
         tipTemp, 0, "|" );
      Answer4 = String.elementAt( 
         tipTemp, 0, "|" );
      
      // set the option attribute values
      var result1 = "wrong", result2 = "wrong",
         result3 = "wrong", result4 = "wrong";

      if ( rightAnswer == 1 )
         result1 = "correct";
      else if ( rightAnswer == 2 )
         result2 = "correct";
      else if ( rightAnswer == 3 )
         result3 = "correct";
      else if ( rightAnswer == 4 )
         result4 = "correct";

      // set answers as browser variables
      WMLBrowser.setVar( 
         "select1", Answer1 );
      WMLBrowser.setVar( 
         "select2", Answer2 );
      WMLBrowser.setVar( 
         "select3", Answer3 );
      WMLBrowser.setVar( 
         "select4", Answer4 );

      // set answer attributes
      WMLBrowser.setVar( "attribute1", result1 );
      WMLBrowser.setVar( "attribute2", result2 );
      WMLBrowser.setVar( "attribute3", result3 );
      WMLBrowser.setVar( "attribute4", result4 );

      WMLBrowser.refresh();
}
     
