function TTest(name1, avg1, SD1, n1, name2, avg2, SD2, n2, answer, objname) {
	this.name1=name1;			this.name2=name2;
	this.avg1=avg1;				this.avg2=avg2;
	this.SD1=SD1;				this.SD2=SD2;
	this.n1=n1;					this.n2=n2;
	this.SE1=SD1/Math.sqrt(n1);	this.SE2=SD2/Math.sqrt(n2);
	this.diff = Math.abs(avg1-avg2);
	this.SEcomb = Math.sqrt(this.SE1*this.SE1 + this.SE2*this.SE2);
	this.ratio = this.diff / this.SEcomb;
	this.objname=objname;
	this.answer = answer;
	}
	
TTest.prototype.write = function() {
	var str = '<table width="70%"  border="1" cellpadding="3" bgcolor="#9999FF">'
  + '<tr><th scope="col">&nbsp;</th>'
    + '<th scope="col">Average</th>'
    + '<th scope="col">SD</th>'
    + '<th scope="col" >n</th>'
    + '<th scope="col">SE</th>'
    + '<th scope="col">t<sub>calc</sub></th>'
  + '</tr><tr><td>'+this.name1+' </td>'
    + '<td>'+this.avg1+'</td>'
    + '<td>'+this.SD1+'</td>'
    + '<td>'+this.n1+'</td>'
    + '<td><div id="id-se-1">'
    + '<input type="text" name="textfield" size="5" id="id-se-1-bl"></div></td>'
    + '<td>&nbsp;</td>'
  + '</tr><tr><td>'+this.name2+' </td>'
    + '<td>'+this.avg2+'</td>'
    + '<td>'+this.SD2+'</td>'
    + '<td>'+this.n2+'</td>'
    + '<td><div id="id-se-2">'
    + '<input type="text" name="textfield" size="5"  id="id-se-2-bl"></div></td>'
    + '<td>&nbsp;</td>'
  + '</tr><tr><td>&nbsp;</td>'
    + '<td>difference: <div id="id-diff">'
    + '<input type="text" name="textfield" size="5"  id="id-diff-bl"></div></td>'
    + '<td>&nbsp;</td>'
    + '<td>&nbsp;</td>'
    + '<td>combined SE: <div id="id-secomb">'
    + '<input type="text" name="textfield" size="5" id="id-secomb-bl"></div></td>'
    //+ '<td>ratio: <div id="id-ratio">'
    //+ '<input type="text" name="textfield" size="5"  id="id-ratio-bl"></div></td>'
    + '<td><table border="1"><tr><td>ratio: <div id="id-ratio">'
    + '<input type="text" name="textfield" size="5"  id="id-ratio-bl"></div></td>'
	+ '<td>Is the difference significant?<br><input id="id-yes" type="radio" name="yesno">yes<br><input id="id-no" type="radio" name="yesno">no'
	+ '</td></tr></table></td>'
  + '</tr><tr><td>&nbsp;</td>'
    + '<td><input id="id-but-diff" type="button" value="Check column" onClick="'+this.objname+'.checkDiff()"></td>'
    + '<td>&nbsp;</td>'
    + '<td>&nbsp;</td>'
    + '<td><input id="id-but-se" type="button" value="Check column" onClick="'+this.objname+'.checkSE()"></td>'
    + '<td><input id="id-but-ratio" type="button" value="Check column" onClick="'+this.objname+'.checkRatio()"></td>'
  + '</tr></table>';
  document.write(str);
}

TTest.prototype.checkDiff = function() {
	if ((document.getElementById("id-diff-bl").value == this.avg1-this.avg2) ||
		(document.getElementById("id-diff-bl").value == this.avg2-this.avg1))	{
		alert("great, keep going");
		document.getElementById("id-diff").innerHTML = document.getElementById("id-diff-bl").value;
		document.getElementById("id-diff").style.fontWeight = 900;
		document.getElementById("id-but-diff").disabled=true;
		}
	else {alert("try again -- subtract the "+this.name1+" average from the "+this.name2+" average");} 
}
TTest.prototype.checkSE = function() {
	var wrong=0;
	if (document.getElementById("id-se-1-bl")!= null) {
	if (within(document.getElementById("id-se-1-bl").value, this.SE1, .2) )	{
		document.getElementById("id-se-1").innerHTML = (this.SE1).toFixed(2);
		document.getElementById("id-se-1").style.fontWeight = 900;		
		}
	else {document.getElementById("id-se-1-bl").style.color="#f00"; ++wrong;} }
	if (document.getElementById("id-se-2-bl")!= null) {
	if (within(document.getElementById("id-se-2-bl").value, this.SE2, .2) )	{
		document.getElementById("id-se-2").innerHTML = (this.SE2).toFixed(2);
		document.getElementById("id-se-2").style.fontWeight = 900;		
		}
	else {document.getElementById("id-se-2-bl").style.color="#f00"; ++wrong;} }
	if (document.getElementById("id-secomb")!= null) {
	if (within(document.getElementById("id-secomb-bl").value, this.SEcomb, .2) )	{
		document.getElementById("id-secomb").innerHTML = (this.SEcomb).toFixed(2);
		document.getElementById("id-secomb").style.fontWeight = 900;		
		}
	else {document.getElementById("id-secomb-bl").style.color="#f00"; ++wrong;} }
	if (wrong==0) {
		alert("good job, just a little more...");
		document.getElementById("id-but-se").disabled=true;
		}
		else alert("check the answers is red again");
}
TTest.prototype.checkRatio = function() {
	if (document.getElementById("id-ratio-bl")!=null)
	{if (within(document.getElementById("id-ratio-bl").value, this.ratio, .2) )	{
		document.getElementById("id-ratio").innerHTML = (this.ratio).toFixed(3);
		document.getElementById("id-ratio").style.fontWeight = 900;		
		}
	else {alert("try again -- divide the difference in averages by the combined standard error");
			return(false);} }
	if ((this.answer=="yes" && document.getElementById("id-yes").checked==true) ||
		(this.answer=="no" && document.getElementById("id-no").checked==true) ) {
		alert("excellent -- you're done");
		document.getElementById("id-but-ratio").disabled=true;		
		}
	else alert("look up the ratio on the table -- if your ratio is bigger than the lookup value, then the difference is significant.");
	
}
