//-------------------------Start scripts for this page only
function localUnloadPg() {

}
//-----------------------------------------------------------------

function restoreSettings(){

for(i=0;i<document.form.selectIQTest.options.length;i++){
if(document.form.selectIQTest.options[i].defaultSelected==true){
document.form.selectIQTest.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.IQTestScore.options.length;i++){
if(document.form.IQTestScore.options[i].defaultSelected==true){
document.form.IQTestScore.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.IQTestMean.options.length;i++){
if(document.form.IQTestMean.options[i].defaultSelected==true){
document.form.IQTestMean.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.IQTestSD.options.length;i++){
if(document.form.IQTestSD.options[i].defaultSelected==true){
document.form.IQTestSD.options[i].selected=true;
break;
}
}

for(i=0;i<document.form.IQTestR.options.length;i++){
if(document.form.IQTestR.options[i].defaultSelected==true){
document.form.IQTestR.options[i].selected=true;
break;
}
}

document.form.IQTestName.value="";
document.form.IQTestVerification.value="";


}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function localLoadPgSetup(){

if(buildCheckTestsList()==0){
pruneTestList("noName");
}
document.form.numTests.value=document.form.checkIQTests.options.length-1;

}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function buildCheckTestsList(){

testLimit=iqFieldArray.length;

testsPresentFlag=0;

for(i=0;i<testLimit;i++){
if((document.form[iqFieldArray[i]].value!=null)&&(document.form[iqFieldArray[i]].value!="")){
testStr=document.form[iqFieldArray[i]].value;
testName=testStr.substring(0,(testStr.indexOf("/")));
updateTestList(testName);
testsPresentFlag=1;
}
}
return testsPresentFlag;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function combineTestInfo(){

testInfoStr="No Value";

if(document.form.IQTestName.value!=""){

//----
userTestName=document.form.IQTestName.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.IQTestName.value=userTestName;
}
//}

//----

testInfoStr=document.form.IQTestName.value;
testInfoStr+="/user";
testInfoStr+="/"+document.form.IQTestScore.options[document.form.IQTestScore.options.selectedIndex].text;
testInfoStr+="/"+document.form.IQTestMean.options[document.form.IQTestMean.options.selectedIndex].text;
testInfoStr+="/"+document.form.IQTestSD.options[document.form.IQTestSD.options.selectedIndex].text;
testInfoStr+="/"+document.form.IQTestR.options[document.form.IQTestR.options.selectedIndex].text;

}else{
//--------------------------------
if((document.form.selectIQTest.selectedIndex!=0)&&((document.form.selectIQTest.options[document.form.selectIQTest.options.selectedIndex].value)!="noValue")){
testInfoStr=document.form.selectIQTest.options[document.form.selectIQTest.options.selectedIndex].text;
testInfoStr+="/"+document.form.selectIQTest.options[document.form.selectIQTest.options.selectedIndex].value;
testInfoStr+="/"+document.form.IQTestScore.options[document.form.IQTestScore.options.selectedIndex].text;
}
}
//----------------------------------
return testInfoStr;
}

//----------------------------------------------------
function updateTestList(testName){
testOption=new Option(testName);
document.form.checkIQTests.options[document.form.checkIQTests.options.length]=testOption;
pruneTestList("noName");
document.form.numTests.value=document.form.checkIQTests.options.length-1;

}

//----------------------------------------------------
function removeTestListItem(){
if(document.form.checkIQTests.options.selectedIndex!=0){
testNameToRemove=document.form.checkIQTests.options[document.form.checkIQTests.options.selectedIndex].text;
testLimit=iqFieldArray.length;
startPtElemArray=9;

for(i=0;i<testLimit;i++){
testInfoStr=document.form[iqFieldArray[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.checkIQTests.options[document.form.checkIQTests.options.selectedIndex]=null;
document.form[iqFieldArray[i]].value="";
document.form.numTests.value=document.form.checkIQTests.options.length-1;
restoreSettings();
}


for(i=0;i<document.form.checkIQTests.options.length;i++){
if(document.form.checkIQTests.options[i].defaultSelected==true){
document.form.checkIQTests.options[i].selected=true;
pruneTestList("noName");
break;
}
}
break;
}

}
}

}
//----------------------------------------------------
function pruneTestList(testName){

if(testName=="noName"){
if(document.form.checkIQTests.options.length==1){
document.form.checkIQTests.options[document.form.checkIQTests.options.selectedIndex].text="(No IQ Tests Have Been Selected.)";
}else{
document.form.checkIQTests.options[document.form.checkIQTests.options.selectedIndex].text="(Check List of Previously Selected IQ Tests)";
}
}
document.form.numTests.value=document.form.checkIQTests.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("/")));
IQTestName=document.form.IQTestName.value;

testConfirmMsg="You have selected the IQ test "+testName+".  ";

strSearchStart=testInfo.indexOf("/")+1;
strSearchEnd=testInfo.indexOf("/",strSearchStart);
testTypeStr=testInfo.substring(strSearchStart,strSearchEnd);
//document.form.IQTestVerification.value=testTypeStr;

if (testTypeStr=="user"){
testConfirmMsg+="The name and statistics for this test were entered by the user:    ";
}
testScore=document.form.IQTestScore.options[document.form.IQTestScore.options.selectedIndex].text;
testMean=document.form.IQTestMean.options[document.form.IQTestMean.options.selectedIndex].text;
testSD=document.form.IQTestSD.options[document.form.IQTestSD.options.selectedIndex].text;
testR=document.form.IQTestR.options[document.form.IQTestR.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=iqFieldArray.length;
fieldsFullFlag=1;

for (i=0;i<testLimit;i++){

//--Check to see that test has not already been selected
storedTestInfoStr=testInfoStr=document.form[iqFieldArray[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[iqFieldArray[i]].value==" ")||(document.form[iqFieldArray[i]].value=="")||(document.form[iqFieldArray[i]].value==null)){

document.form[iqFieldArray[i]].value=testInfo;
fieldsFullFlag=0;
updateTestList(testName);
restoreSettings();
document.form.IQTestVerification.value=testConfirmMsg;
break;
}
//startPtElemArray++;
}
if(fieldsFullFlag==1){
msg="------------------------------------------------------------------------------------------------------------------------\n";
msg+="You have already selected the limit of "+testLimit+" IQ 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();
}
}

iqFieldArray=new Array();

iqFieldArray[0]="IQTest1Info";
iqFieldArray[1]="IQTest2Info";
iqFieldArray[2]="IQTest3Info";
//iqFieldArray[3]="IQTest4Info";
//iqFieldArray[4]="IQTest5Info";

//----------------------------------------------End scripts this page only