function inicializar_lightbox(ruta){
    ruta +="pub/lib/datagrid/modules/sexylightbox/sexyimages/";
    alert(ruta);
    SexyLightbox.initialize({
        imagesdir: "'"+ruta+"'"
    });
}
function grand(h) 
{
    iframe=document.getElementById("iframe_wiki")
    iframe.height=h;
}
function reSize(h)
{  
    try
    {
        var oBody	=	iframe_wiki.document.body;
        var oFrame	=	document.all("iframe_wiki");
  		
        oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
        oFrame.style.width = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
    }
    catch(e) //An error is raised if the IFrame domain != its container's domain
    {
        window.status =	'Error: ' + e.number + '; ' + e.description;
    }
}


function Ajax_portal(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function gid(id){
    return document.getElementById(id);
}

function get_contenido(url,parametros,elemento){
    ajax_portal=Ajax_portal();
    ajax_portal.open("POST",url,true);
    ajax_portal.onreadystatechange=function(){
        if (ajax_portal.readyState==4){
            if(ajax_portal.responseText!="")
                switch(elemento){                    
                    case "frm_contacto":
                        Sexy.alert("Disculpe su consulta no ha podido se enviada.<br/>Inténtelo de nuevo mas tarde usted.");
                        break;
                }
            else{
                switch(elemento){
                    case "portal_botonera_superior_registro":
                        Sexy.alert("El usuario o contrase&ntilde;a introducidos no son validos.<br/>");
                        break;
                    case "frm_contacto":
                        Sexy.alert("Su consulta ha sido enviada.<br/>En breve nos pondremos en contacto con usted.");
                        gid('frm_contacto').reset();
                        break;
                }
            }
        }
    }
    ajax_portal.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax_portal.send(parametros);
}

function validar_registro(){	
    elemento='portal_botonera_superior_registro';
    parametros="portal_id="+gid('portal_id').value+"&login="+gid('login_portal').value+"&password="+gid('password_portal').value;
    mensaje_fallo="<h1>Entorno Activo</h1><br/><em>\u00A1Error!</em><br/><p>El usuario introducido no es válido</p>";
    get_contenido(host_modulos+'login/login.php',parametros,elemento);
	
}
function validar_frm_contacto(){
    var mensaje="";
    if(gid('txt_nombre').value=='')
        mensaje="Nombre<br />";
    if(gid('txt_telefono').value=='')
        mensaje+="Teléfono<br />";
    if(gid('txt_email').value=='')
        mensaje+="Correo<br />";
    if(gid('txa_comentarios').value=="")
        mensaje+="Comentario<br />"
    if(mensaje!="")
        Sexy.alert("<h3>Por favor rellene los siguientes campos</h3><br />"+mensaje);
    else{
        parametros="txt_nombre="+gid('txt_nombre').value+"&txt_telefono="+gid('txt_telefono').value+"&txt_email="+gid('txt_email').value+"&txa_comentarios="+gid('txa_comentarios').value;
        elemento="frm_contacto";
        get_contenido(host_modulos+'contacto/envio_frm_contacto.php',parametros,elemento);
    }
}
function salir_registro(portal_id){	
    elemento='portal_botonera_superior_registro';
    parametros="portal_id="+portal_id;
    //alert(portal_id);
    get_contenido(host_modulos+'login/logout.php',parametros,elemento);
}

$(document).ready(function(){
    $('#aumentar').fontSizer({
        action: "up",
        elements: ".portal_cuerpo_principal_contenido_texto",
        max: 36
    });

    $('#disminuir').fontSizer({
        action: 'down',
        elements: ".portal_cuerpo_principal_contenido_texto"
    });
})
        



var fontsize_portal=10;
function mkStyleSize(id,value){
    maxvalue=25;
    minvalue=8;
    if(value==1){
        if(fontsize_portal<maxvalue)
            fontsize_portal++;
    }
    else{
        if(fontsize_portal>minvalue)
            fontsize_portal--;
    }
    gid(id).style.fontSize=fontsize_portal+"px";
}

function cambia_general(){
    setTimeout("abrir_general()", 3000);
}
function abrir_general(){
    ajax_portal = Ajax_portal();
    ajax_portal.open('POST', '../../../includes/modules/chat/concurrencia.php', true);   
    ajax_portal.onreadystatechange=function() {
  
        if (ajax_portal.readyState==4) {
    //alert(ajax.responseText);
    }
  		
    }
    ajax_portal.send(null)
    cambia_general();
}
function ajustar(){
    jQuery(document).ready(function(){
        /*	if ( jQuery("div#portal_cuerpo_principal_contenido").height () < jQuery("div#portal_cuerpo_lateral_izq").height () ) {
			jQuery("div#portal_cuerpo_principal_contenido") .height ( jQuery("div#portal_cuerpo_lateral_izq").height() )
		}*/
        if ( jQuery("div#portal_cuerpo_principal_contenido").height () < jQuery("div#portal_cuerpo_lateral_derecho").height () ) {
            jQuery("div#portal_cuerpo_principal_contenido").height ( jQuery("div#portal_cuerpo_lateral_derecho").height() )
        }
    /*	if ( jQuery( "div#portal_cuerpo_lateral_derecho" ).height () > jQuery ( "div#portal_cuerpo_lateral_izq" ).height () ) {
			jQuery( "div#portal_cuerpo_lateral_izq" ).height ( jQuery( "div#portal_cuerpo_lateral_derecho" ).height () )
		} else {
			jQuery( "div#portal_cuerpo_lateral_derecho" ).height ( jQuery( "div#portal_cuerpo_lateral_izq" ).height () )
		}*/
			
    } ) ;
}
function at_show_aux(parent, child)
{
    var p = document.getElementById(parent);
    var c = document.getElementById(child );

    var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
    var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

    for (; p; p = p.offsetParent)
    {
        top  += p.offsetTop;
        left += p.offsetLeft;
    }

    c.style.position   = "absolute";
    c.style.top        = top +'px';
    c.style.left       = left+'px';
    c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
    var p = document.getElementById(this["at_parent"]);
    var c = document.getElementById(this["at_child" ]);

    at_show_aux(p.id, c.id);
    clearTimeout(c["at_timeout"]);
}
function objetoAjax(){
    var xmlhttp=false;
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function Pagina2(direccion,pags,limite,id,portal_id){
    ajax=objetoAjax();
    ajax.open("POST", direccion+"?portal_id="+portal_id+"&pags="+pags+"&limite="+limite);
 
    ajax.onreadystatechange = function() {
        if (ajax.readyState == 4) {
            document.getElementById(id).innerHTML = ajax.responseText
        }
    }
    //como hacemos uso del metodo GET
    //colocamos null ya que enviamos
    //el valor por la url ?pags=nropagina
    ajax.send(null)
}

function cargar_muni(prov){
    ajax=objetoAjax();
    ajax.open("GET", "../../../includes/modules/privado/cont_muni.php?prov="+prov,true);
	
    ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax.onreadystatechange=function(){
        if (ajax.readyState==1){
            gid('etiqueta_carga_muni').style.display='inline';
        }
        if (ajax.readyState==4){
            gid('etiqueta_carga_muni').style.display='none';
            gid('cont_muni').innerHTML=""+ ajax.responseText + "";
            ajax2=objetoAjax();
            ajax2.open("GET", "../../../includes/modules/privado/cont_cp.php?muni=",true);
    	
            ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            ajax2.onreadystatechange=function(){
                if (ajax2.readyState==1){
                    gid('etiqueta_carga_cp').style.display='inline';
                }
                if (ajax2.readyState==4){
                    gid('etiqueta_carga_cp').style.display='none';
                    gid('cont_cp').innerHTML=""+ ajax2.responseText + "";
                }
            }
            ajax2.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
            ajax2.send('D');
        }
    }
    ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
    ajax.send('D');
}

function cargar_cp(muni){
    ajax=objetoAjax();
    ajax.open("GET", "../../../includes/modules/privado/cont_cp.php?muni="+muni,true);
	
    ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax.onreadystatechange=function(){
        if (ajax.readyState==1){
            gid('etiqueta_carga_cp').style.display='inline';
        }
        if (ajax.readyState==4){
            gid('etiqueta_carga_cp').style.display='none';
            gid('cont_cp').innerHTML=""+ ajax.responseText + "";
        }
    }
    ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
    ajax.send('D');
}

function agregar(){
    //IE
    if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4))
    {
        var url="http://www.entornoactivo.com/"; //Cambia esta dirección por la de tu web
        var titulo="Entorno Activo"; //Cambia esta nombre por el de tu web
        window.external.AddFavorite(url,titulo);
    }
    //Para Firefox
    else
    {
        if(navigator.appName == "Netscape")
            //Hay que modificar el nombre por el de vuestra pagina
            window.sidebar.addPanel("Entorno Activo", "http://www.entornoactivo.com/","");
    }
}

function changeIdioma(valor){
    document.location = '?idioma_id=' + valor;
}

function cargarNoticia(id){
    ajax_portal = Ajax_portal();
    ajax_portal.open('POST', '../../../includes/modules/noticias/ver_noticia.php?id='+id, true);
    ajax_portal.onreadystatechange=function() {
  
        if (ajax_portal.readyState==4) {
            gid('SLB-Contenido').innerHTML = ajax_portal.responseText;
        }
    }
    ajax_portal.send("id="+id)
}

function cargarProducto(id){
    ajax_portal = Ajax_portal();
    ajax_portal.open('POST', '../../../includes/modules/productos_dest/ver_producto.php?id='+id, true);
    ajax_portal.onreadystatechange=function() {
  
        if (ajax_portal.readyState==4) {
            gid('SLB-Contenido').innerHTML = ajax_portal.responseText;
        }
    }
    ajax_portal.send("id="+id)
}

function paginar_ajax(direccion,contenedor){
    //donde se mostrará los registros
	
    ajax_portal = Ajax_portal();
    //uso del medoto GET
    //indicamos el archivo que realizará el proceso de paginar
    //junto con un valor que representa el nro de pagina
    ajax_portal.open("GET", direccion);
	
    ajax_portal.onreadystatechange = function() {
        if (ajax_portal.readyState == 4) {
            gid(contenedor).innerHTML = ajax_portal.responseText	        
        }
    }
    //como hacemos uso del metodo GET
    //colocamos null ya que enviamos
    //el valor por la url ?pag=nropagina
    ajax_portal.send(null)
}
function ocultar_modulo(capa){
    var modulo = gid(capa);
    if (modulo.style.display == 'none')
        modulo.style.display = 'inline';
    else
        modulo.style.display = 'none';
}


