// ***************************************************************
// * Career Values                                               *
// *                                                             *
// * Author:  Nathan Bunker                                      *
// * Date:    Sep  3, 2001                                       *
// * For:     Fred Coon                                          *
// *                                                             *
// *                                                             *
// ***************************************************************

var QuestionLabel  = [ "",
"Independence",
"Challenging Problems",
"Exercise Competence",
"Job Tranquility",
"Creative Expression",
"Work Under Pressure",
"Physical Challenge",
"Precision Work",
"Knowledge",
"Aesthetics",
"Status",
"Intellectual Status",
"Fast Pace",
"Excitement",
"Security",
"Change and Variety",
"Advancement",
"Work on Frontiers of Knowledge",
"Work Alone",
"Influence People",
"Help Others",
"Stability",
"Friendships",
"Make Decisions",
"Power and Authority",
"Help Society",
"Public Contact",
"Affiliation",
"Competition",
"Creativity (general)",
"Community",
"Time Freedom",
"Recognition",
"Moral Fulfillment",
"Location",
"Artistic Creativity",
"Work With Others",
"High Earnings Anticipated",
"Profit, Gain",
"Supervision",
"Family",
"Spirituality",
"Work-Life Balance",
"Environment",
"Honest and Integrity",
"Fun and Humor",
"Structure and Predictability",
"Steep Learning Curve",
"Personal Safety",
"Group & Team",
"Tradition",
"Practicality",
"Diversity",
"Adventure",
"You selected the following values as ALWAYS VALUED. Please prioritize them by selecting the most valued first followed by the second most valued, until all values are selected.",
"You selected the following values as OFTEN VALUED. Please prioritize them by selecting the most valued first followed by the second most valued, until all values are selected.",
"You selected the following values as SOMETIMES VALUED. Please prioritize them by selecting the most valued first followed by the second most valued, until all values are selected.",
"You selected the following values as SELDOM VALUED. Please prioritize them by selecting the most valued first followed by the second most valued, until all values are selected.",
"You selected the following values as NEVER VALUED. Please prioritize them by selecting the most valued first followed by the second most valued, until all values are selected." ];

var AbbreviatedLabel = QuestionLabel;

var QuestionSubLabel = [ "",
"Be able to determine nature of work without significant direction from others; not have to follow instructions or conform to regulations.",
"Engage continually with complex questions and demanding tasks, trouble-shooting and problem-solving as core part of job.","Demonstrate a high degree of proficiency in job skills and knowledge; show above-average effectiveness.",
'Avoid pressures and "the rat race" in job role and work setting.',
"Be able to express in writing and in person my ideas concerning job and how I might improve it; have opportunities for experimentation and innovation.",
"Work in time-pressured circumstances, where there is little or no margin of error, or with demanding personal relationships.",
"Have a job that requires bodily strength, speed, or dexterity, or agility.",
"Deal with tasks that have exact specification, that require careful, accurate attention to detail.",
"Engage myself in pursuit of knowledge, truth and understanding.",
"Be involved in studying or appreciating the beauty of things, ideas, etc.",
"Impress or gain the respect of friends, family and community by the nature and/or level of responsibility of my work.",
'Be regarded as very well-informed and a strong theorist, as one acknowledged "expert" in a given field.',
"Work in circumstances where there is high pace activity and work done rapidly.",
"Experience a high degree of stimulation or frequent novelty and drama on the job.",
"Be assured of keeping my job and a reasonable financial reward.",
"Have work responsibilities frequently changed in content and setting.",
"Be able to get ahead rapidly, gaining opportunities for growth and seniority from work well-done.",
"Work in research and development, generating information and new ideas in the academic, scientific, or business communities.",
"Do projects by myself, without any amount of contact with others.",
"Be in a position to change attitudes or opinions of other people.",
"Be involved in helping people directly, either individually or in small groups.",
"Have a work routine and job duties that are largely predictable and not likely to change over long period of time.",
"Develop close personal relationships with people as a result of work activity.",
"Have the power to decide courses of action, policies, etc. -- a judgment job.",
"Control the work activities or (partially) destinies of others.",
"Do something to contribute to the betterment of the world.",
"Have a lot of day-to-day contact with people.",
"Be recognized as a member of a particular organization.",
"Engage in activities which pit my abilities against others.",
"Create new ideas, programs, organized structures or anything else not following format developed by others.",
"Live in a town or city where I can meet my neighbors and become active in local politics or service projects.",
"Have responsibilities I can work at according to my time schedule; no specific working hours required.",
"Get positive feedback and public credit for work well done.",
"Feel that my work is contributing to ideals I feel are very important.",
"Find a place to live (town, geographic area) conducive to my lifestyle, a desirable home base for my leisure, learning, and work life.",
"Engage in creative work in any of several art forms.",
"Have close working relations with group; work as a team to common goals.",
"Be able to purchase essentials and the luxuries of life I wish.",
"Have strong likelihood of accumulating large amounts of money or other material gain through ownership, profit-sharing, commissions, merit pay increases and the like.",
"Have a job in which I am directly responsible for work done by others.",
"Insure that the type of work I do and the hours I work fit with my family responsibilities.",
"Work in a setting that is supportve of my spiritual beliefs.",
"A job that allows me adequate time for my family, hobbies and social activities.",
"Work on tasks that have a positive effect on the natural environment.",
"Work in a setting where honesty and integrity are assests.",
"Work in a setting where it is possible (and appropriate) to joke and have fun.",
"Do work with a high level of structure and predictability.",
"Be presented with new, unique or difficult tasks to be quickly mastered.",
"Have a high probability of being safe and healthy at work.",
"Work with a group to obtain team (rather than individual) results.",
"Be involved in work that is consistent with the social traditions in which I was brought up with.",
"Be involved with work that yields a practical or useful result.",
"Work in a setting that includes individuals of diverse religious, racial or social backgrounds.",
"Have job duties which involve frequent risk-taking."];

//   Response ***************************************************************
var ResponseLabel = new Array(5);
ResponseLabel[0] = ["Always Valued", "Often Valued", "Sometimes Valued", "Seldom Valued", "Never Valued"];

var SectionLabel = ["", "Sort Values", "Prioritize Values", "The End"];

var SectionText = [ "",
"Sort the following values by how much you value them.",
"Now, prioritize these previous values.",
"You have now completed the Career Values Card Sort. If you wish to review your responses, press back."];

var numberOfQuestionsA = 54;
var numberOfQuestionsB = 1;
var numberOfResults    = 5;
var AnswerD;
var ADTrack;
var AnswerIndex;


var NOQ = 41;
var QuestionWindow;
var Name;
var Answer = new Array(NOQ+1);
for (var i = 0; i <= NOQ; i++) {
   Answer[i] = -1;
}

var Results = new Array(numberOfResults);

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("","CareerValues","scrollbars,width=500,height=450,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 <= numberOfQuestionsA && Answer[q] != -1; q++) ;
    AskQuestion(q,-2);
  //}
}

function AskQuestion(n, r) {   //  n = Current Question   r = Response
  SST = false;
  if (r >= 0) {
    if ( n > 0 && n <= numberOfQuestionsA) {
      Answer[n] = r;
      n++;
      SST = true;
    }
    else if ( n > numberOfQuestionsA && n <= (numberOfQuestionsA + numberOfQuestionsB)) {
      var i = n - numberOfQuestionsA - 1;
      if (AnswerD[i][r] == -1) {
        AnswerD[i][r] = Count[i];
        ADTrack[i][Count[i]] = r;
        Count[i]++;
        if (Count[i] == AnswerIndex[i]) {
          n++;
          SST = true;
        }
      }
      else {
        for (var j = 0; j < AnswerIndex[i]; j++) {          
          if (AnswerD[i][j] > AnswerD[i][r]) {
            AnswerD[i][j]--;
          }
        }
        Count[i]--;
        for (var j = AnswerD[i][r]; j < Count[i]; j++) {
           ADTrack[i][j] = ADTrack[i][j+1];
        }
        ADTrack[i][Count[i]] = -1;
        AnswerD[i][r] = -1;
      }
    }
  }
  if (SST) {
    SST = false;
    if      (n == 1)   { SST = true; }
    else if (n == (numberOfQuestionsA + 1)) {SST = true; }
    else if (n == (numberOfQuestionsA + numberOfQuestionsB + 1)) { SST = true; }
  }
  if (SST && n == (numberOfQuestionsA + 1)) {
    AnswerD     = new Array(numberOfQuestionsB);
    ADTrack     = new Array(numberOfQuestionsB);
    Count       = new Array(numberOfQuestionsB);
    AnswerIndex = new Array(numberOfQuestionsB);
    var c       = new Array(numberOfQuestionsB);
    for (var i = 0; i < numberOfQuestionsB; i++) {
      c[i] = 0;
    }
    for (var i = 1; i <= numberOfQuestionsA; i++) {
      if (Answer[i] >= 0 && Answer[i] < numberOfQuestionsB) {
        c[Answer[i]]++;
      }
    }
    for (var i = 0; i < c.length; i++) {
      AnswerD[i]       = new Array(c[i]);
      ADTrack[i]       = new Array(c[i]);
      Count[i]         = 0;
      ResponseLabel[i] = new Array(c[i]);
      AnswerIndex[i]   = c[i];
    }
    for (var i = 0; i < numberOfQuestionsB; i++) {
      c[i] = 0;
    }
    var a;
    for (var i = 1; i <= numberOfQuestionsA; i++) {
      a = Answer[i];
      if (a >= 0 && a < numberOfQuestionsB) {
        ResponseLabel[a][c[a]] = AbbreviatedLabel[i];
        AnswerD[a][c[a]] = -1;
        ADTrack[a][c[a]] = -1;
        //alert("c[" + a + "] = " + c[a] + "\nAnswer[" + i + "]=" + Answer[i]);
        c[a]++;
      }
    }
  }
  if (SST || r == -2) {
    ShowSectionTitle(n);
  }
  else {
    if (n == (numberOfQuestionsA + numberOfQuestionsB + 1)) {
      var v = 0;
      for (; v < numberOfQuestionsB; v++) {
        Results[v] = new Array(AnswerIndex[v]);
        for (var x = 0; x < AnswerIndex[v]; x++) {
          Results[v][x] = ResponseLabel[v][ADTrack[v][x]];
        }
      }
      var ct = new Array(numberOfResults);
      for (var i = 0; i < numberOfResults; i++) { ct[i] = 0; }
      for (var i = 1; i <= numberOfQuestionsA; i++) {
        if (Answer[i] >= 0 && Answer[i] < numberOfResults) {
          ct[Answer[i]]++;
        }
      }
      var aIndex = 1;
      for (; v < numberOfResults; v++) {
        Results[v] = new Array(ct[v]);
        aIndex = 1;
        for (var x = 0; x < ct[v]; x++) {
          while (Answer[aIndex] != v && aIndex <= numberOfQuestionsA) {
            aIndex++;
          }
          Results[v][x] = QuestionLabel[aIndex];
          aIndex++;
        }
      }
      QuestionWindow.close();
      window.focus();
      ShowResults(Results, Name);
    }
    else if (n <= numberOfQuestionsA) {
      ShowQverA(n);
    }
    else {
      ShowQverB(n);
    }
  }
}

function ShowQverA(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[0].length; i++) {
    d.writeln('  <tr><td width="25"></td>');
    href = '<a href="javascript:opener.AskQuestion(' + n + ', ' + i + ');">';
    if (Answer[0][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[0][i] + '</font></a></td></tr>');
  }
  d.writeln('</table>');
  d.writeln('<br>');
  d.writeln('<table width="450" border="0" align="center"><tr>');
  if (n != 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[0][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(' + n + ');"><img src="help.jpg" width="29" height="12" border="0"></a>');
  d.writeln('</td></tr></table>');
  d.close();
}

function ShowQverB(n) {
  //alert("n = " + 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>');
  //alert("n_sub = " + n_sub + "\nAnswerIndex[n_sub] = " + AnswerIndex[n_sub]);
  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(n) {
  var s;
  if      (n <= numberOfQuestionsA)  { s = 1; }
  else if (n <= numberOfQuestionsA + numberOfQuestionsB)  { s = 2; }
  else    { s = 3; }
  
  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 && s != 2) 
    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(Results, Name) {

  var d = document.getElementById('guttercontent');	
  var x = '';
  x += '&nbsp;&nbsp;<b>Summary Sheet of Career Values</b> <br><br>';
    x += '<br><br><div align="center" style="font-size:8pt;">';

    x += '<table width="100%" border="1" cellpadding="4" cellspacing="0">';
    x += '<tr>';
    x += '  <th width="20%">Always Valued</th>';
    x += '  <th width="20%">Often Valued</th>';
    x += '  <th width="20%">Sometimes Valued</th>';
    x += '  <th width="20%">Seldom Valued</th>';
    x += '  <th width="20%">Never Valued</th>';
    x += '</tr>';
  
  var max = Results[0].length;
  var i;
  for (i = 1; i < Results.length; i++) {
    if (Results[i].length > max) {
      max = Results[i].length;
    }
  }
  for (var j = 0; j < max ; j++) {
      x += '<tr>';
    for (var k = 0; k < Results.length; k++) {
        x += '  <td width="20%">';
      if (j < Results[k].length) {
          x += Results[k][j];
      }
      else {
          x += '&nbsp;';
      }
        x += '</td>';
    }
      x += '</tr>';
  }
    x += '</table>';
    x += "<p>&nbsp;</p>";
    x += '<p><font size="+1"><a href="javascript:window.print();">Print this page now.</a></font></p>';
    x += '<p><font size="+1">After printing, ';
    x += '<a href="worksheet.phtml">continue to the worksheet</a></font></p>';
  var now = new Date();
    x += '<p><font size="-1">Results generated ';
  //  x += Name);
    x += '<br>';
    x += now.toLocaleString();
    x += "</font></p>";
    d.innerHTML = x;
}
