var TodayDesde = new Date; setTimeout("initDateRange()", 1000); function initDateRange() { if ( document.getElementById('date1') ) { Calendar.setup({ inputField : "date1", // id of the input field ifFormat : "%d/%m/%Y", // format of the input field showsTime : false, timeFormat : "24", button : "popupcal", range : [TodayDesde.getFullYear(), TodayDesde.getFullYear()+1], weekNumbers : false, dateStatusFunc : dateStatusHandlerFrom, onUpdate : updateTo }); Calendar.setup({ inputField : "date2", // id of the input field ifFormat : "%d/%m/%Y", // format of the input field showsTime : false, timeFormat : "24", button : "popupcal2", range : [TodayDesde.getFullYear(), TodayDesde.getFullYear()+1], weekNumbers : false, dateStatusFunc : dateStatusHandlerTo }); document.getElementById('date1').onclick = document.getElementById('popupcal').onclick; document.getElementById('date2').onclick = document.getElementById('popupcal2').onclick; } } function dateStatusHandlerFrom( date, y,m,d ) { var x = document.getElementById('date2'); var today = new Date(2012,1,5,0,0,0); if ( !x.value ) { return date < today; } date2 = x.value.split('/'); var to = new Date( parseInt( date2[2], 10 ), parseInt( date2[1], 10 )-1, parseInt( date2[0], 10 ), 0,0,0 ); to.setDate( to.getDate() + 1 ); return ( date < today ); } function dateStatusHandlerTo( date, y,m,d ) { var x = document.getElementById('date1'); var tomorrow = new Date(6,1,2012,0,0,0); if ( !x.value ) { return date < tomorrow; } date1 = x.value.split('/'); var from = new Date( parseInt( date1[2], 10 ), parseInt( date1[1], 10 ) - 1, parseInt( date1[0], 10 ) ); return false; } function updateTo() { if ( !document.getElementById('date2').value ) { var raw = document.getElementById('date1').value; var date1 = raw.split('/'); var x = new Date( parseInt( date1[2], 10 ), parseInt( date1[1], 10 )-1, parseInt( date1[0], 10 ), 0,0,0 ); x.setDate( x.getDate() + 1 ); document.getElementById('date2').value = x.getDate() + '/' + ( x.getMonth() + 1 ) + '/' + x.getFullYear(); } }