$(function () {
    $('#email').val($('#email').attr('placeholder'));
    $('#password').val($('#password').attr('placeholder'));
    $('#email').live('keypress', submit);
    $('#password').live('keypress', submit);
    $('#loginBtn').live('click',
		function()
		{
			if (window.external && ('AutoCompleteSaveForm' in window.external))
			{
				window.external.AutoCompleteSaveForm(loginForm);
			}
			document.getElementById('loginForm').submit();
			/*return login();*/
		});
    $('#email').live('focus', function () {
        if ($(this).val() == $(this).attr('placeholder'))
            $(this).val('');
    });
    $('#email').live('blur', function () {
        if ($(this).val() == '')
            $(this).val($(this).attr('placeholder'));
    });
    $('#password').live('focus', function () {
        if ($(this).val() == $(this).attr('placeholder'))
            $(this).val('');
    });
    $('#password').live('blur', function () {
        if ($(this).val() == '')
            $(this).val($(this).attr('placeholder'));
    });
});
function login() {
    $('#loginBtn').attr('disabled', 'disabled');
    $.ajax({
        type: 'POST',
        url: '/my/login.php',
        data: $('#loginForm').serialize(),
        dataType: 'json',
        success: function (response) {
            if (response.isError) {
                $('#loginPnl').html(response.content);
            }
            else
                window.location.href = '/my/';
        },
        error: function () {
            showWait('К сожалению произошла ошибка. Попробуйте снова...');
            $('#loginBtn').attr('disabled', '');
        }
    });
    return false;
}
function submit(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
        return login();
    }
    else {
        return true;
    }
}
