﻿jQuery(document).ready(function() {
    InitializeWatermarks();
});

function InitializeWatermarks() {
    jQuery('.watermark').each(function() {
        var origText = jQuery(this).attr('watermark');

        if (origText && jQuery.trim(origText) != '') {
            var isPW = false;

            if (jQuery(this).attr('type') == 'password') {
                // append a textbox below it
                var txt = jQuery('<input type="text" />');
                txt.val(origText);
                txt.css({
                    width: jQuery(this).width(),
                    color: '#b1b1b1'
                });
                txt.insertAfter(jQuery(this));

                // hide real box
                jQuery(this).hide();

                // add enter event
                txt.focus(function() {
                    jQuery(this).hide();
                    jQuery(this).prev().show();
                    jQuery(this).prev().focus();
                });

                isPW = true;
            }   //if

            if (jQuery.trim(jQuery(this).val()) == '' || jQuery.trim(jQuery(this).val()) == origText) {
                jQuery(this).val(origText);
                jQuery(this).css('color', '#b1b1b1');
            }   //if

            jQuery(this).focus(function() {
                if (jQuery(this).val() == origText) {
                    jQuery(this).val('');
                    jQuery(this).css('color', 'black');
                }   //if
            });

            jQuery(this).blur(function() {
                if (jQuery.trim(jQuery(this).val()) == '') {
                    if (isPW) {
                        // need to show the inserted textbox
                        jQuery(this).hide();
                        jQuery(this).next().show();
                    }   //if

                    jQuery(this).val(origText);
                    jQuery(this).css('color', '#b1b1b1');
                }   //if
            });

            jQuery(this).change(function() {
                if (jQuery.trim(jQuery(this).val()) != '' && jQuery.trim(jQuery(this).val()) != origText) {
                    jQuery(this).css('color', 'black');
                }   //if
            });
        }   //if
    });
}
