
//
//  PARTIR EN COLUMNAS
//
//  Fuente: rebelion.org
//

var TxInicial = 12;
var textoHtml;
var numCol = 1;
var elementoHTML = "Test";
function zoom(elementoHTML,Factor)
{
	tx = document.getElementById(elementoHTML);
	TxInicial = TxInicial + Factor;
	tx.style.fontSize = TxInicial;
	if (numCol > 1)
	{
		tb = document.getElementById("tablaColumnas");
		tb.style.fontSize = TxInicial;
	}
}
function CogerTexto(elementoHTML)
{
	texto = document.getElementById(elementoHTML);
	textoHtml = texto.innerHTML;
	zoom(elementoHTML,1);

}
function columnas(elementoHTML,numCol,estilo) {
	var ini, fin

	if (!isNaN(numCol) && numCol>1){
	texto = document.getElementById(elementoHTML);
	texto.innerHTML = "";
	if (document.all)
	{
		var newTable = document.createElement("<table id='tablaColumnas' class='"+estilo+"' style=\"padding-right:20px;\" cellpadding='0' cellspacing='0' border='0' width='100%'></table>")
		var newRow = newTable.insertRow();
	}else{
	 	var newTable = document.createElement("table");
	 	newTable.setAttribute("border", "0");
		newTable.setAttribute("width", "100%");
		newTable.setAttribute("cellpadding", "0");
		newTable.setAttribute("cellspacing", "0");
		newTable.setAttribute("class", estilo);
		newTable.setAttribute("id", "tablaColumnas");
		var newRow = document.createElement("tr");
		newTable.appendChild(newRow);
	}

	fin = -1;
	var ancho = Math.floor(100 / numCol) + "%";
	for(i=1; i<=numCol; i++) {
	 	if (document.all)
		{
			var newCell = newRow.insertCell();
			newCell.width =  ancho;
			newCell.vAlign = "top";
		}else{
			var newCell = document.createElement("td");
			newRow.appendChild(newCell);
			newCell.setAttribute("style", "padding-right:20px");
			newCell.setAttribute("width", ancho);
			newCell.setAttribute("vAlign", "top");
			var celdaVacia = document.createElement("td");
		}

		// DIVIDIR TEXTO
		ini = fin + 1;
		fin += Math.floor((textoHtml.length-100) / numCol);
		if (fin  > textoHtml.length || i == numCol)
		   fin = textoHtml.length;

		// NO CORTAR TAGS
		var j;
		for(j=ini+fin-1; j>=ini && textoHtml.charAt(j) != ">" && textoHtml.charAt(j) != "<"; j--);
		if (textoHtml.charAt(j) == "<")
		   for(; fin<textoHtml.length && textoHtml.charAt(fin) != ">"; fin++);

		// ACABAR EN BLANCO O PUNTO
		if (textoHtml.charAt(fin) != " " && textoHtml.charAt(fin) != ".")
		   for(; fin<textoHtml.length && textoHtml.charAt(fin) != " " && textoHtml.charAt(fin) != "."; fin++);

		newCell.innerHTML = textoHtml.substring(ini, fin);
	 }
	 texto.appendChild(newTable)

   }
   else
   {
	   texto.innerHTML = textoHtml;
	   numCol = 1;
   }
}