//*****************************************************
//*** Objeto para Desarrollo DINAMIC HTML con capas ***
//*****************************************************
var NS4 = ((parseInt(navigator.appVersion)>=4) && (navigator.appName.indexOf("Netscape")!=-1));
var IE4 = ((parseInt(navigator.appVersion)>=4) && (navigator.appName.indexOf("Explorer")!=-1));

var layerObj = (NS4) ? 'document' : 'document.all';
var styleObj = (NS4) ? '' : '.style';

var objeto;
var misObjetos;

var show_visible = (NS4) ? 'show' : 'visible';
var hide_hidden = (NS4) ? 'hide' : 'hidden';

function objetoCapa(nombreCapa,altura)
{
  objeto = eval(layerObj + '["' + nombreCapa + '"]' + styleObj);

  objeto.visible=0;
  objeto.alto=altura;
  
  objeto.nombre = nombreCapa;
  objeto.mover = mover;
  objeto.moverX = moverX;
  objeto.moverY = moverY;
  objeto.scrollY = scrollY;
  objeto.scrollX = scrollX;
  objeto.mostrar = mostrar;
  objeto.ocultar = ocultar;
  //objeto.animacion = animacion;

  objeto.recortar = recortar;
  objeto.recorte = new Array(4);
  objeto.recorte["top"] = -1;
  objeto.recorte["right"] = -1;
  objeto.recorte["bottom"] = -1;
  objeto.recorte["left"] = -1;
  
  objeto.scrolling = scrolling;
  objeto.scrollingUp = scrollingUp;
  
  objeto.getWidth = getWidth;
  objeto.getHeight = getHeight;
  
  objeto.actualizarContenido = actualizarContenido;
  
  misObjetos[nombreCapa] = objeto;
  return objeto;
}

function mostrar()
{
  eval('misObjetos["' + this.nombre + '"].visibility = show_visible');
  this.visible=1;
}

function ocultar()
{
  eval('misObjetos["' + this.nombre + '"].visibility = hide_hidden');
  this.visible=0;
}

function mover(x,y)
{
  eval('misObjetos["' + this.nombre + '"].left = x');
  eval('misObjetos["' + this.nombre + '"].top = y');
}
function moverX(x)
{eval('misObjetos["' + this.nombre + '"].left = x');}
function moverY(y)
{eval('misObjetos["' + this.nombre + '"].top = y');}

var scrtempY=90000;
function scrollY(initY,finalY)
{
  if (scrtempY==90000) {scrtempY=initY}
  
  if(initY<finalY)
  {
    scrtempY=scrtempY+10;
    if (scrtempY>finalY) {scrtempY=finalY}
  }
  if(initY>finalY)
  {
    scrtempY=scrtempY-10;
    if (scrtempY<finalY) {scrtempY=finalY}
  }
  
  eval('misObjetos["' + this.nombre + '"].top = scrtempY');

  if (scrtempY!=finalY)
  {setTimeout("cp_" + this.nombre + ".scrollY(" + initY + "," + finalY + ")",50);}
  
  if (scrtempY==finalY) {scrtempY=90000}
}

var scrtempX=90000;
function scrollX(initX,finalX)
{
  if (scrtempX==90000) {scrtempX=initX}
  
  if(initX<finalX)
  {
    scrtempX=scrtempX+7;
    if (scrtempX>finalX) {scrtempX=finalX}
  }
  if(initX>finalX)
  {
    scrtempX=scrtempX-7;
    if (scrtempX<finalX) {scrtempX=finalX}
  }
  
  eval('misObjetos["' + this.nombre + '"].left = scrtempX');

  if (scrtempX!=finalX)
  {setTimeout("cp_" + this.nombre + ".scrollX(" + initX + "," + finalX + ")",50);}
  
  if (scrtempX==finalX) {scrtempX=90000}
}

function recortar(ntop, nright, nbottom, nleft)
{
  var cadena='';
  if (NS4)
  {
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.clip.top=ntop');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.clip.right=nright');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.clip.bottom=nbottom');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.clip.left=nleft');
  }
  else
  {
     cadena += 'rect(' + ntop + ' ' + nright + ' ' + nbottom + ' ' + nleft + ')';
	 eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.clip=cadena');
  }
  this.recorte["top"]=ntop;
  this.recorte["right"]=nright;
  this.recorte["bottom"]=nbottom;
  this.recorte["left"]=nleft;
}

function scrolling(scrollLoop, scrollSpeed, scrollPixels, scrollAreaWidth, scrollAreaHeight)
{
  this.scrollLoop=scrollLoop;
  this.scrollSpeed=scrollSpeed;
  this.scrollPixels=scrollPixels;
  this.scrollAreaWidth=scrollAreaWidth;
  this.scrollAreaHeight=scrollAreaHeight;
  this.scrollTop=parseInt(this.top,10);
  this.recortar(this.scrollTop,scrollAreaWidth,scrollAreaHeight,0);
  this.finScroll = finScroll;
  this.scrollPause=false;
}

function scrollingUp()
{
  if(!this.scrollPause)
  {
     if(this.recorte["top"]<this.getHeight())
	 {
	    this.top=parseInt(this.top,10)-this.scrollPixels;
		recorteTop=this.scrollTop - parseInt(this.top,10);
		recorteBottom=this.scrollAreaHeight + recorteTop;
		this.recortar(recorteTop,this.recorte["right"],recorteBottom,this.recorte["left"]);
		setTimeout('misObjetos["' + this.nombre + '"].scrollingUp()',this.scrollSpeed);
	 }
	 else
	 {
	    if(this.scrollLoop>0)
		{
		   this.top=this.scrollAreaHeight;
		   recorteTop=-this.scrollAreaHeight;
		   recorteBottom=0;
		   this.recortar(recorteTop,this.recorte["right"],recorteBottom,this.recorte["left"]);
		   this.scrollLoop--;
		   setTimeout('misObjetos["' + this.nombre + '"].scrollingUp()',this.scrollSpeed);
		}
		else
		{
		   this.finScroll();
		}
	 }
  }
}
function getWidth()
{
  widthProperties=(NS4) ? '.document.width':'offsetWidth';
  currentWidth=eval('parseInt(' + layerObj + '["' + this.nombre + '"]' + widthPropertie + ',10)');
  return currentWidth;
}
function getHeight()
{
  heightPropertie=(NS4) ? '.document.height':'.offsetHeight';
  currentHeight=eval('parseInt(' + layerObj + '["' + this.nombre + '"]' + heightPropertie + ',10)');
  return currentHeight;
}
function actualizarContenido(contenido)
{
  if(NS4)
  {
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.open()');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.write(contenido)');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.close()');
  }
  else
  {
     eval(layerObj + '["' + this.nombre + '"].innerHTML = contenido');
  }
}
function finScroll()
{
  this.scrollPause = false;
}


document.onmouseover = RoverText
document.onmouseout = RoutText
function RoverText()
{
  src = event.toElement;
  if (src.tagName=="A" && src.className!="") src.className = src.className+"Activo"
  window.setTimeout('window.status=\"\"',100)
}
function RoutText()
{
  src=event.fromElement
  if (src.tagName=="A" && src.className!="") src.className = src.className.substring(0,(src.className.length-6))
  window.status=""
}

mnuNormal='#456478';
mnuOver='#EDB346';
function cColor(src,clrOver)
{src.style.cursor = 'hand';src.bgColor = clrOver; }

function OpenWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}

function AbrirVentana(URL,WINDOWNAME,FEATURES)
{
  window.open(URL,WINDOWNAME,FEATURES);
}

//********************************
//*** Sistema de Objetos DHTML ***
//********************************
var NS4 = ((parseInt(navigator.appVersion)>=4) && (navigator.appName.indexOf("Netscape")!=-1));
var IE4 = ((parseInt(navigator.appVersion)>=4) && (navigator.appName.indexOf("Explorer")!=-1));

var layerObj = (NS4) ? 'document' : 'document.all';
var styleObj = (NS4) ? '' : '.style';

var objeto;
var misObjetos;

var show_visible = (NS4) ? 'show' : 'visible';
var hide_hidden = (NS4) ? 'hide' : 'hidden';

function objetoCapa(nombreCapa,altura)
{
  objeto = eval(layerObj + '["' + nombreCapa + '"]' + styleObj);

  objeto.visible=0;
  objeto.alto=altura;
  
  objeto.nombre = nombreCapa;
  objeto.mover = mover;
  objeto.mostrar = mostrar;
  objeto.ocultar = ocultar;
  objeto.moverY = moverY;
  objeto.scrollY = scrollY;
  //objeto.animacion = animacion;

  objeto.actualizarContenido = actualizarContenido;
  
  misObjetos[nombreCapa] = objeto;
  return objeto;
}
function mover(x,y)
{
  eval('misObjetos["' + this.nombre + '"].left = x');
  eval('misObjetos["' + this.nombre + '"].top = y');
}
function mostrar()
{
  eval('misObjetos["' + this.nombre + '"].visibility = show_visible');
  this.visible=1;
}

function ocultar()
{
  eval('misObjetos["' + this.nombre + '"].visibility = hide_hidden');
  this.visible=0;
}

function moverY(y)
{eval('misObjetos["' + this.nombre + '"].top = y');}

var scrtempY=90000;
function scrollY(initY,finalY)
{
  if (scrtempY==90000) {scrtempY=initY}
  
  if(initY<finalY)
  {
    scrtempY=scrtempY+10;
    if (scrtempY>finalY) {scrtempY=finalY}
  }
  if(initY>finalY)
  {
    scrtempY=scrtempY-10;
    if (scrtempY<finalY) {scrtempY=finalY}
  }
  
  eval('misObjetos["' + this.nombre + '"].top = scrtempY');

  if (scrtempY!=finalY)
  {setTimeout("cp_" + this.nombre + ".scrollY(" + initY + "," + finalY + ")",50);}
  
  if (scrtempY==finalY) {scrtempY=90000}
}

function actualizarContenido(contenido)
{
  if(NS4)
  {
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.open()');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.write(contenido)');
     eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.close()');
  }
  else
  {
     eval(layerObj + '["' + this.nombre + '"].innerHTML = contenido');
  }
}
//*** Muestra los bordes del estilo, con efecto de Botón normal
function b_normal(p1)
{
  miobjeto= new Object(p1);
  
  miobjeto.style.borderLeftColor='white';
  miobjeto.style.borderTopColor='white';
  miobjeto.style.borderRightColor='black';
  miobjeto.style.borderBottomColor='black';
}

//*** Muestra los bordes del estilo, con efecto de Botón Hundido
function b_hundido(p1)
{
  miobjeto= new Object(p1);
  
  miobjeto.style.borderLeftColor='black';
  miobjeto.style.borderTopColor='black';
  miobjeto.style.borderRightColor='white';
  miobjeto.style.borderBottomColor='white';
}
//***************************************************************
//*** Funciones de propósito general para Validación de Datos ***
//***************************************************************

//*** Permite conocer si una cadena está vacía o contiene null ***
function isEmpty(inputStr)
{
  if (inputStr==null || inputStr=="")
    {return true}
  else
    {return false}
}
//*************************************************************************
//*** Copyright 2000 (c) Syntax Informática, S.L.                       ***
//*** http://www.sintax.es                                              ***
//*** mailto:sintax@sintax.es         | Todo un mundo lleno de Ideas |  ***
//*************************************************************************

document.onmouseover = RoverText
document.onmouseout = RoutText
function RoverText()
{
  src = event.toElement;
  if (src.tagName=="A" && src.className!="") src.className = src.className+"Activo"
  window.setTimeout('window.status=\"\"',100)
}
function RoutText()
{
  src=event.fromElement
  if (src.tagName=="A" && src.className!="") src.className = src.className.substring(0,(src.className.length-6))
  window.status=""
}

function OpenWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}

function AbrirVentana(URL,WINDOWNAME,FEATURES)
{
  window.open(URL,WINDOWNAME,FEATURES);
}


//*************************************************************************
//*** Funciones de Estilo, para efectos dinámicos sobre los objetos HTM ***
//*************************************************************************

//*** Muestra los bordes del estilo, con efecto de Botón normal
function b_normal(p1)
{
  miobjeto= new Object(p1);
  
  miobjeto.style.borderLeftColor='white';
  miobjeto.style.borderTopColor='white';
  miobjeto.style.borderRightColor='black';
  miobjeto.style.borderBottomColor='black';
}

//*** Muestra los bordes del estilo, con efecto de Botón Hundido
function b_hundido(p1)
{
  miobjeto= new Object(p1);
  
  miobjeto.style.borderLeftColor='black';
  miobjeto.style.borderTopColor='black';
  miobjeto.style.borderRightColor='white';
  miobjeto.style.borderBottomColor='white';
}

//***********************************************************
//*** Funciones de propósito general para Manejar Cadenas ***
//***********************************************************
function insertString(mainStr,searchStr,insertStr)
{
  var front=getFront(mainStr,searchStr)
  var end=getEnd(mainStr,searchStr)
  if (front!=null && end !=null) {return front+insertStr+end}
  return null
}

function deleteString(mainStr,deleteStr)
  {return replaceString(mainStr,deleteStr,"")}

function replaceString(mainStr,searchStr,replaceStr)
{
  var front=getFront(mainStr,searchStr)
  var end=getEnd(mainStr,searchStr)
  if (front!=null && end !=null) {return front+replaceStr+end}
  return null
}

function getFront(mainStr,searchStr)
{
  foundOffset = mainStr.indexOf(searchStr)
  if (foundOffset==-1) return null
  return mainStr.substring(0,foundOffset)
}

function getEnd(mainStr,searchStr)
{
  foundOffset=mainStr.indexOf(searchStr)
  if(foundOffset==-1) {return null}
  return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
}

function trunc(mainStr,positions)
{
  if(isNumber(mainStr)) 
  {
    if (mainStr.indexOf(".")!=-1)
	{
      var front=getFront(mainStr,".")
      var end=getEnd(mainStr,".")
      if (end.length>positions)
        {return front + "." + end.substring(0,positions)}
	  else
	    {return mainStr}
    }
	else
	{
	  return mainStr
	}
  }
  return null
}


//***************************************************************
//*** Funciones de propósito general para Validación de Datos ***
//***************************************************************

//*** Permite conocer si una cadena está vacía o contiene null ***
function isEmpty(inputStr)
{
  if (inputStr==null || inputStr=="")
    {return true}
  else
    {return false}
}

//*** Comprueba que una cadena contiene números entre el 0 y el 9, ***
//***    sin signo, puntuación u otros símbolos.                   ***
//***    No se permiten cadenas vacías.                            ***
function isPosInteger(inputVal)
{
  inputStr="" + inputVal
  if (inputStr.length==0) {return false}
  for (var i=0;i<inputStr.length;i++)
  {
    var oneChar=inputStr.charAt(i)
	if (oneChar<"0" || oneChar>"9") {return false}
  }
  return true
}

//*** Comprueba que una cadena contiene números entre el 0 y el 9, ***
//***    permitiéndose el signo + y - en la primera posición de    ***
//***    de la cadena. El resto no es permitido.                   ***
//***    No se permiten cadenas vacías.                            ***
function isInteger(inputVal)
{
  inputStr="" + inputVal
  if (inputStr.length==0) {return false}
  for (var i=0;i<inputStr.length;i++)
  {
    var oneChar=inputStr.charAt(i)
	if (i==0 && (oneChar=="-" || oneChar=="+")) {continue}
	if (oneChar<"0" || oneChar>"9") {return false}
  }
  return true
}

//*** Comprueba que una cadena contiene números entre el 0 y el 9, ***
//***    permitiéndose el signo + y - en la primera posición de    ***
//***    de la cadena, así como un "." para los decimales.         ***
//***    No se permiten cadenas vacías.                            ***
function isNumber(inputVal)
{
  oneDecimal = false
  inputStr="" + inputVal
  if (inputStr.length==0) {return false}
  for (var i=0;i<inputStr.length;i++)
  {
    var oneChar=inputStr.charAt(i)
	if (i==0 && (oneChar=="-" || oneChar=="+")) {continue}
	if (oneChar=="." && !oneDecimal) {oneDecimal=true;continue}
	if (oneChar<"0" || oneChar>"9") {return false}
  }
  return true
}

//*** Comprueba que una cadena contine un valor de tipo Hora, ***
//***    en el formato H:MM o bien HH:MM.                     ***
function isHour(inputVal)
{
  inputStr="" + inputVal
  if (inputStr.length>5 || inputStr.length<4) {return false}
  if (inputStr.indexOf(":")==-1) {return false}
  if (inputStr.indexOf(":")==inputStr.lastIndexOf(":"))
  {
    if (inputStr.indexOf(":")==0 || inputStr.indexOf(":")==(inputStr.length-1)) {return false}
	firstPart = inputStr.substring(0,inputStr.indexOf(":"));
	lastPart = inputStr.substring(inputStr.indexOf(":")+1,inputStr.length);
	if (!isPosInteger(firstPart) || !isPosInteger(lastPart)) {return false}
	if (parseInt(firstPart)<0 || parseInt(firstPart)>23) {return false}
	if (parseInt(lastPart)<0 || parseInt(lastPart)>59) {return false}
  }
  return true
}

//*** Comprueba que una cadena contiene un valor de tipo Fecha, ***
//***    en el formato DD/MM/AAAA.                              ***
function isDate(inputVal)
{
  inputStr="" + inputVal
  if (inputStr.length!=10) {return false}
  if (!(inputStr.substring(2,3)=="/" && inputStr.substring(5,6)=="/")) {return false}
  dia= "" + inputStr.substring(0,2)
  mes= "" + inputStr.substring(3,5)
  anio= "" + inputStr.substring(6,10)
  if (!isPosInteger(dia) || !isPosInteger(mes) || !isPosInteger(anio)) {return false}
  if (parseInt(dia)<=0 || parseInt(dia)>31) {return false}
  if (parseInt(mes)<=0 || parseInt(mes)>12) {return false}
  if (parseInt(anio)<=0 || parseInt(anio)>3000) {return false}
  return true
}

//*** Calcula la cantidad de horas transcurridas entre una hora ***
//***    inicial y otra final, develviendo el resultado.        ***
//*** Contamos con que los parámetros que pasamos a la función, ***
//*** ya han sido comprobados con inHous().                     ***
function howManyHours(inputBefore,inputAfter)
{
  var firstBefore = parseInt(eval(inputBefore.substring(0,inputBefore.indexOf(":"))));
  var lastBefore = parseInt(eval(inputBefore.substring(inputBefore.indexOf(":")+1,inputBefore.length)));
  var firstAfter = parseInt(eval(inputAfter.substring(0,inputAfter.indexOf(":"))));
  var lastAfter = parseInt(eval(inputAfter.substring(inputAfter.indexOf(":")+1,inputAfter.length)));
  
  resultInt = firstAfter - firstBefore
  if (lastAfter>lastBefore)
    {resultFlt=(lastAfter-lastBefore) / 60}
  else
  if (lastAfter<lastBefore)
    {resultFlt=(((60-lastBefore)+lastAfter) / 60)-1}
  else
  if (lastAfter==lastBefore)
    {resultFlt=0}
  
  return resultInt+resultFlt
  
}


