$(document).ready(function(){ 
	var $_GET = {};

	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
	    function decode(s) {
	        return decodeURIComponent(s.split("+").join(" "));
	    }

	    $_GET[decode(arguments[1])] = decode(arguments[2]);
	});



	// initialise jqModal
	$('#jqModal').jqm({
		overlay: 70,
		modal: false,
		trigger: 'a.triggerRegistro',
		onShow: function(hash){ hash.w.fadeIn(500);hash.o.fadeIn(500); },
		onHide: function(hash){ hash.w.fadeOut(300);hash.o.fadeOut(300, function(){$(this).remove()}); $('#registrar input[type="text"], #registrar input[type="password"]').each(function(){$(this).val("");}); }
	}).jqmAddClose('#cancelar,#cerrar');
	
	$('#registrar').submit(function(){
		var error =0;	
		
		$("#registrarUsuario input").each(function(){
			if($(this).val()==''){error++;}
		
		});
		if(error!=0){
			$("#estado").html("Llene los campos incompletos.")
				.addClass('error')
				.show()
				.fadeOut(4000,function(){$(this).removeClass('error');});
			
			return false;
		
		}
		
		
		$.ajax({
			type:"post",
			url:"admin/actions/agregar-usuariosv.php",
			dataType: "html",
			data: "lang="+$_GET["lang"]+"&guardar=si&nombre="+$("#nombre").val()+"&apellido="+$("#apellido").val()+"&nick="+$("#nick").val()+"&email="+$("#email").val()+"&clave="+$("#clave").val(),
			beforeSend: function(){
						$("#estado").html("Procesando datos de registro.").show();
						$("#registrar").fadeOut();
						},
			success: function(data){
					$("#estado").html(data);
					$("#cerrar").show();
					}
		});
		return false;
	});
	
});  
