function reloj() {
  //obtiene fecha y hora
  var fecha = new Date();
  var Anio = fecha.getFullYear();
  var Mes = fecha.getMonth();
  var DiaActual = fecha.getDate();
  var Dia = fecha.getDay();
  var horas = fecha.getHours();
  var minutos = fecha.getMinutes();
  var segundos = fecha.getSeconds();

  //asigna p.m. o a.m. segun el caso
  var cir = "";
  var i = 12;
  if(horas < i) {
  cir = "A.M.";
  } else if(horas >= i) {
  cir = "P.M.";
  }

  //array nombres meses
  var mes = new Array();
  mes[0] = "Enero";
  mes[1] = "Febrero";
  mes[2] = "Marzo";
  mes[3] = "Abril";
  mes[4] = "Mayo";
  mes[5] = "Junio";
  mes[6] = "Julio";
  mes[7] = "Agosto";
  mes[8] = "Septiembre";
  mes[9] = "Octubre";
  mes[10] = "Noviembre";
  mes[11] = "Diciembre";

  //array nombres dias
  var dia = new Array();
  dia[0] = "Domingo";
  dia[1] = "Lunes";
  dia[2] = "Martes";
  dia[3] = "Miércoles";
  dia[4] = "Jueves";
  dia[5] = "Viernes";
  dia[6] = "Sábado";

  //array horas
  var hr = new Array();
  hr[0] = "12";
  hr[1] = "01";
  hr[2] = "02";
  hr[3] = "03";
  hr[4] = "04";
  hr[5] = "05";
  hr[6] = "06";
  hr[7] = "07";
  hr[8] = "08";
  hr[9] = "09";
  hr[10] = "10";
  hr[11] = "11";
  hr[12] = "12";
  hr[13] = "01";
  hr[14] = "02";
  hr[15] = "03";
  hr[16] = "04";
  hr[17] = "05";
  hr[18] = "06";
  hr[19] = "07";
  hr[20] = "08";
  hr[21] = "09";
  hr[22] = "10";
  hr[23] = "11";

  //obtiene nombre mes
  //mas faci: Mes = mes[Mes];
  if(Mes==0){Mes = mes[0];}
  if(Mes==1){Mes = mes[1];}
  if(Mes==2){Mes = mes[2];}
  if(Mes==3){Mes = mes[3];}
  if(Mes==4){Mes = mes[4];}
  if(Mes==5){Mes = mes[5];}
  if(Mes==6){Mes = mes[6];}
  if(Mes==7){Mes = mes[7];}
  if(Mes==8){Mes = mes[8];}
  if(Mes==9){Mes = mes[9];}
  if(Mes==10){Mes = mes[10];}
  if(Mes==11){Mes = mes[11];}

  //obtiene nombre dia
  //mas facil: Dia = dia[Dia];
  if(Dia==0){Dia = dia[0];}
  if(Dia==1){Dia = dia[1];}
  if(Dia==2){Dia = dia[2];}
  if(Dia==3){Dia = dia[3];}
  if(Dia==4){Dia = dia[4];}
  if(Dia==5){Dia = dia[5];}
  if(Dia==6){Dia = dia[6];}

  //ajusta formato horas
  //mas facil: horas = hr[horas];
  if(horas==0){horas = hr[0];}
  if(horas==1){horas = hr[1];}
  if(horas==2){horas = hr[2];}
  if(horas==3){horas = hr[3];}
  if(horas==4){horas = hr[4];}
  if(horas==5){horas = hr[5];}
  if(horas==6){horas = hr[6];}
  if(horas==7){horas = hr[7];}
  if(horas==8){horas = hr[8];}
  if(horas==9){horas = hr[9];}
  if(horas==10){horas = hr[10];}
  if(horas==11){horas = hr[11];}
  if(horas==12){horas = hr[12];}
  if(horas==13){horas = hr[13];}
  if(horas==14){horas = hr[14];}
  if(horas==15){horas = hr[15];}
  if(horas==16){horas = hr[16];}
  if(horas==17){horas = hr[17];}
  if(horas==18){horas = hr[18];}
  if(horas==19){horas = hr[19];}
  if(horas==20){horas = hr[20];}
  if(horas==21){horas = hr[21];}
  if(horas==22){horas = hr[22];}
  if(horas==23){horas = hr[23];}

  //ajusta segundos
  var m = 10;
  if(minutos < m) { minutos="0"+minutos; }
  if(segundos < m) { segundos="0"+segundos; }

  //cadena final
  textoFinal = (Dia+", "+DiaActual+" de "+Mes+" de "+Anio+"   "+horas+":"+minutos+":"+segundos+" "+cir+"");

  document.getElementById("fecha").innerHTML = textoFinal;

  //repite cada 1 segundo
  setTimeout("reloj()",1000);
}

function isIE4()
{
  if(document.all) {
    return true;
  }
  return false;
}

function setContent(name, value) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  d.innerHTML = value;
}

function getContent(name) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  return d.innerHTML;
}

function setColor(name, value) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  d.style.color = value;
}

function getColor(name) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  return d.style.color;
}

function setSize(name, value) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  d.style.fontSize = value+'px';
}

function getSize(name) {
  var d;
  if (isIE4()) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
  f = "12px";
  if (d.style.fontSize)
  {
    f = d.style.fontSize
  }
  f = f.replace("px","");
  //f = f.replace("em","");
  var s = parseInt(f);
  return s;
}


function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;

	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100;
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0;

	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0

	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;

	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
  if (isIE4()) {
    d = document.all[elemId];
  } else {
    d = document.getElementById(elemId);
  }

  SetOpacity(d, Math.round(parseInt(fromOpacity) + (delta * stepNum)));

  if (stepNum < steps)
      setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}


var animate_aux = 1;

function animate(name) {
  var opacityini = 20;
  var opacityfin = 100;

  //if (animate_aux)
  //{
	  FadeOpacity(name, opacityini, opacityfin, 500, 10);
  	setTimeout("animate('"+name+"');", 4000);
  //}
  //else
  //{
	//  FadeOpacity(name, opacityfin, opacityini, 500, 10);
	//  setTimeout("animate('"+name+"');", 4000);
  //}
  //animate_aux = !animate_aux;

  return false;
  /*
  var col = '#FF7070';
  var value = getContent(name);
	if (value.indexOf('<span') >= 0) { return; }
	var length = 0;
  var str = '';
	var ch;
	var token = '';
	var htmltag = false;

  for (i = 0; i < value.length; i++) {
	  ch = value.substring(i, i+1);
		if (i < value.length - 1) { nextch = value.substring(i+1, i+2); } else { nextch = ' '; }
		token += ch;
		if (ch == '<' && '/aAbBpPhHiIoOuUlLtT'.indexOf(nextch) >= 0) { htmltag = true; }
		if (ch == '>' && htmltag) { htmltag = false; }
		if (!htmltag && ch.charCodeAt(0) > 30 && ch != ' ' && ch != '\n') {
      str += '<span id="' + name + '_' + length + '">' + token + '</span>';
			token = '';
			length++;
		}
  }
  setContent(name, str);
  command = 'animateloop(\'' + name + '\', ' + length + ', 0, 1, \'' + col + '\')';
  //command = 'cycle(\''+name+'\',\''+value+'\')';
  setTimeout(command , 200);
  */
}

function animateloop(name, length, ind, delta, col) {
  var next = ind + delta;
	if (next >= length) { delta = delta * -1; next = ind + delta; }
	if (next < 0) { delta = delta * -1; next = ind + delta; }
  setColor(name + '_' + ind, getColor(name + '_' + next));
  setColor(name + '_' + next, col);
  //decreaseFontSize(name + '_' + ind);
  //increaseFontSize(name + '_' + next);
  setSize(name + '_' + ind, getSize(name + '_' + next));
  setSize(name + '_' + next, getSize(name + '_' + next)+2);
  command = 'animateloop(\'' + name + '\', ' + length + ', ' + next + ', ' + delta + ', \'' + col + '\')';
  setTimeout(command , 200);
}

var pos_1 = 0.5;
var step_1 = 0.25;

function cycle(name,msg)
{
  for(var i= 0; i < msg.length; ++ i){

    var font_size = 12;
    var red = 0;

    var dis = 2 - Math.abs(i - pos_1);
    if (0 < dis){
       font_size += 12 * dis;
       red = Math.ceil(127 * dis);
    }

    str = "<font style='font-size: " + String(font_size)
                   + "px; color: rgb(" + red + ", 0, 0);'>"
                   + msg[i]
                   + "</font>";
    setContent(name+'_' + i , str);
  }

  pos_1 += step_1;
  if ( (0.5 > pos_1) || (7.5 < pos_1) )
    step_1 = - step_1;

  command = 'cycle(\''+name+'\',\''+msg+'\')';
  setTimeout(command , 200);
}


function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function urldecode(str) {
return unescape(str.replace('+', ' '));
}

function seleccionado(lista)
{
	var pcnt = 0;
    var lb = document.getElementById(lista);
    var size = lb.options.length;
    for (i=0; (i<size); i++) {
		if (lb.options[i].selected == true) { pcnt++; }
    }

    if(pcnt==0)
		return(false);
	return(true);
}

function aleatorio(inferior,superior)
{
  var numPosibilidades = superior - inferior + 1;
  var aleat = Math.random() * numPosibilidades;
  aleat = Math.round(aleat);
  return(aleat);
}

var dialogFeaturesMini =
  'center:yes; dialogWidth:800px; dialogHeight:480px; edge:raised; status:yes; help:yes; resizable:yes; scroll:yes; maximize:yes; minimize:yes;';

var dialogFeatures =
  'center:yes; dialogWidth:'+(screen.width - 10)+'px; dialogHeight:'+(screen.height - 55)+'px; edge:raised; status:yes; help:yes; resizable:yes; scroll:yes; maximize:yes; minimize:yes;';

var dialogFeaturesNoModalMini = 'toolbar=0, menubar=0, scrollbars=0, status=0, location=0, width=800, height=500';

var dialogFeaturesNoModal = 'toolbar=0, menubar=0, scrollbars=1, status=0, location=0, width=900, height=700';

var dialogFeaturesNoModalMax = 'toolbar=0, menubar=0, scrollbars=1, status=0, location=0, width='+screen.width+', height='+screen.height;

function Descargar(objid,idatribcat){
  showModalDialog('udownfile.php?extfile='+objid+'&id='+idatribcat,objid,dialogFeatures);
}

function DescargarNoModal(objid,idatribcat){
  window.open('udownfile.php?extfile='+objid+'&id='+idatribcat);
}

function DescargarInforme(crm,cod){
  window.open('udowninforme.php?crm='+crm+'&cod='+cod);
}

function ResultadosParciales(crm,cod){
  //window.open('uLabResultados.php?crm='+crm+'&cod='+cod);
  window.open('uLab.php?crm='+crm+'&cod='+cod);
}

function EditarSeccion(objid){
  var datos = new Array();
  datos[0] = 1;
  datos[1] = 'adminSec.php?obj_id='+objid;
  showModalDialog(datos[1],objid,dialogFeatures);
}

function EditarObjeto(objid){
  var datos = new Array();
  datos[0] = 1;
  datos[1] = 'adminObjetos.php?obj_id='+objid;
  showModalDialog(datos[1],objid,dialogFeatures);
}

function Seleccionar(objid){
  var datos = new Array();
  datos[0] = 2;
  datos[1] = objid;
  datos[2] = document.getElementById('tiporel_'+objid).value;
  returnValue = datos;
  window.close();
}

function SeleccSolicitud(id){
  var datos = new Array();
  datos[0] = 2;
  datos[1] = id;
  returnValue = datos;
  window.close();
}

function Imprimir(bloque)
{
  var ventana = window.open('','_blank', '');
  var contenido = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'+
      '<html xmlns="http://www.w3.org/1999/xhtml">'+
    '<head>'+
    '<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />'+
  	'<title>CENTRO TECNOLOGICO NACIONAL DE LA CONSERVA Y ALIMENTACION</title>'+
    '<meta content="CENTRO TECNOLOGICO NACIONAL DE LA CONSERVA Y ALIMENTACION" name="description" />'+
    '<meta content="alimentación,conserva,alimentos,muestras,determinaciones,análisis,ctnc.es" name="keywords" />'+
    //'<script src="recursos/css/default/js/vscrollarea.js" type="text/javascript"></script>'+
	  //'<script src="recursos/css/default/js/jquery-1.2.6.pack.js" type="text/javascript"></script>'+
    //'<script src="recursos/css/default/js/jquery.galleryScroll1.2.1.js" type="text/javascript"></script>'+
	  //'<script src="recursos/css/default/js/main.js" type="text/javascript"></script>'+
    //'<script src="recursos/css/global/funciones.js" type="text/javascript"></script>'+
    '<link type="text/css" href="recursos/css/inphecthyuz/inphecthyuz.css" rel="stylesheet">'+
 	  '<link href="recursos/css/default/css/all.css" type="text/css" rel="stylesheet" />'+
    '<link href="recursos/css/default/css/print.css" type="text/css" rel="stylesheet" />'+
    '</head>                   '+
    '<body style="margin:0;">'+
    '<div id="main" style="width:100%; padding:0 20px 0 20px;">'+
    '  <div class="left_articles">                                       '+
		'    <h2>CENTRO TECNOLOGICO NACIONAL DE LA CONSERVA Y ALIMENTACION</h2>'+
    '  </div>'+
    '  <div class="container" style="width:100%;">'+
		'    <div class="col-2" style="float:left; width:100%;">'+
  	'		     <div class="left_articles" style="text-align:justify; width:100%;">'+
	  '			     <div id="print_contenido">'+document.getElementById(bloque).innerHTML+'</div>'+
    '			   </div>     '+
    '		 </div>     '+
    '  </div>'+
    '</div>'+
    '</body>'+
    '</html>';

  ventana.document.open("text/html");
  ventana.document.write(contenido);
  var el = ventana.document.getElementById('Panel1_table');
  el.style.overflow = '';
  el.style.display = '';
  el.style.position = '';
  el.style.visibility = '';
  el.style.height = '';
  el.style.width = '100%';
  var els = getElementsByClassName(ventana.document,'container');
  for(var i=0;i<els.length;i++)
  {
    els[i].style.overflow = '';
    els[i].style.display = '';
    els[i].style.position = '';
    els[i].style.visibility = '';
    els[i].style.height = '';
    els[i].style.width = '100%';
  }
  var els = getElementsByClassName(ventana.document,'col-2');
  for(var i=0;i<els.length;i++)
  {
    els[i].style.overflow = '';
    els[i].style.display = '';
    els[i].style.position = '';
    els[i].style.visibility = '';
    els[i].style.height = '';
    els[i].style.width = '100%';
  }
  var els = getElementsByClassName(ventana.document,'scrollable');
  for(var i=0;i<els.length;i++)
  {
    els[i].style.overflow = '';
    els[i].style.display = '';
    els[i].style.position = '';
    els[i].style.visibility = '';
    els[i].style.height = '';
    els[i].style.width = '100%';
  }
  var els = getElementsByClassName(ventana.document,'scroll-content');
  for(var i=0;i<els.length;i++)
  {
    els[i].style.overflow = '';
    els[i].style.display = '';
    els[i].style.position = '';
    els[i].style.visibility = '';
    els[i].style.height = '';
    els[i].style.width = '100%';
  }

  ventana.document.close();
}

function LeerMas(objid){
  var datos = new Array();
  datos[0] = 3;
  datos[1] = 'uPrevObjeto.php?objid='+objid;
  window.open(datos[1],objid,'');
}

function AbrirNoModal(ref){
  window.open(ref,null,dialogFeaturesNoModalMax);
}

function AbrirNoModalMini(ref){
  window.open(ref,1,dialogFeaturesNoModalMini);
}

function AbrirModal(ref){
  returnValue = showModalDialog(ref,1,dialogFeatures);
}

function AbrirModalMini(ref){
  returnValue = showModalDialog(ref,1,dialogFeaturesMini);
}


function BuscarTexto(texto) {
  document.forms[0].action = 'buscar.php';
  document.forms[0].method = 'POST';
  document.forms[0].submit();
  return false;
}

function adminBuscar(){
  var datosBuscador=showModalDialog('adminBuscar.php?seleccion=0',null,dialogFeatures);
  if (datosBuscador!=null)
  {
    if (datosBuscador[0]==1)
    {
      //Editar
      window.location.href = datosBuscador[1];
    }
    else if (datosBuscador[0]==3)
    {
      //Leer mas
      window.open(datosBuscador[1],"Previsualizacion","toolbar=1, menubar=1, status=1, location=1, width=900, height=700");
      }
    }
}
function adminSalir() {
  var salir = confirm("Va a salir del panel de administración, ¿está seguro?")
  if (salir)
    window.location.href='index2.php';
}

function getElementsByClassName(doc,needle) {
   var my_array = doc.getElementsByTagName("*");
   var retvalue = new Array();
   var i;
   var j;

   for (i=0,j=0;i<my_array.length;i++) {
      var c = " " + my_array[i].className + " ";
      if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
   }
   return retvalue;
}
