// JavaScript Document for common functions

/********************************* Confirma ********************************************
sirve para enviar un mensaje de confirmación
mensaje	= cadena de texto que se envia como mensaje
return:False || True
***************************************************************************************/
function confirma(mensaje)
{
if (confirm(mensaje))
	return true;
else
	return false;
}

/********************************* valida_passwords ***************************************
sirve para validar que dos passwords sean iguales (confirmar password)
p1, p2	= cadenas de texto que contienen los passwords a validar
return: False || True
***************************************************************************************/
function valida_passwords(p1,p2)
{
	if(p1==p2)
		return true
	else
		return false;
}

/********************************* valida_radiobutton ***************************************
sirve para validar que se haya selecionado una opcion de un grupo de radio_buttons
nombre	= campo radiobutton que se desea validar
return: true || False
********************************************************************************************/
function valida_radiobutton(nombre)
{
    opciones = document.getElementsByName(nombre);
	var seleccionado = false;
	for(var i=0; i<opciones.length; i++) {	
	  if(opciones[i].checked) {
		seleccionado = true;
		break;
	  }
	} 
	if(!seleccionado) return false;
	else return true;	
}

/********************************* valida_checkbox ***************************************
sirve para validar que se haya selecionado una opcion de un grupo de checkboxes
nombre	= campo cehckbox que se desea validar
return: true || False
********************************************************************************************/
function valida_checkbox(nombre)
{
    opciones = document.getElementsByName(nombre);
	var seleccionado = false;
	for(var i=0; i<opciones.length; i++) {	
	  if(opciones[i].checked) {
		seleccionado = true;
		//break;
	  }
	} 
	if(!seleccionado) return false;
	else return true;	
}

/********************************* valida_checkbox_con_text ***************************************
sirve para validar que se haya selecionado una opcion de un grupo de checkboxes o que se haya escrito algo en un text ligado
nombre	= campo cehckbox que se desea validar
return: true || False
********************************************************************************************/
function valida_checkbox_con_text(nombre)
{
    //text=document.getElementById(texto).value;
	opciones = document.getElementsByName(nombre);
	var seleccionado = false;
	for(var i=0; i<opciones.length; i++) {	
	  if(opciones[i].checked) {
		seleccionado = true;
		//break;
	  }
	} 
	
	//if(opciones[opciones.length-1].type=="text")
	text=opciones[opciones.length-1].value;
	
	if(!seleccionado && text=="") 
	     return false;
	else 
	     return true;	
}


/********************************* valida_text ***************************************
sirve para validar que se haya escrito algo en un text
nombre	= campo text que se desea validar
return: true || False
********************************************************************************************/
function valida_text(nombre)
{
    texto = document.getElementById(nombre)
	if(texto.value!="")
		return true;
	else 
		return false;	
}

/********************************* valida_select ***************************************
sirve para validar que se haya selecionado una opcion de un select
campo	= campo select que se desea validar
return:False || True
***************************************************************************************/
function valida_select(campo)
{
indice = document.getElementById("opciones").selectedIndex;
if( indice == null || indice == 0 ) {
  return false;
}
else return true;
}

/****************************** cambia_select ***********************************************
select  = campo select que se valida
campo	= campo de texto con el que se enlaza
capa	= div contenedora del campo texto que se mustra o se oculta
indice_select	= indice del campo select que no es valido, para mostrar la capa
*********************************************************************************************/
function cambia_select(select1,campo,capa,indice_select)
{
obj_select = document.getElementById(select1);
obj_text=document.getElementById(campo);
obj_text.value=obj_select.value;
indice=obj_select.selectedIndex;
//obj_capa=document.getElementById(capa);
	if( indice != indice_select )//&& indice != 0 )
	 {
	    ocultar(capa);
	    obj_text.value=obj_select.value;
	 }
	else
	 {
		obj_text.value="";
		mostrar(capa);
		obj_text.focus();
	 }
}
/************************************************************************************************/

/*
function noEnter(e) 
{    
  tecla = (document.all) ? e.keyCode :e.CharCode;
  //var evento = e || window.event;
  if (tecla == 13) 
	{        
		event.cancelBubble = true;
		//event.returnValue = false;
		event.keyCode = 9;
    }
} 

function manejador(elEvento) {
  var evento = elEvento || window.event;
  var caracter = evento.which || evento.keyCode;
  alert("El carácter pulsado es: " + String.fromCharCode(caracter));
}document.onkeypress = manejador;*/
/*
//Esta línea llama a la funcion InicializarEventos
addEvent(window,'load',inicializarEventos,false);


function inicializarEventos()
{
// Aquie obtienes mediante DOM el control a traves de ID 
  //var ob1=document.getElementById('criterio');
    var ob1=document.getElementByClassName('campo_texto');//class="campo_texto"

// Se le agrega al objeto el evento (keypress), y la funcion que se va a ejecutar al presionar cualquie tecla...('presionar')
  //addEvent(ob1,'keydown',noEnter,false);
  addEvent(ob1,'keypress',noEnter,false);
}

/*
function presionar(e)
	{
	//Esta parrte es para IE
	if (window.event)
	  {
	           if (window.event.keyCode==13)
		{nom_funcion()}// Aqui escribe el nombre tu funcion que hace la busqueda...
	  }
	  else
                    //Esto es para Firefox y creo otros navegadores
		if (e)
		{
		  if(e.which==13)
		  	{nom_funcion()}//Igual que arriba
		}
	}
	


//Lo que hace la funcion addEvent es agregar la funcion para IE u otros navegadores, en IE es attachEvent y en los otros navegadores es addEventListener, fijense como se antepone el "on" para hacer referencia al evento para IE mientras que en los otros navegadores no es necesario...

function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}
*/