jQuery.validator.addMethod("notplaceholder", function(value, element, params) {
    return value != element.attr("data-placeholder");
}, jQuery.validator.format("Please enter something in this field."));
  
$(document).ready(function() {
  $("input[data-placeholder]").placeholder();

  var fullNewsletter = $("#full-newsletter-signup");

  fullNewsletter.find(".close").click(function(e) {
    e.preventDefault();
    fullNewsletter.fadeOut();
  });

  $("#quick-newsletter").submit(function(e) {
    e.preventDefault();

    var form = $(this);
    
    fullNewsletter.center().fadeIn();
    fullNewsletter.find("input").each(function() {
      var targetField = $(this);
      var sourceField = form.find("[name=" + targetField.attr("name") + "]").first();

      if(typeof sourceField != "undefined") {
        targetField.attr("value", sourceField.attr("value"));
      }
      
      if(targetField.attr("name") == "cd_CONSTITUENT") {
        targetField.attr("value", generateTimestamp());
      }
    });
  });
  
  $("#menu li").hover(function() {
      $(this).addClass("hover");
    },
    function() {
      $(this).removeClass("hover");
  });
  
  $("#signup").validate({
    rules: {
			"cd_FIRSTNAME": "required",
			"cd_LASTNAME": "required",
			"Email": {
				required: true,
				email: true
			}
		}
  });
});

(function($) {
  $.fn.placeholder = function() {
    $.each(this, function() {
      var field = $(this);
      var text = field.attr("data-placeholder");

      field.attr("value", text);

      field.focus(function() {
        if(this.value == text) {
          this.value = "";
        }
        else {
          this.select();
        }
      });
      
      field.blur(function() {
        if(this.value === "") {
          this.value = text;
        }
      });
    });

    return this;
  };

  $.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");

    return this;
  };
})(jQuery);

generateTimestamp = function() {
  var now = new Date();
  return  now.getFullYear()  + '' + 
          now.getMonth()+1 + '' +
          now.getDate() + '' + 
          now.getHours() + '' + 
          now.getMinutes() + '' + 
          now.getSeconds();
};


