alturaCelda = 15;

function revSub(id) {
	window.open('','rev','width=420,height=320');
	rF = document.getElementById('revForm'+id);
	rF.target='rev';
	rF.submit();
	shD(id);
}

function shR(id) {
//Shows opinions for this newspaper
	objById('opnSpan'+id).className = 'ls_optFG';
	objById('detSpan'+id).className = 'ls_optBG';

	dest = document.getElementById('body'+id);
	dest.innerHTML = " <b>Loading ... Please wait.</b>";
	copyURLContent('REV/dLIST.cfm?ID='+id,'body'+id,'body'+id);
}

function shRF(id) {
//Shows rate & review form for this newspaper
	//document.getElementById('rev_l'+id).style.display = 'none';
	document.getElementById('rev'+id).style.display = 'block';
}

function shD(id) {
//Show newspaper details
	objById('opnSpan'+id).className = 'ls_optBG';
	objById('detSpan'+id).className = 'ls_optFG';

	r = -1;
	for (i = 0; i < p.length; i++) { if ( p[i] && p[i][2] == id) r = i; }
	if (r >= 0)
		document.getElementById('body'+id).innerHTML = pubDet(p[r][3],p[r][4],p[r][5],p[r][6],p[r][8]);
}

function OG(gr, total) {
// Changes a group state
//This function uses td's scope attribute to keep unrelated information
	if(!p) {
		alert('p not defined');
		return ;
	}

	tabla = document.getElementById(gr); //grupo de pubs

	if (tabla.scope == 0) 
		CG(gr, total); //El grupo no estaba creado

	else 
		DG(gr); //El grupo estaba creado
}

function ET() {
//Expand all groups
	if(!p) alert('p not defined');
	else {
		for (i = 0; i < p.length; i++)
			if (p[i]) CG(p[i][0]);
	}
}

function CG(gr, tot){
//Create group

	listaHTML = renglonBlanco();

	for (i = 0; i < p.length; i++) {
		if (p[i] && p[i][0] == gr)
			listaHTML += AP(p[i][0], p[i][1], p[i][2], p[i][3], p[i][4], p[i][5], p[i][6], p[i][7], p[i][8], p[i][9]);
	}

	if (tot >= per_por_grupo) listaHTML += EL(gr, tot - per_por_grupo);

	imag = document.getElementById('s_'+gr);
	imag.src = 'images/less.gif';

	tabla = document.getElementById(gr);
	tabla.scope = 1;
	tabla.innerHTML = "<table width='100%' cellspacing='0' cellpading='0' border='0'>" + listaHTML + "</table>";
}

function DG(gr){
//Delete grupo
	tabla = document.getElementById(gr);
	tabla.innerHTML = "&nbsp;";
	tabla.scope = 0;
	imag = document.getElementById('s_'+gr);
	imag.src = 'images/plus.gif';
}

function AP (gr, nombre, id, lang, topic, dif, loc, rank, p, nRevs) {

	salida = "";

	// *** Presentation empty row ***
	//if (who)
	salida = "<tr><td></td><td height='4' colSpan='2' class='ls_publicacion'></td><td></td></tr>"

	// *** 1st row ***
	salida += "<tr class='ls_publicacion' valign='middle'>"; //First newspaper description row
	salida += "<td width='16' height='"+alturaCelda+"' bgColor='F2FCF2'></td>"; //White
	salida += "<td>&nbsp;<u>" + vinculo(nombre, "link.cfm?ID="+id, "_blank", "ls_link") + "</u></td>"; //Name and link

	//Options
	salida += "<td align='right' border='0' width='245'>";
	//if (who) {
		salida += "<span class='ls_optBG' id='opnSpan"+id+"'>&nbsp;";
		salida += vinculo("User opinions","javascript:shR("+id+");","","", "See user opinions on " + nombre);
		salida += " </span>&nbsp;&nbsp;<span class='ls_optFG' id='detSpan"+id+"'> ";
		salida += vinculo("Details","javascript:shD("+id+");","","", "") + " ";
		salida += "</span>";

		//}

	// Stars
	salida += imagen('images/st_old/'+ rank + '.gif','Rank: ' + rank/2 +' / 5');
	salida += "</td>";

	salida += "<td width='16' height='"+alturaCelda+"' bgColor='F2FCF2'></td>";
	salida += "</tr>";

	// *** 2nd row ***
	salida += "<tr><td height='"+alturaCelda+"' width='16' bgColor='F2FCF2'></td>";
	salida += "<td id='body" + id + "' colSpan='2' height='50'>";
	salida += pubDet(id, lang, topic, dif, loc, p);
	salida += "";

	salida += "</td></tr>";
	salida += "<tr><td></td><td colSpan='2'>&nbsp;</td><td></td></tr>"; //White row
	return salida;
}

function pubDet(id, lang, topic, dif, loc, p) {
	pShow = perToString(p); //Get frequency

	retV = "<table width='100%'><tr><td width='50%' class='ls_descr' valign='top'>Language: " + lang + "<br>" + "Topic: " + topic +  "</td>";
	retV += "<td width='50%' class='ls_descr' valign='top'>Diffusion: " + dif;

	if (loc.length > 0) retV += "<br>Location: " + loc;
	if (pShow.length > 0) retV += "<br>Frequency: " + pShow;
	retV += "</td></tr></table>";

	return retV;
}

function EL(gr, res) {
//"Refine your search" link
	salida = "<tr class='ls_subheader'><td colSpan='2'><b>" + vinculo('REFINE YOUR SEARCH','dSE.cfm','_self', 'ls_link') + "</b></td>"
	salida += "<td class='ls_sub_short' colSpan='2' align='right'>" + res + " MORE RESULT(S) FROM " + gr.toUpperCase() + "</td></tr>";
	salida += renglonBlanco();
	return salida;
}

function perToString(p) {
	if (p == '0') return '';
	if (p == '1') return 'Daily';
	if (p == '7') return 'Weekly';
	if (p == '30') return 'Monthly';
	return 'Each ' + p + ' days';
}