$.fn.extend( {
    txt: function ( emptyvalue )
    {

        if ( $( this ).val() == '' )
            $( this ).val( emptyvalue );

        $( this ).focus( function ()
        {
            if ( $( this ).val() == emptyvalue )
            {
                $( this ).val( '' )
            }
        } );
        $( this ).blur( function ()
        {
            if ( $( this ).val() == '' )
            {
                $( this ).val( emptyvalue );
            }
        } );
    },
    txtpassword: function ( emptyvalue )
    {

        var field = $( this ).hide();
        var copyfield = $( " <input type='text'  value='' />" );
        copyfield.addClass( $( this ).attr( 'class' ) );
        $( this ).after( copyfield );

        $( this ).val( emptyvalue );
        copyfield.val( emptyvalue );

        $( copyfield ).focus( function ()
        {
            $( this ).hide();
            field.show();
            field.focus();
            if ( $( this ).val() == emptyvalue )
            {
                field.val( '' )
            }
        } );
        $( this ).blur( function ()
        {

            if ( field.val() == '' )
            {
                copyfield.val( emptyvalue );
                field.hide();
                copyfield.show();

            }
        } );
    },
    txtsearch: function ( button, emptyvalue )
    {
        var SearchTerm = htmlDecode( Request()['SearchTerm'] );
        if (SearchTerm != 'undefined' )
            $( this ).val( SearchTerm );
        
        $( this ).bind( 'keypress', function ( e )
        {
            if ( e.keyCode == 13 ) { button.click(); }
        } );

        function Request()
        {
            var vars = [], hash;
            var hashes = window.location.href.slice( window.location.href.indexOf( '?' ) + 1 ).split( '&' );
            for ( var i = 0; i < hashes.length; i++ )
            {
                hash = hashes[i].split( '=' );
                vars.push( hash[0] );
                vars[hash[0]] = hash[1];
            }
            return vars;
        }
        function htmlEncode( value )
        {
            return encodeURI( value );
        }
        function htmlDecode( value )
        {
            return decodeURI( value );
        }
        var input = $( this );
        $( button ).click( function ()
        {
            var value = htmlEncode( input.attr( 'value' ) ).trim().toString();
            if ( value.length > 0 )
            {
                var url = 'Search.aspx?SearchTerm=' + value;
                window.location = url;
            }
        } );
    }
} );
