function setForm() {
	var today = new Date();
	
	//date set
	document.jobForm.dated_day.value = (today.getDate() < 9) ? "0" + today.getDate() : today.getDate();
	document.jobForm.dated_month.value = ((today.getMonth() + 1) < 9) ? "0" + (today.getMonth() + 1) : (today.getMonth() + 1);
	document.jobForm.dated_year.value = today.getYear();
}

function checkStartDay() {
	if (!document.jobForm.start_day.value.length) {
		alert("Please complete the Starting Date (Day) Entry Box!");
		document.jobForm.start_day.focus();
	} else if (document.jobForm.start_day.value.length < 2) {
		document.jobForm.start_day.value = "0" + document.jobForm.start_day.value;
	} else if (document.jobForm.start_day.value > 31) {
		alert("Please correct the Starting Date (Day) Entry Box!\nDay number is " + document.jobForm.start_day.value);
		document.jobForm.start_day.focus();
	}
}

function checkStartMonth() {
	if (!document.jobForm.start_month.value.length) {
		alert("Please complete the Starting Date (Month) Entry Box!");
		document.jobForm.start_month.focus();
	} else if (document.jobForm.start_month.value.length < 2) {
		document.jobForm.start_month.value = "0" + document.jobForm.start_month.value;
	} else if (document.jobForm.start_month.value > 12) {
		alert("Please correct the Starting Date (Month) Entry Box!\nMonth number is " + document.jobForm.start_month.value);
		document.jobForm.start_month.focus();
	}
}

function checkStartYear() {
	if (!document.jobForm.start_year.value.length) {
		alert("Please complete the Starting Date (Year) Entry Box!");
		document.jobForm.start_year.focus();
	} else if (document.jobForm.start_year.value.length < 4) {
		alert("Please complete the Starting Date (Year) Entry Box!\nRight now it is to short!");
		document.jobForm.start_year.focus();
	}
}

function checkFinishDay() {
	if (!document.jobForm.finishing_day.value.length) {
		alert("Please complete the Finishing Date (Day) Entry Box!");
		document.jobForm.finishing_day.focus();
	} else if (document.jobForm.finishing_day.value.length < 2) {
		document.jobForm.finishing_day.value = "0" + document.jobForm.finishing_day.value;
	} else if (document.jobForm.finishing_day.value > 31) {
		alert("Please correct the Finishing Date (Day) Entry Box!\nDay number is " + document.jobForm.finishing_day.value);
		document.jobForm.finishing_day.focus();
	}
}

function checkFinishMonth() {
	if (!document.jobForm.finishing_month.value.length) {
		alert("Please complete the Finishing Date (Month) Entry Box!");
		document.jobForm.finishing_month.focus();
	} else if (document.jobForm.finishing_month.value.length < 2) {
		document.jobForm.finishing_month.value = "0" + document.jobForm.finishing_month.value;
	} else if (document.jobForm.finishing_month.value > 12) {
		alert("Please correct the Finishing Date (Month) Entry Box!\nMonth number is " + document.jobForm.finishing_month.value);
		document.jobForm.finishing_month.focus();
	}
}

function checkFinishYear() {
	if (!document.jobForm.finishing_year.value.length) {
		alert("Please complete the Finishing Date (Year) Entry Box!");
		document.jobForm.finishing_year.focus();
	} else if (document.jobForm.finishing_year.value.length < 4) {
		alert("Please complete the Finishing Date (Year) Entry Box!\nRight now it is to short!");
		document.jobForm.finishing_year.focus();
	}
}

function checkForm(form) {
	var flexiHours = false;
	
	if (!form.company_name.value.length) {
		alert("Please complete the Company Name Entry Box!");
		form.company_name.focus();
		return false;
	}
	
	if (!form.street.value.length) {
		alert("Please complete the Street Entry Box!");
		form.street.focus();
		return false;
	}
	
	if (!form.zipcode.value.length) {
		alert("Please complete the Zip-Code Entry Box!");
		form.zipcode.focus();
		return false;
	}
	
	if (!form.city.value.length) {
		alert("Please complete the City / Post Office Entry Box!");
		form.city.focus();
		return false;
	}
	
	if (!form.email.value.length) {
		if (!confirm("The E-mail address entry box is empty!\nDo you want to continue?")) {
			alert("Please complete the E-mail address Entry Box!");
			form.email.focus();
			return false;
		}
	} else {
		var str = form.email.value;
      var hasAt = false, hasDot = false, hasDoubleDot = false;
      var countAt = 0, countDot = 0;
		var indexAt = 0, indexDoubleDot = 0;
      
		if ((str.charAt(0) == '@') || (str.charAt(0) == '.')) {
			alert("The E-mail address entry box is invalid!\nE-mail address cannot start with a '" + str.charAt(0) + "' character!");
         form.email.focus();
         return false;
      } else if ((str.charAt(str.length-1) == '@')) {
         alert("The E-mail address entry box is invalid!\nThere is a mail server domain missing!\nYou have: " + form.email.value + "\nShould be (eg.): " + form.email.value + "server.com");
         form.email.focus();
         return false;
      } else if ((str.charAt(str.length-1) == '.')) {
			alert("The E-mail address entry box is invalid!\nThere is a domain missing!\nYou have: " + form.email.value + "\nShould be (eg.): " + form.email.value + "com");
         form.email.focus();
         return false;
		}
		  
      for(i = 0; i < str.length; i++) {
			switch(str.charAt(i)) {
				case '@':
					hasAt = true;
					countAt++;
					break;
				case ' ':
            case '\\':
            case '/':
            case '!':
            case '~':
            case '`':
            case '#':
            case '$':
            case '%':
            case '^':
            case '&':
            case '*':
            case '(':
            case ')':
            case '+':
            case '=':
            case '|':
            case '{':
            case '}':
            case '[':
            case ']':
            case ':':
            case ';':
            case '"':
            case '\'':
            case '<':
            case '>':
            case ',':
            case '?':
            	alert("The E-mail address entry box is invalid because of a wrong charecter '" + str.charAt(i) +"' at the position no. " + (i+1));
               form.email.focus();
               return false;                    
            default:
               break;
         }
			
			if (hasAt) {
      		if (countAt != 1) {
         		alert("The E-mail address entry box is invalid!\nThere are to many '@' characters!");
	            return false;
   	      } else {
					if (indexAt == 0) {
						indexAt = i;
					}
				}
      	}
		}
	 
		if (!hasAt) {
         alert("The E-mail address entry box is invalid!\nThere is a '@' character missing!");
         form.email.focus();
         return false;
      }
		
		for(i = indexAt; i < str.length; i++) {
			if (str.charAt(i) == '.') {
				countDot++;
				hasDot = true;
				if (str.charAt(i+1) == '.') {
					if (!hasDoubleDot) {
						hasDoubleDot = true;
						indexDoubleDot = i+1;
					} else {
						break;
					}
				}
			}
		}
		
		if (!hasDot) {
			alert("The E-mail address entry box is invalid!\nThere is a domain name missing!");
         form.email.focus();
         return false;
		} else {
			if (indexDoubleDot != 0) {
				var errStr = str.substring(indexDoubleDot-1, str.length);
				var corrStr = str.substring(0, indexDoubleDot-1);
				
				hasDoubleDot = false;
				for(i = 0; i < errStr.length; i++) {
					if (errStr.charAt(i) == '.') {
						if (errStr.charAt(i+1) != '.') {
							if (!hasDoubleDot) {
								corrStr += errStr.charAt(i);
							}							
						} else {
							if (!hasDoubleDot) {
								hasDoubleDot = true;
								corrStr += errStr.charAt(i);
							}
						}
					} else {
						if (hasDoubleDot) {
							hasDoubleDot = false;
						}
						corrStr += errStr.charAt(i);
					}
				}
				
				if (confirm("The E-mail address entry box is invalid!\nThere are to many dots in the mail server address!\nYou have: " + str + "\nShould be: " + corrStr + "\n\nWould you like me, to put the correct value into the E-mail address entry box?")) {
					form.email.value = corrStr;
					alert("The E-mail address entry box was changed!\nPlease click SEND button to send the form.");
					form.sendButton.focus();
				} else {
					alert("Please correct the E-mail address entry box immediately!");
					form.email.focus();
				}
				return false;
			}
		}
	}
	
	if (!form.job_title.value.length) {
		alert("Please complete the Job Title Entry Box!");
		form.job_title.focus();
		return false;
	}
	
	if (!form.number_vacancies.value.length) {
		alert("Please complete the No. Vacancies Entry Box!");
		form.number_vacancies.focus();
		return false;
	}
	
	if (!form.preffered_age.value.length) {
		alert("Please complete the Preferred Age Entry Box!");
		form.preffered_age.focus();
		return false;
	}
	
	if (!form.male.checked) {
		if (!form.female.checked) {
			alert("Please complete the Preferred Sex Entry Box!");
			form.male.focus();
			return false;
		}
	} else {
		if (form.female.checked) {
			alert("Are you sure!? :))");
			form.male.focus();
			return false;
		}
	}
	
	if (!form.duties.value.length) {
		alert("Please complete the Full Description of Duties Entry Box!");
		form.duties.focus();
		return false;
	}
	
	if (!form.uniform_yes.checked) {
		if (!form.uniform_no.checked) {
			alert("Please complete the Uniform Supplied Entry Box!\nOne Box Must Be Completed YES or No");
			form.uniform_yes.focus();
			return false;
		}
	} else {
		if (form.uniform_no.checked) {
			alert("Are you sure!?\nOne Box Must Be Completed YES or No");
			form.uniform_yes.focus();
			return false;
		}
	}
	
	if (!form.flexi_hours_yes.checked) {
		if (!flexi_hours_no.checked) {
			alert("Please complete the Will Flexi Hours be worked? Entry Box!\nOne Box Must Be Filled YES or No");
			form.flexi_hours_yes.focus();
			return false;
		}
	} else {
		flexiHours = true;
		if (form.flexi_hours_no.checked) {
			alert("Are you sure!?\nOne Box Must Be Filled YES or No");
			form.flexi_hours_yes.focus();
			return false;
		}
	}
	
	if (flexiHours) {
		if (!form.examples_add_cloth.value.length) {
			alert("Please complete the If Yes... Entry Box!");
			form.examples_add_cloth.focus();
			return false;
		}
	}
	
	if (!form.hour_pay.value.length) {
		alert("Please complete the Hourly Rate of Pay Entry Box!");
		form.hour_pay.focus();
		return false;
	}
	
	if (!form.numbers_hours_week.value.length) {
		alert("Please complete the Number of Hours Worked per Week Entry Box!");
		form.numbers_hours_week.focus();
		return false;
	}
	
	if (!form.days_week.value.length) {
		alert("Please complete the No. of Days Off per Week Entry Box!");
		form.days_week.focus();
		return false;
	}
	
	if (!form.boards_lodging.value.length) {
		alert("Please complete the Board & Lodging Entry Box!");
		form.boards_lodging.focus();
		return false;
	}
	
	if (!form.terms_agreed_by.value.length) {
		alert("Please complete the These terms & Conditions of Employment have been agreed by Entry Box!");
		form.terms_agreed_by.focus();
		return false;
	}
	
	if (!form.position_held.value.length) {
		alert("Please complete the Position Held Entry Box!");
		form.position_held.focus();
		return false;
	}
	return true;
}