function obliga(lista,mensaje) {
  for (i=0;i<lista.length;i++) {
    if (lista[i].value == "") {
      alert(mensaje);
      return false;
	}  
  }
  return true;
}

function irSiElegidoyConfirma(elem,confirmar,dir,mensaje) {
  //En dir, la palabra reservada ELEGIDO indica el value del elemento elegido
  if (elem.selectedIndex >= 0) {
    if (confirm(confirmar+elem.options[elem.selectedIndex].text)) {
      dir = dir.replace('ELEGIDO',elem.options[elem.selectedIndex].value);
      self.location.href = dir;
	}   
  } else {
    alert(mensaje);
  }	
}

function validaClave(clave1,clave2,form,mensaje) {
  if ( (clave1 == clave2) && (clave1!="") ) form.submit();
  else alert(mensaje);
    
}

//FUNCIONES PARA EL FORMATO DE LOS DATOS ##########################
var vORIGEN = "";

function getVO(campo) {
  vORIGEN = campo.value;
}  

function setVO(campo,tipo) {
  //tipo 	= 1 - porcentaje con decimales dd,xx
  //		= 2 - real dddd,xx
  //tipo	= 3 - entero dddd
  //tipo	= 4 - text

  // Quit if backspace key or arrow keys or INSERT or DEL
  if ( /^(8|3[7-9]|40|45|46)$/.test( event.keyCode ) ) return;
  
  //Quit if empty
  if (campo.value == "") return;

  //If tipo = TEXT compruebo que no ha metido el caracter '
  if (tipo==4) {
    if (event.keyCode == 219 ) {
      campo.value = vORIGEN;
	}  
	return;
  }	
  
  if (campo.value.indexOf(',') >= 0 ) 	campo.value = campo.value.replace(",",".");
  
  //if ( ((campo.value.charAt(campo.value.length-1)) == ".") && ((tipo=="1") || (tipo=="2"))) return;
  
  if (isNaN(Number(campo.value)) || ((tipo=="1") && ((campo.value < 0)||(campo.value > 100)))) {
    campo.value = vORIGEN;
	return;
  }	
  
  if ((tipo=="1") || (tipo=="2")) {
    posicion_punto = campo.value.indexOf('.');
	if ( (posicion_punto >= 0) && (campo.value.length - posicion_punto > 3) ) {
      campo.value = Math.round(parseFloat(campo.value) * Math.pow(10, 2)) / Math.pow(10, 2); 
	}  
  } else {
    campo.value = Math.round(parseFloat(campo.value) * Math.pow(10, 0)) / Math.pow(10, 0); 
  }	
}
