//-------------------------Start scripts for this page only
function localUnloadPg() {

}
//-----------------------------------------------------------
function localLoadPgSetup(){
loadAgeValues();
}
//-----------------------------------------------------------

function loadAgeValues(){

testStr=document.form.birthMonthField.value;
if((testStr!=null)&&(testStr>0)){
document.form.birthMonth.selectedIndex=testStr;
}


testStr=document.form.birthDayField.value;
if((testStr!=null)&&(testStr>0)){
document.form.birthDay.selectedIndex=testStr;
}


testStr=document.form.birthYearField.value;
if((testStr!=null)&&(testStr>0)){
document.form.birthYear.selectedIndex=testStr;
}


testStr=document.form.testMonthField.value;
if((testStr!=null)&&(testStr>0)){
document.form.testMonth.selectedIndex=testStr;
}


testStr=document.form.testDayField.value;
if((testStr!=null)&&(testStr>0)){
document.form.testDay.selectedIndex=testStr;
}


testStr=document.form.testYearField.value;
if((testStr!=null)&&(testStr>0)){
document.form.testYear.selectedIndex=testStr;
}
checkAgeSettings("0");

}

function calcAge(){

iBirthMonth=(document.form.birthMonth.selectedIndex);
iBirthDay=(document.form.birthDay.selectedIndex);
iBirthYear=parseInt(document.form.birthYear.options[document.form.birthYear.selectedIndex].text);

iTestMonth=(document.form.testMonth.selectedIndex);
iTestDay=(document.form.testDay.selectedIndex);
iTestYear=parseInt(document.form.testYear.options[document.form.testYear.selectedIndex].text);

//----------enter selected date values into hidden fields

document.form.birthMonthField.value=iBirthMonth;
document.form.birthDayField.value=iBirthDay;
document.form.birthYearField.value=document.form.birthYear.selectedIndex

document.form.testMonthField.value=iTestMonth;
document.form.testDayField.value=iTestDay;
document.form.testYearField.value=document.form.testYear.selectedIndex;

//--------------------------

diffYear=parseInt(iTestYear-iBirthYear);

diffMonth=iTestMonth-iBirthMonth;
if(diffMonth<0){
diffMonth+=12;
diffYear-=1;
}

diffDay=iTestDay-iBirthDay;
if(diffDay<0){
diffDay+=30;
diffMonth-=1;
if(diffMonth<0){
diffMonth+=12;
diffYear-=1;

}

}
allAgeValues="";
ageInMonths=(diffYear*12);

ageInMonths+=diffMonth;

if(diffDay>15){
ageInMonths++;
}
allAgeValues=diffYear+"-"+diffMonth+"-"+diffDay;
document.form.allAgeValues.value=allAgeValues;
document.form.age.value=ageInMonths;

ageCalStr=diffYear;

//-------Routine to prevent negative age values
if(diffYear<0){
alert("You have selected incorrect student birth and test dates that resulted in a negative age value.  Please re-enter date values.");

document.form.testMonth.selectedIndex=0;
document.form.testDay.selectedIndex=0;
document.form.testYear.selectedIndex=0;

document.form.birthMonth.selectedIndex=0;
document.form.birthDay.selectedIndex=0;
document.form.birthYear.selectedIndex=0;

document.form.ageVerification.value="";
return;
}
//---------------

verifyStr="At the time of testing, the student was "+diffYear+" years "+diffMonth+" months and "+diffDay+" days of age.  ";
verifyStr+="In months, the student's age was "+ageInMonths+".";

document.form.ageVerification.value=verifyStr;
}
//------------------------------

function checkAgeSettings(alertToken) {

numberOfAgeDropMenus=6;
for (iDropMenus=0; iDropMenus<numberOfAgeDropMenus; iDropMenus++) {
//if ((document.form.elements[iDropMenus].selectedIndex==0)&&(alertToken==1) ){
if (document.form.elements[iDropMenus].selectedIndex==0){
if(alertToken==1){
alertString="You have not yet selected  "+ageCalcPrompts[iDropMenus]+" from the date drop-lists.  ";
alertString+="Please make sure that testing and student birth dates have been fully entered before going on.";
alert(alertString);
}
return 0;
}
}
calcAge();
return 1;
}

ageCalcPrompts=new Array();

ageCalcPrompts[0]="the month in which the student was tested";
ageCalcPrompts[1]="the day on which the student was tested";
ageCalcPrompts[2]="the year in which the student was tested";
ageCalcPrompts[3]="the month in which the student was born";
ageCalcPrompts[4]="the day on which the student was born";
ageCalcPrompts[5]="the year in which the student was born";

//----------------------------------------------End scripts this page only