/* Funciones javascript de uso general */
/* autor: Francisco Sánchez */
/////////////////////////////////////////////
// CONTADOR DE CARACTERES PARA UN TEXTAREA //
/////////////////////////////////////////////
/* USO:
*/
function verPlantilla(id){
if (id=="" || id==-1)
alert ("No hay ninguna plantilla seleccionada");
else{
var ventana=window.open("/servlet/integra.servlets.Plantillas?METHOD=VERIMAGEN&id="+id,null,'width=500,height=400,top=50,left=100,scrollbars=yes,resizable=yes');
ventana.focus();
}
}
function restarCaracter( textArea, inputText, numCaracteres ) {
var tecla = window.event.keyCode;
if ( tecla == 8 ) {
numCaracteres++;
} else {
numCaracteres--;
}
inputText.value = numCaracteres - textArea.value.length;
}
function muestraTotal( textArea, inputText, numCaracteres ) {
inputText.value = numCaracteres - textArea.value.length;
}
////////////////////////
// Cambio de Imagenes //
////////////////////////
function Permut (flag,img) {
if (document.images) {
if (document.images[img].permloaded) {
if (flag==1) document.images[img].src = document.images[img].perm.src
else document.images[img].src = document.images[img].perm.oldsrc
}
}
}
function preloadPermut (img,adresse) {
if (document.images) {
img.onload = null;
img.perm = new Image ();
img.perm.oldsrc = img.src;
img.perm.src = adresse;
img.permloaded = true;
}
}
function abrirVentana(var1) {
var ventana = window.open( var1, null, 'width=500,height=450,top=50,left=100,scrollbars=yes' );
ventana.focus();
}
///////////
// RADIO //
///////////
/* Devuelve true si hay alguna opción seleccionada */
function isRadioSelected( r ) {
if ( r.length != null ) { // Caso de n radio buttons
for ( i = 0; i < r.length; i++ ) {
if ( r[i].checked ) {
return true;
}
}
return false;
} else { // Caso de 1 radiobutton
return r.checked;
}
}
function getRadioSelected( r ) {
if ( r.length != null ) { // caso de n radio buttons
for ( i = 0; i < r.length; i++ ) {
if ( r[i].checked ) {
return r[i].value;
}
}
return "-1";
} else { // caso 1 radio button
return r.value;
}
}
///////////////
// CHECKBOX //
///////////////
/* Realiza el submit del formulario que se le pasa *
* como parámetro e invoca a una operación del servlet */
function operacion(frm,operacion) {
frm.METHOD.value = operacion;
frm.submit();
}
/* Devuelve true si hay algun check seleccionado */
function isAnyElementChecked(frm,nombreCheck) {
for ( i=0; i 0 ) {
sel.options[0] = null;
}
}
/* Añade una nueva opción al select que se pasa como parámetro */
function addNewOptionSel( sel, text, value ) {
var opt = new Option( text, value );
sel.options[sel.length] = opt;
}
/* Selecciona la opción cuyo value se pasa como parámetro */
function selectOptionSel( sel, value ) {
var optionSelected = 0;
for ( var i = 0; i < sel.length; i++ ) {
if ( sel.options[i].value == value ) {
optionSelected = i;
}
}
sel.options.selectedIndex = optionSelected;
}
/* Devuelve el campo value de la opcion seleccionada del select que se *
* pasa como parámetro */
function getValueOptionSelected( sel ) {
var i = sel.options.selectedIndex;
return sel.options[i].value;
}
/* Devuelve el campo text de la opcion seleccionada del select que se *
* pasa como parámetro */
function getTextOptionSelected( sel ) {
var i = sel.options.selectedIndex;
return sel.options[i].text;
}
/* Obtiene todos valores de un select en un string separados por comas */
function getAllOptions(sel) {
var str = "";
for ( var i = 0; i < sel.options.length; i++ ) {
var valorOpcion = sel.options[i].value;
if ( i == 0 ) {
str = valorOpcion;
} else {
str += ( "," + valorOpcion );
}
}
return str;
}
/* Devuelve true si existe la opcion en el select con el value pasado como parámetro */
function existOption(sel,valor) {
for ( var i = 0; i < sel.length; i++ ) {
if ( valor == sel.options[i].value ) return true;
}
return false;
}
/* Borra la opción del select cuyo value pasamos como parámetro */
function removeOptionSel(sel,valor) {
for ( var i = 0; i < sel.options.length; i++ ) {
if ( valor == sel.options[i].value ) {
sel.options[i] = null;
return;
}
}
}
/* Devuelve el número de opciones seleccionadas */
function getNumOptionsSelected(sel) {
var count = 0;
for ( var i = 0; i < sel.options.length; i++ ) {
if ( sel.options[i].selected ) {
count++;
}
}
return count;
}
/* Borra las opciones del select que estén seleccionadas */
function removeAllSelectedOptionsSel(sel) {
var i = 0;
while( i < sel.options.length ){
if ( sel.options[i].selected ) {
sel.options[i] = null;
}
else {
i++;
}
}
}
////////////////////////////////////////////////////////////////
// FUNCIONES PARA PASAR ELEMENTOS ENTRE DOS SELECTS MULTIPLES //
////////////////////////////////////////////////////////////////
/* formulario = nombre completo del formulario *
* selIncluidos = nombre completo del select *
* seleccionados = nombre completo del input hidden del formulario */
function deNoIncluidosAIncluidos(selNoIncluidos,selIncluidos) {
var idIncluidos = "";
var descIncluidos = "";
for ( var i=0; i < selNoIncluidos.length; i++ ) {
if ( selNoIncluidos[i].selected == true) {
var opt = new Option(selNoIncluidos.options[i].text,selNoIncluidos.options[i].value);
var j = selIncluidos.length;
selIncluidos.options[j] = opt;
selNoIncluidos.options[i] = null;
i--;
}
}
}
function deIncluidosANoIncluidos(selNoIncluidos,selIncluidos) {
var idNoIncluidos = "";
var descNoIncluidos = "";
for ( var i=0; i < selIncluidos.length; i++ ) {
if ( selIncluidos[i].selected ) {
var opt = new Option(selIncluidos.options[i].text,selIncluidos.options[i].value);
var j = selNoIncluidos.length;
selNoIncluidos.options[j] = opt;
selIncluidos.options[i] = null;
i--;
}
}
}
function Trim(orgString){
return LTrim(RTrim(orgString))
}
function LTrim(orgString){
return orgString.replace(/^\s+/,'')
}
function RTrim(orgString){
return orgString.replace(/\s+$/,'')
}
function contarCarac(maxChars, ta, cont)
{
//MaxChars: Nº máximo de caracteres
//ta: Textarea fuente de los datos
//cont: Textfield informador de tamaño restante
cadena=ta.value;
cont.value=maxChars - cadena.length;
if ((maxChars - cadena.length) < 0)
{
ta.value=cadena.substring(0,eval(maxChars));
cont.value=0;
}
return;
}
/* comprueba si el parámetro es un número */
function isANumber(isenit)
{
return !isNaN( isenit.valueOf() );
}
function ayuda(proyecto,servicio,privilegio) {
var ventana;
ventana = open("/JSP/"+proyecto+"/comunes/ayuda/ayuda.jsp?SERVICIO="+servicio+"&PRIVILEGIO="+privilegio,"Ayuda","scrollbars=yes,width=600, height=400");
ventana.focus();
}
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim
*/
{
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1) {
// We have a string with leading blank(s)...
var j=0, i = s.length;
// Iterate from the far left of string until we
// don't have any more whitespace...
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;
// Get the substring from the first non-whitespace
// character to the end of the string...
s = s.substring(j, i);
}
return s;
}
/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
PURPOSE: Remove trailing blanks from our string.
IN: str - the string we want to RTrim
*/
{
// We don't want to trip JUST spaces, but also tabs,
// line feeds, etc. Add anything else you want to
// "trim" here in Whitespace
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
// We have a string with trailing blank(s)...
var i = s.length - 1; // Get length of string
// Iterate from the far right of string until we
// don't have any more whitespace...
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;
// Get the substring from the front of the string to
// where the last non-whitespace character is...
s = s.substring(0, i+1);
}
return s;
}
/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
PURPOSE: Remove trailing and leading blanks from our string.
IN: str - the string we want to Trim
RETVAL: A Trimmed string!
*/
{
return RTrim(LTrim(str));
}
/** Devuelve la coordenada X de un objeto HTML determinado */
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
/** Devuelve la coordenada Y de un objeto HTML determinado */
function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function closeWindow(){
if (confirm("Pulse 'Aceptar' si desea cerrar la ventana. ")){
window.open('','_self','');
window.close();
}
}