
// JavaScript Document

	function abrirVentana(ventana,sitio)
	{
		if (ventana=="1")
		{
			document.getElementById("capaFondo1").style.visibility="visible";
			document.getElementById("capaFondo2").style.visibility="hidden";
			document.getElementById("capaFondo3").style.visibility="hidden";
		
		}
		else if (ventana=="2")
		{
			document.getElementById("capaFondo1").style.visibility="hidden";
			document.getElementById("capaFondo2").style.visibility="visible";
			document.getElementById("capaFondo3").style.visibility="hidden";
		}
		else
		{
			document.getElementById("capaFondo1").style.visibility="hidden";
			document.getElementById("capaFondo2").style.visibility="hidden";
			document.getElementById("capaFondo3").style.visibility="visible";
		}
		
		document.getElementById(sitio).style.visibility="visible";
		//document.formulario.bAceptar.focus();
	   
	}
	
	function cerrarVentana3(sitio)
	{
		document.getElementById("capaFondo1").style.visibility="hidden";
		document.getElementById("capaFondo2").style.visibility="hidden";
		document.getElementById("capaFondo3").style.visibility="hidden";
		document.getElementById(sitio).style.visibility="hidden";
		//document.formulario.bAceptar.blur();
	}




//alertas formularios
/*
function validar_campos()
{
var s="" 
for (e=0; e<=document.form1.length; e++){ 
if (document.form1.elements[e].value=="" || document.form1.elements[e].value==" "){ 
s=s + document.form1.elements[e].name 
} 
} 
if (s!=""){ 
alert("No llenaste todo el formulario"); 
return false
} else { 
document.form1.submit(); 
}

}

/*
function Enter(Evento, Campo)
{
var keyCode = Evento.keyCode ? Evento.keyCode : Evento.which ? Evento.which : Evento.charCode; 
if (keyCode == 13) 
{ 
var i;
for (i = 0; i < Campo.form.elements.length; i++) 
if (Campo == Campo.form.elements[i]) 
break; 
i = Campo.form.elements[i].tabIndex + 1; 
for( j = 0 ; j < Campo.form.elements.length; j++)
{ 
if( Campo.form.elements[j].tabIndex == i)
break; 
} 
Campo.form.elements[j].focus(); 
return false; 
} 
else 
return true; 
}

*/
//validadion para expedientres
function ocultarDiv(objeto1){ objeto1.style.display = 'none'; } 


function mostrarDiv (objeto1){ objeto1.style.display = 'block'; }


//validaion de emil

function validarEmail(valor1,valor2,valor3) {
      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor1)){
      
      } else {
      alert('El campo ' + valor2+   ' tiene un email incorrecto ');
      valor3.focus();
	  return false;
      }
      }




function validar_for (F) {

//16 elementos del formulario 
     //mail
	
	 valor=F.elements[0].value;
      if(valor=='') {
      alert('El campo ' + F.elements[0].name +   ' no puede estar vacio ');
      F.elements[0].focus();
      return false
	  }
      //
    
	 //formato 
	 
	
	 //clave
	 valor=F.elements[1].value;
      if(valor=='') {
      alert('El campo ' + F.elements[1].name +   ' no puede estar vacio ');
      F.elements[1].focus();
      return false
	  }
     //temañao
	 
	 if (F.elements[1].value!=''){

	  if ((F.elements[1].value.length < 8)|| (F.elements[1].value.length > 8)) {
	  alert('El campo ' + F.elements[1].name +   ' su contraseña dbe ser de 8 digitos ');
      F.elements[1].focus();
	  return false
	  }
	  
	  }
	 
	 
	 
	 //
	 //documento
	 valor1=F.elements[2].value;
      if(valor1=='') {
      alert('El campo ' + F.elements[2].name +   ' no puede estar vacio ');
      F.elements[2].focus();
       return false
	  }
	   
	 
	  
	 
	 
	 
	 
	 valor=F.elements[1].value;
	   valor1=F.elements[2].value;
	
	if(valor1!='' && valor!='') {
	
	if(valor1!=valor) {
      alert('El campo ' + F.elements[1].name +   ' no puede ser diferente al campo ' + F.elements[2].name +  ' ');
      F.elements[2].focus();
       return false
	  } 
     
	}
	
	//valida email 
	
	//codigo
	 valor=F.elements[3].value;
      if(valor=='') {
      alert('El campo ' + F.elements[3].name +   ' no puede estar vacio ');
      F.elements[3].focus();
      return false
	  }
	
	
	
	valor1=F.elements[0].value;
      if(valor1!='') {
      return validarEmail(F.elements[0].value,F.elements[0].name,F.elements[0]);
	  	  }
	
	

}
//fin de validacion de expedientes 

//
function validar_for1 (F) {

//16 elementos del formulario 
     //mail
	
	 valor=F.elements[0].value;
      if(valor=='') {
      alert('El campo ' + F.elements[0].name +   ' no puede estar vacio ');
      F.elements[0].focus();
      return false
	  }
      //
    
	 //formato 
	 
	
	 //clave
	 valor=F.elements[1].value;
      if(valor=='') {
      alert('El campo ' + F.elements[1].name +   ' no puede estar vacio ');
      F.elements[1].focus();
      return false
	  }
     //temañao
	 
	 if (F.elements[1].value!=''){

	  if ((F.elements[1].value.length < 8)|| (F.elements[1].value.length > 8)) {
	  alert('El campo ' + F.elements[1].name +   ' su contraseña dbe ser de 8 digitos ');
      F.elements[1].focus();
	  return false
	  }
	  
	  }
	 
	
	
	
	valor1=F.elements[0].value;
      if(valor1!='') {
      return validarEmail(F.elements[0].value,F.elements[0].name,F.elements[0]);
	  	  }
	
	

}
//fin de validacion de expedientes 




//
function validar(e) { // 1
     tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
   // patron = /\D/;
	patron =/[A-Za-zñÑ\s]/;
		//patron =/[A-ZÁÉÍÓÚÜÑ]/;
	//patron =/[A-Za-zñÑ\s];
	// 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
} 

function validar_num(e) { // 1
     tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
   // patron = /\D/;
	patron = /\d/; // Solo acepta números
		//patron =/[A-ZÁÉÍÓÚÜÑ]/;
	//patron =/[A-Za-zñÑ\s];
	// 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
} 

function foco_1(e,F){
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; 
//alert(F);
//13 corresponde al intro 
if (keyCode == 13) { 

F.focus();

return false
}


}







function foco_letras(e,F){
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; 
//alert(F);
//13 corresponde al intro 
if (keyCode == 13) { 

F.focus();

return false
}

else {

 //alert('aca entro');
 return validar(e);
   

}
}


//
function foco_numeros(e,F){
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; 
//alert(F);
//13 corresponde al intro 
if (keyCode == 13) { 

F.focus();

return false
}

else {

 //alert('aca entro');
 return validar_num(e);
   

}
}




//FUNCION CAMPOS VACIOS SIMPLES 
function validar_campos(e,number,F)
{
   for (e; e<=number; e++){ 
   var valor = F.elements[e].value;
      if(valor=='') {
       
	  alert('El campo ' + F.elements[e].name +   ' no puede estar vacio ');
      F.elements[e].focus();
      return false
       
          }
   
	
	
	}

}
//fin de campos simples
//funcion con campos numericos 
function validar_campos1(e,cantidad,numerico,F)
{
   for (e; e<=cantidad; e++){ 
   var valor = F.elements[e].value;
      
	  if(e==numerico ) {
	     
		 
         if(isNaN(valor)==true) {
          alert('El campo '+ F.elements[e].name + ' tiene que ser numerico');
         F.elements[e].focus();
          return false }
		 
	    }
	  
	  if(valor=='') {
       
	  alert('El campo ' + F.elements[e].name +   ' no puede estar vacio ');
      F.elements[e].focus();
      return false
       
          }
    
	}


}
// fin  funcion  mixta de numeros 
//fucnion validar numeros 
function validar_camposN(e,number,F)
{
   for (e; e<=number; e++){ 
   var valor = F.elements[e].value;
     
	 if(valor=='') {
       
	  alert('El campo ' + F.elements[e].name +   ' no puede estar vacio ');
      F.elements[e].focus();
      return false
       
          }
    
	 	 
	 if(isNaN(valor)==true ) {
          alert('El campo '+ F.elements[e].name + ' tiene que ser numerico');
         F.elements[e].focus();
          return false
       
          }
    
	}

}
//fin funcion validar numeros 

// ingreso solo numeros BLOQUEANDO EL ENTER 
var nav = window.Event ? true : false;
function acceptNum(evt) {
// NOTA: Backspace = 8->si, Enter = 13->no, '0' = 48, '9' = 57, '.'=46->si
var key = nav ? evt.which : evt.keyCode;
return (key < 13 || key ==46 || (key >= 48 && key <= 57 || key == 13  ));
}

//var nav = window.Event ? true : false;  
//validar solo letras



/* patrones esto se cambia por el patron de arriba
patron =/[A-Za-z\s]/;
patron = /\d/; // Solo acepta números
patron = /\w/; // Acepta números y letras
patron = /\D/; // No acepta números
patron =/[A-Za-zñÑ\s]/; // igual que el ejemplo, pero acepta también las letras ñ y Ñ

*/
//fin de validar letras



// fin solo numeros BLOQUEANDO EL ENTER CON EL KEYPRESSS onKeyPress="return acceptNum(event);" 
//RECORRE EL FORMULARIO CON ENTER
/*
Con esta función lo primero q se hace es validar el evento xa saber si se presionó la tecla enter, luego se recorren los elementos del formulario xa saber sobre cual estoy posicionado, como puede suceder que el orden de creación de los elementos no sea el mismo que el del tabindex, se recorre nuevamente los elementos xa saber cual tiene el siguiente tabindex y se ubica el foco sobre este.

No se si exista alguna función más simple pero esta solucionó mis problemas del momento y es la q uso actualimente.

Lo q debes hacer es hacer el llamado de la función en el evento onKeypress del campo deseado y tener organizado el tabindex de todos los campos.

Lo otro q puedes haces es modificar el código de la función Enter para que cuando detecte q se presiono enter ejecute el submit o la funcion q desees ejecutar.
/*

*/
/*
function Enter(Evento, Campo)
{
var keyCode = Evento.keyCode ? Evento.keyCode : Evento.which ? Evento.which : Evento.charCode; 
if (keyCode == 13) 
{ 
var i;
for (i = 0; i < Campo.form.elements.length; i++) 
if (Campo == Campo.form.elements[i]) 
break; 
i = Campo.form.elements[i].tabIndex + 1; 
for( j = 0 ; j < Campo.form.elements.length; j++)
{ 
if( Campo.form.elements[j].tabIndex == i)
break; 
} 
Campo.form.elements[j].focus(); 
return false; 
} 
else 
return true; 
}




//

//VALIDAR NUMERO SI BLOQUEAR EL ENTER FUCNIONA CON onkeydown="return Verificar(this);"

function es_numerico (strString)
{
var strValidChars = "0123456789.";
var strChar;
var blnResult = true;

for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}

function Verificar (obj)
{
if (es_numerico(obj.value))
{
return true;
}
else
{
return false;
}
}


//FIN VALIDAR NUMEROS SIN BLOQUEAR EL ENTER

/*
function validar_campos(e,number,F)
{
//alert(number);
   for (e; e<=number; e++){ 
  
       alert('El campo  ' + e + ' '+F.elements[e].name);
          
		  // return false
		  }
}

*/
/*
function validar_letras(F)
{

var nombre1 = f.value;
if(isNaN(nombre1)==false) {
alert('campo incorrecto');
F.Nombre_129.focus();
return false
}
//Nombre 2
var checkOK = 'ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ' + 'abcdefghijklmnñopqrstuvwxyzáéíóú ';
var checkStr = F.value;
var allValid = true; 
for (i = 0; i < checkStr.length; i++) {
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
 if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length) { 
allValid = false; 
break; 
}
}
  if (!allValid) { 
    alert('digitos incorrectos'); 
    F.focus(); 
    return (false); 
  } 


/*
function validar_campos1()
{
var s="" 
for (e=0; e<=document.form1.length; e++){ 
if (document.form1.elements[e].value=="" || document.form1.elements[e].value==" "){ 
s=s + document.form1.elements[e].name 
} 
} 
if (s!=""){ 
alert("No llenaste todo el formulario"); 
} else { 
document.form1.submit(); 
} 

}
*/
