/*
Sept 8, 2004

line 189: thisSubject = new Sj
setup field defaulting to "you" and "me"

stuff like speed and distance values
get computed first in
function compileData || line 801

function displayData || line 927
is where the Oberg norms undergo unit conversion
based on conversions and TmConvFactors || lines 80-92

these conversion factors should really be verified
before any new scientific studies are undertaken
*/

window.onerror=errorsuppressor

function errorsuppressor(msg, url, linenumber){
if (txtScriptState == "initializing") {
	blnTrustApplet = false;
	initialize();
} else if (txtScriptState == "printing" && NN) {
} else {
	alert('Javascript error encountered while '+txtScriptState+'\n\nMessage: '+msg+'\nLine Number: '+linenumber);
	txtScriptState = "...";
}
return true
}

var blnTrustApplet = true;
var txtScriptState = "initializing";

/////////////////////////////
//INITIALIZE DHTML VARIABLES 
//AND FUNCTIONS 2003/03/23
/////////////////////////////
var NN4 = document.layers && !document.getElementById;
var NN = !document.all && document.getElementById;
var IE4 = document.all && !document.getElementById;
var IE = document.all;

var contemp = false;
var optLen;// .....handy constraint customization scheme
var intOnScreen;// .....one of 8 or 9 screens we need to render
var savedScreens = new Array();// .....reusable DHTML content
var thisSubject;// the object where testing variables all get stored
var units = new Array();
units[0] = new Array("feet","meters","meters");
units[1] = new Array("miles/hour","km/hour","km/hour");

var copytext = ""; // PRISM 2010 for Internet Explorer and FAHC, initially...
					// see function Clipboard() and
					// http://www.htmlgoodies.com/beyond/javascript/article.php/3458851/Click-Its-Copied.htm

function Oberg(sex,age,units) {
	//CONVERT OBERG SPEED FROM cm/s, CAD FROM step/min, STEPLEN FROM cm
	//AND CREATE LABELS FOR THE BAR GRAPHS
	this.speed = goalSpeed[sex][age]/conversions[units][0];
	this.speedLabel = labels[units][0];
	
	this.cadence = goalCad[sex][age]/conversions[units][1];
	this.cadenceLabel = labels[units][1];
	
	this.steplength = goalStepLen[sex][age]/conversions[units][2];
	this.steplengthLabel = labels[units][2];
}

var conversions = new Array();
var labels = new Array();

/*
UNIT CONVERSION ARRAY FOR ENGLISH[0], METRIC[1], and SI[2]
****** SEE DEVELOPERS NOTE, AT TOP OF THIS FILE ******

THESE VALUES ARE READ BY THE function Oberg() TO
CONVERT OBERG NORMS FOR SPEED, CADENCE, and STEPLENGTH
FROM cm/sec, steps/min, and cm TO...
*/

//ENGLISH
conversions[0] = [0.508,1,2.54];
labels[0] = ["ft/min","steps/min","inches"];

//METRIC
conversions[1] = [1.6666667,1,1];
labels[1] = ["m/min","steps/min","cm"];

//SI
conversions[2] = [1,60,1];
labels[2] = ["cm/sec","steps/sec (hz)","cm"];

//OBERG'S ft/min to mph, m/min to kph, or cm/sec to kph
var TmConvFactors = [88,16.6666667,27.7777778];
var TmConvLabels = ["mph","kph","kph"];

var btn_StyleOptions = new Array("disabled","on","ready","bright");
var testingOK = false;//boolean - flipped by setup form events, applied to btn4 style
var blnLockButtons = false;//set to true only while the nixer popup is present
var LCAction = false;
//set LIGHTS/CAMERA/ACTION to true to make keypress events capture data!
//set it to false whenever the "s" key is pressed or one of the nav buttons is clicked
systemChecks = new Array('red_light.gif','green_light.gif');
var checkArray = new Array(1,0,0,0,0);
//0=js, 1=cookie, 2=java, 3=DOM, 4=floppy

Welcome = new Image(16,16);Welcome.src = './images/welcome.gif';
Welcome_hi = new Image(16,16);Welcome_hi.src = './images/welcome_hi.gif';
Help = new Image(16,16);Help.src = './images/help.gif';
Help_hi = new Image(16,16);Help_hi.src = './images/help_hi.gif';

function initialize() {
	if (!IE && !IE4 && !NN) contemp = true;
	if (contemp) {
		if (confirm("!! OLDER BROWSER DETECTED !!\n\nYour "+navigator.appName+"\n"+navigator.appVersion+" browser\nlacks the power to run the JAVA/JAVASCRIPT content\nin the Shaw Gait Assessment program.\n\nWould you like to try running an earlier version of SGA instead??")) {
				 	window.location.href="./sga4/pacer.htm";
		 } else {
		 	alert("Program terminated.\n\nBrowser updates can be obtained free from\nhttp://microsoft.com/windows/ie/ or\nhttp://home.netscape.com/computing/download/");
		 }
	} else {
		//see which browser features are enable/disabled
		systemCheck();
		//store the starting lengths of each test constraint array
		optLen = new Array(document.setup.setD.length,document.setup.setT.length,document.setup.setS.length);
		//commit the HTML in the setup page 
		//to the savedScreens array
		intOnScreen = 3;
		var scrSetup = getEl("MainBody");
		savedScreens[intOnScreen] = scrSetup.innerHTML;
		//the results screen must start blank
		savedScreens[5] = "";
		//load the welcome page
		bID = getEl("btn_0");
		txtScriptState = "..."; 
		mClick(bID,true);
		//make the mainbody div visible
		showIt("MainBody");
	}
}

function systemCheck(chkFct)  {
	if (IE || NN) checkArray[3] = 1;
}

function getEl(elID) {
	var elEl = (IE) ? document.all[elID]: document.getElementById(elID);
	return elEl
}

function WriteToEl(thsOutput,thsTarget) {
	//alert("to write *" + thsOutput.substring(0,100) + "*\n\nto " + thsTarget);
	//handles both IE and NN6 variants
	thsTarget = getEl(thsTarget);
	
	//write new content
	thsTarget.innerHTML = thsOutput;
	
	if (thsOutput == "") {
		thsTarget.style.height=0;
	}
}

function Sj(Nn,Aa,Xx,Uu,Dd,Tt,Ss,Cc,Rr,Cd,Ct,Cs,Ca,Yr,Mm,Dt,Hr,Mn,Sc) {
	this.name = Nn;// persistent name holder
	this.age = Aa;// index
	this.sex = Xx;// 0 for male; 1 for female
	this.units = Uu;// 0 for english; 1 for metric; 2 for SI
	this.distance = Dd;// index
	this.time = Tt;// index
	this.speed = Ss;// index
	this.comment = Cc;// comment
	this.rater = Rr;// persistent rater name
	this.customD = Cd;// distance value
	this.customT = Ct;// time value
	this.customS = Cs;// speed value
	this.customA = Ca;// age (range) value
	this.Yr = Yr;// test yr
	this.Mm = Mm;// test mon
	this.Dt = Dt;// test day of month
	this.Hr = Hr;// test hour
	this.Mn = Mn;// test min
	this.Sc = Sc;// test sec
}

function showSubject(thsSj,basicParms) {
	if (basicParms) {
		thisSubject = new Sj("",0,0,thisSubject.units,thisSubject.distance,thisSubject.time,thisSubject.speed,"",thisSubject.rater,"");
		savedScreens[5] = "";
	} else if (!thsSj) {
		thisSubject = new Sj("",0,0,0,3,0,0,"","","");
		//thisSubject = new Sj("you",0,0,0,3,0,0,"","me","");
		savedScreens[5] = "";
	}
	var frm = document.setup;
	frm.client1.value = thisSubject.name;
	frm.decade.selectedIndex = thisSubject.age;
	frm.sex[thisSubject.sex].checked = true;
	frm.metric[thisSubject.units].checked = true;
	frm.setD.selectedIndex = thisSubject.distance;
	frm.setT.selectedIndex = thisSubject.time;
	frm.setS.selectedIndex = thisSubject.speed;
	frm.comment.value = thisSubject.comment;
	frm.rater1.value = thisSubject.rater;
	reLabel(thisSubject.units);
}

function reLabel(mmtUnits) {
	// 0 for metric and 1 for english
	var dst = getEl("dst");
	var spd = getEl("spd");
	dst.innerHTML = units[0][mmtUnits];
	spd.innerHTML = units[1][mmtUnits];
}

function enableNavigation(onscreen) {
	/*
	using the btn_StyleOptions array...
	first thing set em all to style 2
	next set 4-6 to style 0
	apply logic to disable 4 if too soon to be "ready"
	apply logic to disable 5 and 6 if no past test results to display/print
	set self to 1;
	*/
	var bID;
	for (i=0;i<10;i++) {
		bID = "btn_"+i;
		bID = getEl(bID);
		if (i != 8 && i != 7) bID.className = btn_StyleOptions[2]; //button 8 is the exit button...now hidden. 10/04 the download button is hidden to (id=btn7)
		imgPicker("Welcome",(onscreen == "btn_0") ? 4:3);
		imgPicker("Help",(onscreen == "btn_1") ? 4:3);
		if (i==4 && testingOK==false) {bID.className = btn_StyleOptions[0]};
		if (i==5 && savedScreens[5] == "") {bID.className = btn_StyleOptions[0]};
		if ((i==6  || i==9) && (savedScreens[5] == "" || onscreen != "btn_5")) {bID.className = btn_StyleOptions[0]};
		if ((i==9 || i==10) && checkArray[2] == 0) {bID.className = btn_StyleOptions[0]};
		//alert("btn_"+i+"'s classname is: "+bID.className);
	}
	bID = getEl(onscreen);
	bID.className = btn_StyleOptions[1];
	return true
}

function mOver(cel) {
	if(cel.className != 'disabled' && cel.className != 'on') cel.className = btn_StyleOptions[3]
}

function mOut(cel) {
	if(cel.className != 'disabled' && cel.className != 'on') cel.className = btn_StyleOptions[2]
}

function mClick(cel,NoMatterWhat) {
	if (!blnLockButtons && !contemp && !(txtScriptState == "initializing")) {
		//closeAllWindows();
		if (cel.id=="btn_8") {
			window.close();
		} else if (cel.id=="btn_6" && intOnScreen == 5) {
			if (!IE4) {txtScriptState="printing";window.print();txtScriptState="..."} else {alert("Not supported in Internet Explorer 4x.\n\nInstead, use File -> Print in the menubar.")}
		} else if (cel.id=="btn_9" && intOnScreen == 5) {
			//check settings and save the test;
			SaveTest2(cel.className);
		} else if (cel.id=="btn_10" && cel.className == "disabled") {
			alert("Cannot display saved tests as the\nJava Security layer is not enabled.\n\nYou may browse for those saved tests manually, however.\n\nFor more detail, see the help menu on the Welcome screen.");
		} else {
			var blnBlocked = false;
			if (cel.className == "on") blnBlocked = "";
			if (cel.className == "disabled") {
				blnBlocked = "Please make another selection.  "+
				"This button is disabled at present.";
				if(cel.id=="btn_4") alert("Please complete all REQUIRED FIELDS (*)\non the 'Setup' screen, then click 'Test'");
			}
			//alert(blnBlocked);
			window.status= (blnBlocked) ? blnBlocked:"";//allow action for cel.id
			if (!blnBlocked || NoMatterWhat) {
				LCAction = (cel.id=="btn_4") ? true:false;
				//alert(cel.id + " was clicked, and screen[" + intOnScreen + "] is being replaced.");
				if (!NoMatterWhat && intOnScreen != 5) savedScreens[intOnScreen] = getEl("MainBody").innerHTML;
				enableNavigation(cel.id);
				WriteToEl(refreshScreen(cel.id),"MainBody");
				//if screen 5 (results) then update the comment field
				if (intOnScreen == 5) WriteToEl("<strong>Comment: </strong>" + thisSubject.comment,"MainComment");
				//if screen 3 (setup) then populate the fillin fields
				if (intOnScreen == 3) showSubject(thisSubject);
				if (intOnScreen == 3) document.setup.client1.focus();
				if (intOnScreen == 4 && getEl("distance_here")) WriteToEl("&nbsp;" + thisSubject.customD + " " + units[0][thisSubject.units] + " apart.","distance_here");
				if (intOnScreen == 4 && getEl("speed_here")) WriteToEl(thisSubject.customS + " " + units[1][thisSubject.units] + ".","speed_here");
				if (intOnScreen == 4 && getEl("units_here")) WriteToEl(units[0][thisSubject.units],"units_here");
			}
		}
	}
}

function refreshScreen(strBtn) {
	if (strBtn == "btn_0") {intOnScreen = 0;return scrHome()}
	if (strBtn == "btn_1") {intOnScreen = 1;return scrHelp()}
	if (strBtn == "btn_2") {intOnScreen = 2;return scrPrivacy()}
	if (strBtn == "btn_3") {intOnScreen = 3;return savedScreens[3];}
	
	if (strBtn == "btn_4") {intOnScreen = 4;blnAcceptableTest = true;n=0;m=1;return scrTest()}
	if (strBtn == "btn_5") {intOnScreen = 5;return savedScreens[5]} //results button
	if (strBtn == "btn_6") {intOnScreen = 6;return savedScreens[5]} //print button
	if (strBtn == "btn_9") {intOnScreen = 9;return savedScreens[5]} //save button
	
	if (strBtn == "btn_7") {intOnScreen = 7;return scrDownload()}
	if (strBtn == "btn_8") {intOnScreen = 8;return scrDownload()}
	if (strBtn == "btn_10") {intOnScreen = 10;return scrCompare()}
	return null;
}

function tidy(wName) {
	var iRegExp = new RegExp("[^A-Za-z0-9]+","gi");
	wName = wName.replace(iRegExp,"");
	return wName;
}

function scrDownload() {
return "<span class='title'>Download</span>" +
"<p>The full-featured Shaw Gait Assessment tool is available for download at no charge.  The full version allows you to:<ul>" +
"<li>Install and run the program on non-networked machines, such as laptops, for enhanced portability.<li>Save tests electronically to floppy disk and/or hard drive (via JAVA applet).<li>Make convenient change-over-time (test/retest) comparisons for clients.</ul>" +
"<p>Being a browser-based program, it should cause no conflicts with your network or operating system. If in doubt, check with your facility's network administrator.<p>Be sure to 'Bookmark' the SGA welcome page in your browser (Netscape) or add it to 'Favorites' (Internet Explorer) for easy access in the future.<p>" +
"<a href='sga_setup.exe'>Click here to download SGA</a>.";
}

function scrPrivacy() {
return "<span class='title'>Privacy Statement</span>" +
"<p>No information about your client(s) is EVER transmitted by SGA over the internet to a remote computer or server.<sup>1</sup>" +
"<p>At test completion, identifiable client results are displayed on-screen, and this SGA demo version gives you the option to print this results page for inclusion in the client's medical record.   <!--In addition, the downloadable full version of the SGA allows you to save tests electronically for later recall (<a href='javascript:mClick(getEl(\"btn_7\"))'>details</a>).--><p>Protecting the confidentiality of client information in accordance with applicable local, state, and federal regulations is the sole responsibility of the therapist (end user) of SGA. This includes results displayed on-screen, printed, and/or saved electronically.<p>" +
"<p>" +
"<ol>" +
"<li class=footnote>The core processing in SGA is handled by javaScript, which does not require server-side processing.";
}

function scrHome() {
return "<table>" +
"<tr>" +
"<td colspan='2' class='title'>Shaw Gait Assessment</td>" +
"</tr>" +
"<tr>" +
"<td colspan='2' class='byline'>Putting objective gait analysis at your fingertips!</td>" +
"</tr>" +
"<tr>" +
"<td colspan='2'>Developed in 1999, and redesigned in 2003, the Shaw Gait Assessment gives therapists with PC access objective real-time temporal gait data.  Its results are norm-referenced for speed, step length, and step frequency (cadence), dependent upon age and gender. SGA computation for these parameters has been scientifically validated in clinical trials with healthy adult subjects.<!--footnote-Sheila?]-->" +
"</td>" +
"</tr>" +
"<tr>" +
"<td valign=top>You will find it a useful biofeedback tool, a means to quantify (and report) the severity of a client's gait deviations, and a way to gauge her or his response to your current intervention.<p>" +
"<b>Click the 'Setup' button to get started...</b>" +
"<!--<p>First time users may find it helpful to view the <br />" +
"<a href='#'>" +
"<span class='normal_link'>SGA Tutorial</span>" +
"</a>.-->" +
"</td>" +
"<td>" +
"<table cellspacing='0' class='NoticeTable' width=300>" +
"<tr>" +
"<td colspan=4>The checkboxes below should all hold green checkmarks.  If not, you may have an out-dated browser on your PC, or you may need to adjust your browser settings.  Click 'help' below for more detail.</td>" +
"</tr>" +
"<tr>" +
"<td colspan=4 class='JustNoticeMe'>Browser Checklist</td>" +
"</tr>" +
"<tr>" +
"<td>" +
"<img src='./images/"+systemChecks[checkArray[0]]+"' width='12' height='12' border='0'>" +
"</a>" +
"</td>" +
"<td>JavaScript Check</td>" +
"<td>" +
"<a href='javascript:troubleshooting(0)'>help</a>" +
"</td>" +
"<td>&nbsp;</td>" +
"</tr>" +
"<!--<tr>" +
"<td>" +
"<img src='./images/"+systemChecks[checkArray[1]]+"' width='12' height='12' border='0'>" +
"</a>" +
"</td>" +
"<td>Cookie Check</td>" +
"<td>" +
"<a href='javascript:troubleshooting(1)'>help</a>" +
"</td>" +
"<td>&nbsp;</td>" +
"</tr>-->" +
"<tr>" +
"<td>" +
"<img src='./images/"+systemChecks[checkArray[3]]+"' width='12' height='12'  border='0'>" +
"</a>" +
"</td>" +
"<td>DOM Check</td>" +
"<td>" +
"<a href='javascript:troubleshooting(3)'>help</a>" +
"</td>" +
"<td>&nbsp;</td>" +
"</tr>" +
"<!--<tr>" +
"<td>" +
"<img src='./images/"+systemChecks[checkArray[2]]+"' width='12' height='12' border='0'>" +
"</a>" +
"</td>" +
"<td>Java Permissions Check (C:)</td>" +
"<td>" +
"<a href='javascript:troubleshooting(2)'>help</a>" +
"</td>" +
"<td>&nbsp;</td>" +
"</tr>" +
"<tr>" +
"<td>" +
"<img name='check4' src='./images/"+systemChecks[checkArray[4]]+"' width='12' height='12' border='0'>" +
"</a>" +
"</td>" +
"<td>Java Floppy Check (A:)</td>" +
"<td>" +
"<a href='javascript:troubleshooting(4,"+checkArray[2]+")'>help</a>" +
"</td>" +
"<td>" +
"<a href='javascript:sysReCheck(4)'>retry</a>" +
"</td>" +
"</tr>" +
"</table>" +
"</td>" +
"</tr>-->" +
"</table>";
}

var shootingMsg = new Array();
shootingMsg[0] = "JavaScript must be enabled for SGA to run properly. This setting can be turned on in your browser preferences screen.";
shootingMsg[1] = "If the cookie test failed, then the cookie feature has been disabled in your browser.\n\nThis can be corrected in Internet Explorer in the Tools menu, Internet Options, Privacy Tab (select Medium or Default).\n\nIn Netscape, open the Edit dropdown menu, choose Preferences-->Privacy and Security-->Cookies (enable for the originating website).\n\nWith cookies disabled, SGA should still be functional.\n\nSGA cookies that contain identifible client information are deleted from the hard drive as soon as you exit SGA, for privacy reasons.";
shootingMsg[2] = "1. If the Java Applet did not load, you may have declined to 'Trust the signed Java Applet' upon opening SGA. Try closing all browsers, opening SGA again, and answering 'Yes I trust the content'.\n\n2. Possibly, a browser compatibility issue is responsible.  SGA does not yet support the JAVA2 security model shipped with Netscape 6 and above.\n\n3. If your default browser is Internet Explorer, you may want to download the latest browsers free from 'www.microsoft.com'.\n\n4. For best results with Internet Explorer, open the Java Plug-in control (in the Windows Control Panel) and reset the Java Runtime Environment (on the advanced tab) to 1.3.0_01.\n\n5. IN THE ABSENCE OF NON-JAVA ERROR MESSAGES, YOU SHOULD STILL BE ABLE TO USE SGA, ALTHOUGH YOU MAY BE UNABLE TO SAVE TESTS TO THE HARD DRIVE OR FLOPPY DISK (PRINT THEM, INSTEAD)."
shootingMsg[3] = "If the DOM check box is red, you apparently are using an out-dated or incompatible browser.\n\nTo run SGA you need Internet Explorer v4+ or Netscape v5+.  You may download the latest browsers free from 'www.microsoft.com' and 'www.netscape.com'."
shootingMsg[4] = new Array("Before trouble-shooting floppy drive access, you must address the apparent failure to gain global JAVA file privileges...\n\n"+shootingMsg[2],"If the floppy access check fails...\n\n1. You may need to insert a floppy disk.\n\n2. You may need to check the floppy disk and turn off the 'write-protect' tab.\n\n3. You may be using a laptop or PC with no built-in floppy drive.","Before trouble-shooting floppy drive access, you will need to address global JAVA file access issues...\n\n"+shootingMsg[2]);

function troubleshooting(ndx,contingency) {
	var alertVal = "TROUBLE-SHOOTING\n\n";
	if (contingency==0 || contingency==1) {
		alertVal += shootingMsg[ndx][contingency];
	} else {
		alertVal += shootingMsg[ndx];
	}
	alert(alertVal+"\n\nMAC users: support for the MAC platform is not fully implemented, and results may be unpredictable.");
}

function scrTest() {
	var helpVals = new Array();
	helpVals[0] = "";//AVOID THIS TO AVOID DIV BY ZERO ERROR!
	helpVals[1] = thisSubject.customD;
	helpVals[2] = thisSubject.customS;
	helpVals[3] = units[0][thisSubject.units];
	helpVals[4] = units[1][thisSubject.units];
	helpVals[5] = thisSubject.customT;
	
	var TestType = (thisSubject.distance>0) ? 0:(thisSubject.time>0) ? 1:2;
	
	return "<b>Review test parameters. To adjust them, click \"Setup\".</b>" +
"<br />"+vitals(helpVals)+"<hr class=title style=\"border-style: dashed\">" +
"<table>" +
"<tr>" +
"<td VALIGN=\"TOP\">" +
"<img WIDTH=143 HEIGHT=241 NAME=\"test\" SRC=\"./images/ready_to_test.gif\" />" +
"</td>" +
"<td VALIGN=\"TOP\">"+scrHelp(TestType)+"</td>" +
"</tr>" +
"</table>";
	}

function scrHelp(arg)  {
	var ky = (IE || NN) ? "arrow key":"mouse button";
	var im = (IE || NN) ? "ky_hi":"ms";
	var ac = (IE || NN) ? "pressing":"clicking";
	var listType = (arg == null) ? "a":"1";
	
var HelpScreen = new Array();

HelpScreen[0] = "<span class='title'>Help</span>";
HelpScreen[1] = "Using the Shaw Gait Assessment tool requires a bit of dexterity and concentration.  Before testing actual clients, it is advisable to practice with the tool a few times with a volunteer subject, following the instructions below.<br />&nbsp;";
HelpScreen[2] = "<b>Setup Parameters:</b> On the \"Setup\" screen, enter client name or ID, age, gender, and your name (tester). Select metric or english units. Specify the test constraint [distance, time, or speed]. Click \"Test\".<br />&nbsp;";
HelpScreen[3] = "<b>Instructions for Distance-constrained Testing:</b>" +
"<img class=padleft align=right width=200 height=156 src=\"./images/"+im+"200156.gif\">" +
"<ol type='" + listType + "'>" +
"<li>Measure and mark starting and finish lines on the floor<span id='distance_here'>.</span> Instruct the client to begin walking toward the starting line.  <li>" +
"<b>Begin the test by "+ac+" the LEFT "+ky+" or RIGHT "+ky+" depending on which foot is first to make initial contact <u>BEYOND</u> the starting line</b> (see photo at right). <li>Keep up with the client's steps. <b>Capture each footfall</b> inside the measured walkway by "+ac+" the LEFT or RIGHT "+ky+" at the moment of foot contact.  <li>" +
"<b>To end the test press \"s\" (for STOP) the moment either foot makes initial contact <u>BEYOND</u> the finish line</b>, instead of pressing a final L or R "+ky+".";
HelpScreen[4] = "<li>Because testers sometimes inadvertently log superfluous steps at the start and/or finish line, you will be given the option of overlooking one or two inadvertently logged steps before SGA displays the test results.";
HelpScreen[6] = "<b>Instructions for Time-constrained Testing:</b>" +
"<ol type='" + listType + "'>" +
"<li>Mark a starting line only on the floor. Instruct the client to begin walking toward the starting line. <li>" +
"<b>Begin the test by "+ac+" the LEFT "+ky+" or RIGHT "+ky+" depending on which foot is first to make initial contact <u>BEYOND</u> the starting line.</b>" +
"<li>Keep up with the client's steps. <b>Capture each footfall</b> by "+ac+" the LEFT or RIGHT "+ky+" at the moment of foot contact.  <li>" +
"<b>When the \"Stop!\" sign appears on-screen, measure the actual distance travelled</b> by the client (in <span id='units_here'>either meters or feet, as initially specified</span>), first heel contact to last heel contact. <b>Enter this distance into SGA, and click \"OK\".</b>";
HelpScreen[7] = "<b>Instructions for Treadmill Testing:</b>" +
"<ol type='" + listType + "'>" +
"<li>Set up the client on the treadmill at <span id='speed_here'>the pre-selected speed.</span>" +
"<li>" +
"<b>Begin the test at your discretion by "+ac+" the LEFT "+ky+" or RIGHT "+ky+", concurrent with left (or right) foot contact</b>. <li>Keep up with the client's steps, "+ac+" the L or R "+ky+" at the moment of foot contact. <li>" +
"<b>Press \"s\" (for STOP) at your discretion -- concurrent with the final step of the test</b> -- in lieu of depressing the final L or R arrow key, and stop the treadmill.";
HelpScreen[8] = "<b>Review results</b> relative to gender-specific &amp; age-matched norms; these are reflected in bar graph height and percentage values. Compare performance to past tests for the client, when available. Add post-test comments. Print/save test results.  When appropriate adjust test parameters and/or testing conditions, then retest.";
HelpScreen[9] = "<br />Please contact us by <a href = 'mailto:boatful@comcast.net?subject=Shaw.Gait.Assessment.Inquiry.2004'>email</a> with specific SGA questions or comments.";

var res;
if (arg == null) res = HelpScreen[0] + "<table HEIGHT=100%>" +
"<tr>" +
"<td COLSPAN=2>" + HelpScreen[1] + "</td>" +
"</tr>" +
"<tr>" +
"<td VALIGN=TOP>1.</td>" +
"<td>" + HelpScreen[2] + "</td>" +
"</tr>" +
"<tr>" +
"<td VALIGN=TOP>2.</td>" +
"<td VALIGN=TOP>" + HelpScreen[3] + "</ol>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td VALIGN=TOP>&nbsp;</td>" +
"<td>" + HelpScreen[6] + "</ol>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td VALIGN=TOP>&nbsp;</td>" +
"<td>" + HelpScreen[7] + "</ol>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td VALIGN=TOP>3.</td>" +
"<td COLSPAN=2>" + HelpScreen[8] + "</td>" +
"</tr>" +
"</table>" + HelpScreen[9];
else if (arg == 0) res = HelpScreen[3] + HelpScreen[4] + "<li>" + HelpScreen[8] + "</ol>";
else if (arg == 1) res = HelpScreen[6] + "<li>" + HelpScreen[8] + "</ol>";
else if (arg == 2) res = HelpScreen[7] + "<li>" + HelpScreen[8] + "</ol>";
return res
}

function refreshSetupVars()  {
	//write units to the distance and speed layers
	var dst1 = getEl("dst"); dst1.innerHTML = units[0][thisSubject.units];
	var spd1 = getEl("spd"); spd1.innerHTML = units[1][thisSubject.units];
}

function ReadyToTest2(ths)  {
	if (ths.name == "client1") thisSubject.name = ths.value;
	if (ths.name == "rater1") thisSubject.rater = ths.value;
	myRe = /[0-9a-zA-Z]+/;
	if(thisSubject.name.match(myRe) && thisSubject.rater.match(myRe) && thisSubject.age > 0) {
		testingOK = true;
	} else {
		testingOK = false;
	}
	if (testingOK) {
		thisSubject.distance = document.setup.setD.selectedIndex;
		thisSubject.time = document.setup.setT.selectedIndex;
		thisSubject.speed = document.setup.setS.selectedIndex;
		thisSubject.customD = document.setup.setD[document.setup.setD.selectedIndex].value;
		thisSubject.customT = document.setup.setT[document.setup.setT.selectedIndex].value;
		thisSubject.customS = document.setup.setS[document.setup.setS.selectedIndex].value;
	}	
	bID = getEl("btn_4");
	bID.className = (testingOK) ? btn_StyleOptions[2]:btn_StyleOptions[0];
}

function JuggleConstraints (selectObj) {
	var selID = (selectObj.name == "setD") ? "0":(selectObj.name == "setT") ? "1":"2";
	if (selectObj.selectedIndex == 0) { 
		//user clicked N/A
		alert("You may not set all three test constraints to 'N/A'.");
		var retval = (selID == "0") ? thisSubject.distance : (selID == "1") ? thisSubject.time : thisSubject.speed;
		return retval
	} else {
		//determine whether click was a literal or 'other'
		if (selectObj.selectedIndex == selectObj.length-1) { 
			//user clicked "other"
			var sI_offset = -1; //set to zero if "other" clicked for first time
			var txtPrompt = (selID == "0") ? "walkway length (in "+units[0][thisSubject.units]:(selID == "1") ? "time (in seconds":"treadmill speed (in "+units[1][thisSubject.units];
			var newVal = prompt("Enter new " + txtPrompt + "):","");
			
			if(!newVal || newVal/newVal !=1) { 
				//cancelled or non-numeric input
				newVal=(selID == "0") ? thisSubject.distance : (selID == "1") ? thisSubject.time : thisSubject.speed;
				return newVal;
			} else {
				//rewrite the pulldown
				if (selectObj.length == optLen[selID]) { 
					//no 'other' value is already in list
					//create the "other" option as the last choice
					selectObj.length++;
					selectObj[selectObj.length-1].text = "other";
					sI_offset = 0;
				}
				//store newVaL as the second to last value
				selectObj[selectObj.length-2].value = newVal;
				selectObj[selectObj.length-2].text = newVal;
				if (selID == "1") selectObj[selectObj.length-2].text += " sec."
				//set the selected index...using the offset value of 0 or 1
				selectObj.selectedIndex = selectObj.selectedIndex + sI_offset;
			}
		}
		//set the other sI's to 0 and adjust all thisSubject values
		if (selID == "0") { 
			//adj distance value
			thisSubject.distance = selectObj.selectedIndex;thisSubject.customD = selectObj[selectObj.selectedIndex].value;
			document.setup.setT.selectedIndex = 0;thisSubject.time = 0;thisSubject.customT = "";
			document.setup.setS.selectedIndex = 0;thisSubject.speed= 0;thisSubject.customS = "";
		} else if (selID == "1") { 
			//adj time value
			thisSubject.time = selectObj.selectedIndex;thisSubject.customT = selectObj[selectObj.selectedIndex].value;
			document.setup.setD.selectedIndex = 0;thisSubject.distance = 0;thisSubject.customD = "";
			document.setup.setS.selectedIndex = 0;thisSubject.speed= 0;thisSubject.customS = "";
		} else { 
			//adj speed value
			thisSubject.speed = selectObj.selectedIndex;thisSubject.customS = selectObj[selectObj.selectedIndex].value;
			document.setup.setD.selectedIndex = 0;thisSubject.distance = 0;thisSubject.customD = "";
			document.setup.setT.selectedIndex = 0;thisSubject.time = 0;thisSubject.customT = "";
		}
	}
	return selectObj.selectedIndex
}

/*/////////////////////////////
READY TO TEST VARIABLES AND FUNCTIONS
AS OF MARCH 23, 2003
/////////////////////////////*/

//preserve the name attached to a given test
//until the test is overwritten!!
var testSubjectName;

var goalSpeed = new Array();// SPEED NORMS (cm/s)
//   values i calculate are 131.6,133.3,122.0,129.8,130.0,124.4,126.8,117.5
goalSpeed[0] = new Array("",132.3,135.1,122.7,131.6,132.8,125.2,127.7,118.2);// M
//   values i calculate are 106.8,123.9,122.9,127.2,123.3,108.6,113.9,110.0
goalSpeed[1] = new Array("",108.6,123.9,124.1,128.5,124.7,110.5,115.7,111.3);// F

var goalCad = new Array();// CADENCE NORMS (steps/min)
goalCad[0] = new Array("",128.4,121.2,118.8,120,120.6,117.6,117,114.6);// M
goalCad[1] = new Array("",118.2,125.4,124.8,127.8,129.6,121.8,123.6,121.8);// F

var goalStepLen = new Array();// STEP LENGTH NORMS (cm)
goalStepLen[0] = new Array("",61.5,66,61.6,64.9,64.7,63.5,65,61.5);// M
goalStepLen[1] = new Array("",54.2,59.3,59.1,59.7,57.1,53.5,55.3,54.2);// F

var conditionLab = new Array("Distance-constrained","Time-constrained","Treadmill");

var n;//RESET TO 0 FOR EACH NEW TEST
var m;//RESET TO 1 FOR EACH NEW TEST
var blnAcceptableTest = true;//NEVER DELETE THIS LINE!!
var leadFoot;
var nextFoot;

testReady = new Image(143,241);testReady.src = './images/ready_to_test.gif';
testGo = new Image(143,241);testGo.src = './images/footsteps_ani02.gif';
testStop = new Image(143,241);testStop.src = './images/stop2.gif';

var stepArray = new Array();

function vitals(helpValArray) {
	//return miscellany stored about the subject and test condditions
	var resV = "<table width=100%>";
	resV += "<td class=vitals>Subject: </td>" +
"<td valign='top'>" + thisSubject.name + "</td>" +
"<td width=12>&nbsp;</td>";
	resV += "<td class=vitals>Age: </td>" +
"<td nowrap valign='top'>" + thisSubject.customA + "</td>" +
"<td width=12>&nbsp;</td>";
	resV += "<td class=vitals>Rater: </td>" +
"<td valign='top'>" + thisSubject.rater + "</td>" +
"</tr>";
	
	resV += "<td class=vitals>Gender: </td>" +
"<td valign='top'>" + ((thisSubject.sex==0) ? "Male":"Female") + "</td>" +
"<td width=12>&nbsp;</td>";
	resV += "<td class=vitals>";
	
	if (thisSubject.distance) resV += "Distance: </td>" +
"<td nowrap valign='top'>" + helpValArray[1]+" " + helpValArray[3] + "</td>";
	if (thisSubject.time) resV += "Time: </td>" +
"<td nowrap valign='top'>" + helpValArray[5] + " seconds</td>";
	if (thisSubject.speed) resV += "Treadmill Speed: </td>" +
"<td nowrap valign='top'>" + helpValArray[2]+" "+helpValArray[4] + "</td>";
	resV += "<td width=12>&nbsp;</td>";
	resV += "<td class=vitals>Comment:</td>" +
"<td rowspan='3' valign='top'>" + thisSubject.comment + "</td>" +
"</tr>" +
"<tr>" +
"<td>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td>" +
"</td>" +
"</tr>" +
"</table>";
	return resV
}

function myKeyPress(e) { 
	if (navigator.appName == "Netscape") { 
		var charCode = e.which 
	 } else { 
		var charCode = e.keyCode 
	 }
	
	if (!thisSubject.time && (charCode==115 || charCode==83 || charCode==32)) {
	addOne(new Date(),nextFoot,true)
	}
	
	// left-arrow=37; right-arrow=39 (MSIE)
	if ((IE || NN) && charCode==37) addOne(new Date(),0);
	if ((IE || NN) && charCode==39) addOne(new Date(),1);
}

function addOne(dat,side,done,ky)  {
	if(done && n<2) {
		alert("\nToo few steps recorded.\nInvalid entry.");
		bID = getEl("btn_4"); mClick(bID,true);
	} else {
		if (n==0) {imgPicker('test',1);refVal = dat.getTime();leadFoot = side}
		var newVal = dat.getTime();
		elapsedT = newVal - refVal;
		//commit the next recorded keystroke in milliseconds relative to time=0
		stepArray[n] = new Array(side,newVal - refVal);
		if ((thisSubject.customT && elapsedT>thisSubject.customT*1000) || done) {
			//test ended
			LCAction = false;
			imgPicker('test',2);
			if (thisSubject.customD) {
				setTimeout('showIt("NixerPopup");document.whoa.finish.focus()',500);
				ctEl = getEl("NixStepCount");
				ctEl.innerHTML = (n+1) + " steps (total) were counted.";
				blnLockButtons = true;
			} else {
				compileData(elapsedT);
			}
		} else {
			n++;
			nextFoot = 1-side;
		}
	}
}

function nixSome(last,first)  {
	if (last != 'false') {
		n--; elapsedT = stepArray[n][1];
	}
	if (first != 'false') {
		elapsedT = stepArray[n][1]-stepArray[m][1];
		m++;
	}
	compileData(elapsedT);
}

//the layer reference must be browser specific
var layerRef;var endLayerRef;var styleRef;
var browser = navigator.appName;
var browserNum = parseInt(navigator.appVersion);

if ((browser == "Netscape") && (browserNum < 5))
{
	// Netscape 4.x
	layerRef = "document.layers['";
	endLayerRef = "']";
	styleRef = "";
}
else if ((browser == "Netscape") && (browserNum >= 5))
{
	// Netscape 6
	layerRef = "document.getElementById('";
	styleRef = ".style";
	endLayerRef = "')";
}
else
{
	// Internet Explorer
	layerRef = "document.all['";
	endLayerRef = "']";
	styleRef = ".style";
}
		
function showIt(layerName)
{
	eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'visible'");
}

function nixIt(layerName)
{
	eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'hidden'");
}

function imgPicker(imgName,indx)  {
	if (indx/indx == 1) { //numeric arg passed
		var opts = new Array("Ready","Go","Stop","","_hi");
		imgPicked = eval(""+imgName + opts[indx]+".src");
	} else { //string arg passed...
		//avoid DHTML element naming conflict 
		//in the spinout archive script...
		imgName = "IMG" + imgName;
		imgPicked = eval(indx + ".src");
	}
	document[imgName].src = imgPicked;
}

/*/////////////////////////////
COMPUTATIONAL VARIABLES AND FUNCTIONS
AS OF MARCH 23, 2003
/////////////////////////////*/

var blnTestSituation = true;blnTestSituation = false;
var editComm = '<button class="footnote" onclick="newComm()" style="cursor:pointer;">Add/Edit Comment</button>';

// 2010
// if(document.all && document.getElementById) editComm += ' <button class="footnote" onclick="CopyPasteDummy()" style="cursor:pointer;">Copy Result Summary to Clipboard</button>';

var stepLab = new Array("left","right");
var moyArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");

function compileData(eTime)  {
	var dx,totSteps,totTime,speed,allAvg,pace,stepLen,l,r,leftTot,rightTot,oopsCount,intVal,oopsStatement,leftAvg,rightAvg;
	if (thisSubject.customT) {
		while (!dx) {
			dx = prompt("How many "+units[0][thisSubject.units]+" did the client travel?","");
		}
	} else {
		if(thisSubject.customS) {
			dx = thisSubject.customS*eTime;
			// distance: (converted from mi or km to) feet or meters
			//taking into account the hours to sec conversion factor
			dx /= (thisSubject.units==0) ? 681.8:3600;
		} else {
			// dx in feet or meters
			dx = thisSubject.customD;
		}
	}
	totSteps = n+1-m; // adjusted steps (nearly = stepArray.length-1)
	totTime = eTime/1000; //secs;
	if(thisSubject.customS) {
		// mph or kph
		speed = thisSubject.customS;
	} else {
		// ft/min or m/min
		speed = dx/totTime*60;
	}
	allAvg = totTime/totSteps; // secs/step;
	pace = 60/allAvg; // steps/min;
	stepLen = dx/totSteps;// in meters or feet
	stepLen *= (thisSubject.units==0) ? 12:100;// convert to inches or cm
	stepLen = Math.round(stepLen*100)/100;
	
	//scrutinize the data stored for symmetry calculations
	l=0; r=0; leftTot=0; rightTot=0;oopsCount=0;
	
	for (i=m ;i <= n;i++)  {
		intVal = stepArray[i][1] - stepArray[i-1][1];
		
		if (stepArray[i][0]==0) {
			leftTot += intVal; l++;
		} else {
			rightTot += intVal; r++;
		}
		//added July2002, to alert users if ever
		//double LL or RR pressed inadvertently
		if (stepArray[i][0]-stepArray[i-1][0] == 0) oopsCount++;
	}
	if (oopsCount != 0) {
		oopsStatement = (oopsCount ==1) ? "step was":"steps were";
		alert(oopsCount + " double "+oopsStatement+" logged (e.g. L..L or R..R).\nIf this was unintentional, consider re-testing.");
	}
	//end of oopsCount code
	
	leftAvg = (leftTot/l)/1000;	
	rightAvg = (rightTot/r)/1000;
	
	var varience = 1- Math.min(leftAvg,rightAvg)/((leftAvg+rightAvg)/2);
	var varprcnt = Math.round(varience *1000)/10; //percent;
	if (leftAvg<rightAvg) varprcnt = "-"+varprcnt;
	
	displayData(Math.round(speed*100)/100, Math.round(pace*100)/100,Math.round(leftAvg*100)/100,Math.round(rightAvg*100)/100,varprcnt,stepLen,0,Math.round(eTime/10)/100,Math.round(dx));
}

barImgs = new Array("2x2_blu_dk.gif","2x2_blu_med.gif");

function barGif(altTxt,intNdx,numHt) {
return "<th valign=\"bottom\">" +
"<img alt=\""+altTxt+"\" align=bottom src=\"./images/"+barImgs[intNdx]+"\" height=\""+parseInt(numHt)+"\" width=\"40\" />" +
"</th>";
}

function tablesWizard() {
	//September 2004: now the first 3 bargraphs are constructed
	//by one function, for consistency and ease of code maintenance
	var res = "";
	cellstyle = " style = \"padding:0 1em;\"";
	for(tw=0;tw<arguments.length;tw++) {
		switch (arguments[tw][0]) {
		case "SPEED":
			testVal = arguments[tw][3][0];//speed
			if(thisSubject.units==2 && !thisSubject.customS) {
				//when SI selected on distance or time based tests
				//convert speed to cm/sec from m/min
				testVal = Math.round((testVal*1000)/60)/10;
			}
			if (thisSubject.customS) arguments[tw][0] = "TREADMILL"; 
		break;
		case "STEP LENGTH":
			testVal = arguments[tw][3][5];//step length
		break;
		case "CADENCE":
			cellstyle = " style = \"border-right:solid 1px;padding:0 1em;\"";
			testVal = arguments[tw][3][1];//cadence
			if(thisSubject.units==2 && !thisSubject.customS) {
				//when SI selected on distance or time based tests
				//convert cadence to hertz from steps/min
				testVal = Math.round(testVal*(100/60))/100;
			}
		break;
		}
		var testUnits = arguments[tw][2];
		var fudge = 200/arguments[tw][1];
		barHtTop = (arguments[tw][1]-testVal)*fudge;
		barHtBottom = fudge*testVal;
		
		var cell5 = "<tr>" +
		"<th nowrap>"+testVal+"<br />"+testUnits+"</th>" +
		"</tr>";
		var cell4 = "<tr>"+barGif(arguments[tw][0],0,barHtBottom)+"</tr>";
		var cell3 = (testVal>=arguments[tw][1]) ? "":"<tr>"+barGif(arguments[tw][0],1,barHtTop)+"</tr>";
		var cell2 = "<th>"+Math.round(testVal/arguments[tw][1]*100)+"%</th>" +
		"</tr>";
		var cell1 = "<tr>" +
		"<td width=\"40\" rowspan =";
		cell1 += (cell3) ? "4":"3";
		
		var iRegExp = new RegExp("([A-Za-z ])","g");
		label = arguments[tw][0].replace(iRegExp,"$1<br />");
		
		cell1 += " align=\"left\" valign=\"bottom\" style=\"padding-bottom:45px;padding-right:5px;\">\n" + label + 
		"</td>";
		res += "<td width=22% align=\"center\" valign=\"bottom\"" + cellstyle + ">\n<table border=0 cellpadding=0 cellspacing=0>"+cell1+cell2+cell3+cell4+cell5+"</table>\n</td>";
	}
	return res;
}

function displayData(speed,pace,advL,advR,varPrcnt,len,goalCat,tm,dx)  {


/*
Sept 2004: cleaner way to convert the Oberg norms
into units handy for comparison purposes
****** SEE DEVELOPERS NOTE, AT TOP OF THIS FILE ******
*/
ObergNorms = new Oberg(thisSubject.sex,thisSubject.age,thisSubject.units);

//A treadmill test tweak is all that is needed (just below)
if (thisSubject.customS) {
	ObergNorms.speed /= TmConvFactors[thisSubject.units];
	ObergNorms.speedLabel = TmConvLabels[thisSubject.units];
	if(thisSubject.units==2) {
		arguments[1] = Math.round((arguments[1]/60)*100)/100; 
		//convert cadence to hertz from steps/min
	}
}

var res = tablesWizard(new Array("SPEED",ObergNorms.speed,ObergNorms.speedLabel,arguments),new Array("STEP LENGTH",ObergNorms.steplength,ObergNorms.steplengthLabel,arguments),new Array("CADENCE",ObergNorms.cadence,ObergNorms.cadenceLabel,arguments));

//Sept 2004: I did not touch the code that displays L/R symmetry
//It is fairly complex, and may be overly convoluted
//It probably could stand to be cleaned up, sometime
var fudgesymm = 200/(advL+advR);

var Llonger = (advL > advR) ? true:false;
var noLonger = (advL==advR) ? true:false;

var lBarLabel = "LEFT LIMB ADVANCE TIME (AVERAGE)";
var rBarLabel = "RIGHT LIMB ADVANCE TIME (AVERAGE)";

var bar3 = new Array();
bar3[0] = (advL+advR); bar3[0] -= (Llonger) ? advL:advR;
bar3[3] = 0; bar3[3] += (Llonger) ? advR:advL;
bar3[1] = ((advL+advR)/2) - bar3[0];
bar3[2] = ((advL+advR)/2) - bar3[3];

for(i=0;i<=3;i++) {bar3[i] *= fudgesymm}

var cell7l = "<tr>" +
"<th NOWRAP>"+advL+"<br />sec</th>";
var cell7r = "<th NOWRAP>"+advR+"<br />sec</th>" +
"</tr>";

var cell6l = "<tr>"+barGif(lBarLabel,0,bar3[3]);
var cell6r = ""+barGif(rBarLabel,0,bar3[3])+"</tr>";

var Lcolor = 1; var Rcolor = 0;
if (Llonger) { Lcolor = 0; Rcolor = 1 }
if (noLonger) { Lcolor = 0 }

var cell5l = (noLonger) ? "":"<tr>"+barGif(lBarLabel,Lcolor,bar3[2]);
var cell5r = (noLonger) ? "":""+barGif(rBarLabel,Rcolor,bar3[2])+"</tr>";

Lcolor = 1; var Rcolor = 0;
if (Llonger) { Lcolor = 0; Rcolor = 1 }
if (noLonger) { Rcolor = 1 }

var cell4l = (noLonger) ? "":"<tr>"+barGif(lBarLabel,Lcolor,bar3[1]);
var cell4r = (noLonger) ? "":""+barGif(rBarLabel,Rcolor,bar3[1])+"</tr>";

var cell3l ="<tr>"+barGif(lBarLabel,1,bar3[0]);
var cell3r = ""+barGif(rBarLabel,1,bar3[0])+"</tr>";

var cell2l = "<th>L</th>";
var cell2r = "<th>R</th>" +
"</tr>";

var cell1 = "<tr>" +
"<td ROWSPAN=6 ALIGN=\"CENTER\" VALIGN=\"BOTTOM\" STYLE=\"padding: 0 10px 90px 0px;\">\nLIMB<br />ADVANCE<br />TIME<br />( L.A.T. )<br />" +
"<!--<br />(secs)-->" +
"</td>";

var table3 = "<table BORDER=0 CELLPADDING=0 CELLSPACING=0>"+cell1+cell2l+"<td ROWSPAN=6>&nbsp;&nbsp;&nbsp;&nbsp;</td>"+cell2r+cell3l+cell3r+cell4l+cell4r+cell5l+cell5r+cell6l+cell6r+cell7l+cell7r+"</table>";

var button3align = (blnTestSituation) ? "align=\"left\" nowrap":"";

//CONSOLIDATE ALL THE CONSTRUCTED BAR GRAPHS
var res = "<CENTER>" +
"<span class=\"title\">Temporal Gait Result for "+thisSubject.name+"</span>" +
"<br />" +
"<span class=\"instructions\">"+fleshDate()+"</span>" +
"<table width=\"400\" cellspacing=\"0\" cellpadding=\"0\" class=\"NoticeTable\" style=\"background-color: #CCCCCC;\">" +
"<tr>" +
res + 
"<td WIDTH=34% VALIGN=\"BOTTOM\" ALIGN=\"CENTER\" style=\"padding:0 1em;\">"+table3+"</td>" +
"</tr>" +
"</table>" +
"</CENTER>" +
"<p>";

//APPEND MISCELLANEOUS TEST PARAMETERS 
//AND A RESULTS SUMMARY INCLUDING VAR-PERCENT
res += "<table ALIGN=\"CENTER\" WIDTH=\"410\" BORDER=\"0\">"+constantVar(true,tm,dx)+
"<tr>" +
"<td NOWRAP CLASS=\"cVarLabel\">Asymmetry Index:</td>" +
"<td>"+varPrcnt+"% ( left vs. right L.A.T. )</td>" +
"</tr>" +
"<tr>" +
"<td NOWRAP CLASS=\"cVarLabel\">Name of tester:</td>" +
"<td>"+thisSubject.rater+"</td>" +
"</tr>" +
"<tr>" +
"<td  COLSPAN=\"2\">" +
"<DIV ID=\"MainComment\">" +
"<B>Comment: </B>" + thisSubject.comment + "</DIV>" +
"</td>" +
"</tr>";

// PRISM: 2010
// alert("speed:"+speed+" "+ObergNorms.speedLabel+"\nPace:"+pace+" steps/min\nadvL:"+advL+" sec.\nadvR:"+advR+" sec.\nAssymetry Index:"+varPrcnt+"% (left vs. right L.A.T.)\nStep Length:"+len+" "+ObergNorms.steplengthLabel+"\ngoalCat:"+goalCat+"\ntm:"+tm+" sec\ndx:"+dx+" ");
// alert(speed/ObergNorms.speed); //%
// alert(len/ObergNorms.steplength); //%
// alert(pace/ObergNorms.cadence); //%
// alert("<tr>"+constantVar(true,tm,dx));
/*
var browser_type=navigator.appName
// MSIE
if (browser_type=="Microsoft Internet Explorer") {
 copytext = "<table><tbody>" + "<tr>" + constantVar(true,tm,dx) + "</tbody></table>";
 holdtext.innerText = copytext;
}
*/




res += "<tr>" +
"<td COLSPAN=\"2\">"+editComm+"</td>" +
"</tr>" +
"</table>";
//APPEND THE GENDER AND AGE SPECIFIC NORM REFERENCE
res += "<p align=\"center\">Norms for ";
res += (thisSubject.sex==0) ? "males ":"females ";
res += "age "+thisSubject.customA;
//another reference =  http://moon.ouhsc.edu/dthompso/gait/knmatics/stride.htm#sources
res += " adapted from Oberg, Karsznia, and Oberg (1993)";

//APPEND THE RAW DATA IN A BORDERED TABLE
res += "\n"+rawData();

testSubjectName = thisSubject.name;
savedScreens[5] = res;
LCAction = false;
//enable the results button
bID = getEl("btn_5"); bID.className = "ready";
mClick(bID);
}

function smartNotes(n) {
	var ths = getEl("SmartNotes"+n);
	var originalComment = ths.innerHTML;
	var oldComment = (ths.innerHTML=="&nbsp;") ? "":ths.innerHTML;
	var newComment = prompt("Add/edit comment for step #"+n+" below:",oldComment);
	if (newComment == null) {
		//user pressed 'cancel'
		newComment = originalComment;
	} else if (!newComment) {
		//user left field blank
		newComment = "&nbsp;";
	}
	ths.innerHTML = newComment;
	var bdy = getEl("MainBody");
	savedScreens[5] = bdy.innerHTML;
}

function rawData() {
	trimSteps = n+2-m;
	var res = "<p align='center'>" +
"<span class='pre'>--<</span> "+trimSteps+" STEPS LOGGED <span class='pre'>>--</span>" +
"<table CELLPADDING=0 CELLSPACING=0 WIDTH=500>" +
"<tr>" +
"<th class='smartnotecell'>SIDE</th>" +
"<th  class='smartnotecell'>ELAPSED(sec)</th>" +
"<th class='smartnotecell'>NOTES (click cells below to add specific comments)</th>" +
"</tr>";
	var fudge1 = stepArray[m-1][1];
	for (x=(m-1);x<=n;x++) {
		res += "<tr>" +
"<td WIDTH='15' class='smartnotecell'>"+stepLab[stepArray[x][0]]+" </td>" +
"<td WIDTH='15' class='smartnotecell' style='padding-left:15px;'>"+Math.round((stepArray[x][1]-fudge1)/10)/100+"</td>" +
"<td WIDTH='470' class='smartnotecomment' onClick='smartNotes("+((x+2)-m)+")' ID='SmartNotes"+((x+2)-m)+"'>&nbsp;</td>" +
"</tr>";
	}
	return res+"</table>";
}

function fleshDate()  {
	var dat = new Date();
	dayt = dat.getTime();
	thisSubject.Yr = dat.getYear();// test yr
	thisSubject.Mm = moyArray[dat.getMonth()];// test mon
	thisSubject.Dt = (dat.getDate() < 10) ? "0" + dat.getDate() : dat.getDate();// test day
	thisSubject.Hr = (dat.getHours() < 10) ? "0" + dat.getHours() : dat.getHours();// test hour
	thisSubject.Mn = (dat.getMinutes() < 10) ? "0" + dat.getMinutes() : dat.getMinutes();// test min
	thisSubject.Sc = (dat.getSeconds() < 10) ? "0" + dat.getSeconds() : dat.getSeconds();// test sec
	return dat
}

function constantVar(resultPage,tm,dx)  {
	var cVar = "<td WIDTH='50%' NOWRAP CLASS='cVarLabel'>Test constant:</td>" +
"<td NOWRAP WIDTH='50%'>"
	if(thisSubject.customT) cVar += "Time = "+thisSubject.customT+" sec.";
	if(thisSubject.customD) cVar += "Distance = "+thisSubject.customD+" "+units[0][thisSubject.units];
	if(thisSubject.customS) cVar += "Treadmill speed = "+thisSubject.customS+" "+units[1][thisSubject.units];
	cVar += "</td>" +
"</tr>"
	
	cVar += (thisSubject.customS) ? "<tr>" +
"<td ROWSPAN='2' VALIGN='TOP' CLASS='cVarLabel'>Incidental Variables:</td>":"<tr>" +
"<td  CLASS='cVarLabel'>Dependent variable:</td>";
	var celDval = "<td>Distance = "+dx+" "+units[0][thisSubject.units]+"</td>"
	var celTval = "<td>Time = "+tm+" sec.</td>"
	
	cVar += (thisSubject.customT) ? celDval:celTval;
	if (thisSubject.customS) cVar += "<tr>"+celDval;
	cVar += "</tr>";
	return cVar
}

/*/////////////////////////////
UTILITY VARIABLES AND FUNCTIONS
AS OF MARCH 23, 2003
/////////////////////////////*/

var blnOffline = true;//blnOffline = false;

function newComm() {
	var nC = prompt("Add/edit comment here.",thisSubject.comment);
	if (nC == null) {
		nC = thisSubject.comment;
	} else {
		thisSubject.comment = nC;
	}
	WriteToEl("<strong>Comment: </strong>" + nC,"MainComment");
	var bdy = getEl("MainBody");
	savedScreens[5] = bdy.innerHTML;
}

function SaveTest2(txtButtonState)  {
	alert("Cannot save test(s) as the\nJava Security layer is disabled in the SGA online version.\n\nFeel free to print test(s) instead.");
	//\n\nClick the 'Download' button to get the full-featured SGA version, at no charge.
}

function addToFaves(){
	var url = window.location.href;
	var who = "Shaw Gait Assessment";
	if (IE && !IE4) {
	window.external.AddFavorite(url,who);
	} else {
	alert("Press control-D to create a bookmark\nfor the Shaw Gait Assessment");
	}
}

function ClipBoard()
{
alert("testing...");
}


function ClipBoard_testing()
{
// holdtext.innerText = copytext;
// Copied = holdtext.createTextRange();
// Copied = holdtext.createRange();
// Copied.execCommand("Copy");

// var pwin = external.menuArguments;
// var doc = pwin.document;
	holdtext.focus();
//	holdtext.select();
	
	
	
	
var sel = holdtext.select();
var rng = sel.createTextRange();
//   
//	var rng = selection.createRange();

   rng.execCommand("Copy");
   
}

// 2010
function CopyPasteDummy() {
	alert("Coming soon...");
	if(self.location.href == "http://theralink.com/apps/sga/indexx.html") CopyPaste();
}