function formValidator(){
	// Make quick references to our fields
	var upload_file = document.getElementById("upload_file").value;	
	
	// find the path info and remove it
	var lastslash_location = upload_file.lastIndexOf("\\") + 1;
	upload_file = upload_file.substr(lastslash_location);
	
	// find ext and remove
	var ext_location = upload_file.lastIndexOf(".");
	upload_file = upload_file.substr(0,ext_location);
	
	// Check FILENAME FORMAT!
	if(checkForUndsc(upload_file, "Filename is not in correct format, I cannot find the 2 underscores between year, month, and day")){
		if(isNumeric(upload_file, "Filename is not in correct format...month, day, and year must be numeric only.")){
			if(lengthRestriction(upload_file, 2, 2)){
				if(checkMonDayYear(upload_file)){
					return true;
				}
			}
		}
	}	
	return false;	
}

function checkKey(keypressed, tax, event){	
	if (keypressed == 13) {
		isNumericTax(tax, "Assessment dollar amount entered...\n1.  Must be numeric. \n2.  Have no commas, periods, dollar signs, or spaces. \n3.  Must be whole numbers only.")
		if (event == "key") {
			return false;
		}
	}
	else {
		return true;
	}
}

function isNumericTax(tax, helperMsg){	
	
	var numericExpression = /^[0-9]+$/;

	if(tax.match(numericExpression)){
		serverGetTax(tax);
	}else{
		alert(helperMsg);		
	}		
		
}

function isNumeric(file_uploaded, helperMsg){
	var numericExpression = /^[0-9]+$/;
	
	// separate parts on the underscore
	var file_parts = file_uploaded.split("_");

	for(i=0; i<=2; i++){
		if(file_parts[i].match(numericExpression)){
			continue;
		}else{
			alert(helperMsg);		
			return false;
		}	
	}
	return true;
}

function lengthRestriction(file_uploaded, min, max){
	// separate parts on the underscore
	var file_parts = file_uploaded.split("_");
	
	for(i=0; i<=2; i++){
		if(file_parts[i].length >= min && file_parts[i].length <= max){
			continue;
		}else{
			alert("Filename is not in correct format, the year, month, and day must each be 2 digits long");			
			return false;
		}
	}
	return true;
}

function checkForUndsc(file_uploaded, helperMsg){
	// an underscore should appear twice in our filename
	occurs = file_uploaded.split("_").length-1
	
	if (occurs == 2){return true;}		
	else{
		alert(helperMsg);		
		return false;
	}
}

function checkMonDayYear(file_uploaded){
	// separate parts on the underscore
	var file_parts = file_uploaded.split("_");
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	

	for(i=0; i<=2; i++){
		if (i == 1) {			
			if (file_parts[1] > 12) {
				alert("The month portion of the filename entered is not valid");		
				return false;
			}
		}		
	}
	
	alert("FYI...The filename entered suggests a date of - " + getMonthName(file_parts[1]) + " " + file_parts[2] + ", 20" + file_parts[0]);
	return true;
}

// get the name of the Month
function getMonthName(monthNum) {   
   if (monthNum == 1){name = "January";}
   else if (monthNum == 2){name = "February";}   
   else if (monthNum == 3){name = "March";}
   else if (monthNum == 4){name = "April";}
   else if (monthNum == 5){name = "May";}
   else if (monthNum == 6){name = "June";}
   else if (monthNum == 7){name = "July";}
   else if (monthNum == 8){name = "August";}
   else if (monthNum == 9){name = "September";}
   else if (monthNum == 10){name = "October";}
   else if (monthNum == 11){name = "November";}
   else {name = "December";}
   
   return name;
}
