//CALENDAR
// need to have a div id=cal
function movecal(evt){
e=(window.event)?window.event:evt;
//alert(e.x);
id='cal';
ty=e.y+130;
tx=e.x+25;
document.getElementById(id).style.top=ty+document.body.scrollTop-150;
document.getElementById(id).style.left=tx-150;
}

function initcal(dateinputid){
mustbeafterdate=new Date();
document.getElementById('cal').className='hide';
drawcal(mustbeafterdate.getMonth(),mustbeafterdate.getFullYear(),mustbeafterdate,dateinputid)
}

function initanycal(dateinputid){
mustbeafterdate=new Date(1970, 1, 1);
thisdate=new Date();
document.getElementById('cal').className='hide';
drawcal(thisdate.getMonth(),thisdate.getFullYear(),mustbeafterdate,dateinputid)
}

function togcal(){
el=document.getElementById("cal");
cclass=el.className;
if(cclass=='hide'){el.className='sho'}else{el.className='hide'}
}

function drawcal(mno,yrno,mustbeafterdate,dateinputid){
mons=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
if (mustbeafterdate==0){mustbeafterdate=new Date()};
tday=new Date(mustbeafterdate.getFullYear(),mustbeafterdate.getMonth(),mustbeafterdate.getDate());//midnight
tbl="<table>";tble="</table>";tde="</td>";tr="<tr>";tre="</tr>";d=0;
fday=new Date(yrno, mno, 1);ofs=fday.getDay();
nmonth=new Date(yrno, mno+1, 1);lmonth=new Date(yrno, mno-1, 1);
nextbehav='drawcal('+ nmonth.getMonth() +',' + nmonth.getFullYear() + ',0,\"' + dateinputid +'\")';
lastbehav='drawcal('+ lmonth.getMonth() +',' + lmonth.getFullYear() + ',0,\"' + dateinputid +'\")';
//op=(tbl+tr+"<td colspan=7>"+dateinputid+tre);
op=(tbl+tr+"<th><a onClick='"+ lastbehav +"'>&lt;</a><th colspan=4>"+mons[mno]+" "+yrno+"<th colspan=1><a onClick='"+ nextbehav +"'>&gt;</a><th><a onClick='togcal()'>X</a>"+tre);
op+= (tr+ "<th>S<th>M<th>T<th>W<th>T<th>F<th>S"+tre);
for (r=0;r<6;r++){
op+= (tr);
for (c=0;c<7;c++){d++;dte=new Date(yrno,mno,[d-ofs]);
if (mno!=dte.getMonth()){cn=" class='dayoff'";op+="<td class='dayoff'>"+dte.getDate()}//not this month so dayoff for inactive
else{//date is valid but is it after the mustbeafterdate?
if (dte.getTime()>=tday.getTime()){
datetext=''+dte.getDate()+' '+mons[dte.getMonth()]+' '+ dte.getFullYear();
behav='document.getElementById(\"'+dateinputid+'\").value=\"'+datetext+'\";togcal()';
op+="<td><a onClick='"+ behav +"'>"+dte.getDate()+"</a>"}
else{op+="<td>"+dte.getDate()}  
}}
op+= (tre);
}
op+= (tble);
document.getElementById("cal").innerHTML=op;
}
//end Calendar