$(function() {  
  $('.error').hide();
  $(".button").click(function() {
	// validate and process form here  
	$('.error').hide();  
    var name = $("input#name").val();
	  if (name == "") {  
      $("label#name_error").show();  
      $("input#name").focus();  
      return false;  
    }  
    var email = $("input#email").val(); 
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;	
    if (email == "") {  
      $("label#email_error").show();  
      $("input#email").focus();  
      return false;  
    }else if( !emailReg.test( email ) ){
		$("label#email_error").html('<label class="error" for="email" id="email_error">Please enter valid email.</label>');
		$("label#email_error").show();  
        $("input#email").focus();
		return false;
	}  
        var country = $("input#country").val();  
        if (country == "") {  
      $("label#country_error").show();  
      $("input#country").focus();  
      return false;  
    }  
	
	var dataString = 'name='+ name + '&email=' + email + '&country=' + country;  
	//alert (dataString);return false;  
	$.ajax({  
	  type: "POST",  
	  url: "popUp.php",  
	  dataType: 'json',
	  data: dataString,  
	  success: function(html) {
		if( html.msg == 'success' ) {
			$('#outerImageContainer').css('cssText', 'height: 150px !important;width: 500px !important');
			$('#modalContainer').css('cssText', 'height: 150px !important;width: 500px !important');
			$('#newsletter_form').html("<div id='message'></div>");
			$('#message').html("<h2 style ='margin-top: 0;'>Newsletter Form Submitted!</h2>")  
			.append("<table><tr><td><img width ='100px' height = '150px' src = 'http://www.timeforresults.com/images/karlaThanks.jpg'/></td><td style = 'vertical-align: top;padding-top:5px;padding-left:5px;'>Please check your email in three minutes for an email from Karla@KarlaBrandau.com. It will contain the download links to Karla's complimentary materials that will help you determine your future.</td></tr></table>")  
			.hide()  
			.fadeIn(1500, function() {  
			  $('#message').append("");  
			});
			
		}else{
			alert('Sorry, unexpected error. Please try again later.');
			$('#newsletter_form').html("<div id='message'></div>");  
			$('#message').html("Sorry, unexpected error. Please try again later.")  
		}	
	  }  
	});  
	return false;
  
  });
  
  
  
  
  
	
});


