// JavaScript Document

// JavaScript Document
$(function() {
		   
	function isValidEmailAddress(emailAddress) {
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			return pattern.test(emailAddress);
	}
	
	var mac = $.client.os;
	var safari = $.client.browser;
	if (mac == 'Mac' && (safari == 'Safari' || safari == 'Firefox')) {
		$('form#franchise_form p.big_right').css({
													'width': 514
												 });
		$('form#franchise_form p.big input[name=employer]').css({
										   'width':'339px',
										   'margin-right':'8px'
										   
										   });
		$('form#franchise_form input[name=dob]').css({'width':'67px'});
	}
	
	$('input[name=submit]').click(function() {
		var title = $('select#title option:selected').val();
		var fname = $('#fname').val();
		var lname = $('#lname').val();
		var address = $('#address').val();
		var town = $('#town').val();
		var county = $('#county').val();
		var post_code = $('#post_code').val();
		var home_no = $('#home_no').val();
		var email = $('#email').val();
		var dob = $('input[name=dob]').val();
		var marital = $('#marital').val();
		var phone = $('#phone').val();
		var nationality = $('#nationality').val();
		var date = $('#date').val();
		var employer = $('#employer').val();
		var responsibility = $('#responsibility').val();
		var salary = $('#salary').val();
		var success = $('#success').val();
		var interest = $('select#interest option:selected').val();
		var pack = $('select#pack option:selected').val();
		var finance = $('#finance').val();
		var capital = $('select#capital option:selected').val();
		var home_owner = $('select#home_owner option:selected').val();
		var location = $('select#location option:selected').val();
		
		
		if(title == "Please select" && fname == "" && lname == "" && address == "" && town == "" && county == "" && post_code == "" && home_no == "" && email == "" && dob == "" && marital == "Please select" && phone == "" && nationality == "" && date == "" && employer == "" && responsibility == "" && salary == "" && success == "" && interest == "Please select" && pack == "Please select" && finance == "" && capital == "Please select" && home_owner == "Please select" && location == "Please select") {
			alert("Please complete all the fields in the form");
			$('#title').focus();
			return false;
		}else if(fname == "") {
			alert('please enter your first name');
			$('#fname').focus();
			return false;
		}else if(lname == "") {
			alert('please enter your last name');
			$('#lname').focus();
			return false;
		}else if(address == "") {
			alert('please enter your address');
			$('#address').focus();
			return false;
		}else if(town == "") {
			alert('please enter your town');
			$('#town').focus();
			return false;
		}else if(county == "") {
			alert('please enter your county');
			$('#county').focus();
			return false;
		}else if(post_code == "") {
			alert('please enter your post code');
			$('#post_code').focus();
			return false;
		}else if(home_no == "") {
			alert('please enter your house number');
			$('#home_no').focus();
			return false;
		}else if(email == "") {
			alert('please enter your email');
			$('#email').focus();
			return false;
		}else if(dob == "") {
			alert('please enter your date of birth');
			$('#dob').focus();
			return false;
		}else if(marital == "Please select") {
			alert('please enter your marital status');
			$('#marital').focus();
			return false;
		}else if(phone == "") {
			alert('please enter your telephone number');
			$('#phone').focus();
			return false;
		}else if(nationality == "") {
			alert('please enter your nationality');
			$('#nationality').focus();
			return false;
		}else if(date == "") {
			alert('please enter the dates you worked');
			$('#date').focus();
			return false;
		}else if(employer == "") {
			alert('please enter your employers details');
			$('#employer').focus();
			return false;
		}else if(responsibility == "") {
			alert('please enter your responsibilities');
			$('#responsibility').focus();
			return false;
		}else if(salary == "") {
			alert('please enter your salary');
			$('#salary').focus();
			return false;
		}else if(success == "") {
			alert('please specify why you think that you can be a successful business person');
			$('#success').focus();
			return false;
		}else if(interest == "Please select") {
			alert('please specify your interest level');
			$('#interest').focus();
			return false;
		}else if(pack == "Please select") {
			alert('please select yes if you received your info pack');
			$('#pack').focus();
			return false;
		}else if(finance == "") {
			alert('please specify how you re planning to fund your purchase');
			$('#finance').focus();
			return false;
		}else if(capital == "Please select") {
			alert('please specify your liquid capital');
			$('#capital').focus();
			return false;
		}else if(home_owner == "Please select") {
			alert('please select yes if you are a home owner');
			$('#home_owner').focus();
			return false;
		}else if(location == "Please select") {
			alert('please select your location');
			$('#location').focus();
			return false;
		}
		
										  
	});
	
});
