/*
* Fix for bug in Firebug when cloning input boxes
*/
$(document).ready(function() {
    $('input[type="password"]').attr('autocomplete', 'false');
});


(function($) { $.fn.extend({ defaultValue: function(str) { return this.each(function() { var defaultValue = str || $(this).attr('rel'); var defaultType = $(this).attr('type') || null; var cloneId = null; var self = $(this); self.data("defaultValue", defaultValue); if (defaultType == 'password') { createClone(this); $(this).blur(function() { if ($(self).val().length <= 0) { $('#' + cloneId).show(); $(self).hide() } }) } else { $(this).click(function() { if ($(this).val() == defaultValue) { $(this).val('') } }).keypress(function() { if ($(this).val().length > 0) { setState(this) } }).blur(function() { setState(this) }).focus(function() { if ($(this).val() == defaultValue) { $(this).val('') } }); $.trim($(this).val()); setState(this) } function setState(element) { val = $.trim($(element).val()); if (val.length <= 0 || val == defaultValue) { $(element).val(defaultValue).addClass('empty') } else { $(element).removeClass('empty') } } function createClone(element) { cloneId = $(element).attr('id') + 'Clone'; if ($('#' + cloneId).length > 0) return; $("<input id='" + cloneId + "' type='text' />").attr('value', defaultValue).insertAfter(element).show().focus(function() { $(this).hide(); $(self).show(); setTimeout(function() { $(self).focus() }, 10) }).addClass($(element).attr('class') + ' empty').attr('style', $(element).attr('style')); $(self).hide() } }) } }) })(jQuery);


/*
* Validation
*/
function validateDefaultValueTextBox(source, args) {
    var textBoxID = $(source).data('textBoxToValidate');
    var textBoxToValidate = $('#' + textBoxID);

    var trimmedValue = jQuery.trim(args.Value);
    if (trimmedValue == "") {
        args.IsValid = false;
    }

    if (args.IsValid) {
        var defaultValue = textBoxToValidate.data('defaultValue');
        defaultValue = jQuery.trim(defaultValue);

        if (trimmedValue == defaultValue) {
            args.IsValid = false;
        }
    }

    var textBoxToValidateClone = $('#' + textBoxID + 'Clone');

    if (!args.IsValid) {
        textBoxToValidate.addClass('validationError');

        if (textBoxToValidateClone.length > 0)
            textBoxToValidateClone.addClass('validationError');
    }
    else {
        textBoxToValidate.removeClass('validationError');

        if (textBoxToValidateClone.length > 0)
            textBoxToValidateClone.removeClass('validationError');
    }
}
