//Recupera el primer objeto con el ID
function getObject(id) {
	if( window.mmIsOpera ) return(document.getElementById(id));
	if (document.all) return(document.all[id]);
	if (document.getElementById) return(document.getElementById(id));
	return(false);
}

//Recupera todos los objetos con el mismo ID
function getObjects(id){
    var nodes = document.getElementsByTagName('*');
    var matches = new Array();
    for(var i=0;i<nodes.length;i++){
        if(nodes[i].id == id) matches[matches.length] = nodes[i];
    }
    if (matches.length > 0)
        return(matches);
    else
        return(false);
}

//Script que pinta la fecha pasada en milis
function pintaFecha(id, creacion, modificacion){
    var fecha = new Date(creacion);
    var hoy = new Date();
    var seconds_hoy=hoy.getTime();
    var seconds_crea = fecha.getTime();
    var dif=seconds_hoy-seconds_crea;
    var dias = Math.floor(dif / (1000 * 60 * 60 * 24));

    var result = "";
    var str="(Hace ";
    var date=new Date(dif);
    if (dias > 0){
        result = formatLong(fecha,'d \'de\' MMMM \'del\' yyyy', 'es');
    }else{
      var horas=date.getHours();
      if (horas > 0){
        if (horas == 1){
          result = str + horas + " hora)";
        }else{
          result = str + horas + " horas)";
        }
      }else{
        var minutos=date.getMinutes();
        if (minutos > 0){
          if (minutos == 1){
            result = str + minutos + " minuto)";
          }else{
            result = str + minutos + " minutos)";
          }
        }
      }
    }
    getObject(id).innerHTML = result;
}

function cerrarEncuesta(id, fechaCierre, hora){
    var hoy =new Date();
    var horas = parseInt(hora.substring(0, hora.indexOf(":")));
    var min =  parseInt(hora.substring(hora.indexOf(":")+1, hora.length));
    fechaCierre = fechaCierre+(horas*60+min)*60000;
                
    if (hoy.getTime() > fechaCierre) {
        if (document.getElementById(id)!=null)
        document.getElementById(id).style.display='none';
    }
}
