// Código necesario para cambiar el estilo automáticamente en función de
// un parametro
var sCSS;
var sPathRelativo;

if (sCSS==undefined) sCSS='';
sParametros=window.location.search;
if (sParametros.length>0)
{
	if (sParametros.substr(0,1)=='?') sParametros=sParametros.substr(1);
  aParam=sParametros.split('&');
  for(i in aParam)
  {
		sParam=aParam[i];
		aPareja=sParam.split('=');
		if (aPareja.length==2)
		{
			if (aPareja[0].toLowerCase()=='css')
			{
				sCSS=aPareja[1];
			}
		}
	}
}
if(sPathRelativo==undefined)
{
	sPathRelativo='../../css/';
}
if(sCSS.length>0)
{
  if (NavegadorIE()) document.createStyleSheet( sPathRelativo+ sCSS + '.css');
  else
  {
		if (document.styleSheets.length>0)
		{
			var sPath,iPos;
			sPath=window.location.pathname;
			iPos=sPath.lastIndexOf('/');
			if (iPos>0)
			{ 
				sPath=sPath.substring(0,iPos+1);
				sPath=sPath + sPathRelativo + sCSS + '.css';
				oCSS=document.styleSheets.item(document.styleSheets.length-1);
				while (oCSS.cssRules.length>0) oCSS.deleteRule(0);
				oCSS.insertRule('@import url(' + sPath + ');',0);
			}
		}
  }
}



// Función utilizada para gestionar los links en el caso de trabajar con múltiples CSS
function GestionarEnlace(sEnlace, w, h, iURL, iVentanaNueva, sTarget,iHTTPS){
	//Le pasamos el parametro (si tiene)
 	if (sCSS.length>0)
	{
		if (sEnlace.indexOf("?")==-1) sEnlace=sEnlace + '?css=' + sCSS;
		else sEnlace=sEnlace + '&css=' + sCSS;
	}
	
  sEnlace=CalcularURLHTTPS(sEnlace,iHTTPS);

	//Comprobamos el destino del link
	if (iVentanaNueva==0)	{
		if (sTarget.length==0) 
	    window.open(sEnlace,'_self');
		else
      window.open(sEnlace,sTarget);
	}
	else {
		abrirVentana(sEnlace,w,h,iURL);
	}
}

function CalcularURLHTTPS(sEnlace,iHTTPS)
{
  var sNuevoEnlace, sPathBase;
  var bCambiarProtocolo=false;
  var lPos;
   sNuevoEnlace=sEnlace;
   if (iHTTPS!="2")
   {
     if ((sEnlace.indexOf("http://")==-1)&& (sEnlace.indexOf("https://")==-1))
     {
        if (self.location.protocol=="http:" && iHTTPS==1) bCambiarProtocolo=true;
        if (self.location.protocol=="https:" && iHTTPS==0) bCambiarProtocolo=true;
        if (bCambiarProtocolo)
        {
          if (iHTTPS==0) sNuevoEnlace="http://";
          if (iHTTPS==1) sNuevoEnlace="https://";
          sNuevoEnlace=sNuevoEnlace + self.location.host;
          if(self.location.port!="")  sNuevoEnlace=sNuevoEnlace + ":" + self.location.port;
          sPathBase=self.location.pathname;
          lPos=sPathBase.lastIndexOf("/");
          if (lPos!=-1)
          {
            sPathBase=sPathBase.substring(0,lPos-1);
           }
          sNuevoEnlace=sNuevoEnlace+sPathBase + "/" +sEnlace;
        }    
        
      }
   }
      return sNuevoEnlace;
}



//Abre una nueva ventana con la URL indicada
function abrirVentana(enlace, w, h, iURL)
{
  var ileft,itop;

  /* Calculamos la posición de la ventana para que salga en el centro */
	ileft=Math.round((window.screen.availWidth-w)/2);
  if (ileft<0) ileft=0;
	itop=Math.round((window.screen.availHeight-h)/2);
  if (itop<0) itop=0;

	/* Si se trata de una URL, mostramos todas las barras de la navegación */  
  if (iURL == 0)
  {
  	win2 = window.open(enlace,'_blank','scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+ileft+',top='+itop); 
  }
  else
  {
  	win2 = window.open(enlace,'_blank','menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,location=yes,width='+w+',height='+h+',left='+ileft+',top='+itop); 
  }    

	/* Ponemos el foco en la nueva ventana */    
  win2.focus();
}
function abrirDocumento(enlace, w, h)
{
  var ileft,itop;

  /* Calculamos la posición de la ventana para que salga en el centro */
	ileft=Math.round((window.screen.availWidth-w)/2);
  if (ileft<0) ileft=0;
	itop=Math.round((window.screen.availHeight-h)/2);
  if (itop<0) itop=0;

	/* mostramos solo las barras de menu */  
  	win2 = window.open(enlace,'_blank','menubar=yes,scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+ileft+',top='+itop); 
	/* Ponemos el foco en la nueva ventana */    
    win2.focus();
}
 //Abre una nueva ventana OCULTA con la URL indicada
function abrirVentanaOculta(enlace)
{
  	win2 = window.open(enlace,'oculta','scrollbars=no,resizable=no,toolbar=no,titlebar=no,status=no,location=no,width=1,height=1,left=0,top=0');  
    self.focus();
}
//funciones relacionadas con los menús Flash
//Captura el nombre del directorio y lo envia al menu flash
function obtenerUrl(){
			//cadenaUrl = location.pathname;
			if(parent.frames[0]){
				cadenaUrl = parent.frames[0].location.href;
			}else{
			 cadenaUrl = location.pathname;
			}
			partesUrl = cadenaUrl.split("/"); // la contrabarra se escribe doble: \\
			seccion= partesUrl[partesUrl.length-2];
			return seccion
	}

//envia el valor de la variable al archivo flash
function pasaVariable() 
{
	if(document.flsMenu)
	{
			document.flsMenu.SetVariable("_root.carpeta",obtenerUrl());
	}
	return 0;
}
//inserta la fecha
function fecha(){
var ahora=new Date();
var anyo=(ahora.getYear()<1000)?ahora.getYear()+1900:ahora.getYear();
var mes=ahora.getMonth()+1;
var dia=ahora.getDate();
mes=(mes<10)?"0"+mes:mes;
dia=(dia<10)?"0"+dia:dia;
  document.write(dia+"."+mes+"."+anyo);
}

//--------------------------------------------------
//	Función para identificar el navegador que está
//	utilizando el cliente
//--------------------------------------------------
function NavegadorIE() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return true;
	} else {
		return false;
	}
}


//--------------------------------------------------
//	Funcions per ocultar les seccions que no es
//	volen imprimir
//--------------------------------------------------
function antesImpresion()
{
  var oItm; 
  for(i = 0; i < document.all.length; i++)
  {
    oItm = document.all(i);
	  if ("clsNoImprimir" == oItm.className) oItm.className = "clsOcultarAlImprimir";
  }
}

function despuesImpresion()
{
  var oItm; 
  for(i = 0; i < document.all.length; i++)
  {
    oItm = document.all(i);
    if ("clsOcultarAlImprimir" == oItm.className) oItm.className = "clsNoImprimir";
  }
}

window.onbeforeprint=antesImpresion;
window.onafterprint=despuesImpresion;