/************************************************************************************************
  inputWatermark v1.0.0
* inputWatermark es plugin para jquery
* su utilidad es la de mostrar un texto dentro de un input con otro color 
mientras dicho input no sea utlizado por el usuario
* tiene un único parámetro: {colorWatermark:""} que sirve para especificar el color de texto
del input cuando está en modo Watermark
* el texto que se muestra dentro del input cuando este aún no ha sido rellenado 
es el del própio title del dicho input
**************************************************************************************************/
(function ($) {
    $.fn.extend({
        inputWatermark: function (options) {

            var defaults = {
                colorWatermark: "#CCCCCC"
            };

            var options = $.extend(defaults, options);

            var privateMethods = {
                quitaWatermark: function (element) {
                    var $element = $(element);
                    if ($element.val() == element.strWatermark || $.trim($element.val()) == "") {
                        $element.val("");
                        $element.css({ "color": element.colorDefault });
                    }
                },
                ponerWatermark: function (element) {
                    var $element = $(element);
                    if ($element.val() == element.strWatermark || $.trim($element.val()) == "") {
                        $element.css({ "color": options.colorWatermark });
                        $element.val(element.strWatermark);
                    }
                }
            };

            var privateProperties = {
                inputTextColletion: new Array()
            };

            return this.each(function () {
                var $inputText = $(this);
                if (this.tagName.toLowerCase() == "input" && $inputText.attr("type") == "text") {
                    
                    privateProperties.inputTextColletion.push(this);
                    this.colorDefault = $inputText.css("color");
                    this.strWatermark = $.trim($inputText.attr("title"));

                    if (this.strWatermark.length != "") {

                        $inputText.blur();
                        privateMethods.ponerWatermark(this);

                        $inputText.bind("focus", function () {
                            privateMethods.quitaWatermark(this);
                        });

                        $inputText.bind("blur , changue", function () {
                            privateMethods.ponerWatermark(this);
                        });

                        $("input[type='submit']", this.form).bind("mouseup", function () {
                            $inputText.each(function () {
                                privateMethods.quitaWatermark(this);
                                setTimeout(function () {
                                    for (i in privateProperties.inputTextColletion) {
                                        privateMethods.ponerWatermark(privateProperties.inputTextColletion[i]);
                                    }
                                }, 500);
                            });
                        });

                        $(this.form).bind("submit", function () {
                            $inputText.each(function () {
                                privateMethods.quitaWatermark(this);
                            });
                        });

                    }
                }
            });
        }
    });

})(jQuery);

// en UscFormContactoListado.ascx
$(function () {

    $(".inputWatermark").inputWatermark({ colorWatermark: "#999" });

    $(".FormContactoListado span.nombre input , .FormContactoListado span.telefono input").each(function () {
        var label = $("label[for='" + this.id + "']");
        this.title = label.text();
        $(this).inputWatermark({ colorWatermark: "#0A4286" });
        label.remove();
    });
});
