 function desplegar(id)
{
	$('#'+id).slideToggle();
}

function seleccionar_acabado(id,id_real)
{
	$(".imagen_acabado").hide();
	$("#acabado"+id).show();
	$("#acabado"+id).css("display","block");
	$(".acabado img").removeClass("selected");
	$("#muestra_acabado"+id+" img").addClass("selected");
	$("#acabado_seleccionado").val(id_real);
	
	$.ajax({
		type: "GET",
		url: "index.php",
		data: "ajax=true&function=get_tallas&id_p="+id_real,
		success: function(html){
			$('.talla.hidden').remove();
			$('#purchuase-button').before(html);
		}
	});
	
	
	// Control de stock
	if ($('#talla_seleccionada').attr('value') == '_u_') {
		$.ajax({
			async:false,
			type: "GET",
			url: "index.php",
			data: "ajax=true&function=get_stock&id_t="+$("#talla_seleccionada").val()+"&id_a="+$("#acabado_seleccionado").val()+"&items="+$("#unidades").val(),
			success: function(html){
				
				
				if (html.length > 5) {
					
					$('#purchuase-button').html("NO DISPONIBLE");
					
				} else $('#purchuase-button').html("AÑADIR A LA CESTA");
				
			}
		});
	} else {
		
		$('#talla_seleccionada').attr('value','');
		
	}
	
}

function seleccionar_talla(id,id_real)
{
	$(".talla").removeClass("selected");
	$("#talla"+id).addClass("selected");
	$("#talla_seleccionada").val(id_real);
	
	// Control de stock
	$.ajax({
		async:false,
		type: "GET",
		url: "index.php",
		data: "ajax=true&function=get_stock&id_t="+$("#talla_seleccionada").val()+"&id_a="+$("#acabado_seleccionado").val()+"&items="+$("#unidades").val(),
		success: function(html){
			
			
			if (html.length > 5) {
				
				$('#purchuase-button').html("NO DISPONIBLE");
				
			} else $('#purchuase-button').html("AÑADIR A LA CESTA");
			
		}
	});


}

function comprobar_ficha_producto()
{
	if($("#acabado_seleccionado").val()=="")
	{
		alert('Por favor, selecciona una de las opciones disponibles para añadir el producto al pedido.');
		return false;
	}
	
	if($("#talla_seleccionada").val()=="")
	{
		alert('Por favor, selecciona una talla para añadir el producto al pedido.');
		return false;
	}
	
	var errors = false;
	
	// Control de stock
	$.ajax({
		async:false,
		type: "GET",
		url: "index.php",
		data: "ajax=true&function=get_stock&id_t="+$("#talla_seleccionada").val()+"&id_a="+$("#acabado_seleccionado").val()+"&items="+$("#unidades").val(),
		success: function(html){
			
			
			if (html.length > 5) {
				errors = true;
				alert (html);
				
			}
			
		}
	});

	if (!errors) return true;
	else return false;
}
/*
function callback_return(){
	alert ('lere');
}*/

$(document).ready( function() { 
	
	document.getElementById('s').focus();

	
	//Ficha de producto
	$("#purchuase-button").click(function() { aux=comprobar_ficha_producto(); return aux; });
} );
