// JavaScript Document
window.addEvent('domready', function() {
	$('a_envia_login').addEvent('click', function(e) {
		/* Prevent the submit event */
		new Event(e).stop();

		if (ValidarCampo($('form_login').txt_user, 2, true, 'El campo usuario es obligatorio.', '')==false) return false;
		if (ValidarCampo($('form_login').txt_pass, 2, true, 'El campo contraseņa es obligatorio.', '')==false) return false;
		var log = $('div_enviar_login').addClass('ajax-loading');
		
		var sender = new Request.JSON();
		sender.onSuccess=function(responseJSON, responseText){
			if (responseJSON!=null) {
				if (responseJSON.codigo=='0') {
					alert(responseJSON.valor);
				} else if (responseJSON.codigo=='1') {
					self.parent.location=responseJSON.valor;
				}
			}
			log.removeClass('ajax-loading');
		};
		sender.send({data: $('form_login'), url: $('form_login').get('action')});
	});
	$('txt_user').focus();
});
