$(function(){
  
  // Placeholders for older browsers
  // -----------------------------------------------------------------
  var showPlaceholders = function(){
    if(!Modernizr.input.placeholder){
     $("input").each(function(){
       if($(this).val()=="" && $(this).attr("placeholder")!=""){
         $(this).val($(this).attr("placeholder"));
         $(this).addClass("placeholder");
         $(this).focus(function(){if($(this).val()==$(this).attr("placeholder")) $(this).val("").removeClass("placeholder");});
         $(this).blur(function(){if($(this).val()=="") $(this).val($(this).attr("placeholder")).addClass("placeholder");});
       }
     });
    }
  };
  showPlaceholders();
  window['showPlaceholders'] = showPlaceholders;
  
  // Homepage
  // -----------------------------------------------------------------
  if($("body").hasClass("home")){

    $("#domain").focus(function(){
      $(this).parents("#choose-domain").addClass("active");
    });
    $("#domain").focusout(function(){
      $(this).parents("#choose-domain").removeClass("active");
    });
  }
  
  
  // Form Validator
  // -----------------------------------------------------------------
  $.tools.validator.fn("[data-equals]", "Value not equal with the $1 field", function(input) {
    var name = input.attr("data-equals"),
       field = this.getInputs().filter("[name=" + name + "]"); 
    return input.val() == field.val() ? true : [name.replace('_',' ')]; 
  });
  
  
  // .submit submits the form
  // -----------------------------------------------------------------
    
  $(".submit").click(function(){
    $(this).parents("form").submit();
    return false; 
  });

  // .close Popup
  // -----------------------------------------------------------------
  if($(".popup").length){
    $(".open-popup").click(function(){
      var popup = $(this).attr("href");
      $(".overlay").fadeIn();
      $(popup).show();
      return false;
    });
    $(".popup .close").click(function(){
      $(this).parents(".popup").hide();
      $(".overlay").fadeOut();
      return false;
    });
  }
  
});
