function pop(que){
window.open(que,'popscroll','resizable=1,status=1,toolbar=0,menubar=0,scrollbars=1,width=630,height='+(screen.height-200)+',screenX='+(screen.width-400)+',screenY=0,left='+(screen.width-500)+',top=0');
}

function addCesta(idLibro){
	$.ajax({
			type: "POST",
			url: "ajax/ajx-cesta.php",
			data: "action=control&idLibro="+idLibro,
			success: function(ok){		
				if(ok==1){
					$.ajax({
							type: "POST",
							url: "ajax/ajx-cesta.php",
							data: "action=add&idLibro="+idLibro,
							success: function(html){
								$("#enlaCesta").text(html);
								$("#info").show();
								$("#info").fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800, function() {
									$("#info").hide();
								  });
							}
					});
				}else{
					$("#info2").show();
					$("#info2").fadeOut(800).fadeIn(1600).fadeOut(800, function() {
						$("#info2").hide();
					});
				}
			}
		});			
}

function addRCesta(idLibro){
	$.ajax({
			type: "POST",
			url: "ajax/ajx-cesta.php",
			data: "action=control&idLibro="+idLibro,
			success: function(ok){		
				if(ok==1){
					$.ajax({
							type: "POST",
							url: "ajax/ajx-cesta.php",
							data: "action=addR&idLibro="+idLibro,
							success: function(html){
								/*$("#enlaCesta").text(html);
								$("#info_"+idLibro).show();
								$("#info_"+idLibro).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800, function() {
									$("#info_"+idLibro).hide();
								  });
								  */
								 $("#libros_regalo").hide(); 
								 $("#libro_regalo_finalizado").show(); 
							}
					});
				}else{
					$("#info2_"+idLibro).show();
					$("#info2_"+idLibro).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(1600).fadeOut(800, function() {
						$("#info2_"+idLibro).hide();
					});
				}
			}
		});			
}
function addECesta(idLibro){
	$.ajax({
			type: "POST",
			url: "ajax/ajx-cesta.php",
			data: "action=Eadd&idLibro="+idLibro,
			success: function(html){
				$("#enlaCesta").text(html);
				$("#Einfo").show();
				$("#Einfo").fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800, function() {
					$("#Einfo").hide();
				  });
			}
	});
}

function menosItem(idLibro,ebook){
		$.ajax({
			type: "POST",
			url: "ajax/ajx-cesta.php",
			data: "action=menos&idLibro="+idLibro+"&ebook="+ebook,
			success: function(html){
				$("#basket-main").empty();
				$("#basket-main").append(html);
				$.ajax({
						type: "POST",
						url: "ajax/ajx-cesta.php",
						data: "action=updateTxt",
						success: function(html){
							$("#enlaCesta").text(html);
						}
				});
			}
	});
}

function masItem(idLibro,ebook){
	$.ajax({
			type: "POST",
			url: "ajax/ajx-cesta.php",
			data: "action=mas&idLibro="+idLibro+"&ebook="+ebook,
			success: function(html){
				$("#basket-main").empty();
				$("#basket-main").append(html);
				$.ajax({
						type: "POST",
						url: "ajax/ajx-cesta.php",
						data: "action=updateTxt",
						success: function(html){
							$("#enlaCesta").text(html);
						}
				});
			}
	});
}

function SubmitLoginCesta(){
	var login = $("#loginCesta").val();
	var passwd = $("#passwdCesta").val();
	$.ajax({
		type: "POST",
		url: "ajax/ajx-login.php",
		data: "action=login&login="+login+"&passwd="+passwd,
		success: function(html){
			if(html=='0'){
				alert('login o contraseña incorrecta');
			}else{
				$("#usuario").text(html);
				$.ajax({
					type: "POST",
					url: "ajax/ajx-login.php",
					data: "action=getlogoutForm",
					success: function(resu){
						$('#topMenu').empty();
						$('#topMenu').append(resu);
					}
				});
				$.ajax({
					type: "POST",
					url: "ajax/ajx-cesta.php",
					data: "action=getCliInfo&login="+html,
					success: function(html){
						$("#cesta-pasos").empty();
						$("#cesta-pasos").append(html);
					}
				});
			}
		}
	});
}

function getDatosStep2(checkObj){
	if(checkObj.checked){
		$.ajax({
					type: "POST",
					url: "ajax/ajx-cesta.php",
					data: "action=fillstep3&step=3",
					success: function(html){
						$(".form_step3").empty();
						$(".form_step3").append(html);
					}
				});
	}
}

function validForm2(){
	if(document.getElementById('condgen')){
		if($('#condgen').is(':checked')){
			$('#step2form').submit();
		}else{
			alert('Tienes que leer y acceptar la ley de Protección de datos');
		}
	}else{
		$('#step2form').submit();
	}
}

$(document).ready(function(){
	$('#nuevoUsuario').click(function(){
		$(".form-fila-existente").hide();
		$(".form-fila-nuevo").show();
	});
	$('#tengoCuenta').click(function(){
		$(".form-fila-nuevo").hide();
		$(".form-fila-existente").show();
	});

});
