$(function() {

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

  $("#send-query").click(function() { 

    jQuery.fn.cleanWhitespace = function() {
    textNodes = this.contents().filter(
        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
        .remove();
    }
 
    $('.shareerror').hide();
     
         
    var customer_name = $("input#name").val();
    if (customer_name == "") {
      $("label#labname").show();
      $("input#name").focus();
      return false;
    } 
    
    var customer_email = $("input#email").val();
    if (customer_email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }	

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(customer_email) == false) {
      $("label#invalidemail_error").show();
      $("input#email").focus();
      return false;
    }	 			

   var customer_query = $("textarea#message_input").val();

    if (customer_query == "") {
      $("label#message_error").show();
      $("textarea#message_input").focus();
      return false;
    } 

    var dataString = "customer_name="+ customer_name +"&customer_email="+ customer_email +"&customer_query="+customer_query;
   
      $.ajax({
      type: "POST",
      url: "sendemail.php",
      data: dataString,
      success: function ( result, request ) {
	  $(".contactmessage").html("Thank you for your interest.");
	}
     });
    return false;
	});

// Newsletter 
   $("#send-newsletter").click(function() { 

    jQuery.fn.cleanWhitespace = function() {
    textNodes = this.contents().filter(
        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
        .remove();
    }
 
    $('.shareerror').hide();
     
         
    var customer_name = $("input#newsname").val();
    if (customer_name == "") {
      $("label#labnewsname").show();
      $("input#newsname").focus();
      return false;
    } 
    
    var customer_email = $("input#newsemail").val();
    if (customer_email == "") {
      $("label#newsemail_error").show();
      $("input#newsemail").focus();
      return false;
    }	

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(customer_email) == false) {
      $("label#invalidnewsemail_error").show();
      $("input#newsemail").focus();
      return false;
    }	 			
 
     var dataString = "customer_name="+ customer_name +"&customer_email="+ customer_email;
   
      $.ajax({
      type: "POST",
      url: "savenewsletter.php",
      data: dataString,
      success: function ( result, request ) {
	if(result ==1){				
	   $(".newsmessage").html("User is already exist.");
	 }
	else{
	    $(".newsmessage").html("Thank you for your interest.You have successfully subscribed for our email updates.");	
	}
	}
     });
    return false;
	});		
});

