//_c_prefixpath is require from page which call opencalendar
//-->init in _c_Calendar
var _c_imgDir = "";
var _c_prefixpath = "";
//<--

var _cf_arr_Select_El = []; // hide <select> <applet> IE6
var _c_show_hint = false;	//do you want to show hint on window status basr
var _c_startAt = 0;			// 0 - sunday ; 1 - monday
var _c_showWeekNumber = 0	;	// 0 - don't show; 1 - show
var _c_showToday = 1;			// 0 - don't show; 1 - show
var _c_showBarToday = 0	;			// 0 - don't show; 1 - show

var _c_imgsrc = new Array("drop1.gif","drop1.gif","left1.gif","left1.gif","right1.gif","right1.gif")
var _c_imgBL = "cornerbotleft.gif"
var _c_imgBR = "cornerbotright.gif"
var _c_imgTL = "cornertopleft.gif"
var _c_imgTR = "cornertopright.gif"
var	_c_styleAnchor="text-decoration:none;color:black;"
// Set Border Color of Selected Date
var	_c_styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"
//var	_c_styleLightBorder="border-style:solid;border-width:1px;border-color:#FF0000;"

var img = new Array();
var _c_iStart,_c_iEnd

var _c_today = new Date()
var _c_dateNow = _c_today.getDate()
var _c_monthNow = _c_today.getMonth()
var _c_yearNow = _c_today.getFullYear()

var _c_ie = document.all;
var _c_dom = document.getElementById;
var _c_ns4 = document.layers;

function _c_Calendar(objname, divname, format, formatChar, lang, path)
{
	_c_prefixpath = path;
	_c_imgDir = _c_prefixpath + "images/calendar/";

	_c_imgBL = _c_imgDir + _c_imgBL;
	_c_imgBR = _c_imgDir + _c_imgBR;
	_c_imgTL = _c_imgDir + _c_imgTL;
	_c_imgTR = _c_imgDir + _c_imgTR;

	this._c_obj = objname;
	
	this._c_divCalendarName = divname;
	if(this._c_divCalendarName=="") this._c_divCalendarName = "divCalendarMTX";

	this._c_currlang = lang;
	if(this._c_currlang=="") this._c_currlang = "en";
	
	if(this._c_currlang=="en")
	{
		this._c_monthNameLong = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		this._c_monthNameShort = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		if (_c_startAt==0)
		{
			this._c_dayNameLong = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
			this._c_dayNameShort = new Array ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		}
		else
		{
			this._c_dayNameLong = new Array ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
			this._c_dayNameShort = new Array ("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
		}
	}
	else
	if(this._c_currlang=="th")
	{
		this._c_monthNameLong = new Array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤกษาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
		this._c_monthNameShort = new Array("มค","กพ","มีค","เมย","พค","มิย","กค","สค","กย","ตค","พย","ธค");
		if (_c_startAt==0)
		{
			this._c_dayNameLong = new Array ("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
			this._c_dayNameShort = new Array ("อา","จ","อ","พ","พฤ","ศ","ส");
		}
		else
		{
			this._c_dayNameLong = new Array ("จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์","อาทิตย์");
			this._c_dayNameShort = new Array ("จ","อ","พ","พฤ","ศ","ส","อา");
		}
	}
	else
	{
		this._c_monthNameLong = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
		this._c_monthNameShort = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
		if (_c_startAt==0)
		{
			this._c_dayNameLong = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
			this._c_dayNameShort = new Array ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		}
		else
		{
			this._c_dayNameLong = new Array ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
			this._c_dayNameShort = new Array ("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
		}
	}

	this._c_format = format;
	if(format=="") this._c_format = "dd/mm/yyyy";

	if(this._c_format.indexOf("mmmm")!=-1) {this._c_monthName = this._c_monthNameLong;}
	else {this._c_monthName = this._c_monthNameShort;}

	if(this._c_format.indexOf("dddd")!=-1) {this._c_dayName = this._c_dayNameLong;}
	else {this._c_dayName = this._c_dayNameShort;}

	this._c_formatChar = formatChar;
	if(formatChar=="") this._c_formatChar = "/";

	this._c_prefixyearAddOn = 1;

	this._c_gotoString = "Go To Current Month";
	this._c_todayString = "Today is";
	this._c_weekString = "Wk";

	if(_c_show_hint)
	{
		this._c_scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
		this._c_scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
		this._c_selectMonthMessage = "Click to select a month.";
		this._c_selectYearMessage = "Click to select a year.";
	}
	else
	{
		this._c_scrollLeftMessage = "";
		this._c_scrollRightMessage = "";
		this._c_selectMonthMessage = "";
		this._c_selectYearMessage = "";
	}

	this._c_closeCalendarMessage = "Close"
	this._c_selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.
	this._c_bPageLoaded=false;
	
	//eval("var " + this._c_divCalendarName + "bShow = false");
	this.bShow = false;
	this.HolidaysCounter = 0
	this.Holidays = new Array()

	if (_c_dom)
	{
		for(i=0;i<_c_imgsrc.length;i++)
		{
			img[i] = new Image
			img[i].src = _c_imgDir + _c_imgsrc[i]
		}
		mainLayer = "<div onclick='"+this._c_obj+".bShow=true;' id='"+this._c_divCalendarName+"' style='display:none;z-index:+999;position:absolute;visibility:hidden;top:0;left:0;'>"
		mainLayer += "	<table cellspacing=0 cellpadding=0 style='font-family:arial;font-size:11px;'>"
		mainLayer += "		<tr><td>"
		mainLayer += "			<table width=100% cellspacing=0 cellpadding=0 border=0 style='font-family:arial;font-size:11px;line-height:0em;'>"
		mainLayer += "				<tr><td width='1'><img src="+_c_imgTL+"></td>";
		mainLayer += "					<td bgcolor='#ffbf00' style='padding-top:3px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='"+this._c_divCalendarName+"_c_caption'></span></B></font></td>"
		mainLayer += "					<td align=right bgcolor='#ffbf00'>"
		mainLayer += "						<table id='" + this._c_divCalendarName + "closeButton' cellpadding=0 cellspacing=1 border=0 bgcolor=#f9d35f style='line-height:0em;'>"
		mainLayer += "							<tr><td><a href=\"javascript:_cf_hideCalendar('" + this._c_divCalendarName +"')\" onMouseOver='document.getElementById(\"" + this._c_divCalendarName + "closeButton\").className=\"whiteBorder\"' onMouseOut='document.getElementById(\"" + this._c_divCalendarName + "closeButton\").className=\"\"'><IMG SRC='"+_c_imgDir+"close.gif' BORDER='0' ALT='"+this._c_closeCalendarMessage+"' style='vertical-align:middle;'></a></td></tr>"
		mainLayer += "						</table></td>"
		mainLayer += "					<td><img src="+_c_imgTR+"></td></tr>"
		mainLayer += "			</table>"
		mainLayer += "		</td></tr>"
		mainLayer += "		<tr><td style='padding:0px' bgcolor=#ffffff>"
		mainLayer += "			<table width=100% cellspacing=0 cellpadding=0 border=0>"
		mainLayer += "				<tr><td width=1 bgcolor=#FFBF00></td><td bgcolor=#FFFFFF><span id='"+this._c_divCalendarName+"content'></span></td><td width=1 bgcolor=#FFBF00></td></tr>"
		mainLayer += "			</table>"
		mainLayer += "		</td></tr>"

		if (_c_showToday==1)
		{
			mainLayer += "<tr><td align=center><table width=100% cellspacing=0 cellpadding=0 border=0 style='line-height:0em;'><tr><td rowspan=2 width=1><img border=0 src=" + _c_imgBL + "></td><td align=center height=5 bgcolor=#FFFFFF><span id='"+ this._c_divCalendarName + "_c_lblToday' style='font-family:Verdana;font-size:9px;'></span></td><td rowspan=2 width=1><img border=0 src=" + _c_imgBR + "></td></tr><tr><td bgcolor=#FFBF00 width=100% height=1>&nbsp;</td></tr></table></td></tr>";
		}
		mainLayer += "</table></div><div id='"+this._c_divCalendarName+"selectMonth' style='z-index:+999;position:absolute;visibility:;'></div><div id='" + this._c_divCalendarName + "selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>";
		document.write (mainLayer);
	}

	_c_Calendar.prototype._cf_addOnClick = function(txtname, callback) 
			{
				eval("var a = document.getElementById('"+txtname+"');");
				if(a!=null)
				{
					eval("document.getElementById('"+txtname+"').onclick = function() {"+this._c_obj+".onclick('"+txtname+"', '" + callback + "');return false;}");
					eval("document.getElementById('"+txtname+"').onkeypress = document.getElementById('"+txtname+"').onclick");
				}
			}
	
	_c_Calendar.prototype._cf_addOnClickTo = function(txtname, dObj, callback) 
			{
				eval("var a = document.getElementById('"+ dObj +"');");
				if(a!=null)
				{
					eval("document.getElementById('"+ dObj +"').onclick = function() {"+this._c_obj+".onclick('"+txtname+"', '" + callback + "');return false;}");
					eval("document.getElementById('"+ dObj +"').onkeypress = document.getElementById('"+txtname+"').onclick");
				}
			}
	
	_c_Calendar.prototype.initca = function() 
			{
				if (!_c_ns4)
				{
					this._c_crossobj = _cf_findElstyle(this._c_divCalendarName);
					this._c_crossMonthObj = _cf_findElstyle(this._c_divCalendarName + "selectMonth");
					this._c_crossYearObj = _cf_findElstyle(this._c_divCalendarName + "selectYear");

					_cf_hideCalendar(this._c_divCalendarName);

					this._c_monthConstructed=false;
					this._c_yearConstructed=false;

					if (_c_showToday==1)
					{
						if(_c_showBarToday==1)
						{
							document.getElementById(this._c_divCalendarName + "_c_lblToday").innerHTML =	this._c_todayString + " <a onmousemove='window.status=\""+this._c_gotoString+"\"' onmouseout='window.status=\"\"' title='"+this._c_gotoString+"' style='"+_c_styleAnchor+"' href='javascript:" + this._c_obj +"._c_dateSelected=_c_dateNow;" + this._c_obj +"._c_monthSelected=_c_monthNow;" + this._c_obj + "._c_yearSelected=_c_yearNow;"+this._c_obj+".constructCalendar();'>"+this._c_dayName[(_c_today.getDay()-_c_startAt==-1)?6:(_c_today.getDay()-_c_startAt)]+", " + _c_dateNow + " " + this._c_monthName[_c_monthNow].substring(0,3)	+ "	" +	_c_yearNow	+ "</a>"
						}
					}

					sHTML1="<span id='"+this._c_divCalendarName+"_c_spanLeft' style='border-style:solid;border-width:1;border-color:#f9d35f;cursor:pointer' onmouseover='_cf_swapImage(\""+this._c_divCalendarName+"changeLeft\",\"left1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\""+this._c_scrollLeftMessage+"\"' onclick=\"javascript:"+this._c_obj+".decMonth()\" onmouseout='clearInterval("+this._c_obj+"._c_intervalID1);_cf_swapImage(\""+this._c_divCalendarName+"changeLeft\",\"left1.gif\");this.style.borderColor=\"#f9d35f\";window.status=\"\"' onmousedown='clearTimeout(" + this._c_obj + "._c_timeoutID1);" + this._c_obj + "._c_timeoutID1=setTimeout(\"" + this._c_obj + ".StartDecMonth()\",500)'onmouseup='clearTimeout(" + this._c_obj + "._c_timeoutID1);clearInterval("+ this._c_obj +"._c_intervalID1)'>&nbsp<IMG align=middle id='"+this._c_divCalendarName+"changeLeft' SRC='"+_c_imgDir+"left1.gif' width=10 height=11 BORDER=0 style='vertical-align:middle;'>&nbsp</span>&nbsp;"
					sHTML1+="<span id='"+this._c_divCalendarName+"_c_spanRight' style='border-style:solid;border-width:1;border-color:#f9d35f;cursor:pointer' onmouseover='_cf_swapImage(\""+this._c_divCalendarName+"changeRight\",\"right1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\""+this._c_scrollRightMessage+"\"' onmouseout='clearInterval(" + this._c_obj + "._c_intervalID1);_cf_swapImage(\"" + this._c_divCalendarName + "changeRight\",\"right1.gif\");this.style.borderColor=\"#f9d35f\";window.status=\"\"' onclick='"+this._c_obj+".incMonth()' onmousedown='clearTimeout(" + this._c_obj + "._c_timeoutID1);" + this._c_obj + "._c_timeoutID1=setTimeout(\"" + this._c_obj + ".StartIncMonth()\",500)'onmouseup='clearTimeout(" + this._c_obj + "._c_timeoutID1);clearInterval(" + this._c_obj + "._c_intervalID1)'>&nbsp<IMG align=middle id='"+this._c_divCalendarName+"changeRight' SRC='"+_c_imgDir+"right1.gif'	width=10 height=11 BORDER=0 style='vertical-align:middle;'>&nbsp</span>&nbsp"
					
					sHTML1+="<span id='"+this._c_divCalendarName+"_c_spanMonth' style='border-style:solid;border-width:1;border-color:#f9d35f;cursor:pointer' onmouseover='_cf_swapImage(\""+this._c_divCalendarName+"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\""+this._c_selectMonthMessage+"\"' onmouseout='_cf_swapImage(\""+this._c_divCalendarName+"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#f9d35f\";window.status=\"\"' onclick='"+ this._c_obj +".popUpMonth()'></span>&nbsp;"
					sHTML1+="<span id='"+this._c_divCalendarName+"_c_spanYear' style='border-style:solid;border-width:1;border-color:#f9d35f;cursor:pointer' onmouseover='_cf_swapImage(\""+this._c_divCalendarName+"changeYear\",\"drop1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\""+this._c_selectYearMessage+"\"' onmouseout='_cf_swapImage(\""+this._c_divCalendarName+"changeYear\",\"drop1.gif\");this.style.borderColor=\"#f9d35f\";window.status=\"\"'	onclick='"+ this._c_obj +".popUpYear()'></span>"
					//sHTML1+="<span id='"+this._c_divCalendarName+"_c_spanYear' style='display: none; border-style:solid;border-width:1;border-color:#f9d35f;cursor:pointer' onmouseover='_cf_swapImage(\""+this._c_divCalendarName+"changeYear\",\"drop2.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\""+this._c_selectYearMessage+"\"' onmouseout='_cf_swapImage(\""+this._c_divCalendarName+"changeYear\",\"drop1.gif\");this.style.borderColor=\"#f9d35f\";window.status=\"\"'	onclick='"+ this._c_obj +".popUpYear()'></span>&nbsp;"

					document.getElementById(this._c_divCalendarName + "_c_caption").innerHTML  =	sHTML1;

					this._c_bPageLoaded=true;
				}
			}

	_c_Calendar.prototype.prefixYear = function (values) 
			{
				if(values==1) {
					this._c_prefixyearAddOn = 1;
				} else {
					var tnow = new Date();
					var sMonth = tnow.getMonth() + 1;
					var sYear = tnow.getFullYear();
					var sYearOld = sYear;
					var i;
					for(i=0;i<=18;i++) {
						sMonth = sMonth + 1;
						if(sMonth>=13) {
							sMonth = 1;
							sYear = sYear + 1;
						}
					}
					this._c_prefixyearAddOn = sYear - sYearOld;
				}
			}

   _c_Calendar.prototype.WeekNbr = function(n) 
			{
			  // Algorithm used:
			  // From Klaus Tondering's Calendar document (The Authority/Guru)
			  // hhtp://www.tondering.dk/claus/calendar.html
			  // a = (14-month) / 12
			  // y = year + 4800 - a
			  // m = month + 12a - 3
			  // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
			  // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
			  // L = d4 / 1460
			  // d1 = ((d4 - L) mod 365) + L
			  // WeekNumber = d1 / 7 + 1

			  year = n.getFullYear();
			  month = n.getMonth() + 1;
			  if (_c_startAt == 0) {
				 day = n.getDate() + 1;
			  }
			  else {
				 day = n.getDate();
			  }

			  a = Math.floor((14-month) / 12);
			  y = year + 4800 - a;
			  m = month + 12 * a - 3;
			  b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
			  J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
			  d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
			  L = Math.floor(d4 / 1460);
			  d1 = ((d4 - L) % 365) + L;
			  week = Math.floor(d1/7) + 1;

			  return week;
		   }

	_c_Calendar.prototype.closeCalendar = function() 
			{
				var	sTmp;
				_cf_hideCalendar(this._c_divCalendarName);
				if (this._c_yearSelected>(_c_yearNow+this._c_prefixyearAddOn))
				{
					var strvar = _cf_constructDate(_c_dateNow, _c_monthNow, _c_yearNow, this._c_format, this._c_monthName, this._c_dayName);
				} 
				else if ((new Date(this._c_yearSelected, this._c_monthSelected, this._c_dateSelected)).getTime()<_c_today.getTime())
				{
					var strvar = _cf_constructDate(_c_dateNow, _c_monthNow, _c_yearNow, this._c_format, this._c_monthName, this._c_dayName);
				}
				else 
				{
					var strvar = _cf_constructDate(this._c_dateSelected, this._c_monthSelected, this._c_yearSelected, this._c_format, this._c_monthName, this._c_dayName);
				}
				this._c_ctlToPlaceValue1.value = strvar;
				eval(this.callback);
			}

	_c_Calendar.prototype.HolidayRec = function(d, m, y, desc)
			{
				this.d = d
				this.m = m
				this.y = y
				this.desc = desc
			}

	_c_Calendar.prototype.addHoliday = function(d, m, y, desc)
			{
				this.Holidays[this.HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
			}

		/*** Year Pulldown	***/
	_c_Calendar.prototype.StartDecYear = function()
			{
				this._c_intervalID1=eval("setInterval('" + this._c_obj + "decYear()',80);");
			}

	_c_Calendar.prototype.StartIncYear = function()
			{
				this._c_intervalID1=eval("setInterval('" + this._c_obj + "incYear()',80);");
			}

		/*** Month Pulldown	***/
	_c_Calendar.prototype.StartDecMonth = function()
			{
				this._c_intervalID1=eval("setInterval('" + this._c_obj + "decMonth()',80);");
			}

	_c_Calendar.prototype.StartIncMonth = function()
			{
				this._c_intervalID1=eval("setInterval('" + this._c_obj + "incMonth()',80);");
			}

	_c_Calendar.prototype.incMonth = function() 
			{
				this._c_monthSelected++;
				if (this._c_monthSelected>11) {
					this._c_monthSelected=0;
					this._c_yearSelected++;
				}
				this.constructCalendar();
			}

	_c_Calendar.prototype.decMonth = function() 
			{
				this._c_monthSelected--;
				if (this._c_monthSelected<0) {
					this._c_monthSelected=11;
					this._c_yearSelected--;
				}
				this.constructCalendar();
			}

	_c_Calendar.prototype.constructMonth = function() 
			{
				this.popDownYear()
			//	if (!this._c_monthConstructed) {
					sHTML =	""
					_c_iStart=0;
					_c_iEnd=12;

						//_c_iStart=_c_monthNow;
						j=0;
						k=0;

						for(i=_c_iStart; i<_c_iEnd; i++) {
							j = i;
							sName =	this._c_monthName[j];
							//j = i + _c_monthNow
							//if (j<=11) {
							//	k = _c_yearNow
							//	sName =	this._c_monthName[j];
							//} else {
							//	j = j-12
							//	k = _c_yearNow + 1
							//	sName =	this._c_monthName[j];
							//}
							k = this._c_yearSelected;
							if (i==this._c_monthSelected){
								sName =	"<B>" +	sName +	"</B>"
							}
							sHTML += "<tr><td id='m" + j + "/" + k + "' onmouseover='this.style.backgroundColor=\"#FFBF00\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='" + this._c_obj + "._c_monthConstructed=false;" + this._c_obj + "._c_monthSelected=" + j + ";" + this._c_obj + "._c_yearSelected="+k+";"+this._c_obj+".constructCalendar();"+this._c_obj+".popDownMonth();event.cancelBubble=true' class=calendar10>&nbsp;" + sName + " &nbsp;</td></tr>"
						}

					document.getElementById(this._c_divCalendarName + "selectMonth").innerHTML = "<table style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#FFBF00;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(" + this._c_obj + "._c_timeoutID1)'	onmouseout='clearTimeout(" + this._c_obj + "._c_timeoutID1);" + this._c_obj + "._c_timeoutID1=setTimeout(\""+this._c_obj+".popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>"

					this._c_monthConstructed=true
			//	}
			}

	_c_Calendar.prototype.constructYear = function() 
			{
				this.popDownMonth()
				sHTML =	""
				if (!this._c_yearConstructed) {
					sHTML =	"";
					//sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#FFBF00\"' onmouseout='clearInterval(" + this._c_obj + "._c_intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='clearInterval(" + this._c_obj + "._c_intervalID1);" + this._c_obj + "._c_intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval("+ this._c_obj +"._c_intervalID1)'>-</td></tr>"

					j =	0
					this._c_nStartingYear =	_c_yearNow;
					for	(i=(_c_yearNow); i<=(_c_yearNow+this._c_prefixyearAddOn); i++) {
						sName =	i;
						if (i==this._c_yearSelected){
							sName =	"<B>" +	sName +	"</B>"
						}

						sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#FFBF00\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='"+ this._c_obj +".selectYear("+j+");event.cancelBubble=true' class=calendar10>&nbsp;" + sName + "&nbsp;</td></tr>"
						j ++;
					}

					//sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(" + this._c_obj + "._c_intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(" + this._c_obj + "._c_intervalID2);" + this._c_obj + "._c_intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(" + this._c_obj + "._c_intervalID2)'>+</td></tr>"

					document.getElementById(this._c_divCalendarName + "selectYear").innerHTML	= "<table style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#FFBF00;'	bgcolor='#FFFFDD' onmouseover='clearTimeout(" + this._c_obj + "._c_timeoutID2)' onmouseout='clearTimeout(" + this._c_obj + "._c_timeoutID2);" + this._c_obj + "._c_timeoutID2=setTimeout(\""+this._c_obj+".popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"

					this._c_yearConstructed	= true
				}
			}

	_c_Calendar.prototype.popDownYear = function() 
			{
				clearInterval(this._c_intervalID1);
				clearTimeout(this._c_timeoutID1);
				clearInterval(this._c_intervalID2);
				clearTimeout(this._c_timeoutID2);
				this._c_crossYearObj.visibility= "hidden";
			}

	_c_Calendar.prototype.popUpYear = function() 
			{
				var	leftOffset;

				this.constructYear();

				this._c_crossYearObj.visibility	= (_c_dom||_c_ie)? "visible" : "show";
				var obj;
				obj = document.getElementById(this._c_divCalendarName + "_c_spanYear");
				var xy = _cf_getMouseXY(obj);
				var x;
				var y;

				x = xy["x"];
				y = xy["y"] + obj.offsetHeight;;

				var old_c_crossYearObjleft = this._c_crossYearObj.left;
				this._c_crossYearObj.left = x;
				if(this._c_crossYearObj.left==old_c_crossYearObjleft) this._c_crossYearObj.left = x +'px';

				var old_c_crossYearObjtop= this._c_crossYearObj.top;
				this._c_crossYearObj.top = y;
				if(this._c_crossYearObj.top==old_c_crossYearObjtop) this._c_crossYearObj.top = y +'px';
			}

	_c_Calendar.prototype.constructCalendar = function() 
			{
				if (this._c_currlang == 'th') {
					tmp_c_yearSelected = _c_yearSelected - 543;
				} else {
					tmp_c_yearSelected = this._c_yearSelected;
				}
				
				//if ((this._c_monthSelected<_c_monthNow) && (this._c_yearSelected==_c_yearNow)) this._c_yearSelected = this._c_yearSelected+1;	//For dropdown changed

				var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)
				var dateMessage
				var startDate =	new Date (tmp_c_yearSelected,this._c_monthSelected,1)
				var endDate

				if (this._c_monthSelected==1)
				{
					endDate	= new Date (tmp_c_yearSelected,this._c_monthSelected+1,1);
					endDate	= new Date (endDate - (24*60*60*1000));
					numDaysInMonth = endDate.getDate()
				}
				else
				{
					numDaysInMonth = aNumDays[this._c_monthSelected];
				}

				datePointer	= 0
				dayPointer = startDate.getDay() - _c_startAt

				if (dayPointer<0)
				{
					dayPointer = 6
				}

				sHTML =	"<table	 border=0 style='font-family:verdana;font-size:10px;'><tr>"

				if (_c_showWeekNumber==1)
				{
					sHTML += "<td width=27><b>" + this._c_weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"+_c_imgDir+"divider.gif' width=1></td>"
				}

				for	(i=0; i<7; i++)	{
					//sHTML += "<td width='' align='right'><B>"+ this._c_dayName[i]+"</B></td>"
					sHTML += "<td width='' align='center' class=calendar10>"+ this._c_dayName[i]+"</td>"
				}
				sHTML +="</tr><tr>"

				if (_c_showWeekNumber==1)
				{
					sHTML += "<td align=right>" + this.WeekNbr(startDate) + "&nbsp;</td>"
				}

				for	( var i=1; i<=dayPointer;i++ )
				{
					sHTML += "<td class=calendar10>&nbsp;</td>"
				}

				for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
				{
					dayPointer++;
					//sHTML += "<td align=right>"
					sStyle = _c_styleAnchor;
					
					if ((datePointer==this.o_c_dateSelected) && (this._c_monthSelected==this.o_c_monthSelected) && (this._c_yearSelected==this.o_c_yearSelected))
					{ sStyle+=_c_styleLightBorder }

					sHint = ""
					for (k=0;k<this.HolidaysCounter;k++)
					{
						if ((parseInt(this.Holidays[k].d)==datePointer)&&(parseInt(this.Holidays[k].m)==(this._c_monthSelected+1)))
						{
							if ((parseInt(this.Holidays[k].y)==0)||((parseInt(this.Holidays[k].y)==this._c_yearSelected)&&(parseInt(this.Holidays[k].y)!=0)))
							{
								sStyle+="background-color:#FFDDDD;"
								sHint+=sHint==""?this.Holidays[k].desc:"\n"+this.Holidays[k].desc
							}
						}
					}

					var regexp= /\"/g
					sHint=sHint.replace(regexp,"&quot;")
					dateMessage = "onmousemove='window.status=\""+this._c_selectDateMessage.replace("[date]",_cf_constructDate(datePointer,this._c_monthSelected,this._c_yearSelected, this._c_format, this._c_monthName, this._c_dayName))+"\"' onmouseout='window.status=\"\"' "

					currentDate = new Date(this._c_yearSelected, this._c_monthSelected, datePointer)

					if ((datePointer==_c_dateNow)&&(this._c_monthSelected==_c_monthNow)&&(this._c_yearSelected==_c_yearNow))
					{
						sHTML += "<td align=right class=calendar10>"
						sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:" + this._c_obj + "._c_dateSelected="+datePointer+";"+this._c_obj+".closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font>&nbsp;</a></b>"}
					//else if	(dayPointer % 7 == (_c_startAt * -1)+1)
					//{
					//	sHTML += "<td align=right>"
					//	sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:" + this._c_obj + "._c_dateSelected="+datePointer + ";"+this._c_obj+".closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" }
					else if(currentDate<_c_today)
					{
						sHTML += "<td align=right class=calendar10>"
						sHTML += "<font color=#cccccc	>&nbsp;" + datePointer + "</font>&nbsp;" }
					else
					{
						sHTML += "<td align=right class=calendar10>"
						sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:" + this._c_obj + "._c_dateSelected="+datePointer + ";"+this._c_obj+".closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" }
					sHTML += ""
					if ((dayPointer+_c_startAt) % 7 == _c_startAt) {
						sHTML += "</tr><tr>"
					//	if ((_c_showWeekNumber==1)&&(datePointer<numDaysInMonth))
					//	{
					//		sHTML += "<td align=right>" + (this.WeekNbr(new Date(this._c_yearSelected,this._c_monthSelected,datePointer+1))) + "&nbsp;</td>"
					//	}
					}
				}

				document.getElementById(this._c_divCalendarName + "content").innerHTML   = sHTML
				document.getElementById(this._c_divCalendarName+"_c_spanMonth").innerHTML = "&nbsp;" + this._c_monthName[this._c_monthSelected] + " &nbsp;<IMG id='" + this._c_divCalendarName+"changeMonth' SRC='"+_c_imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
				document.getElementById(this._c_divCalendarName+"_c_spanYear").innerHTML =	"&nbsp;" + this._c_yearSelected	+ "&nbsp;<IMG id='" + this._c_divCalendarName+"changeYear' SRC='"+_c_imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
			}

	_c_Calendar.prototype.selectYear = function(nYear) 
			{
				this._c_yearSelected=parseInt(nYear+this._c_nStartingYear);
				this._c_yearConstructed=false;
				this.constructMonth();
				this.constructCalendar();
				this.popDownYear();
			}

	_c_Calendar.prototype.decYear = function() 
			{
				for (i=0; i<7; i++){
					newYear	= (i+this._c_nStartingYear)-1
					if (newYear==this._c_yearSelected)
					{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
					else
					{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
					document.getElementById(this._c_divCalendarName+"y"+i).innerHTML = txtYear;
				}
				this._c_nStartingYear --;
				eval(this._c_obj+".bShow=true");
			}

	_c_Calendar.prototype.opencalendar = function (ctl1, callback) 
			{
				this.callback = callback;
				_cf_hideCalendar(this._c_divCalendarName);
				if (this._c_bPageLoaded)
				{
					if ( this._c_crossobj.visibility ==	"hidden" ) {
						this._c_ctlToPlaceValue1	= ctl1
						//this._c_ctlToPlaceValue2	= ctl2

						var strDate;
						if (ctl1.value == "")
						{
							strDate = _cf_constructDate(_c_dateNow, _c_monthNow, _c_yearNow, this._c_format, this._c_monthName, this._c_dayName);
						}
						else
						{
							strDate = ctl1.value;
						}

						_cf_TextToDate(strDate, this, "array");

						this.o_c_dateSelected=this._c_dateSelected;
						this.o_c_monthSelected=this._c_monthSelected;
						this.o_c_yearSelected=this._c_yearSelected;

						this.constructCalendar (1, this._c_monthSelected, this._c_yearSelected);
						
						var _c_oClicked = document.getElementById(ctl1.id);
						var xy = _cf_getMouseXY(_c_oClicked);

						var _c_oShow = document.getElementById(this._c_divCalendarName);
						
						x = ((xy["x"]+_c_oClicked.offsetWidth)-_c_oShow.offsetWidth);
						if(x<0) x =0;
						y = xy["y"]+_c_oClicked.offsetHeight;

						var old_c_crossobjleft = this._c_crossobj.left;
						this._c_crossobj.left = x;
						if(this._c_crossobj.left==old_c_crossobjleft) this._c_crossobj.left = x +'px';

						var old_c_crossobjtop = this._c_crossobj.top;
						this._c_crossobj.top = y;
						if(this._c_crossobj.top==old_c_crossobjtop) this._c_crossobj.top = y +'px';

						this._c_crossobj.display="block"
						this._c_crossobj.visibility=(_c_dom||_c_ie)? "visible" : "show"

						if(_cf_getInternetExplorerVersion()=="6")
						{
							_cf_hideElement( 'SELECT', document.getElementById(this._c_divCalendarName));
							_cf_hideElement( 'APPLET', document.getElementById(this._c_divCalendarName));
						}
						eval(this._c_obj+".bShow = true");
					}
					else
					{
						_cf_hideCalendar(this._c_divCalendarName);
						if (this._c_ctlNow!=ctl1) {this.opencalendar(ctl1,callback)}
					}
					this._c_ctlNow = ctl1;
				}
			}

	_c_Calendar.prototype.popDownMonth = function() 
			{
				this._c_crossMonthObj.visibility= "hidden";
			}

	_c_Calendar.prototype.popUpMonth = function() 
			{
				this.constructMonth();
				this._c_crossMonthObj.visibility = (_c_dom||_c_ie)? "visible"	: "show";

				var obj;
				obj = document.getElementById(this._c_divCalendarName + "_c_spanMonth");
				var xy = _cf_getMouseXY(obj);
				var x;
				var y;

				x = xy["x"];
				y = xy["y"] + obj.offsetHeight;;

				var old_c_crossMonthObjleft = this._c_crossMonthObj.left;
				this._c_crossMonthObj.left = x;
				if(this._c_crossMonthObj.left==old_c_crossMonthObjleft) this._c_crossMonthObj.left = x +'px';

				var old_c_crossMonthObjtop= this._c_crossMonthObj.top;
				this._c_crossMonthObj.top = y;
				if(this._c_crossMonthObj.top==old_c_crossMonthObjtop) this._c_crossMonthObj.top = y +'px';

				if(_cf_getInternetExplorerVersion()=="6")
				{
					_cf_hideElement( 'SELECT', document.getElementById(this._c_divCalendarName + "selectMonth") );
					_cf_hideElement( 'APPLET', document.getElementById(this._c_divCalendarName + "selectMonth") );
				}
			}

		/*** Year Pulldown ***/
	_c_Calendar.prototype.incYear = function() 
			{
				for	(i=0; i<7; i++){
					newYear	= (i+this._c_nStartingYear)+1
					if (newYear==this._c_yearSelected)
					{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
					else
					{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
					document.getElementById(this._c_divCalendarName +"y"+i).innerHTML = txtYear;
				}
				this._c_nStartingYear ++;
				eval(this._c_obj +".bShow=true");
			}

	_c_Calendar.prototype.hideWhenClick = function() 
			{
				var a = this.bShow;
				if (!a)
				{
					_cf_hideCalendar(this._c_divCalendarName)
				}
				eval(this._c_obj+".bShow = false");
			}
	_cf_checkattach("document.onclick",this._c_obj+"addhideandonclick",this._c_obj + ".hideWhenClick");

	this.initca();
}

//global function
function _cf_swapImage(srcImg, destImg){
	if (document.getElementById(srcImg)!=null) { document.getElementById(srcImg).setAttribute("src",_c_imgDir + destImg) }
}

//Returns the version of Internet Explorer or a -1
//(indicating the use of another browser).
function _cf_getInternetExplorerVersion() {
	var rv = 1000; // Return value assumes success.
	if (navigator.appName == 'Microsoft Internet Explorer')	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)  rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

/* hides <select> and <applet> objects (for IE only) */
function _cf_hideElement( elmID, overDiv)
{
  if( _cf_getInternetExplorerVersion()=="6" )
  {
	for( i = 0; i < document.all.tags( elmID ).length; i++ )
	{
	  obj = document.all.tags( elmID )[i];
	  if( !obj || !obj.offsetParent )
	  {
		continue;
	  }

	  // Find the element's offsetTop and offsetLeft relative to the BODY tag.
	  objLeft   = obj.offsetLeft;
	  objTop    = obj.offsetTop;
	  objParent = obj.offsetParent;

	  while( objParent.tagName.toUpperCase() != "BODY" && objParent.tagName.toUpperCase() != "HTML")
	  {
		objLeft  += objParent.offsetLeft;
		objTop   += objParent.offsetTop;
		objParent = objParent.offsetParent;
	  }

	  objHeight = obj.offsetHeight;
	  objWidth = obj.offsetWidth;

	  if(( objLeft + objWidth)<=overDiv.offsetLeft ) {}
	  else if(objLeft >=( overDiv.offsetLeft + overDiv.offsetWidth )) {}
	  else if(objTop>=( overDiv.offsetTop + overDiv.offsetHeight )) {}
	  else if((objTop + objHeight) <=overDiv.offsetTop ) {}
	  else
	  {
			if((obj.style.display=="none") || (obj.style.visibility=="hidden")) {}
			else
			{
				if(_cf_arr_Select_El.indexOf(obj)==-1)
				{
					_cf_arr_Select_El.push(obj);
				}
				obj.style.visibility = "hidden";
				obj.style.display = "none";
			}
	  }
	}
  }
}

/*
* unhides <select> and <applet> objects (for IE only)
*/
function _cf_showElement( )
{
	if(_cf_getInternetExplorerVersion()=="6")
	{
		for(var i=0;i<_cf_arr_Select_El.length;i++)
		{
			var obj = _cf_arr_Select_El[i];
			obj.style.visibility = "visible";
			obj.style.display = "";
		}
		_cf_arr_Select_El = [];
	}
}

function _cf_padZero(num) {
	return (num< 10) ? '0' + num : num ;
}

function _cf_findElstyle(divname)
{
	var a;
	if(_c_dom) 
	{
		a = document.getElementById(divname);
		if(a!=null) {a = a.style;}
	}
	else
	{
		if(_c_ie){ try {a = eval("document.all." + divname)} catch(e){a = null}}
		else {try {a =eval("document." + divname)} catch(e){a = null}}
	}
	return a;
}

function _cf_hideCalendar(divname)
{
	try
	{
		var _c_crossobj = _cf_findElstyle(divname);
		var _c_crossMonthObj = _cf_findElstyle(divname + "selectMonth");
		var _c_crossYearObj = _cf_findElstyle(divname + "selectYear");
		
		if (_c_crossobj != null){_c_crossobj.display="block";_c_crossobj.visibility="hidden";}
		if (_c_crossMonthObj != null){_c_crossMonthObj.visibility="hidden";}
		if (_c_crossYearObj !=	null){_c_crossYearObj.visibility="hidden";}
		if(_cf_getInternetExplorerVersion()=="6")
		{
			_cf_showElement( );
		}
	} catch(e) {}
}

function _cf_getEl(tmpname) {
	var a = (_c_dom)?document.getElementById(tmpname) : _c_ie? eval("document.all."+tmpname)	: eval("document."+tmpname)
	return a;
}

function _cf_checkattach(wevent,names,wfunc) {
	var para = "()";
	if(arguments[3]) para = arguments[3];
	var oldonload;
	oldonload = eval(wevent);
	if(typeof(oldonload)=='function') {
		eval(wevent+'=function '+names+ '() {oldonload();'+wfunc+ para+';}');
	} else {
		eval(wevent+'=function '+names+'() {'+wfunc+ para + ';}');
	}
}

function _cf_getMouseXY(elem) {
	if (!elem) {
		return {"x":0,"y":0};
	}
	var xy={"x":elem.offsetLeft,"y":elem.offsetTop}
	var par=_cf_getMouseXY(elem.offsetParent);
	for (var key in par) {
		xy[key]+=par[key];
	}

	return xy;
}

function _cf_constructDate(d,m,y, format, arrayMonth, arrayDay)
{
	var sTmp = "";
	sTmp = format;
	sTmp = sTmp.replace	("dddd","<z>");
	sTmp = sTmp.replace	("ddd","<z>");
	sTmp = sTmp.replace	("dd","<e>");
	sTmp = sTmp.replace	("d","<d>");
	sTmp = sTmp.replace	("<e>",_cf_padZero(d));
	sTmp = sTmp.replace	("<d>",d);
	sTmp = sTmp.replace	("mmmm","<o>");
	sTmp = sTmp.replace	("mmm","<o>");
	sTmp = sTmp.replace	("mm","<n>");
	sTmp = sTmp.replace	("m","<m>");
	sTmp = sTmp.replace	("<m>",m+1);
	sTmp = sTmp.replace	("<n>",_cf_padZero(m+1));
	sTmp = sTmp.replace	("<o>",arrayMonth[m]);
	var tmpDateM = new Date(y, Number(m), d);
	sTmp = sTmp.replace	("<z>",arrayDay[(tmpDateM.getDay()-_c_startAt==-1)?6:(tmpDateM.getDay()-_c_startAt)]);
	return sTmp.replace ("yyyy",y);
}

function _cf_findValue(arr, index)
{
	var a;
	try
	{
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i]==index) return i;
		}
	} catch(e){ a = "";}
	return a;
}

function _cf_TextToDate(strDate, obj, rtn)
{
	var aFormat	= obj._c_format.split(obj._c_formatChar);
	var aData = strDate.split(obj._c_formatChar);

	var tmpd, tmpm, tmpy
	var tokensChanged = 0;

	for	(i=0;i<aFormat.length;i++)
	{
		if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
		{
			tmpd = parseInt(aData[i], 10)
			tokensChanged ++
		}
		else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
		{
			tmpm =	parseInt(aData[i], 10) - 1
			tokensChanged ++
		}
		else if	(aFormat[i]=="yyyy")
		{
			tmpy = parseInt(aData[i], 10)
			tokensChanged ++
		}
		else if	((aFormat[i]=="mmm") || (aFormat[i]=="mmmm"))
		{
			for	(j=0; j<12;	j++)
			{
				if (aData[i]==obj._c_monthName[j])
				{
					tmpm=j
					tokensChanged ++
				}
			}
		}
	}
	if ((tokensChanged!=3)||isNaN(tmpd)||isNaN(tmpm)||isNaN(tmpy))
	{
		tmpd = _c_dateNow;
		tmpm =	_c_monthNow;
		tmpy = _c_yearNow;
	}

	var tmptext;
	if(rtn=="array")
	{
		obj._c_dateSelected = tmpd;
		obj._c_monthSelected =	tmpm;
		obj._c_yearSelected = tmpy;
	} 
	else if(rtn=="date")
	{
		return _cf_ChStrtoDate(_cf_padZero(tmpd) + obj._c_formatChar + _cf_padZero(tmpm + 1) + obj._c_formatChar + tmpy, obj._c_formatChar);
	}
}

function _cf_ChDatetoStr(cDate, formatChar) {
	return _cf_padZero(cDate.getDate()) + formatChar + _cf_padZero(cDate.getMonth() + 1) + formatChar + cDate.getFullYear();
}

//dd/mm/yyyy
function _cf_ChStrtoDate(cDate, formatChar) {
	var arrcDate = cDate.split(formatChar);
	return new Date(arrcDate[2], Number(arrcDate[1])-1, Number(arrcDate[0]));
}

