<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- 
// File: calendar.htc
//
//  Description:	This behavior allows to add a pop-up calendar to pages.
//  Usage: Attach to image and define corresponding class.
//	Note: do not define onload function in your document!
//	 	  do ont define classes starting with 'cal'!
//
//  Required properties:
//   - textboxName - textbox on the page into which the date is written after
//  				user chooses the date.
//
//  Properties:
//  	- dateFormat	- displayed date format (default: dd/mm/yyyy)
//  	- dateFrom		- limits the  date range starting with dateFrom
//  	- dateTo		- limits the date range ending with dateTo
//  	- hasDropDown	- [true/flase/] drop down for year and month selection
//  	- imgUpSrc		- if hasDropDown=false, provide img for moving to next month/year
//  	- imgDownSrc	- if hasDropDown=false, provide img for moving to previous month/year
//  	- startDay		- starting day of the week: 0=sunday, 1=monday
//		- dateFromNowOn - imits the  date range starting with today (end date unlimited)
//
//  Style definitions (see exapmle definitions in function AddStyles below:
//  	- calClassName			- general cell style
//  	- monthSelectClassName	- select of months style (if hasDropDown set to true)
//  	- yearInputClassName	- year text box style (if hasDropDown set to true)
//  	- calDaysClassName		- week day cell style
//  	- calWeekendClassName   - weekend day cell style
//  	- calBgClassName		- background ofthe whole calendar style
//  	- calBorderClassName    - border of the calendar style
//  	- calLinkClassName		- date link (for choosing the date) style
//  	- calLinkHoverClassName	- hover date link (for choosing the date) style
//									(when user move mouse over the data)
//  	- calDisabledClassName	 - disabled date style
//  	- calHighlightClassName	- selected date style
//
//	Based on javascript calendar control v1.2 by Lea Smart (www.totallysmartit.com)
//	Author: Shulamit Umansky
//	Date: 5/20/2004
// -->
<public:component xmlns:public="urn:HTMLComponent" lightweight="true">
<!--
<public:attach for="element" event="oncontentready" handler="LoadCalendar"/>
-->
<public:attach for="element" event="onclick" handler="ShowCalendar"/>
<!--
<public:attach for="element" event="onmouseover" handler="doMouseOver"/>
<public:attach for="element" event="onmouseout" handler="doMouseOut"/>
-->
<public:property name="dateFormat" value="mm/dd/yyyy"/>
<public:property name="dateFrom"/>
<public:property name="dateTo"/>
<public:property name="hasDropDown" value="false"/>
<public:property name="dateFromNowOn" value="false"/>

<public:property name="textboxName"/>

<public:property name="timeoutDelay" value="2000"/>
<public:property name="imgUpSrc" value="images/up.gif"/>
<public:property name="imgDownSrc" value="images/down.gif"/>
<public:property name="startDay" value="0"/>

<public:property name="calClassName" value="cal"/>
<public:property name="monthSelectClassName" value="month"/>
<public:property name="yearInputClassName" value="year"/>
<public:property name="calDaysClassName" value="calDaysColor"/>
<public:property name="calWeekendClassName" value="calWeekend"/>
<public:property name="calBgClassName" value="calBgColor"/>
<public:property name="calBorderClassName" value="calBorderColor"/>
<public:property name="calLinkClassName" value="calLink"/>
<public:property name="calLinkHoverClassName" value="calLinkHover"/>
<public:property name="calDisabledClassName" value="disabled"/>
<public:property name="calHighlightClassName" value="calHighlightColor"/>

<script type="text/javascript">
//<![CDATA[
/*************************************************************************************************
	Author : Lea Smart
	Source : www.totallysmartit.com
	Date : 7/3/2001
	DHTML Calendar
	Version 1.2

	You are free to use this code if you retain this header.
	You do not need to link to my site (be nice though!)

	Amendments
	22 Jan 2002; Added ns resize bug code; rewrote date functions into Date 'class';
				 Added support for yyyy-mm-dd date format
				 Added support for calendar beginning on any day
	7th Feb 2002 Fixed day highlight when year wasn't current year bug
	9th Jun 2002 Fixed bug with weekend colour
				 Amended the code for the date functions extensions.  Shortened addDays code considerably

Shulamit Umansky:
	01 March 2005 requires "/images/spacer.gif"  to exist - the iframe that hides the form elements is set to have this source, otherwise https pages give security warning
*********************************************************************************************/
var g_Calendar;
var g_startDay;// 0=sunday, 1=monday
var imgUp;
var imgDown ;
	// used by timeout auto hide functions
var timeoutId;
var DocBody;

element.style.cursor = "hand";

//window.attachEvent("onload", onload);
//window.attachEvent("onerror", errHandler);

function AddStyles(){

	var mheight;
	browser.platform=='Win32'?mheight=142:mheight=145;

	if ( browser.ie5 )
	{
			//Next 4 lines are crucial for styles to work! do not remove!
			if ( ! window.document.body.BehaviorStyleSheet)
			{
//				window.document.body.BehaviorStyleSheet = window.document.createStyleSheet();
//				StyleInfo = window.document.body.BehaviorStyleSheet;		
				window.StyleInfo = window.document.createStyleSheet();
				StyleInfo.addRule("td.cal","font-family : Arial,Helvetica,Sans-serif; font-size : 11px;	  color : #000000;  background-color : #d8e6f3;");
				StyleInfo.addRule("#container","position : absolute;left : 100px;top : 100px;width : 124px;height : " + mheight +"px; clip:rect(0px 124px " + mheight + "px 0px);visibility : hidden; background-color : #ffffff; z-index:3;");
				StyleInfo.addRule("select.month","font-family:Arial,Helvetica,Sans-serif; font-size:11px;	  color:#000000; width:85px;");
				StyleInfo.addRule("input.year"," font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #000000;  width : 30px;");
				StyleInfo.addRule(".calDaysColor","font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff;  background-color : #536272;");
				StyleInfo.addRule(".calWeekend","font-family : Arial,Helvetica,Sans-serif; font-size : 11px;  color : #ffffff; background-color : #f4ddac;");
				StyleInfo.addRule(".calBgColor","font-family : Arial,Helvetica,Sans-serif; font-size : 11px;   color : #ffffff; background-color : #d8e6f3;");
				StyleInfo.addRule(".calBorderColor","font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff; background-color : #a9a9a9;");
				StyleInfo.addRule(".calLink","font-family : Arial,Helvetica,Sans-serif;font-size : 11px; color : #000000;text-decoration : none; cursor : hand; ");
				StyleInfo.addRule(".calLinkHover","font-family : Arial,Helvetica,Sans-serif;font-size : 11px;	  color : #FF0000; text-decoration : none; cursor : hand;");
				StyleInfo.addRule(".disabled","font-family : Arial,Helvetica,Sans-serif;font-size : 11px; color : #808080; text-decoration : none;");
				StyleInfo.addRule("td.calHighlightColor","font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff; background-color : #ffffcc;");
			}
	}
	else
	{
			if ( !calClassName ) element.calClassName="cal" ;
			if ( !monthSelectClassName ) element.monthSelectClassName="month" ;
			if ( !yearInputClassName ) element.yearInputClassName="year" ;
			if ( !calDaysClassName ) element.calDaysClassName="calDaysColor"
			if ( !calWeekendClassName ) element.calWeekendClassName="calWeekend"
			if ( !calBgClassName ) element.calBgClassName="calBgColor"
			if ( !calBorderClassName ) element.calBorderClassName="calBorderColor"
			if ( !calLinkClassName ) element.calLinkClassName="calLink"
			if ( !calLinkHoverClassName ) element.calLinkHoverClassName="calLinkHover"
			if ( !calDisabledClassName ) element.calDisabledClassName="disabled"
			if ( !calHighlightClassName ) element.calHighlightClassName="calHighlightColor" ;		
		
			StyleInfo = window.document.styleSheets[0] ;			
			StyleInfo.insertRule("td {color : #000000;}",0);
			StyleInfo.insertRule("input {color : #000000;}",0);
			StyleInfo.insertRule("td.cal {font-family : Arial,Helvetica,Sans-serif; font-size : 11px;	  color : #000000;  background-color : #d8e6f3;}",0);
			StyleInfo.insertRule("#container {position : absolute;left : 100px;top : 100px;width : 124px;height : " + mheight +"px; clip:rect(0px 124px " + mheight + "px 0px);visibility : hidden; background-color : #ffffff; z-index:3;}",0);
			StyleInfo.insertRule("select.month {font-family:Arial,Helvetica,Sans-serif; font-size:11px;	  color:#000000; width:85px;}",0);
			StyleInfo.insertRule("input.year { font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #000000;  width : 30px;}",0);
			StyleInfo.insertRule(".calDaysColor {font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff;  background-color : #000000;}",0);
			StyleInfo.insertRule(".calWeekend {font-family : Arial,Helvetica,Sans-serif; font-size : 11px;  color : #ffffff; background-color : #f4ddac;}",0);
			StyleInfo.insertRule(".calBgColor {font-family : Arial,Helvetica,Sans-serif; font-size : 11px;   color : #ffffff; background-color : #d8e6f3;}",0);
			StyleInfo.insertRule(".calBorderColor {font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff; background-color : #a9a9a9;}",0);
			StyleInfo.insertRule(".calLink {cursor: pointer font-family : Arial,Helvetica,Sans-serif;font-size : 11px; color : #000000;text-decoration : none; } ",0);
			StyleInfo.insertRule(".calLinkHover {cursor: pointer ; font-family : Arial,Helvetica,Sans-serif;font-size : 11px;	  color : #FF0000; text-decoration : none; }",0);
			StyleInfo.insertRule(".disabled {font-family : Arial,Helvetica,Sans-serif;font-size : 11px; color : #808080; text-decoration : none;}",0);
			StyleInfo.insertRule("td.calHighlightColor {font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff; background-color : #ffffcc;}",0);
	}

}

/*
function doMouseOver(){
	if ( browser.ie5 )
		element.style.cursor = "hand";
	else
		element.style.cursor = "pointer";
}
function doMouseOut(){
	element.style.cursor = "default";
}
*/

function errHandler(msg,url,line){
	  alert('******* an error has occurred ********' +
	  '\n\nPlease check that' +
	  '\n\n1)You have not added any code to the body onload event,'
	  +  '\nif you want to run something as well as the calendar initialisation'
	  + '\ncode, add it to the onload event in the calendar library.'
	  + '\n\n2)You have set the parameters correctly in the g_Calendar.show() method '
	  + '\n\nSee www.totallysmartit.com\\examples\\calendar\\simple.asp for examples'
	  + '\n\n------------------------------------------------------'
	  + '\nError details'
	  + '\nText:' + msg + '\nurl:' + url + '\nline:' + line);
	}

/*	
function onload(){
	//LoadCalendar();
  g_Calendar = new Calendar(new Date());

  window.document.calendar_obj = g_Calendar;

}
*/

function Browser(){
	  this.dom = (window.document.getElementById)?1:0;
	  this.ie4 = (window.document.all && !this.dom)?1:0;
	  this.ns4 = (window.document.layers && !this.dom)?1:0;
	  this.ie5 = (this.dom && window.document.all && window.document.createStyleSheet )?1:0;
	  this.ns6 = (this.dom && !this.ie5 )?1:0;
	  this.ok = this.dom || this.ie4 || this.ns4;
	  this.platform = navigator.platform;
	}

function LoadCalendar(){
	window.browser = new Browser();
	AddStyles();
	
	// preload images
	imgUp = new Image(8,12);
	imgUp.src = imgUpSrc;
	window.document.imgUpObj = imgUp;

	imgDown = new Image(8,12);
	imgDown.src = imgDownSrc;
	window.document.imgDownObj = imgDown;
	timeoutId = false;
	g_startDay = element.startDay;

	var mheight;
	//mheight=140;
	browser.platform=='Win32'?mheight=132:mheight=145;

	var divElm = window.document.createElement("div");
	divElm.id = "container";
	//divElm.style.height = mheight+"px";

//	window.document.body.insertAdjacentElement("BeforeEnd",divElm);
	window.document.body.insertBefore(divElm,null);
/*	
	var rt;
	rt=window.document.createElement("DIV");
	rt.id="ifrCalendar";
	rt.frameBorder=0;
	rt.style.position="absolute";
	rt.style.visibility="hidden";
	rt.style.left="100px";
	rt.style.top="100px";
	rt.style.width="124px";
	rt.style.height=mheight+"px";
	rt.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
	rt.allowTransparency=false;
	rt.zIndex=1;
	window.document.body.insertBefore(rt,window.document.body.firstChild);
*/	
		//if (timeoutDelay) document.write(' onmouseout="calendarTimeout();" onmouseover="if (timeoutId) clearTimeout(timeoutId);"');

}
function ShowCalendar(){
	if ( !window.document.calendar_obj )
	{
		LoadCalendar() ;
		window.document.calendar_obj =new Calendar(new Date());
	}
	g_Calendar = window.document.calendar_obj ;

	if ( browser.ie4 || browser.ie5 )	
		window.document.attachEvent("onclick", handleDocumentClick);
	else
		window.document.addEventListener( 'click', handleDocumentClick, false ) ;
	
	event.cancelBubble = true ;

	if (element.dateFromNowOn=="true"){
		t = new Date();
		element.dateFrom = t.toString();
	}
	if (element.dateFrom==null){
		element.dateFrom="01/01/1900";

	}
	if (element.dateTo==null){
		element.dateTo="01/01/2300";
	}
	var dateFromV, dateToV;


	window.document.calendar_obj.show(event,element.textboxName,(element.hasDropDown=="true"),element.dateFormat, new Date(element.dateFrom), new Date(element.dateTo) );

	return false;
}
function clearCalendarTimeout(){
	//if (timeoutId)
	//	clearTimeout(timeoutId);
	window.status='Show Calendar';
	return true;
}
function setCalendarTimeout(){
	//if (timeoutDelay)
	//	calendarTimeout();
	window.status='';
}

	/*function calendarTimeout(){
	  if (browser.ie4 || browser.ie5){
	    if (document.parentWindow.event.srcElement && document.parentWindow.event.srcElement.name!='month') timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	  if (browser.ns6 || browser.ns4){
	    timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	}*/

function Calendar(){
 // g_Calendar = this;
  // some constants needed throughout the program
  this.daysOfWeek = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
  this.months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  this.daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);


  if (browser.dom || browser.ie4){
	var tmpLayer = browser.dom?window.document.getElementById('container'):window.document.all.container;
  }

  	this.containerLayer = tmpLayer;
/*		
		var rtLayer = window.document.getElementById('ifrCalendar');
		this.rt = rtLayer;
*/
}

Calendar.prototype.getFirstDOM = function() {
	var thedate = new Date();
	thedate.setDate(1);
	thedate.setMonth(this.month);
	thedate.setFullYear(this.year);
	return thedate.getDay();
}

Calendar.prototype.getDaysInMonth = function (){
   if (this.month!=1) {
   return this.daysInMonth[this.month]
   }
   else {
     // is it a leap year
	    if (Date.isLeapYear(this.year)) {
		  return 29;
		}
	    else {
		  return 28;
		}
   }
}

Calendar.prototype.buildString = function(){
	  var tmpStr = '<form onSubmit="this.year.blur();return false;" id="frmCal" name="frmCal"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="'+ element.calBorderClassName + '"><tr><td class="txt-top"><table width="100%" border="0" cellspacing="0" cellpadding="1" class="'+ element.calBgClassName + '">';
  tmpStr += '<tr>';
	  tmpStr += '<td width="60%" class="'+ element.calClassName + '" align="left">';
  if (this.hasDropDown) {
    tmpStr += '<select class="'+ element.monthSelectClassName + '" name="month" onchange="document.calendar_obj.selectChange();">';
	for (var i=0;i<this.months.length;i++){
      tmpStr += '<option value="' + i + '"'
	  if (i == this.month) tmpStr += ' selected';
	  tmpStr += '>' + this.months[i] + '</option>';
    }
    tmpStr += '</select>';
  } else {
	    tmpStr += '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img onClick="document.calendar_obj.changeMonth(-1);"  style="cursor: pointer; cursor: hand;" name="calendar" src="'+element.imgDownSrc + '" width="8" height="12" border="0" alt=""></td><td class="'+ element.calClassName + '" width="100%" align="center">' + this.months[this.month] + '</td><td class="'+ element.calClassName + '"><img onClick="document.calendar_obj.changeMonth(+1);" name="calendar"  style="cursor: pointer;cursor: hand;" src="'+ element.imgUpSrc+'" width="8" height="12" border="0" alt=""></td></tr></table>';
  }
  tmpStr += '</td>';
  /* observation : for some reason if the below event is changed to 'onChange' rather than 'onBlur' it totally crashes IE (4 and 5)!
  */
	  tmpStr += '<td width="40%" align="right" class="'+ element.calClassName + '">';

  if (this.hasDropDown) {
    tmpStr += '<input class="'+element.yearInputClassName+'" type="text" size="';
    // get round NS4 win32 lenght of year input problem
    //(browser.ns4 && browser.platform=='Win32')?tmpStr += 1:
	tmpStr += 4;
  tmpStr += '" name="year" maxlength="4" onBlur="document.calendar_obj.inputChange();" value="' + this.year + '">';
  } else {
	  tmpStr += '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="'+ element.calClassName + '"><img onClick="document.calendar_obj.changeYear(-1);"  style="cursor: pointer; cursor: hand;"  name="calendar" src="'+element.imgDownSrc+'" width="8" height="12" border="0" alt=""></td><td class="'+ element.calClassName + '" width="100%" align="center">' + this.year + '</td><td class="'+ element.calClassName + '"><img style="cursor: pointer;cursor: hand;"  onClick="document.calendar_obj.changeYear(+1);" name="calendar" src="'+element.imgUpSrc+'" width="8" height="12" border="0" alt=""></td></tr></table>'
  }
  tmpStr += '</td>';
  tmpStr += '</tr>';
  tmpStr += '</table>';
  var iCount = 1;

  var iFirstDOM = (7+this.getFirstDOM()-g_startDay)%7; // to prevent calling it in a loop

  var iDaysInMonth = this.getDaysInMonth(); // to prevent calling it in a loop

	  tmpStr += '<table width="100%" border="0" cellspacing="0" cellpadding="1" class="' + element.calBgClassName + '">';
  tmpStr += '<tr>';
    for (var i=0;i<7;i++){
	  tmpStr += '<td align="center" class="'+element.calDaysClassName+'">' + this.daysOfWeek[(g_startDay+i)%7] + '</td>';
	}
  tmpStr += '</tr>';
  var tmpFrom = parseInt('' + this.dateFromYear + this.dateFromMonth + this.dateFromDay,10);
  var tmpTo = parseInt('' + this.dateToYear + this.dateToMonth + this.dateToDay,10);
  var tmpCompare;
  for (var j=1;j<=6;j++){
     tmpStr += '<tr>';
     for (var i=1;i<=7;i++){
	   tmpStr += '<td width="16" align="center" '
	   if ( (7*(j-1) + i)>=iFirstDOM+1  && iCount <= iDaysInMonth){
	     if (iCount==this.day && this.year==this.oYear && this.month==this.oMonth) tmpStr += 'class="'+ element.calHighlightClassName + '"';
		 else {
		    if (i==7-g_startDay || i==((7-g_startDay)%7)+1) tmpStr += 'class="'+element.calWeekendClassName + '"';
				else tmpStr += 'class="'+ element.calClassName + '"';
		 }
	     tmpStr += '>';
		 /* could create a date object here and compare that but probably more efficient to convert to a number
		   and compare number as numbers are primitives */
		 tmpCompare = parseInt('' + this.year + padZero(this.month) + padZero(iCount),10);
		 if (tmpCompare >= tmpFrom && tmpCompare <= tmpTo) {

				tmpStr += "<span class='"+element.calLinkClassName + "' onClick=' document.calendar_obj.clickDay(" + iCount + ");' onMouseOver='this.className=\""+ element.calLinkHoverClassName+"\";' onMouseOut='this.className=\""+element.calLinkClassName +"\";'>" + iCount + "</span>";
		 } else {
		   tmpStr += '<span class="'+ element.calDisabledClassName + '">' + iCount + '</span>';
		 }
		 iCount++;
	   } else {
		     if  (i==7-g_startDay || i==((7-g_startDay)%7)+1) tmpStr += 'class="'+element.calWeekendClassName + '"'; else tmpStr +='class="'+ element.calClassName + '"';
		 tmpStr += '>&nbsp;';
	   }
	   tmpStr += '</td>'
	 }
	 tmpStr += '</tr>'
  }
  tmpStr += '</table></td></tr></table></form>';



  return tmpStr;
}

Calendar.prototype.selectChange = function(){
 // browser.ns6?this.containerLayer.ownerDocument.forms[0].month.selectedIndex:
this.month = this.containerLayer.document.forms["frmCal"].month.selectedIndex;
  this.writeString(this.buildString());
}

Calendar.prototype.inputChange = function(){
  //browser.ns6?this.containerLayer.ownerDocument.forms[0].year:
	var tmp = this.containerLayer.document.forms["frmCal"].year;
  if (tmp.value >=1900 || tmp.value <=2100){
    this.year = tmp.value;
    this.writeString(this.buildString());
  } else {
    tmp.value = this.year;
  }
}
Calendar.prototype.changeYear = function(incr){
   (incr==1)?this.year++:this.year--;
   this.writeString(this.buildString());
}
Calendar.prototype.changeMonth = function(incr){
    if (this.month==11 && incr==1){
      this.month = 0;
  	  this.year++;
    } else {
      if (this.month==0 && incr==-1){
        this.month = 11;
	    this.year--;
      } else {
	    (incr==1)?this.month++:this.month--;
	  }
	}
	this.writeString(this.buildString());
}

Calendar.prototype.clickDay = function(day){

   var tmp = window.document.getElementById(this.target);

   tmp.value = this.formatDateAsString(day,this.month,this.year);
   tmp.fireEvent("onchange");

    if (browser.dom || browser.ie4){
      this.containerLayer.style.visibility='hidden';
	  window.isolationIframe.style.display='none';	
	  //this.rt.style.visibility='hidden';
    }
}
Calendar.prototype.formatDateAsString = function(day, month, year){
  var delim = eval('/\\' + this.dateDelim + '/g');
   switch (this.dateFormat.replace(delim,"")){
     case 'ddmmmyyyy': return padZero(day) + this.dateDelim + this.months[month].substr(0,3) + this.dateDelim + year;
	 case 'ddmmyyyy': return padZero(day) + this.dateDelim + padZero(month+1) + this.dateDelim + year;
	 case 'mmddyyyy': return padZero((month+1)) + this.dateDelim + padZero(day) + this.dateDelim + year;
     case 'yyyymmdd': return year + this.dateDelim + padZero(month+1) + this.dateDelim + padZero(day);
	 default: alert('unsupported date format');
   }
}
Calendar.prototype.writeString = function(str){
    this.containerLayer.innerHTML = str;
}

Calendar.prototype.show = function(event, target, bHasDropDown, dateFormat, dateFrom, dateTo){

// calendar can restrict choices between 2 dates, if however no restrictions
// are made, let them choose any date between 1900 and 3000
this.dateFrom = dateFrom || new Date(1900,0,1);
this.dateFromDay = padZero(this.dateFrom.getDate());
this.dateFromMonth = padZero(this.dateFrom.getMonth());
this.dateFromYear = this.dateFrom.getFullYear();
this.dateTo = dateTo || new Date(3000,0,1);
this.dateToDay = padZero(this.dateTo.getDate());
this.dateToMonth = padZero(this.dateTo.getMonth());
this.dateToYear = this.dateTo.getFullYear();
this.hasDropDown = bHasDropDown;
this.dateFormat = dateFormat || 'mm/dd/yyyy';
switch (this.dateFormat){
  case 'dd-mmm-yyyy':
  case 'dd-mm-yyyy':
  case 'yyyy-mm-dd':
    this.dateDelim = '-';
	break;
  case 'dd/mm/yyyy':
  case 'mm/dd/yyyy':
  case 'dd/mmm/yyyy':
    this.dateDelim = '/';
	break;
}

   
  if (browser.dom || browser.ie4){
    if (this.containerLayer.style.visibility=='visible') {
	  this.containerLayer.style.visibility='hidden';
	  window.isolationIframe.style.display='none';	
	  //this.rt.style.visibility='hidden';
	  return;
	}
  }

 
	
  var newX=0, newY=0 ;
	var obj = event.srcElement;
	while (obj != null && obj.tagName.toUpperCase() != "BODY") 
	{

			newX += obj.offsetLeft;
			newY += obj.offsetTop;
			obj = obj.offsetParent;
	}

	//check if it's not going outside the screen


   
	if ( parseInt(newX) + 124 + 35 > parseInt(window.document.body.clientWidth)){
	    newX = newX-124-element.width;
	    
	}

	if ( parseInt(newY) + 132 > parseInt(window.document.body.clientHeight))
		newY = newY - 132 +element.height;

	this.containerLayer.style.left = (newX+element.width)+"px";
  

	
	this.containerLayer.style.top = newY+"px";
	

  this.target = target;
  var tmp = window.document.getElementById(this.target); //eval('document.' + this.target);
  if (tmp && tmp.value && tmp.value.split(this.dateDelim).length==3 && tmp.value.indexOf('d')==-1){
    var atmp = tmp.value.split(this.dateDelim)
	switch (this.dateFormat){
	 case 'dd-mmm-yyyy':
	 case 'dd/mmm/yyyy':
	   for (var i=0;i<this.months.length;i++){
	     if (atmp[1].toLowerCase()==this.months[i].substr(0,3).toLowerCase()){
	       this.month = this.oMonth = i;
		   break;
	     }
	   }
	   this.day = parseInt(atmp[0],10);
	   this.year = this.oYear = parseInt(atmp[2],10);
	   break;
	 case 'dd/mm/yyyy':
	 case 'dd-mm-yyyy':
	   this.month = this.oMonth = parseInt(atmp[1]-1,10);
	   this.day = parseInt(atmp[0],10);
	   this.year = this.oYear = parseInt(atmp[2],10);
	   break;
	 case 'mm/dd/yyyy':
	 case 'mm-dd-yyyy':
	   this.month = this.oMonth = parseInt(atmp[0]-1,10);
	   this.day = parseInt(atmp[1],10);
	   this.year = this.oYear = parseInt(atmp[2],10);
	   break;
	 case 'yyyy-mm-dd':
	   this.month = this.oMonth = parseInt(atmp[1]-1,10);
	   this.day = parseInt(atmp[2],10);
	   this.year = this.oYear = parseInt(atmp[0],10);
	   break;
	}
  } else { // no date set, default to today
    var theDate = new Date();
  	 this.year = this.oYear = theDate.getFullYear();
     this.month = this.oMonth = theDate.getMonth();
     this.day = this.oDay = theDate.getDate();
  }
  this.writeString(this.buildString());
  //alert(this.containerLayer.innerHTML);
  // and then show it!
  /* if (browser.ns4) {
   this.containerLayer.hidden=false;
   }*/
  if (browser.dom || browser.ie4){
      this.containerLayer.style.visibility='visible';
		if ( !window.isolationIframe )
		{
			window.isolationIframe=window.document.createElement("IFRAME");
			window.isolationIframe.src="/images/spacer.gif";
			window.isolationIframe.id="ifrCalendar";
			window.isolationIframe.frameBorder=0;
			window.isolationIframe.style.position="absolute";
			window.isolationIframe.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
			window.isolationIframe.allowTransparency=false;
			window.isolationIframe.zIndex=1;
			window.document.body.appendChild(window.isolationIframe); 
		}
		window.isolationIframe.style.top = this.containerLayer.offsetTop ;
		window.isolationIframe.style.left = this.containerLayer.offsetLeft ;
		window.isolationIframe.style.width = this.containerLayer.offsetWidth ;
		window.isolationIframe.style.height = this.containerLayer.offsetHeight ;
		//window.isolationIframe.style.visibility='visible';
		window.isolationIframe.style.display='';
  }

}
Calendar.prototype.hide = function(){
 // if (browser.ns4) this.containerLayer.hidden = true;
  if (browser.dom || browser.ie4){
    this.containerLayer.style.visibility='hidden';
//		window.isolationIframe.style.visibility='hidden';	
		window.isolationIframe.style.display='none';	
	//this.rt.style.visibility='hidden';
  }
}

function handleDocumentClick(e){	
	if ( browser.ie4 || browser.ie5 )	
		window.document.detachEvent("onclick", handleDocumentClick);
	else
		window.document.removeEventListener( 'click', handleDocumentClick, false ) ;
		
		if (browser.ie4 || browser.ie5) e =event;

 /* if (browser.ns6){
    var bTest = (e.pageX > parseInt(g_Calendar.containerLayer.style.left,10) && e.pageX <  (parseInt(g_Calendar.containerLayer.style.left,10)+125) && e.pageY < (parseInt(g_Calendar.containerLayer.style.top,10)+125) && e.pageY > parseInt(g_Calendar.containerLayer.style.top,10));
    if (e.target.name!='imgCalendar' && e.target.name!='month'  && e.target.name!='year' && e.target.name!='calendar' && !bTest){
	  g_Calendar.hide();
		}
  }
	else
  if (browser.ie4 || browser.ie5){*/
	// extra test to see if user clicked inside the calendar but not on a valid date, we don't want it to disappear in this case
		var bTest = (e.x > parseInt(window.document.calendar_obj.containerLayer.style.left, 10) && e.x < (parseInt(window.document.calendar_obj.containerLayer.style.left, 10) + 125) && e.y < (parseInt(window.document.calendar_obj.containerLayer.style.top, 10) + 125) && e.y > parseInt(window.document.calendar_obj.containerLayer.style.top, 10));
		// alert('e.x=' + e.X + ' | e.y=' + e.y+ ' e=' + e);
		// alert(bTest + ' _ ' + e.srcElement.name);
		//e.srcElement.name!='calendar' was added to if for Mozilla browser
    if (e.srcElement.name!='calendar' && e.srcElement.name!='imgCalendar' && e.srcElement.name!='month' && e.srcElement.name!='year' && !bTest ){ //& typeof(e.srcElement)!='object'
//&& e.srcElement.name!=element.textboxName
	  window.document.calendar_obj.hide();
	}
  /*}*/
  /*if (browser.ns4) g_Calendar.hide();*/
}
// utility function
function padZero(num) {
  return ((num <= 9) ? ("0" + num) : num);
}
  // Finally licked extending  native date object;
Date.isLeapYear = function(year){ if (year%4==0 && ((year%100!=0) || (year%400==0))) return true; 	else return false; }
Date.daysInYear = function(year){ if (Date.isLeapYear(year)) return 366; else return 365;}

var DAY = 1000*60*60*24;
Date.prototype.addDays = function(num){
	return new Date((num*DAY)+this.valueOf());
}

//]]>
</script>
</public:component>



