function combo_seleccion(id,retorna){
var posicion=document.getElementById(id).options.selectedIndex;
if(retorna=='id'){
return document.getElementById(id).options[posicion].id;
}else if(retorna=='valor'){
return 	document.getElementById(id).options[posicion].text;
}
}
$pos=0;
$postop=0;
$alto_control=0;
function ampliar_caja(inicio_alto,inicio_ancho,alto,ancho,id){
var cuenta=document.getElementById('caja_cuenta');

if(!cuenta){
	var a=document.createElement('div');
	a.setAttribute('id','caja_cuenta');
	a.style.width='20px';
	a.style.position='absolute';
	a.style.height='20px';
	a.style.border='1px solid #999';
	a.style.background='#FFF';
	a.style.padding='4px';
	a.style.borderRadius='4px';
	a.style.overflow='hidden';
	a.style.zIndex=10;
	$pos_=Position(id);
	$pos=$pos_.left;
	$postop=$pos_.top;
	a.style.top=($pos_.top)+'px';
	a.style.left=$pos+'px';
	document.body.appendChild(a);
	$pos_real=$pos+100;
$crecimiento=ancho/alto;	
$crecimiento_aux=$crecimiento;
$posicion=$pos_real/alto;
intervalo1=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo2=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo3=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo4=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo5=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo6=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo7=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
intervalo8=setInterval(function(){ampliar_caja(inicio_alto,inicio_ancho,alto,ancho);},1);
$('#caja_cuenta').css({'opacity':0});
$('#caja_cuenta').fadeTo('slow',1);
}
if(cuenta){
	if($alto_control<alto){
		cuenta.style.height=$alto_control+'px';
		$alto_control++;
		cuenta.style.width=$crecimiento+'px';
		$crecimiento=$crecimiento_aux+$crecimiento;
		cuenta.style.left=$pos+'px';
		cuenta.style.top=$postop+'px';
		$postop=$postop-0.4;
		$pos=$pos-0.4;
		
		
			
	}else{
		clearInterval(intervalo1);
		 clearInterval(intervalo2);
		  clearInterval(intervalo3);
		   clearInterval(intervalo4);
		    clearInterval(intervalo5);
			clearInterval(intervalo6); clearInterval(intervalo7);
		clearInterval(intervalo8);
		$pos=0;
		$postop=0;
		}
}
}
function cuenta_detalles(alto,ancho,id,$t_datos,$dato){
$pos=0;
$alto_control=0;
if(document.getElementById('caja_cuenta')){ sacar('caja_cuenta'); }
switch($t_datos){
case 'preview':
ampliar_caja(0,0,alto,ancho,id);
document.getElementById('caja_cuenta').innerHTML="<div style='width:100%; height:19px; float:left;'><input type='button' style='float:right; width:15px; height:18px;' class='close' value='x' onclick=\"sacar(\'caja_cuenta'\);\"></div><div id='cuenta_detalles' style='float:left; width:100%; padding:2px; text-align:center;'></div>";	
mostrar('preview.php',document.getElementById('cuenta_detalles'),"?id="+$dato,'');
break;
case 'users':
ampliar_caja(0,0,alto,ancho,id);
document.getElementById('caja_cuenta').innerHTML="<input type='button' style='float:right; width:15px; height:18px;' class='close' value='x' onclick=\"sacar(\'caja_cuenta'\);\"><div id='cuenta_detalles' style='float:left; width:100%; padding:2px;'></div>";	
break;
case 'faq':
ampliar_caja(0,0,alto,ancho,id);
document.getElementById('caja_cuenta').innerHTML="<input type='button' style='float:right; width:15px; height:18px;' class='close' value='x' onclick=\"sacar(\'caja_cuenta'\);\"><div id='cuenta_detalles' style='float:left; width:100%; padding:2px;'></div>";	
mostrar('faq.php',document.getElementById('cuenta_detalles'),"?id="+$dato,'');
break;
}
}
function Position(element) {
if (typeof element == "string")
element = document.getElementById(element)

if (!element) return { top:0,left:0 };

var y = 0;
var x = 0;
while (element.offsetParent) {
x += element.offsetLeft;
y += element.offsetTop;
element = element.offsetParent;
}
return {top:y,left:x};
}
function sacar(id){if(id=='Fondo'){ sacar('Caja'); $('Fondo').parentNode.removeChild($('Fondo'));}else{document.getElementById(id).parentNode.removeChild(document.getElementById(id)); } }

function mostrar(url,contenid,dato,callback){
var preloader = document.createElement('div');
preloader.setAttribute('id','preloader');
preloader.style.position="absolute";
preloader.style.left="40%";
preloader.style.top="200px";
preloader.style.width="100px";
preloader.style.height="100px";
preloader.style.zIndex=15;
document.body.appendChild(preloader);
var ajax=nuevoajax();
switch(url){
case "preview.php": ajax.open("POST", url+dato,true); break;
case "faq.php": ajax.open("POST", url+dato,true); break;
case "register.php": ajax.open("POST", url+dato,true); break;
case "recuperar.php": ajax.open("POST", url+dato,true); break;
case "downloads_list.php": if(dato=='send'){ //$combo=combo_seleccion('tipo','valor');
  ajax.open("POST", url+"?artist="+document.getElementById('artist_input').value+"&order=date"+callback,true); 
}else{ ajax.open("POST", url+dato,true);
 } break;
case "downloads.php": if(dato=='send'){ $combo=combo_seleccion('tipo','valor');  ajax.open("POST", url+"?artist="+document.getElementById('artist_input').value+"&song="+document.getElementById('song').value+"&order="+$combo,true); }else{ ajax.open("POST", url+dato,true); } break;
}
ajax.onreadystatechange=function(){
if(ajax.readyState==1){
document.getElementById('preloader').innerHTML = "<img src='images/cargando.gif' />";
//modificamos el estilo de la div, mostrando una imagen de fondo
}else if(ajax.readyState==4){
if(ajax.status==200){
//mostramos los datos dentro de la div

contenid.innerHTML = ajax.responseText;
}else if(ajax.status==404){
preloader.innerHTML = "La página no existe";
}else{
//mostramos el posible error
preloader.innerHTML = "Error:".ajax.status;
}
}
}
ajax.send(null);
document.body.removeChild(document.getElementById("preloader"));
}
function nuevoajax(){
if (window.XMLHttpRequest){
	return new XMLHttpRequest();
}
else if(window.ActiveXObject){
	var versionesObj = new Array(
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP');
	for (var i = 0; i < versionesObj.length; i++)
	{
	try
	{
return new ActiveXObject(versionesObj[i]);
}
catch (errorControlado) //Capturamos el error, ya que podría crearse otro objeto.
{
}
}
}
throw new Error("No se pudo crear el objeto XMLHttpRequest");
}
function enter(evento,darfoco){
	var keyCode = evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode;
if (keyCode == 13) {
	darfoco.focus();
}
}

function colorear(v,el){
	if(v=='no visto'){
		el.style.border='1px solid #F30';
		el.style.height=49+'px';

	}else if(v=='visto'){
		el.style.border='1px solid #70DC50';
		el.style.height=49+'px';

	}else{ el.style.border='0px'; el.style.height='50px'; }
}
