jQuery(function($) {
	
	
	$('#submitbtn').click(function() {

		var error_msg = "Please fix the following fields\n\n";
		var errors = 0;	
		var gencnt = 0;
		var agecnt = 0;
		
		$('.required').each(function(i) {			
			var fieldname = $(this).attr('name');
			switch(fieldname) {
				case "five_experiences":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter two of the five experiences from the video \n"; 
							$(this).addClass('error');	
					}
				break;firstname
				case "firstname":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your first name \n"; 
							$(this).addClass('error');	
					}
				break;
				case "lastname":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your last name \n"; 
							$(this).addClass('error');	
					}
				break;
				case "email":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your email address \n"; 
							$(this).addClass('error');	
					}else if (!checkemail($(this).val())) {
						errors++;
						error_msg += "Your email address is invalid, please enter a valid adderss \n";
						$(this).addClass('error');
					}
				break;
				case "address":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your address \n"; 
							$(this).addClass('error');	
					}
				break;
				case "phone1":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your country code \n"; 
							$(this).addClass('error');	
					}
				break;
				case "phone2":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your area code \n"; 
							$(this).addClass('error');	
					}
				break;	
				case "phone3":
					if ($(this).val() == "") { 
							errors++; 
							error_msg += "Enter your phone number \n"; 
							$(this).addClass('error');	
					}
				break;
				case "country":
					if ($(this).val() != "1") { 
							errors++; 
							error_msg += "Enter your country \n"; 
							$(this).addClass('error');	
					}
				break;
			}
		})
		
		if (errors == 0) {
			$("form").submit();
		}else{
			alert(error_msg);
		}

	})	
	
});

var testresults
function checkemail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) {
		testresults=true
	}else{
		//alert("Please input a valid email address!")
		testresults=false
	}
	return (testresults)
}
