jQuery( document ).ready(function()
{
    var labels = jQuery('label.inside');

    labels.each(function()
	{
        var self = jQuery( this );
        var forId = self.attr('for');
        if (forId.length < 1)
        {
            return;
        }

        var labelText = jQuery.trim(self.text()).replace(/\:$/, '');
        this.fields = jQuery( '#'.concat(forId) );

        this.fields.each(function()
    	{
    	    this.labelText = labelText;
            if (this.value == '')
            {
                this.value = this.labelText;
            }
        });

    	this.fields.focus(function()
    	{

    		if (this.value == this.labelText)
    		{
    			this.value = '';
    		}
    	});

    	this.fields.blur(function()
    	{
    		if (this.value == '')
    		{
    			this.value = this.labelText;
    		}
    	});

	});

	labels.parents('form').submit(function()
	{
	    var self = jQuery( this );
	    var labels = self.find('label.inside');
        labels.each(function()
        {
            var self = jQuery( this );
            var forId = self.attr('for');
            if (forId.length < 1)
            {
                return;
            }

            this.fields.each(function()
        	{
                if (this.value == this.labelText)
                {
                    this.value = '';
                }
            });
        });

	});

});

