function pintaCalendar(field, ObjetoImagen){ //Si existen calendarios los eliminamos; destroyCalendar(); obj = document.getElementById(field); dateField = field; myDate = new Date(); if(obj.value!="") { myDateArray = obj.value.split("/"); myDate.setFullYear(myDateArray[2], myDateArray[1]-1, myDateArray[0]); if(myDate == "NaN") myDate = new Date(); } /* thisMonth = new calendar('thisMonth',new Date());*/ thisMonth = new calendar('thisMonth',myDate); container = document.createElement("div"); container.id = 'calContainer'; container.className = 'divContainer'; containerIE = document.createElement("div"); containerIE.id = 'calContainerIE'; containerIE.className = 'divContainerIE'; ieworkaround = document.createElement("iframe"); //ieworkaround.className= 'divContainerIE'; ieworkaround.src='blanca?OpenPage'; container.innerHTML=thisMonth.write(); containerIE.appendChild(ieworkaround); //DJC 23/12/08 Calcular posición del calendario a partir de la imagen del botón var x = ObjetoImagen.offsetLeft -100; var y = ObjetoImagen.offsetTop + ObjetoImagen.offsetHeight; var parent = ObjetoImagen; while (parent.offsetParent) { parent = parent.offsetParent; x += parent.offsetLeft; y += parent.offsetTop; } // 200 es la anchura del calendario if((x+200)>document.body.clientWidth){ x = (x-200) + ObjetoImagen.offsetWidth } if(document.getElementById('MainMenu')) { container.style.top= y+'px'; container.style.left= x+'px'; containerIE.style.top= y+'px'; containerIE.style.left= x+'px'; //container.style.top='160'; //container.style.left='500'; //containerIE.style.top='160'; //containerIE.style.left='500'; } else { container.style.top= y+'px'; container.style.left= x+'px'; containerIE.style.top= y+'px'; containerIE.style.left= x+'px'; //container.style.top='160'; //container.style.left='550'; //containerIE.style.top='160'; //containerIE.style.left='550'; }; document.getElementsByTagName('body')[0].appendChild(container); document.getElementsByTagName('body')[0].appendChild(containerIE); } function destroyCalendar() { cal = document.getElementById('calContainer'); calIE = document.getElementById('calContainerIE'); if(cal!=null) cal.parentNode.removeChild(cal); if(calIE!=null) calIE.parentNode.removeChild(calIE); } var days = new Array('Lu','Ma','Mi', 'Ju','Vi','Sa','Do'); var months = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'); // Constructor function calendar(id, d){ this.id = id; this.dateObject = d; this.write = writeCalendar; this.length = getLength(d.getMonth(),d.getFullYear()); this.month = d.getMonth(); this.date = d.getDate(); this.day = d.getDay(); this.year = d.getFullYear(); this.getFormattedDate = getFormattedDate; this.dateToPrint = dateToPrint; // get the first day of the month's day d.setDate(1); this.firstDay = d.getDay()-1; // corrección para que la semana empiece el lunes if (this.firstDay < 0) { // corrección para que la semana empiece el lunes this.firstDay = 6; } // then reset the date object to the correct date d.setDate(this.date); } function changeDate(td,cal){ // Some JavaScript trickery // Change the cal argument to the existing // calendar object // This is why the first argument in the // constructor must match the variable name // The cal reference also allows for // multiple calendars on a page cal = eval(cal); document.getElementById(cal.id + "selected").className = "days"; document.getElementById(cal.id + "selected").id = ""; td.className = "date"; td.id = cal.id + "selected"; // set the calendar object to the new date cal.dateObject.setDate(td.firstChild.nodeValue); cal = new calendar(cal.id,cal.dateObject); // here is where you could react to a date change— // I'll just display the formatted date td.onMouseOut="td.className=\'date\'"; document.getElementById(dateField).value=cal.dateToPrint(); destroyCalendar(); } function changeMonth(mo,cal){ // more trickery! cal = eval(cal); // The Date object is smart enough to // know that it should roll over in December // when going forward and in January // when going back cal.dateObject.setMonth(cal.dateObject.getMonth() + mo); cal = new calendar(cal.id,cal.dateObject,cal.pix); cal.formattedDate = cal.getFormattedDate(); document.getElementById('calContainer').innerHTML = cal.write(); } function getFormattedDate(){ return this.date + '/' + (this.month+1) + '/' + this.year; } function dateToPrint() { if(this.date<10) this.date = '0'+this.date; if(this.month<9){ this.month = '0'+(this.month+1); } else { this.month = this.month+1; } return this.date + '/' + this.month + '/' + this.year; } function getLength(mes,anyo){ // thirty days has September... switch(mes){ case 1: if ((anyo%4==0 && anyo%100!=0) || anyo%400==0) return 29; // leap year else return 28; case 3: return 30; case 5: return 30; case 8: return 30; case 10: return 30 default: return 31; } } function writeCalendar(){ var calString = '
'; // write month and year at top of table calString += ''; // write the month // mod to draw navigation on top calString += ''; // calString += ''; // write a row containing days of the week calString += ''; for(i=0;i'; } // write the body of the calendar calString += ''; // create 6 rows so the calendar doesn't resize for(j=0;j<42;j++){ var displayNum = (j-this.firstDay+1); if(j' + displayNum + ''; }else if(displayNum > this.length){ // Empty cells at bottom of calendar calString += ''; }else{ // the rest of the numbered cells calString += ''; } if(j%7==6){ calString += ''; } } // close the last number row calString += ''; calString += '
<<<' + months[this.month] + ', ' + this.year + '>>>
' + // months[this.month] + ', ' + this.year + // '
 ' + displayNum + '
'; calString += '
cerrar
'; calString += '
'; return calString; }