/*
* CodeForce LLC
* jQuery disableonclick plugin
* Version 2.33 (29-MAR-2010)
* @requires jQuery v1.2.3 or later
*
* Copyright (c) 2007-2008 M. Alsup
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* This plugin can disable and apply a disable class to any type of html control that can support a click event from it. 
* It has built in support for micorsoft validation testing, showing a waitui and clearing watermarks on click.
* 
*   OPTIONS available for overriding
*   disableAll - allows all controls with the disableonclick= true to be disabled regardless of group or location
*   clearWatermarksCallout - allows for a function callout to a clearwatermarks method. to be used with other jquery watermark plugins
*   waituiCallout - allows for a function callout to a waitui method or event which can do what ever you like between the client click and postback
*   activeClass - active class used on control if any
*   inactiveClass: - inactive class applied on disable
*   resetTimer - time in milliseconds i wait to reset the form controls if validation fails
*   useDisableAttribute - flag to determine if i should also apply the  disable attribute or just the classes
*   groupName - you can apply groupname based on a container level call to ensure all controls with a disableonclick are fired together. optionally you can assign the
*   groupname on the control itset as a custom attribute. which will allow for more specific control of the groupings
*
* Example Usage
    <script type="text/javascript">
        $(document).ready(function () {
            $(".ff").disableonclick({waituiCallout:showWatUI, clearWatermarksCallout: clearMarks, );            
        });
        function showWatUI() {		
        }
        function clearMarks() {
        }
    </script>
    <div class="ff">
        <asp:Button ID="Button1" runat="server" CssClass="testbtn" disableonclick="true" groupname="g"
        OnClientClick=" return false;" Text="Button" CausesValidation="true"  ValidationGroup="ff	/>
			
        <asp:Button ID="Button1" runat="server" CssClass="testbtn" disableonclick="true" groupname="g"
        OnClientClick=" return false;" Text="Button" CausesValidation="true"  ValidationGroup="ff" />
			
        <asp:TextBox ID="TextBox1" ValidationGroup="ff" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1"  ValidationGroup="ff" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    </div>
*
*

*/
(function(a){if(/1\.(0|1|2)\.(0|1|2)/.test(a.fn.jquery)||/^1.1/.test(a.fn.jquery)){alert("disableonclick requires jQuery v1.2.3 or later!  You are using v"+a.fn.jquery);return}a.fn.canceldisableonclick=function(g,h){d(g,h)};a.fn.disableonclick=function(g){var h=a.extend({},a.fn.disableonclick.defaults,g);return this.each(function(){$this=a(this);f($this,h)})};a.fn.disableonclick.defaults={disableAll:false,clearWatermarksCallout:null,waituiCallout:null,activeClass:"cntrlactive",inactiveClass:"cntrlinactive",resetTimer:1000,useDisableAttribute:true,groupName:null};function f(g,h){h=a.extend({},a.fn.disableonclick.defaults,h||{});a(g+"[disableonclick='true']"||g+" > *[disableonclick='true']").each(function(k){var j=a(this);if(h.groupName!=null){j.attr("groupname",h.groupName)}j.click(function(){if(h.clearWatermarksCallout!=null&&h.clearWatermarksCallout!=undefined&&typeof h.clearWatermarksCallout!=undefined&&typeof h.clearWatermarksCallout=="function"){h.clearWatermarksCallout()}if((typeof Page_ClientValidate=="function"&&typeof Page_IsValid!="undefined"&&Page_IsValid)||typeof Page_ClientValidate=="undefined"){e(h);if(h.disableAll){a("*[disableonclick='true']").each(function(l){c(a(this),h)})}else{var i=a(this).attr("groupname");if(i!=null&&i!=undefined&&i.length>0){a("[disableonclick='true'][groupname='"+i+"']").each(function(l){c(this,h)})}else{c(this,h)}}setTimeout(function(){b(this,h)},h.resetTimer)}})})}function e(g){if(g.waituiCallout!=null&&g.waituiCallout!=undefined&&typeof g.waituiCallout!=undefined&&typeof g.waituiCallout=="function"){g.waituiCallout()}}function c(h,i){i=a.extend({},a.fn.disableonclick.defaults,i||{});var g=a(h);g.addClass(i.inactiveClass);g.removeClass(i.activeClass);if(i.useDisableAttribute){g.attr("disabled","true")}}function d(h,i){i=a.extend({},a.fn.disableonclick.defaults,i||{});var g=a(h);g.addClass(i.inactiveClass);g.removeClass(i.activeClass);if(i.useDisableAttribute){g.removeAttr("disabled")}}function b(g,h){h=a.extend({},a.fn.disableonclick.defaults,h||{});if((typeof Page_ClientValidate=="undefined")||(typeof Page_IsValid!="undefined"&&!Page_IsValid)){a(g+"[disableonclick='true'][class*='"+h.inactiveClass+"']"||g+" > [disableonclick='true'][class*='"+h.inactiveClass+"']").each(function(j){a(this).addClass(h.activeClass);a(this).removeClass(h.inactiveClass);if(h.useDisableAttribute){a(this).removeAttr("disabled")}});return false}return true}})(jQuery);
