/*
   Script: jQuery-extend.js
      Contains extensions to jQuery loaded with extend.
*/

/*
   Package: Parse
      These methods add the ability to parse any value, and return it
      if sensible, else returning a caller supplied alternate.  Useful
      utilities when attempting to load values.
*/
jQuery.extend({

   /*
      Function: parseStr
         Parses and returns the given value as a String if appropriate,
         else returns the alternate.

         Takes any value and an alternate as input, and if the value is not
         undefined or null, returns a String containing the value, or else it
         returns the alternate.

      Parameters:
         value - <any> The value that we can potentially return.
         alternate - <String> The alternate to return if the value is no good.

      Returns:
         <String> The value as a String, or the alternate.
   */
   parseStr: function(value, alternate) {
      if (value !== undefined && value !== null)
         return String(value);
      return alternate;
   },

   /*
      Function: parseInt
         Parses and returns the given value as an int if appropriate,
         else returns the alternate.

         Takes any value and an alternate as input, and if the value is not
         undefined or null, and can be parsed as an int, it will be returned as
         an int, or else the alternate will be returned.

      Parameters:
         value - <any> The value that we can potentially return.
         alternate - <int> The alternate to return if the value is no good.

      Returns:
         <int> The value as an int, or the alternate.
   */
   parseInt: function(value, alternate) {
      if (value !== undefined && value !== null)
         if (!isNaN(parseInt(String(value))))
            return parseInt(String(value));
      return alternate;
   },

   /*
      Function: parseFlt
         Parses and returns the given value as a float if appropriate,
         else returns the alternate.

         Takes any value and an alternate as input, and if the value is not
         undefined or null, and can be parsed as an float, it will be returned
         as a float, or else the alternate will be returned.

      Parameters:
         value - <any> The value that we can potentially return.
         alternate - <float> The alternate to return if the value is no good.

      Returns:
         <float> The value as a float, or the alternate.
   */
   parseFlt: function(value, alternate) {
      if (value !== undefined && value !== null)
         if (!isNaN(parseFloat(String(value))))
            return parseFloat(String(value));
      return alternate;
   }

});

jQuery.fn.extend({

   buttonHover: function() {;
      jQuery(".buttonLeft", this).removeClass("buttonLeft").addClass("buttonLeftHover");
      jQuery(".buttonMiddle", this).removeClass("buttonMiddle").addClass("buttonMiddleHover");
      jQuery(".buttonRight", this).removeClass("buttonRight").addClass("buttonRightHover");
      return this;
   },

   buttonUnhover: function() {
      jQuery(".buttonLeftHover", this).removeClass("buttonLeftHover").addClass("buttonLeft");
      jQuery(".buttonMiddleHover", this).removeClass("buttonMiddleHover").addClass("buttonMiddle");
      jQuery(".buttonRightHover", this).removeClass("buttonRightHover").addClass("buttonRight");
      return this;
   },

   buttonSubmitAndDisable: function() {
      if (jQuery(".buttonLeftDisabled", this).size() > 0)
         return false;

      if (jQuery(".buttonLeftHover", this).size() > 0) {
         jQuery(".buttonLeftHover", this).removeClass("buttonLeftHover").addClass("buttonLeftDisabled");
         jQuery(".buttonMiddleHover", this).removeClass("buttonMiddleHover").addClass("buttonMiddleDisabled");
         jQuery(".buttonRightHover", this).removeClass("buttonRightHover").addClass("buttonRightDisabled");
      }
      else if (jQuery(".buttonLeft", this).size() > 0) {
         jQuery(".buttonLeft", this).removeClass("buttonLeft").addClass("buttonLeftDisabled");
         jQuery(".buttonMiddle", this).removeClass("buttonMiddle").addClass("buttonMiddleDisabled");
         jQuery(".buttonRight", this).removeClass("buttonRight").addClass("buttonRightDisabled");
      }
      $(".buttonText", this).text(disableFormLang.BUTTON)
      return true;
   }

});