function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function inicializaDescriptores()
{
	for (i=0;i<g_arrTipoCategoria.length;i++) 
	{
			//rescata error para los descriptores ocultos
			try
			{
				eval("document.getElementById('Descriptor" + g_arrTipoCategoria[i] + i + "').style.display='none'")
				eval("document.getElementById('Descriptor" + g_arrTipoCategoria[i] + i + "t').style.display='none'")
				document.getElementById("DescriptorTR").style.display='none'
			}
			catch(exc){}
	}

}

function VisualizaDescriptoresPorCategoria(idCategoria)
{
		
		
		if (idCategoria != "")
		{			
			inicializaDescriptores()
		}
		
		for (i=0;i<g_arrTipoCategoria.length;i++) 
		{		
			if (g_arrTipoCategoria[i] == idCategoria)
			{	
				//rescata error para los descriptores ocultos
				try
				{			
					document.getElementById("DescriptorTR").style.display=''
					eval("document.getElementById('Descriptor" + idCategoria + i + "').style.display=''")
					eval("document.getElementById('Descriptor" + idCategoria + i + "t').style.display=''")
				}
				catch(exc){}
			}
		}	
		
}

function CargaDescriptoresPorCategoria(idCategoria,idMaterial)
{

		var ValorDescriptor  = ""
		var NombreDescriptor = ""
		
		document.write ("<table class='txttabla'><tr>")
		for (i=0;i<g_arrTipoCategoria.length;i++) 
		{		
			
				oLista = ""
				if (g_arrIDCampoDescriptor[i]==1) //Texto
				{
					// Se rescata dinamicamente el campo descriptor y ademas asigna la validacion a este.
					try
					{
						//rescata  el nombere y valor del descriptor tipo texto
						NombreDescriptor = eval('DescriptorName' + i)
												
						for (var Cont=0;Cont<g_arrTipoCategoria.length;Cont++) 
						{
						   if (NombreDescriptor == g_arrNombreDescriptor[Cont])
						   {
							  ValorDescriptor = eval('DescriptorValue' + i)
						   }
						}
						
					    // Se asigna la validación al descriptor
						switch(g_arrIDTipoDato[i])
						{
							case "1":
							  varTipoDato = "ValidarCaracter('Numerico','', false);"  
							  break;	
							  
							case "2":
							  varTipoDato = "ValidarCaracter('Texto','', false);"
							  break;						
							  
							case "3":
							  varTipoDato = "ValidarCaracter('Alfanumerico','', false);"
							  break;
						}
					}
					catch(exp)
					{
						
						switch(g_arrIDTipoDato[i])
						{
							case "1":
							  varTipoDato = "ValidarCaracter('Numerico','', false);"  
							  break; 	
							case "2":
							  varTipoDato = "ValidarCaracter('Texto','', false);"
							  break;						
							case "3":
							  varTipoDato = "ValidarCaracter('Alfanumerico','', false);"
						      break;
						}
						
					}
					
					var oOption="<INPUT  class='campos' TYPE='text' name='Descriptor|" + g_arrNombreDescriptor[i] + "' maxlength='100' value = '" + ValorDescriptor + "' onkeypress=\"" + varTipoDato + "\">"
				}

				if (g_arrIDCampoDescriptor[i]==2) //Lista
				{
				
					var sw = 0
					var DescriptorListaSelected
					
					try
					{					
						//rescata  el nombere y valor del descriptor tipo Lista
						NombreDescriptor = eval('DescriptorName' + i)
												
						for (Cont=0;Cont<g_arrNombreDescriptor.length;Cont++) 
						{
						
						   if (NombreDescriptor == g_arrNombreDescriptor[Cont])
						   {
								ValorDescriptor = eval('DescriptorValue' + i)								
						   }
						}
					}
					catch(exc){}
					
					var oOption="<Select  class='campos' name='Descriptor|" + g_arrNombreDescriptor[i] + "'>"
													
					//opcionb todos cuando no se selecciona ningun valor de un descriptor lista
					oOption = oOption + "<option name='TodosDescriptores' Selected>Todos</option>"
					for (j=0;j<g_arrIDDescriptorLista.length;j++) 
					{
						
						if (g_arrIDDescriptor[i] == g_arrIDDescriptorLista[j])
						{
							
							if (ValorDescriptor == g_arrNombreLista[j])	{DescriptorListaSelected	= "selected"}
							else {DescriptorListaSelected	= ""}
						
							oLista = "<option name='" + g_arrNombreLista[j] + "'" + DescriptorListaSelected + ">" + g_arrNombreLista[j] + "</option>" + oLista							
						}
						sw = 1
					}	
				}

				if ((i % 3) == 0)
				{
					document.write ("<tr>")
				}	
			
				// oculta los descriptores
   				if (navigator.appname == "Internet Explorer")
		        {
					document.write ("<td style='display=none' id='Descriptor" + g_arrTipoCategoria[i] + i + "' class='titulo'><b>" + g_arrNombreDescriptor[i] + "<b></td>")
					document.write ("<td style='display=none' id='Descriptor" + g_arrTipoCategoria[i] + i + "t'>" + oOption)
			    }
		        else
		        {
					//Mozilla y opera
					document.write ("<td id='Descriptor" + g_arrTipoCategoria[i] + i + "' class='titulo'><b>" + g_arrNombreDescriptor[i] + "<b></td>")
					document.write ("<td id='Descriptor" + g_arrTipoCategoria[i] + i + "t'>" + oOption)
		            document.getElementById("Descriptor" + eval(g_arrTipoCategoria[i] + i)).style.display="none"
					document.getElementById("Descriptor" + eval(g_arrTipoCategoria[i] + i) + "t").style.display="none"
				}
						
				
				if 	(sw == 1) {	document.write (oLista + "</select></td>")	}
 
		}	
		document.write ("</tr></table>")
}


function FindDoc()
{
    if (eval("document.getElementById('Avanzadas').style.display") != "none")
    {			           
		  document.frmBiblioteca.hdd_Avanzadas.value = "1"	
	}
    else
    {        
		 document.frmBiblioteca.hdd_Avanzadas.value = "0";
	}
		
	DiaInicio = document.frmBiblioteca.DiaInicio.value
	if (document.frmBiblioteca.DiaInicio.value < 10)
	{
		DiaInicio = "0" + document.frmBiblioteca.DiaInicio.value
	}
			
	MesInicio = document.frmBiblioteca.MesInicio.value
	if (document.frmBiblioteca.MesInicio.value < 10)
	{
		MesInicio = "0" + document.frmBiblioteca.MesInicio.value			
	}
				
	DiaFin = document.frmBiblioteca.DiaFin.value
	if (document.frmBiblioteca.DiaFin.value < 10)
	{
		DiaFin = "0" + document.frmBiblioteca.DiaFin.value
	}
			
	MesFin = document.frmBiblioteca.MesFin.value
	if (document.frmBiblioteca.MesFin.value < 10)
	{
		MesFin = "0" + document.frmBiblioteca.MesFin.value
	}
		
	fechainicio	= DiaInicio + "/" + MesInicio + "/" + document.frmBiblioteca.AnoInicio.value; 
	fechafin	= DiaFin + "/" + MesFin + "/" + document.frmBiblioteca.AnoInicio.value;
	
	if(fechas(fechainicio)== false)
	{
		alert("Fecha Inicio Incorrecta");		
		return false
	}
		
	if(fechas(fechafin)== false)
	{
		alert("Fecha Termino Incorrecta");
		return false
	}

	document.frmBiblioteca.submit();
}


function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}
function activarfecha(FechaActiva){

	if (document.forms[0].FechaActiva.checked || FechaActiva == 1)
	{
		document.forms[0].DiaInicio.disabled=false;
		document.forms[0].MesInicio.disabled=false;
		document.forms[0].AnoInicio.disabled=false;
		document.forms[0].DiaFin.disabled=false;
		document.forms[0].MesFin.disabled=false;
		document.forms[0].AnoFin.disabled=false;		
	}
	else
	{
		document.forms[0].DiaInicio.disabled=true;
		document.forms[0].MesInicio.disabled=true;
		document.forms[0].AnoInicio.disabled=true;
		document.forms[0].DiaFin.disabled=true;
		document.forms[0].MesFin.disabled=true;
		document.forms[0].AnoFin.disabled=true;				
	}
}

	function AsignaSubCategorias(idCategoria,idSubcategoria,TipoID)
	{

		var ArrayNombreSubcategoria;
		var ArrayIDCategoria;
		var	ArrayIDSubCategoria;
		
		ArrayNombreSubcategoria = SubcategoriasNombreJS.split(",");
		ArrayIDCategoria	    = CategoriasIDJS.split(",");
		ArrayIDSubCategoria	    = SubcategoriasIDJS.split(",");
		ArrayIDTipoBiblioteca   = TipoBibliotecaIDJS.split(",");
		
		document.forms[0].cbsubCat.length = 0
		document.forms[0].cbsubCat.options[document.forms[0].cbsubCat.length]	= new Option("Todas",0);
		document.forms[0].cbsubCat.options[0].title = "Todas";

		PosSubCat = 0;
		Pos=0
		Largo = 0
		
		for (i=0;i<ArrayNombreSubcategoria.length - 1;i++)
		{
			if (ArrayIDCategoria[i] == idCategoria)
			{
					
				if (ArrayIDSubCategoria[i] == idSubcategoria)
				{	
					document.forms[0].cbsubCat.options[document.forms[0].cbsubCat.length] = new Option(ArrayNombreSubcategoria[i], ArrayIDSubCategoria[i]);					
					document.forms[0].cbsubCat.options[PosSubCat + 1].title = ArrayNombreSubcategoria[i];
					Pos = PosSubCat
				}
				else
				{					
					document.forms[0].cbsubCat.options[document.forms[0].cbsubCat.length]	= new Option(ArrayNombreSubcategoria[i], ArrayIDSubCategoria[i]);
					document.forms[0].cbsubCat.options[PosSubCat + 1].title = ArrayNombreSubcategoria[i];
					PosSubCat = PosSubCat + 1
				}
			}
					
			if (idCategoria==0)
			{
				// Rescata las sub categorias del tipo biblioteca
				if  (ArrayIDTipoBiblioteca[i] == TipoID)
				{
					
					if (ArrayIDSubCategoria[i] == idSubcategoria)
					{	
						document.forms[0].cbsubCat.options[document.forms[0].cbsubCat.length]= new Option(ArrayNombreSubcategoria[i], ArrayIDSubCategoria[i]);					
												
						if (document.forms[0].cbsubCat.length > 0) 	{Largo=document.forms[0].cbsubCat.length - 1}
						document.forms[0].cbsubCat.options[Largo].title = ArrayNombreSubcategoria[i];
						Pos = i
					}
					else
					{									
						document.forms[0].cbsubCat.options[document.forms[0].cbsubCat.length]	= new Option(ArrayNombreSubcategoria[i], ArrayIDSubCategoria[i]);
						if (document.forms[0].cbsubCat.length > 0) 	{Largo=document.forms[0].cbsubCat.length - 1}
						document.forms[0].cbsubCat.options[Largo].title = ArrayNombreSubcategoria[i];
					}
				}				
			}
		}
		
		if (idSubcategoria == 0)
		{
			Pos = Pos - 1	
		}

		document.forms[0].cbsubCat.options[Pos + 1].selected=true
		
		VisualizaDescriptoresPorCategoria(idCategoria)
		
	}
	
function MostrarTabla(activo)
{
		if (activo == "0") 
		{
			eval("document.getElementById('Avanzadas').style.display = 'none'") 
		}
		else
		{
			if (activo=="0")
			{
				eval("document.getElementById('Avanzadas').style.display = 'none'")    
			}

			if (activo=="1")
			{
				
				eval("document.getElementById('Avanzadas').style.display = ''")             
			}
		}
}
	
function ocultar(elemento)
{
			if (eval("document.getElementById('" + elemento + "').style.display") != "none")
            {			           
					eval("document.getElementById('" + elemento + "').style.display = 'none'") 
					document.frmBiblioteca.FechaActiva.checked=false;
					document.frmBiblioteca.NombreArchivo.value = ""					
					document.frmBiblioteca.Campos.options[0].selected=true
					document.frmBiblioteca.TipoArchivo.options[0].selected=true
	        }
            else
            {        
					eval("document.getElementById('" + elemento + "').style.display = ''") 		
			}                                                    
}
