jQuery(function() {
	jQuery('.error').hide();
  
	// reset no errors
	jQuery('input.text-input').css({backgroundColor:"#fff"});
	jQuery('input.text-input').focus(function(){ jQuery(this).css({backgroundColor:"#ededed"}); });
	jQuery('input.text-input').blur(function(){ jQuery(this).css({backgroundColor:"#fff"}); });
	
	jQuery('textarea.text-input').css({backgroundColor:"#fff"});
	jQuery('textarea.text-input').focus(function(){ jQuery(this).css({backgroundColor:"#ededed"}); });
	jQuery('textarea.text-input').blur(function(){ jQuery(this).css({backgroundColor:"#fff"}); });
	
	
	jQuery(".button").click(function() {
		// validate and process form first hide any error messages
	    jQuery('.error').hide();
			
		var name = jQuery("input#name").val();
		if (name == "") {
	      jQuery("label#name_error").show();
	      jQuery("input#name").focus();
	      return false;
		}
		
		var email = jQuery("input#email").val();
		if (email == "") {
	      jQuery("label#email_error").show();
	      jQuery("input#email").focus();
	      return false;
	    }
		
		var comment = jQuery("textarea#comment").val();
		if (comment == "") {
	      jQuery("label#comment_error").show();
	      jQuery("textarea#comment").focus();
	      return false;
	    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment;
		//alert (dataString);return false;
		
		jQuery.ajax({
			type: "POST",
			url: "http://www.visiomente.com/wp-content/themes/visiomente/bin/process.php",
      		data: dataString,
      		success: function() {
        		//alert('success');
				jQuery('#contact-form').html("<div id='message'></div>");
        		jQuery('#message').html("<h2>Thank you for your submission.</h2>")
        		.append("<h3>We will be in touch soon.</h3>")
		        .hide()
		        .fadeIn(1500, function() {
		          jQuery('#message').append("<img id='checkmark' src='http://www.visiomente.com/wp-content/themes/visiomente/images/forms/check.png' />");
		        });
      		},
      		error: function(XMLHttpRequest, textStatus, errorThrown){
				jQuery('#contact-form').html("<div id='message'></div>");
        		jQuery('#message').html("<h2>An error occured during your submission.</h2>")
        		.append("<h3>Please contact us immediately for assistance!</h3>")
		        .hide()
		        .fadeIn(1500, function() {
		          jQuery('#message').append("<img id='checkmark' src='images/forms/check.png' />");
		        });
			}
     	});
    	return false;
	});
});
runOnLoad(function(){
  jQuery("input#name").select().focus();
});
