//-------------------------Start scripts for this page only
function localUnloadPg() {
;
}
//-----------------------------------------------------------------

function restoreSettings(){

for(i=0;i<document.form.selectAchTest.options.length;i++){
if(document.form.selectAchTest.options[i].defaultSelected==true){
document.form.selectAchTest.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.achTestScore.options.length;i++){
if(document.form.achTestScore.options[i].defaultSelected==true){
document.form.achTestScore.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.achTestMean.options.length;i++){
if(document.form.achTestMean.options[i].defaultSelected==true){
document.form.achTestMean.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.achTestSD.options.length;i++){
if(document.form.achTestSD.options[i].defaultSelected==true){
document.form.achTestSD.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.achTestR.options.length;i++){
if(document.form.achTestR.options[i].defaultSelected==true){
document.form.achTestR.options[i].selected=true;
break;
}
}

document.form.achTestName.value="";
document.form.achTestVerification.value="";


}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function localLoadPgSetup(){


if(buildCheckTestsList()==0){
pruneTestList("noName");
}
document.form.numTests.value=document.form.checkAchTests.options.length-1;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function buildCheckTestsList(){

testLimit=achFieldArray.length;

testsPresentFlag=0;

for(i=0;i<testLimit;i++){
if((document.form[achFieldArray[i]].value!=null)&&(document.form[achFieldArray[i]].value!="")){
testStr=document.form[achFieldArray[i]].value;
testName=testStr.substring(0,(testStr.indexOf("/")));
updateTestList(testName);
testsPresentFlag=1;
}
}
return testsPresentFlag;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function combineTestInfo(){

testInfoStr="No Value";

if(document.form.achTestName.value!=""){


//----
userTestName=document.form.achTestName.value;

while((userTestName.indexOf("/"))!=-1){
	hyphenLoc=userTestName.indexOf("/");
	userTestNameStr1=userTestName.substring(0, hyphenLoc);
	userTestNameStr2=userTestName.substring(hyphenLoc+1,userTestName.length);
	userTestName=userTestNameStr1+"-"+userTestNameStr2;	
	document.form.achTestName.value=userTestName;
}


//----


testInfoStr=document.form.achTestName.value;
testInfoStr+="/user";
testInfoStr+="/"+document.form.achTestScore.options[document.form.achTestScore.options.selectedIndex].text;
testInfoStr+="/"+document.form.achTestMean.options[document.form.achTestMean.options.selectedIndex].text;
testInfoStr+="/"+document.form.achTestSD.options[document.form.achTestSD.options.selectedIndex].text;
testInfoStr+="/"+document.form.achTestR.options[document.form.achTestR.options.selectedIndex].text;

}else{
//--------------------------------
if((document.form.selectAchTest.selectedIndex!=0)&&((document.form.selectAchTest.options[document.form.selectAchTest.options.selectedIndex].value)!="noValue")){
testInfoStr=document.form.selectAchTest.options[document.form.selectAchTest.options.selectedIndex].text;
testInfoStr+="/"+document.form.selectAchTest.options[document.form.selectAchTest.options.selectedIndex].value;
testInfoStr+="/"+document.form.achTestScore.options[document.form.achTestScore.options.selectedIndex].text;
}
}
//----------------------------------
return testInfoStr;
}

//----------------------------------------------------
function updateTestList(testName){
testOption=new Option(testName);
document.form.checkAchTests.options[document.form.checkAchTests.options.length]=testOption;
pruneTestList("noName");
document.form.numTests.value=document.form.checkAchTests.options.length-1;

}

//----------------------------------------------------
function removeTestListItem(){
if(document.form.checkAchTests.options.selectedIndex!=0){
testNameToRemove=document.form.checkAchTests.options[document.form.checkAchTests.options.selectedIndex].text;
testLimit=achFieldArray.length;

for (i=0;i<testLimit;i++){
testInfoStr=document.form[achFieldArray[i]].value;
testNameToCompare=testInfoStr.substring(0,(testInfoStr.indexOf("/")));

if(testNameToCompare==testNameToRemove){

confirmMsg="You have just selected a test, "+testNameToRemove+",\n";
confirmMsg+="to be removed from your list of selected tests.  Are you sure that you want to do this?";

if(confirm(confirmMsg)){
document.form.checkAchTests.options[document.form.checkAchTests.options.selectedIndex]=null;
document.form[achFieldArray[i]].value="";

document.form.numTests.value=document.form.checkAchTests.options.length-1;
restoreSettings();
}


for(i=0;i<document.form.checkAchTests.options.length;i++){
if(document.form.checkAchTests.options[i].defaultSelected==true){
document.form.checkAchTests.options[i].selected=true;
pruneTestList("noName");
break;
}
}
break;
}

}
}

}
//----------------------------------------------------
function pruneTestList(testName){

if(testName=="noName"){
if(document.form.checkAchTests.options.length==1){
document.form.checkAchTests.options[document.form.checkAchTests.options.selectedIndex].text="(No Achievment Tests Have Been Selected.)";
}else{
document.form.checkAchTests.options[document.form.checkAchTests.options.selectedIndex].text="(Check List of Previously Selected Achievement Tests)";
}
}
document.form.numTests.value=document.form.checkAchTests.options.length-1;

}
//----------------------------------------------------
function enterTest(){

testInfo=combineTestInfo();
//--------Alert if no test was selected
if(testInfo=="No Value"){
alert("You have not selected a test.");
restoreSettings();
return;
}

//------------------------------
testName=testInfo.substring(0,(testInfo.indexOf("/")));
achTestName=document.form.achTestName.value;

testConfirmMsg="You have selected the achievement test "+testName+".  ";

strSearchStart=testInfo.indexOf("/")+1;
strSearchEnd=testInfo.indexOf("/",strSearchStart);
testTypeStr=testInfo.substring(strSearchStart,strSearchEnd);
//document.form.achTestVerification.value=testTypeStr;

if (testTypeStr=="user"){
testConfirmMsg+="The name and statistics for this test were entered by the user:    ";
}
testScore=document.form.achTestScore.options[document.form.achTestScore.options.selectedIndex].text;
testMean=document.form.achTestMean.options[document.form.achTestMean.options.selectedIndex].text;
testSD=document.form.achTestSD.options[document.form.achTestSD.options.selectedIndex].text;
testR=document.form.achTestR.options[document.form.achTestR.options.selectedIndex].text;

testConfirmMsg+="The student score entered for this test is "+ testScore+".  ";

if (testTypeStr=="user"){
testConfirmMsg+="The mean for this user-entered measure is " +testMean+".  ";
testConfirmMsg+="The standard deviation entered for the test is " +testSD+".  ";
testConfirmMsg+="The internal consistency reliability co-efficient entered for the test is " +testR+".  ";
}

//---------------------

testLimit=achFieldArray.length;;

fieldsFullFlag=1;

for (i=0;i<testLimit;i++){

//--Check to see that test has not already been selected
storedTestInfoStr=document.form[achFieldArray[i]].value;
testToCompare=storedTestInfoStr.substring(0,(testInfo.indexOf("/")));

if(testName==testToCompare){
alert("You have already selected this test!");
fieldsFullFlag=0;
restoreSettings();
break;
}
//---------------

if((document.form[achFieldArray[i]].value==" ")||(document.form[achFieldArray[i]].value=="")||(document.form[achFieldArray[i]].value==null)){

document.form[achFieldArray[i]].value=testInfo;
fieldsFullFlag=0;
updateTestList(testName);
restoreSettings();
document.form.achTestVerification.value=testConfirmMsg;
break;
}

}
if(fieldsFullFlag==1){
msg="------------------------------------------------------------------------------------------------------------------------\n";
msg+="You have already selected the limit of "+testLimit+"  achievement tests. \n ";
msg+="To make room for more tests in your list, go to step 1 on this page.\n"
msg+="There you will find instructions on how to erase an existing test from \nyour list of selected measures.\n";
msg+="------------------------------------------------------------------------------------------------------------------------\n";
alert(msg);
restoreSettings();
}
}

achFieldArray=new Array();

achFieldArray[0]="achTest1Info";
achFieldArray[1]="achTest2Info";
achFieldArray[2]="achTest3Info";
achFieldArray[3]="achTest4Info";
achFieldArray[4]="achTest5Info";

//----------------------------------------------End scripts this page only