/*********************************************************************/
/*                                                                   */
/*               SCRIPT DE PREVISUALIZACION DE MultiPANDOs           */
/*                             para SMF                              */
/*                                                                   */
/*********************************************************************/
/*                 Programado por elprofesional007                   */
/*                                                                   */
/*                                                                   */
/*    Si quieres usarlo, contacta con elprofesional007@gmail.com     */
/*                                                                   */
/*********************************************************************/
/* seleccionar focus */
function capturar(field) {
        document.getElementById(field).focus()
        document.getElementById(field).select()
        
}

/* Pop-up para el boton goodies */
function goodies()
{
window.open('/UserFiles/goodies.html', 'muestraVentana',
'width=750, height=500, menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes')
}
/* funciones para precargar imagenes para el onmouseover y onmouseout, colocando 2 imagenes en la carpeta mpando*/
function activar(nombreImagen,id) {
if (document.images) {
var nombre = nombreImagen+'-'+id;
document[nombre].src="/Sources/mpando/"+nombreImagen+"_over.gif"; }
}
function desactivar(nombreImagen,id) {
var nombre = nombreImagen+'-'+id;
if (document.images) {
document[nombre].src="/Sources/mpando/"+nombreImagen+".gif"; }
}

/* aqui empieza el script mpando */
var package_out = new Array ();
var package_count = 0;

function mprintPackageCallBack(packageInfo) {
	// cuando el packageInfo nos envie el dato de expired, aqui esta la orden necesaria
  //var jodido = packageInfo['expired'];
// por el momento damos valor a mano como true, ya que el packageInfo no recoge ese dato
var jodido = true;
	//Tamaño
	var size = packageInfo['packageSize'] / 1024 / 1024;
	size = Math.round(size * 100) / 100;
	if (size < 1000) {
		size = size + ' MB';
	} else {
		size = Math.round([size / 1024] * 100) / 100 + ' GB';
	}
	//Get number of days till expiration (negative = expirado)
	var days = Math.round( (new Date(packageInfo['expirationDate']) - new Date()) / 86400000);
	//store expiration status
	var expirado = (days >= 0) ? 0 : 1;
	//use absolute values of days for a readable string
	days = Math.abs(days);
	//get title from package info
	var title = packageInfo['title'];
	//¿Titulo muy largo?
	if (title.length > 46) {
		title = title.substring(0,27) + '...' + title.substring(46,64);
	}
	//generate img tag with thumbnail from package info
	var thumb = "<img src='"+ packageInfo['thumbnailURL'] +"' alt='' />";
	//generate anchor tag from package URL; assumes packageKey is set
	var packageA = "<a href='" + PandoAPI.getPackageURL(packageId,packageKey) + "&tt=S2W'>";
	//get appropriately pluralized X day(s) string
	var daystring = days +' d&iacute;a'+ ( (days > 1) ? ('s') : ('') );	
	//get # of downloads from package info
	var dl = packageInfo['downloads'];
	//if package is not expirado, link the title and thumbnail to the package URL
	//  and set the expiration days string accordingly
// mostrar propiedades del packageInfo
// for (var prop in packageInfo) 
//		document.write(prop+': <em>'+packageInfo[prop]+'</em><br/>'); 

	if(!expirado) {
		title = packageA + title + '</a>';
		thumb = packageA + thumb + '</a>';
		dias = ''+ daystring +'';
	}
  	else if (jodido == true){
		dias = 'NO DISPONIBLE'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
	}
   else  {
			dias = 'Nunca expira';
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
		}
	//otherwise, do not link the title/thumbnail, and set expiration string accordingly


	//generate human-friendly Downloaded X times / Never Download string
	if(dl > 0)
		dlstring = '<strong>'+dl+'</strong> '+( (dl > 1) ? ('descargas') : ('descarga') );
	else
		dlstring = 'Nunca descargado';
	//El que lo sube
	var uploader = packageInfo['packager'];
		
//	package_out[package_count] = '<table class="mpandopackage"><tr><td class="mpackagethumb" valign="top"><img src="/Themes/niceblue2/images/post/pando.gif" alt="Pando"></td><td valign="top" class="mpackagemeta1"><span class="mptitle"><abbr title="'+ packageInfo['title'] + '">' + title +'</abbr></span></td><td valign="top" class="mpackagemeta">'+ uploader +'</td><td valign="top" class="mpackagemeta">'+ dias +'</td></tr><tr><td valign="top" class="mpackagemeta">&nbsp;</td><td valign="top" class="mpackagemeta">'+ size + '</td><td valign="top" class="mpackagemeta">' + dlstring + '</td></tr></table>';
package_out[package_count] = '<table class="cajarapid"  border="0"><tr width=100%><td class="icono"><img src="/Themes/niceblue2/images/post/pando.gif" alt="Pando" /><td><td class="nombre"><abbr title="'+ packageInfo['title'] + '">' + title +'</abbr></td><td class="tamano">'+ uploader +'|'+ size + '|' + dlstring + '</td><td class="disponibilidad">'+ dias +'</td><tr></table>';	
		document.write(package_out[package_count]);
}
function mparsePandoUrl(url) {
  var parts = url.split('?',2);
  var args = parts[1];
  parts = args.split('&amp;');
  for(var i=0; i<parts.length; i++) {
    if(parts[i].match(/^id=[A-Z0-9]*/))
      packageId = parts[i].substring(3);
    if(parts[i].match(/^key=[A-Z0-9]*/))
      packageKey = parts[i].substring(4);			
  }
}
function mshowPackage(url) {
  parsePandoUrl(url);
  PandoAPI.getPackageInfo(packageId,mprintPackageCallBack,packageKey);
  package_count++
}


