//*************************************************************************
function Intervalo(formname, min, max) //{{{
{
  var form = eval('document.' + formname);
  form.MinId.value = min;
  form.MaxId.value = max;
}//}}}
//*************************************************************************
function Desplegar(formname, id) //{{{
{
  var form = eval('document.' + formname);
  form.Desplegado.value = id;
}//}}}
//*************************************************************************
function Desplegar2(formname, id) //{{{
{
  var form = eval('document.' + formname);
  form.Desplegado2.value = id;
}//}}}
//*************************************************************************
function Download(formname, id, reg) //{{{
{
  var form = eval('document.' + formname);
  form.Accion.value = 'Download';
  form.FormId.value = id;
  form.RegId.value = reg;
  form.submit();
}//}}}
//*************************************************************************
function isEmpty(value) //{{{
{
  if (value == '')
    return true;
  else
    return false;
}//}}}
//*************************************************************************
function PopUp(url, name, width, height, scroll) //{{{
{
  return window.open(url, name, 'toolbar=no,location=no,directories=no,status=no,scrollbars=' + scroll + ',resizable=no,width=' + width + ',height=' + height + ',top=0,left=0');
}//}}}
//*************************************************************************
function Preview(formname, id, reg) //{{{
{
  var form = eval('document.' + formname);
  PopUp('about:blank', 'PREVIEW', '765', '540', 'YES');
  form.target = 'PREVIEW';
  form.FrameType.value = 'FrmPrint';
  form.FormId.value = id;
  if (form.RegId)
    form.RegId.value = reg;
  form.submit();
  form.target = '';
}//}}}
//*************************************************************************
function EnlaceCalendario(formname, id, fecha) //{{{
{
  var form = eval('document.' + formname);
  form.FECHABUSCAR.value = fecha;
  form.FormId.value = id;
  form.submit();
}//}}}
//*************************************************************************
function CheckFechaVacia(form)
{
  if ((form.FECHAVACIA) && (form.FECHA))
  {
  	if (form.FECHAVACIA.checked)
  	{
  		form.DiaFecha.disabled = true;
  		form.MesFecha.disabled = true;
  		form.AnyoFecha.disabled = true;
  		form.HoraFecha.disabled = true;
  		form.MinutoFecha.disabled = true;
  		form.FECHA.value = form.FECHAVACIA.value;
    }
    else
    {
  		form.DiaFecha.disabled = false;
  		form.MesFecha.disabled = false;
  		form.AnyoFecha.disabled = false;
  		form.HoraFecha.disabled = false;
  		form.MinutoFecha.disabled = false;
    }
  }
}
<!--
function MM_findObj(n, d) { //v4.01
  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(!(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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideMaximizedLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideMaximizedLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
	  if ((obj=MM_findObj(args[i]))!=null)
	  {
	    v=args[i+2];
	    if (obj.style)
	    {
	      obj=obj.style;
				if (parseInt(navigator.appVersion)>3)
				{
				  if (navigator.appName=="Netscape")
				  {
				    obj.width = window.innerWidth;
				    obj.height = window.innerHeight;
				  }
				  if (navigator.appName.indexOf("Microsoft")!=-1)
				  {
				    obj.width = document.body.offsetWidth;
				    obj.height = document.body.offsetHeight;
				  }
				}
	      v=(v=='show')?'visible':(v=='hide')?'hidden':v;
	    }
	    obj.visibility=v;
	  }
	  else
	  	alert('ERROR');
}
//-->
//*************************************************************************
function EnlaceImportar(formname, id, reg)
{
  var form = eval('document.' + formname);
  var error = false;
  var errores = '';
	if ((form.FECHAVACIA) && (form.FECHAVACIA.checked))
	{
	}
  else if ((form.FECHA) && (form.DiaFecha))
  {
    if (!chkdate(form.AnyoFecha.value, form.MesFecha.value, form.DiaFecha.value))
    {
      error = true;
      errores += '- LA FECHA NO ES CORRECTA\n';
    }
    else if ((form.HoraFecha) && (form.MinutoFecha))
      if ((form.HoraFecha.value > 23) || (form.MinutoFecha.value > 59))
      {
        error = true;
        errores += '- LA FECHA NO ES CORRECTA\n';
      }
    form.FECHA.value = form.DiaFecha.value + '-' + form.MesFecha.value + '-' + form.AnyoFecha.value + ' ... ' + form.HoraFecha.value + ':' + form.MinutoFecha.value;
  }
  else if ((form.FECHABUSCAR) && (form.DiaFecha))
  {
    if ((form.DiaFecha.value != '') && (form.DiaFecha.value != '*') &&
        (form.MesFecha.value != '') && (form.MesFecha.value != '*') &&
        (form.AnyoFecha.value != '') && (form.AnyoFecha.value != '*'))
    {
      if (!chkdate(form.AnyoFecha.value, form.MesFecha.value, form.DiaFecha.value))
      {
        error = true;
        errores += '- LA FECHA NO ES CORRECTA\n';
      }
      form.FECHABUSCAR.value = form.DiaFecha.value + '-' + form.MesFecha.value + '-' + form.AnyoFecha.value;
    }
    else
    {
      form.DiaFecha.value = '*';
      form.MesFecha.value = '*';
      form.AnyoFecha.value = '*';
      form.FECHABUSCAR.value = '';
    }
  }
  else if (id == 'RecordarClave')
  {
    if (form.username.value == '')
    {
      error = true;
      errores += '- PARA RECORDAR LA CONTRASEÑA DEBE INTRODUCIR SU NOMBRE DE USUARIO\n';
    }
  }
  if (form.CHECKFIELDS)
  {
    var CheckFields = form.CHECKFIELDS.value;
    var CheckFieldsArray = CheckFields.split('|');
    for (i = 0; i < CheckFieldsArray.length; i+=3)
    {
      var field = eval('form.' + CheckFieldsArray[i+1] + '.value');
      if (CheckFieldsArray[i] == 'R') // CAMPO OBLIGATORIO
        if (isEmpty(field))
        {
          error = true;
          errores += '- EL CAMPO "' + CheckFieldsArray[i+2] + '" NO PUEDE ESTAR VACIO.\n';
        }
    }
    if (error)
      errores = 'Se han producido los siguientes errores:\n' + errores;
  }
  if (!error)
  {
    form.FormId.value = id;
    if (form.RegId)
      form.RegId.value = reg;
//			MM_showHideMaximizedLayers('Importando','','show');
    form.submit();
  }
  else
    alert(errores);
}//}}}
//*************************************************************************
function Enlace(formname, id, reg)
{
  var form = eval('document.' + formname);
  var error = false;
  var errores = '';
  if ((form.FECHA) && (form.DiaFecha))
  {
    if (!chkdate(form.AnyoFecha.value, form.MesFecha.value, form.DiaFecha.value))
    {
      error = true;
      errores += '- LA FECHA NO ES CORRECTA\n';
    }
    else if ((form.HoraFecha) && (form.MinutoFecha))
      if ((form.HoraFecha.value > 23) || (form.MinutoFecha.value > 59))
      {
        error = true;
        errores += '- LA FECHA NO ES CORRECTA\n';
      }
    form.FECHA.value = form.DiaFecha.value + '-' + form.MesFecha.value + '-' + form.AnyoFecha.value + ' ... ' + form.HoraFecha.value + ':' + form.MinutoFecha.value;
  }
  else if ((form.FECHABUSCAR) && (form.DiaFecha))
  {
    if ((form.DiaFecha.value != '') && (form.DiaFecha.value != '*') &&
        (form.MesFecha.value != '') && (form.MesFecha.value != '*') &&
        (form.AnyoFecha.value != '') && (form.AnyoFecha.value != '*'))
    {
      if (!chkdate(form.AnyoFecha.value, form.MesFecha.value, form.DiaFecha.value))
      {
        error = true;
        errores += '- LA FECHA NO ES CORRECTA\n';
      }
      form.FECHABUSCAR.value = form.DiaFecha.value + '-' + form.MesFecha.value + '-' + form.AnyoFecha.value;
    }
    else
    {
      form.DiaFecha.value = '*';
      form.MesFecha.value = '*';
      form.AnyoFecha.value = '*';
      form.FECHABUSCAR.value = '';
    }
  }
  else if (id == 'RecordarClave')
  {
    if (form.username.value == '')
    {
      error = true;
      errores += '- PARA RECORDAR LA CONTRASEÑA DEBE INTRODUCIR SU NOMBRE DE USUARIO\n';
    }
  }
  if (form.CHECKFIELDS)
  {
    var CheckFields = form.CHECKFIELDS.value;
    var CheckFieldsArray = CheckFields.split('|');
    for (i = 0; i < CheckFieldsArray.length; i+=3)
    {
      if (CheckFieldsArray[i] == 'HORA') // CAMPO HORA
      {
	    var field = eval('form.' + CheckFieldsArray[i+1] + '.value');      
      	if (! validar_hora(field)){
      		error = true;
      		errores += '- EL CAMPO "' + CheckFieldsArray[i+2] + '" TIENE QUE CONTENER UNA HORA VÁLIDA.\n';
      	} 
      }
      else if (CheckFieldsArray[i] == 'URL') // CAMPO URL
      {
	    var field = eval('form.' + CheckFieldsArray[i+1] + '.value');      
      	if (! validar_url(field)){
      		error = true;
      		errores += '- EL CAMPO "' + CheckFieldsArray[i+2] + '" TIENE QUE CONTENER UNA URL VÁLIDA.\n';
      	} 
      }
      else if (CheckFieldsArray[i] == 'R') // CAMPO OBLIGATORIO
      {
	    var field = eval('form.' + CheckFieldsArray[i+1] + '.value');
        if (isEmpty(field))
        {
          error = true;
          errores += '- EL CAMPO "' + CheckFieldsArray[i+2] + '" NO PUEDE ESTAR VACIO.\n';
        }
      }
      else if (CheckFieldsArray[i] == 'ORSELECT')
      {
      	var selected = false;
      	var SelectsArray = CheckFieldsArray[i+1].split(':');
      	var SelectsTitles = CheckFieldsArray[i+2].split(':');
      	var titlesor = '';
      	for (j = 0; j < SelectsArray.length; j++)
      	{
      		if (eval('form.' + SelectsArray[j] + '.selectedIndex > 0'))
      		{
      			selected = true;
      			break;
      		}
      		else
      		{
      			if (titlesor != '')
      			{
      				titlesor += ',';
      			}
      			titlesor += SelectsTitles[j];
      		}
      	}
      	if (!selected)
      	{
      		error = true;
      		errores += '- DEBE SELECCIONAR ALGUNO DE LOS CAMPOS "' + titlesor + '"\n';
      	}
      }
    }
    if (error)
      errores = 'Se han producido los siguientes errores:\n' + errores;
  }
  if (!error)
  {
    form.FormId.value = id;
    if (form.RegId)
      form.RegId.value = reg;
    form.submit();
  }
  else
    alert(errores);
}
//*************************************************************************
function Borrar(formname, id, reg) //{{{
{
  var form = eval('document.' + formname);
  var Mensaje = '';
  if (id == 'Usuario.Borrar')
    Mensaje = 'Se dispone a borrar el siguiente registro.\nEste proceso ELIMINA DEFINITIVAMENTE toda la información asociada al registro.\nSi lo que quiere es ocultar la información al público DESACTIVE el registro a través de la opción EDITAR\n\n¿Desea continuar?';
  else
    Mensaje = 'Se dispone a borrar el siguiente registro.\nEste proceso ELIMINA DEFINITIVAMENTE toda la información asociada al registro.\n\n¿Desea continuar?';
  if (confirm(Mensaje))
  {
    form.FormId.value = id;
    form.RegId.value = reg;
    form.submit();
  }
}//}}}
//*************************************************************************
function CheckEnviado(form) //{{{
{
  if (form.Enviado)
    form.Enviado.value = '';
}//}}}
//*************************************************************************
function CampoEntero(evento, negativos) //{{{
{
  if ((evento.keyCode == 45) || ((evento.keyCode >= 48) && (evento.keyCode <= 57)))
  {
    if (evento.keyCode == 45)
    {
      if (!negativos)
        evento.returnValue = false;
      else if (evento.srcElement.value.indexOf('-') != -1)
        evento.returnValue = false;
    }
  }
  else
    evento.returnValue = false;
}//}}}
//*************************************************************************
function CampoNumerico(evento, negativos) //{{{
{
  tecla=(document.all) ? evento.keyCode : evento.which;
  valor=(document.all) ? evento.srcElement : evento.target;
  if ((tecla == 0) || (tecla == 8))
  	return true;
  if (((tecla > 44) && (tecla <= 46)) || ((tecla >= 48) && (tecla <= 57)))
  {
    if (tecla == 45)
    {
      if (!negativos)
        return false;
      else if (valor.value.indexOf('-') != -1)
        return false;
    }
    if ((tecla == 46) && (valor.value.indexOf('.') != -1))
      return false;
  }
  else {
    return false;
  }
}//}}}
//*************************************************************************
function CambiarPuntoPorComa(evento) //{{{
{
  tecla=(document.all) ? evento.keyCode : evento.which;
  if ((tecla == 46) || (tecla == 44))
  {
    tecla = 44;
    if (evento.srcElement.value.indexOf(',') != -1)
      return false;
  }
}//}}}
//*************************************************************************
function CambiarComaPorPunto(input)//{{{
{
  if (input != null && input.length != 0) {
    var str = input;
    str = str.replace(",",".");
    input=str;
    input= "" + eval(input);
  }
  return input;
}//}}}
//*************************************************************************
function Round2Decimales(value) //{{{
{
  var Result = '0,00';
  var Resto;

  if (!isEmpty(value))
  {
    value = (value.replace(',', '.')*1);
    value = Math.round((value * 100) + 0.0001);
    Resto = (value % 100);
    if (Resto)
    {
      if (Resto < 1)
        Resto = '00';
      else if (Resto < 10)
        Resto = '0' + Resto;
    }
    else
      Resto = '00';
    Entero = Math.floor((value / 100) + 0.0001);
    Result = Entero + ',' + Resto;
  }

  return Result;
}//}}}
//*************************************************************************
function chkdate(intYear,intMonth,intday)//{{{
{
  var err = 0;
  if (intMonth>12 || intMonth<1)
  {
    err = 5;
    return false;
  }
  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
  {
    err = 6;
    return false;
  }
  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
  {
    err = 7;
    return false;
  }
  if (intMonth == 2)
  {
    if (intday < 1)
    {
      err = 8;
      return false;
    }
    if (LeapYear(intYear) == true)
    {
      if (intday > 29)
      {
        err = 9;
        return false;
      }
    }
    else
    {
      if (intday > 28)
      {
        err = 10;
        return false;
      }
    }
  }
  return true;
}//}}}
//*************************************************************************
function LeapYear(intYear)//{{{
{
  if (intYear % 100 == 0)
  {
    if (intYear % 400 == 0) { return true; }
  }
  else
  {
    if ((intYear % 4) == 0) { return true; }
  }
  return false;
}//}}}
//*************************************************************************
function SetNumNeuronas(field1, field2, value)
{
	field1.value = value;
	field2.value = value;
}
//*************************************************************************
function ShowLayer(capa)
{
  var offset = 150;
  capa.style.left=window.innerWidth/2+document.body.scrollLeft;
  capa.style.top=window.innerHeight/2+document.body.scrollTop-offset;
  capa.style.visibility = 'visible';
}
//*********************************************************************************************
function ShowLayer2(event, capa, offset)
{
  capa.style.left=event.clientX+document.body.scrollLeft;
  capa.style.top=event.clientY+document.body.scrollTop-offset;
  capa.style.visibility = 'visible';
}
//*************************************************************************
function CheckSession()//{{{
{
  if (parent.FrmCabecera.document.FORMPrincipal.AreaPrivada.value == '1')
  {
    alert('Su session ha sido desactivada al haber superado el tiempo máximo de inactividad');
    parent.FrmCabecera.location.reload();
  }
}//}}}
//*************************************************************************
function establecer_fecha(fieldfecha) {
	var FormReloj = document.form_reloj;
	var Fecha = eval('document.' + fieldfecha);
	var momentoactual = new Date();
	
	var ano = momentoactual.getFullYear();
	//alert(ano);
	//Revisar el año lo está cogiendo mal
	//ano  = '2008';
	mes = momentoactual.getMonth()+1;
	dia = momentoactual.getDate();
  hora = momentoactual.getHours();
  minuto = momentoactual.getMinutes();
  segundos = momentoactual.getSeconds();
  str_minuto = new String (minuto);
  if (str_minuto.length == 1)
  	str_minuto = "0" + str_minuto;
  str_hora = new String (hora);
  if (str_hora.length == 1)
		str_hora = "0" + str_hora;
  str_segundos = new String (segundos);
  if (str_segundos.length == 1)
  	str_segundos = "0" + str_segundos;
  str_mes = new String (mes);
  if (str_mes.length == 1)
		str_mes = "0" + str_mes;
  str_dia = new String (dia);
  if (str_dia.length == 1)
		str_dia = "0" + str_dia;
  var horaImprimible = str_hora + ":" + str_minuto;
	if (Fecha)
	{
		Fecha.value = ano+'-'+str_mes+'-'+str_dia+' '+str_hora+':'+str_minuto+':'+str_segundos;
	}
	if (FormReloj)
	{
		FormReloj.reloj.value = horaImprimible;
	}
//	document.FORMEjecutar.Fecha.value=ano+'-'+mes+'-'+dia+' '+hora+':'+minuto+':'+segundos;
//  document.form_reloj.reloj.value = horaImprimible;

}

//*************************************************************************
function recargar_pagina(t,id,fieldfecha){
	var actual = new Date();
	var sistema = new Date();
	var str_hora_min = document.form_reloj.reloj.value;
//	alert(str_hora_min);
	var hora_min = str_hora_min.split(':');
//	alert(hora_min);
	actual.setSeconds(0);
	sistema.setHours(hora_min[0]);
	sistema.setMinutes(hora_min[1]);
	sistema.setSeconds(0);
	establecer_fecha(fieldfecha);
	if (actual > sistema)
	{
		Enlace("FORMEjecutar", "Ejecutar.Estado",id);
	}
	else
	{
		setTimeout("recargar_pagina("+t+",'"+id+"','"+fieldfecha+"')",t);
	}
}
//*************************************************************************
function recargar_pagina2(t,fieldfecha){
	var actual = new Date();
	var sistema = new Date();
	var str_hora_min = document.form_reloj.reloj.value;
//	alert(str_hora_min);
	var hora_min = str_hora_min.split(':');
//	alert(hora_min);
	actual.setSeconds(0);
	sistema.setHours(hora_min[0]);
	sistema.setMinutes(hora_min[1]);
	sistema.setSeconds(0);
	establecer_fecha(fieldfecha);
	if (actual > sistema)
	{
	    var form = eval('document.FORMEjecutar');
		//form.FormId.value = "Ejecutar.Estado";
		form.submit();
	}
	else
	{
		setTimeout("recargar_pagina2("+t+",'"+fieldfecha+"')",t);
	}
}
//*************************************************************************
function recargar_pagina3(formname){
   var form = eval('document.' + formname);
   form.submit();
}
//*************************************************************************
function rollon(a) {
   a.style.cursor='hand';
}
//*************************************************************************
function rolloff(a) {
   a.style.cursor='default';
}

//*************************************************************************
function ejecutar_entornos(formname) {
   //establecer_fecha(formname + '.Fecha');
   var entornos = "";
   var primero = "";
   var form = eval('document.' + formname);
   var inputs = document.getElementsByTagName("input");
   for(var i=0; i<inputs.length; i++){
      if(inputs[i].getAttribute('type')=='checkbox'){
      	if (inputs[i]["checked"]){
      		if (entornos == "") {
      			entornos = inputs[i].getAttribute('value');
      			primero = entornos;
      		} else entornos = entornos + ","+inputs[i].getAttribute('value');
      	}
      }
   }
   if (entornos == "")
   		alert("Debe seleccionar algún entorno para poder ejecutarlo.");
   else {
   	    form.Entornos.value = entornos;
   	    form.FormId.value = 'Ejecutar.Arrancar2';  	   
    	form.submit();
   }  
} 
//*************************************************************************
function validar_hora(valor)
{
	patron=/^[0-9]{2,2}\:[0-9]{2,2}$/;
	test2=valor.split(':');
	hok=parseInt(test2[0])>=0 && parseInt(test2[0])<24;
	mok=parseInt(test2[1])>=0 && parseInt(test2[1])<60;
	if (!(patron.test(valor) && hok && mok)){
		return false;
	} else
		return true;
}
//*************************************************************************
function validar_url(valor)
{
    var re=/^http:\/\/\w+(\.\w+)*\.\w{2,3}(\/\w+(\.)*\w+)*$/;
    return re.test(valor); 
}