//Procedimientos de control general de Webs
//©2010, zanoni
//THE MIRACLE
//*******************************************************************************
/*METODOS MIEMBROS DE CLASES*/


function Init()
{
if (this.tabla==null)
	{
	ViewPag("off");
	return;
	}
else
	{
	ViewPag("on");	
	};

var a,b,c,n,ref,ref2;
this.items= new Array(this.rango);
this.detail= new Array(this.campos);
this.label= new Array(this.campos);
b= this.rango;
c= this.campos;
for (a=0;a<b;a++)
	{
	ref= this.name + "_registro_" + (a+1).toString();
	this.items[a]= document.getElementById(ref);
	this.items[a].style.cursor= "pointer";
	this.items[a].style.visibility= "hidden";
	};
for (a=0;a<c;a++)
	{
	ref= this.name + "_campo_" + (a+1).toString();
	ref2= this.name + "_etiqueta_" + (a+1).toString();
	this.detail[a]= document.getElementById(ref);
	this.label[a]= document.getElementById(ref2);
	this.detail[a].style.visibility= "hidden";
	this.label[a].style.visibility= "hidden";
	};	
ref= this.name + "_menos";
ref2= this.name + "_mas";
this.menos= document.getElementById(ref);
this.mas= document.getElementById(ref2);
this.menos.style.cursor= "pointer";
this.mas.style.cursor= "pointer";
this.menos.style.visibility= "hidden";
this.mas.style.visibility= "hidden";
this.menos.title= "Retrocede en la lista hacia atrás";
this.mas.title= "Avanza la lista hacia adelante";
ref= this.name + "_leyenda";
this.leyenda= document.getElementById(ref);
ref= this.name + "_portada";
this.portada= document.getElementById(ref);
if (this.opciones!=null)
	{
	n= this.nOpciones;	
	this.itemsOpciones= new Array(n);
	for (a=0;a<n;a++)
		{
		ref= this.name + "_opciones_" + (a+1).toString();
		this.itemsOpciones[a]= document.getElementById(ref);
		this.itemsOpciones[a].style.cursor= "pointer";
		this.itemsOpciones[a].style.visibility= "hidden";
		};	
	};

if(this.portada!=null)
	this.portada.style.visibility= "visible";
	
return;	
}

function opcionClick(n)
{
if (this.opciones==null)
	return;

var opcion,temp,ventana1;
opcion= n;
temp= this.opciones[this.reg-1][opcion];
if (temp=="0")
	return;
switch (opcion)
	{
	case 1:
		AbrirVentana("SOLICITUDES",temp,null,null);
		break;	
	case 2:	
		AbrirVentana("DESCARGAS",temp,1024,768);
		break;	
	};

return;	
}

function mOver(n)
{
if (this.tabla==null)
	return;

var activo= this.inicio+n-1;
var a,b;
b= this.campos;
if (activo>this.registros)
	return;
if (activo==this.reg)
	return;
this.items[n-1].className= this.over;
return;	
}

function mOut(n)
{
if (this.tabla==null)
	return;

var activo= this.inicio+n-1;
var a,b;
b= this.campos;
if (activo>this.registros)
	return;
if (activo==this.reg)
	return;
this.items[n-1].className= this.off;
return;	
}

function mClick(n)
{
if (this.tabla==null)
	return;
if (this.portada!=null)
	this.portada.style.visibility= "hidden";
	
var activo= this.inicio+n-1;
var a,b;
b= this.campos;
if (activo>this.registros)
	return;
if (activo==this.reg)
	return;
if ((this.reg>=this.inicio)&&(this.reg<=(this.inicio+this.rango-1)))
	this.items[this.reg-this.inicio].className= this.off;
this.items[n-1].className= this.on;
this.reg= activo;

for (a=0;a<b;a++)
	{
	this.detail[a].style.visibility= "visible";
	this.label[a].style.visibility= "visible";
	if (navigator.appName=="Netscape")
		this.detail[a].textContent= this.tabla[this.reg-1][a]
	else
		this.detail[a].innerText= this.tabla[this.reg-1][a];
	};

if (this.opciones!=null)
	{
	b= this.nOpciones;
	for (a=0;a<b;a++)
		{
		if (this.opciones[this.reg-1][a+1]=="0")
			this.itemsOpciones[a].style.visibility= "hidden"
		else
			this.itemsOpciones[a].style.visibility= "visible";
		};		
	};

return;	
}

function View()
{
if (this.tabla==null)
	return;

var a,b,c,d,n,m,vacio;
a= this.inicio;
b= this.registros;
c= this.rango;
d= this.campos;
m= this.clave;
vacio= " ";
for (n=0;n<c;n++)
	{
		if (a==this.reg)
			this.items[n].className= this.on
		else
			this.items[n].className= this.off;
		
		if (a>b)
			{
			if (navigator.appName=="Netscape")
				this.items[n].textContent= vacio
			else
				this.items[n].innerText= vacio;
			this.items[n].style.visibility= "hidden";
			}
		else
			{
			if (navigator.appName=="Netscape")
				this.items[n].textContent= this.tabla[a-1][m-1]
			else
				this.items[n].innerText= this.tabla[a-1][m-1];
			this.items[n].style.visibility= "visible";
			};
	a= a+1;	
	};
		
if ((this.inicio+c-1)>=b)
	this.mas.style.visibility= "hidden"
else
	this.mas.style.visibility= "visible";
if (this.inicio==1)
	this.menos.style.visibility= "hidden"
else
	this.menos.style.visibility= "visible";

if (this.leyenda!=null)
	{
	if ((this.inicio+c-1)>b)
		m= b
	else
		m= this.inicio+c-1;
	if (navigator.appName=="Netscape")
		this.leyenda.textContent= "Total:" + this.registros.toString() + " (mostrando del " + (this.inicio).toString() + " al " + m.toString() + ")"
	else
		this.leyenda.innerText= "Total:" + this.registros.toString() + " (mostrando del " + (this.inicio).toString() + " al " + m.toString() + ")";		
	};


return;	
}

function Next()
{
if (this.tabla==null)
	return;

if ((this.inicio + this.rango)<=this.registros)
	this.inicio= this.inicio + this.rango
else
	return;

this.View();	
return;	
}

function Prev()
{
if (this.tabla==null)
	return;

if ((this.inicio - this.rango)>=1)
	this.inicio= this.inicio - this.rango
else
	return;
	
this.View();
return;
}

function InitMenu()
{
var a,b,c,n,ref;
b= this.items.length;
for (a=0;a<b;a++)
	{
	ref= this.name + "_" + (a+1).toString();
	this.items[a]= document.getElementById(ref);
	this.items[a].style.cursor= "pointer";
	};
return;	
}

function menuOver(n)
{
var activo= n;	
if (activo==this.opcion)
	return;
this.items[n-1].className= this.over;		
return;	
}

function menuOut(n)
{
var activo= n;
if (activo==this.opcion)
	return;
this.items[n-1].className= this.off;		
return;
}

function menuClick(n)
{
var activo= n;
var a,b;
if (activo==this.opcion)
	return;
if (this.opcion!=null)
	this.items[this.opcion-1].className= this.off;

this.items[n-1].className= this.on;
this.opcion= activo;	
return;	
}

function menuView()
{
var a,b,c,d,n,m,vacio;
c= this.items.length;
for (n=0;n<c;n++)
	{
	if ((n+1)==this.opcion)
		this.items[n].className= this.on
	else
		this.items[n].className= this.off;
	};	
return;	
}

function menuWeb(pag,marco)						//navega a la pag. web especificada en ventana principal o en marco especificado
{
if (marco==null)
	window.location.href= pag
else
	document.getElementById(marco).src= pag;
return;	
}


function TestLoad(objeto,ref)
{
var test= false;	
if (objeto.readyState!="complete")
	test= false
else
	test= true;

if (test==true)
	{
	window.clearInterval(ref);
	window.location.reload();
	};
return test;	
}

function ViewPag(ver)
{
if (ver=="on")
	{
	document.getElementById("banner").style.visibility= "visible";
	document.getElementById("foot").style.visibility= "visible";
	document.getElementById("main").style.visibility= "visible";		
	};
if (ver=="off")
	{
	document.getElementById("banner").style.visibility= "hidden";
	document.getElementById("foot").style.visibility= "hidden";
	document.getElementById("main").style.visibility= "hidden";	
	};
return;	
}

function CargaXML(base,baseopciones)
{
var navegador= window.navigator.appName;
var ref,ref2,ref3;
ref= this.name + "_" + "ie";
this.ie= document.getElementById(ref);
if (this.archivoOpciones!=null)
	{
	ref2= this.name + "_" + "ieOpciones";
	this.ieOpciones= document.getElementById(ref2);
	};
ref3= "TestLoad(" + this.name + ".ie," + this.name + ".test1)"; 

if (navegador=="Microsoft Internet Explorer")
	{
	if (this.ie.readyState!="complete")
		{
		this.test1= window.setInterval(ref3,1000);
		return false;
		};
	
	var xmldoc= this.ie.XMLDocument;	
	}
else	
	if (window.XMLHttpRequest)
		{
		var xdoc= new XMLHttpRequest();
		xdoc.open("GET",this.archivoTabla,false);
		xdoc.send("");
		var xmldoc= xdoc.responseXML;
		}
	else
		{
		window.alert("Este navegador es obsoleto. Actualícelo, por favor.");
		return false;
		};

var database= xmldoc.getElementsByTagName(base);
var nreg= database.length;		//numero de registros
var nfield= 0;					//numero de campos
var x= database[0].firstChild;
while(x!=null)
	{
	if(x.nodeType==1)
		nfield= nfield+1;
	x= x.nextSibling;
	};
this.tabla= new Array(nreg);
var a,b;
for(a=0;a<nreg;a++)
	{
	x= database[a].firstChild;
	this.tabla[a]= new Array(nfield);
	b= 0;
	while(x!=null)
		{
		if(x.nodeType==1)
			{
			this.tabla[a][b]= x.firstChild.data;
			b= b+1;
			};
		x= x.nextSibling;
		};
	};

if (this.archivoOpciones!=null)
	{
	ref3= "TestLoad(" + this.name + ".ieOpciones," + this.name + ".test2)";
	
	if (navegador=="Microsoft Internet Explorer")
		{
		if (this.ieOpciones.readyState!="complete")
			{
			this.test2= window.setInterval(ref3,1000);
			return false;
			};
	
		var xmldoc= this.ieOpciones.XMLDocument;	
		}
	else	
		if (window.XMLHttpRequest)
			{
			var xdoc= new XMLHttpRequest();
			xdoc.open("GET",this.archivoOpciones,false);
			xdoc.send("");
			var xmldoc= xdoc.responseXML;
			};

	database= xmldoc.getElementsByTagName(baseopciones);
	nreg= database.length;		//numero de registros
	nfield= 0;					//numero de campos
	x= database[0].firstChild;
	while(x!=null)
	{
	if(x.nodeType==1)
		nfield= nfield+1;
	x= x.nextSibling;
	};
	this.opciones= new Array(nreg);
	var a,b;
	for(a=0;a<nreg;a++)
		{
		x= database[a].firstChild;
		this.opciones[a]= new Array(nfield);
		b= 0;
		while(x!=null)
			{
			if(x.nodeType==1)
				{
				this.opciones[a][b]= x.firstChild.data;
				b= b+1;
				};
			x= x.nextSibling;
			};
		};	
	this.nOpciones= this.opciones[0].length -1;			
	};

this.registros= this.tabla.length;
this.campos= this.tabla[0].length;

return true;
}

function calInit()
{
var a,b,c;
//this.fecha.setMonth(5);
this.dia= this.fecha.getDate();
this.ano= this.fecha.getFullYear();
this.mes= this.fecha.getMonth() + 1;
this.semana= this.fecha.getDay();
if (this.semana==0)
	this.semana= 7;
switch (this.mes)
	{
	case 1:
		this.mesLong= "enero";
		break;
	case 2:
		this.mesLong= "febrero";
		break;
	case 3:
		this.mesLong= "marzo";
		break;
	case 4:
		this.mesLong= "abril";
		break;
	case 5:
		this.mesLong= "mayo";
		break;
	case 6:
		this.mesLong= "junio";
		break;
	case 7:
		this.mesLong= "julio";
		break;
	case 8:
		this.mesLong= "agosto";
		break;
	case 9:
		this.mesLong= "septiembre";
		break;
	case 10:
		this.mesLong= "octubre";
		break;
	case 11:
		this.mesLong= "noviembre";
		break;
	case 12:
		this.mesLong= "diciembre";		
	};
switch (this.semana)
	{
	case 1:
		this.semanaLong= "lunes";
		break;
	case 2:
		this.semanaLong= "martes";
		break;
	case 3:
		this.semanaLong= "miércoles";
		break;
	case 4:
		this.semanaLong= "jueves";
		break;
	case 5:
		this.semanaLong= "viernes";
		break;
	case 6:
		this.semanaLong= "sábado";
		break;
	case 7:
		this.semanaLong= "domingo";	
	};
for (a=29;a<=31;a++)
	{
	this.fecha.setDate(a);
	b= this.fecha.getMonth() + 1;
	if (b!=this.mes)
		break;
	};
this.diaultimo= a - 1;
this.fecha.setDate(1);
this.fecha.setMonth(this.mes-1);
this.dia1= this.fecha.getDay();
if (this.dia1==0)
	this.dia1= 7;
return;	
}

//****************************************************************************************
//CLASES GENERICAS
//****************************************************************************************

//Clase para control de menus
function Menu(nombre,boton_off,boton_over,boton_on,opciones,selec)
{
this.name= nombre;
this.off= boton_off;
this.over= boton_over;
this.on= boton_on;
this.items= new Array(opciones);
this.opcion= selec;
this.Init= InitMenu;
this.mOver= menuOver;
this.mOut= menuOut;
this.mClick= menuClick;
this.View= menuView;
this.Web= menuWeb;
}

//Clase para control de lista
function Lista(nombre,boton_off,boton_over,boton_on,archivoTabla,archivoOpciones,rango,campoclave,selec)
{
this.name= nombre;										//nombre del objeto(instancia)
this.off= boton_off;
this.over= boton_over;
this.on= boton_on;
this.items= null;													//matriz de objetos visuales de la lista
this.rango= rango;
this.detail= null;												//matriz de objetos visuales de detalle (campos detalle)
this.label= null;													//matriz de objetos visuales de etiqueta
this.opciones= null;																			//tabla de opciones
this.itemsOpciones= null;																	//tabla de objetos visuales de las opciones
this.menos= null;																					//cursor retroceder
this.mas= null;																						//cursor avanzar
this.tabla= null;																					//tabla de datos principal
this.registros= null;																			//numero de registros
this.campos= null;																				//numero de campos
this.nOpciones= null;																			//numero de opciones
this.inicio= 1;																						//registro inicial visible
this.reg= selec;																					//registro activo seleccionado
this.clave= campoclave;																		//campo clave (1 a N)
this.InitTabla= CargaXML;
this.Init= Init;																					//inicialización principal
this.mOver= mOver;
this.mOut= mOut;
this.mClick= mClick;
this.View= View;
this.Next= Next;
this.Prev= Prev;
this.opcionClick= opcionClick; 
this.leyenda= null;													//objeto visual que muestra la leyenda: numero de items y rango actual - Si es NULL, no hay leyenda	
this.portada= null;																
this.ie= false;																						//objeto XML de Internet Explorer de la lista principal 
this.ieOpciones= false;																		//objeto XML de Internet Explorer de la lista de opciones 
this.test1= null;
this.test2= null;
this.archivoTabla= archivoTabla;
this.archivoOpciones= archivoOpciones;
}

//Clase para control de calendarios
function Calendario(nombre,fondo,celdas,selec)
{
this.name= nombre;										
this.off= fondo;										//estilo del fondo del calendario
this.cell= celdas;										//estilo de las celdas
this.selec= selec;										//dia seleccionado
this.fecha= new Date();
this.items= new Array(6);
this.Init= calInit;
this.dia;												//dia de hoy
this.semana;										//dia de semana de hoy (1:lunes 7:domingo)
this.mes;											//mes de hoy (1-12)
this.ano;											//año de hoy
this.mesLong;										//mes, nombre literal
this.semanaLong;									//dia de semana, nombre literal
this.dia1;											//dia de semana (1-7) del primer dia del mes
this.diaultimo;										//ultimo dia del mes (28,29,30,31)
}


//***********************************************************************************************
//



function ExtenderCapa(caparef,capa)
{
var navegador= navigator.appName;
var ref= document.getElementById(caparef);
var subcapa= document.getElementById(capa);
var ext;
if ((navegador=="Microsoft Internet Explorer")||(navegador=="Opera"))
	ext= parseInt(subcapa.currentStyle.top,10) + subcapa.clientHeight;
if (navegador=="Netscape")
	ext= parseInt(window.getComputedStyle(subcapa,"").getPropertyValue("top"),10) + subcapa.clientHeight;
if (ext>ref.clientHeight)
	ref.style.height= ext.toString() + "px";
return(ext);	
};

function AbrirVentana(titulo,web,x,y)
{
var pantallaAncho,pantallaAlto;
if ((x==null)&&(y==null))
	{
	pantallaAncho= window.screen.availWidth-48;
	pantallaAlto= window.screen.availHeight-48;
	}
else
	{
	pantallaAncho= x;
	pantallaAlto= y;
	};
ventana1= window.open(web,titulo,"width=" + pantallaAncho + ",height=" + pantallaAlto);
ventana1.focus();
ventana1.moveTo(0,0);
return;	
};

function InitPag()
{
//inicializacion de la pag web
var navegador= navigator.appName;
var ventana;
var extension;
if (navegador=="Microsoft Internet Explorer")
	ventana= document.body.parentNode.clientHeight;
if ((navegador=="Opera")||(navegador=="Netscape"))
	ventana= window.innerHeight-1;
extension= document.getElementById("banner").clientHeight + document.getElementById("main").clientHeight + document.getElementById("foot").clientHeight;
if (extension<ventana)
	document.getElementById("main").style.height= (ventana - document.getElementById("banner").clientHeight - document.getElementById("foot").clientHeight).toString() + "px";

var pos= document.getElementById("banner").clientHeight + document.getElementById("main").clientHeight;
document.getElementById("foot").style.top= pos.toString() + "px";

/*
var ancho= window.screen.width;
var x;
if (ancho>1024)
	{
	x= (ancho/2)-512;
	document.getElementById("banner").style.left= x.toString() + "px";
	document.getElementById("foot").style.left= x.toString() + "px";
	document.getElementById("main").style.left= x.toString() + "px";
	};
*/
document.getElementById("banner").style.visibility= "visible";
document.getElementById("foot").style.visibility= "visible";
document.getElementById("main").style.visibility= "visible";

return;	
};




