//<!-- Variables globales -->
<!--

var nn  = (document.layers) ? true : false;
var ie  = (document.all) ? true : false;
var ie5 = (ie && navigator.appVersion.indexOf("5.") >= 0) ? true : false;
var n6  = (navigator.userAgent.indexOf('Gecko') != -1) ? true : false;

//almacena capas
var ly;
informaCapas();

function informaCapas(){

				 //Se repite porq nn4.x no inicializa bien los campos si fuera de function
				 nn  = (document.layers) ? true : false;
				 ie  = (document.all) ? true : false;
				 ie5 = (ie && navigator.appVersion.indexOf("5.") >= 0) ? true : false;
				 n6  = (navigator.userAgent.indexOf('Gecko') != -1) ? true : false;


	 if (n6)
	 {
	   document.layers = document.getElementsByTagName('div');
		   for ( var i=0 ; i < document.layers.length - 1 ; i++ ) // Crea un array asociativo con las capas.
			     document.layers[document.layers[i].id] = document.layers[i];
			 nn=false;
		}

		if(nn || n6) ly = document.layers;
		if(ie)  ly = document.all;

}

//<!-- Lista -->
var time;

function colocaCabecera(nombreLista, numCols){
		for (i=1 ; i<= numCols ; i++){
				var cabecera = document.getElementById(nombreLista+"_cabeceraCol"+i).offsetWidth;
				var fila = document.getElementById(nombreLista+"_filaCol"+i).offsetWidth;
				if (cabecera < fila){
					 	var anchoCol = document.getElementById(nombreLista+"_filaCol"+i).offsetWidth;
					  document.getElementById(nombreLista+"_cabeceraCol"+i).width = anchoCol;
						document.getElementById(nombreLista+"_filaCol"+i).width =  anchoCol;
				}
				else{
					 var anchoFil = document.getElementById(nombreLista+"_cabeceraCol"+i).offsetWidth;
					 document.getElementById(nombreLista+"_filaCol"+i).width = anchoFil;
					 document.getElementById(nombreLista+"_cabeceraCol"+i).width = anchoFil;	
			 }
		}
}

function scroll(c, mov)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
	
	var altocapa = AltoCapa(c);
	
	if ( (mov > 0  && getTopClip(c) <= 0 ) || (mov < 0  && getBottomClip(c) > altocapa )    ) 	
  	return;

  if(mov < 0 && (altocapa - getBottomClip(c)) < (0-mov)) {mov = getBottomClip(c) - altocapa ;}
	if(mov > 0 && (getTopClip(c)-mov) <= 0) {mov = getTopClip(c) ;}
  
	MueveCapa(c, leftCapa(c), topCapa(c)+ mov);
	setTopClip(c, getTopClip(c) - mov);
	setBottomClip(c, getBottomClip(c) - mov);

 	time = setTimeout('scroll("'+ c +'",'+ mov +')', 100);
} 

function stopScroll()
{
	if (time) clearTimeout(time);
}

function scrollLista(c, mov, altocapa)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
	if ( (mov > 0  && getTopClip(c) <= 0 ) || (mov < 0  && getBottomClip(c) >= altocapa )    ) 	
	{
		return;
	}
  if(mov < 0 && (altocapa - getBottomClip(c)) < (0-mov)) {mov = getBottomClip(c) - altocapa ;}
	if(mov > 0 && (getTopClip(c)-mov) <= 0) {mov = getTopClip(c) ;}

	
	MueveCapa(c, leftCapa(c), topCapa(c)+ mov);
	setTopClip(c, getTopClip(c) - mov);
	setBottomClip(c, getBottomClip(c) - mov);
	
	time = setTimeout('scrollLista("'+ c +'",'+ mov +','+ altocapa +')', 200);
} 

function MueveCapa(c, x, y) // c = nombre de capa
{
//alert( "mueve "+ly[c].id + "x "+x+"_y "+y);

 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
	if(nn) ly[c].moveTo(x, y);
	if(ie || n6) { ly[c].style.left = x; ly[c].style.top = y; }
	
}

function enviaForm(capa, indexFormulario, eValue, objReferencia)
{
  var formulario = document.layers[capa].document.forms[indexFormulario];
  var nombre = objReferencia.name;
	var campo = eval("formulario."+nombre);

	formulario.e.value = eValue;
	campo.value = objReferencia.value;

	var indice = capa.substring((capa.length-1),capa.length);
  indice = parseInt(indice)-1;

	if(validarCampos(indice)) formulario.submit();
	
}
function copiaValorRadio(capa, indexFormulario, objReferencia)
{
  var formulario = document.layers[capa].document.forms[indexFormulario];
  var nombre = objReferencia.name;
	var campo = eval("formulario."+nombre);

	campo.value = objReferencia.value;
}

function OcultaCapas(capasVisibles)
{
	var name;
	for(var i=0; i<ly.length; i++)
	{
	 name = ly[i].name;
	 if(name.indexOf(capasVisibles) == -1)
	 {
	 		 if(nn) ly[i].visibility = 'hidden';
			 if(ie || n6) ly[i].style.visibility = 'hidden';														
	 }
	 
	}
}

function cambiaNombre(obj, prefijo)
{
 	if(obj.type == "text" && obj.value != obj.defaultValue && obj.name.indexOf(prefijo) == -1) obj.name = prefijo + obj.name;
 	else if(obj.name.indexOf(prefijo) == -1)	obj.name = prefijo + obj.name;
}

function cambiaNombreValor(obj, layerName, indexFormulario, prefijo)
{
 		if((obj.type == "text" && obj.value != obj.defaultValue) || obj.type == "select-one")
		{
		 		var formulario = document.layers[layerName].document.forms[indexFormulario];
				var objGlobal;
				if(obj.name.indexOf(prefijo)==-1)
				{
				 	  objGlobal = formulario.elements[obj.name];
						objGlobal.name = prefijo + objGlobal.name;
						obj.name = prefijo + obj.name;
				} else {
						objGlobal = formulario.elements[obj.name.substring(2)];
				}
				if(obj.type == "text") objGlobal.value = obj.value;
				else {
						objGlobal.value = obj.options[obj.selectedIndex].value;
				}
		}
}

function getTopClip(c)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn)  return ly[c].clip.top; 
  if (ie || n6) return parseInt( ly[c].style.clip.split(" ")[0].replace(/rect\(/, "") );
}

function getBottomClip(c)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn)  return ly[c].clip.bottom; 
  if (ie || n6) return parseInt( ly[c].style.clip.split(" ")[2] );
}


function setTopClip(c, top)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn)  ly[c].clip.top = top;
  if (ie || n6)
  {
		var clip = ly[c].style.clip.split(" ");
    ly[c].style.clip = 'rect('+ top +' '+ clip[1] +' '+ clip[2] +' '+ clip[3];
  }
}
function setBottomClip(c, bottom)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn)  ly[c].clip.bottom = bottom;
  if (ie || n6)
  {
		var clip = ly[c].style.clip.split(" ");
    ly[c].style.clip =  clip[0] +' '+ clip[1] +' '+ bottom +' '+ clip[3];   
  }
}

function AltoCapa(c)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn) return ly[c].document.height;
  if (ie) return ly[c].scrollHeight;
  if (n6) return ly[c].offsetHeight;
}

function topCapa(c)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn) return ly[c].top;
  if (ie || n6) return ly[c].offsetTop;
}

function leftCapa(c)
{
 //para nn ly puede no estar inicializada la primera vez
  if (ly == null)  informaCapas();

	if (!ly[c]) return;
  if (nn) return ly[c].left;
  if (ie || n6) return ly[c].offsetLeft;
}

 function findPosX(obj)
{
if (obj != null){
	var curleft = 0;
	if (document.getElementById || document.all)
	{
	
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}
else
		return 0;
}

function findPosY(obj)
{
if (obj != null){
	var curtop = 0;

	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}
else
		return 0;

}

//-->

