function CreateNewFolder(){
	$('#new_proyect div').toggle();
}
function CreateNewProyect(){$('#new_proyect div').toggle();}
function SendNewProyect(page){
folder_name = $('#nombre_proyecto').val();
	if (folder_name === '' || folder_name === undefined ){
	alert('Debes introducir un nombre para la carpeta de tu proyecto.');
	return false;
	}
	
	$.ajax({
	  type: "POST",
	  data: "nombre=" + folder_name + "&page=" + page, 
	  url: "/includes/create_folder.php",
	  dataType: "script"
	});	
	return false;
}
function ReloadFolders(){
el = $('#folder');
el.attr('disabled','true');
$.ajax({type: "GET",dataType: "html", url: "/includes/reload_folder.php", success: function(msg){
    el.html(msg);
	el.removeAttr("disabled");
	el.val(0);
  }});
}
function UpdateFolder(){
el = $('#folders');
selected_folder = $('#folder').val();
el.html('<img src="/images/folder_spinner.gif"/>');
$.ajax({type: "POST",dataType: "html", data: 'proyecto_id=' + selected_folder ,url: "/includes/folders.php", success: function(msg){
    el.html(msg);
  }});
	
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function Download(id){
	if (is_logged > 0 ){
	window.location.href = '/download.php?id='+id;
	}else{
	OpenLogin();
	}
	return false;
}
function Delete(id, estado){
	if (!estado){
		alert('Este archivo ya fue eliminado y se encuentra en el purgatorio');
	return false;	
	}
	if (is_logged > 0 ){
			if (confirm("Seguro que desea eliminar archivo?")) {
			window.open('delete.php?id='+id);
			}
	
	}else{
	window.location.href='/login.php';
	}
	return false;
}


function DeleteEntrie(type,id){
	if (!confirm("Seguro que desea eliminar este "+ type +"?")) {
	return false;
	}
	id = parseInt(id);
	if (type === '' || type === undefined || id == 0 ){
		return false;
	}
	data = "type=" + type + "&id=" + id;
	$.ajax({
	  type: "POST",
	  data: data, 
	  url: "/includes/delete_entrie.php",
	  dataType: "script"
	});	
	return false;
}

function ChangeFileFolder(page){
c = 0;
files_id = ''; 
v = $('#folder_2').val();
$("#subidos input[@type='checkbox']").each(function() {if (this.checked ){c = c + 1 ;files_id = files_id +  ',' + this.value;}});
if (c == 0){alert('Debes seleccionar archivo');return false;}
if (v === ''){alert('Debes selecciona una carpeta');return false;}
data = "new_id=" + v + "&files_id=" + files_id+ "&page=" + page;
//alert(data);
$.ajax({
	  type: "POST",
	  data: data, 
	  url: "/includes/move_files.php",
	  dataType: "script"
	});	
return false;
}

function OpenAdvanced(){
e = $('#advanced');	
	if (e.css('display') == 'none'){
			if (e.html().length < 100){
			e.show();
	$.ajax({type:"GET",dataType:"html",url:"/includes/advanced.php",success:function HandleFormResponde(msg){separador=msg.indexOf('|');layer=msg.substring(0,separador);contenido=msg.substring(separador+1,msg.length);$('#'+layer).html(contenido);}})	
			}else{
			e.slideDown("slow");
			}
	
	}else{
	e.slideUp("slow");
	}
	return false;
}
function Reply(id){
$('#pedido_id').val(id);	
window.location.hash = 'comments';
$('#comentario').val('RE: Pedido @'+id+" - ");
$('#comentario').focus();
}
function CommentChange(){
	v = $('#comentario').val();
	if (v == ''){
		$('#pedido_id').val(0);
	}
}
function SendComment(){
	desc=$('#comentario').val();proyecto_id=$('#proyecto_id').val();if(desc!=''){
		$('#send_comment').attr('disabled',true).attr('value','Enviando');;
		$.ajax({type:"GET",dataType:"html",url:"/add_comment.php?desc="+desc+'&proyecto_id='+proyecto_id,success:function HandleFormResponde(msg){separador=msg.indexOf('|');layer=msg.substring(0,separador);contenido=msg.substring(separador+1,msg.length);$('#'+layer).prepend(contenido);$('#send_comment').attr('value','Enviar').removeAttr("disabled");
		  $('#comentario').val('');}})}else{alert("Debes ingresar un comentario")}return false}

function SendComment2(){
	desc=$('#comentario').val();user_id=$('#user_id').val();if(desc!=''){
		$('#send_comment').attr('disabled',true).attr('value','Enviando');;
		$.ajax({type:"GET",dataType:"html",url:"/add_post.php?desc="+desc+'&user_id='+user_id,success:function HandleFormResponde(msg){separador=msg.indexOf('|');layer=msg.substring(0,separador);contenido=msg.substring(separador+1,msg.length);$('#'+layer).prepend(contenido);$('#send_comment').attr('value','Enviar').removeAttr("disabled"); 
																																																																																		
		  $('#comentario').val('');}})}else{alert("Debes ingresar un comentario")}return false}
		
function SendPedido(){
	desc=$('#comentario').val();
	pedido_id = parseInt($('#pedido_id').val());
	if(desc!=''){
		$('#send_comment').attr('disabled',true).attr('value','Enviando...');;
		data = "pedido_id="+pedido_id+"&desc="+desc;
		$.ajax({type:"POST",dataType:"html",url:"/add_pedido.php",data:data,success:function HandleFormResponde(msg){separador=msg.indexOf('|');layer=msg.substring(0,separador);contenido=msg.substring(separador+1,msg.length);$('#'+layer).prepend(contenido); $('#send_comment').attr('value','Dejar Pedido').removeAttr("disabled"); if (pedido_id > 0 ) { window.location.hash = 'respuestas_'+pedido_id; }
		  $('#comentario').val('');}})}else{alert("Debes ingresar un comentario")}return false}
		
		
		function SetFileType(value){value=parseInt(value);$('#tipo_archivo_id').attr('value',value);$('#upload_box dl div').show();$('#input_otro_tipo_id').hide();$('#input_lyric').hide();if(value==3){$('#input_generos').hide('slow');$('#input_tempo').hide('slow')}if(value==4){$('#input_generos').hide('slow');$('#input_instrumentos').hide('slow');$('#input_tempo').hide('slow');$('#input_otro_tipo_id').show('slow')}$("#upload_box .con a").each(function(i){$(this).css('opacity',.5);if(i==0&&value==5){$(this).css('opacity',1)}if(i==value){$(this).css('opacity',1)}})}
		
		
		function OnChangeType(){
v = $('#otro_tipo_id').val();
	if (v == 1){
		$('#input_file').hide();
		$('#input_lyric').show('slow');
		$('#subir_label').hide();
		$("*[@type='submit']").show();
	}
	if (v == 2){
		$('#subir_label').show();
		$('#input_file').show();
		$('#input_lyric').hide('slow');
		
	}
}
		