(function($) {

/**
 * jQuery debugging helper.
 *
 * Invented for Dreditor.
 *
 * @usage
 *   $.debug(var [, name]);
 *   $variable.debug( [name] );
 */
jQuery.extend({
  debug: function () {
    // Setup debug storage in global window. We want to look into it.
    window.debug = window.debug || [];

    args = jQuery.makeArray(arguments);
    // Determine data source; this is an object for $variable.debug().
    // Also determine the identifier to store data with.
    if (typeof this == 'object') {
      var name = (args.length ? args[0] : window.debug.length);
      var data = this;
    }
    else {
      var name = (args.length > 1 ? args.pop() : window.debug.length);
      var data = args[0];
    }
    // Store data.
    window.debug[name] = data;
    // Dump data into Firebug console.
    if (typeof console != 'undefined') {
      console.log(name, data);
    }
    return this;
  }
});
// @todo Is this the right way?
jQuery.fn.debug = jQuery.debug;

})(jQuery);
;
(function($){	
	$(document).ready(function(){
/*
			// wrap all name textboxes
			var textboxes = '';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-name1' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-name2' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-name3' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-name4';
			$(textboxes).wrapAll("<div class='form-item-group-wrapper form-item-group-wrapper-col-1 form-item-step1-name-wrapper'></div>");
			
			// wrap all job textboxes
			var textboxes = '';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-job-title1' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-job-title2' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-job-title3' + ',';
			textboxes = textboxes + '.form-item-step1-name-title-dma-awards-job-title4';
			$(textboxes).wrapAll("<div class='form-item-group-wrapper form-item-group-wrapper-col-2 form-item-step1-job-wrapper'></div>");	
			
			// wrap all company textboxes
			var textboxes = '';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-comp-name1' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-comp-name2' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-comp-name3' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-comp-name4';
			$(textboxes).wrapAll("<div class='form-item-group-wrapper form-item-group-wrapper-col-1 form-item-step1-comp-wrapper'></div>");
			
			// wrap all involvement textboxes
			var textboxes = '';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-involvement1' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-involvement2' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-involvement3' + ',';
			textboxes = textboxes + '.form-item-step1-name-involvement-dma-awards-involvement4';
			$(textboxes).wrapAll("<div class='form-item-group-wrapper form-item-group-wrapper-col-2 form-item-step1-involvement-wrapper'></div>");	
*/
			/* set up word counters
			$("#edit-step1-dma-awards-reference-info").counter({
				type: 'char',
				goal: 250,
				count: 'up'            
			});		
			*/	
			$("#awards-rejection-form #edit-reason").counter({
				type: 'char',
				goal: 1500,
				count: 'down'            
			});	
			
			/* hover effect for <input> tags */
			$("#awards-myentry-account .form-submit").hover(
			  function () {
				$(this).addClass('hovered');
			  }, 
			  function () {
				$(this).removeClass('hovered');
			  }
			);
			
	});
})(jQuery);
﻿/*
   jQuery (character and word) counter
   Copyright (C) 2009  Wilkins Fernandez

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function($) {
    $.fn.extend({
        counter: function(options) {
            // Set the default values, use comma to separate the settings
            var defaults = {
                type: 'char',   // {char || word}
                count: 'down',  // count {up || down} from or to the goal number
                goal: 140       // count {to || from} this number                
            };
            var options = $.extend({}, defaults, options);
            var flag = false;   // Set to true when goal is reached

            // Loop through each instance of the object that being is passed (the users selector).
            // Allows for multiple instances of the jQuery methods available to THIS (instance of the) object
            // (you can use this plug-in more than once on a page).
            return this.each(function() {
                var msg;
                var $obj = $(this);

                // Sets the appropriate message based on the options
                function get_msg_equation(objLength) {
                    // Make sure that the right values are set
                    if (typeof options.type !== 'string') {
                    } else {
                        switch (options.type) {
                            case 'char':
                                if (options.count === 'down') {
                                    msg = " character(s) left";
                                    return (options.goal - objLength);
                                }
                                else if (options.count === 'up') {
                                    msg = " characters (" + options.goal + " max)";
                                    return objLength;
                                }
                                break;
                            case 'word':
                                if (options.count === 'down') {
                                    msg = " word(s) left";
                                    return (options.goal - objLength);
                                }
                                else if (options.count === 'up') {
                                    msg = " words (" + options.goal + " max)";
                                    return objLength;
                                }
                                break;
                            default:
                        } //END switch
                    } // END if
                } // END function

                // * Initialize *: the bind event needs an object to bind to
                $('<div id=\"' + this.id + '_counter\"><span>' + get_msg_equation($($obj).val().length ) + '</span>' + msg + '</div>').insertAfter($obj);

                // Cache the counter selector
                var $currentCount = $("#" + this.id + "_counter" + " span");

                // Bind events to a function that returns the length
                // of the characters || words in the given text field.
                $obj.bind('keyup click blur focus change paste', function(new_length) {
                    // Update characters depending on the option selected
                    switch (options.type) {
                        case 'char':
                            new_length = $($obj).val().length;
                            break;
                        case 'word':
                            if ($obj.val() === '') {
                                new_length = 0;
                            }
                            else {
                                new_length = $.trim($obj.val())
                                    .replace(/\s+/g, " ")
                                    .split(' ').length;
                            }
                            break;
                        default:
                    } // END switch

                    // Set flag TRUE when counter reaches goal
                    switch (options.count) {
                        case 'up':
                            if (get_msg_equation(new_length) >= options.goal && options.type === 'char') {
                                $(this).val($(this).val().substring(0, options.goal));
                                flag = true;
                                break;
                            }
                            if (get_msg_equation(new_length) === options.goal && options.type === 'word') {
                                flag = true;
                                break;
                            } else if (get_msg_equation(new_length) > options.goal && options.type === 'word') {
                                $(this).val("");
								$currentCount.text("0");
                                flag = true;
                                break;
                            }
                            break;
                        case 'down':
                            if (get_msg_equation(new_length) <= 0 && options.type === 'char') {
                                $(this).val($(this).val().substring(0, options.goal));
                                flag = true;
                                break;
                            }
                            if (get_msg_equation(new_length) === 0 && options.type === 'word') {
                                flag = true;
                            } else if (get_msg_equation(new_length) < 0 && options.type === 'word') {
                                $(this).val("");
                                flag = true;
                                break;
                            }
                            break;
                        default:
                    } // END switch

                    // Listen on keydown to catch the last character or word typed
                    // and prevent the user from typing
                    $obj.keydown(function(event) {
                        if (flag) {
                            this.focus();
                            // Listen for delete & backspace
                            if ((event.keyCode !== 46 && event.keyCode !== 8)) {
                                if ($(this).val().length > options.goal && options.type === 'char') {
                                    $(this).val($(this).val().substring(0, options.goal));
                                    return false;   // Stop the default action (typing)
									// Listen for blank (spacebar) & return 
                                } else if (event.keyCode !== 32 && event.keyCode !== 8 && options.type === 'word') {   //Allow to continue typing last word
                                    return true;
                                } else {
                                    return false;   // Stop the default action (typing)
                                }
                            } else {
                                flag = false;
                                return true;
                            }
                        }
                    }); // END keydown
                    $currentCount.text(get_msg_equation(new_length));
                }); // END Bind
            }); //END return
        } // END counter function
    }); // END extend
}) // END function
(jQuery); // Return jQuery object;
/**
 * @file
 * Modifies the file selection and download access expiration interfaces.
 */

var uc_file_list = {};

/**
 * Disables duration amount when its type is "never".
 */
function _uc_file_expiration_disable_check(granularity, quantity) {
  // 'never' means there's no point in setting a duration.
  if (jQuery(granularity).val() == 'never') {
    jQuery(quantity).attr('disabled', 'disabled').val('');
  }
  // Anything besides 'never' should enable setting a duration.
  else {
    jQuery(quantity).removeAttr('disabled');
  }
}

/**
 * Adds files to delete to the list.
 */
function _uc_file_delete_list_populate() {
  jQuery('.affected-file-name').empty().append(uc_file_list[jQuery('#edit-recurse-directories').attr('checked')]);
}

jQuery(document).ready(
  function() {
    _uc_file_expiration_disable_check('#edit-uc-file-download-limit-duration-granularity', '#edit-uc-file-download-limit-duration-qty');
    _uc_file_expiration_disable_check('#edit-download-limit-duration-granularity', '#edit-download-limit-duration-qty');
    _uc_file_expiration_disable_check('#edit-download-limit-duration-granularity', '#edit-download-limit-duration-qty');
    _uc_file_delete_list_populate();

    toggle_limit_settings('#edit-download-override', '#edit-download-limit-number-wrapper');
    toggle_limit_settings('#edit-location-override', '#edit-download-limit-addresses-wrapper');
    toggle_limit_settings('#edit-time-override', '#edit-download-limit-duration-qty-wrapper');
    toggle_limit_settings('#edit-time-override', '#edit-download-limit-duration-granularity-wrapper');
  }
);

// When you change the global file expiration granularity select.
Drupal.behaviors.ucGlobalFileDownloadGranularity = {
  attach: function(context, settings) {
    jQuery('#edit-uc-file-download-limit-duration-granularity:not(.ucGlobalFileDownloadGranularity-processed)', context).addClass('ucGlobalFileDownloadGranularity-processed').change(
      function() {
        _uc_file_expiration_disable_check('#edit-uc-file-download-limit-duration-granularity', '#edit-uc-file-download-limit-duration-qty');
      }
    );
  }
}

// When you change the per-file expiration granularity select.
Drupal.behaviors.ucFileDownloadGranularity = {
  attach: function(context, settings) {
    jQuery('#edit-download-limit-duration-granularity:not(.ucFileDownloadGranularity-processed)', context).addClass('ucFileDownloadGranularity-processed').change(
      function() {
        _uc_file_expiration_disable_check('#edit-download-limit-duration-granularity', '#edit-download-limit-duration-qty');
      }
    );
  }
}

// When you click 'Check all' on the file action form.
Drupal.behaviors.ucFileSelectAll = {
  attach: function(context, settings) {
    jQuery('#uc_file_select_all:not(.ucFileSelectAll-processed)', context).addClass('ucFileSelectAll-processed').click(
      function() {
        jQuery('.form-checkbox').attr('checked', true);
      }
    );
  }
}

// When you click 'Uncheck all' on the file action form.
Drupal.behaviors.ucFileSelectNone = {
  attach: function(context, settings) {
    jQuery('#uc_file_select_none:not(.ucFileSelectNone-processed)', context).addClass('ucFileSelectNone-processed').click(
      function() {
        jQuery('.form-checkbox').removeAttr('checked');
      }
    );
  }
}

// When you (un)check the recursion option on the file deletion form.
Drupal.behaviors.ucFileDeleteList = {
  attach: function(context, settings) {
    jQuery('#edit-recurse-directories:not(.ucFileDeleteList-processed)', context).addClass('ucFileDeleteList-processed').change(
      function() {
        _uc_file_delete_list_populate()
      }
    );
  }
}

/**
 * Give visual feedback to the user about download numbers.
 *
 * TODO: would be to use AJAX to get the new download key and
 * insert it into the link if the user hasn't exceeded download limits.
 * I dunno if that's technically feasible though.
 */
function uc_file_update_download(id, accessed, limit) {
  if (accessed < limit || limit == -1) {

    // Handle the max download number as well.
    var downloads = '';
    downloads += accessed + 1;
    downloads += '/';
    downloads += limit == -1 ? 'Unlimited' : limit;
    jQuery('td#download-' + id).html(downloads);
    jQuery('td#download-' + id).attr("onclick", "");
  }
}

Drupal.behaviors.ucFileLimitDownloads = {
  attach: function(context, settings) {
    jQuery('#edit-download-override:not(.ucFileLimitDownloads-processed)', context).addClass('ucFileLimitDownloads-processed').click(
      function() {
        toggle_limit_settings('#edit-download-override', '#edit-download-limit-number-wrapper');
      }
    );
  }
}

Drupal.behaviors.ucFileLimitLocations = {
  attach: function(context, settings) {
    jQuery('#edit-location-override:not(.ucFileLimitLocations-processed)', context).addClass('ucFileLimitLocations-processed').click(
      function() {
        toggle_limit_settings('#edit-location-override', '#edit-download-limit-addresses-wrapper');
      }
    );
  }
}

Drupal.behaviors.ucFileLimitTime = {
  attach: function(context, settings) {
    jQuery('#edit-time-override:not(.ucFileLimitTime-processed)', context).addClass('ucFileLimitTime-processed').click(
      function() {
        toggle_limit_settings('#edit-time-override', '#edit-download-limit-duration-qty-wrapper');
        toggle_limit_settings('#edit-time-override', '#edit-download-limit-duration-granularity-wrapper');
      }
    );
  }
}

/**
 * Toggle the limit settings.
 */
function toggle_limit_settings(cause, effect) {
  if (jQuery(cause).attr('checked')) {
    jQuery(effect).show();
  }
  else {
    jQuery(effect).hide();
  }
}
;

