function limpa (nome) {
	document.getElementById(nome).style.background="#E1E1E1";
}

function limpa2 () {
	document.getElementById('feed_drag').innerHTML=''; 
	document.getElementById('id_drag').value='';
}

function limpa10 (id,texto) {
	if (document.getElementById(id).value==texto) {
		document.getElementById(id).value="";
	}
}

function fechar (framex,new_page,first) {
	window.scroll(0,0);
	mostra_aguarde2();
	
	if (new_page=="") {
		document.getElementById(framex).innerHTML = '';
		esconde_aguarde2();	
	} else {
		window.open(new_page,"prov");
	}
	
	exit();
	
	if (first!="sim") {
		mostra_aguarde2();
		setTimeout("fechar('" + framex + "','" + new_page + "','sim');", 1);
	} else {
		var altura;
		var t2;
		altura=document.getElementById(framex).height;
		
		document.getElementById(framex).innerHTML = '';
		
		if (altura<=20) {
			t2=1;
			
		} else {
			t2=altura-20;
		}
		
		document.getElementById(framex).height = t2;
		if (t2>=2) {
			setTimeout("fechar('" + framex + "','" + new_page + "','sim');", 1);
		} else {
			window.open(new_page,"prov");
		}
	}

}

function ignora_aguarde() {
	setTimeout("esconde_aguarde2();", 200);
}

function fechar2 (framex,new_page,first) {
	if (first!="sim") {
		setTimeout("fechar('" + framex + "','" + new_page + "','sim');", 1);
	} else {
		var altura;
		var t2;
		altura=document.getElementById(framex).height;
		
		document.getElementById(framex).innerHTML = '';
		
		if (altura<=20) {
			t2=1;
			
		} else {
			t2=altura-20;
		}
		
		document.getElementById(framex).height = t2;
		if (t2>=2) {
			setTimeout("fechar('" + framex + "','" + new_page + "','sim');", 1);
		} else {
			window.open(new_page,"prov");
		}
	}
}

function muda_pagina (new_page) {
	window.open(new_page,"prov");
}

function teste(anox) {
	if (anox<=1988) {
		document.getElementById('escalao').value = "Séniores";
	}
	if (anox>=1989) {
		document.getElementById('escalao').value = "Júniores";
	}
	if (anox>=1991) {
		document.getElementById('escalao').value = "Juvenis";
	}
	if (anox>=1993) {
		document.getElementById('escalao').value = "Iniciados";
	}
	if (anox>=1995) {
		document.getElementById('escalao').value = "Infantis A";
	}
	if (anox>=1997) {
		document.getElementById('escalao').value = "Infantis B";
	}
}

function aguarde (framex) {
	document.getElementById(framex).innerHTML = '<table width="200" border="0" cellpadding="0" cellspacing="0"><tr><td align="right" valign="middle" class="texto3" width="175">Aguarde por favor...</td><td height="30" align="right" valign="middle" width="25"><img src="imagens/progress.gif" /></td></tr></table>';
}

function aguarde2 (framex) {
	document.getElementById(framex).innerHTML = '<table width="200" border="0" cellpadding="0" cellspacing="0"><tr><td height="30" align="left" valign="middle" width="25"><img src="../../imagens/progress.gif" /></td><td align="left" valign="middle" class="texto3" width="175">Aguarde por favor...</td></tr></table>';
}

function carrega_concelho () {
	var distrito;
	distrito=document.getElementById('distrito').value
	window.open("includes/includes.php?frame=feed_concelho&altura=0&page=scripts/concelhos&distrito=" + distrito,"prov");
	document.getElementById('freguesia').options.length = 0; 
}

function carrega_freguesia () {
	var concelho;
	concelho=document.getElementById('concelho').value
	window.open("includes/includes.php?frame=feed_freguesia&altura=0&page=scripts/freguesias&concelho=" + concelho,"prov");
}

function carrega_escaloes (frame,base_esc) {
	var escalao;
	escalao=document.getElementById('escalao').value
	document.getElementById('feed_botao').innerHTML = '';
	window.open("includes/includes1.php?page=config_torneio/escalao1&id_esc=" + escalao + "&frame=" + frame + "&base_esc=" + base_esc + "&esc_id=" + escalao,"prov");
	limpa_esc ();
}

function carrega_populacao_especifica (pagina) {
	var populacao;
	populacao=document.getElementById('populacao').value
	if (populacao=="População específica") {
		window.open("includes/includes1.php?page=config_torneio/populacao_especifica&frame=" + pagina,"prov");
	} else {
		document.getElementById('feed_pop_especifica').innerHTML='';
	}
}

function insere_foto (id) {
	document.getElementById('feed_foto').innerHTML = '<form action="scripts/upload_foto.php" target="prov" method="post" enctype="multipart/form-data"><table width="20%" border="0" cellspacing="0" cellpadding="0">      <tr>      <td height="36" align="left" valign="middle" class="texto1">Indique a foto...        <input name="id" type="hidden" id="id" value="' + id + '" />          <br />          <input type="file" name="uploadedfile" /></td>    </tr>    <tr>      <td height="37" align="center" valign="middle" class="texto1"><input name="inserir" type="submit" class="but" id="inserir" value="Inserir foto" /></td>    </tr>    <tr>     <td height="19" align="center" valign="middle" class="texto3" id="feed_upload_foto">&nbsp;</td>    </tr> </table> </form>';
}

function insere_foto1 (id) {
	document.getElementById('feed_foto').innerHTML = '<form action="scripts/upload_foto.php" target="prov5" method="post" enctype="multipart/form-data"><table width="20%" border="0" cellspacing="0" cellpadding="0">      <tr>      <td height="36" align="left" valign="middle" class="texto1">Indique a foto...        <input name="id" type="hidden" id="id" value="' + id + '" />          <br />          <input type="file" name="uploadedfile" /></td>    </tr>    <tr>      <td height="37" align="center" valign="middle" class="texto1"><input name="inserir" type="submit" class="but" id="inserir" value="Inserir foto" /></td>    </tr>    <tr>     <td height="19" align="center" valign="middle" class="texto3" id="feed_upload_foto">&nbsp;</td>    </tr>  </table></form>';
}

function todas (limite,ref) {
	for (x=0;x<=limite;x=x+1) 
	{
    	document.getElementById(ref + x).checked="checked";
	}
}

function nenhuma (limite,ref) {
	for (x=0;x<=limite;x=x+1) 
	{
    	document.getElementById(ref + x).checked="";
	}
}

function WriteLayer(ID,parentID,sText) {
	if (document.layers) {
		var oLayer = (parentID)? eval('document.' + parentID + '.document.' + ID + '.document') : document.layers[ID].document;
		oLayer.open();
		oLayer.write(sText);
		oLayer.close();
	}
	else if (document.all) document.all[ID].innerHTML = sText
	else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
		document.getElementById(ID).innerHTML = sText;
	}
}

function esconde() {
	var obj = document.getElementById('info').style; 
	obj.visibility = 'hidden';
}

function FP_swapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function activa_check(id_box) {
	if (document.getElementById(id_box).checked) {
		document.getElementById(id_box).checked="";
	} else {
		document.getElementById(id_box).checked="checked";
	}
	limpa_esc ();
}

function AddItem(texto,valor,caixa) {
	var opt = document.createElement('option');
	document.getElementById(caixa).options.add(opt);
	opt.text = texto;
	opt.value = valor;
	
	for(i=0;i<document.all(caixa).length;i++)
	{
		if(document.all(caixa).options[i].value==valor)
		{
			document.all(caixa).selectedIndex=i;

		}
	}
}

function submeter_msg (texto,frame,align) {
	parent.document.getElementById(frame).innerHTML = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="30" align="' + align + '" valign="bottom" class="texto3" style="padding-right:30px"><img src="imagens/progress.gif" />' + texto + '</td></tr></table>';	
}

function ultimo_passo (texto,frame,align,id_tor) {
	parent.document.getElementById(frame).innerHTML = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="30" align="' + align + '" valign="bottom" class="texto3" style="padding-right:30px"><img src="imagens/progress.gif" />' + texto + '</td></tr></table>';
	window.open("includes/config_torneio/scripts/config_torneios4_script.php?id_tor=" + id_tor,"prov");
}

function load_name_convert () {
	var nome;
	nome=document.getElementById('nome').value;
	window.open('includes/includes1.php?frame=feed_nome_abreviado&altura=0&page=scripts/nome_abreviado&nome=' + nome,"prov");
}

function load_name_convert2 () {
	var nome;
	nome=document.getElementById('nome').value;
	window.open('../../includes/includes1.php?frame=feed_nome_abreviado&altura=0&page=scripts/nome_abreviado&nome=' + nome,"prov5");
}

function insere_poster (id) {
	document.getElementById('feed_poster').innerHTML = '<table width="186" border="0" cellspacing="0" cellpadding="0">  <form action="scripts/upload_poster.php" target="prov" method="post" enctype="multipart/form-data">    <tr>      <td width="216" height="36" align="left" valign="middle" class="texto1"><input name="id" type="hidden" id="id" value="' + id + '" />          <br />          <input type="file" name="uploadedfile" style=" width:180px" /></td>    </tr>    <tr>      <td height="37" align="center" valign="middle" class="texto1"><input name="inserir" type="submit" class="but" id="inserir" value="Inserir Cartaz" onclick="aguarde(\'feed_upload_poster\');" /></td>    </tr>    <tr><td height="40" align="center" valign="middle" class="texto3" id="feed_upload_poster" style="padding-left:15px">&nbsp;</td></tr><tr>     <td height="83" align="left" valign="middle" class="texto_back" style="padding-left:15px">Tamanho m&aacute;ximo da imagem: <strong>200kb</strong> <br /><br />Tipos de ficheiros suportados: <br /><strong>jpg, gif e png</strong> </td>    </tr>  </form></table>';
}

function insere_auto (id,opt) {
	window.open("scripts/autorizacao.php?id_tor=" + id + "&opt_auto=" + opt,"prov");
}

function insere_regu (id,opt) {
	window.open("scripts/regulamento.php?id_tor=" + id + "&opt_regu=" + opt,"prov");
}

function opt_pagina (id,opt) {
	window.open("scripts/opt_pagina.php?id_tor=" + id + "&opt_pagina=" + opt,"prov");
}

function opt_regu (id,opt) {
	window.open("scripts/opt_regu.php?id_tor=" + id + "&opt_regu=" + opt,"prov");
}

function muda_trofeu(trofeu,id_tor,tipo) {
	window.open("includes/includes1.php?page=config_trofeus&frame=feed_trofeus&id_tor=" + id_tor + "&trofeu=" + trofeu + "&tipo=" + tipo,"prov");
}

function opt_pagamento(id_tor,valor,page,frame) {
	if (document.getElementById(valor).checked) {
		valor="sim";	
	}
	window.open("includes/includes1.php?page=" + page + "&frame=" + frame + "&id_tor=" + id_tor + "&valor=" + valor,"prov");
}

//function limpa(id,texto) {
//	if (document.getElementById(id).value==texto) {
//		document.getElementById(id).value="";
//	}
//}

function muda_paga(valor,id_tor,id_insq) {
	aguarde2('feed_paga' + id_insq);
	window.open("../includes1.php?page=torneios_page/scripts/forma_paga&id_tor=" + id_tor + "&valor=" + valor + "&frame=feed_paga" + id_insq + "&id_insq=" + id_insq,"prov5");
}

function pagina_pesquisa (next) {
	window.open("includes/includes1.php?page=pesquisa/resultado_pesquisa&frame=feed_res_pesquisa&altura=300&next=" + next,"prov");
}

function pagina_pesquisa2 (next) {
	window.open("includes/includes1.php?page=pesquisa/resultado_pesquisa2&frame=feed_res_pesquisa&altura=300&next=" + next,"prov");
}

function pagina_pesquisa3 (next,id_tor) {
	window.open("../../includes1.php?page=torneios_page/inscrever/resultado_pesquisa&frame=feed_pesq_user&altura=300&next=" + next + "&id_tor=" + id_tor,"prov5");
}

function muda_passo(local) {
	window.open("includes/config_torneio/muda_passos.php?local=" + local,"prov2");
}

function eliminar_torneio () {
	var nome;
	var id_tor;
	nome=document.getElementById('elim_confirm').value
	id_tor=document.getElementById('id_torneio').value
	window.open("scripts/conf_elim_tor.php?conf=" + nome + "&id_tor=" + id_tor,"prov");
}

function activa_check2(id_box,nome_esc) {
	
	if (document.getElementById('esc' + id_box).checked) {
		document.getElementById('esc' + id_box).checked="";
	} else {
		document.getElementById('esc' + id_box).checked="checked";
	}
	conta_escalao(nome_esc);
}

function conta_escalao(nome_esc) {
	var total_esc=document.getElementById('total_esc').value;
	var vistos;
	var nomes;
	var num;
	var x;
	vistos=0;
	num=0;
	nomes="";
	
	//---conta o número de inscrições---
	for (x=0;x<=total_esc-1;x=x+1) {
		
		if (document.getElementById('esc' + x).checked) {
			vistos=vistos+1;
			nomes=nomes + "»» " + document.getElementById('nom' + x).value + ' - ' + document.getElementById('sex' + x).value + "<br>";
			num=num+parseInt(document.getElementById('num' + x).value);
		}
	}
	
	if (vistos==1) {
		document.getElementById('feed_escalao').innerHTML = 'Já escolheu uma prova para este torneio. <br><br>Total de inscrições nesta prova: ' + num + '. <br><br>Carregue em "PASSO SEGUINTE" para proceder à escolha do sistema de competição a utilizar neste torneio.<input type="hidden" id="n_insq" name="n_insq" value="' + num + '" />';
	}
	
	if (vistos>1) {
		document.getElementById('feed_escalao').innerHTML = '<table width="350" border="0" cellspacing="0" cellpadding="0"><tr><td align="left">Optou por agrupar as seguintes ' + vistos + ' provas: <br /><br />' + nomes + '<br />Total de inscrições: ' + num + '<br /><br />Terá que atribuir um título a este agrupamento de provas:<br /><br /> Título: <input name="nome_esc" type="text" id="nome_esc" maxlength="20" class="box" value="' + nome_esc + '" /><input type="hidden" id="n_insq" name="n_insq" value="' + num + '" /><br /></td></tr></table>';
	}
	
	if (vistos==0) {
		document.getElementById('feed_escalao').innerHTML = 'Ainda não escolheu nenhum escalão para este torneio.';
	}
	
}

function sistema_competicao (sistema,n_insq) {
	if (sistema=="Todos contra todos") {
		texto="<strong>Sistema de competição:</strong> Todos contra todos<br><strong>Mínimo de inscrições:</strong> 3<br><strong>Máximo de inscrições:</strong> 32<br><br><strong>Características:</strong> Serão criadas automaticamente as jornadas dos jogos, onde cada equipa joga contra todas as outras, uma, duas, três ou quatro vezes. As classificações são calculadas automaticamente, assim como os jogos ganhos, perdidos, etc.";
		document.getElementById('feed_info_sistema').innerHTML = '';
	}
	if (sistema=="Eliminatória directa") {
		
		var dica;
		var bye;
		var fase;
		
		bye=0;
		
 		texto="<strong>Sistema de competição:</strong> Eliminatória directa<br><strong>Mínimo de inscrições:</strong> 4<br><strong>Máximo de inscrições:</strong> 256<br><br><strong>Características:</strong> Será feito um sorteio aleatório e os participantes serão colocados numa grelha de confrontos directos. Ao introduzir os resultados dos jogos, os vencedores passam automaticamente à fase seguinte.";
		//---da uma dica para o número de inscritos nestes torneio.
		if (n_insq<=3) {
			dica="Neste momento só existem " + n_insq + " inscrições neste torneio. Tem que ter no mínimo 4 inscrições, para que possa passar ao passo seguinte!";
		}
		
		if (n_insq>=257) {
			dica="Existe um número excessivo de inscrições neste torneio (máximo 256) elimine algumas inscrições.";
		}
   
   		if (n_insq==4 || n_insq==8) {
			dica="O número de inscrições (" + n_insq + ") é ideal para este tipo de torneio.";
		}
     		
		if (n_insq > 4 && n_insq < 8) {
			bye = 8 - n_insq;
			fase = " a 1/2 final ";
		}
		
		if (n_insq > 8 && n_insq < 16) {
			bye = 16 - n_insq;
			fase = " os 1/4 de final ";
		}
		
		if (n_insq > 16 && n_insq < 32) {
			bye = 32 - n_insq;
			fase = " os 1/8 de final ";
		}
		
		if (n_insq > 32 && n_insq < 64) {
			bye = 64 - n_insq;
			fase = " os 1/16 de final ";
		}
		
		if (n_insq > 64 && n_insq < 128) {
			bye = 128 - n_insq;
			fase = " os 1/32 de final ";
		}
		
		if (bye == 1) { dica = bye + " dos inscritos passa directamente para" + fase + "do torneio!"; }
		if (bye != 1 && bye !=0) { dica = bye + " dos inscritos passam directamente para" + fase + "do torneio!"; }
		
		document.getElementById('feed_info_sistema').innerHTML = '<strong>Nota: </strong>' + dica;
	}
	
	if (sistema=="Fase de grupos + Eliminatória directa") {
		texto="<strong>Sistema de competição: </strong>Fase de grupos + Eliminatória directa<br><strong>Mínimo de inscrições:</strong> 6<br><strong>Máximo de inscrições:</strong> 256<br><br><strong>Características:</strong> Os grupos podem ser criados manualmente pelo utilizador ou automaticamente/aleatoriamente pelo Torneios.com.pt. O criador do torneio escolhe quantas equipas passam a fase de eliminatória directa do torneio (apuramento directo e/ou repescagem).";
		document.getElementById('feed_info_sistema').innerHTML = '';
	}
	document.getElementById('feed_sistema').innerHTML = '<table width="480" border="0" cellspacing="0" cellpadding="0">                    <tr>                      <td width="71" height="182" align="left" valign="top" style="padding-top:18px"><img src="imagens/fundos/info.png" width="56" height="56" /></td>                      <td width="409" align="left" valign="top" style="padding-top:15px">' + texto + '</td></tr></table>';
}

function passo3 (sistema,tipo) {
	if (sistema=="Todos contra todos") {
		window.open("includes/includes2.php?frame=feed_criar_torneios&altura=250&page=criar_torneio/sistemas_competicao/todos_contra_todos/criar_torneio3","prov");
	}
	
	if (sistema=="Eliminatória directa") {
		window.open("includes/includes2.php?frame=feed_criar_torneios&altura=250&page=criar_torneio/sistemas_competicao/eliminatoria_directa/criar_torneio3","prov");
	}
	
	if (sistema=="Fase de grupos + Eliminatória directa") {
		window.open("includes/includes2.php?frame=feed_criar_torneios&altura=250&page=criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/criar_torneio3" + tipo,"prov");
	}
}

function confirma_criar(modalidade) {
	document.getElementById('feed_criar').innerHTML = '<table width="401" border="0" cellspacing="0" cellpadding="0"><tr><td height="84"><img src="imagens/bolas/' + modalidade + '.png" /></td><td class="but_blue" style="line-height:20px"><div align="justify" class="texto10">O portal Torneios.com.pt j&aacute; tens todos os dados necess&aacute;rios para proceder &agrave; cria&ccedil;&atilde;o deste torneio. Certifique-se que todos os dados est&atilde;o correctos, e carregue no bot&atilde;o &quot;CRIAR ESTE TORNEIO&quot;. </div></td></tr><tr><td width="126" height="52">&nbsp;</td><td width="275" align="center"><input name="Submit2" type="submit" class="but_green" value="CRIAR ESTE TORNEIO" onclick="confirma_criar2()" /></td></tr></table>';
}

function confirma_criar2() {
	//document.getElementById('feed_criar').innerHTML = '<table width="300" border="0" cellpadding="0" cellspacing="0"><tr><td height="30" align="left" valign="middle" width="30"><img src="imagens/progress.gif" /></td><td align="left" valign="middle" class="texto3" width="270">A criar torneio, aguarde por favor...</td></tr></table>';
	//document.getElementById('but_left').innerHTML = '';
	//document.getElementById('but_right').innerHTML = '';
	//document.getElementById('but_calcula').innerHTML = '';	
}

function limpa_esc () {
	document.getElementById('feed_esc_tor').innerHTML = '';
}

function apuradas2 () {
	var grupos;
	var apuradas;
	var repescadas;
	grupos=document.getElementById('grupos').value;
	apuradas=document.getElementById('apuradas').value;
	repescadas=document.getElementById('repescadas').value;
	window.open("includes/criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/scripts/apuradas.php?grupos=" + grupos + "&apuradas=" + apuradas + "&repescadas=" + repescadas,"prov");
}

function repescadas7 () {
	var grupos7;
	var apuradas7;
	var repescadas7;
	grupos7=document.getElementById('grupos').value;
	apuradas7=document.getElementById('apuradas').value;
	repescadas7=document.getElementById('repescadas').value;
	window.open("includes/criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/scripts/repescadas.php?grupos=" + grupos7 + "&apuradas=" + apuradas7 + "&repescadas=" + repescadas7,"prov");
}

function sugestao4 () {
	var grupos;
	var apuradas;
	var repescadas;
	grupos=document.getElementById('grupos').value;
	apuradas=document.getElementById('apuradas').value;
	repescadas=document.getElementById('repescadas').value;
	window.open("includes/criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/scripts/sugestao2.php?grupos=" + grupos + "&apuradas=" + apuradas + "&repescadas=" + repescadas,"prov");
}

function esconde2() {
	var obj = document.getElementById('drag').style; 
	obj.visibility = 'hidden';
}

function esconde3() {
	var obj = document.getElementById('drag2').style; 
	obj.visibility = 'hidden';
}


function agarra (code) {
	document.getElementById('feed_drag').innerHTML=document.getElementById(code).innerHTML;
	document.getElementById('id_drag').value=code;
}

function agarra2 (code) {
	document.getElementById('feed_drag').innerHTML=document.getElementById(code).value;
	document.getElementById('id_drag2').value=code;
}

function agarra4 (evt) {
	document.getElementById('pos_layer').value=parseInt(mouseY3(evt));
	document.getElementById('altura_linha').value=parseInt(document.getElementById('feed_down').height);
}

function larga(nome) {
	
	if (document.getElementById('feed_drag').innerHTML!="") {
		if (document.getElementById('elim' + nome).value=="") {
			
			document.getElementById('elim' + nome).value=document.getElementById('feed_drag').innerHTML;
			
			var id_drag;
			id_drag=document.getElementById('id_drag').value;
			
			document.getElementById('equipa_elim' + nome).value=document.getElementById('equipa_elim_' + id_drag).value;
			document.getElementById('id_elim' + nome).value=document.getElementById('id_elim_' + id_drag).value;
			document.getElementById('nome_elim' + nome).value=document.getElementById('nome_elim_' + id_drag).value;
			document.getElementById('id_insc' + nome).value=document.getElementById('id_insc_' + id_drag).value;
			
			document.getElementById(id_drag).innerHTML='';
			document.getElementById(id_drag).height="1";
			document.getElementById('feed_but').innerHTML='<input name="Button" type="button" class="texto_back" style="width:140px" value="Anular distribuição" onclick="javascript:javascript:anula_auto6 ();" />';
			limpa7();
		}
	}
}

function larga2(nome) {
	
	if (document.getElementById('feed_drag').innerHTML!="") {
		if (document.getElementById('elim' + nome).value=="") {
			
			document.getElementById('elim' + nome).value=document.getElementById('feed_drag').innerHTML;
			
			var id_drag;
			id_drag=document.getElementById('id_drag').value;
			document.getElementById(id_drag).innerHTML='';
			document.getElementById(id_drag).height="1";
			document.getElementById('feed_but').innerHTML='<input name="Button" type="button" class="texto_back" style="width:140px" value="Anular distribuição" onclick="javascript:javascript:anula_auto ();" />';
			limpa7();
		}
	}
}

function limpa7 () {
	setTimeout("document.getElementById('feed_drag').innerHTML=''; document.getElementById('id_drag').value=''; document.getElementById('tot').value='';", 10);		
}

function closeWindows () {	
	Windows.closeAll();
}

function apuradas_auto () {
	var grupos;
	var apuradas;
	var repescadas;
	grupos=document.getElementById('grupos').value;
	apuradas=document.getElementById('apuradas').value;
	repescadas=document.getElementById('repescadas').value;
	window.open("includes/criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/apuradas_auto.php?grupos=" + grupos + "&apuradas=" + apuradas + "&repescadas=" + repescadas,"prov2");
}

function apuradas_auto6 () {
	window.open("includes/criar_torneio/sistemas_competicao/eliminatoria_directa/apuradas_auto.php","prov2");
}

function anula_auto() {
	var grupos;
	var apuradas;
	var repescadas;
	grupos=document.getElementById('grupos').value;
	apuradas=document.getElementById('apuradas').value;
	repescadas=document.getElementById('repescadas').value;
	window.open("includes/criar_torneio/sistemas_competicao/grupos_eliminatoria_directa/final.php?grupos=" + grupos + "&apuradas=" + apuradas + "&repescadas=" + repescadas,"prov2")
}

function anula_auto6() {
	window.open("includes/criar_torneio/sistemas_competicao/eliminatoria_directa/final.php","prov2")
}

function agarra3 (nome,id,grupo) {
	document.getElementById('feed_drag').innerHTML=nome;
	document.getElementById('id_drag').value=id;
	document.getElementById('grupo').value=grupo;
}

function larga3(grupo2) {
	if (document.getElementById('feed_drag').innerHTML!="") {
		
		var texto1;
		var texto2;
		var tot1;
		var tot2;
		var nome1;
		var nome2;
		var id1;
		var id2;
		var grupo1;
		var nome3;
		var id3;
		var x;
		
		grupo1=document.getElementById('grupo').value;
		nome3=document.getElementById('feed_drag').innerHTML;
		id3=document.getElementById('id_drag').value;
		
		//----limpa os dados temprarios---
		document.getElementById('feed_drag').innerHTML='';
		document.getElementById('id_drag').value='';
		document.getElementById('grupo').value='';
		
		tot1=document.getElementById('tot' + grupo1).value;
		tot2=document.getElementById('tot' + grupo2).value;
		
		texto1="";
		texto2="";
		
		if (grupo1!=grupo2) {
			//----update do grupo de destino----
			for (var i = 0; i < tot2; i++) {
			
				nome2=document.getElementById('nome' + grupo2 + i).innerHTML;
				id2=document.getElementById('insq_id' + grupo2 + i).value;
				
				//----jogadores ja existentes---
				texto2=texto2 + '<table cellpadding="0" cellspacing="0" border="0" style="float:left" width="169"><tr><td width="169" height="30" align="center" class="texto_padrao" style="cursor:hand;" onmousedown="agarra3(\'' + nome2 + '\',\'' + id2 + '\',\'' + grupo2 + '\'); follow2(event);" onmouseover="javascript:this.className=\'menu_on\'" onmouseout="javascript:this.className=\'texto_padrao\'" id="nome' + grupo2 + i + '">' + nome2 + '</td><input type="hidden" id="insq_id' + grupo2 + i + '" name="insq_id' + grupo2 + i + '" value="' + id2 + '" /></tr></table>';
			}
			
			//----jogador novo----
			tot2=parseInt(tot2)+1;
			
			texto2=texto2 + '<table cellpadding="0" cellspacing="0" border="0" style="float:left" width="169"><tr><td width="169" height="30" align="center" class="texto_padrao" style="cursor:hand;" onmousedown="agarra3(\'' + nome3 + '\',\'' + id3 + '\',\'' + grupo2 + '\'); follow2(event);" onmouseover="javascript:this.className=\'menu_on\'" onmouseout="javascript:this.className=\'texto_padrao\'" id="nome' + grupo2 + i + '">' + nome3 + '</td><input type="hidden" id="insq_id' + grupo2 + i + '" name="insq_id' + grupo2 + i + '" value="' + id3 + '" /></tr></table>';
			
			//----update do grupo de origem----
			x=0;
			for (var i = 0; i < tot1; i++) {
			
				nome1=document.getElementById('nome' + grupo1 + i).innerHTML;
				id1=document.getElementById('insq_id' + grupo1 + i).value;
				
				if (id3!=id1) {
					//----jogadores ja existentes---
					texto1=texto1 + '<table cellpadding="0" cellspacing="0" border="0" style="float:left" width="169"><tr><td width="169" height="30" align="center" class="texto_padrao" style="cursor:hand;" onmousedown="agarra3(\'' + nome1 + '\',\'' + id1 + '\',\'' + grupo1 + '\'); follow2(event);" onmouseover="javascript:this.className=\'menu_on\'" onmouseout="javascript:this.className=\'texto_padrao\'" id="nome' + grupo1 + x + '">' + nome1 + '</td><input type="hidden" id="insq_id' + grupo1 + x + '" name="insq_id' + grupo1 + x + '" value="' + id1 + '" /></tr></table>';
					x=parseInt(x)+1;
				} 
			}
			
			document.getElementById('feed_grupo' + grupo1).innerHTML=texto1;
			tot1=parseInt(tot1)-1;
			document.getElementById('tot' + grupo1).value=tot1;
			
			document.getElementById('feed_grupo' + grupo2).innerHTML=texto2;
			document.getElementById('tot' + grupo2).value=tot2;
		}
	}
}

function mostra_aguarde() {
	var obj = document.getElementById('aguarde1').style; 
	obj.visibility = 'visible';
}

function esconde_aguarde() {
	var obj = document.getElementById('aguarde1').style; 
	obj.visibility = 'hidden';
}

function mostra_aguarde2() {
	var obj = document.getElementById('aguarde2').style; 
	obj.visibility = 'visible';
}

function esconde_aguarde2() {
	var obj = document.getElementById('aguarde2').style; 
	obj.visibility = 'hidden';
}

function elimina_prova123(id_tor, escalao) {
	window.open("includes/criar_torneio/scripts/elimina_prova2.php?id_tor=" + id_tor + "&escalao=" + escalao,"prov");
}

function so_numeros(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	} else {
		return true;
	}
}

function dados_admin5 () {
	if (document.getElementById('opt_admin').value=="sim") {
		var nome;
		var email;
		var tel;
		var opt1;
		var opt2;
		var opt_admin;
		var tel;
		if (document.getElementById('opt1').checked==true) {
			opt1="s";	
		} else {
			opt1="n";	
		}
		if (document.getElementById('opt2').checked==true) {
			opt2="s";	
		} else {
			opt2="n";	
		}
		
		nome=document.getElementById('nome').value; 
		email=document.getElementById('mail').value; 
		opt_admin=document.getElementById('opt_admin').value; 
		tel=document.getElementById('tel').value; 
		document.getElementById('dados_admin').value=nome + "*" + email + "*" + opt1 + "*" + opt2 + "*" + opt_admin + "*" + tel;
	} else {
		document.getElementById('dados_admin').value="****nao*";
	}
}

function opt_mail () {
	document.getElementById('opt_mail2').value=document.getElementById('opt_mail').value;
}

function promo_esc () {
	var nome
	nome=document.getElementById('a1').value;
	if (document.getElementById('c10').checked==true) {
		window.open("includes/includes7.php?page=subscrever/dados_escola&frame=feed_promo&nome=" + nome,"prov");
		document.getElementById('a1').disabled=true;
		document.getElementById('c1').disabled=true;
		document.getElementById('c2').disabled=true;
		document.getElementById('c3').disabled=true;
		document.getElementById('c4').disabled=true;
		document.getElementById('c5').disabled=true;
		document.getElementById('c6').disabled=true;
		document.getElementById('c7').disabled=true;
		document.getElementById('c8').disabled=true;
		document.getElementById('c9').disabled=true;
		document.getElementById('c1').checked="";
		document.getElementById('c2').checked="";
		document.getElementById('c3').checked="";
		document.getElementById('c4').checked="";
		document.getElementById('c5').checked="";
		document.getElementById('c6').checked="";
		document.getElementById('c7').checked="";
		document.getElementById('c8').checked="";
		document.getElementById('c9').checked="";
	} else {
		document.getElementById('feed_promo').innerHTML="";
		document.getElementById('a1').disabled=false;
		document.getElementById('c1').disabled=false;
		document.getElementById('c2').disabled=false;
		document.getElementById('c3').disabled=false;
		document.getElementById('c4').disabled=false;
		document.getElementById('c5').disabled=false;
		document.getElementById('c6').disabled=false;
		document.getElementById('c7').disabled=false;
		document.getElementById('c8').disabled=false;
		document.getElementById('c9').disabled=false;
	}
}

function twin_names (nome) {
	document.getElementById('a1').value=nome;
	document.getElementById('nome_esc').value=nome;
}

function carrega_concelho4 () {
	var distrito;
	distrito=document.getElementById('distrito').value
	window.open("../../includes/includes6.php?frame=feed_concelho&page=scripts/concelhos&distrito=" + distrito,"prov5");
	document.getElementById('escola').options.length = 0; 
}

function carrega_concelho6() {
	//var distrito;
	//distrito=document.getElementById('distrito').value
	alert ("ss");
	//window.open("../../includes/includes6.php?frame=feed_concelho&page=scripts/concelhos&distrito=" + distrito,"prov5");
}

function carrega_escolas () {
	var distrito;
	distrito=document.getElementById('distrito').value
	var concelho;
	concelho=document.getElementById('concelho').value
	window.open("../../includes/includes6.php?frame=feed_escolas&page=scripts/escolas&distrito=" + distrito + "&concelho=" + concelho,"prov5");
}

function carrega_concelho5 () {
	var distrito;
	distrito=document.getElementById('distrito').value
	window.open("includes/includes8.php?frame=feed_concelho&page=scripts/concelhos1&distrito=" + distrito,"prov");
	document.getElementById('escola').options.length = 0; 
}

function carrega_escolas1 () {
	var distrito;
	distrito=document.getElementById('distrito').value
	var concelho;
	concelho=document.getElementById('concelho').value
	window.open("includes/includes8.php?frame=feed_escolas&page=scripts/escolas&distrito=" + distrito + "&concelho=" + concelho,"prov");
}

function carrega_concelho3 () {
	var distrito;
	distrito=document.getElementById('distrito').value
	window.open("includes/includes.php?frame=feed_concelho&altura=0&page=scripts/concelhos3&distrito=" + distrito,"prov");
	document.getElementById('freguesia').options.length = 0; 
}

function carrega_escolas3 () {
	var distrito;
	distrito=document.getElementById('distrito').value
	var concelho;
	concelho=document.getElementById('concelho').value
	window.open("includes/includes8.php?frame=feed_escolas&page=scripts/escolas3&distrito=" + distrito + "&concelho=" + concelho,"prov");
}

function nova_escola () {
	var escola;
	escola=document.getElementById('nome_esc').value;
	if (escola=="0") {
		document.getElementById('feed_escolas').innerHTML='Digite o nome da Escola: 	<input type="text" class="box" style="width:295px" id="nome_esc" name="a1" onblur="twin_names(this.value);" />';		
	} else {
		document.getElementById('a1').value=document.getElementById('nome_esc').value;	
	}
}

function pagina_torneios (pagina,id_tor,mod,id_foto,voltar,escalao) {
	$.fn.colorbox({href:"includes/torneios_page/inicio.php?id_tor=" + id_tor + "&modalidade=" + mod + "&id_foto=" + id_foto + "&voltar=" + voltar + "&nome_escalao=" + escalao, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:pagina});
}

function pagina_torneios2 (pagina,id_tor,mod,id_foto,voltar,escalao) {
	$.fn.colorbox({href:"includes/gerir_torneio/inicio.php?id_tor=" + id_tor + "&modalidade=" + mod + "&id_foto=" + id_foto + "&voltar=" + voltar + "&nome_escalao=" + escalao, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Gestão do torneio ' + pagina});
}

function perfil_user (id_user,nome,id_tor,equipa,id_t,nome_t,voltar,escalao,id_jogador) {	
	$.fn.colorbox({href:"includes/perfil_user/perfil_user.php?id_user=" + id_user + "&nome=" + nome + "&id_tor=" + id_tor + "&equipa=" + equipa + "&id_t=" + id_t + "&nome_t=" + nome_t + "&voltar=" + voltar + "&escalao=" + escalao  + "&id_jogador=" + id_jogador, open:false, iframe:true, width:573, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500});
} 

function perfil_user3 (id_user) {	
	$.fn.colorbox({href:"includes/perfil_user/perfil_user3.php?id_user=" + id_user, open:false, iframe:true, width:573, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500});
} 

function perfil_user2 (id_user,nome,id_tor,equipa,id_t,nome_t,voltar,escalao,id_jogador) {	
	$.fn.colorbox({href:"includes/perfil_user/perfil_user2.php?id_user=" + id_user + "&nome=" + nome + "&id_tor=" + id_tor + "&equipa=" + equipa + "&id_t=" + id_t + "&nome_t=" + nome_t + "&voltar=" + voltar + "&escalao=" + escalao  + "&id_jogador=" + id_jogador, open:false, iframe:true, width:573, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500});
}


function perfil_equipa (id_user,nome,id_tor,equipa,id_t,nome_t,voltar,escalao,id_insc) {
	$.fn.colorbox({href:"includes/perfil_user/perfil_equipa.php?id_user=" + id_user + "&nome=" + nome + "&id_tor=" + id_tor + "&equipa=" + equipa + "&id_t=" + id_t + "&nome_t=" + nome_t + "&voltar=" + voltar + "&escalao=" + escalao + "&id_insc=" + id_insc, open:false, iframe:true, width:573, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Constituição da equipa'});
}

function perfil_equipa2 (id_user,nome,id_tor,equipa,id_t,nome_t,voltar,escalao,id_insc) {
	$.fn.colorbox({href:"includes/perfil_user/perfil_equipa2.php?id_user=" + id_user + "&nome=" + nome + "&id_tor=" + id_tor + "&equipa=" + equipa + "&id_t=" + id_t + "&nome_t=" + nome_t + "&voltar=" + voltar + "&escalao=" + escalao + "&id_insc=" + id_insc, open:false, iframe:true, width:573, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Constituição da equipa'});
}

function gerir_torneio (pagina,id_tor,modalidade,tipo_quadros) {
	$.fn.colorbox({href:"includes/gerir_torneio/inicio.php?id_tor=" + id_tor + "&modalidade=" + modalidade + "&tipo_quadros=" + tipo_quadros, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Gestão do torneio ' + pagina});
	
	//window.scroll(0,0);
	//ver_position=5;
	//var hor_position
	//hor_position=(screen.width/2)-505-18;
	//var win = new Window({className: "spread", title: "Gestão do torneio " + pagina, top:ver_position+1, left:hor_position, width:1010, height:600, url: "includes/gerir_torneio/inicio.php?id_tor=" + id_tor + "&modalidade=" + modalidade + "&tipo_quadros=" + tipo_quadros, showEffectOptions: {duration:1}})
	//win.refresh();
	//win.show();
	//win.toFront()
}

function gerir_inscricoes (pagina,id_tor) {
	$.fn.colorbox({href:"includes/gerir_inscricoes/inicio.php?id_tor=" + id_tor, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Gestão de inscrições no torneio ' + pagina});
}

function pagina_info (pagina) {	
		$.fn.colorbox({href:pagina, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Mais informações do torneio'});
}

function pagina_info2 (pagina) {
	$.fn.colorbox({href:pagina, open:false, iframe:true, width:1035, height:600, opacity:0.8, initialWidth:1, initialHeight:1, transition:'elastic', speed:500, title:'Regulamento do torneio'});
}