// JavaScript Document
function cerrar() {
	document.getElementById("informacion_alreves").style.display="none";
}

function minimizar() {
	document.getElementById("informacion_alreves").style.display="none";
	document.getElementById("informacion_alreves_mini").style.display="block";
	copia_posicion_capa("informacion_alreves","informacion_alreves_mini");
}

function maximizar() {
	document.getElementById("informacion_alreves_mini").style.display="none";
	document.getElementById("informacion_alreves").style.display="block";
	copia_posicion_capa("informacion_alreves_mini","informacion_alreves");
}

function copia_posicion_capa(capa,capa2) {
	elMovimiento = document.getElementById(capa);
	elMovimiento2 = document.getElementById(capa2);
	if (isNaN(parseInt(elMovimiento.style.left))) {
	    elComienzoX=ancho-parseInt(elMovimiento.style.right)-parseInt(elMovimiento.style.width);
    	elComienzoY=alto-parseInt(elMovimiento.style.bottom)-parseInt(elMovimiento.style.height);
	} else {
	    elComienzoX=parseInt(elMovimiento.style.left);
    	elComienzoY=parseInt(elMovimiento.style.top);
	}
	elMovimiento2.style.left = elComienzoX;
	elMovimiento2.style.top = elComienzoY;
}

function addElement(contenido,nuevo_id) {
  var ni = document.getElementById('tmp_pdi');
  var numi = document.getElementById('theValue');
  var num = nuevo_id;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = contenido;
  ni.appendChild(newdiv);
  return(divIdName);
}

function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}


function Expandir(){

	if (window.innerHeight){
	   alto = window.innerHeight;
	}
	else if (document.documentElement.clientHeight){
		alto = document.documentElement.clientHeight;
	}
	else{
		alto = 800;
	}

	window.document.getElementById("mapa").style.height = alto + "px";

}


function carga()
{
    posicion=0;

    // IE
    if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
    // Otros
    else navegador=1;
}

function evitaEventos(event)
{
    // Funcion que evita que se ejecuten eventos adicionales
    if(navegador==0)
    {
        window.event.cancelBubble=true;
        window.event.returnValue=false;
    }
    if(navegador==1) event.preventDefault();
}

function comienzoMovimiento(event, id)
{
    elMovimiento=document.getElementById(id);

     // Obtengo la posicion del cursor
    if(navegador==0)
     {
        cursorComienzoX=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;
        cursorComienzoY=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop;

        document.attachEvent("onmousemove", enMovimiento);
        document.attachEvent("onmouseup", finMovimiento);
    }
    if(navegador==1)
    {
        cursorComienzoX=event.clientX+window.scrollX;
        cursorComienzoY=event.clientY+window.scrollY;

        document.addEventListener("mousemove", enMovimiento, true);
        document.addEventListener("mouseup", finMovimiento, true);
    }


	if (window.innerHeight){
	   alto = window.innerHeight;
   	   ancho = window.innerWidth;
	}
	else if (document.documentElement.clientHeight){
		alto = document.documentElement.clientHeight;
		ancho = document.documentElement.clientWidth;
	}
	else{
		alto = 800;
		ancho = 1024;
	}

	if (isNaN(parseInt(elMovimiento.style.left))) {
	    elComienzoX=ancho-parseInt(elMovimiento.style.right)-parseInt(elMovimiento.style.width);
    	elComienzoY=alto-parseInt(elMovimiento.style.bottom)-parseInt(elMovimiento.style.height);
	} else {
	    elComienzoX=parseInt(elMovimiento.style.left);
    	elComienzoY=parseInt(elMovimiento.style.top);
	}


    // Actualizo el posicion del elemento
    elMovimiento.style.zIndex=++posicion;

    evitaEventos(event);
}

function enMovimiento(event)
{
    var xActual, yActual;
    if(navegador==0)
    {
        xActual=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;
        yActual=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop;
    }
    if(navegador==1)
    {
        xActual=event.clientX+window.scrollX;
        yActual=event.clientY+window.scrollY;
    }

    elMovimiento.style.left=(elComienzoX+xActual-cursorComienzoX)+"px";
    elMovimiento.style.top=(elComienzoY+yActual-cursorComienzoY)+"px";

    evitaEventos(event);
}

function finMovimiento(event)
{
    if(navegador==0)
    {
        document.detachEvent("onmousemove", enMovimiento);
        document.detachEvent("onmouseup", finMovimiento);
    }
    if(navegador==1)
    {
        document.removeEventListener("mousemove", enMovimiento, true);
        document.removeEventListener("mouseup", finMovimiento, true);
    }
}

// Shadowbox

function openShadowbox(contenido,reproductor,titulo,alto,ancho){
    Shadowbox.open({
        content:    contenido,
        player:     reproductor,
        title:      titulo,
		height:		alto,
		width:		ancho
    });
	
}

function abrirShadowInfo(Id,Ancho,Alto){
	window.parent.Shadowbox.close();
	PosH=((screen.availWidth/2)-(Ancho/2));
	PosV=((screen.availHeight/2)-(Alto/2));
	opciones2="height="+Alto+", width="+Ancho+", toolbar=no, directories=no, status=no, menubar=no, resizable=no, left="+PosH+", top="+PosV+", scrollbars=yes";
	window.open('masinfo.php?Id='+Id,'',opciones2);
}


function obtener_datos_pdi(tipo,id_pdi){
url="DatosPdi.xhtml?tipo="+tipo+"&id_pdi="+id_pdi;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else {// code for IE6, IE5
	  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
	  	if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var xmlDoc=xmlhttp.responseXML.documentElement;
			contenido =xmlDoc.getElementsByTagName("contenido")[0].childNodes[0].nodeValue;
			titulo=xmlDoc.getElementsByTagName("nombre")[0].childNodes[0].nodeValue;
			tipopdi=xmlDoc.getElementsByTagName("tipopdi")[0].childNodes[0].nodeValue;
			var newdiv = document.createElement('div');
			var divIdName = tipo+"-"+id_pdi;
			newdiv.setAttribute('id',divIdName);
			newdiv.innerHTML = contenido;
			document.getElementById('tmp_pdi').appendChild(newdiv);
			mi_width = document.getElementById(tipopdi).offsetWidth+24;
			mi_height = document.getElementById('datospdi').offsetHeight;
			openShadowbox(contenido,"html","",mi_height,mi_width);
			document.getElementById('tmp_pdi').removeChild(newdiv);
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}



//Relacionadas con GoogleMaps

function crearParadas(point,id_pdi,ico) {
	markers[1] = new GMarker(point,ico);
	GEvent.addListener(markers[1], "click", function() { obtener_datos_pdi('paradametro',id_pdi);});
	return markers[1];
}

function crearPuntos(point) {
	markers[1] = new GMarker(point);
	return markers[1];
}
function crearPdi(point,id_pdi,ico){
	markers[1] = new GMarker(point,ico);
	GEvent.addListener(markers[1], "click", function() { obtener_datos_pdi('pdi',id_pdi);});
	return markers[1];
}
function crearLineas(point) {

	return point;
}
