var edtClave;
var btnEntrar;

function BtnEntrarClick( e )
{
	if ( e )
		e.preventDefault();
	
	$.ajax( 
		{
			url:         'cmdLogin.asp',
			type:        'POST',
			cache:       false,
			dataType:    'json',
			
			data:
			{
				clave: edtClave.val()
			},
			
			error: function( XMLHttpRequest, textStatus, errorThrown )
			{
				alert( 'Se ha producido un error en la validación...' );
			},
			
			success: function( data, textStatus )
			{
				if ( data.ok )
				{
					if ( data.loginOk )
						document.location.href = 'menu.asp';
					else
					{
						alert( 'La clave no es correcta. Inténtelo de nuevo' );
						
						edtClave.focus();
						
						edtClave.val( '' );
					}
				}
				else
					this.error();
			},
			
			complete: function( XMLHttpRequest, textStatus )
			{
			}						
		} );
}

function EdtClaveKeyPress( e )
{
	if ( 13 == e.which )
		BtnEntrarClick();
}

function WindowLoad()
{
	edtClave  =  $( '#edtClave' );
	btnEntrar = $( '#btnEntrar' );
	
	edtClave.keypress( EdtClaveKeyPress );
	
	btnEntrar.click( BtnEntrarClick );
	
	edtClave.focus();
};

$( WindowLoad );