$(function() {
  $('.error2').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
//  $('input.text-input').focus(function(){
//    $(this).css({backgroundColor:"#FFDDAA"});
//  });
//  $('input.text-input').blur(function(){
//    $(this).css({backgroundColor:"#FFFFFF"});
//  });

  $(".contact_button").click(function() {
							  	
		// validate and process form
		// first hide any error messages
    $('.error2').hide();
		

		var email = $("input#email2").val();
		if (email == "") {
      $("label#email_error2").show();
	   $("label#email_error2").text("Please enter your email address.");
      $("input#email2").focus();
      return false;
    }
	
	
	
	  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
      var email = $("input#email2").val();
   if(reg.test(email) == false) {
	    $("label#email_error2").show();
		$("label#email_error2").text("Email address is not valid.");
		$("input#email2").focus();
		return false;
	   
   }
	

	  var interest = $("select#interest2").val();
		if (interest == "null") {
      $("label#interest_error2").show();
	  
      $("input#interest2").focus();
      return false;
    }
	
		var question = $("textarea#question2").val();
		if (question == "") {
      $("label#question_error2").show();
      $("input#question2").focus();
      return false;
    }
		
		var dataString = 'interest='+ interest + '&email=' + email + '&question=' + question;
		//alert (dataString);return false;
		
		
		$.ajax({
      type: "POST",
      url: "http://www.substance-marketing.com/wp-content/themes/Substance/send_contact.php",
      data: dataString,
      success: function() {
		  


      $('#main_contact_form').html("<div id='message2'></div>");
	// 		document.getElementById("contactForm").style.background = "url(http://www.substance-marketing.com/wp-content/themes/Substance/images/form-bg-thanks.png)";

       $('#message2').html("<h2>Contact Form Submitted!</h2>")
	
       // .append("<p>We will be in touch soon.</p>")
      .hide()
        .fadeIn(300, function() {
          $('#message2');
        });
      }
     });
    return false;
	});
});

