var maxDuration=30;if(maxDuration==0)maxDuration=30;

function inito(){var d=new Date(); var y=d.getFullYear(); var lm=document.getElementById('AVP_list_months'); var ld=document.getElementById('AVP_list_days'); var ldm=document.getElementById('AVP_list_dmonths'); var ldd=document.getElementById('AVP_list_ddays'); var ln=document.getElementById('AVP_list_nights'); for(i=0;i<12;i++){ var m=(d.getMonth()+i)%12; if(m==0&&i!=0)y++; appendOption(lm,months[m]+' '+y,y+'-'+(m+1)); if (ldm) appendOption(ldm,months[m]+' '+y,y+'-'+(m+1));}	for(i=1;i<=31;i++){appendOption(ld,i,i); if (ldd) appendOption(ldd,i,i); if(ln && i<=maxDuration) appendOption(ln,i,i);} ld.selectedIndex=d.getDate()-1; if(ldd) ldd.selectedIndex=d.getDate(); setDays(); setDDays();}
function setDays(){var ld=document.getElementById('AVP_list_days'); var lm=document.getElementById('AVP_list_months'); var ym=lm.options[lm.selectedIndex].value; var y=eval(ym.substring(0,4)); var m=eval(ym.substring(5,ym.length)); var d=getDaysInMonth(y,m); if(d>ld.length){ for(i=ld.length;i<d;i++)appendOption(ld,i+1,i+1); } if(d<ld.length){ if(ld.selectedIndex>d-1)ld.selectedIndex=d-1; ld.length=d; }}
function setDDays(){var ld=document.getElementById('AVP_list_ddays'); var lm=document.getElementById('AVP_list_dmonths'); if (ld && lm){var ym=lm.options[lm.selectedIndex].value; var y=eval(ym.substring(0,4)); var m=eval(ym.substring(5,ym.length)); var d=getDaysInMonth(y,m); if(d>ld.length){for(i=ld.length;i<d;i++)appendOption(ld,i+1,i+1); }	if(d<ld.length){if(ld.selectedIndex>d-1)ld.selectedIndex=d-1; ld.length=d; }}}
function appendOption(l,t,v){var e=document.createElement('option');e.text=t;e.value=v;try{l.add(e,null);}catch(ex){l.add(e);}}
function getDaysInMonth(y,m){var days=[31,28,31,30,31,30,31,31,30,31,30,31];var d=days[m-1];if(d==28){if(isLeapYear(y))d=29;}return d/1;}
function isLeapYear(y){if(y%400==0||(y%4==0&&y%100!=0))return true;return false;}
function validate(){var lm=document.getElementById('AVP_list_months'); var ld=document.getElementById('AVP_list_days'); var ym=lm.options[lm.selectedIndex].value; var y=eval(ym.substring(0,4)); var m=eval(ym.substring(5,ym.length)); var d=new Date(); var t=new Date(d.getFullYear(),d.getMonth(),d.getDate()); d=new Date(y,m-1,eval(ld.options[ld.selectedIndex].value)); var nights = 1; var ln=document.getElementById('AVP_list_nights'); var ldm=document.getElementById('AVP_list_dmonths'); var ldd=document.getElementById('AVP_list_ddays'); if (ldm && ldd){var ydm=lm.options[ldm.selectedIndex].value; var yd=eval(ydm.substring(0,4)); var md=eval(ydm.substring(5,ydm.length)); var dd=new Date(); var td=new Date(dd.getFullYear(),dd.getMonth(),dd.getDate()); dd=new Date(yd,md-1,eval(ldd.options[ldd.selectedIndex].value)); var one_day=1000*60*60*24; nights = Math.ceil((dd.getTime()-d.getTime())/one_day); if(d<t || dd <= d || nights > maxDuration){ alert(message); return false; }} else if (ln) { nights = ln.options[ln.selectedIndex].value; if(d<t){alert(message); return false; }} document.getElementById('AVP_arrivalDate').value = lm.options[lm.selectedIndex].value+'-'+ld.options[ld.selectedIndex].value; document.getElementById('AVP_nights').value = nights; document.getElementById('AVP').submit(); }

inito();

