﻿$(document).ready(function()
{
	var objLoginContainer = $('#loginFieldsContainer');
	if (objLoginContainer.length > 0)
	{
		var objPassField = objLoginContainer.find('input[type = "password"]');
		if (objPassField.length > 0 && objPassField.val() === '')
		{

			$('<div id="fakePasswordText">Lösenord</div>').css(
			{
				'background-color': '#FFFFFF',
				'color': '#777777',
				'position': 'absolute',
				'font-size': '1em',
				'float': 'none',
				'line-height': '14px',
				'margin': '0px 0px 5px 5px',
				'padding': '0px 0px 0px 3px',
				'cursor': 'text',
				'width': (objPassField.width() - 3) + 'px',
				'height': objPassField.height() + 'px',
				'top': objPassField.position().top + 'px',
				'left': objPassField.position().left + 'px'
			}).click(function(e)
			{
				e.preventDefault();
				e.stopImmediatePropagation();
				$(this).hide();
				objPassField.focus();
			}).appendTo(objPassField.parent())
			objPassField.blur(function(e)
			{
				if ($(this).val() === '')
				{
					$('#fakePasswordText').show();
				}
			}).focus(function(e)
			{
				$('#fakePasswordText').hide();
			});

			var enterKeyFunction = function(e)
			{
				if (e.keyCode == '13' && objPassField.val() !== '' && objLoginContainer.find('input[type = "text"]').val() !== '')
				{
					var href = objLoginContainer.find('a:eq(0)').attr('href');
					href = href.substring((href.indexOf('WebForm_PostBackOptions(') + 25), href.indexOf('", "", true'));

					//WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl05$LoginView$LoginControl$LoginBtn", "", true, "loginGroup", "", false, true));
					if (href.length > 0 && href.indexOf('LoginView$LoginControl$LoginBtn') > -1)
					{
						
						WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(href, "", true, "loginGroup", "", false, true));
					}
				}
			}

			objPassField.keydown(enterKeyFunction);
			objLoginContainer.find('input[type = "text"]').keydown(enterKeyFunction);
		}
		objLoginContainer.find('input[type = "text"]').focus(function(e)
		{
			if ($(this).val() === 'Användare')
			{
				$(this).val('');
			}
		}).blur(function(e)
		{
			if ($(this).val() === '')
			{
				$(this).val('Användare');
			}
		});
	}
});