$(document).ready( function() { 	

	jQuery("#login_form").validate({
		rules: {
			usuario: {
				required: true,
				minlength: 5,
				maxlength:15,
				remote: "/cxcat/ajax_validar_usuario.php?accion=2" //verificar si usuario existen pwd
			},
			clave: {
				required: true,
				minlength: 5,
				maxlength:15
			}
		},
		messages: {
			usuario: {
				required: "<br />Introdueix el teu usuari",
				minlength: "<br />Mínim 5 caràcters",
				maxlength: "<br />Màxim 15 caràcters",
				remote: "<br />Usuari erroni"
			},
			clave: {
				required: "<br />Introdueix la teva clau",
				maxlength: "<br />Màxim 15 caràcters",
				minlength: "<br />Mínim 5 caràcters"
			}
		},
		//verificar si coinciden usuario y clave, si es asi iniciar variables de sesion y recargar la pagina
		submitHandler: function(){
			var login = jQuery("#usuario").val();
			var clave = jQuery("#clave").val();
			jQuery.ajax({
				url: '/cxcat/ajax_validar_usuario.php?accion=1&login=' + login + '&clave=' + clave,
				type: 'GET',
				dataType: 'text',
				error: function(error){
					//alert('Error Data');
				},
				success: function(codigoMsg){
					//location.href=codigoMsg;
					if (codigoMsg == "false") {
						tb_show("Informaci&oacute;","html_informacio.php?tipus=1&tab=0&height=80&width=400", null);
					}
					else {
						location.href=codigoMsg;
					}
					
				
				
				}
			});
		}
	});
	
	/*
	$("#lnk_logoff").click( function() {
		jQuery.ajax({
			url: '/cxcat/ajax_logoff.php?k=1',
			type: 'GET',
			dataType: 'text',
			error: function(error) {
				tb_show("Informaci&oacute;","html_informacio.php?tipus=2&tab=0&height=250&width=400", null);
			},
			success: function(msg) {
				//tb_show("Informaci&oacute;","html_informacio.php?tipus=3&tab=0&height=250&width=400", null);
				document.location.reload()
			}
		});
	})
	*/
	
	$("#form_encuesta").click( function() {
		//alert($("#respuesta").val());
	})

});

