//Variables de configuración general var cal_homeImg = "/assa/img/calendario"; var cal_separador = "/"; //------------------------------------------ // No modificar nada a partir de esta línea //------------------------------------------ var cal_version = "2.3.1"; function Calendario(mes,anno,nombreInput,fechaDesde,fechaHasta,nombreFechaDesde,nombreFechaHasta){ this.nombreInput = nombreInput; this.estiloCabecera = "calCabecera"; this.separador = cal_separador; this.estiloDesactivado = "calDesactivado"; this.estiloNormal = "calNormal"; this.estiloHoy = "calHoy"; this.estiloEspecial = "calEspecial"; this.estiloTabla = "calTotal"; this.estiloSelecto = "calSelecto"; this.estiloCapaBase = "calCapaBase"; this.colorFondo = "white"; this.homeCalendario = cal_homeImg; this.flechaArr = this.homeCalendario+"/flechaArriba.gif"; this.flechaAbj = this.homeCalendario+"/flechaAbajo.gif"; this.ancho = 142; this.bloqueado = false; this.mensaje = null; this.onBlurPrim = null; this.nombreFechaDesde = nombreFechaDesde; this.nombreFechaHasta = nombreFechaHasta; this.fechaDesde = fechaDesde; this.fechaHasta = fechaHasta; this.d_fechaDesde = null; this.d_fechaHasta = null; this.elegido = null; this.mes = mes; this.anno = anno; this.meses = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"]; this.diasSemana = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"); this.transForm = [6,0,1,2,3,4,5]; this.resaltados = []; this.nombreCalendario = "cal_"+nombreInput.replace(/\./g,"_"); this.evaluaExtremos = function(){ this.setFechas(); var inputDesde = document.getElementsByName(nombreFechaDesde); if (inputDesde!==undefined && inputDesde[0]!==undefined && inputDesde[0].value!==""){ this.d_fechaDesde = this.cadena2Fecha(inputDesde[0].value); } var inputHasta = document.getElementsByName(nombreFechaHasta); if (inputHasta!==undefined && inputHasta[0]!==undefined && inputHasta[0].value!==""){ this.d_fechaHasta = this.cadena2Fecha(inputHasta[0].value); } this.ampliaFechas(); }; this.ampliaFechas = function(){ if (this.d_fechaDesde!==undefined && this.d_fechaDesde!==null){ this.d_fechaDesde.setHours(0); this.d_fechaDesde.setMinutes(0); this.d_fechaDesde.setSeconds(0); } if (this.d_fechaHasta!==undefined && this.d_fechaHasta!==null){ this.d_fechaHasta.setHours(23); this.d_fechaHasta.setMinutes(59); this.d_fechaHasta.setSeconds(59); } } this.setFechas = function(){ if (this.fechaDesde!==undefined){ this.d_fechaDesde = this.cadena2Fecha(this.fechaDesde); } if (this.fechaHasta!==undefined){ this.d_fechaHasta = this.cadena2Fecha(this.fechaHasta); } this.ampliaFechas(); }; this.getResMes = function(){ var mes = ponCero(this.mes+1); var j = 0; var x = 4; var z = this.resaltados.length; var resMes = []; var ids = []; var y = 0; for (var i = 0;i"+ponCero(dia)+""; }else{ sClass = this.estiloDesactivado; sDia = ponCero(dia); } var sGif = ""; var z = resMes.length; for (var i = 0;i"; break } } return ""+sDia+""; } this.cadena2Fecha = function(cadena){ if (cadena.length>0){ var comp = cadena.split(this.separador); var anno = comp[2]; if (isNaN(anno) || anno.length == 0) return null; else anno = parseInt(anno,10); var mes = parseInt(comp[1],10); var dia = parseInt(comp[0],10); if (anno > 0 && mes<=12 && mes > 0 && dia > 0){ if ((mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) && dia > 31){ return null; }else if (mes==2 && dia > (icoEsAnioBisiesto(anno) ? 29 : 28)){ return null; }else if ((mes==4 || mes==6 || mes==9 || mes==11) && dia > 30){ return null; } }else{ return null; } mes = mes - 1; var res = new Date(); res.setFullYear(anno,mes,dia); return res; } } this.comprueba = function(valor,fecha){ if (valor==null && fecha!==undefined) valor = this.getFechaFormato(fecha); if (valor!=null){ var rexp = new RegExp("(0[1-9]|[12][0-9]|3[01])[- "+cal_separador+".](0[1-9]|1[012])[- "+cal_separador+".](19|20)\\d\\d"); if (!valor.match(rexp)){ this.mensaje = "
Formato de fecha
no válido.
Formato requerido:
dd"+cal_separador+"mm"+cal_separador+"aaaa
"; return false; } } if (fecha==undefined) fecha = this.cadena2Fecha(valor); if (this.d_fechaDesde!=undefined || this.d_fechaHasta!=undefined){ if ((this.d_fechaDesde!=undefined && fecha.getTime()<=this.d_fechaDesde.getTime()) || (this.d_fechaHasta!=undefined && fecha.getTime()>=this.d_fechaHasta.getTime())){ var mensaje = "Fecha no permitida.
Solo fechas "; if (this.d_fechaDesde!=undefined) mensaje += "
desde: "+this.getFechaFormato(this.d_fechaDesde); if (this.d_fechaHasta!=undefined) mensaje += "
hasta: "+this.getFechaFormato(this.d_fechaHasta); this.mensaje = "
"+mensaje+"
"; return false } } return true; } this.chequea = function(){ var input = document.getElementsByName(this.nombreInput); var valor = input[0].value; var actualiza = false; if (valor.length>0){ this.elegido = this.cadena2Fecha(valor); actualiza = true; }else{ this.elegido = null; } if (this.elegido == null){ var tmp = new Date(); this.pinta(tmp.getMonth(),tmp.getFullYear(),actualiza); }else{ this.pinta(this.elegido.getMonth(),this.elegido.getFullYear(),actualiza); } } this.setFecha = function(dia,mes,anno){ this.elegido = new Date(); this.elegido.setFullYear(anno,mes,dia); this.pinta(mes,anno); this.oculta(); } this.getFechaFormato = function(fecha){ return fecha!=null?(ponCero(fecha.getDate())+this.separador+ponCero(fecha.getMonth()+1)+this.separador+fecha.getFullYear()):""; } this.getCalendario = function(mes,anno,actualiza){ var input = document.getElementsByName(this.nombreInput); var sHTML = ""; var fecha = new Date(); this.mes = mes; this.anno = anno; if (this.d_fechaDesde!=undefined){ fecha.setFullYear(this.anno,this.mes,1); var fechaTmp = new Date(); fechaTmp.setFullYear(this.d_fechaDesde.getFullYear(),this.d_fechaDesde.getMonth(),1); if (fecha.getTime()<=fechaTmp.getTime()){ this.mes = this.d_fechaDesde.getMonth(); this.anno = this.d_fechaDesde.getFullYear(); } } if (this.d_fechaHasta!=undefined){ fecha.setFullYear(this.anno,this.mes,1); var fechaTmp = new Date(); fechaTmp.setFullYear(this.d_fechaHasta.getFullYear(),this.d_fechaHasta.getMonth(),1); if (fecha.getTime()>=fechaTmp.getTime()){ this.mes = this.d_fechaHasta.getMonth(); this.anno = this.d_fechaHasta.getFullYear(); } } fecha.setFullYear(this.anno,this.mes,1); var valor = ""; if (this.elegido!=null || (input[0].value!==undefined && input[0].value!=="")){ if (this.comprueba(null,this.elegido)){ valor = this.getFechaFormato(this.elegido); }else{ this.comprueba(input[0].value); if (!actualiza){ input[0].value=""; }else{ this.elegido = null; return this.mensaje; } } } var diaDesde,hoy,endia; var resMes = this.getResMes(); sHTML = "" sHTML += "" sHTML += ""; sHTML += "" sHTML += "" sHTML += ""; sHTML += "" sHTML += "" sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += ""; sHTML += "" for (var i = 0;i<6;i++){ if (i==5 && fecha.getMonth()!=this.mes) break; sHTML += "" if (i==0){ sHTML += ""; diaDesde = this.transForm[fecha.getDay()]; } for (var j = 0;j<7;j++){ if (j>=diaDesde){ hoy = fecha.getDate(); if (i>0 && fecha.getMonth()!=this.mes){ endia = ""; }else{ endia = this.esRes(hoy,resMes,this.mes,this.anno); } fecha.setDate(fecha.getDate()+1); }else{ endia = ""; } sHTML += endia; } if (i==0){ sHTML += ""; diaDesde = 0; } sHTML += "" } sHTML += "
"; sHTML += ""; sHTML += ""; sHTML += "
Mes siguiente
Mes anterior
"+this.getMes(fecha.getMonth())+""+this.anno+""; sHTML += ""; sHTML += ""; sHTML += "
Año siguiente
Año anterior
 LMXJVSD 
    
" if (!actualiza){ input[0].value=valor; } sHTML += ""; return sHTML; } this.next = function(mes,anno,intervalo){ var fecha = new Date(); fecha.setFullYear(anno,mes,1); if (intervalo==1){ fecha.setFullYear(fecha.getFullYear()+1); }else{ fecha.setMonth(fecha.getMonth()+1); } this.bloqueado = true; setTimeout(this.nombreCalendario+".setBloqueado(false);",250); setTimeout(this.nombreCalendario+".setFocus();",260); this.pinta(fecha.getMonth(),fecha.getFullYear()); } this.back = function(mes,anno,intervalo){ var fecha = new Date(); fecha.setFullYear(anno,mes,1); if (intervalo==1){ fecha.setFullYear(fecha.getFullYear()-1); }else{ fecha.setMonth(fecha.getMonth()-1); } this.bloqueado = true; setTimeout(this.nombreCalendario+".setBloqueado(false);",250); setTimeout(this.nombreCalendario+".setFocus();",260); this.pinta(fecha.getMonth(),fecha.getFullYear()) } this.pintaCapa = function(html){ var capa = document.getElementById(this.nombreInput+"_div"); var iframe = document.getElementById(this.nombreInput+"_iframe"); capa.style.display = ""; capa.innerHTML = html; var dentro = document.getElementById(this.nombreInput+"_dentro"); iframe.style.height = dentro.offsetHeight; iframe.style.width = dentro.offsetWidth; iframe.style.display = ""; } this.pinta = function(mes,anno,actualiza){ if (mes==undefined) mes = this.mes; if (anno==undefined) anno = this.anno; this.evaluaExtremos(); this.pintaCapa(this.getCalendario(mes,anno,actualiza)); } this.oculta = function(){ if (!this.bloqueado){ document.getElementById(this.nombreInput+"_div").style.display = "none"; document.getElementById(this.nombreInput+"_iframe").style.display = "none"; } } this.ejecutaOnBlurPrim = function(funccion){ var input = document.getElementsByName(this.nombreInput); if (input[0].value!=""){ input[0].value = this.getFechaFormato(this.cadena2Fecha(input[0].value)); if (!this.comprueba(input[0].value)){ input[0].value = ""; this.elegido = null; var hoy = new Date(); this.mes = hoy.getMonth(); this.anno = hoy.getFullYear(); } } if (document.getElementById(this.nombreInput+"_div").style.display=="none" && this.onBlurPrim!=null) this.onBlurPrim(); } this.inicializa = function(mes,anno){ if (mes==undefined) mes = this.mes; if (anno==undefined) anno = this.anno; var input = document.getElementsByName(this.nombreInput); this.onBlurPrim = input[0].onblur; input[0].onblur = function(){ ocultaCalendario(nombreInput); } input[0].onkeyup = function(){ chequeaCalendario(nombreInput); } var contenedor = document.body; var sTop = (getElementTop(input[0])+20)+"px"; var sLeft = getElementLeft(input[0])+"px"; var br = document.createElement("br"); br.setAttribute("id",this.nombreInput+"_br"); contenedor.appendChild(br); var elemento = document.createElement("div"); elemento.setAttribute("id",this.nombreInput+"_div"); elemento.style.position = "absolute"; elemento.style.top = sTop; elemento.style.left = sLeft; elemento.style.zIndex='200'; elemento.className = this.estiloCapaBase; var tapador = document.createElement("iframe"); tapador.style.position = "absolute"; tapador.style.zIndex="1"; tapador.style.top = sTop; tapador.style.left = sLeft; tapador.style.height = "154px"; tapador.style.width = "158px"; tapador.setAttribute("id",this.nombreInput+"_iframe"); tapador.frameBorder="0"; tapador.src=this.homeCalendario+"/blanco.html"; contenedor.appendChild(tapador); contenedor.appendChild(elemento); this.setFechas(); this.chequea(); } this.getMes = function(num){ return this.meses[num]; } this.setBloqueado = function(bloqueado){ this.bloqueado = bloqueado; } this.setFocus = function(){ document.getElementsByName(this.nombreInput)[0].focus(); } } function iniciaCalendario(nombre,fechaDesde,fechaHasta,nombreFechaDesde,nombreFechaHasta){ var nombreObjeto = nombre.replace(/\./g,"_"); try{ eval("cal_"+nombreObjeto+".pinta();"); }catch (e){ var tmp = new Date(); eval("cal_"+nombreObjeto+" = new Calendario("+tmp.getMonth()+","+tmp.getFullYear()+",'"+nombre+"','"+fechaDesde+"','"+fechaHasta+"','"+nombreFechaDesde+"','"+nombreFechaHasta+"');"); eval("cal_"+nombreObjeto+".inicializa();"); } } function ponCero(nValor){ var sValor = ""; if (nValor<10) sValor = "0"+nValor; else sValor = ""+nValor; return sValor; } function ocultaCalendario(nombre,onBlurPrim){ var nombreObjeto = nombre.replace(/\./g,"_"); setTimeout("cal_"+nombreObjeto+".oculta();",200); setTimeout("cal_"+nombreObjeto+".ejecutaOnBlurPrim();",300); } function chequeaCalendario(nombre){ //alert("chequeaCalendario"); var nombreObjeto = nombre.replace(/\./g,"_"); eval("cal_"+nombreObjeto+".chequea();"); } function icoEsAnioBisiesto (anio) { return ((anio % 4 == 0) && ((!(anio % 100 == 0)) || (anio % 400 == 0))); } function o(texto){ document.getElementById("log").innerHTML = document.getElementById("log").innerHTML + texto +"
"; } function getElementLeft(elem) { xPos = elem.offsetLeft; tempEl = elem.offsetParent; while (tempEl != null) { xPos += tempEl.offsetLeft; tempEl = tempEl.offsetParent; } return xPos; } function getElementTop(elem) { yPos = elem.offsetTop; tempEl = elem.offsetParent; while (tempEl != null) { yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; } return yPos; }