var zIndex = 3000;
function formatData(name, precio, stock, rank, cat, irank, istock, iupdown, i, devolucion) {
	var url 		= 'http://www.appinformatica.com/'+GetURL(getCategoStr(cat) +' '+ name)+'.php',
		img			= 'http://www.appinformatica.com/'+GetURL(getCategoStr(cat) +' '+ name)+'.jpg',
		catUrl		= 'http://www.appinformatica.com/'+GetURL(getCategoStr(cat))+'.htm',
		iStrRank 	= 'http://www.appinformatica.com/imf-dis/rs-stars'+irank+'.gif',
		iStrStock 	= 'http://www.appinformatica.com/imf-dis/stocks'+istock+'.gif',
		devImg		= '',
		strRank 	= '';

	switch(iupdown) {
	case 0:
	case 1: strRank = rank+' <a href="#" onmouseout="rmvHint(this);" onmouseover="highOnOver(this);" onclick="getHint(4, 0, this); retrun false;"><img src="'+iStrUpdown+'" border="0" width="7"  height="8"></a>'; break;
	case 2: strRank = ' <a href="#" onmouseout="rmvHint(this);" onmouseover="highOnOver(this);" onclick="getHint(4, 0, this); retrun false;"><img src="/imf-list/nuevo-java.gif" border="0" width="47"  height="10"></a>'; break;
	case 3: strRank = ' <a href="#" onmouseout="rmvHint(this);" onmouseover="highOnOver(this);" onclick="getHint(4, 0, this); retrun false;"><img src="/imf-list/oferta-java.gif" border="0"></a>'; break;
	case 4: strRank = ' <a href="#" onmouseout="rmvHint(this);" onmouseover="highOnOver(this);" onclick="getHint(4, 0, this); retrun false;"><img src="/imf-list/outlet-java.gif" border="0"></a>'; break;
	}

	var newSrc = '';
	var newAlt = '';
	var newTpe = -1;

	/*Pregunto si es outlet*/
	if (iupdown == 4) {
		newSrc = '/imf-dis/outlet.png';
		//newAlt = 'outlet!!';
		newTpe = 6;
	}

	/*Pregunto si es oferta*/
	if (iupdown == 3) {
		newSrc = '/imf-dis/oferta-hasta.png';
		//newAlt = 'OFERTA!!';
		newTpe = 0;
	}

	/*Pregunto si es nuevo y no es 4..5 estrellas*/
	if ( (iupdown == 2) ) {
		newSrc = '/imf-dis/rs-nuevo.png';
		//newAlt = 'ARTICULO NUEVO!!';
		newTpe = 1;
	}

	if ((irank == 9) && (iupdown < 3)) {
		newSrc = '/imf-dis/rs-top-ventas.png';
		//newAlt = 'TOP VENTAS APP!!';
		newTpe = 2;
	}

	/*Pregunto si es Top1 y no es oferta*/
	var top = getTopList(articulos);
	if ( (top.descripcion == name) && (iupdown < 3) && (irank != 9) ) {
		newSrc = '/imf-dis/rs-n1.png';
		//newAlt = 'ARTICULO MAS VENDIDO!!'
		newTpe = 3;
	}

	if ((irank == 10) && (iupdown < 3)) {
		newSrc = '/imf-dis/rs-premiado-super-ventas.png';
		//newAlt = 'PREMIADO APP!!';
		newTpe = 4;
	}
	
	

//~

    //~ Desde 0,0% al 0,9% ... verde luminoso.
    //~ Desde 1,0% al 1,9% --- amarillo
    //~ Desde 2,0% al 2,9% --- naranja
    //~ Desde 3,0% al 9,9% --- rojo tomatón
	var simbolo = '%';

	if (devolucion != 88) {
			 if (devolucion > 3) {
								 devImg = '/imf-dis/semaforo-rojo.gif';
								 newSrc = '/imf-dis/rma-alto.png';
								 newAlt = 'RMA Alto';
								 newTpe = 5;

		}
		else if (devolucion > 2) devImg = '/imf-dis/semaforo-naranja.gif';
		else if (devolucion > 1) devImg = '/imf-dis/semaforo-amarillo.gif';
		else 					 devImg = '/imf-dis/semaforo-verde.gif';

		devolucion = fmtMoney(devolucion, 1, ",", '.');
	} else {
		devolucion = 'S/D';
		simbolo = '';
		devImg = '/imf-dis/semaforo-gris.gif';
	}

	switch(iupdown) {
		case 1: var iStrUpdown = '/imf-dis/baja.gif'; break;
		default: var iStrUpdown = '/imf-dis/sube.gif';
	}


	var precioFmt = precio.replace(/([0-9.]*),([0-9]*)/g, "$1<span class=\"sup\">,$2</span>");
	var nameFmt = adjust_text(name, 25);

	var premioHolder = (newSrc != '') ? '<a href="#"  onmouseover="highOnOver(this);" onmouseout="rmvHint(this);" onclick="getHint(0, '+newTpe+', this);return false;" class="premioOver"><img border="0" src="'+newSrc+'" alt="'+newAlt+'" title="'+newAlt+'" /></a>' : '';

	var html = '';

	html =
				//'<a class="link_iconos" href="/iconos.htm" target="_blank">'+



					'<div class="stkdevHolder">'+
						'<div class="stock">Stock:&nbsp;&nbsp;&nbsp;<span class="blu">'+stock+'</span> unid <img border="0" src="'+iStrStock+'" /></div>'+
						//'<a class="devolOver" href="#" target="_blank" onmouseover="highOnOver(this);" onclick="getHint(3, 0, this);return false;" onmouseout="rmvHint(this);">&nbsp;</a>'+
						'<div class="devolucion">Devoluci&oacute;n:&nbsp;&nbsp;&nbsp;<span class="blu">'+devolucion+'</span>'+simbolo+'&nbsp;&nbsp;<img border="0" src="'+devImg+'" alt="" /></div>'+
					'</div>'+

					//'<a class="rankOver" href="#" target="_blank" onmouseover="highOnOver(this);" onclick="getHint(2, 0, this);return false;" onmouseout="rmvHint(this);">&nbsp;</a>'+
					'<div class="topRankHold">'+
						'<div class="topVentas">Top: <img border="0" src="'+iStrUpdown+'" />&nbsp;&nbsp;<span class="blu">'+rank+'</span></div>'+
						'<div class="ranking"><img border="0" src="'+iStrRank+'" /></div>'+
					'</div>'+
				//'</a>'+
				'<div class="tarjBodyHolder">'+
					//'<div class="relHolder">'+
						'<div class="premioHolder">'+premioHolder+'</div>'+
						'<div class="globoPrecio clearfix">'+
							//'<div class="iva">IVA Inclu&iacute;do</div>'+
							'<div class="precio">'+precioFmt+'</div>'+
							'<div class="bordeDer"></div>'+
						'</div>'+
						'<div class="imageHolder">'+
							'<img usemap="#mapImg'+i+'" border="0" src="'+img+'" alt="'+name+'" title="'+name+'" />'+
							'<map name="mapImg'+i+'">'+
								'<area shape="rect" coords="0,120,70,134" href="'+catUrl+'" target="_blank">'+
								'<area shape="rect" coords="0,0,219,119" href="'+url+'" target="_blank">'+
								'<area shape="rect" coords="69,118,219,134" href="'+url+'" target="_blank">'+
							'</map>'+
						'</div>'+
					//'</div>'+
				'</div>'+
				'<div class="descr"><a href="'+url+'" target="_blank">'+nameFmt[0].toUpperCase()+'<br />'+nameFmt[1].toUpperCase()+'</a></div>'+

				'<a class="stockOver" href="#" target="_blank" onmouseover="highOnOver(this);" onclick="getHint(1, '+newTpe+', this);return false;" onmouseout="rmvHint(this);">&nbsp;</a>'+
				 '<a class="rankOver" href="#" target="_blank" onmouseover="highOnOver(this);" onclick="getHint(2, 0, this);return false;" onmouseout="rmvHint(this);">&nbsp;</a>'+
				 '<a class="devolOver" href="#" target="_blank" onmouseover="highOnOver(this);" onclick="getHint(3, 0, this);return false;" onmouseout="rmvHint(this);">&nbsp;</a>'

				;

	var div = document.createElement('div');
	div.className = 'tjArt';
	div.innerHTML = html;
	//div.style.zIndex = zIndex - i;

	return div;
 }

function highOnOver(hldrOb) {
	hldrOb.className = hldrOb.className + ' highred';
}


var timer = 0;
function getHint(hntType, hntCode, hldrOb) {

	el = document.getElementById('hint');
	/*if (timer != 0 && el != null) {
		el.parentNode.removeChild(el);
		clearTimeout(timer);
	}*/
	if (el != null) {
		el.parentNode.removeChild(el);
	}

	var txt, tit, cn, hldr, html, top, left;
	var arr = 'arrLeft', flt = 'left';

	//var el = hldrOb.parentNode;

	//if (hntType != 0) hldrOb.className = hldrOb.className + ' highred';
	var rightForLink = 30;
	switch(hntType) {
		case 0: //Premio Hint

				switch (hntCode) {
					case 0:
							tit = 'SUPER OFERTA';
							txt = '&iexcl;Aprov&eacute;chate! ;-)';
							w	= 143;
							break;	//oferta
					case 1:
							tit = 'Art&iacute;culo Nuevo';
							txt = 'Este art&iacute;culo es nuevo en la web de APP.';
							w	= 165;
							break;	//nuevo
					case 2:
							tit = 'Top Ventas';
							txt = 'Este producto esta entre el Top Ventas 101 y el Top Ventas 240 de APP.';
							w	= 193;
							break;	//top
					case 3:
							tit = 'N&ordm; de su Familia';
							txt = 'Este es el producto m&aacute;s vendido de su grupo.';
							w	= 165;
							break;	//topsold
					case 4:
							tit = 'Super Ventas';
							txt = 'Este producto forma parte de los 100 pro- ductos m&aacute;s vendidos de APP.';
							w 	= 175;
							break;	//premiado
					case 5:
							tit = 'RMA Alto';
							txt = 'Indica que este art&iacute;culo tiene un <u>porcentaje alto de devoluci&oacute;n</u> por estar estropeados en su periodo de garant&iacute;a.';
							w 	= 190;
							break;	//high RMA
					case 6:
							tit = 'OUTLET';
							txt = 'Outlet';
							w 	= 190;
							break;	//OUTLET
				}
				top = 30;
				left = - (w + 20);
				break;
		case 1:
				tit = 'Stock';
				txt = 'Indica el n&uacute;mero total de unidades, en tiempo real, que disponen los almace- nes centrales de APP.';
				w = 196;
				left = - (w + 20);
				top = -31;
				break;	//Stock Hint
		case 4:
		case 2:
				tit = 'Top Ventas';
				txt = 'Este dato indica que productos son los m&aacute;s vendidos. <br /> El Top Ventas es un n&uacute;mero entre 1 y 4.500 donde el N&ordm;1 es el m&aacute;s vendido. <br />  Las estrellas son una representa- ci&oacute;n gr&aacute;fica de dicho dato.';
				w 	= 258;
				left = (w - 50);
				top = -21;
				arr = 'arrRight';
				flt = 'right';
				//rightForLink = 9;
				break;	//Stars Hint

		case 3:
				tit = 'Devoluci&oacute;n';
				txt = 'El porcentaje de devoluci&oacute;n (% RMA) indica que porcen- taje de este producto es devuelto a las tiendas de APP por estar estropeados en su per&iacute;odo de garant&iacute;a.';
				w = 208;
				left = - (w + 20);
				top = -11;
				break;	//Devol Hint
	}



	wwidth = mwidth = w + 'px;';

	html = document.createElement('div');
	html.id = 'hint';
	html.className = 'premioHint';
	html.innerHTML = ''+
	'<div style="position:absolute; '+flt+':0px; width: '+(w+8)+'px">'+
		'<div class="top clearfix">'+
			'<div class="l" style="width: '+wwidth+';">&nbsp;</div>'+
			//'<div class="r"><img border="0" src="/images/bocadillo-close.png" alt="Cerrar" title="Cerrar" /></div>'+
			'<div class="r"></div>'+
		'</div>'+
		'<div class="rmiddle" style="width: '+(w+5)+'px">'+
			'<div class="middle" style="width: '+mwidth+';">'+
				'<div class="text">'+
					'<div class="title">'+tit+'</div>'+
					'<div class="p">'+txt+'</div>'+
					'<a href="http://www.appinformatica.com/iconos.htm" class="masinfolink" style="right: '+rightForLink+'px;" target="_blank">M&aacute;s Informaci&oacute;n</a>'+
				'</div>'+
				'</div>'+
		'</div>'+
		'<div class="bottom clearfix">'+
			'<div class="l" style="width: '+wwidth+';">&nbsp;</div>'+
			'<div class="r" >&nbsp;</div>'+
		'</div>'+
		'</div>'+
	'<a href="#" onclick="delHint(); return false;" class="arrClose a'+arr+'">X</a>'+
	'<div class="'+arr+'">&nbsp;</div>';


	//var pos = hldrOb.cumulativeOffset();
	e = getTjAncestor(hldrOb);

	off = $(e).viewportOffset();
	html.style.left = off[0] + left + 'px';
	html.style.top = off[1] + top + 'px';
	html.style.width = w + 30 + 'px';

	document.getElementsByTagName('body')[0].appendChild(html);

	/*highHtml = document.createElement('div');
	highHtml.id = 'highred';
	highHtml.innerHTML = '&nbsp;';
	highHtml.href = "/iconos.htm";
	highHtml.style.left  = hl + "px";
	highHtml.style.top 	 = ht + "px";
	highHtml.style.width = hw + "px";
	highHtml.style.height= hh + "px";*/


	//timer = setTimeout("delHint();", 4000);
	//e.appendChild(highHtml)
}

function delHint() {
	el = document.getElementById('hint');

	if (el != null) {
		el.parentNode.removeChild(el);
	}
}


function rmvHint(ob) {
	//el = document.getElementById('hint');
	if (ob != null) {
		//ob.parentNode.removeChild(el);
		ob.className = ob.className.replace("highred", '');
	}
}

function getTjAncestor(e) {
	cname = '';
	do{
	cname = e.parentNode.className;
	e = e.parentNode;
	} while (cname != 'tjArt')
	return e;
}
