@cc_on
var cCalendarGlobalArray=new Array();
var cCalendarGlobalIE55=(@_jscript_version-5.5)<0?false:true;
var cCalendarGlobalScrollX="visible";
var cCalendarGlobalScrollY="visible";
var cCalendarObject=null;
if(!cCalendarGlobalZIndex)var cCalendarGlobalZIndex=2000000;

/*if (typeof(window['is_calendar_translation_loaded']) == "undefined")
{
	var trans_js_href = document.location.href;
	trans_js_href = trans_js_href + ((trans_js_href.indexOf("?") != -1)?"&":"?") + "class=cAuxilary&method=mGetCalendarJS";
	document.write("<script language='JavaScript' src='" + trans_js_href + "'></script>");
}*/

function calendarKick()
{
	if(document.readyState.toLowerCase()!="complete")return true;
	if(cCalendarGlobalArray.length==0)return true;
	if(typeof(cCalendarGlobalArray[0])!="object"||!(cCalendarGlobalArray[0] instanceof cCalendar))return true;
	var args=calendarKick.arguments;
	var argsLen=args.length;
	var x,y;
	var showTime=false;
	var showForIE5=true;
	if(argsLen>=1) // object to which return the value
	{
		if(typeof(args[0])=="object")
		{
			var retObj=args[0];
		}
		else if(typeof(args[0])=="string")
		{
			var retObj=document.all[args[0]];
			if(!retObj)return false;
		}
		else return false;
	}
	if(argsLen>=3) // coordinates to show the calendar at
	{
		if(typeof(args[1])=="number"&&typeof(args[2])=="number"&&!cCalendarGlobalIE55)
		{
			x=args[1];
			y=args[2];
		}
		else
		{
			if(event&&cCalendarGlobalIE55)
			{
				x=event.x;
				y=event.y;
			}
			else if(event&&!cCalendarGlobalIE55)
			{
				x=document.body.scrollLeft+event.clientX;
				y=document.body.scrollTop+event.clientY;
			}
			else if(!event&&cCalendarGlobalIE55&&typeof(args[1])=="number"&&typeof(args[2])=="number")
			{
				x=args[1];
				y=args[2];
			}
			else return false;
		}
	}
	if(argsLen>=4) // wheather to show the time block
	{
		if(typeof(args[3])=="boolean")
		{
			showTime=args[3];
		}
		else if(typeof(args[3])=="number"||typeof(args[3])=="string")
		{
			showTime=(parseInt(args[3])==1)?true:false;
		}
	}
	if(argsLen>=5) // wheather to show 'Now' button
	{
		if(typeof(args[4])=="boolean")
		{
			var showNow=args[4];
		}
	}
	if(argsLen>=6) // format of the date and time to return
	{
		if(typeof(args[5])=="string")
		{
			var dateFormat=args[5];
		}
	}
	if(argsLen>=7) // wheather to show the date picker in IE 5.0
	{
		if(typeof(args[6])=="boolean")
		{
			var showForIE5=args[6];
		}
	}
	if(typeof(cCalendarGlobalArray[0])=="object"&&(cCalendarGlobalArray[0] instanceof cCalendar))
	{
		var obj=cCalendarGlobalArray[0];
/*		if (retObj.value!="")
		{
		   var re = /(\d+)-(\d+)-(\d+)/;
		   var str = retObj.value;
		   var arr = re.exec(str);
		   obj.setDate(new Date(RegExp.$1,RegExp.$2-1,RegExp.$3));
		}*/
		obj.show({"oRetObj":retObj,"nX":x,"nY":y,"bShowTime":(showTime==showTime?showTime:null),"bShowNow":(showNow==showNow?showNow:null),"sOutFormat":(dateFormat==dateFormat?dateFormat:null),"bShowForIE5":(showForIE5==showForIE5?showForIE5:null)});
	}
	return true;
}

function cCalendar(oDate)
{
	if(cCalendar.arguments.length==0)
	{
		this._selectedDate=new Date;
		this._none=false;
	}
	else
	{
		this._selectedDate=oDate||new Date();
		this._none=oDate==null;
	}

	if(cCalendarGlobalIE55)
	{
		this.oPopup=window.createPopup();
		var oPopupBody=this.oPopup.document.body;
		var oStyle=this.oPopup.document.createElement('LINK');
		oStyle.type="text/css";
		oStyle.rel="StyleSheet";
		oStyle.href="i/def/xsight.cCalendar.css";
		oPopupBody.appendChild(oStyle);

		var oStyle=this.oPopup.document.createElement('LINK');
		oStyle.id='datePickerCSS';
		oStyle.type="text/css";
		oStyle.rel="StyleSheet";
		oStyle.href="i/def/xsight.cCalendar.css";
		oPopupBody.appendChild(oStyle);
	}

	this._returnValueObj=null; //obj to which return the value

	this._returnValueFormat="YYYY-MM-DD";
	this._returnValueDefaultDateFormat="YYYY-MM-DD";
	this._returnValueDefaultDateTimeFormat="YYYY-MM-DD HH24:MI:00";

	this._startYear=1900;

	this._showForIE5=true;

	this._x=0;
	this._y=0;
	this._width=0; // calculated container width
	this._height=0; // calculated container height

	this._fullHeight=0;
	this._timeBlockHeight=0;

	this._matrix=[[],[],[],[],[],[],[]];

	this._showTime=false;
	this._showNow=true;
	this._firstWeekDay=0;
	this._redWeekDay=6;

	this.months=new Array();
	this.months[0] = globals.fGet('TXT_JANUARY');
	this.months[1] = globals.fGet('TXT_FEBRUARY');
	this.months[2] = globals.fGet('TXT_MARCH');
	this.months[3] = globals.fGet('TXT_APRIL');
	this.months[4] = globals.fGet('TXT_MAY');
	this.months[5] = globals.fGet('TXT_JUNE');
	this.months[6] = globals.fGet('TXT_JULY');
	this.months[7] = globals.fGet('TXT_AUGUST');
	this.months[8] = globals.fGet('TXT_SEPTEMBER');
	this.months[9] = globals.fGet('TXT_OCTOBER');
	this.months[10] = globals.fGet('TXT_NOVEMBER');
	this.months[11] = globals.fGet('TXT_DECEMBER');

	this._days=new Array();
	this._days[0] = globals.fGet('TXT_MO');
	this._days[1] = globals.fGet('TXT_TU');
	this._days[2] = globals.fGet('TXT_WE');
	this._days[3] = globals.fGet('TXT_TH');
	this._days[4] = globals.fGet('TXT_FR');
	this._days[5] = globals.fGet('TXT_SA');
	this._days[6] = globals.fGet('TXT_SU');

	this._dontChangeNone=false;

	this.onchange=function(){return true;};

	var id=cCalendarGlobalArray.length;

	cCalendarGlobalArray[id]=this;
	this.id=id;
	return this;
}

cCalendar.prototype.create=function(doc)
{
	if(doc==null)doc=document;

	this._document=doc;

	// create elements

// container
	this._el=doc.createElement("div");
	this._el.className="xsCalendarContainer";

	this.style=this._el.style;

	this._elTable=doc.createElement("table");

	this._elTable.cellPadding=0;
	this._elTable.cellSpacing=0;
	this._elTable.border=0;
	this._elTable.width="100%";

	this._el.appendChild(this._elTable);

	var tbody=doc.createElement("tbody");

	this._elTable.appendChild(tbody);

	var tr=doc.createElement("tr");

	tbody.appendChild(tr);

	var td=doc.createElement("td");

	this._elTableCell=td;

	tr.appendChild(td);

	var fldset=doc.createElement("fieldset");
	this._timeBlock=fldset;
	fldset.className="xsCalendarFieldset";
	fldset.id="cCalendarTimeBlock_id";
	this._timeBlock.style.display=this._showTime?"":"none";

	this._elTableCell.appendChild(fldset);

	var lgnd=doc.createElement("legend");
	lgnd.align="left";
	lgnd.appendChild(doc.createTextNode());
	lgnd.firstChild.nodeValue = globals.fGet('TXT_TIME');

	fldset.appendChild(lgnd);

	// hours + minutes
	var tbl=doc.createElement("table");
	tbl.cellSpacing=0;
	tbl.cellPadding=3;
	tbl.border=0;
	tbl.className="xsCalendarTimeTable";

	fldset.appendChild(tbl);

	var tbody=doc.createElement("tbody");
	tbl.appendChild(tbody);

	var tr=doc.createElement("tr");
	tbody.appendChild(tr);

	var td1=doc.createElement("td");
	td1.appendChild(doc.createTextNode());
	td1.firstChild.nodeValue = globals.fGet('TXT_HOURS');
	tr.appendChild(td1);

	var td2=doc.createElement("td");
	td2.innerHTML="<select hideFocus=true name=cCalendarHours id=cCalendarHours_id class=xsCalendarHours datePickerId="+this.id+" ></select>";

	this._hours=td2.firstChild;
	this._hours.onchange=function()
	{
		cCalendarGlobalArray[parseInt(this.datePickerId)].setHours(this.value);
	}

	tr.appendChild(td2);

	var td3=doc.createElement("td");
	td3.appendChild(doc.createTextNode());
	td3.firstChild.nodeValue = globals.fGet('TXT_MINUTES');

	tr.appendChild(td3);

	var td4=doc.createElement("td");
	td4.innerHTML="<select hideFocus=true name=cCalendarMinutes id=cCalendarMinutes_id class=xsCalendarMinutes datePickerId="+this.id+" ></select>";

	this._minutes=td4.firstChild;
	this._minutes.onchange=function()
	{
		cCalendarGlobalArray[parseInt(this.datePickerId)].setMinutes(this.value);
	}

	tr.appendChild(td4);

	this._fillHours();
	this._fillMinutes();

	//// hours + minutes

// data block

	var fldset=doc.createElement("fieldset");
	fldset.className="xsCalendarFieldset";

	this._elTableCell.appendChild(fldset);

	var lgnd=doc.createElement("legend");
	lgnd.align="left";
	lgnd.appendChild(doc.createTextNode());
	lgnd.firstChild.nodeValue = globals.fGet('TXT_DATE');

	fldset.appendChild(lgnd);

	var tbl=doc.createElement("table");
	tbl.cellSpacing=0;
	tbl.cellPadding=0;
	tbl.border=0;
	tbl.className="xsCalendarDateTable";

	fldset.appendChild(tbl);

	var tbody=doc.createElement("tbody");
	tbl.appendChild(tbody);

	var tr=doc.createElement("tr");
	tbody.appendChild(tr);

	var td=doc.createElement("td");
	tr.appendChild(td);
	// month + year table
	var tbl=doc.createElement("table");
	tbl.cellSpacing=0;
	tbl.cellPadding=3;
	tbl.border=0;
	tbl.className="xsCalendarDateTable";

	td.appendChild(tbl);

	var tbd=doc.createElement("tbody");

	tbl.appendChild(tbd);

	var tr1=doc.createElement("tr");
	tbd.appendChild(tr1);

	var td1=doc.createElement("td");
	td1.appendChild(doc.createTextNode());
	td1.firstChild.nodeValue = globals.fGet('TXT_MONTH');

	tr1.appendChild(td1);

	var td2=doc.createElement("td");
	td2.innerHTML="<select size=2 hideFocus=true name=cCalendarMonth id=cCalendarMonth_id class=xsCalendarMonth datePickerId="+this.id+" ></select>";

	this._months=td2.firstChild;
	this._months.onchange=function()
	{
		cCalendarGlobalArray[parseInt(this.datePickerId)].setMonth(this.value);
	}

	tr1.appendChild(td2);

	var td3=doc.createElement("td");
	td3.appendChild(doc.createTextNode());
	td3.firstChild.nodeValue = globals.fGet('TXT_YEAR');

	tr1.appendChild(td3);

	var td4=doc.createElement("td");
	td4.innerHTML="<select size=2 hideFocus=true name=cCalendarYear id=cCalendarYear_id class=xsCalendarYear datePickerId="+this.id+" ></select>";

	this._years=td4.firstChild;
	this._years.onchange=function()
	{
		cCalendarGlobalArray[parseInt(this.datePickerId)].setYear(this.value);
	}

	tr1.appendChild(td4);

	this._fillMonths();
	//this._fillRusMonths();
	this._fillYears();

	//// month + year table

	var tr=doc.createElement("tr");
	tbody.appendChild(tr);

	var td=doc.createElement("td");
	td.align="center";
	tr.appendChild(td);

	// calendar grid
	div=doc.createElement("div");
	div.className="xsCalendarGrid";

	td.appendChild(div);
	this._table=div;

	//// calendar grid

// time block

	// buttons
	var footerTable=doc.createElement("table");
	footerTable.className="xsCalendarFooterTable";
	footerTable.cellSpacing=footerTable.cellPpacing=footerTable.border=0;
	this._elTableCell.appendChild(footerTable);

	var tBody=doc.createElement("tbody");
	footerTable.appendChild(tBody);

	var tr=doc.createElement("tr");
	tBody.appendChild(tr);

	var td=doc.createElement("td");

	tr.appendChild(td);

	this._nowButton=doc.createElement("button");
	this._nowButton.className="xsCalendarButton";
	this._nowButton.appendChild(doc.createTextNode());
	this._nowButton.firstChild.nodeValue = globals.fGet('BTN_NOW');
	td.appendChild(this._nowButton);

	var td=doc.createElement("td");
	td.style.textAlign="right";
	td.width="75%";

	tr.appendChild(td);

	this._okButton=doc.createElement("button");
	this._okButton.className="xsCalendarButton";
	this._okButton.appendChild(doc.createTextNode());
	this._okButton.firstChild.nodeValue = globals.fGet('BTN_OK');
	td.appendChild(this._okButton);

	this._cancelButton=doc.createElement("button");
	this._cancelButton.className="xsCalendarButton";
	this._cancelButton.appendChild(doc.createTextNode());
	this._cancelButton.firstChild.nodeValue = globals.fGet('BTN_CANCEL');
	td.appendChild(this._cancelButton);

	//// buttons

//////////////////////////////

	this._createTable(doc);

	this._updateTable();

//////////////////////////////

	if(!this._showNow)this._nowButton.style.visibility="hidden";

	// IE55+ extension
	this._nowButton.hideFocus=true;
	this._okButton.hideFocus=true;
	this._cancelButton.hideFocus=true;

	// hook up events
	var dp=this;

	// buttons

	this._nowButton.onclick=function()
	{
		dp.goToToday();
	};

	this._okButton.onclick=function()
	{
		dp.submitForm();
	};

	this._cancelButton.onclick=function()
	{
		dp.cancelForm();
	};

	this._el.onselectstart=this._el.ondragstart=this._el.onclick=this._el.onmousedown=this._el.onmouseup=this._el.onmouseover=this._el.onmouseout=this._el.ondblclick=this._el.oncontextmenu=function()
	{
		return false;
	};

	this._table.onclick=function(e)
	{
		// find event
		if(e==null)e=doc.parentWindow.event;

		// find td
		var el=e.srcElement;
		while(el.nodeType!=1)el=el.parentNode;

		while(el!=null&&el.tagName&&el.tagName.toLowerCase()!="td")el=el.parentNode;

		// if no td found, return
		if(el==null||el.tagName==null||el.tagName.toLowerCase()!="td")return true;

		var d=new Date(dp._selectedDate);
		var n=Number(el.firstChild.data);
		//alert(n);
		if(isNaN(n)||n<=0||n==null)return true;
		d.setDate(n);
		dp.setDate(d);
		doc.parentWindow.event.cancelBubble=true;
		doc.parentWindow.event.returnValue=false;
		return false;
	};

	/*this._el.onkeydown=function(e)
	{
		if(e==null)e=doc.parentWindow.event;
		var kc=e.keyCode!=null?e.keyCode:e.charCode;

		if(kc<37||kc>40)return true;

		var d=new Date(dp._selectedDate).valueOf();
		if(kc==37)d-=86400000; // prev day
		else if(kc==39)d+=86400000; // next day
		else if(kc==38)d-=604800000; // up a week
		else if(kc==40)d+=604800000; // down a week

		dp.setDate(new Date(d));
		return false;
	}*/

	// ie6 extension
	this._el.onmousewheel=function(e)
	{
		if(e==null)e=doc.parentWindow.event;
		var n=-e.wheelDelta/120;
		var d=new Date(dp._selectedDate);
		var m=d.getMonth()+n;
		d.setMonth(m);

		dp._dontChangeNone=true;
		dp.setDate(d);
		dp._dontChangeNone=false;

		return false;
	}

	if(!cCalendarGlobalIE55)
	{
		this.style.display="none";
		this.style.position="absolute";
		this.style.zIndex=cCalendarGlobalZIndex+this.id;
	}

	this._setGeomParams();
	return this._el;
};

cCalendar.prototype.setDate=function(oDate)
{
	// if null then set None
	if(oDate==null)
	{
		if(!this._none)
		{
			this._none=true;
			this._updateTable();

			if(typeof this.onchange=="function")this.onchange();
		}
		return;
	}

	// if string or number create a Date object
	if(typeof oDate=="string"||typeof oDate=="number")
	{
		oDate=new Date(oDate);
	}

	// do not update if not really changed
	if(this._selectedDate.getDate()!=oDate.getDate()||
		this._selectedDate.getMonth()!=oDate.getMonth()||
		this._selectedDate.getFullYear()!=oDate.getFullYear()||
		this._selectedDate.getHours()!=oDate.getHours()||
		this._selectedDate.getMinutes()!=oDate.getMinutes()||
		this._none)
	{

		if(!this._dontChangeNone)this._none=false;

		this._selectedDate=new Date(oDate);

		this._updateTable();
		if(this._selectedDate.getMonth()!=this._months.value)this._updateMonths();
		if(this._selectedDate.getFullYear()!=this._years.value)this._updateYears();

		if(this._showTime)
		{
			if(parseInt(this._selectedDate.getHours())!=parseInt(this._hours.value))this._updateHours();
			if(Math.floor(parseInt(this._selectedDate.getMinutes())/5)!=parseInt(this._minutes.value))this._updateMinutes();
		}

		if(typeof this.onchange=="function")this.onchange();
	}

	if(!this._dontChangeNone)this._none=false;
}

cCalendar.prototype.getDate=function()
{
	if(this._none)return null;
	return new Date(this._selectedDate); // create a new instance
}

cCalendar.prototype.getFormattedDate=function()
{
	if( this._none )
		return null;

	var d = new Date( this._selectedDate );
	return( this._returnValueFormat.replace("DD",(((t=parseInt(d.getDate()))<10)?""+"0"+t:t)).replace("MM",(((t=parseInt(d.getMonth())+1)<10)?""+"0"+t:t)).replace("YYYY",d.getFullYear()).replace("HH24",(((t=parseInt(d.getHours()))<10)?""+"0"+t:t)).replace("HH",(((t=parseInt(d.getHours()))<10)?""+"0"+t:t)).replace("MI",(((t=parseInt(d.getMinutes()))<10)?""+"0"+t:t)) );
}

// creates the table elements and inserts them into the date picker
cCalendar.prototype._createTable=function(doc)
{
	if(this._table==null)return;

	var i;
	var rows=6;
	var cols=7;
	var currentWeek=0;

	var table=doc.createElement("table");
	table.className="xsCalendarGridTable";
	table.cellSpacing=0;

	var tBody=doc.createElement("tbody");
	table.appendChild(tBody);

	// days row
	var tr=doc.createElement("tr");
	tr.className="xsCalendarDaysRow";

	tBody.appendChild(tr);

	var td;
	var nbsp=String.fromCharCode(160);

	for(i=0;i<cols;i++)
	{
		td=doc.createElement("td");
		td.appendChild(doc.createTextNode(nbsp));
		tr.appendChild(td);
	}

	// rest
	for(i=0;i<rows;i++)
	{
		tr=doc.createElement("tr");

		tBody.appendChild(tr);

		for(var j=0;j<cols;j++)
		{
			td=doc.createElement("td");
			td.appendChild(doc.createTextNode(nbsp));
			tr.appendChild(td);
		}
	}

	if(this._table!=null)this._table.appendChild(table);
};

// this method updates all the text nodes inside the table as well
// as all the classNames on the tds
cCalendar.prototype._updateTable=function()
{
	// if no element no need to continue
	if(this._table==null)return;

	var i;
	var str="";
	var rows=6;
	var cols=7;
	var currentWeek=0;

	var cells=new Array(rows);
	this._matrix=new Array(rows)
	for(i=0;i<rows;i++)
	{
		cells[i]=new Array(cols);
		this._matrix[i]=new Array(cols);
	}

	// Set the tmpDate to this month
	var tmpDate=new Date(this._selectedDate.getFullYear(),this._selectedDate.getMonth(),1);

	var today=new Date();

	// go thorugh all days this month and store the text
	// and the class name in the cells matrix
	for(i=1;i<32;i++)
	{
		tmpDate.setDate(i);
		// convert to ISO, Monday is 0 and 6 is Sunday
		var weekDay=(tmpDate.getDay()+6)%7;
		var colIndex=(weekDay-this._firstWeekDay+7)%7;
		if(tmpDate.getMonth()==this._selectedDate.getMonth())
		{
			var isToday=tmpDate.getDate()==today.getDate()&&
						tmpDate.getMonth()==today.getMonth()&&
						tmpDate.getFullYear()==today.getFullYear();

			cells[currentWeek][colIndex]={text:"",className:""};

			if(this._selectedDate.getDate()==tmpDate.getDate()&&!this._none)cells[currentWeek][colIndex].className+="selected ";
			if(isToday)cells[currentWeek][colIndex].className+="today ";
			if((tmpDate.getDay()+6)%7==this._redWeekDay)cells[currentWeek][colIndex].className+="red";// ISO

			cells[currentWeek][colIndex].text=this._matrix[currentWeek][colIndex]=tmpDate.getDate();

			if(colIndex==6)currentWeek++;
		}
	}

	// fix day letter order if not standard
	var weekDays=this._days;
	if(this._firstWeekDay!=0)
	{
		weekDays=new Array(cols);
		for(i=0;i<cols;i++)weekDays[i]=this._days[(i+this._firstWeekDay)%7];
	}

	// update text in days row
	var tds=this._table.firstChild.tBodies[0].rows[0].cells;
	for(var i=0;i<cols;i++)
	{
		tds[i].firstChild.data=weekDays[i];
	}
	// update the text nodes and class names
	var trs=this._table.firstChild.tBodies[0].rows;
	var tmpCell;
	var nbsp=String.fromCharCode(160);
	for(var y=0;y<rows;y++)
	{
		for(var x=0;x<cols;x++)
		{
			tmpCell=trs[y+1].cells[x];
			if(typeof cells[y][x]!="undefined")
			{
				tmpCell.className=cells[y][x].className;
				tmpCell.firstChild.data=cells[y][x].text;
			}
			else
			{
				tmpCell.className="";
				tmpCell.firstChild.data=nbsp;
			}
		}
	}
}

// goes to the selected month
cCalendar.prototype.setMonth=function(nMonth)
{
	if(typeof(nMonth)=="number"||typeof(nMonth)=="string")nMonth=nMonth*1;
	else return false;
	if(nMonth<0||nMonth>11)return false;
	var d=new Date(this._selectedDate);
	d.setMonth(nMonth);
	this.setDate(d);
}

// goes to the selected year
cCalendar.prototype.setYear=function(nYear)
{
	if(typeof(nYear)=="number"||typeof(nYear)=="string")nYear=nYear*1;
	else return false;
	if(nYear<this._startYear||nYear>2049)return false;
	var d=new Date(this._selectedDate);
	d.setFullYear(nYear);
	this.setDate(d);
}

cCalendar.prototype.setHours=function(nHour)
{
	if(typeof(nHour)=="number"||typeof(nHour)=="string")nHour=nHour*1;
	else return false;
	if(nHour<0||nHour>23)return false;
	var d=new Date(this._selectedDate);
	d.setHours(nHour);
	this.setDate(d);
}

cCalendar.prototype.setMinutes=function(nMinutes)
{
	if(typeof(nMinutes)=="number"||typeof(nMinutes)=="string")nMinutes=nMinutes*1;
	else return false;
	if(nMinutes<0||nMinutes>59)return false;
	var d=new Date(this._selectedDate);
	d.setMinutes(nMinutes);
	this.setDate(d);
}

cCalendar.prototype.submitForm=function()
{
	var d=new Date(this._selectedDate);
	if(this._returnValueObj)
	{
		this._returnValueObj.value=this._returnValueFormat.replace("DD",(((t=parseInt(d.getDate()))<10)?""+"0"+t:t)).replace("MM",(((t=parseInt(d.getMonth())+1)<10)?""+"0"+t:t)).replace("YYYY",d.getFullYear()).replace("HH24",(((t=parseInt(d.getHours()))<10)?""+"0"+t:t)).replace("HH",(((t=parseInt(d.getHours()))<10)?""+"0"+t:t)).replace("MI",(((t=parseInt(d.getMinutes()))<10)?""+"0"+t:t));
	}
	this.hide();
	return true;
}

cCalendar.prototype.cancelForm=function()
{
	this.hide();
	return true;
}

cCalendar.prototype.goToToday=function()
{
	if(this._none)this._selectedDate=new Date(this._selectedDate+10000000000); // change the selectedDate to force update if none was true
	this._none=false;
	this.setDate(new Date());
	return;
}

cCalendar.prototype.setShowToday=function(bShowNow)
{
	if(typeof(bShowNow)=="boolean")
	{
		if(this._nowButton!=null)this._nowButton.style.visibility=bShowNow?"visible":"hidden";
		this._showNow=bShowNow;
	}
	return;
}

cCalendar.prototype.getShowToday=function()
{
	return this._showNow;
}

cCalendar.prototype.setShowTime=function(bShowTime)
{
	if(typeof(bShowTime)=="boolean")
	{
		if(this._timeBlock!=null)this._timeBlock.style.display=bShowTime?"":"none";
		this._showTime=bShowTime;
		this._returnValueFormat=this._showTime?this._returnValueDefaultDateTimeFormat:this._returnValueDefaultDateFormat;
		this._updateGeomParams();
	}
	return;
}

cCalendar.prototype.getShowTime=function()
{
	return this._showTime;
}

// 0 is monday and 6 is sunday as in the ISO standard
cCalendar.prototype.setFirstWeekDay=function(nFirstWeekDay)
{
	if(this._firstWeekDay!=nFirstWeekDay)
	{
		this._firstWeekDay=nFirstWeekDay;
		this._updateTable();
	}
	return;
}

cCalendar.prototype.getFirstWeekDay=function()
{
	return this._firstWeekDay;
}

// 0 is monday and 6 is sunday as in the ISO standard
cCalendar.prototype.setRedWeekDay=function(nRedWeekDay)
{
	if(this._redWeekDay!=nRedWeekDay)
	{
		this._redWeekDay=nRedWeekDay;
		this._updateTable();
	}
	return;
}

cCalendar.prototype.getRedWeekDay=function()
{
	return this._redWeekDay;
}

cCalendar.prototype._fillHours=function()
{
	var theEl=this._hours;
	var theCurHours=this._selectedDate.getHours();
	theCurHours=theCurHours<10?""+"0"+theCurHours:theCurHours;
	if(theEl)
	{
		if(theEl.options.length>0)for(var i=0;i<theEl.options.length;i++)theEl.options.remove(0);
		for(var i=0;i<24;i++)
		{
			var opt=this._document.createElement("option");
			opt.value=opt.text=(i<10?""+"0"+i:i);
			theEl.options.add(opt);
		}
		theEl.options[parseInt(theCurHours)].selected=true;
	}
	return true;
}

cCalendar.prototype._updateHours=function()
{
	var theEl=this._hours;
	var theCurHours=parseInt(this._selectedDate.getHours());
	if(theEl)theEl.options[theCurHours].selected=true;
	return true;
}

cCalendar.prototype._fillMinutes=function()
{
	var theEl=this._minutes;
	var theCurMinutes=this._selectedDate.getMinutes();
	theCurMinutes=theCurMinutes<10?""+"0"+theCurMinutes:theCurMinutes;
	if(theEl)
	{
		theEl.options.length=0;
		for(var i=0;i<60;i+=5)
		{
			var opt=this._document.createElement("option");
			opt.value=opt.text=(i<10?""+"0"+i:i);
			theEl.options.add(opt);
		}
		theEl.options[Math.floor(parseInt(theCurMinutes)/5)].selected=true;
	}
	return true;
}

cCalendar.prototype._updateMinutes=function()
{
	var theEl=this._minutes;
	var theCurMinutes=parseInt(this._selectedDate.getMinutes());
	if(theEl)theEl.options[Math.floor(theCurMinutes/5)].selected=true;
	return true;
}

cCalendar.prototype._fillMonths=function()
{
	var theEl=this._months;
	var theCurMonth=this._selectedDate.getMonth();
	if(theEl)
	{
		var len=this.months.length;
		if(theEl.options.length>0)for(var i=0;i<theEl.options.length;i++)theEl.options.remove(0);
		for(var i=0;i<len;i++)
		{
			var opt=this._document.createElement("option");
			opt.value=i;
			opt.text=this.months[i];
			theEl.options.add(opt);
		}
		theEl.options[theCurMonth].selected=true;
	}
	return true;
}

cCalendar.prototype._updateMonths=function()
{
	var theEl=this._months;
	var theCurMonth=this._selectedDate.getMonth();
	if(theEl)theEl.options[theCurMonth].selected=true;
	return true;
}

cCalendar.prototype._fillYears=function()
{
	var theEl=this._years;
	var theSelYear=this._selectedDate.getFullYear();
	var theCurYear=new Date().getFullYear();
//	if(theSelYear<this._startYear)theSelYear=2000;
//	if(theCurYear<2000)theCurYear=2000;
	if(theSelYear<this._startYear)theSelYear=1920;
	if(theCurYear<2000)theCurYear=1920;
	if(theEl)
	{
		if(theEl.options.length>0)for(var i=0;i<theEl.options.length;i++)theEl.options.remove(0);
		var len=(theCurYear+1-this._startYear)+20;
		if(len<2)len=2;
		for(var i=0;i<len;i++)
		{
			var opt=this._document.createElement("option");
			opt.value=opt.id=opt.text=i+this._startYear;
			theEl.options.add(opt);
		}
		theEl.options[theSelYear-this._startYear].selected=true;
	}
	return true;
}

cCalendar.prototype._updateYears=function()
{
	var theEl=this._years;
	var theSelYear=this._selectedDate.getFullYear();
	
	try
	{
		if(theEl)
			theEl.options[theSelYear-this._startYear].selected=true;
	}
	catch (err)
	{
		
	}

	return true;
}

cCalendar.prototype._setGeomParams=function()
{
	if(this._table==null)return false;
	if(!this._showTime)this._timeBlock.style.display="";
	this.style.width=(this._width=this._el.offsetWidth)+"px";
	this.style.height=(this._fullHeight=this._height=this._el.offsetHeight)+"px";
	this._timeBlockHeight=this._timeBlock.offsetHeight;
	if(!this._showTime)this._timeBlock.style.display="none";
	return true;
}

cCalendar.prototype._updateGeomParams=function()
{
	if(this._table==null)return false;
	this._document.recalc();
	if(this._showTime)
	{
		this.style.height=(this._height=this._fullHeight)+"px";
	}
	else
	{
		this.style.height=(this._height=this._fullHeight-this._timeBlockHeight)+"px";
	}
	//if(this._showForIE5||cCalendarGlobalIE55)this.show();
	return true;
}

cCalendar.prototype.show=function()
{
	if(this._table==null)return false;
	var args=arguments;
	var argsLen=args.length;
	if(argsLen>0)
	{
		this._x=(!isNaN(args[0]["nX"]))?args[0]["nX"]:this._x;
		this._y=(!isNaN(args[0]["nY"]))?args[0]["nY"]:this._y;
		this._returnValueObj=(typeof(args[0]["oRetObj"])=="object")?args[0]["oRetObj"]:this._returnValueObj;
		this._showForIE5=((typeof(args[0]["bShowForIE5"])=="boolean")?args[0]["bShowForIE5"]:this._showForIE5);
		this.setShowTime((typeof(args[0]["bShowTime"])=="boolean")?args[0]["bShowTime"]:this._showTime);
		this.setShowToday((typeof(args[0]["bShowNow"])=="boolean")?args[0]["bShowNow"]:this._showNow);
		this._returnValueFormat=(typeof(args[0]["sOutFormat"])=="string")?args[0]["sOutFormat"]:this._returnValueFormat;
	}
	if(cCalendarGlobalIE55)
	{
		if(this.oPopup)
		{
			if(this.oPopup.isOpen)this.oPopup.hide();
			this.oPopup.show(this._x,this._y,this._width,this._height,document.body);
			if(this._width==0||this._height==0)setTimeout("cCalendarGlobalArray["+this.id+"]._setGeomParams();",100);
		}
		this._showForIE5=true;
	}
	else
	{
		if(this._el&&this.style&&this._showForIE5)
		{
			this._showForIE5=true;
			var st=this.style;
			if(st.display!="none")st.display="none";
			st.left=this._x;
			st.top=this._y;
			st.zIndex=cCalendarGlobalZIndex+cCalendarGlobalArray.length;
			st.display=st.display=="none"?"":"none";
			//if(cCalendarGlobalScrollX!="hidden")document.body.style.overflowX="hidden";
			//if(cCalendarGlobalScrollY!="hidden")document.body.style.overflowY="hidden";
			this._el.scrollIntoView(true);
		}
		else if(!this._showForIE5)
		{
			var st=this._el.style;
			if(st.display!="none")st.display="none";
			this._showForIE5=true;
			this.setDate(new Date());
			this.submitForm();
		}
	}
	return true;
}

cCalendar.prototype.hide=function()
{
	if(this._table==null)return false;
	if(cCalendarGlobalIE55)
	{
		if(this.oPopup)
		{
			if(this.oPopup.isOpen)this.oPopup.hide();
		}
	}
	else
	{
		if(this._el&&this._el.style)
		{
			var st=this._el.style;
			if(st.display!="none")st.display="none";
			st.zIndex=cCalendarGlobalZIndex+this.id;
			//if(cCalendarGlobalScrollX!=document.body.currentStyle.overflowX)document.body.style.overflowX=cCalendarGlobalScrollX=="visible"?"auto":(cCalendarGlobalScrollX=="scroll"?"scroll":"hidden");
			//if(cCalendarGlobalScrollY!=document.body.currentStyle.overflowY)document.body.style.overflowY=cCalendarGlobalScrollY=="visible"?"auto":(cCalendarGlobalScrollY=="scroll"?"scroll":"hidden");
		}
	}
	return true;
}

function cCalendarAttach()
{
	cCalendarGlobalScrollX=document.body.currentStyle.overflowX;
	cCalendarGlobalScrollY=document.body.currentStyle.overflowY;
	var oStyle=document.createElement("LINK");
	oStyle.id="datePickerCSS";
	oStyle.type="text/css";
	oStyle.rel="stylesheet";
	oStyle.href="i/def/xsight.cCalendar.css";
	document.body.insertBefore(oStyle);

	cCalendarObject=new cCalendar(new Date());
	cCalendarObject.setFirstWeekDay(0);
	cCalendarObject.setRedWeekDay(6);
	if(cCalendarGlobalIE55)
	{
		cCalendarObject.oPopup.document.body.appendChild(cCalendarObject.create(cCalendarObject.oPopup.document));
		cCalendarObject.oPopup.show(0,0,0,0);
		setTimeout("cCalendarObject._setGeomParams();cCalendarObject.hide()",1000);
	}
	else
	{
		document.body.appendChild(cCalendarObject.create());
	}
	return true;
}
window.attachEvent("onload",cCalendarAttach);

