
var calLink = new Array("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","");
var calNextMonLink = "";
var calPreMonLink = "";
var calNowMonLink="";
var nextMonthName="";
var preMonthName="";
var header="";
function setCalLink(inLink,inDay){
	calLink[inDay-1]=inLink;
}

function setNextMonLink(inLink){
	calNextMonLink = inLink;
}
function setNextMonName(name){
	nextMonthName = name;
}

function setPreMonLink(inLink){
	calPreMonLink  = inLink;
}
function setPreMonName(name){
	preMonthName = name;
}

function setNowMonLink(inLink) {
	calNowMonLink =inLink;
}

function setHeader(name) {
	header=name;
}

function getCalMonthName(inNum){

	if (inNum < 0 )
		inNum=inNum+12;
	if (inNum > 11)
		inNum= inNum-12;
//	alert(inNum);	
   var x = new Array("Jan", "Feb", "Mar", "Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
   return x[inNum];

}


function getTotalDayofMonth(inMon, inYear){
      var output=0;
   var x = new Array(31, 28, 31, 30,31,30,31,31,30,31,30,31);
	if(inYear%4 == 0 && inMon == 1){
		return 29;
	}else{
		return x[inMon];
	}	
}

function getCalender(inDay){
	var colWidth=20;
	w = new Date(inDay);
	wNo = w.getDay();
	var output ="";
	var i;
	var curDay;
	var isStartWrite=0;
	var totalDay;
	totalDay = getTotalDayofMonth(w.getMonth(),w.getYear());
	curDay = 1;
	
	//------------------- Header -------------------------
	output = "<table id=\"wp-calendar\" style=\";font-size:8pt;font-family:Verdana;color:#666666;\" border=0>"+
			"<caption style=\"width:100%;border-bottom-style:solid;border-bottom-width:1;\" ><a href=\""+calNowMonLink+"\" style=\"letter-spacing:2;\" ><b>"+header+"</b></caption>"+
		    "<thead><tr>" +
			"<th abbr=\"Monday\" scope=\"col\" title=\"Monday\" style=\"width:"+colWidth+";font-size:8pt;;color:#666666\">Mon</th>"+
			"<th abbr=\"Tuesday\" scope=\"col\" title=\"Tuesday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Tue</th>"+
			"<th abbr=\"Wednesday\" scope=\"col\" title=\"Wednesday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Wed</th>"+
			"<th abbr=\"Thursday\" scope=\"col\" title=\"Thursday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Thu</th>"+
			"<th abbr=\"Friday\" scope=\"col\" title=\"Friday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Fri</th>"+
			"<th abbr=\"Saturday\" scope=\"col\" title=\"Saturday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Sat</th>"+
			"<th abbr=\"Sunday\" scope=\"col\" title=\"Sunday\" style=\"width:"+colWidth+";font-size:8pt;color:#666666;\">Sun</th>"+
		    "</tr></thead><tfoot><tr>"+
			"<td abbr=\"June\" colspan=\"8\" id=\"prev\">"+
			" <table border=0 width=100% style=\"font-size:10pt;font-family:arial;color:#666666\" ><tr><td>";
			//"<a href=\""+calPreMonLink+"\">&laquo;"+getCalMonthName(w.getMonth()-2)+"&nbsp;</a>"+
	if (calPreMonLink!="")
			output +="<a href=\""+calPreMonLink+"\">&laquo;"+preMonthName+"&nbsp;</a>";
			
			output +="</td><td align=right>";
	if (calNextMonLink!="")	
			output +="<a href=\""+calNextMonLink+"\"> "+nextMonthName+"&raquo;&nbsp;</a>";
			//"<a href=\""+calPreMonLink+"\"> "+getCalMonthName(w.getMonth()+2)+"&raquo;&nbsp;</a>"+
			output +="</td></tr></table></td></tr></tfoot><tbody><tr>";
	
	
	while(totalDay>0){
		output = output + "<tr>";
		for(i=0; i<7; i++){
			if(isStartWrite==0 && i >= wNo-1){
				isStartWrite = 1;
			}
			if(isStartWrite==1 && totalDay>0){
				if(calLink[curDay-1] !=""){
					output = output + "<td align=center style=\";font-size:8pt;font-family:Verdana;color:#666666\" ><a href=\""+calLink[curDay-1]+"\">"+curDay+"</a></td>";
				}else{
					output = output + "<td align=center style=\";font-size:8pt;font-family:Verdana;color:#666666\" >"+curDay+"</td>";
				}	
				curDay++;
				totalDay--;
			}else{
				output = output + "<td>&nbsp;</td>";
			}
		}
		output = output + "</tr>";
	}	
	
	output = output + "</tr></tbody></table>";
	return output;
}	


