/********Rutinas generales para los casos Javascript***********/
/***Objetos globales definidos aquí**********/

function oNavegador(  ) {
	this.nombre = navigator.appName;
	this.iniciar = iniciar;
	this.ponerModVer = ponerModVer;
	this.IE = this.nombre.toUpperCase().indexOf('MICROSOFT') >=0;
	this.NS = this.nombre.toUpperCase().indexOf('NETSCAPE') >=0;
	this.OP = this.nombre.toUpperCase().indexOf('OPERA') >= 0;
	this.XX = !this.IE && !this.NS && !this.OP;
	this.version = this.iniciar();
	this.Verent = parseInt(this.version);
	this.standard = (this.IE && this.Verent >=5) || (this.NS && this.Verent >=5)
	this.modVer = this.ponerModVer();
/* ======================================================================
	FUNCION:	iniciar( ), miembro de oNavegador
	ARGS: 		none.
	DEVUELVE:	nada
	DESCRIP:	Inicializa los valores del objeto
====================================================================== */
  function iniciar() {
  var ver = navigator.appVersion;
  if(ver+"" != "NaN")
	if (this.IE)
		{
		ver.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
  		ver = RegExp.$3;
		}
  return ver;
  } //Termina la funcion iniciar el objeto
 //Selector para usar en sentencias switch
 //Los modelos de navegadores serán de la forma IE4, IE5, NS4, NS5 ...
  function ponerModVer()
  {
  if (this.IE) return "IE"+this.Verent;
  if (this.NS) return "NS"+this.Verent;
  if (this.OP) return "OP"+this.Verent;
  return "XXNN";
   }
}

window.miNavegador = new oNavegador()
window.miNavegador.iniciar();
var mie = "IE4, IE5, IE6, NS5".indexOf(miNavegador.modVer)>=0;
var version=navigator.appVersion, verex;
if ( window.miNavegador.IE ) 
{
   version.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
   verex = RegExp.$3;
}
//Busca un valor de estilo en un descriptor. Solo MSIE <5
//no llamar con otro explorador
function estiloActual(obj, estilo, atributo)
{
var regla;
var devolver=null
//Si el estilo está definido en linea
if (miNavegador.NS && miNavegador.version < 5) return obj[atributo];
if (obj.style[atributo] != '') return obj.style[atributo]
if (verex >=5)
	devolver = obj.currentStyle[atributo]
else{
	regla = buscaEstilo(estilo)
	devolver = regla.style[atributo];	
	}
return devolver;
}

function buscaEstilo(estilo)
{
var hj, fin, hojas = document.styleSheets;
for (hj = 0; hj < hojas.length; hj++)
	{
	reglas = hojas[hj].rules;
	for (ti=0; ti< reglas.length; ti++)       
		{
		if (reglas[ti].selectorText.toUpperCase() == '.'+estilo.toUpperCase())
			{
			devolver = reglas[ti];	
			fin = true;
			break;
			}
		}	
	if (fin) break;		
	}		
return reglas[ti];
}
//Cambia el valor de un atributo (MSIE)
function atributoClase(nombre, atributo, valor)
{
var regla = buscaEstilo(nombre)
regla.style[atributo] = valor;
}


function objHtml(n, d) { 
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
  if (d.getElementById) 
  		x = d.getElementById(n);
  if(!x && !(x=d[n]) && d.all) 
      x=d.all[n]; 
  for (i=0; !x && i<d.forms.length; i++) 
      x=d.forms[i][n];
  for(i=0; !x && d.layers &&i< d.layers.length; i++) 
      x=objHtml(n,d.layers[i].document); 
  return x;
}

function cambImg() {
var i,j=0,x,a=cambImg.arguments; 
document.arIm=new Array; 
for(i=0;i<(a.length-2);i+=2)
if ((x=objHtml(a[i]))!=null){
    document.arIm[j++]=x; 
    if(!x.oSrc) x.oSrc=x.src; 
    x.src=a[i+1];}
}
function restImg() { 
  var i,x,a=document.arIm;
 for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Precarga de imágenes */
/*Argumentos: nombres y situación de imágenes a precargar*/
function precargaImags() { 
 if(document.images){ 
     if(!document.prs) 
        document.prs=new Array();
 var i,j=document.prs.length,args=precargaImags.arguments; 
 for(i=0; i<args.length; i++)
    { document.prs[j]=new Image; document.prs[j].src=args[i]; j++}}
}

function ultActual() {
var cfecha = document.lastModified;
return fechaDia(cfecha);
}

function fechaDia(cfecha)
{
var meses = new Array("Enero", "Febrero","Marzo","Abril","Mayo","Junio",
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var fecha
if (cfecha)
	fecha = new Date(Date.parse(cfecha));
else
	fecha = new Date();
var dia = fecha.getDate();
var mes = meses[fecha.getMonth()];
var agno = fecha.getFullYear();
if (agno <= 1900)
	agno += 100
return (dia +" de "+mes +" de "+agno);
}
function mostrarCapa(obj)
{
var eleHtml = objHtml(obj)
if (eleHtml.style)
	eleHtml.style.visibility = "visible"
else	
	eleHtml.visibility = "visible"
}

function mostrarBlq(obj, sino)
{
var estado;
if (arguments.length >1)
	{
	estado = sino?'visible':'hidden';
	if (miNavegador.standard)
		obj.style.visibility = estado;
	else 
		obj.visibility = estado;
	}		
else
	{
	if (miNavegador.standard)
		estado = obj.style.visibility;
	else 
		estado = obj.visibility;
	}	
return estado;		
}
function ctrlError()
{
return true;
}
//window.onerror = ctrlError;

function cambProp(objeto,Prop,Valor) { 
  var obj;
  if (objeto.id) obj = objeto;
  else obj = objHtml(objeto);
  if (!obj) return;
  if (miNavegador.standard || (miNavegador.IE && miNavegador.Verent == 4))
  	{
	if (obj[Prop])
	    obj[Prop]=Valor;    
	else
	    obj.style[Prop]=Valor;    
	if (obj.style.cursor == "hand")
		obj.style.cursor = "default";
	else
		obj.style.cursor = "hand"	
	}  
  else {
	if (Prop == "className")
		if (document.classes[Valor].all.backgroundColor)
			obj.bgColor = document.classes[Valor].all.backgroundColor;
		else
			obj.bgColor = null;	
	else
		obj[Prop] = Valor;	 	
    }
}

function posAbsY(obj)
{
if (obj.offsetParent!=null)
	return obj.offsetTop+posAbsY(obj.offsetParent)
return obj.offsetTop;
}
function posAbsX(obj)
{
if (obj.offsetParent!=null)
	return obj.offsetLeft+posAbsX(obj.offsetParent)
return obj.offsetLeft;
}
//Alto del documento en la ventana
function altoDoc()
{
var i, max = 0;
var colec;
if (miNavegador.standard)
	{
	if (miNavegador.IE)
		{
		max=document.body.scrollHeight;	
		colec = document.all.tags('Div');
		}
	else	
		colec = document.getElementsByTagName('Div');
	for (i=0; i < colec.length; i++)
		max = Math.max(posAbsY(colec[i])+colec[i].offsetHeight, max);
	}
  else 	
	max = document.Height ;
return max;
}
function ponerPie(nombPie)
{
if(miNavegador.IE && document.readyState != 'complete')
	{
	setTimeout("ponerPie('"+nombPie+"')", 500);
	return;
	}

var altura;
var pie = objHtml(nombPie);
if (!pie) return;
if (miNavegador.standard || miNavegador.IE)
	{
	altura = altoDoc();
	pie.style.top = altura;
	pie.style.left = 30;
	pie.style.visibility = 'visible';
	pie.style.zIndex = 0;
	}
else
	{
	pie.top = document.height;
	document.height += pie.clip.height;
	pie.visibility = 'visible';
	}
}
//fin de rutbasicas
/*================================================================================
FUNCION:	Constructor del objeto oVentana
ARGS:		Obj:	objeto Html ligado
			clase:	estilo CSS usado para el objeto ventana
DEVUELVE:	-----
DESCRIP.:
El objeto oVentana es un objeto ligado a un bloque DIV de la página HTML usado para el
texto que se va a desplazar dentro de una ventana contenedora representada por el objeto 
oPersiana.
Sus propiedades y métodos son:
Propiedades:
	elemDiv		Objeto HTML ligado (un bloque DIV)
	estilo		estilo CSS
Métodos	
	escribir	Rellenar el elemento HTML
	mover		Mover el elemento
	situar		Colocar la capa en una posición
	leerX		Lee la posición horizontal			
	leerY		Lee la posición vertical
	Alto		Pone la altura del objeto
	Ancho		Pone la anchura del objeto
================================================================================*/
function oVentana(obj, clase)
{
this.elemDiv = obj;
this.estilo = clase;
this.escribir = oVentana_escribir;
this.mostrar = oVentana_mostrar;
this.mover = oVentana_mover;
this.situar = oVentana_situar;
this.leerX = oVentana_X;
this.leerY = oVentana_Y;
this.Alto = oVentana_Alto;
this.Ancho = oVentana_Ancho;
}	

function oVentana_mostrar(sino)
{
var estado = (sino)?"visible":"hidden";
if (miNavegador.standard || miNavegador.modVer == "IE4")
	this.elemDiv.style.visibility = estado;
else	
	this.elemDiv.visibility = estado;

}
function oVentana_escribir(cadena, ancho)
{
var capa = this.elemDiv;
switch (miNavegador.modVer){
case "IE4":
case "IE5":
case "IE6":
case "NS5":
	capa.innerHTML = cadena;
	break;
case "NS4":
	capa = capa.document;
	var hija = capa.id;
	var objest = document.classes[this.estilo].all;
	with (capa.ids[hija]){
		fontsize = objest.fontsize; 
		fontfamily = objest.fontfamily;
		fontWeight = objest.fontWeight;
		fontStyle = objest.fontStyle;
		textDecoration = objest.textDecoration;
		textAlign =  objest.textAlign;
		color = objest.color;
		paddingRight = objest.paddingRight;
		paddingLeft= objest.paddingLeft;
		paddingTop = objest.paddingTop;
		paddingBottom = objest.paddingBottom;
		}
	if (ancho)
		{
		capa.open()	
		capa.write('<div style="width:'+ancho+'px" >'+cadena+'</div>')
		capa.close()
		}
	else	
		{
		capa.open()
		capa.write('<div id="'+hija+'" >'+cadena+'</div>')
		capa.close()
		}
	}
}

function oVentana_mover(incx, incy)
{
var capa = this.elemDiv
if	(capa.style)
	{
	capa.style.left = parseInt(capa.style.left) + incx;
	capa.style.top = parseInt(capa.style.top) + incy;
	}
else
	{
	capa.left += incx;
	capa.top += incy;
	}	
}

function oVentana_situar(x,y)
{
var capa = this.elemDiv
if (capa.style)
	{
	capa.style.left = x+'px';
	capa.style.top = y+'px';
	}
else
	{
	capa.left = x;
	capa.top = y;
	}
}

function oVentana_X()
{
if (this.elemDiv.style)
	return parseInt(this.elemDiv.style.left);
else	
	return this.elemDiv.left;
}

function oVentana_Y()
{
if (this.elemDiv.style)
	return parseInt(this.elemDiv.style.top)
else
	return this.elemDiv.top;	
}

function oVentana_Alto(arg)
{
if (this.elemDiv.style)
	if (!arg)
		return this.elemDiv.offsetHeight;
	else	
		this.elemDiv.style.height = arg + "px";
else
	if (!arg)
		return this.elemDiv.clip.height;
	else	
		this.elemDiv.clip.height = arg;
}

function oVentana_Ancho(arg)
{
if (this.elemDiv.style)
	if (!arg)
		return this.elemDiv.style.offsetWidth;
	else	
		this.elemDiv.style.width = arg + "px";
else
	if (!arg)
		return this.elemDiv.clip.width;
	else	
		this.elemDiv.clip.right = arg;
}
//FIN DEL OBJETO oVentana
/*=====================================================================================
OBJETO oPersiana.
Es una ventana delante de la cual se va desplazando en vertical un conjunto de textos.
Está formado por una ventana contenedora y dos ventanas hijas: una de ellas contiene el
texto que está visible y la otra contiene el texto que sustituirá al actual. Las ventanas
hijas son objetos tipo oVentana.
Propiedades
	marco 		Marco ventana principal, es un objeto oVentana
	estilo		estilo CSS del marco
	textos		Lista de textos que recorreran el marco
	txtind 		Indice del texto actual en la lista
	pausa 		Pausa entre textos
	sent		Sentido del movimiento. 1= Ar-Ab, -1= Ab-Ar
	veloc 		Rapidez del movto
	movil		Marco hijo
Métodos	
	actualizar 	Mover hijo
	preparaHija	Inicializa una ventana hija

FUNCION:	Constructor del objeto oPersiana
ARGS:		Marco:	ID del bloque HTML que forma la ventana contenedora
			veloc:	un número que indica la rapidez con la que se desplazará el texto
			textos: array con los textos que aparecerán en la ventana
			sent: 	Sentido del movimiento del texto. 1= Ar-Ab, -1= Ab-Ar
			pausa: 	número indicando el tiempo que el texto permanecerá en reposo
			estilo:	nombre del estilo CSS usado para la ventana contenedora. 
				
DEVUELVE:	---
DESCRIP:	Constructor del objeto persiana
}
=====================================================================================*/
function oPersiana(idMarco, veloc, textos, sent, pausa, estilo)
{
var capa, hija, obj = objHtml(idMarco);
this.marco = null;
this.estilo = estilo;
this.textos = textos.slice(0);
this.txtind = 0;
this.pausa = pausa;
this.sent = sent;
this.veloc = veloc;
this.movil = new Array(null, null);
this.movact = 0;
this.actualizar = oPersiana_actualizar;
this.preparaHija = oPersiana_preparaHija;
//Crea la ventana del marco contenedor
this.marco =new oVentana(obj, this.estilo);
//Crea las capas hijas
capa = '<div id="'+idMarco+'_h1" style="position: absolute; "></div>'
capa +='<div id="'+idMarco+'_h2" style="position: absolute; "></div>'
this.marco.escribir(capa, this.marco.Ancho());
this.marco.mostrar(true);
//Crea las dos ventanas móviles usadas
for(n=0; n<2; n++)
	{
	switch (miNavegador.modVer){
		case "IE4":
			hija = this.marco.elemDiv.children[n];
			hija.style.paddingLeft = "4px";
			hija.style.paddingTop = "4px";
			break;
		case "IE5":
		case "IE6":
		case "NS5":
			hija = this.marco.elemDiv.childNodes[n];
			hija.style.paddingLeft = "4px";
			hija.style.paddingTop = "4px";			
			break;
		case "NS4":
			hija = this.marco.elemDiv.document.layers[n];
		}	
	this.movil[n] = new oVentana( hija, this.estilo);
	}	
//Inicializa la primera ventana hija
this.preparaHija(0);
this.preparaHija(1);
}
/*=====================================================================================
FUNCION:	Método del objeto oPersiana: oPersiana_preparaHija(n)
ARGS:		número de la ventana hija
DEVUELVE:	---
DESCRIP:	Prepara una ventana hija colocándole el texto que se mostrará y situándola
			fuera de la ventana contenedora. La posición vertical deberá ser tal que 
			la ventana queda debajo de la que en un momento dado se está mostrando, o
			sea, la hija 1 deberá quedar debajo de la 0 y viceversa.
=====================================================================================*/
function oPersiana_preparaHija(n)
{
this.movil[n].mostrar(false);
this.movil[n].escribir(this.textos[this.txtind]);
//La sitúa bajo la ventana anterior
if (this.sent >0)
	this.movil[n].situar(1, -Math.max(this.movil[n].Alto(),this.marco.Alto()));
else
	this.movil[n].situar(1, Math.max(this.movil[1-n].Alto(),this.marco.Alto()));
this.movil[n].mostrar(true);
}
/*=====================================================================================
FUNCION:	Método del objeto oPersiana: oPersiana_actualizar(arg)
ARGS:		cadena identificador de la persiana
DEVUELVE:	---
DESCRIP:	Actualiza el contenido de la ventana principal desplazando adecuadamente
			las ventanas hijas.
=====================================================================================*/
function oPersiana_actualizar(arg)
{
var objPers=eval(arg);
var tmp = objPers.veloc;
var act = objPers.movact;
var sig = 1-act;
var movil = objPers.movil[act];
var sigmov = objPers.movil[sig];
var marco = objPers.marco;
var fin, ind = 0;
movil.mover(0, objPers.sent)
if (sigmov) 
	sigmov.mover(0, objPers.sent)
fin = movil.leerY() == 0;
if (!fin)
	setTimeout(arg+".actualizar('"+arg+"')", tmp);
else
	{
	tmp = tmp*objPers.pausa;
	objPers.txtind++;
	if (objPers.txtind >= objPers.textos.length)
		objPers.txtind = 0;
	objPers.movact = 1-objPers.movact;
	objPers.preparaHija(objPers.movact);
	setTimeout(arg+".actualizar('"+arg+"')", tmp);
	}
}

