/**
 * Activa los pop-ups de los enlaces con rel="external", y centra el pop-up en la pantalla. 
 * Hace uso de la biblioteca jQuery. 
 * @param {int} ancho
 * @param {int} alto
 */
function activarPopups(ancho, alto)
{
	if (ancho > screen.width) { ancho = screen.width;}
	if (alto > screen.height) { alto = screen.height;}
	var x = (screen.width - ancho) / 2;
	var y = ((screen.height - alto) / 2) - 30;
	$("[rel=external],div.a a,div.b a,div.c a,div.d a,div.e a,div.f a").click(function(e) // Activamos el popup al hacer clic.  
	{
		window.open(this.href, null, "width=" + ancho + ",height=" + alto + ",left=" + x + ",top=" + y + ",resizable=yes,scrollbars=yes");
		return false;
	});
}

function marcarSeccionActiva()
{
	var h = location.href;
	var url = h.substring(h.lastIndexOf("/") + 1);
	$("#columna-izquierda > ul a[href$=" + url + "]").css("background-color", "#2f3336");
	$("#columna-izquierda > ul ul a[href$=" + url + "]").css("background-color", "#838280");
	$("#columna-izquierda > ul ul a[href$=" + url + "]").parent().parent().parent().css("background-color", "#2f3336");
}

/**
 * Pone el foco en el primer input, textarea o select del documento
 */
function ponerFocoEnPrimerCampo()
{
	var etiquetas = document.getElementsByTagName("label");
	var campos;
	var tipoDeCampo;
	var focoPuesto = false;
	var i = 0;
	
	if (etiquetas.length > 0) // hay etiquetas en el documento
	{
		campos = etiquetas[0].childNodes; // obtenemos los hijos de la primera etiqueta
		/* Recorremos los hijos de la etiqueta hasta encontrar un input, y le asignamos el foco */
		while ((i < campos.length) && (focoPuesto == false))
		{
			tipoDeCampo = campos[i].nodeName.toLowerCase();
			if ((tipoDeCampo == "input") || (tipoDeCampo == "textarea") || (tipoDeCampo == "select"))
			{
				campos[i].focus();
				focoPuesto = true;
			}
			i++;
		}
	}
}

$(document).ready(function()
{
	ponerFocoEnPrimerCampo();
	activarPopups(800,600);
	marcarSeccionActiva();
	$()
	$(".thickbox").fancybox({'padding':0,'imageScale':false,'overlayOpacity':0.8,'hideOnContentClick':true,'centerOnScroll':false});
});

