﻿// Javascript Base de www.textilalcoyana.com
// © Agrupación Empresarial Textil Alcoyana 2004-2008

//
// Variables Globales
//
var ie = false;
var ie6 = false;
var safari = false;
var firefox = false;
var version;

//
// Funciones Globales
//

// Detectar navegador
if(navigator.appName=='Microsoft Internet Explorer') ie=true;
if(navigator.userAgent.indexOf("Safari") > -1) safari=true;
if(navigator.userAgent.indexOf("Firefox") > -1) firefox=true;

// Version
if(ie)
{
	var arVersion = navigator.appVersion.split("MSIE");
	version = parseFloat(arVersion[1]);

	if (version == 6)
	    ie6 = true;
}



// Funciones de posicionamiento del menú desplegable
function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}

// Obtener el tamaño vertical del canvas del navegador
function getViewPortHeight()
{
	// Mozilla, Opera, y Safari
	if(window.innerHeight)
	 return window.innerHeight;
	 	
	// Modos estándar de IE, pero no en ningún otro modo
	if(window.document.documentElement.clientHeight)
	 return document.documentElement.clientHeight;
	
	// Viejas versiones de IE, y IE para Mac.
	return window.document.body.clientHeight;
}

// Obtener el tamaño horizontal del canvas del navegador
function getViewPortWidth()
{
	// Mozilla, Opera, Safari
	if(window.innerWidth)
	 return window.innerWidth;
	 
	// Modos estándar de IE, pero no en ningún otro modo
	if(window.document.documentElement.clientWidth)
	 return document.documentElement.clientWidth;

	// Viejas versiones de IE, y IE para Mac.
	return window.document.body.clientWidth;	 
}

//
// Funciones Estándar para el Website
//


// Ir al TOP de la página actual
function irArriba()
{
	scroll(0,0);
}

// Ir a una URL
function goToUrl(url)
{
	location.href=url;
}

// Ir a la página anterior
function PaginaAnterior()
{
	window.history.back();
}

// Mostrar y ocultar capa
function ShowHide(objetoid)
{
    var o = document.getElementById(objetoid);
	
	switch (o.style.display)
	{
		case 'none':
			o.style.display = 'block';
			break;
		case 'block':
			o.style.display = 'none';
			break;
	}
}

function MostrarOcultar(objetoid)
{
    var o = document.getElementById(objetoid);

    if (o.className == 'Invisible')
        o.className = 'Visible';
    else
        o.className = 'Invisible';
}

//
// Variables y Funciones de Menú Principal
//

// Posiciones del Menú Principal
var posTopMenu = 37;


// Mostrar Menu
function ShowMenu(menu, boton)
{
    LimpiarMenus();
	setMenuComun(menu, boton);
	
	if(ie)
		setMenuIE(menu, boton);
	else
		setMenuMozilla(menu, boton);
}

function LimpiarMenus()
{
    HideMenu('divEntidad', 'aEntidad');
    HideMenu('divServicios', 'aServicios');
    HideMenu('divGestionCorporativa', 'aGestionCorporativa');
}

function setMenuComun(menu, boton)
{
	var divMenu = document.getElementById(menu);
	var aBoton = document.getElementById(boton);
	var posicion = getAnchorPosition(boton);
	
	var posLeftMenu=posicion.x;

	holdMenuButtonOn(aBoton);
	divMenu.style.top=posTopMenu+ 'px';
	divMenu.style.left=posLeftMenu + 'px';
}

// Menú para Internet Explorer
function setMenuIE(menu, boton)
{
	var divMenu = document.getElementById(menu);
	
	divMenu.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=90), progid:DXImageTransform.Microsoft.Fade(duration=0.3,overlap=1.0);';
	divMenu.filters[1].Apply();
	divMenu.style.visibility='visible';
	divMenu.filters[1].Play();
}

// Menú para Mozilla (Safari, Firefox)
function setMenuMozilla(menu, boton)
{
	var divMenu = document.getElementById(menu);
	var aBoton = document.getElementById(boton);
	var posicion = getAnchorPosition(boton);
	
	var anchoLayer = divMenu.offsetWidth;
	var anchoBtn = aBoton.offsetWidth;

	divMenu.style.visibility='visible';
}

// Mantener Menú en Mozilla
function HoldMenu(menu, boton)
{
	var divMenu = document.getElementById(menu);
	var aBoton = document.getElementById(boton);

	holdMenuButtonOn(aBoton);
	divMenu.style.visibility='visible';
}

// Ocultar menu
function HideMenu(menu, boton)
{
	var divMenu = document.getElementById(menu);
	var aBoton = document.getElementById(boton);

	divMenu.style.visibility = 'hidden';
	aBoton.style.backgroundPosition = '0px 0px';
}

// Activar boton menu desplegable
function holdMenuButtonOn(aBoton)
{
	aBoton.style.backgroundPosition='0px 22px';
}

//
// Funciones de Presentación
// 

function ResizePagina()
{
    LimpiarMenus();
    
	// Resize Pie Página
    var divContenido, altDivContenido, altDivFinal, anchoPagina, divContenidoPagina;

	anchoPagina = getViewPortWidth();
	divContenido = document.getElementById('divContenido');
	divContenidoPagina = document.getElementById('divContenidoPagina');
	altDivContenido = document.getElementById('divContenido').offsetHeight;
	
	if(divContenido)
	{
	    altDivFinal = getViewPortHeight() - 265;
	    divContenido.style.minHeight = altDivFinal + 'px';
	    
		if(altDivContenido<getViewPortHeight() && ie && version<7)
            divContenido.style.height=altDivFinal-2 + 'px';
	}

	if (divContenidoPagina)
	{
	    if (anchoPagina < 1000)
	    {
	        divContenido.style.backgroundImage = 'none';
	        divContenidoPagina.style.marginRight = '0px';
	    }
	    else if (anchoPagina > 1000 && anchoPagina < 1200)
	    {
	        divContenido.style.backgroundPosition = '115% top';
	        divContenidoPagina.style.marginRight = '200px';
	    }
	    else
	    {
	        divContenido.style.backgroundImage = '';
	        divContenido.style.backgroundPosition = 'right top';
	        divContenidoPagina.style.marginRight = '300px';
	    }
	}
}
