var $j = jQuery.noConflict(); 
/**
 * Formulario de login
 */
$j(document).ready( function($) {
	var loginForm = $('#loginForm');

	loginForm.bind("invalid-form.validate", function() {
		$("body").css("overflow", "hidden");
		alert("Llene los campos requeridos para ingresar");
	}).validate( {
		rules : {
			usuario : {
				required : true,
			},
			pass1 : {
				required : true,
				minlength : 3
			}
		},
		messages : {},
		errorPlacement : function(error, element) {
			//alert("test: " + element);
		},
		submitHandler : function() {
			loginForm.ajaxSubmit( {
			//dataType: "json",
			beforeSubmit : showRequest, // pre-submit callback
			success : showResponse
			// post-submit callback
				});
		}
	});
	function showResponseName(responseText) {
		document.getElementById('loginDiv').innerHTML = responseText;
	}
	function showResponseLogin(responseText) {
		document.getElementById('titulo_header').innerHTML = responseText;
	}
	function showRequest(formData, jqForm, options) {
	}
	function showResponse(responseText, statusText) {
		if (navigator.appName == 'Microsoft Internet Explorer') {
			document.location.href = window.location.href;
		}
		var status = responseText.substring(0,2);
		var msg = responseText.substring(2);
		if ( status == 00 ) {
			alert(msg);
			var html = $.ajax( {
				type : "POST",
				url : baseURL+"loginname.html",
				success : showResponseName
			});
			$.ajax( {
				type : 'post',
				url : baseURL+'logintext.html',
				success : showResponseLogin
			});
			$('#login').addClass('loginChico');

		} else if ( status == 10 ) {//error al iniciar sesión
			alert(msg);
		}
	}
});

