$(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 emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  //var emailReg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
  var email = $("input#GoGifty_email").val();
		if (email == "") {
      $("label#GoGifty_email_error").show();
      $("input#GoGifty_email").focus();
      return false;
    }
else if(!emailReg.test(email)) {
            $("label#GoGifty_email_error2").show();
      $("input#GoGifty_email").focus();
            //hasError = true;
	    return false;
        }



var location = $("select#GoGifty_location").val();




		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var dataString = 'email=' + email + '&location=' + location;
		//alert (dataString);return false;	//	testing
		
		$.ajax({
      type: "POST",
      url: "http://www.gogifty.co.uk/newsletter/register_new.php",
      data: dataString,
      success: function() {
        $('#GoGifty_contact_form').html("<div id='GoGifty_message'></div>");
        $('#GoGifty_message').html("<center><h2>You're signed up for great deals!</h2></center>")
        .append("<h3><center><img src='http://www.gogifty.co.uk/newsletter/date.png' />  Keep a watchful eye on your Inbox!  <img src='http://www.gogifty.co.uk/newsletter/date.png' /></center></h3>")
        .hide()
        .fadeIn(1500, function() {
          $('#GoGifty_message').append("");
	  
	  
	  
        });
	
	
	
      }
     });
		
		
		
    return false;
	});
  
  
});
//runOnLoad(function(){
//  $("input#name").select().focus();
//  });



 
 
