// ***************************************************************
// * Motivated Skills                                            *
// *                                                             *
// * Author:  Nathan Bunker                                      *
// * Date:    May 15, 2001                                       *
// * For:     Fred Coon                                          *
// *                                                             *
// *                                                             *
// ***************************************************************

var QuestionLabel  = [ "",
"Computer Literate",
"Plan, Organize",
"Observe",
"Maintain Records",
"Teach, Train",
"Interview for Information",
"Customer Service",
"Adapt to Change",
"Work with Numbers",
"Conceptualize",
"Mediate",
"Classify",
"Make Arrangements",
"Budget",
"Entertain, Perform",
"Read for Information",
"Initiate Change",
"Deal with Ambibuity",
"Delegate",
"Monitor",
"Perceive Intuitively",
"Proofread, Edit",
"Make Decisions",
"Sell",
"Negotiate",
"Design",
"Manage",
"Counsel",
"Deal with Feelings",
"Expedite",
"Improvise",
"Motivate",
"Use Mechanical Abilities",
"Implement",
"Portray Images",
"Act as Liaison",
"Analyze",
"Team Work",
"Supervise",
"Test",
"Visualize",
"Strategize",
"Innovate, Invent",
"Generate Ideas",
"Write",
"Evaluate",
"Synthesize",
"Estimate",
"Mentor",
"Multi-Task",
"Research Online",];

var QuestionSubLabel = [ "",
"Develop, Organize and Complete Tasks and Projects Using Software Programs Such as MS Word, Excel, and PowerPoint",
"Define Goals and Objectives, Schedule and Develop Projects or Programs.",
"Study, Scrutinize, Examine Data, People, or Things Scientifically.",
"Keep Accurate and Up-to-Date Records, Log, Record, Itemize, Collate, Tabulate Data.",
"Inform, Explain, Give Instruction to Students, Employees, or Customers.",
"Draw Out Subjects Through Incisive Questioning.",
"Effectively Solve Problems and Challenges That Satisfy Customers.",
"Easily and Quickly Respond to Changing Assignments, Work Settings and Priorities.",
"Easily Calculate, Compute, Organize, Understand and Solve Numerical and Quantitative Problems.",
"Conceive and Internally Develop Concepts and Ideas.",
"Manage Conflict, Reconcile Differences.",
"Group, Categorize, Systematize Data, People, or Things.",
"Coordinate Events, Handle Logistics.",
"Economize, Save, Stretch Money or Other Resources.",
"Amuse, Sing, Dance, Act, Play Music for, Give a Demonstration to, Speak to an Audience.",
"Research Written Resources Efficiently and Exhaustively.",
"Exert Influence on Changing the Status Quo, Exercise Leadership in Bringing About New Directions.",
"Be Comfortabl and Effective with Issues That Lack Clarity Structure or Certainty.",
"Achieve Effective Results by Assigning Tasks to Others.",
"Keep Track of the Movement of Data, People or Things.",
"Sense, Show Insight and Foresight.",
"Check writings for Proper Usage and Stylistic Flair, Make Improvements.",
"Make Major, Complex, or Frequent Decisions.",
"Promote a Person, Company, Goods or Services, Convince of Merits, Raise Money",
"Bargain for Rights or Advantages.",
"Structure New or Innovative Practices, Programs, Products, or Environments.",
"Ability to Prioritize, Structure and Schedule Tasks to Maximize Effort and Meet Deadlines.",
"Facilitate Insight and Personal Growth, Guide, Advise, Coach Students, Employees, or Clients.",
"Draw Out, Listen, Accept, Empathize, Express Sensitivity, Defuse Anger, Calm, Inject Humor, Appreciate.",
"Speed Up Production or Services, Trouble-Shoot Problems, Streamline Procedures.",
"To Effectively Think, Speak and Act Without Preparation.",
"Recruit Involvement, Mobilize Energy, Stimulate Peak Performance.",
"Assemble, Tune, Repair, or Operate Engines or Other Machinery.",
"Provide Detailed Follow-Through of Policies and Plans.",
"Sketch, Draw, Illustrate, Paint, Photograph.",
"Represent, Serve as a Link Between Individuals or Groups.",
"Break Down, Figure Out Problems Logically.",
"Easily and Effectively Work With Others to Obtain Results.",
"Oversee, Direct the Work of Others.",
"Measure Proficiency, Quality, or Validity, Check and Double-Check.",
"Imagine Possibilities, See in Mind's Eye.",
"Effectively Plan and Develop Long-Range Strategies That Successfully Accomplish Objectives.",
"Create Unique Ideas or Combine Existing Ideas to Obtain a New or Unique Result.",
"Reflect Upon, Conceive of, Dream Up, Brainstorm Ideas.",
"Compose Reports, Letters, Articles, Ads, Stories, or Educational Materials.",
"Assess, Review, Critique Feasibility or Quality.",
"Integrate Ideas and Information, Combine Diverse Elements into Coherent Whole.",
"Appraise Value or Cost.",
"Educate, Guide, Coach or Counsel a LEss Accomplished or Junior Colleague",
"To Effectively Manage a Variety of Tasks and Projects Simultaneously.",
"Able to Use Search Engines and The Internet to Gather and Organize Information and Data."];

//   Response ***************************************************************
var ResponseLabel = new Array(2);
ResponseLabel[0] = ["Total Delight in Using","Enjoy Using Very Much","Like Using","Prefer Not To Use","Strongly Dislike Using"];
ResponseLabel[1] = ["Highly Proficient","Competent","Lack Desired Skill Level"];

var SectionLabel = ["", "First Sort", "Second Sort", "The End"];

var SectionText = [ "",
"Categorize each of the following activities by how much you like to perform them.",
"Categorize each of the following activities by how well you perform them.",
"You have now complete categorizing each activity. Click continue to see and print your results. If you wish to review your responses, press back."];

var NOQ = 51;
var QuestionWindow;
var Name;
var pass;
var Answer = new Array(2);
Answer[0] = new Array(NOQ+1);
Answer[1] = new Array(NOQ+1);

for (var i = 0; i <= NOQ; i++) {
   Answer[0][i] = -1;
   Answer[1][i] = -1;
}

var Result = new Array(5);
for (var i = 0; i < Result.length; i++) {
  Result[i] = new Array(3);
  Result[i][0] = new Array(0);
  Result[i][1] = new Array(0);
  Result[i][2] = new Array(0);
}

var answerLimit = 4;
var answerCountA = 0;
var answerCountB = 0;
var answerBinA = new Array(answerLimit + 1);
var answerBinB = new Array(answerLimit + 1);

function Start() {
  //if (document.forms[0].name.value == "") {
  //  alert("Please enter your name before beginning.");
  //}
  //else {
  //  Name = document.forms[0].name.value;
    QuestionWindow  = window.open("","MotivationalSkills","scrollbars,width=500,height=330,resizable");
    QuestionWindow.focus();
    QuestionWindow.document.write('<br><br><h3 align=center><font color="#999999">Loading...</font></h3>');
    QuestionWindow.document.close();
    var q;
    for (q = 1; q < (NOQ+1) && Answer[0][q] != -1; q++) ;
    pass = 0;
    AskQuestion(q,-2);
  //}
}
function AdjustQuestion(current_n, adjust_n, adjust_r) {
  //alert ("current_n = " + current_n + "\nadjust_n = " + adjust_n + "\nadjust_r =" + adjust_r);

  pass = 0;
  Answer[pass][adjust_n] = adjust_r;
  if ( adjust_r == 1 ) {
    answerCountA--;
    var i = 0;
    for (; i < answerLimit && answerBinA[i] != adjust_n; i++);
    for (; i < answerLimit; i++) {
      answerBinA[i] = answerBinA[i+1];
    }
  }
  else if ( adjust_r == 3 ) {
    answerCountB--;
    var i = 0;
    for (; i < answerLimit && answerBinB[i] != adjust_n; i++);
    for (; i < answerLimit; i++) {
      answerBinB[i] = answerBinB[i+1];
    }
  }
  //alert ("Answer[pass][current_n] = " + Answer[pass][current_n]);
  AskQuestion(current_n, Answer[pass][current_n]);
}

function AskQuestion(n, r) {   //  n = Current Question   r = Response
  // *********************************************
  var skipRest = false;  

  if (pass == 0 && r >= 0 && n > 0 && n <= NOQ) {
    if (Answer[pass][n] == 0 && r != 0) {
      var i = 0;
      for (; i < answerLimit && answerBinA[i] != n; i++);
      if (answerBinA[i] == n) { answerCountA--; }
      for (; i < answerLimit; i++) {
        answerBinA[i] = answerBinA[i+1];
      }
    }
    else if (Answer[pass][n] == 4 && r != 4) {
      var i = 0;
      for (; i < answerLimit && answerBinB[i] != n; i++);
      if (answerBinB[i] == n) { answerCountB--; }
      for (; i < answerLimit; i++) {
        answerBinB[i] = answerBinB[i+1];
      }
    }
    else if ( r == 0 && Answer[pass][n] != 0) {
      //alert("recording");
      for (var i = 0; i < answerCountA; i++) {
        if (answerBinA[i] == n) { skipRest = true; }
      }
      if (skipRest) {
        skipRest = false;
      }
      else {
        answerBinA[answerCountA] = n;
        answerCountA++;
        Answer[pass][n] = r;
      }
    }
    else if ( r == 4 && Answer[pass][n] != 4) {
      for (var i = 0; i < answerCountB; i++) {
        if (answerBinB[i] == n) { skipRest = true; }
      }
      if (skipRest) {
        skipRest = false;
      }
      else {
        answerBinB[answerCountB] = n;
        answerCountB++;
        Answer[pass][n] = r;
      }
    }
    if ( answerCountA > answerLimit) { 
      ShowBinALimit(pass, n);
      skipRest = true;
    }
    else if ( answerCountB > answerLimit) {
      ShowBinBLimit(pass, n);
      skipRest = true;
    }
  }
  
  // *********************************************
  if (!skipRest) {
    SST = false;
    if (r < 0 && n == 0 && pass > 0) {
      pass--;
      n = NOQ;
    }
    if (r >= 0) {
      if (n > 0 && n <= NOQ) {
        Answer[pass][n] = r;
        n++;
        SST = true;
        if (n > NOQ) {
          pass++;
          n = 1;
        }
      }
    }
    if (SST) {
      SST = false;
      if      (n == 1)   { SST = true; }
      else if (n == (NOQ+1))  { SST = true; }
    }
    if (n == 1 && pass == 2) {
      var a, b, l;
      for (var i = 1; i <= NOQ; i++) {
        a = Answer[0][i];
        b = Answer[1][i];
        l = Result[a][b].length;
        Result[a][b][l] = QuestionLabel[i];
      }
      QuestionWindow.close();
      ShowResults(Result , Name, ResponseLabel);
    }
    else if (SST || r == -2) {
      ShowSectionTitle(pass,n);  // Show Help
    }
    else {
      ShowQverA(pass,n);         // Show Question
    }
  }
}


function ShowBinALimit(pass,n) { // ^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^
  var d = QuestionWindow.document;
  var HasChosen = false;
  var href;
  d.open();

  d.writeln('<h3>Category Full</h3>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.writeln('  <td width="25" valign="top" align="right"><font size="+2"><b>Y</b></font></td>');
  d.writeln('  <td colspan="2">ou have marked the following skills as "Total Delight');
  d.writeln('  in Using". There is a limit of ');
  d.writeln(answerLimit);
  d.writeln(' skills in this category. ');
  d.writeln('  Please select the skill that you enjoy using the least.');
  d.writeln('  This skill will be placed in the "Enjoy Using Very Much" category.');
  d.writeln('  </td></tr>');

  for (var i = 0; i < answerBinA.length; i++) {
    d.writeln('  <tr><td width="25"></td>');
    href = '<a href="javascript:opener.AdjustQuestion(' + n + ', ' + answerBinA[i] + ', 1);">';
      d.writeln('<td width="30" align="center">' + href + '<img src="teal_dot.jpg" height="12" width="12" border="0"></a></td>');
    d.writeln('<td width="381">');
    d.write(href);
    d.writeln('<font size="+1" color="#214251">' + QuestionLabel[answerBinA[i]] + '</font></a></td></tr>');
  }
  d.writeln('</table>');
  d.writeln('<br>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.write('  <tr><td width="350"><a href="javascript:opener.AskQuestion(' + n + ', -1);"><img src="back.jpg" width="52" height="18" border="0"></a>');
  d.writeln('  </td><td width="100" align="right">');
  d.writeln('</td></tr></table>');
  d.close();
}

function ShowBinBLimit(pass,n) { // ^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^
  var d = QuestionWindow.document;
  var HasChosen = false;
  var href;
  d.open();

  d.writeln('<h3>Category Full</h3>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.writeln('  <td width="25" valign="top" align="right"><font size="+2"><b>Y</b></font></td>');
  d.writeln('  <td colspan="2">ou have marked the following skills as "Strongly Dislike');
  d.writeln('  Using". There is a limit of ');
  d.writeln(answerLimit);
  d.writeln(' skills in this category. ');
  d.writeln('  Please select the skill that you dislike using the least.');
  d.writeln('  This skill will be placed in the "Prefer Not To Use" category.');
  d.writeln('  </td></tr>');

  for (var i = 0; i < answerBinB.length; i++) {
    d.writeln('  <tr><td width="25"></td>');
    href = '<a href="javascript:opener.AdjustQuestion(' + n + ', ' + answerBinB[i] + ', 3);">';
      d.writeln('<td width="30" align="center">' + href + '<img src="teal_dot.jpg" height="12" width="12" border="0"></a></td>');
    d.writeln('<td width="381">');
    d.write(href);
    d.writeln('<font size="+1" color="#214251">' + QuestionLabel[answerBinB[i]] + '</font></a></td></tr>');
  }
  d.writeln('</table>');
  d.writeln('<br>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.write('  <tr><td width="350"><a href="javascript:opener.AskQuestion(' + n + ', -1);"><img src="back.jpg" width="52" height="18" border="0"></a>');
  d.writeln('  </td><td width="100" align="right">');
  d.writeln('</td></tr></table>');
  d.close();
}

function ShowQverA(pass,n) {
  var d = QuestionWindow.document;
  var HasChosen = false;
  var href;
  d.open();

  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.writeln('  <td width="25" valign="top" align="center"><font size="+1">' +
    n + '.</font></td>');
  d.writeln('  <td colspan="2"><font size="+1">' +
    QuestionLabel[n].toUpperCase() + '</font><br>');
  d.writeln('  ' + QuestionSubLabel[n] + '</td></tr>');

  for (var i = 0; i < ResponseLabel[pass].length; i++) {
    d.writeln('  <tr><td width="25"></td>');
    href = '<a href="javascript:opener.AskQuestion(' + n + ', ' + i + ');">';
    if (Answer[pass][n] == i) {
      d.writeln('<td width="30" align="center">' + href + '<img src="yellow_dot.jpg" height="12" width="12" border="0"></a></td>');
      HasChosen = true;
    }
    else {
      d.writeln('<td width="30" align="center">' + href + '<img src="teal_dot.jpg" height="12" width="12" border="0"></a></td>');
    }
    d.writeln('<td width="381">');
    d.write(href);
    d.writeln('<font size="+1" color="#214251">' + ResponseLabel[pass][i] + '</font></a></td></tr>');
  }
  d.writeln('</table>');
  d.writeln('<br>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  if (n != 1 || pass == 1) 
    d.write('  <tr><td width="350"><a href="javascript:opener.AskQuestion(' + (n-1) + ', -1);"><img src="back.jpg" width="52" height="18" border="0"></a>');
  if (HasChosen) {
    d.write('  <a href="javascript:opener.AskQuestion(' + n  + ', ' + Answer[pass][n] +');"><img src="continue.jpg" width="92" height="18" border="0"></a>');
  }
  d.writeln('  </td><td width="100" align="right">');
  d.writeln('  <a href="javascript:opener.ShowSectionTitle(' + pass + ', ' + n +');"><img src="help.jpg" width="29" height="12" border="0"></a>');
  d.writeln('</td></tr></table>');
  d.close();
}

function ShowQverB(n) {
  var d = QuestionWindow.document;
  var HasChosen = true;
  var href;
  d.open();
  d.writeln('<table width="450" border="0" align="center"><tr>');
  d.writeln('  <td width="25" valign="top" align="center"><font size="+1">' + n + '.</font></td>');
  d.writeln('  <td colspan="2"><font size="+1">' + QuestionLabel[n] + '</font></td></tr>');

  var i;
  var j;
  var n_sub = n - numberOfQuestionsA -1;
  for (i = 0; i < AnswerIndex[n_sub]; i++) {
    if (AnswerD[n_sub][i] == -1) {
      d.writeln('  <tr><td width="25"></td>');
      href = '<a href="javascript:opener.AskQuestion(' + n + ', ' + i + ');">';
      d.writeln(href + '<td width="30" align="center"><img src="teal_dot.jpg"></td>');
      d.writeln('<td width="381">');
      d.write(href);
      d.writeln('<font size="+1" color="#214251">' + ResponseLabel[n_sub][i] + '</font></a></td></tr>');
      HasChosen = false;
    }
  }
  d.writeln('<tr><td width="25">&nbsp;</td><td width="30" colspan="2"><img src="teal_bar.jpg"></td></tr>');
  for (i = 0; i < AnswerIndex[n_sub] && ADTrack[n_sub][i] != -1; i++) {
    j = ADTrack[n_sub][i];
    d.writeln('  <tr><td width="25"></td>');
    href = '<a href="javascript:opener.AskQuestion(' + n + ', ' + j + ');">';
    d.writeln(href + '<td width="30" align="center"><img src="dot' + (i+1) +'.jpg"></td>');
    d.writeln('<td width="381">');
    d.write(href);
    d.writeln('<font size="+1" color="#214251">' + ResponseLabel[n_sub][j] + '</font></a></td></tr>');
  }
   
  d.writeln('</table>');
  d.writeln('<br>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  if (n_sub >  0) 
    d.write('  <tr><td width="350" valign="center"><a href="javascript:opener.AskQuestion(' + (n-1) + ', -1);"><img src="back.jpg" width="52" height="18" border="0"></a>');
  if (HasChosen) {
    d.write('  <a href="javascript:opener.AskQuestion(' + (n + 1) + ', -1);"><img src="continue.jpg" width="92" height="18" border="0"></a>');
  }
  d.writeln('  </td><td width="100" align="right">');
  d.writeln('  <a href="javascript:opener.ShowSectionTitle(' + n + ');"><img src="help.jpg" width="29" height="12" border="0"></a>');
  d.writeln('</td></tr></table>');
  d.close();

}

function ShowSectionTitle(pass, n) {
  var s;
  if      (pass == 0)  { s = 1; }
  else if (pass == 1)  { s = 2; }
  else if (pass == 2)  { s = 3; }
  else                 { s = 0; }

  var d = QuestionWindow.document;
  d.open();
  d.writeln('<center><table width="350" border="0"><tr>');
  d.writeln('  <td width="300">');
  d.writeln('    <center><h2>' + SectionLabel[s]  + '</center></h2>');
  d.writeln('    <font size="+2">' + SectionText[s] + '</font>');
  d.writeln('  </td>');
  d.writeln('</table><br>');
  if (s != 1) 
    d.write('  <tr><td width="350"><a href="javascript:opener.AskQuestion(' + (n-1) + ', -1);"><img src="back.jpg" width="52" height="18" border="0"></a>');
  d.writeln('<a href="javascript:opener.AskQuestion(' + n + ', -1);"><img src="continue.jpg" border="0" alt="Continue"></a>');
  d.writeln('</center>');
  d.close();
}


function ShowResults(Result, na, ResponseLabel) {
	
  var d = document.getElementById('guttercontent');
  var x = '';

    x += '&nbsp;&nbsp;<b>Motivated Skills Matrix</b><br><br> ';
  //  x += Name);

    x += '<table width="95%" border="1" cellspacing="0" align="center">';
    x += '<tr bgcolor="#FCF3D1"><td>&nbsp;</td>';
  for (var i = 0; i < ResponseLabel[1].length; i++) {
      x += '<td align="center"><h4>' + ResponseLabel[1][i] + '</h4></td>';
  }
    x += '</tr>';
  for (var i = 0; i < ResponseLabel[0].length; i++) {
      x += '<tr><td bgcolor="#FCF3D1" align="center"><h4>' + ResponseLabel[0][i] +
      '</h4></td>';
    for (var j = 0; j < ResponseLabel[1].length; j++) {
        x += '<td valign="top">';      
      if (Result[i][j].length > 0) {
          x += '<ul><li>';       
          x += Result[i][j][0];
          x += '</li>';
        for (var k = 1; k < Result[i][j].length; k++) {
            x += '<li>' + Result[i][j][k] + '</li>';
        }
          x += '</ul>';
      }
      else {
          x += '&nbsp;';
      }
        x += '</td>';
    }
      x += '</tr>';
  }
    x += '</table>';

    x += '<p>&nbsp;</p>';
    x += '<p style="padding-left:10px; padding-right:10px;"><font size="+1"><a href="javascript:window.print();">Print this page now.</a></font></p>';
    x += '<p style="padding-left:10px; padding-right:10px;"><font size="+1">After printing, ';
    x += '<a href="worksheet.phtml">continue to the worksheet</a></font></p>';
  var now = new Date();
    x += '<p style="padding-left:10px; padding-right:10px;"><font size="-1">Results generated ';
  //  x += na;
    x += '<br>';
    x += now.toLocaleString();
    x += "</font><br><br></p>";
    d.innerHTML = x;
}
