﻿

(function($) {
    
    if (typeof $.Artemis != "object" || $.Artemis === null) { $.Artemis = {}; }
    if (typeof $.Artemis.InputMask != "object" || $.Artemis.InputMask === null) { $.Artemis.InputMask = {}; }
    
    
    //------// Watermark Plugin \\------\\
    $.Artemis.InputMask.Watermark = function(selector, options) {
        
        /// <summary>Places a watermark on a selection of text <input> or <textarea> elements.</summary>
        /// <param name="selector" optional="false" type="jQuery|string|DOM" mayBeNull="false">The selected elements to execute the plugin against.</param>
        /// <param name="options" optional="true" type="Object" mayBeNull="true">An object defining the options for the plugin to use.</param>        
        
        options = $.extend({}, $.Artemis.InputMask.Watermark.defaults, options);
        
        $(selector).each(function() {
            var self = $(this);
            
            options = $.meta ? $.extend({}, options, self.data()) : options; // Provided support for the Metadata plugin.
            
            if (options.setInitialValue === true) { self.val(options.initialValue); }
            else if (self.val() !== options.initialValue) { self.removeClass(options.watermarkClass); }
            
            self.focus(function() { 
                var self = $(this);
                
                if ($.trim(self.val()) === options.initialValue) 
                {
                    self.removeClass(options.watermarkClass).val("");
                    
                    if (self[0].createTextRange)
                    {
                        var range = self[0].createTextRange();
                        range.move("character", 0);
                        range.select();
                    }
                }
            }).blur(function() {
                if ($.trim($(this).val()) === "") 
                {
                    $(this).addClass(options.watermarkClass).val(options.initialValue);
                }
            });
        });
    };
    
    
    $.Artemis.InputMask.Watermark.defaults = {
        initialValue : "Please enter a value...",
        watermarkClass : "watermark",
        setInitialValue : true
    };
    //------\\ Watermark Plugin //------//
    
    
    
    
    //------// MaxLength Plugin \\------\\
    
    //------\\ MaxLength Plugin //------//
    
})(jQuery.noConflict());