$(function() {
  $('.error').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"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
var name = $("input#name").val();
       if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

    var email = $("input#email").val();
    if (email == "" || !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
    var phone = $("input#phone").val();
    if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
  //var enquiry = $("input#hearabthidd").val();
		
    var hearabt = $("input#hearabthidd").val();
		
    var contactme = $("input#contactmehidd").val();
		
    if (document.getElementById('agree').checked == false ){
                 $("label#agree_error").show();
                 return false;
    }
		//var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&enquiry=' + enquiry + '&hearabt=' + hearabt + '&contactme=' + contactme ;
		//alert (dataString);return false;

                var ajaxurl = 'http://projects.thesoundpipemedia.com/law/wp-admin/admin-ajax.php';
          var data='action=contact_action&name='+ name + '&email=' + email + '&phone=' + phone+ '&hearabt=' + hearabt+ '&contactme=' + contactme ;
	jQuery.post(ajaxurl, data, function(response) {
	              if(response == 1) {
	                 // alert("if");
	              } else {
                        document.getElementById('message').innerHTML="";
                        document.getElementById('message').innerHTML=response;
                        document.getElementById('name').value='';
                        document.getElementById('email').value='';
                        document.getElementById('phone').value='';
                        document.getElementById('enquiry').value='';
                        document.getElementById('hearabthidd').value='';
                        document.getElementById('contactmehidd').value='';
                        document.getElementById('hearabt').selectedIndex = 0;
                        document.getElementById('contactme').selectedIndex = 0;


                        
	              }
	          });
    return false;
	});
});


