if (Drupal.jsEnabled) {	
  $(document).ready(function() {
    var flag = false;
    target_blank();
    defaultValues();
    nowhere_links();
    //
    //        $("#search-form #edit-all-wrapper label").click(function(){
    //            if ($("#search-form #edit-all-wrapper label input").attr("checked") != false){
    //                $("#search-form .fieldset-wrapper fieldset:last input").attr("checked", false);
    //            } else {
    //                $("#search-form .fieldset-wrapper fieldset:last input").attr("checked",true);
    //            }
    //            if (flag) {
    //                flag = false;
    //            } else {
    //                return false;
    //            }
    //        });
    //
    //        $("#search-form #edit-all-wrapper input").click(function(){
    //            $(this).attr('checked', !$(this).attr('checked'));
    //            flag = true;
    //        });
    $("#search-form #edit-select-all").click(function(){
      $("#search-form .fieldset-wrapper fieldset:last input").attr("checked",true);
      return false;
    });
    $("#search-form #edit-unselect-all").click(function(){
      $("#search-form .fieldset-wrapper fieldset:last input").attr("checked",false);
      return false;
    });
  });
}

function defaultValues() {
  var fields = $('form input.form-default-value');
  var forms = fields.parents('form');
  fields.each(function() {
    this.defaultValue = this.value;
    $(this).focus(function() {
      if (this.value == this.defaultValue) {
        this.value = '';
        $(this).removeClass('form-default-value');
      }
    });
    $(this).blur(function() {
      if (this.value == '') {
        $(this).addClass('form-default-value');
        this.value = this.defaultValue;
      }
    });
  });

  // Clear all the form elements before submission.
  forms.submit(function() {
    fields.focus();
  });
};


function target_blank(){	
  $('a').filter(function() {
    // Filter out links within the site unless they're documents
    // Note: Use this declarative style for clarity
    if($(this).is('[href$=.doc]')) return true;
    if($(this).is('[href$=.pdf]')) return true;
    if(!$(this).is('[href^=http://]')) return false;
    if(!$(this).is('[href^=http://www.naeycdev.org]') && !$(this).is('[href^=http://naeycdev.org]')) {
      return true;
    }
  }).attr('target', '_blank');
}

function nowhere_links() {
  $('a[href$=nowhere]')
  .attr('href', 'javascript:;')
  // Everything from here onward will go in the master stylesheet once approved
  .css('color', '#ccc')
  .css('cursor', 'default')
  .hover(function() {
    $(this).css('text-decoration', 'none');
  },
  function() {
    return 1;
  });
}

