var _F_C_CurrObj = null;
var _F_C_ResultObj = null;

document.write("<div id='_div_cal_blow'></div>");

function _F_C_WriteCal(o){

	_F_C_ResultObj = document.getElementById("_div_cal_blow");
	if(!_F_C_ResultObj)return;
	
	_F_C_CurrObj = o;
	var D = new Date();
	if(_F_C_CurrObj!=null){
		D=new Date(_F_C_CurrObj.value);
		if(isNaN(D))D=new Date();
	}
	_F_C_Write(D);
}

function _F_C_Write(dt){
	dt = new Date(dt);
	var HTM = "";
	HTM+="<table width=100% cellpadding=2 cellspacing=0 class='MenuOff' style='cursor:hand;width:148px;'><tr><td>";
	HTM+="<table width=100% cellpadding=2 cellspacing=0><tr>";
	
	var tmpDT = new Date(dt);
	tmpDT.setMonth(dt.getMonth()-1);

	HTM+="<td><img src='" + _GLOBAL_VAR_IMG + "/des/left.jpg' onclick=\"_F_C_Write('"+tmpDT+"');\"></td>";
	HTM+="<td><b>" + _F_C_getMonthName(dt.getMonth()) + "</b></td>";
	
	tmpDT = new Date(dt);
	tmpDT.setMonth(dt.getMonth()+1);
	HTM+="<td><img src='" + _GLOBAL_VAR_IMG + "/des/right.jpg' onclick=\"_F_C_Write('"+tmpDT+"');\"></td>";
	HTM+="<td><img src='" + _GLOBAL_VAR_IMG + "/des/close.bmp' alt='Close Me' onclick=_F_C_CloseMe()></td>";
	
	tmpDT = new Date(dt);
	tmpDT.setYear(dt.getYear()-1);
	HTM+="<td><img src='" + _GLOBAL_VAR_IMG + "/des/left.jpg' onclick=\"_F_C_Write('"+tmpDT+"');\"></td>";
	HTM+="<td><b>" + _F_C_getYear(dt) + "</b></td>";
	
	tmpDT = new Date(dt);
	tmpDT.setYear(dt.getYear()+1);
	HTM+="<td><img src='" + _GLOBAL_VAR_IMG + "/des/right.jpg' onclick=\"_F_C_Write('"+tmpDT+"');\"></td>";
	HTM+="</tr></table>";
	HTM+="</td></tr>";
	HTM+="<tr><td>";
	HTM+="<table width=100% cellpadding=2 cellspacing=0><tr>";
	
	HTM+="<tr align=center>";
	HTM+="<td><B>S";
	HTM+="<td><B>M";
	HTM+="<td><B>T";
	HTM+="<td><B>W";
	HTM+="<td><B>T";
	HTM+="<td><B>F";
	HTM+="<td><B>S";
	HTM+="</tr>";
	HTM+="<tr><td colspan=7 align=center><img src='" + _GLOBAL_VAR_IMG + "/des/dotted_line.gif'></td></tr>"
	
	dt.setDate(1);
	var j = 31 + dt.getDay();
	for(i=0;i<j;i++){
		if(i%7==0)HTM +="<TR>";
		HTM +="<TD align=center class=";
		if(j-i<=31){
			if(_F_C_isDateToSelect(dt)){
				HTM+="CALDAYHOVER";
			}else{
				HTM +="CALDAY onMouseOver='this.className=\"CALDAYHOVER\"' ";
				HTM +="onMouseOut='this.className=\"CALDAY\"' ";
				
			}
			HTM +=" onClick='_F_C_SelectDate(\"" + dt + "\")'";
			HTM +=">";
			HTM += dt.getDate();
			dt.setDate(dt.getDate() + 1);
			if(dt.getDate()==1)break;
		}else{
			HTM += ">&nbsp;";
		}
	}
	HTM+="</tr></table></td><tr></table>"
	_F_C_ResultObj.innerHTML = HTM;
	
	_F_C_ResultObj.className='abs';
	_F_C_ResultObj.style.left = _F_getL(_F_C_CurrObj) - _F_C_CurrObj.offsetWidth;
	_F_C_ResultObj.style.top = _F_getT(_F_C_CurrObj) + _F_C_CurrObj.offsetHeight;
}

function _F_C_CloseMe(){
	_F_C_ResultObj.innerHTML='';
	_F_C_ResultObj.className='invsbl';
}
function _F_C_SelectDate(d){
	
	if(_F_C_CurrObj==null)return;
	d = new Date(d);
	_F_C_CurrObj.value=_F_C_FormattedDate(d);
	_F_C_Write(d);
	
	_F_C_CloseMe();
}


function _F_C_FormattedDate(d){
	d = new Date(d);
	return (d.getMonth()+1) + "/" + d.getDate() + "/" + _F_C_getYear(d);
}

function _F_C_getYear(d){
	var i = d.getYear();
	if(!document.all)i+=1900;
	return i;
}

function _F_C_getMonthName(m){
	var mNames =new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	return mNames[m];
}

function _F_C_isDateToSelect(d){
	var cD = new Date();
	if(_F_C_CurrObj!=null){
		cD=new Date(_F_C_CurrObj.value);
		if(isNaN(cD))cD=new Date();
	}
	
	return _F_C_FormattedDate(cD)==_F_C_FormattedDate(d);
}