 function Calendar (id,containerId,title,imageId) 
	  {
	       YAHOO.namespace("LBTO.calendar"); 
	       
           this.title = title;
           this.container =containerId;
           this.calImage = imageId;
           
           var date =  new Date();
           this.minDate = (date.getMonth() +1) + "/" + date.getDate() + "/" + date.getFullYear();
           this.maxDate = (date.getMonth() +1) + "/" + date.getDate() + "/" + (date.getFullYear() + 2);
           this.pageDate = (date.getMonth() +1) +"/" + date.getFullYear();
           this.id = id;
           this.textBoxId = null;
           this.onCancel = null;
           this.calender = null;
           var thisObject = this;
           this.setPositionHandler = null;

           
           this.onSelect =function(type,args,obj)
           {
                obj.hide();
                var selDate = obj.getSelectedDates()[0];
                var mStr = obj.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
                var wStr = obj.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];   
                var yStr = selDate.getFullYear();
                var dStr = selDate.getDate();
                try
                {
                    document.getElementById(thisObject.textBoxId).value =wStr + ", " + dStr + ", " + mStr + " " + yStr;
                }
                catch(e)
                {
                }
           }
           
           this.Show = function ()
            {
                var calImage =document.getElementById(thisObject.calImage);
                var pos =  thisObject.getPosition(calImage);
                var left = (pos.x + calImage.width) - 280;
                var top = pos.y + calImage.height +5;
                    
	            thisObject.calender.show();
	           
	           if(thisObject.setPositionHandler != null)
	           {
	                thisObject.setPositionHandler(thisObject);
	           }
	           else
	           {
                    YAHOO.util.Dom.setXY(thisObject.container , [left , top]); 
	           }
           };
           
           this.createCalendar = function(textBoxId) 
           {
                 this.textBoxId = textBoxId;
                 var yuiCalender = new YAHOO.widget.CalendarGroup(this.id,this.container,  
					{ 
					title: this.title, 
					close: true,
					pagedate: this.pageDate, 
					mindate: this.minDate, 
					maxdate: this.maxDate,
					iframe: true,
					START_WEEKDAY: 1
					} 
				);                             
                
                yuiCalender.selectEvent.subscribe(this.onSelect , yuiCalender , true);
                
                var oElement = document.getElementById(this.calImage);
	            YAHOO.util.Event.addListener(oElement, "click",this.Show, yuiCalender, true); 
	        
	            var linkClose = YAHOO.util.Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || document.createElement("a");
	            YAHOO.util.Event.addListener(linkClose, "click", this.onCancel, yuiCalender, true );
	        
                yuiCalender.cfg.setProperty("MDY_DAY_POSITION", 1); 
                yuiCalender.cfg.setProperty("MDY_MONTH_POSITION", 2); 
                yuiCalender.cfg.setProperty("MDY_YEAR_POSITION", 3); 	   
	            yuiCalender.render(); 
	            this.calender = yuiCalender;
                return yuiCalender;
                
           };
           
           this.getDate = function()
           {
                if(this.calender != null)
                {
                    var selDate = this.calender.getSelectedDates()[0];
                    return selDate;
                }
               
           };
           
           this.getPosition =  function(obj)
            {
                var curleft = curtop = 0;
                if (obj.offsetParent) 
                {
                    do 
                    {
	                    curleft += obj.offsetLeft;
	                    curtop += obj.offsetTop;
                    } while (obj = obj.offsetParent);

                    return {x:curleft, y:curtop}
                }
            }
      }