// JavaScript Document

var radio_selection="";
var relative_selection="";
var ged_selection="";
var cmpttest_selection="";
var convicted_selection="";
var charges_selection ="";
var felony_selection ="";
function checkRequired(theForm)
{
		var f = theForm;
		//GENERAL INFORMATION 
		
		if (f.ptitle.value == "") {
			alert ("Please provide the title of the position you are applying for.");
			f.ptitle.focus();
			return false;
		}
		
		if (f.pnumb.value == "") {
			alert ("Please enter the Announcement Number of the position you are applying for.");
			f.pnumb.focus();
			return false;
		}
		
		var valid12 = "0123456789"
		var ok = "yes";
		var temp12;
		for (var i=0; i<f.pnumb.value.length; i++) {
		temp12 = "" + f.pnumb.value.substring(i, i+1);
		if (valid12.indexOf(temp12) == "-1") ok = "no";
		}
		if (ok == "no") {
		alert("Your Position Number entered contains invalid characters.  Use only Numbers.");
		f.pnumb.focus();
		return false;
		}
		
		if (f.fname.value == "") {
			alert ("Please enter your first name.");
			f.fname.focus();
			return false;
		}
		
		if (f.lname.value == "") {
			alert ("Please enter your last name.");
			f.lname.focus();
			return false;
		}
		if (f.street.value == "") {
			alert ("Please enter your Street Address.");
			f.street.focus();
			return false;
		}
		if (f.city.value == "") {
			alert ("Please enter your City.");
			f.city.focus();
			return false;
		}
		
		if (f.state.value == "") {
			alert ("Please enter your State.");
			f.state.focus();
			return false;
		}
		
		var valid = "0123456789-";
		var hyphencount = 0;
		if (f.zip.value.length!=5 &&f.zip.value.length!=10) {
			alert("Please enter your 5 digit or 5 digit+4 zip code.");
			f.zip.focus();
			return false;
		}
		for (var i=0; i < f.zip.value.length; i++) {
			temp = "" + f.zip.value.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
				alert("Invalid characters in your zip code.  Please try again.");
				f.zip.focus();
				return false;
			}
			if ((hyphencount > 1) || ((f.zip.value.length==10) && ""+f.zip.value.charAt(5)!="-")) {
				alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
				f.zip.focus();
				return false;
			   }
			  
		}

		//Email Validation
		if (f.email.value != ""){
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.email.value)){
					
					}else{
						alert("Invalid E-mail Address! Please re-enter.");
						f.email.focus();
						return false;
				}
		}
		if(relative_selection == 'yes'){
			if(f.relname.value=="" ){
				alert("Please Enter the Relative Name relative currently working for the Commission.");
				f.relname.focus();
				return false;
			}else if(f.relrelation.value == ""){
				alert("Please Enter the Relationship of the relative currently working for the Commission.");
				f.relrelation.focus();
				return false;
			
			}

		} 
		//END OF GENERAL INFORMATION
		if (f.resumecoverletter.value == "") {
			alert ("Please attach your resume and cover letter.");
			f.resumecoverletter.focus();
			return false;
		}
		//PARK POLICE VALIDATION
		if(f.prevparkdate.value !=""){
			var matchArrt1 = f.prevparkdate.value.match(/^(\d{2})\/?\d{4}$/);
			var numDashest1 =f.prevparkdate.value.split('/').length;
			if(matchArrt1 == null || numDashest1 == 1){
				alert("Please enter Previously Applied Date for a Park Police Position in the follwoing format MM/YYYY.");
				f.prevparkdate.focus();
				return false;
			}
		}	
		if (radio_selection == 'yes'){
			if (f.branch.value == ""){
				alert("Please enter the Branch of Service you served.");
				f.branch.focus();
				return false;
			}
			if (f.servdatefrom.value !="") {
					var matchArrt1 = f.servdatefrom.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.servdatefrom.value.split('/').length;
					if(matchArrt1 == null || numDashest1 == 1){
						alert("Please enter your 'from' in the follwoing format MM/YYYY.");
						f.servdatefrom.focus();
						return false;
					}	
	 
			}
			if (f.servdateto.value !="") {
				var matchArrt1 = f.servdateto.value.match(/^(\d{2})\/?\d{4}$/);
				var numDashest1 =f.servdateto.value.split('/').length;
				if(matchArrt1 == null || numDashest1 == 1){
					alert("Please enter your 'to' in the follwoing format MM/YYYY.");
					f.servdateto.focus();
					return false;
				}	
			}
			if (f.servdatefrom.value == "" || f.servdateto.value == ""){ 
				alert("Both service dates must be entered.");
				f.servdatefrom.focus();
				return false;
			}
			var numdateto =f.servdateto.value.split('/');
			var numdatefrom =f.servdatefrom.value.split('/');
			if (numdatefrom[1] < numdateto[1]){ 
				//alert("To date must occur after the from date.")
			}else{
				alert ("To date must occur after the from date");
				f.servdateto.focus();
				return false;
			
			}
		}
		//END OF POLICE VALIDATION
		
		//EDUCATION & TRAINING VALIDATION
			if (f.hgrade.value == 0){ 
				alert("Please Select the Highest Grade of High School You Completed.");
				f.hgrade.focus();
				return false;
			}
	/*		if (f.hgraduated.value !="") {
				var matchArrt1 = f.hgraduated.value.match(/^(\d{2})\/?\d{4}$/);
				var numDashest1 =f.hgraduated.value.split('/').length;
				if(matchArrt1 == null || numDashest1 == 1){
					alert("Please enter the Date you Graduated from High School in the follwoing format MM/YYYY.");
					f.hgraduated.focus();
					return false;
				}	
			} */
			if (ged_selection == 'yes' && f.issuestate.value =="" ){
				alert ("Please enter the name of the agency which issued your high school equivalency diploma.");
				f.issuestate.focus();
				return false;				
			} 
				var matchArrt1 = f.hdegreerec.value.match(/^(\d{2})\/?\d{4}$/);
				var numDashest1 =f.hdegreerec.value.split('/').length;
			if (ged_selection=='yes' && (f.hdegreerec.value==""||matchArrt1 == null || numDashest1 == 1)){
				alert ("Please enter the date you received your high school equivalency diploma in the following format: MM/YYYY. ");
				f.hdegreerec.focus();
				return false;
			}

				//Computer Skills Test
				if (cmpttest_selection=='yes'){					
					var matchArrt1 = f.exceldate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.exceldate.value.split('/').length;
					if (f.excel.checked==true &&(f.exceldate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the EXCEL skill test in the following format: MM/YYYY. ");
							f.exceldate.focus();
							return false;
					} else if (f.excelscore.value == "" && f.excel.checked == true){
								alert("Please enter the score you recieved on the EXCEL skills test.");
								f.excelscore.focus();
								return false;		
					 }
					var matchArrt1 = f.accessdate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.accessdate.value.split('/').length;
					if (f.access.checked==true &&(f.accessdate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the ACCESS skill test in the following format: MM/YYYY. ");
							f.accessdate.focus();
							return false;
					 }else if (f.accessscore.value == "" && f.access.checked == true ){
								alert("Please enter the score you recieved on the ACCESS skills test.");
								f.accessscore.focus();
								return false;
					 }
					 
					var matchArrt1 = f.worddate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.worddate.value.split('/').length;
					if (f.word.checked==true &&(f.worddate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the WORD skill test in the following format: MM/YYYY. ");
							f.worddate.focus();
							return false;
					 }else if (f.wordscore.value == "" && f.word.checked==true){
								alert("Please enter the score you recieved on the WORD skills test.");
								f.wordscore.focus();
								return false;
					 }
					var matchArrt1 = f.windowsdate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.windowsdate.value.split('/').length;
					if (f.windows.checked==true &&(f.windowsdate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the WINDOWS skill test in the following format: MM/YYYY. ");
							f.windowsdate.focus();
							return false;
					 }else if (f.windowsscore.value == "" && f.windows.checked==true){
								alert("Please enter the score you recieved on the WINDOWS skills test");
								f.windowsscore.focus();
								return false;
					 }
					var matchArrt1 = f.otherdate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.otherdate.value.split('/').length;
					if (f.other.checked==true &&(f.otherdate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the OTHER skill test in the following format: MM/YYYY. ");
							f.otherdate.focus();
							return false;
					  }else if (f.otherscore.value == "" && f.other.checked == true){
								alert("Please enter the score you recieved on the OTHER skills test ");
								f.otherscore.focus();
								return false;
					 }else if (f.other2.value == "" && f.other.checked == true){
								alert("Please enter the other skill areas you were tested.");
								f.other2.focus();
								return false;	
					 }
					var matchArrt1 = f.ppdate.value.match(/^(\d{2})\/?\d{4}$/);
					var numDashest1 =f.ppdate.value.split('/').length;
					if (f.powerpoint.checked==true &&(f.ppdate.value==""||matchArrt1 == null || numDashest1 == 1)){
							alert ("Please enter the date you took the POWERPOINT skill test in the following format: MM/YYYY. ");
							f.ppdate.focus();
							return false;
					 }else if (f.ppscore.value == "" && f.powerpoint.checked == true){
								alert("Please enter the score you recieved on the skills test.");
								f.ppscore.focus();
								return false;
					 }
					 
					 if (f.excel.checked == false && f.access.checked == false && f.word.checked == false && f.windows.checked == false && f.other.checked == false && f.powerpoint.checked == false){
							alert ("Please select the skill area that you were tested in and provide the date and score you recieved.");
							f.word.focus();
							return false;
					 }		 
				}
				if (f.dateofscore.value != ""){
						var matchArrt1 = f.dateofscore.value.match(/^(\d{2})\/?\d{4}$/);
						var numDashest1 =f.dateofscore.value.split('/').length;
					if(matchArrt1 == null || numDashest1 == 1){
						alert("Please enter the last date you took a typing test at M-NCPPC in the follwoing format MM/YYYY.");
						f.dateofscore.focus();
						return false;
					}
					if(f.typingwpm.value == ""){
						alert("Please enter the typing score you recieved " +f.dateofscore.value+ ".");
						f.typingwpm.focus();
						return false;
					}
				}
					
							
				//End of EDUCATION & TRAINING VALIDATION 
	
					//end of resume
						//Present or most recent position
				/*		if (f.og1.value="") {
							alert ("Please enter the name of the Employer for your present or most recent position.");
							f.og1.focus();
							return false;
						} */	
						if (f.og1.value!="" && f.ogaddress1.value=="") {
							alert ("Please enter the address of the Employer for your present or most recent position.");
							f.ogaddress1.focus();
							return false;
						} 
			
					/*	var valid3 = "0123456789"
						var temp3;
						for (var i=0; i<f.hw1.value.length; i++) 
						temp3 = "" + f.hw1.value.substring(i, i+1);
						if (f.og1.value!=""&&valid3.indexOf(temp3) == "-1")  {
								alert('Please enter the Hours Worked Per Week.'); 
								f.hw1.focus();
								return false;
						}*/


						if (f.og1.value !="" && f.edt1.value=="" ){
						alert ("Please enter the 'To' date.");
						f.edt1.focus();
						return false;
						} 
						
						if (f.og1.value != "" && f.lsy1.value=="" && f.lsm1.value==""){
						alert ("Please enter your 'Last Salary' in the following format 30,000 in either the month or year field.");
						f.lsy1.focus();
						return false;
						}
						//var valid1 = "0123456789"
						//var temp1;
						//for (var i=0; i<f.lsy1.value.length; i++) 
						//temp1 = "" + f.lsy1.value.substring(i, i+1);
							//if (f.lsy1.value !="" &&valid1.indexOf(temp1) == "-1")  {
							//	alert("Please enter your 'Starting Salary' in the following format: 30000"); 
							//	f.lsy1.focus();
							//	return false;
							//}
						//var valid2 = "0123456789"
						//var temp2;
						//for (var i=0; i<f.lsm1.value.length; i++) 
						//temp2 = "" + f.lsm1.value.substring(i, i+1);
						//	if (f.lsm1.value !="" &&valid2.indexOf(temp2) == "-1")  {
						//		alert("Please enter your 'Ending Salary' in the following format: 30000"); 
						//		f.lsm1.focus();
						//		return false;
						//	}
				
						//var valid3 = "0123456789"
						//var temp3;
						//for (var i=0; i<f.hw1.value.length; i++) 
						//temp3 = "" + f.hw1.value.substring(i, i+1);
							//if (f.og1.value!=""&&valid3.indexOf(temp3) == "-1")  {
							//	alert('Please enter the average number of hours you worked per week.'); 
								//f.hw1.focus();
								//return false;
							//}/**/
							
						//End of present or most recent position
						//Second  Position
					/*if (f.og2.value="") {
							alert ("Please enter the name of the Employer for your present or most recent position.");
							f.og2.focus();
							return false;
						}	 */					
						if (f.og2.value!="" && f.ogaddress2.value=="") {
							alert ("Please enter the address of your Former Position.");
							f.ogaddress2.focus();
							return false;
						} 
			
						//var valid3 = "0123456789"
						//var temp3;
						//for (var i=0; i<f.hw2.value.length; i++) 
						//temp3 = "" + f.hw2.value.substring(i, i+1);
						//if (f.og2.value!=""&&valid3.indexOf(temp3) == "-1")  {
								//alert('Please enter the Hours Worked Per Week.'); 
								//f.hw2.focus();
								//return false;
						//}/**/
						
				//		if (f.og2.value !=""&&f.edt2.value=="" ){
				//		alert ("Please enter the 'To' date.");
				//		f.edt2.focus();
				//		return false;
				//		} 
						
						if (f.og2.value != "" && f.lsy2.value=="" && f.lsm2.value==""){
							alert ("Please enter your 'Starting Salary' in the following format 30,000 in either the month or year field.");
							f.lsy2.focus();
							return false;
						}
						//var valid1 = "0123456789"
						//var temp1;
						//for (var i=0; i<f.lsy2.value.length; i++) 
						//temp1 = "" + f.lsy2.value.substring(i, i+1);
							//if (f.lsy2.value !="" &&valid1.indexOf(temp1) == "-1")  {
							//	alert("Please enter your 'Starting Salary' in the following format: 30000"); 
							//	f.lsy2.focus();
								//return false;
							//}
						//var valid2 = "0123456789"
						//var temp2;
						//for (var i=0; i<f.lsm2.value.length; i++) 
						//temp2 = "" + f.lsm2.value.substring(i, i+1);
							//if (f.lsm2.value !="" &&valid2.indexOf(temp2) == "-1")  {
							//	alert("Please enter your 'Ending Salary' in the following format: 30000"); 
							//	f.lsm2.focus();
							//	return false;
							// }
			
						//End of Former Position
						//Third Position
					/*	if (f.og3.value="") {
							alert ("Please enter the name of the Employer for your present or most recent position.");
							f.og3.focus();
							return false;
						} */
						if (f.og3.value!="" && f.ogaddress3.value=="") {
							alert ("Please enter the address of your Former Position.");
							f.ogaddress3.focus();
							return false;
						} 
			
						//var valid3 = "0123456789"
						//var temp3;
						//for (var i=0; i<f.hw3.value.length; i++) 
						//temp3 = "" + f.hw3.value.substring(i, i+1);
						//if (f.og3.value!=""&&valid3.indexOf(temp3) == "-1")  {
								//alert('Please enter the Hours Worked Per Week.'); 
								//f.hw3.focus();
								//return false;
						//}/**/

						if (f.og3.value != "" && f.lsy3.value=="" && f.lsm3.value==""){
						alert ("Please enter your 'Last Salary' in the following format 30,000 in either the month or year field.");
						f.lsy3.focus();
						return false;
						}
						//var valid1 = "0123456789"
						//var temp1;
						//for (var i=0; i<f.lsy3.value.length; i++) 
						//temp1 = "" + f.lsy3.value.substring(i, i+1);
						//	if (f.lsy3.value !="" &&valid1.indexOf(temp1) == "-1")  {
						//		alert("Please enter your 'Starting Salary' in the following format: 30000"); 
							//	f.lsy3.focus();
							//	return false;
							//}
						//var valid2 = "0123456789"
						//var temp2;
						//for (var i=0; i<f.lsm3.value.length; i++) 
						//temp2 = "" + f.lsm3.value.substring(i, i+1);
							//if (f.lsm3.value !="" &&valid2.indexOf(temp2) == "-1")  {
							//	alert("Please enter your 'Ending Salary' in the following format: 30000"); 
							//	f.lsm3.focus();
							//	return false;
							//}

						//End of Third Position
						//Other information
										
				//End of PROFESSIONAL EXPERIENCE
				//Background Information
				
					if (felony_selection == ""){
							alert("Please indicate if you have a valid driver licence.");
							f.driverslicence[0].focus();
							return false;
					
					}

					if (convicted_selection == ""){
							alert("Please indicate if you ever been convicted, imprisoned, on probation, or on parole for other than minor traffic violations by a civilian or military authority.");
							f.convicted[0].focus();
							return false;
					
					}
					if (charges_selection == ""){
							alert("Please indicate if you now under charges for any offense(s) against the law other than minor traffic violations?");
							f.charges[0].focus();
							return false;
					
					}
					if ((charges_selection == 'yes' || convicted_selection == 'yes') && f.explanation.value == ""){
							alert("If your response is 'YES' to either question, you must provide complete details that include dates, explanation of the violation, place of occurrence, and the name and address of the police department or court involved");
							f.explanation.focus();
							return false;
					}

				//End of Background Inforamtion
				
				
		
		/**/
}

function filterNum(str) {
re = /^\$|,|a|A|B|b|C|c|D|d|E|e|F|f|G|g|H|h|I|i|J|j|K|k|L|l|M|m|N|n|O|o|P|p|Q|q|R|r|S|s|T|t|U|u|V|v|W|w|X|x|Y|y|Z|z/g;
// remove "$" and ","
return str.replace(re, "");
}


