/* by Shai 10/09 - specific multi month static calendar GUI
	full CSS support (i.e no output is forced here. use this as an example:
	.calTbl{font-size:10px; font-family:verdana,arial; background-color:#F5F5F5; border:1px solid #999;}
	.calTbl td { border-right:1px solid white; border-top:1px solid white; cursor:default; text-align:right; }
	.calTbl .calMn{font-size:11px; background-color:#90A0A6; color:#FFF;}
	.calTbl .calWd{color:#6060D0}
	.calTbl .calOld{color:#D0D0D0; text-decoration:line-through}
	.calTbl .calReg{background-color:#E0E0E0; border-right:1px solid white; border-top:1px solid white;}
	.calTbl .calHi{background-color:#FFFFE0; border-right:1px solid #999; border-top:1px solid #999; }
	.calTbl .calWend{color:#000066; background-color:#D0E0E6}
	
	the HTML should be like this:
	<div style='position:relative'>
		<INPUT name='Dt' onblur="hideSoon('calDiv')" onfocus="place_cal('calDiv',8,'CalFunc')" ...>
		<div id='calDiv' style='position:absolute; top:24px; background-color:#F0F0F0; visibility:hidden;'></div>
	<script>
	function hideSoon(div){
		setTimeout(function(){ document.getElementById(div).style.visibility='hidden';},200);
	}
	function CalFunc(div_id,mmddyy){
		var o=document.getElementById(div_id),F=document.forms[0];
		if (o) o.style.visibility='hidden';
		F.Dt.value=mmddyy;
	}
	</script>
*/


var bad_dates="-1026-1027-1028-1029-1105-1106-1107-1108-"; // <-- just for testings

function place_cal(div_id,months,func2call,st_date){
	var	mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var msg="<table cellpadding=1 cellspacing=3 border=0>";
	var i,m,d,y,start=new Date();
	if (st_date && st_date.indexOf('/')==2 && parseInt(st_date)>0) {	//start should be in the format mm/dd/yy
		m=parseInt(st_date)-1; d=st_date.substring(3,5); y=20+st_date.substring(6,8);
		start.setFullYear(y,m,d);	
	} 
	m=start.getMonth(); d=start.getDate(); y=start.getFullYear(); 
	start.setFullYear(y,m,d);		// d+1: move one day forward because we do not allow today date
	m=start.getMonth(); y=start.getFullYear(); d=start.getDate();
	var stTime=m*32+y*385+d;
	for(i=0;i<months;i++){
		if (i%4==0) msg+="<tr>";
		msg+="<td valign=top>"+oneM(func2call,m,y,stTime)+"</td>";
		m++; if (m==12) {m=0; y++; } 
	}
	var o=document.getElementById(div_id);
	o.innerHTML=msg+"</tr></table>";
	o.style.visibility='visible';
	
	function oneM(func2call,m,y,stTime){
		var i,j,dTime,tbl,o='<tr>',yy=(y+'').substring(2);
		var D=new Date(y,m,1);
		var wd=D.getDay(),clss,mm,dd;
		tbl="<table class=calTbl cellpadding=0 cellspacing=0 border=0><tr class=calMn><th colspan=7>"+mn[m]+
			' 20'+yy+"</th></tr>"+
		"<tr class=calWd><th class=calWend>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th class=calWend>S</th></tr><tr>";
		for(i=0;i<wd;i++) o+='<td>&nbsp;</td>';
		for(i=1;i<32;i++){
			D.setFullYear(y,m,i); 
			if ((mm=D.getMonth())!=m) break; 
			mm++; if (mm<10) mm='0'+mm;
			dd=i<10?'0'+i:i;
			mmddyy=mm+'/'+dd+'/'+yy;
			if ((dTime=m*32+y*385+i)<stTime) o+="<td class='calOld'>"+i+"</td>";
			else if (tabNo==2 && bad_dates && bad_dates.indexOf("-"+mm+dd)>-1) o+="<td class='calTaken'>"+i+"</td>";
			else {
				if (wd==0 || wd==6) clss=' calWend'; else clss='';
				o+="<td class='calReg"+clss+"' onmouseover=\"this.className='calHi'\" onmouseout=\"this.className='calReg"+
					clss+"'\" onmousedown=\""+func2call+"('"+div_id+"','"+mmddyy+"')\">"+i+"</td>";
			}
			wd++; if (wd==7) {wd=0; o+='</tr><tr>';}
		}
		return tbl+o+"</tr></table>";
	}
}
