// JavaScript Document
<!--

	// INICIALIZACIONES
   var http_request = false;
   	

    // FUNCION httpRequestAjax
    function httpRequestAjax(url, funcion_respuesta) 
	{
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

		if (!http_request) {
			alert('Falla :( No es posible crear una instancia XMLHTTP');
			return false;
		}
		switch (funcion_respuesta) {
			case 'validarTopic':
				http_request.onreadystatechange = validarTopic;
				break;
			case 'validarEstatica':
				http_request.onreadystatechange = validarEstatica;
				break;
		}
        http_request.open('GET', url, true);
        http_request.send(null);
    }   


    // FUNCION httpSeguirTema
    function httpSeguirTema(tipoTema, id, idUsuario, mod) 
	{
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

		if (!http_request) {
			alert('Falla :( No es posible crear una instancia XMLHTTP');
			return false;
		}
			http_request.onreadystatechange = function validarSeguirTema () {
        			if (http_request.readyState == 4) {
            				if (http_request.status == 200) {
						respuesta = trim(http_request.responseText);
						pos_separador = respuesta.indexOf('#');
						id_respuesta = respuesta.substr(0, pos_separador);
						mensaje = respuesta.substr(pos_separador+1);
						if (id_respuesta==0) {
							document.getElementById('id_seguir_tema').innerHTML = "Para hacer eso tienes que estar registrado"
						} else if (id_respuesta==1) {
							document.getElementById('id_seguir_tema').innerHTML = "Estás siguiendo este tema. <a href=javascript:httpSeguirTema('" + tipoTema + "'," + id + "," + idUsuario + ",0);>Cancelar Seguimiento</a>"
						} else if (id_respuesta==2) {
							document.getElementById('id_seguir_tema').innerHTML = "<a href=javascript:httpSeguirTema('" + tipoTema + "'," + id + "," + idUsuario + ",1);>Seguir este tema</a>"
						}
            				} else 	{
                				alert(http_request.status + ' ' + 'Hubo problemas para seguir este tema. Reintentelo más tarde.');
            				}
        			}
			};
	url = "/seguir_tema/?t="+ tipoTema + "&i=" + id + "&u=" + idUsuario + "&o=" + mod;
        http_request.open('GET', url, true);
        http_request.send(null);
    }   


	     
	// Simula el comando TRIM
	function trim(cadena)
	{
		for(i=0; i<cadena.length; )
		{
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(i+1, cadena.length);
			else
				break;
		}

		for(i=cadena.length-1; i>=0; i=cadena.length-1)
		{
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(0,i);
			else
				break;
		}
	
//		forma.caja2.value=cadena;
		return cadena;
	}
   
   // Comprueba si el escript ya esta insertado DOM
   function existeScript (tipo, codigo_script) {
		var existe = false;
		var todos_scripts = document.getElementsByTagName('head')[0].getElementsByTagName('script');
		var arr = new Array();
		for(i = 0,iarr = 0; (i < todos_scripts.length)&&(existe==false); i++) 
		{
			if (tipo=='text') {
//				alert ('TEXT: ' + todos_scripts[i].text + '**************' + codigo_script);
				if (todos_scripts[i].text.indexOf(codigo_script)>=0) {
					existe = true;
				}
			} else if (tipo=='src') {
//				alert ('SRC: ' + todos_scripts[i].src + '**************' + codigo_script);
				if (todos_scripts[i].src.indexOf(codigo_script)>=0) {
					existe = true;
				}
			}
		}
//		alert ('RETURN: ' + existe);
		return existe;
   }
   
   // Esta funcion recorre el codigo html que recibe como parametro y carga de forma dinamica mediante DOM todos los script que encuentra
   function cargarScriptsDOM (id_etiqueta) {
		//comprueba si hay scripts
		objeto_subseccion = document.getElementById(id_etiqueta);
		codigo_html = objeto_subseccion.innerHTML;
		codigo_html = codigo_html.replace('<!--','');
		codigo_html = codigo_html.replace('-->','');
		posicion_script = codigo_html.indexOf("<script");
		if (posicion_script<0) {
			posicion_script = codigo_html.indexOf('<SCRIPT');
		}
		posicion_script_cierre = codigo_html.indexOf('>', posicion_script)+1;
		while (posicion_script>0) {
			// comprueba si el script tiene SRC
			etiqueta_abrir = codigo_html.substring(posicion_script, posicion_script_cierre);
			posicion_src = etiqueta_abrir.indexOf('src=');
			if (posicion_src<0) {
				posicion_src = etiqueta_abrir.indexOf('SRC=');
			}
			if (posicion_src>0) {
				posicion_comillas = etiqueta_abrir.indexOf('"', posicion_src);
				if (posicion_comillas<0) {
					posicion_comillas = etiqueta_abrir.indexOf("'", posicion_src);
					posicion_comillas_fin = etiqueta_abrir.indexOf("'", posicion_comillas+1);
				}
				else {
					posicion_comillas_fin = etiqueta_abrir.indexOf('"', posicion_comillas+1);
				}
				codigo_script_src = etiqueta_abrir.substring(posicion_comillas+1, posicion_comillas_fin);
				if (!existeScript('src', codigo_script_src))
				{
					miScript = document.createElement('script');
					miScript.type = 'text/javascript';
					miScript.src = codigo_script_src;
					headTag = document.getElementsByTagName('head')[0];
					headTag.appendChild(miScript);
//					alert ('src ->*' + codigo_script_src + '*');
				}
			}
			// si hay scripts los carga dinamicamente
			posicion_script_fin = codigo_html.indexOf('</script>', posicion_script_cierre);
			if (posicion_script_fin<0) {
				posicion_script_fin = codigo_html.indexOf('</SCRIPT>', posicion_script_cierre);
			}
			codigo_script = codigo_html.substring (posicion_script_cierre, posicion_script_fin);
			if (codigo_script.length>0)
			{
				if (!existeScript('text', codigo_script))
				{
					miScript = document.createElement('script');
					miScript.type = 'text/javascript';
					miScript.text = codigo_script;			
					headTag = document.getElementsByTagName('head')[0];	
					headTag.appendChild(miScript);
//					alert ('script ->*' + codigo_script + '*');
				}
			}
	
			posicion_script = codigo_html.indexOf('<script', posicion_script_fin);
			if (posicion_script<0) {
				posicion_script = codigo_html.indexOf('<SCRIPT', posicion_script_fin);
			}
			posicion_script_cierre = codigo_html.indexOf('>', posicion_script)+1;
		}

   }
   
	function getElementsByName_iefix(tag, name) 
	{
		var elem = document.getElementsByTagName(tag);
		var arr = new Array();
		for(i = 0,iarr = 0; i < elem.length; i++) 
		{
			att = elem[i].getAttribute("name");
			if(att == name) 
			{
				arr[iarr] = elem[i];
				iarr++;
			}
		}
	return arr;
	}


function cargando (div_inicial, texto)
{
       if (texto!='') {
//	document.getElementById(div_inicial).innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='100%'><tr height='100%'><td align='center' valign='middle'><span class='EstiloTexto'>" + texto +"<br><br><br><img src='/headers/zonas/5652/cargando.gif' border='0'></span></td></tr></table>";
	document.getElementById(div_inicial).innerHTML = "<div align='center' style='position:absolute; top:50%; left:50%;'><span class='EstiloTexto'>" + texto +"<br><br><br><img src='/headers/zonas/5652/cargando.gif' border='0'></span></div>";
     }  else {
//	document.getElementById(div_inicial).innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='100%'><tr height='100%'><td align='center' valign='middle'><span class='EstiloTexto'><img src='/headers/zonas/5652/cargando.gif' border='0'></span></td></tr></table>";
	document.getElementById(div_inicial).innerHTML = "<div align='center' style='position:absolute; top:50%; left:50%;'><img src='/headers/zonas/5652/cargando.gif' border='0'></div>";
     }
}

 
    function cargarSeccionAjax(idEspacioPortal, url) {

        http_request = false;

		document.getElementById('seccion_' + idEspacioPortal).innerHTML = "<div align='center' style='position:absolute; top:50%; left:50%;'><div id='div_subseccion'><img src='/headers/zonas/5652/cargando.gif' border='0'></div></div>";

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Falla :( No es posible crear una instancia XMLHTTP');
            return false;
        }
        http_request.onreadystatechange = function () {
        if (http_request.readyState == 4) 
		{
            if (http_request.status == 200) 
			{
				respuesta_html = http_request.responseText;
				posicion_body = respuesta_html.indexOf('<body');
				final_html = respuesta_html.substring(posicion_body);	
				document.getElementById('seccion_' + idEspacioPortal).innerHTML = final_html;
            } 
	else 
	{
                alert(http_request.status + ' ' + 'Hubo problemas con la petición.');
            }
        }
};
        http_request.open('GET', url, true);
        http_request.send(null);

    }



    function cargarSeccionAjaxNuevo(http_request_nuevo, idEspacioPortal, url) {


		document.getElementById('seccion_' + idEspacioPortal).innerHTML = "<div align='center' style='position:absolute; top:50%; left:50%;'><div id='div_subseccion'><img src='/headers/zonas/5652/cargando.gif' border='0'></div></div>";

        http_request_nuevo.onreadystatechange = function () {
        if (http_request_nuevo.readyState == 4) 
		{
            if (http_request_nuevo.status == 200) 
			{
				respuesta_html = http_request_nuevo.responseText;
				posicion_body = respuesta_html.indexOf('<body');
				final_html = respuesta_html.substring(posicion_body);	
				document.getElementById('seccion_' + idEspacioPortal).innerHTML = final_html;
            } 
	else 
	{
                alert(http_request_nuevo.status + ' ' + 'Hubo problemas con la petición.');
            }
        }
};
        http_request_nuevo.open('GET', url, true);
        http_request_nuevo.send(null);

    }

	
    function alertContents() 
	{
        if (http_request.readyState == 4) 
		{
            if (http_request.status == 200) 
			{
				respuesta_html = http_request.responseText;
				posicion_body = respuesta_html.indexOf('<body');
				final_html = respuesta_html.substring(posicion_body);	
				document.getElementById('seccion_6719').innerHTML = final_html;
//				cargarScriptsDOM ('div_central');	
            } 
	else 
	{
                alert(http_request.status + ' ' + 'Hubo problemas con la petición.');
            }
        }

    }



//-->









