﻿var tamap = {};

/// <summary>
/// Toggles default text for input, e.g. 'Enter your username'
/// </summary>
tamap.toggleDefaultTextForInput = function (inputId, defaultText) {

    // Get input element
    var $textInput = $('input#' + inputId);

    // Set default text value for input
    $textInput.val(defaultText);

    // On text input focus, empty value
    $textInput.focus(function () {
        if ($(this).val() === defaultText) {
            $(this).val('');
        }
    });
    // On text input blur, set default text if empty
    $textInput.blur(function () {
        if ($(this).val() === '') {
            $(this).val(defaultText);
        }
    });
};

/// <summary>
/// Toggles default text for input, e.g. 'Enter your password'
/// </summary>
tamap.toggleDefaultTextForPasswordInput = function (inputId, defaultText) {

    // Get password input element
    var $passwordInput = $('input#' + inputId);

    // Hide password input
    $passwordInput.hide();

    // Create text input for showing default text
    var $passwordTemporaryInput = $(document.createElement('input'));
    $passwordTemporaryInput.attr("type", "text");
    $passwordTemporaryInput.attr("class", $passwordInput.attr('class'));
    $passwordTemporaryInput.attr("id", inputId + '-defaultvalue');
    $passwordTemporaryInput.val(defaultText);

    // On text input focus, show password input
    $passwordTemporaryInput.focus(function () {
        $(this).hide();
        $passwordInput.show();
        $passwordInput.focus();
    });

    // Add text input
    $passwordInput.after($passwordTemporaryInput);

    // On password input blur, show text input if no text entered
    $passwordInput.blur(function () {
        if ($(this).val() === '') {
            $(this).hide();
            $passwordTemporaryInput.show();
        }
    });
};

