﻿(function($) {
    $.fn.AddXbutton = function(options) {
        var defaults = {
            img: '/files/images/x.gif'
        };
        var opts = $.extend(defaults, options);
        var objs = new Array();
        $(this).each(
        function(i) {
            $obj = $(this);
            objs[i] = $obj;
            $(this).before(
                $('<input type="button" id="xButton' + i + '" src="' + opts['img'] + '" />')
                    .css({ 'background': 'transparent url(' + opts['img'] + ') left center no-repeat', 'opacity': '0.9', 'width': '10px', 'height': '10px', 'border': 'none', 'display': 'none', 'position': 'absolute', 'cursor': 'pointer', 'marginLeft': '290px', 'marginTop': '6px' })
                    .click(function() {
                        if (objs[i].attr('id').indexOf('RadDatePickerBirthDate') > 0) {
                            clearText();
                            $("#xButton" + i).hide();
                        } else {
                            objs[i].val('').focus();
                            $("#xButton" + i).hide();
                        }
                    }))
            .keyup(function() {
                if ($(this).val().length > 0) {
                    $("#xButton" + i).show();
                } else {
                    $("#xButton" + i).hide();
                }

            })
            if ($obj.val() != '') $("#xButton" + i).show();
        });

    };
})(jQuery);

