// JavaScript Document
	x=0;
	verif_down = new Array();
	var n, d2, t2, c2, n, d2, t2, c2, verif_down2, verif_cat2, verif_tit2, id, first_index, num_id, down_antigo;
	var v=0;
	
	function abre_editar(cat, cat2, tit, tit2, down, down2)
	{
	
	
			for(n in verif_down)
			{
				
				if(verif_down[n] == down)
				{
				

					document.getElementById(cat2).style.display= "none";
					document.getElementById(tit2).style.display= "none";
					document.getElementById(down2).style.display= "none";
					document.getElementById(cat).style.display = "";
					document.getElementById(tit).style.display = "";
					document.getElementById(down).style.display = "";
					verif_down[down] = '';
					x = 1;
					break;
				
				}
				else
				{
					x = 0;
				
				}
			
			}

			if(x == 0)
			{
			
				document.getElementById(cat2).style.display = "";
				document.getElementById(tit2).style.display = "";
				document.getElementById(down2).style.display = "";
				document.getElementById(cat).style.display = "none";
				document.getElementById(tit).style.display = "none";
				document.getElementById(down).style.display = "none";
				verif_down[down] = down;
				
			}
	}
	
	
	function altera_link()
	{
		
		con = confirm("Tem certeza que deseja fazer essas alterações?");
		if(con == true)
		{
			for(n in verif_down)
			{
		
				id = verif_down[n];
				first_index = id.indexOf("0");
				num_id = id.slice(first_index+1);
				down_antigo += document.getElementById("down0"+num_id).innerHTML+"|";
				verif_down2 += document.getElementById("down20"+num_id).value+"|";
				verif_cat2 += document.getElementById("cat20"+num_id).value+"|";
				verif_tit2 += document.getElementById("tit20"+num_id).value+"|";
		
			}
			
			verif_down2 = verif_down2.slice(9);
			verif_cat2 = verif_cat2.slice(9);
			verif_tit2 = verif_tit2.slice(9);
			down_antigo = down_antigo.slice(9);
			document.cookie="download = "+verif_down2;
			document.cookie="categoria = "+verif_cat2;
			document.cookie="titulo = "+verif_tit2;
			document.cookie="download_antigo ="+down_antigo;
			
		}
		else
		{
		
			return false;
		
		}
		
	}
	
	function remover_link()
	{
		rem = confirm("Tem certeza que deseja remover o link?");
		if(rem == true)
		{
		
			for(n in verif_down)
			{
		
				id = verif_down[n];
				first_index = id.indexOf("0");
				num_id = id.slice(first_index+1);
				down_antigo += document.getElementById("down0"+num_id).innerHTML+"|";
		
			}
			
			down_antigo = down_antigo.slice(9);
			document.cookie="download_remover ="+down_antigo;
			
		}
		else
		{
		
			return false;
		
		}
		
	}
	
	function add_link()
	{
	
		num_down = prompt("Quantos downloads você quer adicionar?(maximo: 15 arquivos)");
		if(num_down <= 15 && num_down > 0)
		{
		
				document.cookie="num_links ="+num_down;
				//document.getElementById("upload").innerHTML += "<form name='upload_files' method='POST' enctype=\"multipart/form-data\" action='bd/envia_banco.php'>";
				for(i=0; i<num_down; i++)
				{

					document.getElementById("upload").innerHTML += "<span id='upload"+i+"'><br /><hr /><br /><label for='text'>Categoria: </label><br /><input type='text' name='new_cat"+i+"'><br /><label for='text'>Título: </label><br /><input type='text' name='new_tit"+i+"'><br /><label for='new_download"+i+"'>Arquivos: <label><br /><input type='file' name='new_download"+i+"' id ='new_download"+i+"' /><br /><br /><center><input type='button' name='cancela_file' id='cancela_file' value='Cancelar' onClick=\"return cancelar_file('"+i+"', '"+num_down+"')\" /></center></span>";
					
				}
				document.getElementById("upload").innerHTML += "<span id='enviar'><br /><br /><br /><center><input type='submit' name='enviar_download' id='enviar_download' value='Enviar tudo' /></center></span>";
				//document.getElementById("upload").innerHTML += "</form>";
			
			
		}
		else if(num_down <= 0)
		{
			
			return false;

		}
		else
		{
		
			alert("Você só pode adicionar 15 arquivos por vez!");
			return false;
		
		}
	
	}
	
	function cancelar_file(n, num_down)
	{
			
			document.getElementById("upload"+n).innerHTML = "";
			v++;
			if(v == num_down)
				document.getElementById("enviar").innerHTML = "";
	}
