function sbmt_personal() {
	var req = ['person_name','person_email','person_phone'];
	var reqlist = ['Full Name','Email','Phone Number'];
	submitForm('requestPInfo', req, reqlist);
}

function sbmt_inforequest() {
	var req = ['person_name', 'name_family', 'name_given', 'person_email',  'address_street', 'address_locality', 'address_region', 'address_pccode', 'address_country', 'person_phone'];
	var reqlist = ['Full Name', 'Family Name', 'Given Name', 'Email', 'Street Address', 'City or Locality', 'State/Province', 'Postal/Zip Code', 'Country', 'Telephone'];
	submitForm('requestInfoForm', req, reqlist);
}

function sbmt_dclogin() {
	var req = ['username','password'];
	var reqlist = ['Username','Password'];
	submitForm('dcLogin', req, reqlist);
}

function sbmt_application(pgm) {
	if (pgm == "BBA") {
		var req = ['program_code', 'person_name', 'name_family', 'name_given', 'person_email',  'address_street', 'address_locality', 'address_region', 'address_pccode', 'address_country', 'person_phone',  'start_in', 'edu_highest', 'edu_withdraw', 'open_enrolltype', 'summary', 'tcredits', 'open_ref'];
		var reqlist = ['Program', 'Full Name', 'Family Name', 'Given Name', 'Email', 'Street Address', 'City or Locality', 'State/Province', 'Postal/Zip Code', 'Country', 'Telephone', 'Start Date', 'Highest Level of Education', 'Post-Secondary Withdrawal', 'Enrollment Type', 'Summary', 'Transfer Credits', 'Referrer'];
		var prev_ed = ['edu_hs1name', 'edu_hs2name', 'edu_un1name', 'edu_un2name'];
	} else {
		var req = ['program_code', 'person_name', 'name_family', 'name_given', 'person_email',  'address_street', 'address_locality', 'address_region', 'address_pccode', 'address_country', 'person_phone',  'start_in', 'employment_name', 'employment_job_title', 'edu_highest', 'edu_program', 'edu_withdraw', 'summary', 'tcredits', 'open_ref'];
		var reqlist = ['Program', 'Full Name', 'Family Name', 'Given Name', 'Email', 'Street Address', 'City or Locality', 'State/Province', 'Postal/Zip Code', 'Country', 'Telephone', 'Start Date', 'Employer', 'Job Title', 'Highest Level of Education', 'Degree/Diploma/Certification', 'Post-Secondary Withdrawal', 'Summary', 'Transfer Credits', 'Referrer'];
		var prev_ed = ['edu_hs1name', 'edu_un1name', 'edu_un2name'];
	}
	submitApplicationForm('appForm', req, reqlist, prev_ed, pgm);
}

function submitForm(frm, req, reqlist) {
	var fm = document.getElementById(frm);
	//
	// Make sure all required fields have been entered before submitting
	//
	var errstr = '';
	for (i=0; i<req.length;i++) {
		var id = req[i];
		if (!fm[id].value) {
			errstr = errstr+" - "+reqlist[i]+"\n";
		}
	}
	//
	// Display error if missed one, otherwise submit the form
	//
	if (errstr) {
		alert("You forgot to enter the following required fields:\n"+errstr);
	} else {
		fm.submit();
	}
}

function submitApplicationForm(frm, req, reqlist, prev_ed, pgm) {
	var fm = document.getElementById(frm);
	//
	// Make sure all required fields have been entered before submitting
	//
	var errstr = '';
	var checkvals = req.length;
	for (i=0; i<checkvals; i++) {
		var id = req[i];
		if (!fm[id].value) {
			errstr = errstr + reqlist[i] + '\n';
		}
	}
	//
	// If applicant withdrew from another institution, make sure they say from where and when 
	//
	if (fm['edu_withdraw'].value == "Yes") {
		if (!fm['edu_wdinst'].value) {
			errstr = errstr + 'Name of institution from which you withdrew\n';
		}
		if (!fm['edu_wdyear'].value) {
			errstr = errstr + 'Year you withdrew from institution\n';
		}
	}	
	
	//
	// Check that at least one school is entered in Previous Education fields
	//
	var fnd = false;
	checkvals = prev_ed.length;
	for (i=0; i<checkvals; i++) {
		var id = prev_ed[i];
		if (fm[id].value) {
			fnd = true;
		}
	}
	if (!fnd) {
		errstr = errstr + "Previous Education\n";
	}
	//
	// Display error if missed one, otherwise submit the form
	//
	if (errstr) {
		alert("You forgot to enter the following required fields:\n" + errstr);
		return;
	} else {

		if ((fm['open_ref'].value == 'Fredericton Chamber of Commerce') && (fm['employment_name'].value == '')) {
			alert("You must enter your employer's name if being referred by the Fredericton Chamber of Commerce.\n");
			return;
		}
		
		if (fm['appidval'].value != fm['myidval'].value) {
			alert("You must type the same number as you see in the security image before you can submit this form.\n");
			return;
		}
	
		//
		// Combine all the education information and other information into two (formerly textarea) fields
		//

		//
		// "Education" field
		//
		fm['education'].value = "Highest level of education - " + fm['edu_highest'].value + "\n";
		fm['education'].value = fm['education'].value + "Program - " + fm['edu_program'].value + "\n\n";
		fm['education'].value = fm['education'].value + "Previous Education:\n";
		if (pgm == "BBA") {
			if (fm['edu_hs1name'].value) {
				fm['education'].value = fm['education'].value + "High School: " + fm['edu_hs1name'].value + " - " + fm['edu_hs1city'].value + ", " + fm['edu_hs1prov'].value + ", " + fm['edu_hs1ctry'].value + "\n";
			}
			if (fm['edu_hs2name'].value) {
				fm['education'].value = fm['education'].value + "High School: " + fm['edu_hs2name'].value + " - " + fm['edu_hs2city'].value + ", " + fm['edu_hs2prov'].value + ", " + fm['edu_hs2ctry'].value + "\n";
			}
		} else {
			if (fm['edu_hs1name'].value) {
				fm['education'].value = fm['education'].value + "Trade School: " + fm['edu_hs1name'].value + " - " + fm['edu_hs1city'].value + ", " + fm['edu_hs1prov'].value + ", " + fm['edu_hs1ctry'].value + "\n";
			}
		}
		if (fm['edu_un1name'].value) {
			fm['education'].value = fm['education'].value + "College/University: " + fm['edu_un1name'].value + " - " + fm['edu_un1city'].value + ", " + fm['edu_un1prov'].value + ", " + fm['edu_un1ctry'].value + "\n";
		}
		if (fm['edu_un2name'].value) {
			fm['education'].value = fm['education'].value + "College/University: " + fm['edu_un2name'].value + " - " + fm['edu_un2city'].value + ", " + fm['edu_un2prov'].value + ", " + fm['edu_un2ctry'].value + "\n";
		}	
		fm['education'].value = fm['education'].value + "\nRequired to withdraw? " + fm['edu_withdraw'].value;
		if (fm['edu_withdraw'].value == "Yes") {
			fm['education'].value = fm['education'].value + ", from " + fm['edu_wdinst'].value + " in " + fm['edu_wdyear'].value;
		}
		fm['education'].value = fm['education'].value + "\n";
		
		//
		// "Why Interested" field
		//
		if (pgm == "BBA") { 
			fm['why_interested'].value = "Enrollment Type - " + fm['open_enrolltype'].value + "\n\n";
		}		
		fm['why_interested'].value = fm['why_interested'].value + "Applying for Transfer Credits? "	+ fm['tcredits'].value + "\n\n";
		fm['why_interested'].value = fm['why_interested'].value + "Referred by " + fm['open_ref'].value + "\n\n";
		fm['why_interested'].value = fm['why_interested'].value + fm['summary'].value + "\n";

		fm.submit();
	}
}

function radiobtn(tag, val) {
	var fm = document.appForm;
	fm[tag].value = val;
}

function togglePrivacyConfirmation(frm) {
	var fm = document.getElementById(frm);
	//
	// Hide the SUBMIT button until you confirm the Privacy Agreement checkbox
	//
	if (fm["confirm_privacy"].checked) {
		fm["Submitbtn"].disabled=false;
	} else {
		fm["Submitbtn"].disabled=true;
	}
}