//-------------------------------------------------------------shared scripts

function onLoadPgSetup(){
localLoadPgSetup();
}

function onUnloadPg(){
//localUnloadPg();

}

function goToLocation(pageLoc){
	var newWindow=window.open();
	newWindow.location=pageLoc;
  }


function newPage(pageLoc){
localUnloadPg();

if(pageLoc=="newReport"){
if((confirm("You are about to erase all information that you have entered?  Do you want to erase all information and start over with a new report?"))==1){
	pageLoc="backgrnd.htm";
	for(i=0;i<document.form.length;i++){
	if(document.form.elements[i].type=="hidden"){
		document.form.elements[i].value="";
	}
    }
  }else{
    return;
}
}
if(pageLoc=="testreport.htm"){
	pageLoc=validateEssentialFields(pageLoc);
}

if(pageLoc=="testreport.htm"){
	document.form.target="_blank";
}else{
	document.form.target="_self";
}	

document.form.nextPage.value=pageLoc;

document.form.submit();
}

function validateEssentialFields(pageLoc){

//essentialFieldArray items 0-3 verify background page info----------------------------------------

arrayStartPt=0;
arrayEndPt=3;

absentValuesFlag=0;
msg="You have not yet entered the following background information about this student:\n";

for(i=arrayStartPt;i<=arrayEndPt;i++){

if((document.form[essentialFieldsArray[i]].value==" ")||(document.form[essentialFieldsArray[i]].value=="")||(document.form[essentialFieldsArray[i]].value==null)||(document.form[essentialFieldsArray[i]].value=="unidentified")){
absentValuesFlag=1;

//place default value of "unidentified" into field for passing to server
document.form[essentialFieldsArray[i]].value="unidentified";

msg+=backgrndMsgArray[i];
}
}
if(absentValuesFlag==1){
msg+="Click OK if you wish to go to the Background Information Page to enter this information.  Click CANCEL to go directly to the Test Report Page.";
if(confirm(msg)){
pageLoc="backgrnd.htm";
return pageLoc;
}
}

//---------------start of age page routine
ageFieldArrayPosition=4;
i=ageFieldArrayPosition;

if((document.form[essentialFieldsArray[i]].value==" ")||(document.form[essentialFieldsArray[i]].value=="")||(document.form[essentialFieldsArray[i]].value==null)||(document.form[essentialFieldsArray[i]].value=="unidentified")){
msg="You have not yet entered all needed information about student birth and testing dates.  This information is required to run a test score discrepancy report.  The program will now take you to the Test Date & Student Age Page.";
alert(msg);
pageLoc="age.htm";
return pageLoc;
}

//------------start of iqpage routine

arrayStartPt=5;
arrayEndPt=7;

absentValuesFlag=0;
msg="You have not yet selected at least one IQ measure, a requirement to run a test score discrepancy report.  The program will now take you to the IQ Test Selection Page.";

for(i=arrayStartPt;i<=arrayEndPt;i++){

if((document.form[essentialFieldsArray[i]].value!=" ")&&(document.form[essentialFieldsArray[i]].value!="")&&(document.form[essentialFieldsArray[i]].value!=null)&&(document.form[essentialFieldsArray[i]].value!="unidentified")){
absentValuesFlag=1;
}
}

if(absentValuesFlag==0){
alert(msg);
pageLoc="iqpg.htm";
return pageLoc;
}


//---------------start of achpage routine

arrayStartPt=8;
arrayEndPt=12;

absentValuesFlag=0;
msg="You have not yet selected at least one academic achievement measure, a requirement to run a test score discrepancy report.  The program will now take you to the Achievement Test Selection Page.";

for(i=arrayStartPt;i<=arrayEndPt;i++){
if((document.form[essentialFieldsArray[i]].value!=" ")&&(document.form[essentialFieldsArray[i]].value!="")&&(document.form[essentialFieldsArray[i]].value!=null)&&(document.form[essentialFieldsArray[i]].value!="unidentified")){
absentValuesFlag=1;
}
}

if(absentValuesFlag==0){
alert(msg);
pageLoc="achpg.htm";
return pageLoc;
}
//------------start of testprefs page routine

arrayStartPt=14;
arrayEndPt=14;
absentValuesFlag=0;

for(i=arrayStartPt;i<=arrayEndPt;i++){

if((document.form[essentialFieldsArray[i]].value!=" ")&&(document.form[essentialFieldsArray[i]].value!="")&&(document.form[essentialFieldsArray[i]].value!=null)&&(document.form[essentialFieldsArray[i]].value!="unidentified")){
absentValuesFlag=1;
}
}

if(absentValuesFlag==0){
document.form.testPrefs.value="5/1/2/4/";
}

//------------start of ruleouts page routine

arrayStartPt=13;
arrayEndPt=13;

absentValuesFlag=0;
msg="You have not yet selected at least one option from the Rule-Outs page, a requirement to run a test score discrepancy report.  The program will now take you to the Rule-Outs Page.";

for(i=arrayStartPt;i<=arrayEndPt;i++){

if((document.form[essentialFieldsArray[i]].value!=" ")&&(document.form[essentialFieldsArray[i]].value!="")&&(document.form[essentialFieldsArray[i]].value!=null)&&(document.form[essentialFieldsArray[i]].value!="unidentified")){
absentValuesFlag=1;
}
}

if(absentValuesFlag==0){
alert(msg);
pageLoc="ruleouts.htm";
return pageLoc;
}


//---------------end of page-checking routines


return pageLoc;
}


essentialFieldsArray=new Array();

essentialFieldsArray[0]="studentFirstNameField";
essentialFieldsArray[1]="studentLastNameField";
essentialFieldsArray[2]="examinerField";
essentialFieldsArray[3]="schoolField";

essentialFieldsArray[4]="age";

essentialFieldsArray[5]="IQTest1Info";
essentialFieldsArray[6]="IQTest2Info";
essentialFieldsArray[7]="IQTest3Info";

essentialFieldsArray[8]="achTest1Info";
essentialFieldsArray[9]="achTest2Info";
essentialFieldsArray[10]="achTest3Info";
essentialFieldsArray[11]="achTest4Info";
essentialFieldsArray[12]="achTest5Info";
essentialFieldsArray[13]="ruleOuts";
essentialFieldsArray[14]="testPrefs";

backgrndMsgArray=new Array();

backgrndMsgArray[0]="*the first name of the student tested.\n";
backgrndMsgArray[1]="*the last name of the student tested.\n";
backgrndMsgArray[2]="*the name of the examiner who completed testing.\n";
backgrndMsgArray[3]="*the school or program that the student attends\n";
//-----------------------------------------------end shared scripts