function show_box() {
	document.getElementById('saved_box').style.visibility = 'visible';
	document.getElementById('submit_box').style.visibility = 'hidden';
	return true;
}
function show_sub_box() {
	document.getElementById('submit_box').style.visibility = 'visible';
	document.getElementById('saved_box').style.visibility = 'hidden';
	return true;
}
function hide_box() {
	document.getElementById('submit_box').style.visibility = 'hidden';
	return true;
}
function expand(i) {
	if (document.getElementById('essay' + i + '_box').style.display == 'block') {
		document.getElementById('essay' + i + '_box').style.display = 'none';
	} else {
		document.getElementById('essay' + i + '_box').style.display = 'block';
	}
}
function expand_box(i) {
	if (document.getElementById(i).style.display == 'block') {
		document.getElementById(i).style.display = 'none';
	} else {
		document.getElementById(i).style.display = 'block';
	}
}

function save_notes(id) {
//$('#save_note input:submit').attr("disabled", "true");
//$('#note_msg').removeClass("updating");
//$('#note_msg').removeClass("saved");
//$('#note_msg').text("Saving....");
//$('#note_msg').addClass("updating");
$.ajax({
type: "POST",
url: "/pages/teacher_application/145.php",
data: id+"="+$("#"+id).val()+"&save_"+id+"=save",
complete: function(msg){
document.getElementById(id + '_box').style.display = 'none';
}
});
return false;
}

// Add form fields
var arrInput = new Array(0);
  var arrInputValue = new Array(0);

function addInput() {
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  display();
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
	institution_num ++;
  return "<label for='institution'>New Institution</label><br /><input type='text' id='institution"+institution_num+"' name='institution[]' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"' class='input'><br /><label for='degree'>New Degree</label><br /><input type='text' name='degree[]' id='degree"+institution_num+"' maxlength='50' class='input' /><br /><label for='year'>New Year</label><br /><input type='text' name='year[]' id='year"+institution_num+"' maxlength='50' class='input' /><br /><br />";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}
// END 


var requiredArr = Array("username","first_name","last_name");
var requiredArrName = Array("Username","First Name", "Last Name");

function isEmailAddress (string) {
  var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  return addressPattern.test(string);
}
function notEmptyStr(strValue) {
	if (strValue != "") return true;
	else return false;
}
function NumericOnly (string) {
	var objRegExp  = /[^0-9]/;
	return(objRegExp.test(string));
}
function validateForm(f) {
	
	var err ='';
	if (!isEmailAddress(f.email.value)) {
		err += 'Your Email is invalid\r\n';
	}
	if (isNaN(f.phone_0.value) || isNaN(f.phone_1.value) || isNaN(f.phone_2.value)) {
		err += 'Your Phone may only contain numbers\r\n';
	}
	if (isNaN(f.school_phone_0.value) || isNaN(f.school_phone_1.value) || isNaN(f.school_phone_2.value)) {
		err += 'Your School Phone may only contain numbers\r\n';
	}
	
	for (var i=0; i<requiredArr.length; i++) {
		var curInput = eval("f."+requiredArr[i]);
		if (curInput) {
			if(notEmptyStr(curInput.value)==false) {
				err+=(requiredArrName[i]+' is blank or invalid\r\n');
			}
		}
	}	
	if (err!='') { 
		alert(err + '\r\n' + 'Your application will not be saved until the fields listed above are valid.');
		document.getElementById('submit_box').style.visibility = 'hidden';
		document.getElementById('saved_box').style.visibility = 'hidden';
		return false;
	}
	return true;
}

var requiredArrSub = Array("username","first_name","last_name", "middle_name", "address", "city", "zip", "school_name", "school_address", "school_city", "school_zip", "school_county", "principal_fname", "principal_lname", "position_title", "grades_taught", "subject_taught", "teachers_team", "phone_0", "phone_1", "phone_2", "school_phone_0", "school_phone_1", "school_phone_2", "essay1", "essay2", "essay3", "essay4", "essay5");
var requiredArrNameSub = Array("Username","First Name", "Last Name", "Middle Name", "Address", "City", "Zip", "School Name", "School Address", "School City", "School Zip", "School County", "Principal First Name", "Principal Last Name", "Your Position/Title", "Grades Currently Taught", "Subjects Currently Taught", "Teachers On Team", "1st part of your Home Phone", "2nd part of your Home Phone", "3rd part of your Home Phone", "1st part of your School Phone", "2nd part of your School Phone", "3rd part of your School Phone", "Application Question 1", "Application Essay 1", "Application Essay 2", "Application Essay 3", "Application Essay 4");

function validateFormSub(f) {
	var err ='';
	 
	if (!isEmailAddress(f.email.value)) {
		err += 'Your Email is invalid\r\n';
	}
	if (isNaN(f.phone_0.value) || isNaN(f.phone_1.value) || isNaN(f.phone_2.value)) {
		err += 'Your Phone may only contain numbers\r\n';
	}
	if (isNaN(f.school_phone_0.value) || isNaN(f.school_phone_1.value) || isNaN(f.school_phone_2.value)) {
		err += 'Your School Phone may only contain numbers\r\n';
	}
	if (notEmptyStr(document.getElementById("institution1").value)==false) {
		err += 'Institution1 is blank or invalid\r\n';
	}
	if (notEmptyStr(document.getElementById("degree1").value)==false) {
		err += 'Degree1 is blank or invalid\r\n';
	}
	if (notEmptyStr(document.getElementById("year1").value)==false) {
		err += 'Year1 is blank or invalid\r\n';
	}
	for (var i=0; i<requiredArrSub.length; i++) {
		var curInput = eval("f."+requiredArrSub[i]);
		if (curInput) {
			if(notEmptyStr(curInput.value)==false) {
				err+=(requiredArrNameSub[i]+' is blank or invalid\r\n');
			}
		}
	}	
	if (err!='') { 
		alert(err);
		document.getElementById('submit_box').style.visibility = 'hidden';
		document.getElementById('saved_box').style.visibility = 'hidden';
		return false;
	}
	return true;
}

