/*
articlepxfontsize_j15 - Plugin Article px Font Size for Joomla! 1.5x
author karmany
copyright (C) 2010 by karmany (http://www.karmany.co.cc)
license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
	
Please retain this copyright notice.
You can use this code if this copyright notice are included
*/

//Los tags que seran modificados:
var tgs = new Array( 'div', 'p', 'tr', 'td', 'table', 'ul', 'ol');
var sz = 9, size_inicial = 9;

function sz_default (por_defecto){
	//Reinicializa la variable sz y guardamos dato
	sz = por_defecto;
	size_inicial = por_defecto;
}

function modify_size( id_class,busca,inc ) {
	
	if (!document.getElementById) return
	var doc = document,eldoc = null,busca_tgs,i,j;
	
	if (inc == 0)
	{
		sz = size_inicial;
	}
	else
	{
		sz += inc;
		if ( sz < 6 ) sz = 6;
		if ( sz > 21 ) sz = 21;
	}
	
	if (id_class == 'id')
		{
			//Verificamos si lo ha encontrado
			if (!(eldoc = doc.getElementById( busca ))) return;
			/*eldoc.style.fontSize = sz+'px'*/
		}
	else
		{
			//Buscamos el div con class
			if (!(eldoc = getElementConClass( busca , 'div'))) return;
			/*eldoc.style.fontSize = sz+'px'*/
		}
	
	for (i=0; i<tgs.length; i++)
	{
		busca_tgs = eldoc.getElementsByTagName( tgs[i] );
		for (j=0; j<busca_tgs.length; j++) busca_tgs[j].style.fontSize = sz+'px'; 	
	}	
}

function getElementConClass(busca_class,tag) {

       var classElement, Cantidad_els, clave, ii;
       
       var els = this.document.getElementsByTagName(tag);

       Cantidad_els = els.length;
       clave = new RegExp("(^|\\s)"+busca_class+"(\\s|$)");
       
       for (ii=0; ii<Cantidad_els; ii++) {
               if ( clave.test(els[ii].className) ) {
                       classElement = els[ii];
                       break;
               }
       }
       return classElement;
}

