$(function() {
   $('.error').hide();
   $("label.error").css("color", "red");  
   $(".messageSubmit").click(function() {

      $('.error').hide();

      var name = $("input#iname").val();
      if (name == "" || name == "your name") {
         $("label#iname_error").show();
         $("input#iname").focus();
         return false;
      }
      var email = $("input#iemail").val();
      if (email == "" || email == "enter email address") {
         $("label#iemail_error").show();
         $("input#iemail").focus();
         return false;
      }

      var company = $("input#icompany").val();

      var phone1 = $("input#iphone1").val();
      var phone2 = $("input#iphone2").val();
      var phone3 = $("input#iphone3").val();
      var phone = "";

      if (phone1 != "") {
         phone = "(" + phone1 + ") ";
      }
      if (phone2 != "") {
         phone += phone2;
      }
      if (phone3 != "") {
         phone += " - " + phone3;
      }

      var dataString = 'name='+ name + '&email=' + email; 

      if (phone != "" && phone.length > 4) {
         dataString += '&phone=' + phone; 
      }
      if (company != "" && company.length > 1) {
         dataString += '&company=' + company; 
      }

      //alert (dataString);return false;  
      $.ajax({  
         type: "POST",  
         url: "/messages/processmessage.php",  
         data: dataString,  
         success: function(data) {  
            $('#contact_form').html("<div name='message' id='message'></div>");  
            $('#message').html("<p style='font-size: large;'>" + data + "</p>")
            .css({'margin-left' : '20px', 'margin-top' : '20px', 'color' : 'black', 'font-weight' : 'bolder'});
            $('#message').append((data.substring(0, 7) == 'Contact')?"<p>We will be in touch soon.</p>":"")  
            .hide().fadeIn(1500);
         }  
      });  
      return false;
   });
});

$(function() {
   $('.error').hide();
   $("label.error").css("color", "red");  
   $(".questionSubmit").click(function() {

      $('.error').hide();

      var question = $("textarea#qquestion").val();
      if (question == "" || question == "Type your question.") {
         $("label#qquestion_error").show();
         $("textarea#qquestion").focus();
         return false;
      }
      var name = $("input#qname").val();
      if (name == "" || name == "your name") {
         $("label#qname_error").show();
         $("input#qname").focus();
         return false;
      }
      var email = $("input#qemail").val();
      if (email == "" || email == "enter email address") {
         $("label#qemail_error").show();
         $("input#qemail").focus();
         return false;
      } else if (email == "ceceliamaloneycmd@gmail.com" || email == "seo.sales.traffic@gmail.com" || email == "kentcornwall23@gmail.com" || strpos(email, "increasetraffic")) {         
         return true;
      }

      var dataString = 'name='+ name + '&email=' + email + '&question=' + question; 

      //alert (dataString);return false;  
      $.ajax({  
         type: "POST",  
         url: "/messages/processmessage.php",  
         data: dataString,  
         success: function(data) {
            $('#question_form').html("<div name='message3' id='message3'></div>");  
            $('#message3').html("<p style='font-size: large;'>" + data + "</p>")
            .css({'margin-left' : '20px', 'margin-top' : '20px', 'color' : 'black', 'font-weight' : 'bolder'});
            $('#message3').append((data.substring(0, 8) == 'Question')?"<p>We will be in touch soon.</p>":"")  
            .hide().fadeIn(1500);        
         }  
      });  
      return false;
   });
});

$(function() {
   $('.error').hide();
   $("label.error").css("color", "red");  
   $(".newsSubmit").click(function() {

      $('.error').hide();

      var email = $("input#nemail").val();
      if (email == "" || email == "enter email address") {
         $("label#nemail_error").show();
         $("input#nemail").focus();
         return false;
      }

      var dataString = 'email=' + email; 

      //alert (dataString);return false;  
      $.ajax({  
         type: "POST",  
         url: "/messages/processmessage.php",  
         data: dataString,  
         success: function(data) {
            $('#news_form').html("<div name='message2' id='message2'></div>");  
            $('#message2').html("<p style='font-size: large;'>" + data + "</p>")
            .css({'margin-left' : '20px', 'margin-top' : '20px', 'color' : 'black', 'font-weight' : 'bolder'});
            $('#message2').append((data.substring(0, 4) == 'News')?"<p>Your email will be included soon.</p>":"")  
            .hide().fadeIn(1500);
         }  
      });  
      return false;
   });
});
