/*
 * Opina: gestor de encuestas
 * Copyright (C) 2005-2007 Opina Development Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * 
 * $Id: opina.js 1342 2007-11-01 19:10:32Z recena $
 */

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

// ToDo: (formulario, atributo, criterio); Ejem: (AccionForm, nombre, ascendente);
function ordenaListado (formulario, criterio) {
    var oForm = eval ('document.' + formulario);
    oForm.orden.value = criterio;
    oForm.submit();
}

function ejecutar (formulario, evento) {
    var oForm = eval ('document.' + formulario);
    if (evento != null) {
        oForm.accion.value = evento;
    }
    oForm.submit();
}

function enviar(accion){
    document.AccionForm.orden.value=accion;
    document.AccionForm.submit();
}

function enviaFormulario(formulario, destino) {
    var oForm = eval ('document.' + formulario);
    if (destino != null) {
        oForm.action=destino;
    }
    oForm.submit();
}

function muestraOculta(formulario, prop, idNodo) {
    var div = document.getElementById(idNodo);
    var oForm = eval ('document.' + formulario);
    var oProp = eval ('oForm.' + prop);
    if (oProp.checked) {
        div.style.display = 'block';
    }
    else {
        div.style.display = 'none';
    }
}

function mostrarCapa (idNodo) {
    var div = document.getElementById(idNodo);
    div.style.display = 'block';
}

function ocultarCapa (idNodo) {
    var div = document.getElementById(idNodo);
    div.style.display = 'none';
}

function ayuda(idPregunta) {
    var nombre = "ayuda";
    var opciones ="width=400,height=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=1,resizable=1";
    var url="asistente/ayuda.ebabel?id="+idPregunta;
    vindu = window.open(url, nombre, opciones);
}

function confirmar(mensaje) {
    return confirm(mensaje);
}

/* Gestor de "enter" */
function defineEventoEnter (activeForm) {
    if (document.layers)
         document.captureEvents(Event.KEYDOWN);
     document.onkeydown = function (evt) {
            var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : 
                event.keyCode;
            if (keyCode == 13 && activeForm) {
                     eval("document."+activeForm+".submit();");
             return false;
            }   else
             return true;
    };
}

function filtroFloat (input) {
    s = input.value;
    filteredValues = "1234567890,";     // Caracteres aceptados
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {  // busco entre los caracteres del texto
        var c = s.charAt(i); 
        if( c==".") //lo convierto en una coma
            c=",";
        // compruebo que el resto de caracteres es valido            
        if (filteredValues.indexOf(c) != -1) returnString += c;
    }
    input.value = returnString;
}

function setFocusOnForm (formName) {
    var oForm = eval ('document.' + formName);
    var bStop = false;
    var i = 0;
    while (i<oForm.elements.length && !bStop) {
        currentElement = oForm.elements[i];
        if (currentElement.type=='text' || currentElement.type=='password' || currentElement.type=='textarea'){
            currentElement.focus();
            bStop = true;
        }
        i++;
    }
}