// Select form small
$(document).ready(function() {
						   
	var okToToggle = true;
	$(".select-trigger").click(function() {
		okToToggle = false;
		$(this).next().slideToggle("fast", function(){
			okToToggle=true;
		});
	});
	$(document).click(function() {
		if(okToToggle) $(".select-items-wrapper").hide();	
	});
	$(".select-items-ul li").hover(function() {
		$(this).addClass("select-items-ul-li-item-hover");
		$(this).children("a").css({"color":"#FFFFFF", "text-decoration":"none"});
	}, function() {
		$(this).removeClass("select-items-ul-li-item-hover");
		$(this).children("a").css({"color":"#535353"});
	});


	// Select form small
	var okToToggleSmall = true;
	$(".select-small-trigger").click(function() {
		okToToggleSmall = false;
		$(this).next().slideToggle("fast", function(){
			okToToggleSmall = true;
		});
	});
	$(document).click(function() {
							 
		if(okToToggleSmall) $(".select-small-items-wrapper").hide();	
	});
	$(".select-small-items-ul li").hover(function() {
		$(this).addClass("select-small-items-ul-li-item-hover");
		$(this).css({"color":"#FFFFFF", "text-decoration":"none"});
	}, function() {
		$(this).removeClass("select-small-items-ul-li-item-hover");
		$(this).css({"color":"#535353"});
	});
	// Select and change first label small
	$(".select-small-item").click(function() {
		var label = $(this).parent().parent().prev();
		var selected_id = $(this).attr('id').replace('area-','');
		var selected_label = $(this).html();
		label.html(selected_label);
		$("#area").val(selected_id);
	});
	
	
	
	//botao de adicionar ao carrinho
	$(".botao_adicionar").click(function(e) {
		e.preventDefault();
		var opcoes=$(".opcao_escolha").size();
		if(opcoes==0)
			$('#produto').submit();
		else
		{
			var flag=false;
			$(".opcao_escolha").each(function()
			{
				if($(this).val()=="")
					flag=true;
			});	
			if(flag)
				alert("Tem de escolher todas as opções")
			else
				$('#produto').submit();			
		}	
	});
	
	var preco_inicial=$("#preco").val();
	
	
	//opcoes
	$(".opcao_escolha").change(function() {
		var valor=0;	
		/*if($("option:selected", this).attr('title')!="")
		{
			var preco_temp=$("#preco").val();
			preco_temp=parseFloat(preco_temp)+parseFloat($("option:selected", this).attr('title'));
			preco_temp=preco_temp.toFixed(2);
			$("#preco").val(preco_temp);
			$(".preco_val_").html(preco_temp.replace(".",","));
		}
		else
		{
			$("#preco").val(preco_inicial);
			$(".preco_val_").html(preco_inicial.replace(".",","));
		}*/
		//preco_temp=preco_temp.replace(",",".");
		
		$(".opcao_escolha option:selected").each(function(){
			if($(this).attr('title')!="")
				valor+=parseFloat($(this).attr('title'));
		});
		
		var preco_temp=0;
		preco_temp=parseFloat(preco_inicial)+parseFloat(valor);
		
		preco_temp=preco_temp.toFixed(2);
		$("#preco").val(preco_temp);
		$(".preco_val_").html(preco_temp.replace(".",","));
		
	});

});

function goTop()
{
	window.scroll(0,0);
}

x = screen.width; 
y=  screen.height;
t = x / 2;
l = y / 2;

function popUpInscritos(prova)
{
	window.open("inscritos.php?prv="+prova,"Inscritos","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=1000,height=700,top=10,left=10");
}

function popUpResultados(prova,classi)
{
	window.open("resultados.php?prv="+prova+"&xid="+classi,"Classificação","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=1000,height=700,top=10,left=10");
}
