// JavaScript Document

function showScholarshipInfo()
{
	/*---------------------------- Messages --------------------------*/

var msg = new Array();
	msg[0] = "If you have taken the ACT, please enter your score and your GPA to see if you qualify for our academic scholarships.";
	msg[1] = "Congratulations. You may qualify for a Regent's Scholarship, worth $11,000!";
	msg[2] = "Congratulations. You may qualify for a Regent's Scholarship, worth $8,500!";
	msg[3] = "Congratulations. You may qualify for an Achievement Award, worth $7,000!";
	msg[4] = "Congratulations. You may qualify for an Achievement Award, worth $3,500!";
	msg[5] = "We are sorry but your scores do not qualify you for any academic scholarships." +
					" However, Concordia offers talent awards in art, music, theatre, debate and athletics." +
					" For more info, call 1-800-535-5494 ext. 7233 or <a href=mailto:admiss@cune.edu>email us</a>.";

	//document.getElementById('calctext').innerHTML = msg[0];
	
	/*---------------------------- Grab Values --------------------------*/
	
	var gpas=document.form.gpa.value;
	gpas = gpas.replace(/ /g,"");
	var acts=document.form.act.value;
	var sats=document.form.sat.value;

	/*---------------------------- GPA Check --------------------------*/

	if(gpas.trim()==''){
		alert("Please enter a GPA.");
		document.form.gpa.focus();
		return;
	}else if(IsNumeric(gpas)){
		if(gpas <= 0 || gpas > 5){
			alert("Please enter a valid GPA.");
			document.form.gpa.focus();
			return;
		}else{
			gpas=parseFloat(gpas);
		}
	}else{
		alert("Please enter a valid GPA.");
		document.form.gpa.focus();
		return;
	}

	/*---------------------------- ACT/SAT Check --------------------------*/

	
	
	if(acts.trim()=='' && sats.trim()==''){
		alert("Please enter an ACT score or an SAT score.");
		document.form.gpa.focus();
		return;
	}
	
	if( (acts.trim() != '' ) ){
		if(!isInt(acts)){
			alert("Please enter a valid ACT score.");
			document.form.act.focus();
			return;
		}else if(acts < 0 || acts > 36){
			alert("Please enter a valid ACT score.");
			document.form.act.focus();
			return;
		}
	}
	
	if( (sats.trim() != '') ){
		if(!isInt(sats)){
			alert("Please enter a valid SAT score.");
			document.form.sat.focus();
			return;
		}else if(sats < 0 || sats > 1600){
			alert("Please enter a valid SAT score.");
			document.form.sat.focus();
			return;
		}
	}

	/*---------------------------- So far everything is OK --------------------------*/
	
	var nsats=0;
	var tier=0;
	var satEqu = new Array(   0, 500, 511, 581, 651, 701, 751, 801, 851, 891, 931, 971,1011,1051,1081,1121,1161,1201,1231,1271,1311,1351,1401,1451,1501,1551,1591,1601);
	var actEqu = new Array(        0,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36);

	if(sats.trim()!=''){
		for(i = 0; i < (satEqu.length - 1);i++ ){
			if(sats >= satEqu[i] && sats < satEqu[i+1])nsats=actEqu[i];
		}
	}
	
	newS=(acts>nsats ? acts : nsats);
	finalS=((gpas*25)+(newS*2.78));
	
	if(finalS<120)tier=5;
	if(finalS>=120&&finalS<145)tier=4;
	if(finalS>=145&&finalS<162)tier=3;
	if(finalS>=162&&finalS<175)tier=2;
	if(finalS>=175)tier=1;
	document.getElementById('calctext').innerHTML = msg[tier];
	
	//alert("ACT: " + acts + "\nSAT Eq: " + nsats + "\nNew Score: " + newS + "\nFinal Score: " + finalS);


	function IsNumeric(sText){
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	   for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if(ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
		}
	   return IsNumber;
	}
		
	function isInt(inputStr){
		if (inputStr == ""){
			return false;
		}else{
			for(var c = 0; c < inputStr.length; c++){
				var oneChar = inputStr.charAt(c);
				if (oneChar < "0" || oneChar > "9"){
					if (c == 0 && oneChar == "-"){
						   //it's alright
					}else{
						return false;
					}
				}
			}
		}
		return true;
	}
}



String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
