$().ready(function(){
	function getUrlVars()
	{
		if(window.location.href.indexOf('#')!=-1){
			var vars = window.location.href.slice(window.location.href.indexOf('#'));
			$(vars).show();
			$(".minificha").hide();
			$("#familia").hide();
			$(".paginacion").hide();
		} else {
			return false;
		}
	}
	getUrlVars();
	//enviar a un amigo
    $(".abrirenviar").toggle(
      function () {
		$(this).text("Cerrar");
		$(this).after($(".enviaramigo"));
		$(".enviaramigo").show();
		$("#idenlace").attr("value", $(this).attr("href"));
		return false;
      },
      function () {
		$(this).text("Enviar a un amigo");
		$(".enviaramigo").hide();
		return false;
      }
    );
	$(".alerta").css( "height", $().height() ).css( "width", $().width() ).css('top', $().scrollTop()+ "px");	
	$('#vercesta').click(function(){
		$("body").css("overflow", "hidden");
		marleft = ($().width()/2)-445;
		$(".contenidocesta").css( "height", $().height() ).css( "width", $().width() ).css('top', $().scrollTop()+ "px").show();
		return false;
	});
	$('#vercesta2').click(function(){
		$("#seguircomprando").trigger('click');
		$("#vercesta").trigger('click');
		return false;
	});
	$('#seguircomprando').click(function(){
		$("body").css("overflow", "auto");
		$(".alerta").hide();
	});
   $(".minificha span").hover(
      function () {
        $(this).parent().addClass("minifichahover");
      }, 
      function () {
        $(this).parent().removeClass("minifichahover");
      }
    );
/*
	$(".minificha span").click(function(){
		var index=  $(".minificha span").index(this);
		$(".formficha:eq("+index+")").show();
		$(".minificha").hide();
		$("#familia").hide();
		$(".paginacion").hide();
		return false;
		}
	);
*/
/*
	$('.cerrar a').click(function(){
		$(this).parent().parent().parent().hide();
		$(".minificha").show();
		$("#familia").show();
		$(".paginacion").show();
		return false;
		}
	);
*/
	$('.seguircompra').click(function(){
		$("body").css("overflow", "auto");
		$(".contenidocesta").hide();
		}
	);
	$('.acceso').click(function(){
		$(".login").show();
		$(".login .errorformdatos").remove();
		return false;
		}
	);
	$('.cerrarlogin').click(function(){
		$(".login").hide();
		}
	);
	$('.cerrarcesta').click(function(){
		$(".alerta").hide();
		}
	);
	$('.filtro select').change(function(){
		location.href = $(this).val(); 
		}
	);
	$(".comprarficha").click(function(){
//		alert($(this).parent().parent().parent().find("#textoconfig").html());
//		return false;
		var graba = $(this).parent().parent().find("#textograbable");
		var confa = $(this).parent().parent().parent().find("#textoconfig");
		if( $(this).parent().parent().find("#textograbable").html() != null ){
			if(graba.val().match(/[^a-zA-Z0-9\-\.\:\,\/] /) != null ){
				alert("Debe indicarnos el texto deseado");
				return false;
			}
		};
		if( $(this).parent().parent().parent().find("#textoconfig").html() != null ){
			if(confa.val().match(/[^a-zA-Z0-9]/) != null || confa.val().length == 0 ){
				alert("Debe indicarnos el texto deseado");
				return false;
			}
		};
	});

	//CALCULADOR DE PRECIOS
    $(".ficha select").change(function () {
		var Arrpreciotalla = $(this).val().split("|");
		var preciosuma = parseFloat(Arrpreciotalla[1]);
		var precioculto = parseFloat($(this).parent().parent().parent().find("#precioculto").text());
		var resultado = preciosuma+precioculto+" €";
		$(this).parent().parent().parent().find("h4").text(preciosuma+precioculto+" €");
	});
	//PREVISUALIZACION FLASH
	$(".prevconf").toggle(
      function () {
        $(this).text("Cerrar Previsualización");
		$(this).parent().find(".flashconf").show();
      },
      function () {
        $(this).text("Ver Previsualización");
        $(this).parent().find(".flashconf").hide();
      }
	);
	$('#textoconfig').keyup(function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		var eltexto = $('#textoconfig').val().toUpperCase();
		  if(code == 32){
			 eltexto = eltexto.slice(0,eltexto.length-1); 
		  }
		$('#textoconfig').val(eltexto)
		}
	);
});
function getNombre() {
	return $("#textoconfig").val();
}
