function checkRadio(fieldname) {
	var field = document.app_2[fieldname];
	var radioLength = field.length;
	for (var i = 0; i < radioLength; i++) {
		if (field[i].checked) {
			return true;
		}
	}
	return false;
}

function checkRadio3(fieldname) {
	var field = document.app_3[fieldname];
	var radioLength = field.length;
	for (var i = 0; i < radioLength; i++) {
		if (field[i].checked) {
			return true;
		}
	}
	return false;
}


function checkCheckbox3(radioObj) {
	var field = document.app_3[fieldname];
	if (field.checked) {
		return true;
	}
	else {
		return false;
	}
}


function checkPartOne() {
	requiredVar = new Array("fname","lname","ssn","phone","present_address_1","present_city","present_state","present_zip");
	requiredExp = new Array("First Name","Last Name","Social Security Number","Home Phone Number","Present Address 1","Present City","Present State","Present Zip");
	reqCount = requiredVar.length;
	omitcount = 0;
	omittedFields = "";
	
	for (i=0; i<reqCount; i++) {
		fieldname = requiredVar[i];
		if (!document.app_1[fieldname].value) {
			omitcount++;
			omittedFields += omitcount + ". " + requiredExp[i] + "\n";
		}
	}
	if (omitcount > 0) {
		alert("Please complete these required fields:\n" + omittedFields);
		return false;
	}
	else {
		// check radio buttons
		if (checkRadio('app_1','has_been_convicted')) {
			if (checkRadio('app_1','is_excluded')) {
				return true;
			}
			else {
				alert("Please complete these required fields:\nAre you currently excluded from participation in any federally funded healthcare program?");
				return false;
			}
		}
		else {
			alert("Please complete these required fields:\nHave you been convicted of a crime...?");
			return false;
		}
	}
}


function checkPartTwo() {
	requiredVar = new Array("hs_name","hs_city","hs_state");
	requiredExp = new Array("Name","City","State");
	reqCount = requiredVar.length;
	omitcount = 0;
	omittedFields = "";
	
	for (i=0; i<reqCount; i++) {
		fieldname = requiredVar[i];
		if (!document.app_2[fieldname].value) {
			omitcount++;
			omittedFields += omitcount + ". " + requiredExp[i] + "\n";
		}
	}
	if (omitcount > 0) {
		alert("Please complete these required fields:\n" + omittedFields);
		return false;
	}
	else {
		if (checkRadio('hs_last_year')) {
			if (checkRadio('hs_did_graduate')) {
				return true;
			}
			else {
				alert("Please complete these required fields:\nGraduated? / GED?");
				return false;
			}
		}
		else {
			alert("Please complete these required fields:\nHigh School: Last Year Attended");
			return false
		}
	}
}



function checkPartThree() {
	requiredVar = new Array("job_1_start_year","job_1_company","job_1_address_1","job_1_city","job_1_state","job_1_zip","job_1_supervisor","job_1_title","job_1_salary","job_1_duties","job_1_reason");
	requiredExp = new Array("Current/Most Recent Job Start Year","Company Name","Address","City","State","Zip","Immediate Supervisor","Job Title","Salary","Nature of Duties","Reason for Leaving");
	reqCount = requiredVar.length;
	omitcount = 0;
	omittedFields = "";
	
	for (i=0; i<reqCount; i++) {
		fieldname = requiredVar[i];
		if (!document.app_3[fieldname].value) {
			omitcount++;
			omittedFields += omitcount + ". " + requiredExp[i] + "\n";
		}
	}
	
	if (document.app_3.resume.value != '') {
		var field = document.app_3.resume.value;
		if (field.lastIndexOf(".doc") == -1 && field.lastIndexOf(".txt") == -1 && field.lastIndexOf(".pdf") == -1 && field.lastIndexOf(".rtf") == -1) {
			alert("Please upload your resume in Word (.doc), PDF (.pdf), plain-text (.txt), or rich-text (.rtf) format.");
			return false;
		}
	}
	
	if (omitcount > 0) {
		alert("Please complete these required fields for Most Recent Job Company:\n" + omittedFields);
		return false;
	}
	else {
		if (document.app_3.acceptance.checked) {
			return true;
		}
		else {
			alert("You must acknowledge the conditions of employment.");
			return false;
		}
	}
}


function isSecure() {
	var protocol = document.location.protocol;
	alert(protocol);
	
	if (protocol == 'http:') {
		var fullurl = parent.document.URL;
		var querystring = fullurl.substring(fullurl.indexOf('?'), fullurl.length);
		var path = window.location.pathname;
		var newpath = 'https://www.capellacareers.com' + path + querystring;
		alert (newpath);
		window.location = newpath;
	}
	
	return true;
}

//isSecure();
