/*This GPA Calculator and Forecaster was written and designed by Fred Carpenter and Kou Vang
 fred.carpenter@metrostate.edu vangko02@go.metrostate.edu
 Under testing please contact for distribution
 Please leave this notice in place
 Creative Commons License CYNCSA
 
 Last Updated 5/6/09
 
 Script modified heavily for Inver Hills Community College, please contact original authors for original script.
 Jason Lachowsky 11/30/09
 
 JavaScript, DHTML Tooltips developed by Walter Zorn
 For more information on how to use this tool, please visit
 http://www.walterzorn.com/tooltip/tooltip_e.htm\
 
 software used for video capture: 
 RenderSoft CamStudio version 2.00
 http://www.camstudio.org/
 
 Magnifying Glass (free) version 1.0
 http://www.workerscollection.com/wcollect/english/html/index.html
 -->
 
 <!-- 
 /******************* How to Search For Codes *********************** 
 
 This html document has been divided into sections.  Sections are titled "Section" 
 followed by a number (e.g Section 1).  Dot notation is used to number subsections
 (e.g. a subsection of Section 1 would be numbered Section 1.1).  A section may or 
 may not have subsections.  
 Due to the nature of this document, sections may not be found in ascending order,
 but rather disjointed.  Sections are divided according to related components and/or
 functions.  To find a particular section of code, use CTRL + F to search for that
 section.
 
 ********************************************************************/
 
 /***************************** Contents ****************************
 
 Section 0 - Title and Links
 	Section 0.1 - Blue Left Divide
    Section 0.2 - Top Banner
    Section 0.3 - Important Information and Links
 Section 1 - Current Information
 	Section 1.1 - Transcript Summary Image
    Section 1.2 - Data Entry and Tooltips
    Section 1.3 - Warning Messages
 
 Section 2 - Semester Forecast
 	Section 2.1 - Semester Course Entry Table
    Section 2.2 - Semester and Cumulative Forecasts
    Section 2.3 - Warning Messages
    
 Section 3 - Optional Report
 
 Section 4 - Input Error Messages
 
 Section 5 - Output Report
 	Section 5.1 - Displaying Current Information
    Section 5.2 - Displaying Semester Forecasted Information
    Section 5.3 - Number of Credits to Complete in Order to Reach Desired Cumultive GPA
    	Section 5.3.1 - Credits per Grade Graph Table
        Section 5.3.2 - Credits per Grade Narratives
    Section 5.4 - Number of Credits to Complete in Order to Reach Desired Cumulative Completion Rate
    	Section 5.4.1 - Credits per Rate Graph Table
        Section 5.4.2 - Credits per Rate Narratives
 
 ********************************************************************/
 
/*********************** Functions ****************************************************

truncate() : truncates a floating point number to two decimal places

generate_report() : generates a copy of input data from Current Information; a copy
					of calculated GPAs and Completion Rates from Semester Forecast; a Credits per Grade
                    graph; a Credits per Grade Narrative table; a Credits per Completion Rate graph; a
                    Credits per Completion Rate Narrative table; and a new page opened in a new window
                    displaying these informations.

getTotalSemesterCredits() : add up the number of credits entered in Semester
							Forecast.  Main usage is for checking the number of current credits entered in
                            Current Information against the total number of credits entered in Semester Forecast.

runCheck() : check for missing inputs and for unmatching entered GPA/Completion Rate 
			 and calculated GPA/Completion Rate.  returns true if any one condition is met, else 
             returns false.

grades() : calculates Semester GPA, Semester Completion Rate, new Cumulative GPA and Completion Rate for Semester Forecast.

clearForm() : set all textfields, textareas, checkboxes, etc to default values blank, first choice, disabled, etc).

determineStatuses() : determines a student's academic standing coming into this form (Current Information).

determineStatuses2() : This function is used to determine the second set of messages to display (Semester Forecast).

calculatecompletionrate() : calculates a student's completion rate based on entered data local cumulative earned credits and attempted credits.

currentcumcomplrate() : check for illegal completion rates and set the current completion rate textfield with the calculated completion rate.

compareGPA() : compares the GPA entered for local cumulative gpa with a calculated gpa.

genable1() through genable6() : enable/disable the grade dropdown menus and repeat checkboxes if credits are entered for a course in Semester Forecast.

enable1() through enable5() : enable/disable previous grade dropdown menus if repeat checkboxes are checked/uncheck.

***********************************************************************************************************************************************/

/*************************** Component Id's **********************************************

**Current Information Components:

local_cum_crattempted : local cumulative attempted credits

local_cum_crearned : local cumulative earned credits

local_cum_gpacredits : local cumulative gpa credits

local_cum_gpapoints : local cumulative gpa points

local_cum_gpa : local cumulative gpa

current_credits : credits currently being taken or registered credits for an upcoming 

semester(s).

local_cum_comprate : calculated local cumulative completion rate

clear : button to clear all components on the page

message_display : display area for academic standing warning messages.


**Semester Forecast Components: 

credits1 - credits6 : number of credits for courses 1 - 6

grade1 - grade6 : letter grade for courses 1 - 6 

repeat1 - repeat6 : checkbox to mark a course as a repeat course for course 1 - 6

previous_grade1 - previous_grade6 : letter grade received for this course previously

calculate : button to calculate gpa's and completion rates

forecast_sem_gpa : semester gpa for the courses entered

forecast_sem_comprate : semester completion rate for the courses entered

forecast_cum_gpa : new cumulative gpa that includes the courses entered

forecast_cum_comprate : new cumulative completion rate that includes the courses 

entered.

message_display2 : display area for academic standing warning messages.


**Optional Report Components: 

goal : a desired gpa goal

submit : button to generate report

*********************************************************************************************/

var table = '';
var newline = String.fromCharCode(13);
var numcredits = '';
var gmaintain = '';
var letter_grade = '';



//fucntion to truncate to 2 decimal places
function truncate(a_number) {
	var the_number = a_number.toFixed(3);
	var numStr = "" + the_number;
	var numStr = numStr.substring(0, numStr.length-1);
	return numStr;
}
			   
function generate_report() { 
	var num_rows = 2;
	var num_cols = 7;
	var strCalculatedGPA = truncate(parseFloat(document.getElementById('local_cum_gpacredits').value) / parseFloat(document.getElementById('local_cum_gpapoints').value));
	var strCompletionRate = truncate(parseFloat(document.getElementById('local_cum_crearned').value) / (parseFloat(document.getElementById('local_cum_crattempted').value) - parseFloat(document.getElementById('current_credits').value)) * 100);

	var isError = runCheck();
	
	if (isError == false) {
	
		if (document.getElementById('goal').value=='' | document.getElementById('goal').value>4) {
			alert('You must enter a target cumulative GPA not over 4.0');
		}	
		else if(document.getElementById('goal').value <= strCalculatedGPA) {
			alert('Your goal \"'+document.getElementById('goal').value+'\" must be higher than your current cumulative \"'+strCalculatedGPA+'\".');
		}
	
		else {
		
	<!-- Section 5.3 - Number of Credits to Complete in Order to Reach Desired Cumultive GPA -->
	
	<!-- Section 5.3.1 - Credits per Grade Graph Table -->
				table = "<table width='100%' bgcolor='#E1EAFB' style='border: 1px solid #CBCC8A; background-color: #FDFDED; font-size: 18px; line-height: 18px'><tr><td><span class='style5'>Your Current Cumulative GPA is: "+document.getElementById('local_cum_gpa').value+"<br>Your target cumulative GPA is: "+document.getElementById('goal').value+"</span></td></tr><br>";
			
				table += "<tr><td><center><TABLE class='style5' WIDTH='200' CELLSPACING='1' CELLPADDING='1' BORDER='1'>" + newline;
		
			// Each Row
			for ( var x = 1; x <= num_rows; x++ ) { 
				table += "    <TR>" + newline;
					if (x == 1) {
						table += "        <td valign='bottom' align='right'>Credits: </td>" + newline;
					}
					else {
						table += "        <td valign='bottom' align='right'>Grade: </td>" + newline;
					}
		
					// Each Column
					for ( var c = 1; c <= num_cols; c = c + 1 ) { 
						if(c == 1) {
								gmaintain = 4;
								letter_grade = 'A';
							}
							else if(c == 2) {
								gmaintain = 3.67;
								letter_grade = 'A-';
							}
							else if(c == 3) {
								gmaintain = 3.33;
								letter_grade = 'B+';
							}
							else if(c == 4) {
								gmaintain = 3.0;
								letter_grade = 'B';
							}
							else if(c == 5) {
								gmaintain = 2.67;
								letter_grade = "B-";
							}
							else if(c == 6) {
								gmaintain = 2.33;
								letter_grade = "C+";
							}
							else if(c == 7) {
								gmaintain = 2.0;
								letter_grade = "C";
							}
		
							numcredits=((document.getElementById('local_cum_gpapoints').value - (document.getElementById('goal').value * document.getElementById('local_cum_gpacredits').value)) / (document.getElementById('goal').value - gmaintain));
							numcredits=Math.ceil(numcredits);
							if(x==1) {
				
				//creating the columns here
							
							if(numcredits>0) {
								if(numcredits>=120) {
									numcredits = 120 + "+";
								}
								
								//table += numcredits;
							
							table += "        <td valign='bottom' align='center' width='30'>"+numcredits+"<br>" +newline;
							table += "           <img src='GPACalculator/poll.gif' width='30' height='"+numcredits+"' /></td>" + newline;
							table += "        </TD>" + newline;
							gmaintain = '';					
														
							}		
							
						}
						else{
							if(numcredits>0) {
							
							
							table +="			<td valign='bottom' align='center' width='30'>"+letter_grade+"</td>" + newline;
							letter_grade = '';
							}
						}
				   }//end for and end column creation
		
				   table += "    </TR>" + newline;
			}//end row creation
		
				   table += "</TABLE></center>" + newline;  //end gpa graph table
				   
	<!-- Section 5.3.2 - Credits per Grade Narratives -->		
		   
				   //creating narrative gpa table
				   table += "<table class='style5'>" + newline;
				   
				   for(var k = 1; k <= num_cols; k = k + 1) {
					   table += "<tr>" + newline;
					   if(k == 1) {
								gmaintain = 4;
								letter_grade = 'A';
							}
							else if(k == 2) {
								gmaintain = 3.67;
								letter_grade = 'A-';
							}
							else if(k == 3) {
								gmaintain = 3.33;
								letter_grade = 'B+';
							}
							else if(k == 4) {
								gmaintain = 3.0;
								letter_grade = 'B';
							}
							else if(k == 5) {
								gmaintain = 2.67;
								letter_grade = "B-";
							}
							else if(k == 6) {
								gmaintain = 2.33;
								letter_grade = "C+";
							}
							else if(k == 7) {
								gmaintain = 2.0;
								letter_grade = "C";
							}
		
							numcredits=((document.getElementById('local_cum_gpapoints').value - (document.getElementById('goal').value * document.getElementById('local_cum_gpacredits').value)) / (document.getElementById('goal').value - gmaintain));
							numcredits=Math.ceil(numcredits);
							if(numcredits>0) {
								if(numcredits>=120) {
									numcredits = 120 + "+";
								}
								
								//table += numcredits;
							
							table += "        <td valign='bottom' align='left'>You will need " + numcredits + " credits each with a(n) " + letter_grade + " to reach your cumulative GPA goal." + newline;
							table += "        </TD></TR>" + newline;
							gmaintain = '';	
							letter_grade =  '';				
														
							}//end if(numcredis>0)
							
				   }//end for
				   table += "</table>" + newline; // end narrative gpa table 
				   
				   table += "</td><td><table class='style5' width='109' border='0' cellspacing='1' cellpadding='1'><tr><td><div align='left'><b>Grade</b></div></td><td><div align='left'><b>GPA</b></div></td></tr><tr><td><div align='left'>A</div></td><td><div align='left'>4.0</div></td></tr><tr><td><div align='left'>B</div></td><td><div align='left'>3.00</div></td></tr><tr><td><div align='left'>C</div></td><td><div align='left'>2.00</div></td></tr><tr><td><div align='left'>D</div></td><td><div align='left'>1.00</div></td></tr><tr><td><div align='left'>F</div></td><td>0</td></tr></table></td>";
				   
				   table += "</tr></table>";  //end gpa section table
	
	<!-- Section 5.4 - Number of Credits to Complete in Order to Reach Desired Cumulative Completion Rate -->
	
				   //completion rate section		   
				   var table2 = "<table width='100%' bgcolor='#E1EAFB' style='border: 1px solid #CBCC8A; background-color: #FDFDED; font-size: 18px; line-height: 18px'>";
				   table2 += "<tr><td class='style5'>Your Local Cumulative Completion Rate is "+document.getElementById('local_cum_comprate').value+"</td></tr>";
				   
				   //prints a message telling students to seek advisory for any completion rate goal above 90%
				   if(strCompletionRate > 90) {
						table2 += "<tr><td class='style5'>Your local cumulative completion rate is above 90%.  Please contact your advisor for any questions on meeting a higher completion rate goal.</td></tr>" + newline;
				   }
								   
				   table2 += "<tr><td>";  //column 1 of section table
				   
	<!-- Section 5.4.1 - Credits per Rate Graph Table -->
	
				   //completion rate table (with bars)
				   table2 += "<TABLE class='style5' WIDTH='300' CELLSPACING='1' CELLPADDING='1' BORDER='1' bordercolor='#CBCC8A' 'ALIGN='center'>" + newline;
				   
				   //row 1 of completion rate table; row with % and gif
				   table2 += "<tr><td valign='bottom' align='left' width='100'>Cumulative Completion<br>Rate</td>"; 
				   
				   var standpercentage = 0.6666;
				   var desirepercentage = 0.70;
				   var creditsForPercentage = '';
				   
				   for(var count = 1; count <= 12; count++) {
						if(count == 1) {
							creditsForPercentage = Math.ceil((standpercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - standpercentage));
							if(creditsForPercentage > 0) {
								
								table2 += "<td valign='bottom' align='center' height='100'>67%<br><img src = 'GPACalculator/poll2.gif' width='30' height='66.66'></td>" + newline;
							
							}//end inner if
						}//end if
						else {
							creditsForPercentage = Math.ceil((desirepercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - desirepercentage));
							if(creditsForPercentage > 0) {
								var truncDP = truncate(desirepercentage*100);							
								table2 += "<td valign='bottom' align='center' height='100'>"+truncDP+"%<br><img src = 'GPACalculator/poll2.gif' width='30' height='"+truncDP+"'></td>" + newline;
								
							}
							desirepercentage = desirepercentage + 0.05; //inver change
						}//end else
											
					}//end for loop
	
					//ends row 1		   
				   table2 += "</tr>";  			   
								
					//resetting variables for use with row 2
				   standpercentage = 0.6666;
				   desirepercentage = 0.70;
				   creditsForPercentage = '';
				   
				   //row 2 of completion rate table; row with the number of credits needed
				   table2 += "<tr><td valign='bottom' align='left' width='100'># of Credits</td>";
				   
				   for(var count = 1; count <= 12; count++) {
						if(count == 1) {
							creditsForPercentage = Math.ceil((standpercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - standpercentage));
							if(creditsForPercentage > 0) {
								
								table2 += "<td valign='bottom' align='center'>"+creditsForPercentage+"</td>" + newline;  //print the result
							
							}//end inner if
						}//end if
						else {
							creditsForPercentage = Math.ceil((desirepercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - desirepercentage));
							if(creditsForPercentage > 0) {							
								table2 += "<td valign='bottom' align='center'>"+creditsForPercentage+"</td>" + newline;  //print the result
								
							}
							desirepercentage = desirepercentage + 0.05; //inver change
						}//end else
						
					}//end for loop
				   
				   //end row 2
				   table2 += "</tr>";
				   table2 += "</table>";  //ends the graph table
				   table2 += "</td>";  //ends column 1 of section table
				   
				   //start and end of column 2 of completion rate section
				   table2 += "<td class='style5' valign='top' align='left'>*Note:  67% is the minimum completion rate to not be on academic probation.</td>";
				   table2 += "</tr>";  //ends row 1 of completion rate section table
				   
				   //row 2 of completion rate section table
				   table2 += "<tr><td>";
				   
				   //resetting variables for use with creating the narrative completion rate table
				   standpercentage = 0.6666;
				   desirepercentage = 0.70;
				   creditsForPercentage = '';
	
	<!-- Section 5.4.2 - Credits per Rate Narratives -->
				   
				   //narrative completion rate table
				   table2 += "<table class='style5' width='500px'>";
				   for(var count = 1; count <= 12; count++) {
						table2 += "<tr>";
						if(count == 1) {
							creditsForPercentage = Math.ceil((standpercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - standpercentage));
							if(creditsForPercentage > 0) {
								
								table2 += "<td valign='bottom' align='left'>You will need "+creditsForPercentage+" credits to reach a course completion rate of 67%.</td>" + newline;
							
							}//end inner if
						}//end if
						else {
							creditsForPercentage = Math.ceil((desirepercentage * (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) - document.getElementById('local_cum_crearned').value) / (1 - desirepercentage));
							if(creditsForPercentage > 0) {
								var truncDP = truncate(desirepercentage*100);							
								table2 += "<td valign='bottom' align='left'>You will need "+creditsForPercentage+" credits to reach a course completion rate of "+truncDP+"%.</td>" + newline;
								
							}
							desirepercentage = desirepercentage + 0.05; //inver change
						}//end else
						table2 += "</tr>";			
					}//end for loop
				   
				   table2 += "</table>";
				   
				   //end row 2 of completion rate secton table
				   table2 += "</td></tr>";
				   
				   table2 += "</table>";  //ends the completion rate section table
				   
		var newpageStyles = "<style type='text/css'><!-- .style1 {color: #FF0000} .style2 {font-family: 'Trebuchet MS'} .style3 {font-family: 'Trebuchet MS', Arial, Verdana, sans-serif} .style5 {font-family: 'Trebuchet MS', Arial, Verdana, sans-serif; font-size: 14px; } .style7 {font-size: 14px} .style8 {font-size: 18px} .style9 {font-family: 'Trebuchet MS', Arial, Verdana, sans-serif; font-size: 18px; font-weight: bold;} --></style>";
				   
		var newpageLayout = "<table width='820' cellpadding='0' cellspacing='0' border='0'><tr><td width='210' bgcolor='#098153' valign='top'><!-- <img src='images/quad.jpg'>--><br><!--<img src='images/blueshadow.jpg'> --><br><br></td><td width='610' bgcolor='#F3F2FE' valign='top' height='440' style='background-image:url(images/lblue_shadow.gif); background-position:top; background-repeat:repeat-x'><div style='padding: 13px 10px 13px 10px; font-family: verdana; font-size: 11px; line-height: 15px'><div style='width: 90%; border-bottom: 1px solid #8C8B16; padding-bottom: 5px'><div align='left'><a href='www.metrostate.edu'><img src='GPACalculator/inverlogo.gif' /></a></div></div>";
	
	<!-- Section 5.1 - Displaying Current Information -->
				   
		var presentVars = "<table width='100%' bgcolor='#E1EAFB' style='border: 1px solid #CBCC8A; background-color: #FDFDED; font-size: 18px; line-height: 18px'><tr><td><span class='style5'>Local Cumulative Credits Attempted: "
		+document.getElementById('local_cum_crattempted').value+
		"<br>Local Cumulative Credits Earned: "
		+document.getElementById('local_cum_crearned').value+
		"<br>Local Cumulative GPA Credits: "
		+document.getElementById('local_cum_gpacredits').value+
		"<br>Local Cumulative GPA Points: "
		+document.getElementById('local_cum_gpapoints').value+
		"<BR>Local Cumulative GPA: "
		+document.getElementById('local_cum_gpa').value+
		"<br>Local Cumulative Completion Rate: "
		+document.getElementById('local_cum_comprate').value+
		"</span></td></tr></table>";
		
	<!-- Section 5.2 - Displaying Current Information -->
		
		var projectedVars = "<table width='100%' bgcolor='#E1EAFB' style='border: 1px solid #CBCC8A; background-color: #FDFDED; font-size: 18px; line-height: 18px'><tr><td><span class='style5'>Semester GPA: "
		+document.getElementById('forecast_sem_gpa').value+
		"<br>Semester Completion Rate: "
		+document.getElementById('forecast_sem_comprate').value+
		"<BR>Cumulative GPA: "
		+document.getElementById('forecast_cum_gpa').value+
		"<br>Cumulative Completion Rate: "
		+document.getElementById('forecast_cum_comprate').value+
		"</span></td></tr></table>";
	
	<!-- Section 5 - Output Report -->
	
				  twin=open("","Table","toolbar=no,scrollbars=yes,directories=no,menubar=no,resizable=yes,width="+parent.width+",height="+parent.height+"");
				  twin.document.open();
				  twin.document.writeln(newpageLayout);
				  twin.document.writeln(newpageStyles);
				  twin.document.writeln("<title>Inver Hills Community College - GPA and Completion Rate Calculator</title>");
				  twin.document.writeln("<div style='font-family: Trebuchet MS, Arial, Verdana, sans-serif; font-size: 24px; font-weight: bold; color: #8C8B16'><center><br/><br>GPA and Completion Rate Calculator<br/></center></div>");
				  twin.document.writeln("<br><span class='style9'>This is strictly for informational purposes only. Please contact <strong>your</strong> counselor for strategic academic planning.</span><br>");
				  twin.document.writeln("<br><span class='style9'>Current Information</span><br><br>");
				  twin.document.writeln(presentVars);
				  twin.document.writeln("<br><span class='style9'>Semester Forcast</span><br><br>");
				  twin.document.writeln(projectedVars);
				  
				  twin.document.writeln("<br><span class='style9'># of Credits to Complete in order to reach Desired Cumulative GPA</span>");
				  twin.document.writeln("<br><span class='style5'>Based on Current Cumulative GPA, <u>not</u> forecasted Cumulative GPA.</span><br>");
				  twin.document.writeln(table);
				  twin.document.writeln("<br><span class='style9'># of Credits to Complete in order to reach Desired Cumulative Completion Rate</span>");
				  twin.document.writeln("<br><span class='style5'>Based on Current Cumulative Completion Rate, <u>not</u> forecasted Cumulative Completion Rate.</span><br><br>");
				  twin.document.writeln(table2);
				  twin.document.writeln("<br><center><input type='button' onClick='window.print()' value='Print This Page'/><input type='button' value='Close Window' onclick='window.close()'></center>");
				  twin.document.writeln("<br><span class='style3'><center>This GPA Calculator and Forecaster was written and designed by Fred Carpenter and Kou Vang<br />fred.carpenter@metrostate.edu vangko02@go.metrostate.edu<br />Under testing please contact for distribution<br />Creative Commons License CYNCSA</center></span>");
				  twin.document.writeln("</div></table>");
		
				  twin.document.close();
				  twin.focus();   
		}//end else

	}//end if
}//end generate_report()
<!--
//add up the total number of credits from semester forecast
function getTotalSemesterCredits() {
	var totalSemesterCredits = "NaN";
	if (document.getElementById('credits1').value != '') {
		totalSemesterCredits = parseFloat(document.getElementById('credits1').value);
	}
	if (document.getElementById('credits2').value != '') {
		totalSemesterCredits += parseFloat(document.getElementById('credits2').value);
	}
	if (document.getElementById('credits3').value != '') {
		totalSemesterCredits += parseFloat(document.getElementById('credits3').value);
	}
	if (document.getElementById('credits4').value != '') {
		totalSemesterCredits += parseFloat(document.getElementById('credits4').value);
	}
	if (document.getElementById('credits5').value != '') {
		totalSemesterCredits += parseFloat(document.getElementById('credits5').value);
	}
	if (document.getElementById('credits6').value != '') {
		totalSemesterCredits += parseFloat(document.getElementById('credits6').value);
	}
	return totalSemesterCredits;
}

<!-- Section 4 - Input Error Messages -->
		//These are not all input error messages.  Functions may throw their own messages.
		

function runCheck() {
	//var checkcr = calculatecompletionrate();								//used to check for a valid entry for credits attempted, earned, and current credits (used 
																			//in calculating local cumulative completion rate).
	var hitAnError = false;													//return variable.  true if any one error is reached.
	
	//checks
	
	//check for auto calculated gpa and completion rate. if the text fields holding these values are not filled,
	//then it means that some or all fields of "Current Information" has not been filled yet.  it is required to
	//fill out "Current Information" before using "Semester Forecast".
	if(document.getElementById('local_cum_gpa').value == '' | document.getElementById('local_cum_comprate').value == '') {
		alert('You must complete part 1 above before proceeding with this part of the form');
		hitAnError = true;
	}
	
	//check for empty entry fields
	else if (document.getElementById('local_cum_crattempted').value == '') {
		alert('Please enter credits for Local Cumulative Attempted Credits.');
		hitAnError = true;
	}
	else if (document.getElementById('local_cum_crearned').value == '') {
		alert('Please enter credits for Local Cumulative Earned Credits.');
		hitAnError = true;
	}
	else if (document.getElementById('local_cum_gpacredits').value == '') {
		alert('Please enter credits for Local Cumulative GPA Credits.');
		hitAnError = true;
	}
	else if (document.getElementById('local_cum_gpapoints').value == '') {
		alert('Please enter points for Local Cumulative GPA Points.');
		hitAnError = true;
	}
	else if (document.getElementById('local_cum_gpa').value == '') {
		alert('Please enter a GPA for Local Cumulative GPA.');
		hitAnError = true;
	}
	else {
		hitAnError = false;
	}
	
	return hitAnError;

}

/*calculates Semester Gpa, Semester Completion Rate, Cumulative Gpa, and Cumulative Completion Rate for Semester Forecast
*throw alerts if: 	1. the calculated completion rate is greater than 100%; less than 0%; goes to -Infinity or +Infinity.
*					2. gpa entered is greater than 4.
*					3. total number of credits entered in semester forecast is not equal to the entered number of current credits.
*					4. no data is entered or not all data fields are filled in.
*/
function grades() {
	//if all precondtions pass, then proceed with the calculations
	var isError = runCheck();
	//if total number of credits entered in Semester forecast is not equivalent to the credits entered for current_credits field
	var totalCurrentCredits = parseFloat(getTotalSemesterCredits());		//used to check for the correct number of current credits

	if (isError == false && parseFloat(document.getElementById('current_credits').value) != totalCurrentCredits) {
		if (document.getElementById('current_credits').value != '') {
			alert('The number of current credits you\'ve entered in your semester forecast does not match what you\'ve entered for your current information.  Please check that they are equal.');
			isError = true;
		}
		else {
			alert('You have not entered the number of current credits.');
			isError = true;
		}
	} 
	if (isError == false) {	
		//entered data variables
		var localAttemptedCredits = parseFloat(document.getElementById('local_cum_crattempted').value) - parseFloat(document.getElementById('current_credits').value);
		var localEarnedCredits = parseFloat(document.getElementById('local_cum_crearned').value);
		
		var localGpaCredits = parseFloat(document.getElementById('local_cum_gpacredits').value);
		
		var localGpaPoints = parseFloat(document.getElementById('local_cum_gpapoints').value);

		//semester forecasting variables
		var semesterAttemptedCredits = 0;
		var semesterEarnedCredits = 0;
		var semesterGpaCredits = 0;
		var semesterGpaPoints = 0;
		
		//Gpa and Completion Rate variables
		var semesterGpa = 0;
		var semesterCompletionRate = 0;
		var cumulativeGpa = 0;
		var cumulativeCompletionRate = 0;
		
		//arrays of semester credits ID's and chosen grade ID's
		var creditsArray = new Array();
		var gradeIndexesArray = new Array();
		
		creditsArray[0] = "credits1";
		creditsArray[1] = "credits2";
		creditsArray[2] = "credits3";
		creditsArray[3] = "credits4";
		creditsArray[4] = "credits5";
		creditsArray[5] = "credits6";
		
		gradeIndexesArray[0] = "grade1";
		gradeIndexesArray[1] = "grade2";
		gradeIndexesArray[2] = "grade3";
		gradeIndexesArray[3] = "grade4";
		gradeIndexesArray[4] = "grade5";
		gradeIndexesArray[5] = "grade6";
		
		//for loop accumulates the number of semester credits and gpa points
		//loop variables
		var creditsZValue;
		var gradeZIndex;
		for (var z = 0; z <= creditsArray.length - 1; z++) {
			creditsZValue = parseFloat(document.getElementById(creditsArray[z]).value);
			gradeZIndex = document.getElementById(gradeIndexesArray[z]).selectedIndex;
			
			//if the credits textfield for a particular course is NOT blank.
			if (document.getElementById(creditsArray[z]).value != '') {
				
				//if the grade selected for course z is an W, NC, or I, then credits are added only to attempted. Inver change JSL
				if (gradeZIndex == 7) {
					semesterAttemptedCredits += creditsZValue;
				}//end if
				
				//if the grade selected for course z is an "P", then credits are added only to attempted and earned. Inver change JSL
				else if (gradeZIndex == 6) {
					semesterAttemptedCredits += creditsZValue;
					semesterEarnedCredits += creditsZValue;
				}//end if
				
				//if the grade selected for course z is an F, then credits are added to attempted and gpacredits.  no credits and gpa points earned.
				else if (gradeZIndex == 5) {
					semesterAttemptedCredits += creditsZValue;
					semesterGpaCredits += creditsZValue;
				}//end else if
				
				//if they did not choose a grade
				else if (gradeZIndex == 0) {
					alert('Please check that you have selected a grade for course # '+ (z+1) +'.');
				}//end else if
				
				//if the grade selected for course z is any other grade (e.g. A, B, C+...), then credits are added to attempted, earned, and gpacredits.
				//gpa points are also earned.
				else {
					semesterAttemptedCredits += creditsZValue;
					semesterEarnedCredits += creditsZValue;
					semesterGpaCredits += creditsZValue;
					semesterGpaPoints += creditsZValue * parseFloat(document.getElementById(gradeIndexesArray[z]).value);
					
				}//end else
			}//end if
		}//end for
		
		//-----------------------------------------Repeating Course Section------------------------------------------------
		//arrays of repeat checkbox IDs and previous grades IDs
		var repeatArray = new Array();
		var previousGradeArray = new Array();
		
		repeatArray[0] = "repeat1";
		repeatArray[1] = "repeat2";
		repeatArray[2] = "repeat3";
		repeatArray[3] = "repeat4";
		repeatArray[4] = "repeat5";
		repeatArray[5] = "repeat6";
		
		previousGradeArray[0] = "previous_grade1";
		previousGradeArray[1] = "previous_grade2";
		previousGradeArray[2] = "previous_grade3";
		previousGradeArray[3] = "previous_grade4";
		previousGradeArray[4] = "previous_grade5";
		previousGradeArray[5] = "previous_grade6";
		
		//other variables used for repeat course calculation purposes.
		var totalRepeatGpaCredits = 0;
		var totalRepeatGpaPoints = 0;
		
		//loop variables
		var creditsQValue;
		var previousGradeQIndex;
		for (var q = 0; q <= repeatArray.length - 1; q++) {
			if (document.getElementById(repeatArray[q]).checked == true) {
				creditsQValue = parseFloat(document.getElementById(creditsArray[q]).value);
				previousGradeQIndex = document.getElementById(previousGradeArray[q]).selectedIndex;
				
				
				
				if (previousGradeQIndex == 1) {
					totalRepeatGpaPoints += creditsQValue * parseFloat(document.getElementById(previousGradeArray[q]).value);
					totalRepeatGpaCredits += creditsQValue;
					//document.getElementById('forecast_cum_gpa').value = totalRepeatGpaPoints;
				}//end if
				else if (previousGradeQIndex == 2) {
					totalRepeatGpaPoints += 0;
					totalRepeatGpaCredits += creditsQValue;

				}//end else if
				else {
					alert('You have selected course # '+ (q+1) +' as a repeating course.  Please select a previous grade for course # '+ (q+1) +'.');
				}//end else
			}//end if
		}//end for		
		
		//---------------------------------------------END Repeating Course Section-------------------------------------------------------
		
		//Gpa and Completion Rate calculations for semester forecast.
		semesterGpa = truncate(semesterGpaPoints / semesterGpaCredits);
		semesterCompletionRate = truncate((semesterEarnedCredits / semesterAttemptedCredits) * 100);
		
		//printing out the forecast
		document.getElementById('forecast_sem_gpa').value = semesterGpa;
		document.getElementById('forecast_sem_comprate').value = semesterCompletionRate + "%";
		
		
		//Cumulative gpa and completion rate we have to consider the impact of repeat courses if there are any.
		var adjustedSemesterGpaCredits = semesterGpaCredits - totalRepeatGpaCredits;			//adjust the total semester gpa credits earned
		var adjustedLocalGpaPoints = localGpaPoints - totalRepeatGpaPoints;						//adjust the cumulative local gpa points earned
		var adjustedLocalEarnedCredits = parseFloat(localEarnedCredits) - totalRepeatGpaCredits;
		
		cumulativeCompletionRate = truncate(((adjustedLocalEarnedCredits + semesterEarnedCredits) / (localAttemptedCredits + semesterAttemptedCredits)) * 100);
		cumulativeGpa = truncate((adjustedLocalGpaPoints + semesterGpaPoints) / (localGpaCredits + adjustedSemesterGpaCredits));
		
		//printing out the new cums' forecast
		document.getElementById('forecast_cum_gpa').value = cumulativeGpa;
		document.getElementById('forecast_cum_comprate').value = cumulativeCompletionRate + "%";
		
		//determine the students academic status based on forecast calculations
		determineStatuses2(semesterGpa, semesterCompletionRate, cumulativeGpa, cumulativeCompletionRate);
		
	}//ends if
}//end function grades()

function clearForm() {
	document.getElementById('local_cum_crattempted').value = '';
	document.getElementById('local_cum_crearned').value = '';
	document.getElementById('local_cum_gpacredits').value = '';
	document.getElementById('local_cum_gpapoints').value = '';
	document.getElementById('local_cum_gpa').value = '';
	document.getElementById('current_credits').value = '';
	document.getElementById('local_cum_comprate').value = '';
	document.getElementById('message_display').value = '';
	document.getElementById('credits1').value = '';
	document.getElementById('credits2').value = '';
	document.getElementById('credits3').value = '';
	document.getElementById('credits4').value = '';
	document.getElementById('credits5').value = '';
	document.getElementById('credits6').value = '';
	document.getElementById('grade1').selectedIndex = 0;
	document.getElementById('grade2').selectedIndex = 0;
	document.getElementById('grade3').selectedIndex = 0;
	document.getElementById('grade4').selectedIndex = 0;
	document.getElementById('grade5').selectedIndex = 0;
	document.getElementById('grade6').selectedIndex = 0;
	document.getElementById('forecast_sem_gpa').value = '';
	document.getElementById('forecast_sem_comprate').value = '';
	document.getElementById('forecast_cum_gpa').value = '';
	document.getElementById('forecast_cum_comprate').value = '';
	document.getElementById('goal').value = '';
	document.getElementById('repeat1').checked = false;
	document.getElementById('repeat2').checked = false;
	document.getElementById('repeat3').checked = false;
	document.getElementById('repeat4').checked = false;
	document.getElementById('repeat5').checked = false;
	document.getElementById('repeat6').checked = false;
	enable1();
	enable2();
	enable3();
	enable4();
	enable5();
	enable6();
	genable1();
	genable2();
	genable3();
	genable4();
	genable5();
	genable6();
	document.getElementById('message_display2').value = '';
	//document.getElementById('').value = '';

}

<!-- Section 2.3 - Warning Messages -->

//This function is used to determine the second set of messages to display (Semester Forecast) by following this policy:
//	1. if student is already determined to be on academic probation based on "entered data":
//		a. a warning message will be displayed of the student's semester gpa is at or below 2.50.
//		b. a warning message will be displayed if the student's semester completion rate is below 75 percent.
//	2. if student is not determined to be on academic probation based on "entered data":
//		a. a warning message will be displayed if the student's forecasted cumulative gpa is at or below 2.00.
//		b. a warning message will be displayed if the student's forecasted cumulative completion rate is at or below 67 percent. Changed for Inver. JSL
function determineStatuses2(semester_gpa, semester_comprate, new_cum_gpa, new_cum_comprate) {
	document.getElementById('message_display2').value = '';
	if(document.getElementById('message_display').value != '') {
		if(parseFloat(semester_gpa) <= 2.5 & parseFloat(semester_comprate) <= 75.00) {
			document.getElementById('message_display2').value = "Based on your current information, you may already be on academic probation or suspension. Based on your semester GPA of " + semester_gpa + " and semester completion rate of " + semester_comprate + "%, you may be put on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
		} 
		else if(parseFloat(semester_gpa) <= 2.5) {
		document.getElementById('message_display2').value = "Based on your current information, you may already be on academic probation or suspension.  Based on your semester GPA of " +semester_gpa+ ", you may be put on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
		}
		else if(parseFloat(semester_comprate) <= 75.00) {
			document.getElementById('message_display2').value = "Based on your current information, you may already be on academic probation or suspension.  Based on your semester completion rate of " + semester_comprate + ", you may be put on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
		}
	}//end if
	
	else {
	
		if(new_cum_gpa <= 2.0 & new_cum_comprate <= 67) {
			document.getElementById('message_display2').value = "Based on BOTH your forecast cumulative GPA of " + new_cum_gpa + " and forecast cumulative completion rate of " + new_cum_comprate + ", you maybe put on academic probation.  Please, contact your advisor immediately!";
		}
		else if(new_cum_gpa <= 2.0) {
			document.getElementById('message_display2').value = "Based on your forecast cumulative GPA of " + new_cum_gpa + ", you may be put on academic probation.  Please, contact your advisor immediately!";
		}
		else if(new_cum_comprate <= 67) {
			document.getElementById('message_display2').value = "Based on your forecast cumulative completion rate of " + new_cum_comprate + ", you may be put on academic probation.  Please, contact your advisor immediately!";
		}
	}//end else
}//end function determineStatuses2()


//functions to determine a student's academic standing coming into this form.
var flag1 = false;	//becomes true if completion fate falls below 67% Changed for Inver JSL
var flag2 = false;	//becomes true if gpa is below 2.0

function determineStatuses() {
	//check completion rate
	if(document.getElementById('local_cum_crearned').value != '' & document.getElementById('local_cum_crattempted').value != '') {
		var ccr = calculatecompletionrate();
		
		if((ccr >= 0.00) & (ccr <= 67)) {
			flag1 = true;
			//document.getElementById('message_display').value = "flag1 = " + flag1 + " ccr = " + ccr;	
		}
	}
	
	//check gpa
	if(document.getElementById('local_cum_gpa').value != '') {
		if(document.getElementById('local_cum_gpa').value < 2.0) {
			flag2 = true;
			//document.getElementById('message_display').value += "flag2 = " + flag2;	
		}
		else if(document.getElementById('local_cum_gpa').value > 4) {
			alert('Local Cumulative GPA cannot be above 4.0');
		}
	}
<!-- Section 1.3 - Warning Messages -->	
	//determine which message to print
	//if both flags are true
	if(flag1 == true & flag2 == true) {
		document.getElementById('message_display').value = "Based on BOTH your cumulative completion rate of " + document.getElementById('local_cum_comprate').value + " AND your cumulative G.P.A of " + document.getElementById('local_cum_gpa').value + ", you may be on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
	}
	else if(flag1 == true & flag2 == false) {
		document.getElementById('message_display').value = "Based on your cumulative completion rate of " + document.getElementById('local_cum_comprate').value + ", you may be on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
	}
	else if(flag1 == false & flag2 == true) {
		document.getElementById('message_display').value = "Based on your cumulative G.P.A of " + document.getElementById('local_cum_gpa').value + ", you may be on academic probation or suspension.  It is IMPORTANT that you see a counselor for academic guidance immediately.  You can set up an appointment by calling 651-450-3508.";
	}
	else {
		document.getElementById('message_display').value = '';
	}
	flag1 = false;
	flag2 = false;
	


}

function calculatecompletionrate() {
	var localCompletionRate = 0;
	if (document.getElementById('current_credits').value < 0) {
		alert('Number of Current Credits cannot not be negative.');
	}
	else {
		localCompletionRate = truncate(document.getElementById('local_cum_crearned').value / (document.getElementById('local_cum_crattempted').value - document.getElementById('current_credits').value) * 100);
		return localCompletionRate;
	}
	

}

function currentcumcomplrate() {
	var clcrate = calculatecompletionrate();
	if(clcrate == 100.00) {
		document.getElementById('local_cum_comprate').value = 100 + "%";
	}
	else if((clcrate > 100.00) | (clcrate == '-Infinity') | (clcrate == 'Infinity') | (clcrate < 0.00)) {
		alert('Please check the number of credits you have entered for Local Cumulative Credits Attempted, Local Cumulative Credits Earned, and/or Current Credits.');
	}
	else {
		document.getElementById('local_cum_comprate').value = clcrate + "%";		
	}

}

function compareGPA() {
	var calcGPA = truncate(document.getElementById('local_cum_gpapoints').value / document.getElementById('local_cum_gpacredits').value);
	
	//only compare if gpa credits, gpa points, and gpa fields are filled in
	if(document.getElementById('local_cum_gpacredits').value != '' & document.getElementById('local_cum_gpapoints').value != '' & document.getElementById('local_cum_gpa').value != '') {
		if(document.getElementById('local_cum_gpa').value != calcGPA) {
			alert("The current GPA that you entered ("+document.getElementById('local_cum_gpa').value+") does not equal what has been calculated ("+calcGPA+").  Please check the data you've entered for GPA Points, GPA Credits, and/or Current GPA.");
		}
	}
}

//enable grade dropdown menues per No. of Credits textfields that are filled
//also used to enable repeat check boxes. same condition.
//grade 1
function genable1() {
	if(document.getElementById('credits1').value != '') {
		document.getElementById('grade1').disabled = false;
		document.getElementById('repeat1').disabled = false;
	}
	else {
		document.getElementById('grade1').selectedIndex = 0;
		document.getElementById('grade1').disabled = true;
		document.getElementById('repeat1').disabled = true;
		document.getElementById('repeat1').checked = false;
		document.getElementById('previous_grade1').selectedIndex = 0;
		document.getElementById('previous_grade1').disabled = true;
	}
}

//grade 2
function genable2() {
	if(document.getElementById('credits2').value != '') {
		document.getElementById('grade2').disabled = false;
		document.getElementById('repeat2').disabled = false;
	}
	else {
		document.getElementById('grade2').selectedIndex = 0;
		document.getElementById('grade2').disabled = true;
		document.getElementById('repeat2').disabled = true;
		document.getElementById('repeat2').checked = false;
		document.getElementById('previous_grade2').selectedIndex = 0;
		document.getElementById('previous_grade2').disabled = true;
	}
}

//grade 3
function genable3() {
	if(document.getElementById('credits3').value != '') {
		document.getElementById('grade3').disabled = false;
		document.getElementById('repeat3').disabled = false;
	}
	else {
		document.getElementById('grade3').selectedIndex = 0;
		document.getElementById('grade3').disabled = true;
		document.getElementById('repeat3').disabled = true;
		document.getElementById('repeat3').checked = false;
		document.getElementById('previous_grade3').selectedIndex = 0;
		document.getElementById('previous_grade3').disabled = true;
	}
}

//grade 4
function genable4() {
	if(document.getElementById('credits4').value != '') {
		document.getElementById('grade4').disabled = false;
		document.getElementById('repeat4').disabled = false;
	}
	else {
		document.getElementById('grade4').selectedIndex = 0;
		document.getElementById('grade4').disabled = true;
		document.getElementById('repeat4').disabled = true;
		document.getElementById('repeat4').checked = false;
		document.getElementById('previous_grade4').selectedIndex = 0;
		document.getElementById('previous_grade4').disabled = true;
	}
}

//grade 5
function genable5() {
	if(document.getElementById('credits5').value != '') {
		document.getElementById('grade5').disabled = false;
		document.getElementById('repeat5').disabled = false;
	}
	else {
		document.getElementById('grade5').selectedIndex = 0;
		document.getElementById('grade5').disabled = true;
		document.getElementById('repeat5').disabled = true;
		document.getElementById('repeat5').checked = false;
		document.getElementById('previous_grade5').selectedIndex = 0;
		document.getElementById('previous_grade5').disabled = true;
	}
}

//grade 6
function genable6() {
	if(document.getElementById('credits6').value != '') {
		document.getElementById('grade6').disabled = false;
		document.getElementById('repeat6').disabled = false;
	}
	else {
		document.getElementById('grade6').selectedIndex = 0;
		document.getElementById('grade6').disabled = true;
		document.getElementById('repeat6').disabled = true;
		document.getElementById('repeat6').checked = false;
		document.getElementById('previous_grade6').selectedIndex = 0;
		document.getElementById('previous_grade6').disabled = true;
	}
}

//enable repeat dropdown menus per checkboxes that are checked
//repeat 1
function enable1() {
	if (document.getElementById('repeat1').checked == true) {
		document.getElementById('previous_grade1').disabled = false;
	}
	else {
		document.getElementById('previous_grade1').selectedIndex = 0;
		document.getElementById('previous_grade1').disabled = true;
	}
}

//repeat 2
function enable2() {
	if (document.getElementById('repeat2').checked == true) {
		document.getElementById('previous_grade2').disabled = false;
	}
	else {
		document.getElementById('previous_grade2').selectedIndex = 0;
		document.getElementById('previous_grade2').disabled = true;
	}
}

//repeat 3
function enable3() {
	if (document.getElementById('repeat3').checked == true) {
		document.getElementById('previous_grade3').disabled = false;
	}
	else {
		document.getElementById('previous_grade3').selectedIndex = 0;
		document.getElementById('previous_grade3').disabled = true;
	}
}

//repeat 4
function enable4() {
	if (document.getElementById('repeat4').checked == true) {
		document.getElementById('previous_grade4').disabled = false;
	}
	else {
		document.getElementById('previous_grade4').selectedIndex = 0;
		document.getElementById('previous_grade4').disabled = true;
	}
}

//repeat 5
function enable5() {
	if (document.getElementById('repeat5').checked == true) {
		document.getElementById('previous_grade5').disabled = false;
	}
	else {
		document.getElementById('previous_grade5').selectedIndex = 0;
		document.getElementById('previous_grade5').disabled = true;
	}
}

//repeat 6
function enable6() {
	if (document.getElementById('repeat6').checked == true) {
		document.getElementById('previous_grade6').disabled = false;
	}
	else {
		document.getElementById('previous_grade6').selectedIndex = 0;
		document.getElementById('previous_grade6').disabled = true;
	}
}