﻿
/****
© 1996-2006 I+P Ingeniería y Prevención de Riesgos S,L. Todos los derechos reservados
  Diseño y Desarrollo: TecnoQuest
****/ 

var path = window.location.pathname;
window.onload = Init;
window.onresize = Page_Resize;

function gId(str){ return document.getElementById(str); }

function Init()
{
	Set_Menu();
	Page_Size();
	
	//Pagina delegaciones
	if(path.indexOf('delegaciones') != -1)
	{
	    Set_Puntos();
		Set_Delegacion(12); //sede central Madrid
	    Set_Window();  
	}
}

/// PAGINA //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Page_Resize(){
	var altDoc = parseInt(gId('cont').scrollHeight + 75);
	var altWin = 0;
	if(document.documentElement && document.documentElement.clientHeight){ altWin = document.documentElement.clientHeight; }
	else if(document.body && document.body.clientHeight){ altWin = document.body.clientHeight; }
	else{ altWin = window.innerHeight; }
	//
	if(altWin > altDoc)
	{
		gId('main').style.height = altWin + 'px';
	}
	else
	{
		gId('main').style.height = (altDoc) + 'px';
	}
	//Pie
	gId('pie').style.top = parseInt(gId('main').style.height) - 60 + 'px';		
	//Velo callejero
	if(gId("velo")) gId("velo").style.height = gId('main').style.height;
}
function Page_Size()
{	
	//Main hasta abajo	
	Page_Resize();
}

// VELO /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Set_Velo()
{   
    var iev = navigator.userAgent.toLowerCase();
    if(iev.indexOf('msie 5.0') != -1 || iev.indexOf('msie 5.5') != -1) //|| iev.indexOf('msie 6.0') != -1)
    {
        return;
    }
    var velo = document.createElement('DIV');
        velo.id = 'velo';
        velo.style.zIndex = 1;
        velo.style.width = '760px';
	    velo.style.height = gId('main').style.height;
	    var ie = (document.all) ? 1 : 0;
        var p = (ie) ? "filter" : "MozOpacity";
        var v = 40;
        v = (ie) ? "alpha(opacity="+v+")" : v/100;
        velo.style[p] = v;
    gId('main').appendChild(velo);
}
function Hide_Velo()
{
    if(gId("velo"))
    {
        gId('main').removeChild(gId('velo'));
    } 
}

/// MENU ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var sec_url = ['index','empresa','servicios','referencias','rrhh','comunicacion','indice'];
var sec_tag = ['Inicio','La Empresa','Ámbitos de actuación','Trabajos realizados','Equipo Humano','Sala de Comunicacion','Índice'];
var sec_ids = ['m_ini','m_com','m_ser','m_ref','m_rrhh','m_sala','m_map'];
var sec_css = ['c_ini','c_com','c_ser','c_ref','c_rrhh','c_sala','c_map'];
	//Compania
	var sub_url_1 = ['actividad', 'objetivos', 'direccion', 'cifras', 'calidad', 'delegaciones', 'contacto'];
	var sub_tag_1 = ['Nuestra actividad', 'Filosofía y Objetivos', 'Equipo Directivo', 'Cifras clave', 'Sistema de Gestión Integrada', 'Delegaciones I+P', 'Contactar'];
	//Servicios
	var sub_url_2 = ['construccion', 'asistencia', 'formacion', 'aplicaciones'];
	var sub_tag_2 = ['Asistencia Técnica en materia de seguridad y salud', 'Asistencia técnico jurídica', 'Formación en técnicas de prevención', 'Aplicaciones informáticas'];
	//Referencias
	var sub_url_3 = [''];
	var sub_tag_3 = [''];
	//RRHH
	var sub_url_4 = ['politica', 'organigrama', 'equipo', 'recursos', 'ofertas', 'altas'];
	var sub_tag_4 = ['Política de RRHH', 'Organigrama Funcional', 'Equipo profesional', 'Recursos técnicos', 'Ofertas de trabajo', 'Envíanos tu CV'];
	//Comunicacion
	var sub_url_5 = ['noticias', 'novedades', 'documentacion', 'galeria', 'enlaces'];
	var sub_tag_5 = ['Noticias I+P', 'Novedades normativas y jurídicas', 'Documentacion corporativa', 'Galería de imágenes', 'Enlaces'];

function Set_Menu()
{	
	//MENU TOP
	gId('m1').innerHTML = '<div id="menu_top">' +
							'<ul>' +
								'<li id="mt_con"><a href="/empresa/contacto.aspx" title="Información de contacto">Contacte con nostros</a></li>' +
								'<li id="mt_ext"><a href="/extranet/" title="Acceso a Extranet I+P">Extranet de Clientes</a></li>' +
								'<li id="mt_ext"><a href="http://imasp.selfip.net/intranet" title="Acceso a la Intranet I+P">Intranet</a></li>' +
							'</ul>' +
						  '</div>';
							
	var top_lks = gId('menu_top').getElementsByTagName('A');
	for(i=0; i < top_lks.length; i++) 
    {
		top_lks[i].onmouseover = Effect_Submenu_On;
		top_lks[i].onmouseout = Effect_Submenu_Off;
	}
	
	//MENU Y SUBMENUS
	gId('m2').innerHTML = '<div id="menu">' +
						      '<div id="menu_bor">' +
							    '<a href="/index.aspx" id="m_ini" class="m_gen" title="Página de Inicio">'+sec_tag[0]+'</a>' +
							    '<a href="/empresa/actividad.aspx" id="m_com" class="m_gen" title="Acerca de I+P">'+sec_tag[1]+'</a>' +
							    '<a href="/servicios/construccion.aspx" id="m_ser" class="m_gen" title="Ámbitos de actuación">'+sec_tag[2]+'</a>' +
							    '<a href="/referencias/proyectos.aspx" id="m_ref" class="m_gen" title="Clientes y trabajos realizados">'+sec_tag[3]+'</a>' +
							    '<a href="/rrhh/politica.aspx" id="m_rrhh" class="m_gen" title="Equipo Humano">'+sec_tag[4]+'</a>' +
							    '<a href="/comunicacion/noticias.aspx" id="m_sala" class="m_gen" title="Noticias, novedades normativas, etc.">'+sec_tag[5]+'</a>' +
							    '<a href="javascript:;" onclick="Show_Mapa(\'m_map\')" id="m_map" class="m_map" title="Mostrar índice de contenidos">'+sec_tag[6]+'</a>' +
						        '<span id="f_map" onclick="Show_Mapa(\'m_map\')" title="Mostrar índice de contenidos"></span>' +
						      '</div>' +
						    '</div>';    
    var asigned = false;	
    for(i=0; i < sec_url.length; i++) 
    {
		//SECCIONES
		if(path.indexOf(sec_url[i]) != -1)
        {
            //menu
			gId(sec_ids[i]).className += "_stay";
            asigned = true;
			if(gId('g_left'))
			{
				//titulo pagina seccion
				gId('t_sec').innerHTML = sec_tag[i];
				
				//SUB-SECCIONES
				var sub_con = '<div id="gc_left"><ul class="ulM">';
				for(j=0; j < eval('sub_url_'+i).length; j++)
    			{
					if(path.indexOf(eval('sub_url_'+i)[j]) != -1)
					{
						//titulo pagina subseccion
						gId('t_sub').innerHTML = eval('sub_tag_'+i)[j];
						
						//submenu selected
						sub_con += '<li class="liM_s">' +
								   '<a href="/' + sec_url[i] + '/' + eval('sub_url_'+i)[j] + '.aspx">' + eval('sub_tag_'+i)[j] + '</a>' + 
								   '</li>';
					}
					else
					{
						//submenu no selected
						sub_con += '<li class="liM">' + 
								   '<a href="/' + sec_url[i] + '/' + eval('sub_url_'+i)[j] + '.aspx" ' +
								   'onmouseover="this.parentNode.className=\'liM_h\'" ' + 
								   'onmouseout="this.parentNode.className=\'liM\'">' + 
								   eval('sub_tag_'+i)[j] + '</a>' + 
								   '</li>';
					}
				}
				sub_con += '</ul></div>';
				gId('g_left').innerHTML = sub_con;
			}
			
			if(sec_url[i] != 'index') gId('main').style.backgroundImage = "url(/_img/bg_mainI.gif)";
        }
    }
    if(!asigned)
    {
        gId(sec_ids[0]).className += "_stay";
    }
    
    //Boton mapa sitio
    Set_BotMapa();
}

function Effect_Submenu_On()
{
	this.parentNode.style.background = 'url(../_img/_menu/bg_submenuO.gif) repeat-x';
}
function Effect_Submenu_Off()
{
	this.parentNode.style.background = 'none';
}

// INDICE DE CONTENIDOS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var cMap = null;

function Set_BotMapa(mode)
{
    gId('m_map').onmouseover = gId('f_map').onmouseover = function(){
        gId('f_map').style.backgroundPosition = '0 -30px';
        gId('m_map').style.color = '#5C5C5C';
        gId('m_map').style.backgroundImage = 'url(/_img/_menu/bg_menuO.gif)';
    }
    gId('m_map').onmouseout = gId('f_map').onmouseout = function(){
        gId('f_map').style.backgroundPosition = '0 0';
        gId('m_map').style.color = '';
        gId('m_map').style.backgroundImage = '';
    }
    if(mode == 'restaura')
    {
        gId('f_map').style.backgroundPosition = '0 0';
        gId('m_map').style.color = '';
        gId('m_map').style.backgroundImage = '';
        gId('m_map').title = gId('f_map').title = 'Mostrar índice de contenidos';
        gId('menu').removeChild(gId('m_map_stay'));
        Hide_Velo();
    }
}

function Show_Mapa(bot)
{
    gId(bot).blur();
    if(gId(bot + 'c'))
    {
        return;
    }
    //Boton indice
    var m_map = document.createElement('DIV');
        m_map.id = 'm_map_stay';
        m_map.innerHTML = '<a href="javascript:;" onclick="Show_Mapa(\'m_map\')" id="m_map2" class="m_map" title="Ocultar índice de contenidos">'+sec_tag[6]+'</a>' +
					      '<span id="f_map2" onclick="Show_Mapa(\'m_map\')" title="Ocultar índice de contenidos"></span>';
    gId('menu').appendChild(m_map);
    
    //Creacion capa
        //Contenedor
        cMap = document.createElement('DIV');
        cMap.id = bot + 'c';
        cMap.className = bot + 'c';
        gId('m2').appendChild(cMap);
        //Continuador boton
        var bMap = document.createElement('DIV');
        bMap.className = 'b_mapc';
        cMap.appendChild(bMap);
        //Contenido
        var map_sec = new Array();
        var sec_css = new Array();
        var asigned = false;
        for(i=0; i < sec_url.length-1; i++)  
        {		    
		    if(path.indexOf(sec_url[i]) != -1)
            {
			    sec_css[i] = "lkGb_stay";
			    asigned = true;
            }
            else
            {
                sec_css[i] = "lkGb";
            }
		    if(i > 0)
		    {
		        map_sec[i] = '<ul class="ulM2">';
		        for(j=0; j < eval('sub_url_'+i).length; j++)
		        {
				    //item selected
			        if(path.indexOf(eval('sub_url_'+i)[j]) != -1)
			        {
				        map_sec[i] += '<li class="liM2_s">' +
						                  '<a href="/' + sec_url[i] + '/' + eval('sub_url_'+i)[j] + '.aspx">' + eval('sub_tag_'+i)[j] + '</a>' + 
						              '</li>';
			        }
			        else
			        {
				        //item no selected
				        map_sec[i] += '<li class="liM2">' + 
						                   '<a href="/' + sec_url[i] + '/' + eval('sub_url_'+i)[j] + '.aspx" ' +
						                   'onmouseover="this.parentNode.className=\'liM2_h\'" ' + 
						                   'onmouseout="this.parentNode.className=\'liM2\'">' + 
						                   eval('sub_tag_'+i)[j] + '</a>' + 
						               '</li>';
			        }
		        }
		        map_sec[i] += '</ul>';
		    }
        }
        if(!asigned)
        {
		    sec_css[0] = "lkGb_stay";
        }
        
        var tMap = document.createElement('DIV');
        tMap.className = 't_mapc';
        tMap.innerHTML = '<table border="0">' +
					        '<tr>' +
					            '<td>' +
					                '<table border="0" width="195">' +
					                    '<tr>' +
					                        '<td><a href="/index.aspx" class="' + sec_css[0] + '" title="Página de Inicio">'+sec_tag[0]+'</a></td>' +
					                    '</tr>' +
					                    '<tr>' +
					                        '<td>' + 
					                            '<a href="/empresa/actividad.aspx" class="' + sec_css[1] + '" title="Acerca de I+P">'+sec_tag[1]+'</a>' +
					                            map_sec[1] + 
					                        '</td>' +
					                    '</tr>' +
					                    '<tr>' +
					                        '<td>' + 
					                            '<a href="/servicios/construccion.aspx" class="' + sec_css[2] + '" title="Servicios Profesionales">'+sec_tag[2]+'</a>' +
					                            map_sec[2] + 
					                        '</td>' +
					                    '</tr>' +
				                    '</table>' +
					            '</td>' +
					            '<td>' +
					                '<table border="0" width="185">' +
					                    '<tr>' +
					                        '<td>' + 
					                            '<a href="/referencias/proyectos.aspx" class="' + sec_css[3] + '" title="Referencias, Clientes y Proyectos">'+sec_tag[3]+'</a>' + 
					                        '</td>' +
					                    '</tr>' +
					                    '<tr>' +
					                        '<td>' +
					                            '<a href="/rrhh/politica.aspx" class="' + sec_css[4] + '" title="Trabajar en I+P">'+sec_tag[4]+'</a>' + 
					                            map_sec[4] + 
					                        '</td>' +
					                    '</tr>' +
					                    '<tr>' +
					                        '<td>' +
					                            '<a href="/comunicacion/noticias.aspx" class="' + sec_css[5] + '" title="Noticias,  novedades normativas, etc.">'+sec_tag[5]+'</a>' +
					                            map_sec[5] + 
					                        '</td>' +
					                    '</tr>' +
				                    '</table>' +
					            '</td>' +
					        '<tr>' +
				          '</table>';
        cMap.appendChild(tMap);
    
    //Velo
    Set_Velo();
    
    //Evento hidden retardado
    setTimeout("Hide_Mapa('"+ bot +"')", 100); 
}

function Hide_Mapa(bot)
{    
    if(document.documentElement)
    { 
        document.documentElement.onclick = function()
        {
            gId('m2').removeChild(cMap); 
            cMap = null;
            document.documentElement.onclick = null;
	        Set_BotMapa('restaura');
        }
    }
	else if(document.body)
	{
	    document.body.onclick = function()
        {
            gId('m2').removeChild(cMap); 
            cMap = null;
            document.documentElement.onclick = null;
	        Set_BotMapa('restaura');
        }
	}
	else{
	    gId('main').onclick = function()
	    {
	        gId('m2').removeChild(cMap); 
            cMap = null;
            gId('main').onclick = null;
	        Set_BotMapa('restaura');
	    }
	}
}

// NEWS HOME ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Set_News()
{
    try
	{
		//Mostrar scroll ficticio
		if(gId('il_news').scrollHeight < 375)
		{
			gId('il_news').style.background = 'url(../_img/scr_news.gif) no-repeat top right';
			gId('il_news').style.paddingRight = '28px';
		}
		gId('il_news').style.height = '375px';
		
		//Estilo ultima noticia del list
		var newsList = gId('il_news').getElementsByTagName('P');
			newsList[newsList.length-1].className = 't_newsU';
	}
	catch(e)
	{
		//
	}
    
}

/// FORMULARIO ENVIO /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Procesar(bot)
{
    gId(bot).onclick = function()
    {
        gId(bot).style.display = "none";
        gId(bot + '_b').style.display = "block"; 
    }
}

// POLITICA PRIVACIDAD //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Open_Politic()
{
	if(gId('lkOpen').className == 'lk_open')
	{
		gId('lkOpen').className = 'lk_close';
		gId('lkOpen').title = 'Ocultar política de privacidad';
		gId('t_pol').style.display = 'block';
		gId('c_mail').innerHTML = 'O a la dirección de correo electrónico <a href="mailto:recepcion@imasp.net" class="lkG" title="Enviar email">recepcion@imasp.net</a>';	
	}
	else
	{
		gId('lkOpen').className = 'lk_open';	
		gId('lkOpen').title = 'Mostrar política de privacidad';
		gId('t_pol').style.display = 'none';	
		gId('c_mail').innerHTML = '';	
	}
	
	Page_Resize();
}
	
	
	
	
	
