// JavaScript Document
function carga(url,id)   
{   
//Creamos un objeto dependiendo del navegador   
var objeto;   
if (window.XMLHttpRequest)   
{   
//Mozilla, Safari, etc   
objeto = new XMLHttpRequest(); 
}   
else if (window.ActiveXObject)   
{   
//Nuestro querido IE   
try {   
objeto = new ActiveXObject("Msxml2.XMLHTTP");   
} catch (e) {   
try { //Version mas antigua   
objeto = new ActiveXObject("Microsoft.XMLHTTP");   
} catch (e) {}   
}   
}   
if (!objeto)   
{   
alert("No ha sido posible crear un objeto de XMLHttpRequest");   
}   
//Cuando XMLHttpRequest cambie de estado, ejecutamos esta funcion   
objeto.onreadystatechange=function()   
{   
cargarobjeto(objeto,id)
}   
objeto.open('GET', url, true) // indicamos con el método open la url a cargar de manera asíncrona   
objeto.send(null) // Enviamos los datos con el metodo send   
}  

function cargarobjeto(objeto, id)   
{   
if (objeto.readyState == 4){ //si se ha cargado completamente   
document.getElementById(id).innerHTML=objeto.responseText;
var scripts = document.getElementById(id).getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
eval(scripts[i].text);}
}
else //en caso contrario, mostramos un gif simulando una precarga   
document.getElementById(id).innerHTML='<IMG style="background-color:transparent; position:absolute; top:177px; left:252px; width:20px; height:20px"  alt=cargando src="imagenes/loader.gif">' 
}  

function align()
{

	var lmt = document.getElementById('CPrincipal');
	var container = document.documentElement;

	if(lmt && container)
	{
	    var containerHeight;
		var containerWidth;
	    if (container.innerWidth)
	    {
            containerHeight = container.innerHeight;
		}
		else
		{
            containerHeight = container.clientHeight;
		}
		if (container.innerHeight)
		{
			containerWidth=container.innerWidth;
		}
		else
		{
			containerWidth=container.clientWidth;
		}
	    var lmtHeight;
		var lmtWidth;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		if (lmt.innetHeight)
		{
			lmtWidth=lmt.innerWidth;
		}
		else
		{
			lmtWidth=lmt.offsetWidth;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		var x = Math.ceil((containerWidth-lmtWidth)/2);
		y=y-10;
		if(x<0)
		{
			x=0;
		}
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
		lmt.style.left= x + "px";
	}
	if (document.getElementById)
	{
		document.body.style.visibility = 'visible';
	}

}

function addevent(obj,evt,fn,capt){
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, fn, capt);
		return true;
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+evt, fn);
		return true;
	}
	else return false;
}

if (document.getElementById && document.getElementsByTagName)
{
	addevent(window, 'load', align, false);
	addevent(window, 'resize', align, false);
}
