// Display entry form for results of some test or exercise

var DEBUG_ALERTS=false;

function RunClick(passedEvent) {
	window.passedEventMembers = objectDissect(passedEvent);
	return RunTests();
}

function SetRunClick() {
	RunButton = element('btnRun');
	if (RunButton != null) { // why is it null in Op7?
		RunButton.onclick = RunClick;
	}
}

function ResultsForm(config,title,opt_runbutton,nextpage,nexturl) {
	wln('<form name=theform id=theform'
		+' onsubmit="return SubmitResults(this);"'
		+' action="http://www.visibone.com/cgibin/TFmail.pl" method="POST">');
	wln('<input type="hidden" name="_config" value="'+config+'" />');

	if (opt_runbutton) {
		wln('<input type="button" value="Run the Tests" name="btnRun" id="btnRun" '
		   +'onclick="return RunTests()" />&nbsp; ');
	}

	wlb(title);
	var cols = /BIG/.test(document.URL) ? 160 : 80;
	var rows = /BIG/.test(document.URL) ? 40 : 8;
	wlb('<textarea cols="'+cols+'" rows="'+rows+'" name="report" id="report" '
	   +'readonly="readonly" onclick="return false;" wrap="soft"><\/textarea>');
	wlb('Totals: <input id=statusbox name=statusbox type="text"'
	   +' readonly="readonly" size="80"'
	   //+' onchange="totalschange(this);"'
	   //+' onreadystatechange="readystatechange(this);"'
	   +' />');
	wlb();
	
	wlb('Name:<input type="text" name="realname" id="realname" />'
	   +'&nbsp;&nbsp;&nbsp;Email:<input type="text" name="email" id="email" />');
	wlb('Comments:&nbsp;&nbsp;&nbsp;&nbsp; (PCFHO: private correspondence for humans only)');
	wlb('<textarea cols="60" rows="3" name="comments" id="comments" wrap="soft"><\/textarea> ');
	wln('<input type="submit" value="Submit the Results" '
	   +'name=btnSubmit id=btnSubmit />');
	if (nextpage != null && nexturl != null) {
		wln('<input type="hidden" name="nextpage" value="'+nextpage+'" />');
		wln('<input type="hidden" name="nexturl" value="'+nexturl+'" />');
	}
	wln('<\/form>');
	wln('<a href="unittests.html">other tests...</a>');
}

function StatusBox(m) {
	if (document != null
	 && document.theform != null
	 && document.theform.statusbox != null
	 && document.theform.statusbox.value != null) {
		document.theform.statusbox.value=m;
	}
}

function SubmitButton(caption) {
	document.theform.btnSubmit.value=caption;
}

function clearreport() {
	document.theform.report.value="";
}

function tallyreport(msg) {
	document.theform.report.value+=msg+"\n";
}

function bodyOnload() {
	StatusBox("Ready to run tests...");
	var jsunitid=getCookie("jsunitid");
	if (DEBUG_ALERTS) {
		alert("jsunitid="+jsunitid);
	}
	var emailname=jsunitid.split("&");
	if (DEBUG_ALERTS) {
		alert("emailname="+emailname.join());
	}
	if (emailname.length == 2) {
		var theform=document.forms["theform"];
		if (theform != null) {
			if (theform.elements["email"] != null
			 && theform.elements["email"].value != null) {
				theform.elements["email"].value=emailname[0];
			}
			if (theform.elements["realname"] != null
			 && theform.elements["realname"].value != null) {
				theform.elements["realname"].value=emailname[1];
			}
		}
	}
	SetRunClick();
}

function SubmitResults(form) {
	if (DEBUG_ALERTS) {
		alert(form.elements["email"].value
	    +"\n"+form.elements["realname"].value);
	}
	setCookie("jsunitid",form.elements["email"].value
	                +"&"+form.elements["realname"].value,30);
	return true;
}
