function RawToProtonormTableSource(){
 this.writeSource = writeSource;
 this.explanation = explanation;
 this.sampIndHardness = sampIndHardness;
 this.median = 413;
}

function writeSource(test){
 var n = test.p.length;
 var source = "";
 source += "<table class=\"margin\" border=\"1\" cellspacing=\"0\">\n";
 source += "<tr><th><a href=\"explained/raw_score.html\">Raw</a></th><th><a href=\"protonorms/\">Protonorm</a></th></tr>\n";
 if(isNaN(test.p[0].protonorm))
  source += "<tr><td>" + test.p[0].raw + "</td><td>" + test.p[0].protonorm + "</td></tr>\n";
 else
  source += "<tr><td>" + test.p[0].raw + "</td><td>" + test.p[0].protonorm + " or lower</td></tr>\n";
 for(var i = 1; i < n; i++)
  source += "<tr><td>" + test.p[i].raw + "</td><td>" + test.p[i].protonorm + "</td></tr>\n";
 source += "</table>\n";
 source += this.explanation(test);
 return source;
}

function explanation(test){
 var source = "<ul><li><a href=\"explained/quality_of_norms.html\">Quality of norms</a>: " + test.qualityOfNorms.toFixed(2) + "</li>\n";
 source += "<li><a href=\"explained/hardness.html\">Sample-independent hardness</a>: " + this.sampIndHardness(test).toFixed(2) + "</li>\n";
 source += "</ul>\n\n";
 source += "<p>Used for norming are all of the known scores from tests correlating " + test.minimumCor.toFixed(2) + " or higher with this test. The used scores are if needed converted to <a href=\"explained/protonorms.html\">protonorms</a> using the relevant conversion formula or table. The <a href=\"explained/raw_score.html\">raw scores</a> on this test that form pairs with the used scores are <a href=\"explained/rank_equation.html\">rank-equated</a> to the used scores, and where needed there is interpolation or extrapolation.</p>\n";
 return source;
}

function sampIndHardness(test){
 var n = test.p.length;
 var bottom = parseInt(test.p[0].raw);
 var top = parseInt(test.p[n - 1].raw);
 if(parseInt(test.p[0].protonorm) >= this.median || test.p[n - 1].raw == "&infin;")
  return 1;
 else if(parseInt(test.p[n - 1].protonorm) <= this.median)
  return 0;
 for(var i = 1; i < n; i++){
  if(test.p[i].protonorm == this.median)
   return (top - test.p[i].raw)/(top - bottom);
  else if(test.p[i].protonorm > this.median)
   return (top - (test.p[i].raw + test.p[i - 1].raw)/2)/(top - bottom);
 }//if fails
 return -1;
}

