///funcion para la hora.....

function hora(){
if (!document.layers&&!document.all)
return
var Digital=new Date()
var horas=Digital.getHours()
var minutos=Digital.getMinutes()
var segundos=Digital.getSeconds()
var dn="AM" 
if (horas>12){
dn="PM"
horas=horas-12
}
if (horas==0)
horas=12
if (minutos<=9)
minutos="0"+minutos
if (segundos<=9)
segundos="0"+segundos
mrelog=""+horas+":"+minutos+":"
+segundos+" "+dn+""
if (document.layers){
document.layers.relog.document.write(mrelog)
document.layers.relog.document.close()
}
else if (document.all)
relog.innerHTML=mrelog
setTimeout("hora()",1000)
}		 
///// Funcin que genera contraseña..//////////


function mkpass(longitud){
	ALF = new Array("a","b",'c',"d","e","f","g","h","i","j","k","l","m","n","ñ","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","!","@","/","\\","*","(",")","{","}","[","-","|","%","$","#","!","~","^","?","¿");	
	len = ALF.length;
	inferior = 0
	superior = ALF.length;    
	numPosibilidades = len - 1;	
	pass="";
	for(i = 0; i < longitud;i++){
        aleat = Math.random() * numPosibilidades;
        aleat = Math.round(aleat);
	    alf1 = parseInt(inferior) + aleat;	
		pass+=ALF[alf1];
	}
    form2.passwd.value=pass;
	
}

///// Codificar texto..//////////

function codifica(texto){
    ref='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ'; 
    resultado=' ';
    for (cont=0; cont<texto.length; cont++){
	     caracter=texto.substring(cont,cont+1);
         pos=ref.indexOf(caracter);
         codigo=ref.substring(pos+1,pos+2);
         resultado+=codigo; 
	 }
    return resultado; 
}

///  Redireccionar a una pagina ////////

function redireccionar(url){
 con = confirm("¿Seguro de esta acción?");
 if(con==true)
    window.location=url;
}

///// Validar campos vacios en un formulario //////
function valida(formulario){
  for(i=0;i<formulario.elements.length;i++){
		   if(formulario.elements[i].type == "text"){
		       if(formulario.elements[i].value==""){
			       alert("Este campo requiere de valores...");
				   formulario.elements[i].focus();
				   event.returnValue=false; 
				   return
			   }
		   }  		   
  }
  
}

function valida_passw(form){
  if(form.pass_anterior.value !="" && form.nueva_pass.value != "" && form.conf_nueva_pass.value){
     if(form.pass_anterior.value != form.nueva_pass.value){	  
	     if(form.nueva_pass.value.length >= 7){
		   g = confirm("¿Realmente desea cambiar su contraseña.?");
		   if(g)
		    form.submit(); 
		 }
		 else{
		   alert("La contraseña debe tener como mínimo 7 caracteres.");
	       form.nueva_pass.focus()
		   form.nueva_pass.select()
		   event.returnValue=false; 
		 }
	 }
	 else{
	       alert("No puede escribir la misma contraseña.");
	       form.nueva_pass.focus()
		   form.nueva_pass.select()
		   event.returnValue=false; 
	 }
  }
  else{
       alert("No se pueden haber campos vacios.");
	   if(form.pass_anterior.value=="")
	    form.pass_anterior.focus();
       if(form.nueva_pass.value=="")
	    form.nueva_pass.focus();
       if(form.conf_nueva_pass.value=="")
	    form.conf_nueva_pass.focus();	
      event.returnValue=false; 			
  }
}

/// Funcion solo numero.....

var nav4 = window.Event ? true : false;
function acceptNum(evt){ 
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
var key = nav4 ? evt.which : evt.keyCode; 
return (key <= 13 || key== 46 || (key >= 48 && key <= 57));

}


//// funcion para el cambio de color de las celdas de las tablas de los resultado.

function BG(campo){
    campo.bgColor="#EDF2FC";
}
function BG1(campo){
    campo.bgColor="#8CAAE6";
}	

/// function Open Window

function Ventana(url,ancho,alto) 
{
www = window.open(url, "", "width="+ancho+",height="+alto+",screenX=0,screenY=0,top=60,left=90");
}		


///// script para los mensajes tipo alt



/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox



   function padNmb(nStr, nLen){ 
    var sRes = String(nStr); 
    var sCeros = "0000000000"; 
    return sCeros.substr(0, nLen - sRes.length) + sRes; 
   } 

   function stringToSeconds(tiempo){ 
    var sep1 = tiempo.indexOf(":"); 
    var sep2 = tiempo.lastIndexOf(":"); 
    var hor = tiempo.substr(0, sep1); 
    var min = tiempo.substr(sep1 + 1, sep2 - sep1 - 1); 
    var sec = tiempo.substr(sep2 + 1); 
    return (Number(sec) + (Number(min) * 60) + (Number(hor) * 3600)); 
   } 

   function secondsToTime(secs){ 
    var hor = Math.floor(secs / 3600); 
    var min = Math.floor((secs - (hor * 3600)) / 60); 
    var sec = secs - (hor * 3600) - (min * 60); 
    return padNmb(hor, 2) + ":" + padNmb(min, 2) + ":" + padNmb(sec, 2); 
   } 

   function substractTimes(t1, t2){ 
    var secs1 = stringToSeconds(t1); 
    var secs2 = stringToSeconds(t2); 
    var secsDif = secs1 - secs2; 
	secsDif = Math.abs(secsDif);
    return (secsDif/60); 
   } 

   function calcT3(){ 
    with (document.frm) 
     t3.value = substractTimes(t1.value, t2.value); 
   } 
   function normal_militar(){
                 
         var hora1 = frm.comienzoH.value + ":" + frm.comienzoM.value + ":00";
         var hora2 = frm.fiH.value + ":" + frm.fiM.value + ":00"; 
		 h1 = frm.thorac.options[frm.thorac.selectedIndex].value
         h2 = frm.thoraf.options[frm.thoraf.selectedIndex].value
         var dot1 = hora1.indexOf(":");
         var dot2 = hora2.indexOf(":");
         var m1 = hora1.substr(0, dot1);
         var m2 = hora2.substr(0, dot2);
         var s1 = hora1.substr(dot1 + 1);
         var s2 = hora2.substr(dot2 + 1); 
		 if(h1=="PM" && m1!="12")
            m1 = parseInt(m1)+12; 
         if(h2=="PM" && m2!="12")
            m2 = parseInt(m2)+12;  
         if(h1=="AM" && m1=="12")
            m1 = "00";  			
         if(h2=="AM" && m2=="12")
            m2 = "00"; 				
		 m1 = m1+":"+ s1;
         m2 = m2+":"+ s2;          
		 if(parseInt(frm.tint.value) > parseInt(substractTimes(m1,m2))){
			 alert("El tiempo de interrupción no puede ser mayor que la diferencia de tiempo");
			 frm.tint.focus();
			 return
		 }
		 frm.ttotal.value = substractTimes(m1,m2)-frm.tint.value;  
          
   }


/////Funcion parea eliminar los avisos 
function eliminar_aviso(id)
{
 p = confirm("Realmente deseas realizar la operación. ");
 if(p)
 window.location ="index.php?mod=portada&eliminar=elim&id=" + id+"";
 
}

///// Limite en cuanto a caracteres.....

function limite(que,cuanto,form)
{
var v=que.value
if(v.length>cuanto)
  que.value=v.substring(0,cuanto)
else
  form.cont.value=cuanto-v.length
}


// Enviar formulario......

function Envia_Form(form,campo){
  if(campo.options[campo.selectedIndex].value!="")
   form.submit();
}

function confirma_eliminar_registro_pagina(id,pagina_actividad,pagina){
    g = confirm("¿Seguro que deseas eliminar esta actividad?");
    if(g)
    window.location="index.php?mod=pagina&op=eliminar&id="+id + "&indicador=" + pagina_actividad + "&pagina=" + pagina;
}