$(document).ready(function(){
			$('.error').hide();
})

$(function() {
            $("#submitButton").click(function(){
				
				var firstname = $("input#first").val();
				if (firstname == "") {
      					$("label#first_error").show();
      					$("input#first").focus();
      					return false;
    			}	
				var lastname = $("input#last").val();
				if (lastname == "") {
      					$("label#lastname_error").show();
      					$("input#last").focus();
      					return false;
    			}
				var email = $("input#email").val();
				if (email == "") {
      					$("label#email_error").show();
      					$("input#email").focus();
      					return false;
    			}
				

 					for(var i=0; i<email.length; i++){
   						if(email.indexOf("@")==-1){
   						$("label#email_error").html("Your Email Address Must Have A '@' !");
   						return false
   					}
 				}

   					if(email.indexOf(".")==-1){
  						$("label#email_error").html("You must have a Dot in your Email!");
   						return false
 				 	}
					
					var e =email.split("@")
					if (e[1].indexOf(".") == -1){
						$("label#email_error").html("You need a DOT to be after the @");
						return false
  				}
				
				var phone1 = $("input#phone1").val();
				var phone2 = $("input#phone2").val();
				var phone3 = $("input#phone3").val();
				var phone = phone1 + '-' + phone2 + '-' + phone3;
				var province = $("#province").val();
				var city = $("input#city").val();
				var topic = $("#topic").val();
				var question = $("#question").val();
				var dataString = 'first_name='+ firstname + '&last_name=' + lastname + '&email=' + email + '&phone='+ phone + '&province=' + province + 			'&city=' + city + '&topic=' + topic + '&question=' + question;
				
				$.ajax({
					type: "POST",
					url: "http://www.financialinsiders.ca/consultations/php/submit.php",
					data: dataString,
					success: function(data) {
						if(data == "emailexists") {
							$("label#email_error").html("Email Already Exists");
						}	else {
							
							$('.leftForm').html("<h2>Thank You</h2>");
						}
					}
			
					});
				return false;
			});
			
        })



