//Script written August 22, 2000 by Daniel Lloyd Northwest Missouri State University Web Team

function isEmpty(inputStr) {
	if (inputStr == "") {
		return true
	}
	else {
		return false
	}
}

function windowWriter(string, award, link) {  
	msgWindow=window.open('','','HEIGHT=300,WIDTH=400,toolbar=no,status=no,scrollbars=no')
	msgWindow.document.open("text/html","replace") 
	msgWindow.document.write("<HTML><HEAD><TITLE>Award Notification</TITLE></HEAD><BODY bgColor=#ffffff><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>") 	
	msgWindow.document.write("<P>You are eligible for the following award(s): </P>") 
	msgWindow.document.write("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><TD WIDTH=65%>")
	msgWindow.document.write("<B><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>Scholarship Name</TD><TD WIDTH=35%><B><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>Amount</TD></TR><TR><TD><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>")  
	msgWindow.document.write("<A HREF='" + link + "' target='blank'>" + string + "</A></TD><TD WIDTH=50%>")
	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>$" + award + "</TD></TR></TABLE>")
}

var rank 		
var classSize 			
var ACT
var verbSAT 		
var mathSAT 		
var SAT
var SATI

function validScoreData(elem){
	if(elem.name == "verbTxt" || elem.name == "mathTxt" || elem.name == "SATITxt") {
		if(parseInt(elem.value) % 10 != 0 && !isEmpty(elem.value)) {
			window.alert("Invaid SAT or SAT I Entry")
			elem.value = ""
			elem.focus()
		}
		else if(elem.name == "verbTxt" || elem.name == "mathTxt") {
			if((elem.value < 200 || elem.value > 800) && !isEmpty(elem.value)) {
				window.alert("Invaid SAT Entry")
				elem.value = ""
				elem.focus()
			}
		}
		else if(elem.name == "SATITxt"){
			if((elem.value < 400 || elem.value > 1600) && !isEmpty(elem.value)) {
				window.alert("Invaid SAT I Entry")
				elem.value = ""
				elem.focus()
			}
		}
	}
	else {
		if((elem.value > 36 || elem.value < 1) && !isEmpty(elem.value)) {
			window.alert("Invalid ACT Entry")
			elem.value = ""
			elem.focus()
		}
	}
}

function validForm(form) {
/*
	var check = 0
	var check2 = 0
	if(isEmpty(form.rankTxt.value)) {
		window.alert("Please fill out the Class Rank Field.")
		form.rankTxt.focus()
	}
	else {
		check++
	}
	if(isEmpty(form.classSizeTxt.value)) {
		window.alert("Please fill out the Class Size Field.")
		form.classSizeTxt.focus()
	}
	else {
		check++
	}
	if(isEmpty(form.ACTTxt.value)) {
		check2++
	}
	if(isEmpty(form.verbTxt.value) && isEmpty(form.mathTxt.value)) {
		check2++
	}
	else if((isEmpty(form.verbTxt.value) && !isEmpty(form.mathTxt.value)) || (!isEmpty(form.verbTxt.value) && isEmpty(form.mathTxt.value))) {
		check2 = check2 + 3
	}
	if(isEmpty(form.SATITxt.value)) {
		check2++
		SATI = 0
	}
	else {
		SATI = parseInt(form.SATITxt.value)
	}
	if(check2 != 2) {
	  window.alert("Please fill out one and only one of the following sections: 1. ACT or 2. SAT 1 or 3. SAT. ")
      window.alert("Please fill out one and only one of the following sections: 1. ACT or 2. SAT 1")
	}
	rank = parseInt(form.rankTxt.value)
	classSize = parseInt(form.classSizeTxt.value)
	ACT = parseInt(form.ACTTxt.value)
	verbSAT = parseInt(form.verbTxt.value)
	mathSAT = parseInt(form.mathTxt.value)
	SAT = verbSAT + mathSAT
	if(rank > classSize){
		window.alert("Your class rank cannot be greater than your class size.")
		check2 = check2 + 3
	}
	if(check == 2 && check2 == 1) { 
	if(check == 2 && check2 == 2) {
		processData(document.AdmIndexFrm)
	}
*/

	if(isEmpty(form.rankTxt.value)) {
		window.alert("Please fill out the Class Rank Field.")
		form.rankTxt.focus()
	} 
	else if(isEmpty(form.classSizeTxt.value)) {
		window.alert("Please fill out the Class Size Field.")
		form.classSizeTxt.focus()
	}
	else if(parseInt(form.rankTxt.value) > parseInt(form.classSizeTxt.value)){
		window.alert("Your class rank cannot be greater than your class size.")
		form.rankTxt.focus()
	}
	else if (isEmpty(form.ACTTxt.value) && isEmpty(form.SATITxt.value)) {
		window.alert("Please fill out either your ACT or SAT 1 score.")
		form.ACTTxt.focus()
	}
	else if (!(isEmpty(form.ACTTxt.value) || isEmpty(form.SATITxt.value))) {
		window.alert("Please submit only one score; either ACT or SAT 1, but not both.")
		form.ACTTxt.focus()
	}
	else
	{
		ACT = parseInt(form.ACTTxt.value)
		SAT = parseInt(form.SATITxt.value)
		rank = parseInt(form.rankTxt.value)
		classSize = parseInt(form.classSizeTxt.value)
		processData(document.AdmIndexFrm)
	}
}

function processData(form) {
	var rankPercentile
	var ACTPercentile
	var admIndex

	function scores(satI, act)	{
		this.satI = satI
		this.act = act
	}
	
        info = new Array();
        info[0] = new scores(0,0)
        info[1] = new scores(400,9)
        info[2] = new scores(410,10)
        info[3] = new scores(510,11)
        info[4] = new scores(560,12)
        info[5] = new scores(620,13)
        info[6] = new scores(670,14)
        info[7] = new scores(720,15)
        info[8] = new scores(770,16)
        info[9] = new scores(820,17)
        info[10] = new scores(860,18)
        info[11] = new scores(900,19)
        info[12] = new scores(940,20)
        info[13] = new scores(980,21)
        info[14] = new scores(1020,22)
        info[15] = new scores(1050,23)
        info[16] = new scores(1090,24)
        info[17] = new scores(1130,25)
        info[18] = new scores(1170,26)
        info[19] = new scores(1210,27)
        info[20] = new scores(1250,28)
        info[21] = new scores(1290,29)
        info[22] = new scores(1330,30)
        info[23] = new scores(1360,31)
        info[24] = new scores(1400,32)
        info[25] = new scores(1440,33)
        info[26] = new scores(1490,34)
        info[27] = new scores(1540,35)
        info[28] = new scores(1600,36)
        info[29] = new scores(10000,99)
	
	if(SATI == 0) {
		for(var i = 0; i < 29; i++) {
			if(SAT < info[i + 1].sat && SAT >= info[i].sat) 
				ACT = info[i].act
		}
	}
	else {
		for(var i = 0; i < 29; i++) {
			if(SATI < info[i + 1].satI && SATI >= info[i].satI)
				ACT = info[i].act
		}
	}

	if (ACT == 0) 
		ACTPercentile = 0
	else if (ACT == 99) 
		ACTPercentile = 0
	else if (ACT >= 31 && ACT <= 36) 
		ACTPercentile = 99
	else if (ACT == 30) 
		ACTPercentile = 98
	else if (ACT == 29)
		ACTPercentile = 96
	else if (ACT == 28) 
		ACTPercentile = 94
	else if (ACT == 27) 
		ACTPercentile = 91
	else if (ACT == 26) 
		ACTPercentile = 87
	else if (ACT == 25) 
		ACTPercentile = 83
	else if (ACT == 24) 
		ACTPercentile = 78
	else if (ACT == 23) 
		ACTPercentile = 72
	else if (ACT == 22) 
		ACTPercentile = 66
	else if (ACT == 21) 
		ACTPercentile = 58
	else if (ACT == 20) 
		ACTPercentile = 51
	else if (ACT == 19) 
		ACTPercentile = 42
	else if (ACT == 18) 
		ACTPercentile = 34
	else if (ACT == 17) 
		ACTPercentile = 26
	else if (ACT == 16) 
		ACTPercentile = 19
	else if (ACT == 15) 
		ACTPercentile = 13
	else if (ACT == 14) 
		ACTPercentile = 8
	else if (ACT == 13) 
		ACTPercentile = 4
	else if (ACT == 12)
		ACTPercentile = 2
	else if (ACT < 12) 
		ACTPercentile = 1
		
	rankPercentile = (1 - (rank/classSize)) * 100
	admIndex = Math.round(ACTPercentile + rankPercentile)
	form.displayTxt.value = admIndex
	
	var fma = "/finaid/freshman2.htm#Merit"
	var reg = "/finaid/freshman2.htm#Regents"
	var hon = "/finaid/freshman2.htm#Super"
	var exc = "/finaid/freshman2.htm#Excellence"
	
	if ((admIndex > 184) || (ACTPercentile >= 94)) {
		windowWriter("Distinguished Scholar", 2500, hon)
		if (admIndex > 184)
			msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>You may compete for the <A HREF=/finaid/freshman.htm#onlinepres' target='blank'>President's Scholarship of Merit.</a></P></FONT>")
		//if (!(admIndex > 184) && (ACTPercentile >= 94))
		//	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>* Scholarships awarded based on ACT scores will require a 2.00 minimum GPA.</P></FONT>")
	}
	else if ((admIndex >= 175 && admIndex <= 184) || (ACTPercentile == 91))
	{
		windowWriter("Academic Excellence Scholar", 2000, exc)
		//if (!(admIndex >= 175 && admIndex <= 184) && (ACTPercentile == 91))
		//	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>* Scholarships rewarded based on ACT scores will require a 2.00 minimum GPA.</P></FONT>")
	}
	else if ((admIndex >= 140 && admIndex <= 174) || (ACTPercentile >= 72 && ACTPercentile <= 87))
	{
		windowWriter("Tower Scholar", 1500, reg)
		//if (!(admIndex >= 140 && admIndex <= 174) && (ACTPercentile >= 72 && ACTPercentile <= 87))
		//	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>* Scholarships awarded based on ACT scores will require a 2.00 minimum GPA.</P></FONT>")
	}
	else if ((admIndex >= 100 && admIndex <= 139) || (ACTPercentile >= 58 && ACTPercentile <= 66))
	{
		windowWriter("Freshman Merit Award", 500, fma)
		//if (!(admIndex >= 100 && admIndex <= 139) && (ACTPercentile >= 58 && ACTPercentile <= 66))
		//	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>* Scholarships awarded based on ACT scores will require a 2.00 minimum GPA.</P></FONT>")
	}
	
	
	if (admIndex >= 140 || ACTPercentile >= 72) {
		msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>You may also be eligible for the following out of state award(s): </P></FONT>") 
		msgWindow.document.write("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><TD WIDTH=65%>")
		msgWindow.document.write("<B><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>Scholarship Name</FONT></B></TD><TD WIDTH=35%><B><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>Amount</TD></TR><TR><TD><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>")
		msgWindow.document.write("<A HREF=/finaid/freshman2.htm#Out' target='blank'>Out-of-State Award</A></FONT></TD><TD WIDTH=50%>")
		msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>*$2361</FONT></TD></TR>")
		msgWindow.document.write("<TR><TD><FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>")
		msgWindow.document.write("<A HREF=/finaid/freshman2.htm#Midwest' target='blank'>Midwest Student Exchange Program</A></FONT></TD><TD>")
		msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'>*$2361</FONT></TD></TR></TABLE>")
		msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><p><i>*All 2008-09 values based on 30 credit hours.</i></p></FONT></BODY></HTML>")
	}
	//else {
	//	msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><p><i><br>All 2008-09 values based on 30 credit hours.</i></p></FONT></BODY></HTML>")
	//	msgWindow.document.close()
	//}
	
	if ((admIndex >= 100) || (ACTPercentile >= 58))
		msgWindow.document.write("<FONT FACE='Arial, Geneva, Helvetica' SIZE='-1'><P>Students must have a minimum 2.00 high school gpa to be eligible for admission-based scholarships.</P></FONT>")
	msgWindow.document.close()
}