   /*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	            DHTML Calendar
	
		Author  : Darren Neimke
		Source  : http://www.showusyourcode.com/
		Email   : darren@showusyourcode.com
		Date    : 8-Feb-2001
		
		Version 3.1
		
		Kudos to Lea Smart [ http://totallysmartit.com/ ] for helping me to 
        architect this calendar, particularly the issues surrounding NS 6
        integration and general software design.  Without his gentle nudge 
        this product would be far inferior to how it is now.
	
	    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	
	
	// -------------------------------------------
    //        Helper classes etc.
    // -------------------------------------------
    
    
        // Visibility enum
        var Visibility = new Array()
            Visibility.On = true ;
            Visibility.Off = false ;
            
        // Browser class
        function Browser()
        {
			if ( parseInt( navigator.appVersion.charAt(0) ) >= 4 )
            // Browser check.
            {
			    this.isDOM = document.getElementById ? true : false ;
                this.isNav6 = (navigator.appName == "Netscape") ? true : false ;
                this.isNav4 = (navigator.appName == "Netscape" && !(this.isDOM)) ? true : false ;
                this.isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false ;
            }
        }
        var browser = new Browser();
        
        
    // -------------------------------------------
    //        Global variables, functions etc.
    // -------------------------------------------
        
    
    // The following variables are global, 
    // don't edit them
    
    // reference to instance
    var gCalendar ;
	var calWidth = 151;
	var calHeight = 152;
	    
    // constructor
    
    function gfnCalInitialize()
    {
        new suycCalendar(new Date()) ;
    }
    
    // Instantiate the calendar
    window.onload = function()
    {
        gfnCalInitialize() ;
    }
    
    
    if(browser.isDOM)
    {
		document.writeln('<style>');
		//document.writeln('.calWeekday{font: \'normal 8pt Arial\';}') ;
		//document.writeln('.calNonCurrentMonth{font: \'normal 8pt Arial\'; color: \'LightGrey\' ;}') ;
		//document.writeln('A {color: Blue; text-decoration: None; font: \'normal 8pt Arial\';}') ; 
        //document.writeln('A:hover {color: Gray; text-decoration: Underline; font: \'normal 8pt Arial\';}') ;
		//document.writeln('td.cal{font-family : Arial;font-size : 8pt;background-color : #ffffff;}');
		
		document.writeln('#calContainer {');
		document.writeln('position : absolute;');
		
		
		if(browser.isIE4)
		{
			//alert('browser ie4');
		    document.writeln('width : ' + calWidth + 'px;');
		    document.writeln('clip:rect(0px ' + (parseInt(calWidth)+1) + 'px ' + (parseInt(calHeight)+1) + 'px 0px);');
    		document.writeln('height : ' + (parseInt(calHeight)+1) + 'px;');
		
	    }
	    else
	    {
			//alert('browser other');
		    document.writeln('width : ' + calWidth + 'px;');
		    document.writeln('clip:rect(0px ' + (parseInt(calWidth)+1) + 'px ' + (parseInt(calHeight)+1) + 'px 0px);');
    		document.writeln('height : ' + (parseInt(calHeight)+1) + 'px;');
		}
		
		document.writeln('visibility : hidden;');
		document.writeln('background-color : LightGrey');
		document.writeln('}');
		document.writeln('</style>')
		document.writeln('<DIV Id="calContainer"></DIV>') ;
		
		
    }
     
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    
    
                      
                      
    function suycCalendar()
    {
        gCalendar = this ;
        this.days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') ;
        this.DaysLen = 1 // sets how many characters are displayed for the day name 1=s, 2= sa, 3= sat etc
        this.months = new Array('January','February','March','April','May','June','July','August','September','October','November','December') ;
        this.monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31) ;
        
        // Populate the current Day|Month|Year properties
        var objDate = new Date() ;
        this.currentDay = objDate.getDate() ;
        this.currentMonth = objDate.getMonth() ; 
        var curYear = objDate.getYear() ; 
        this.currentYear = (curYear < 1000) ? curYear + 1900 : curYear ;
        
        this.year = this.currentYear ;
        this.month = this.currentMonth ;
        
        this.isVisible = false ;
        
        
        
        // Pre-build the top shell
        this.calTopOuter = '<center>';
        //this.calTopOuter += '<form name="frmCalendar">';
        this.calTopOuter += '<table bgcolor="#000000" cellpadding="1" cellspacing="0" border="0" width="150" height="150">'
                      + '<tr>'
                      + '<td>'
                      + '<table cellpadding="0" cellspacing="0" border="0" width="150" height="150">' ;
        
        // Pre-build the selector bar

         //+ '<input type="button" name="previousMonth" value=" < " onClick="gCalendar.MonthClick(-1) ;">'
        this.calSelectorBarTop = '<tr class="calSelectorBar" >'
                         + '<th class="calSelectorBar" align="center">'
                         + '<A onClick="gCalendar.MonthClick(-1);" title="Previous Month"><img src="' + gAppPath + '/WebControls/Calendar/Left.gif" border="0" ALIGN="absMiddle"></A>'
                         + '</th>'
                         + '<th nowrap colspan="5" class="calSelectorBar">'
                         + '<select class="cboMonth" name="calSelMonth" id="calSelMonth" onChange="gCalendar.MonthOnChange();">' ;
                         
        this.calSelectorBarBottom = '</th><th class="calSelectorBar" align="right">'
                         + '<A onClick="gCalendar.MonthClick(1) ;" title="Next Month"><img src="' + gAppPath + '/WebControls/Calendar/Right.gif" border="0" ALIGN="absMiddle"></A>'
                         + '</th>'
                         + '</tr>' ;
        
        
        // Pre-build the day names bar 
        this.calDayNameBar = '<tr bgcolor="LightGrey">' ;
            for (var i=0; i < this.days.length; i++)
            {
	            this.calDayNameBar += '<th align="center" class="calHeading" >' + this.days[i].substr(0,this.DaysLen) + '</th>' ; 
		    }
        this.calDayNameBar += '</tr>' ;
        
        
        // Pre-build the bottom shell
        this.calBottomOuter = '<tr bgcolor="LightGrey">'
            + '<th colspan="7" class="calFooter">'
            + '<a onClick="gCalendar.MoveToCurrent() ;" class="calFooter">Today</a>'
            + '</th></tr></table></td></tr></table>';
         this.calBottomOuter += '</form>';
         this.calBottomOuter += '</center>' ;
        
        // Create the canvass that we will be displaying the calendar on
        this.initCanvass() ;
    }



    /*********************************************
        Public methods
    **********************************************/

    // shows the calendar in a window
    suycCalendar.prototype.ShowPopup = function(event, formname, fieldname, dir)
		{    
			
			
			this.target = document.forms[formname].elements[fieldname] ;
			this.popup = true

		   // calendarWindow = window.open('', 'datePopup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,dependent=no,width=300,height=300');
		    //this.popupWindow = window.open('CalPopup.htm', 'datePopup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=no,width=150,height=160');
			//if (this.popupWindow) this.popupWindow.focus()
			
			this.RenderPopup(this.buildString());		    
			
        }
        

    /*
        Show is called when a user requests a calendar.  The show method
        is passed 4 arguments; the event, the formname, the fieldname
        and and optional dir value of 'right' or left'.  The default for the
        fourth argument is 'right'
    */	
    suycCalendar.prototype.Show = function(event, formname, fieldname, dir,popup)
    {
		var blnUnknown
		blnUnknown = false;
		
		if (typeof(popup) == "undefined") popup=false;
		
		this.popup=popup;
		
		
		//alert(formname + ' ' + fieldname + ' ' + popup);
	        
	
		//alert(document.forms[formname].elements[fieldname]);
        // test the form elementt names
        /*for (var q=0; q < document.forms.length; q++){
			alert(document.forms[q].name);
			for (var i=0; i < document.forms[q].elements.length; i++){
				alert(document.forms[q].elements[i].name);
			}
		} 
		*/
		
			if ((typeof(formname)=="undefined") || (formname.length==0)){
				this.target = document.getElementById(fieldname);
			}
			else{
				this.target = document.forms[formname].elements[fieldname] ;
			}
			

    		if (browser.isIE4)
			{
				var event = window.event ;
				//Set the x pos of the calendar object
				if (dir == 'left')
				{
					this.x = event.clientX - 180 ;
				}
				else
				{
					this.x = event.clientX + 22 ;
				}
				//Set the y pos of the calendar object
				this.y = event.clientY - 10 ;
			}
			else if(browser.isNav6)
			{
				if (dir == 'left')
				{
					this.x = event.pageX - 183 ;
				}
				else
				{
					this.x = event.pageX + 10 ;
				}
				this.y = event.pageY - 5 ;    
			}
			else if (browser.isNav4)
			{
				if (dir == 'left')
				{
					this.x = event.x - 162 ;
				}
				else
				{
					this.x = event.x + 10 ;
				}
				this.y = event.y - 5 ;    
			}
			else{
			// catch all 
				this.x = event.x;
				this.y = event.y;
				blnUnknown = true;
			}
			
			
			
			//adjust div location for scrolling
			if (!this.popup){
				//alert('x:' + this.x + ' scx:' + document.body.scrollLeft + ' y:' + this.y + ' scy:' + document.body.scrollTop);
				if (browser.isIE4){
					this.y = this.y + document.body.scrollTop;
					this.x = this.x + document.body.scrollLeft;
				}
			}
			else{
			
				//alert('x:' + this.x + ' sx:' + window.screenLeft + ' y:' + this.y + ' sy:' + window.screenTop);
				if (typeof(window.screenTop)!="undefined"){
					if (!blnUnknown) {
						this.y = this.y + window.screenTop;
						this.x = this.x + window.screenLeft;
					}
				}
				else{
					//alert(document.body.scrollTop);
					this.y = this.y - document.body.scrollTop;
					this.x = this.x - document.body.scrollLeft;
				}
				
				// Center popup.
				//this.x = (screen.width / 2) - 75;
				//this.y = (screen.height /2) - 75;
				calWidth = 151 + 4;
				calHeight = 152;
				//this.y = 100;
				//this.x = 100;
			}
			
			
			if (this.target.value.length >0){
				this.CurrentDate = this.target.value
				// set the calendar to the date in the textbox.
				var strDate
				strDate = this.target.value.split(' ')
				//alert(strDate[1]);
		        for(i = 0; i < this.months.length; i++){
					if (strDate[1]==this.months[i].substr(0,3)){
						this.month = i;
					}
					
		        }
		        this.year = strDate[2]
				
			}
			else{
				this.CurrentDate =  '';
			}
			
			//alert('Current:' + this.CurrentDate);
			
			if (this.popup){
				this.RenderPopup(this.buildString());	
			}
			else{
				if(this.isVisible == true)
				{
					this.setVisibility(Visibility.Off) ;	 
        			return ;
				}
				this.setVisibility(Visibility.Off) ;
	
				this.positionCanvass() ;
				this.setVisibility(Visibility.On) ;
				this.writeString(this.buildString()) ;
			}   
        
    }
    
			
    /*
        Invoked by the user explicitly closing the calendar
    */
    suycCalendar.prototype.Hide = function()
    {
        this.x = 0 ;
        this.y = 0 ;
        this.setVisibility(Visibility.Off) ;
    }
    
    
    /*
        Invoked by the user explicitly clicking a
        day on the calendar face
    */
    suycCalendar.prototype.DayClick = function(day)
    {
		//alert(this.target.value);
        this.target.value = this.formatDate(day) ;
        if (this.popup){
			this.popupWindow.opener.focus();
			this.popupWindow.close();
        }
        else
        {
			this.setVisibility(Visibility.Off) ;
        }
        
        
        
    }
    
    
    /*
        Invoked by the user explicitly toggling the
        Month by -1 or +1
    */
    suycCalendar.prototype.MonthClick = function(n)
    {
        if((this.month + n) < 0)
        {
            this.month = 11 ;
            -- this.year ;
        }
        else if((this.month + n) >= 12) 
        { 
            this.month = 0 ; 
            ++ this.year ; 
        }
        else
        {
            this.month = this.month + n ;
        }
        
        
		this.writeString(this.buildString()) ;
        
    }
    
    
    /*
        Invoked by the user explicitly changing the
        text in the year selector
    */
    suycCalendar.prototype.YearOnBlur = function()
    {
		var tmp;
     	if (this.popup){
			//tmp = browser.isNav6?this.popupWindow.ownerDocument.forms["frmCalendar"].calTxtYear : this.popupWindow.document.forms["frmCalendar"].calTxtYear;
			tmp = browser.isNav6?this.popupWindow.ownerDocument.getElementById('calTxtYear') : this.popupWindow.document.getElementById('calTxtYear');
     	}
     	else{
			//tmp = browser.isNav6?this.canvass.ownerDocument.forms["frmCalendar"].calTxtYear : this.canvass.document.forms["frmCalendar"].calTxtYear;
			tmp = browser.isNav6?this.canvass.ownerDocument.getElementById('calTxtYear') : this.canvass.document.getElementById('calTxtYear');
        }
	    // TO DO: validate tmp.value
        this.year = tmp.value ;
        this.writeString(this.buildString()) ;
    }
    
    suycCalendar.prototype.YearOnKeypress = function(event)
    {
		//alert('a');
		if (event.keyCode==13) {
			gCalendar.YearOnBlur()
		}

		if (event.keyCode==116) {
			gCalendar.MoveToCurrent()
		}

    }
    
    
    
    /*
        Invoked by the user explicitly changing the
        month dd selector
    */
    suycCalendar.prototype.MonthOnChange = function()
    {
		if (this.popup){
			//this.month = browser.isNav6?this.popupWindow.ownerDocument.forms["frmCalendar"].calSelMonth.selectedIndex:this.popupWindow.document.forms["frmCalendar"].calSelMonth.selectedIndex;		
			this.month = browser.isNav6?this.popupWindow.ownerDocument.getElementById('calSelMonth').selectedIndex:this.popupWindow.document.getElementById('calSelMonth').selectedIndex;		
		}
		else{
			//this.month = browser.isNav6?this.canvass.ownerDocument.forms["frmCalendar"].calSelMonth.selectedIndex:this.canvass.document.forms["frmCalendar"].calSelMonth.selectedIndex;
			this.month = browser.isNav6?this.canvass.ownerDocument.getElementById('calSelMonth').selectedIndex:this.canvass.document.getElementById('calSelMonth').selectedIndex;
	    }

		this.writeString(this.buildString());

    }
    
    
    
    // Moves the Calendar to the current Month/Year
    suycCalendar.prototype.MoveToCurrent = function()
    {
		
        gCalendar.year = parseInt(this.currentYear);
        gCalendar.month = parseInt(this.currentMonth);
        //alert('Today' + this.year + ' ' + this.month);
        gCalendar.writeString(this.buildString());
    }
    
    
    
    
    /*  **********************************************
        Private methods
        **********************************************/
    
    
    // Set up the canvass
    // Called on initialization of the Class to create the acutal DIV|LAYER Object
    suycCalendar.prototype.initCanvass = function()
    {
        if (browser.isNav4) 
        { 
            this.canvass = new Layer(200) ;
        }
        else if (browser.isIE4 || browser.isDOM)
        {
            this.canvass = browser.isDOM ? document.getElementById('calContainer') : document.all.calContainer ;
            //this.canvass = browser.isDOM ? document.body : document.body ;
            
	    }
	    this.setVisibility(Visibility.Off) ;
	}

    
    
    
    // overrideable - optional to pass in a Visibility enum
    // signatureA =  setVisibility()      // defaults to opposite of current values
    // signatureB =  setVisibility(Visibility.[On|Off])
    suycCalendar.prototype.setVisibility = function()
    {

		
		if(browser.isNav4)
        {
            if (this.setVisibility.arguments.length == 0)
			{
				this.canvass.visibility = this.isVisible ? 'show' : 'hide' ;
				this.isVisible = !(this.isVisible)
            }
            else
            {
                this.canvass.visibility = this.setVisibility.arguments[0] ? 'show' : 'hide' ;
                this.isVisible = this.setVisibility.arguments[0] ;
            }
        }
        else if (browser.isIE4 || browser.isDOM)
        {
            if (this.setVisibility.arguments.length == 0)
            {
                this.canvass.style.visibility = this.isVisible ? 'visible' : 'hidden' ;
                this.isVisible = !(this.isVisible)
            }
            else
            {
				this.canvass.style.visibility = this.setVisibility.arguments[0] ? 'visible' : 'hidden' ;
				this.isVisible = this.setVisibility.arguments[0] ;
            }
        }      
    }   // setVisibility
    
    
    
    // apply Positioning
    suycCalendar.prototype.positionCanvass = function()
    {
        if ( browser.isNav4 ) 
        { 
            this.canvass.left = this.x ;
            this.canvass.top = this.y ;
        }
        else if ( browser.isIE4 || browser.isDOM )
        {
            this.canvass.style.left = this.x ;
            this.canvass.style.top = this.y ;
        }       
    }   // positionCanvass
    
    
    
    // builds/accumulates the string
    suycCalendar.prototype.buildString = function()
    {
        
        // Get the first and last Day numbers of the month being fetched
        var objDate = new Date( this.year, this.month, 1 ) ;
        var firstDayOfMonth = objDate.getDay() ;
        var lastDayOfMonth = this.daysInMonth() ;
        objDate = null ;
        var i = 0 ;
        var numCols = 0 ;
        var numRows = 0 ;
        var currentDay = 0 ;
        var endPadding = '&nbsp;&nbsp;' ;
        
        
        // Work out what month last month was
        var pM = 0 ;
        var pY = 0 ;
        if((this.month - 1) < 0)
        {
            pM = 11 ;
            pY = this.year - 1 ;
        }
        else
        { 
            pM = this.month-1 ;
            pY = this.year ;
        }
        var daysInPreviousMonth = this.daysInMonth(pY, pM) ;
        var startOfPreviousMonth = daysInPreviousMonth - (firstDayOfMonth-1)
        
        
        
        // Start building the calendar body
        var tmpString = this.calTopOuter
                + this.calSelectorBarTop ;
        
                for (var i=0; i < this.months.length; i++)
                {
	                tmpString += '<option value="' + i + '"' ;
		            if (i == this.month) tmpString += ' selected' ;
		            tmpString += '>' + this.months[i].substr(0,3) + '</option>' ;
	            }
	     
	     tmpString += '</select>&nbsp;&nbsp;&nbsp;<input class="txtYear" maxlength="4" size="4" type="text" id="calTxtYear" name="calTxtYear" value="' + this.year + '" onkeypress="gCalendar.YearOnKeypress(event)" onBlur="gCalendar.YearOnBlur();">'
	            + this.calSelectorBarBottom
                + this.calDayNameBar ;
                
        // Body of calendar goes here
        
        tmpString += '<TR>' ;
        for(i = 0; i < firstDayOfMonth; i++)
        {
			if (i==0) {
				tmpString += '<td align="center" class="calWeekendDay" bgcolor="#ffffff"><font class="calNonCurrentMonth">' + startOfPreviousMonth++ + '</font></td>' ;
			}
			else
			{
				tmpString += '<td align="center" class="cal" bgcolor="#ffffff"><font class="calNonCurrentMonth">' + startOfPreviousMonth++ + '</font></td>' ;
			}
            
            numCols++ ;
        }
       
        for(i = 1; i <= lastDayOfMonth; i++)
        {
            // Call the method to create the cell contents

			            
            if(this.isToday(i,this.month,this.year))
            {
		        tmpString += '<td align="center" class="calToday" bgcolor="#ffffff"><a href="javascript: void(0) ;" onClick="gCalendar.DayClick(' + i + ') ;" class="calWeekday">' + i + '</a></td>' ;
            }
            else
            {
				if (this.isCurrent(i)){
			        tmpString += '<td align="center" class="calCurrent" bgcolor="#ffffff"><a href="javascript: void(0) ;" onClick="gCalendar.DayClick(' + i + ') ;" class="calWeekday">' + i + '</a></td>' ;
				}
				else{				
					if(this.isWeekendDay(i,this.month,this.year)){
						tmpString += '<td align="center" class="calWeekendDay" bgcolor="#ffffff"><a href="javascript: void(0) ;" onClick="gCalendar.DayClick(' + i + ') ;" class="calWeekday">' + i + '</a></td>' ;
					}
					else{
						tmpString += '<td align="center" class="calDay" bgcolor="#ffffff"><a href="javascript: void(0) ;" onClick="gCalendar.DayClick(' + i + ') ;" class="calWeekday">' + i + '</a></td>' ;		        
					}
		        }
		        
            }

            numCols++ ;

	        /* Display new row after each 7 day block.  */
	        if (numCols % 7 == 0)
	        {
    		    tmpString += '</TR><TR>' ;
    		    numRows++ ;
	        }
        }
        
        var counterCols = numCols ;
        var j = 1 ;
        for(i = counterCols; i < 42; i++)
        {
            
    	    numCols++ ;
    	    if (i == 35){
    			tmpString += '<td align="center" class="calWeekendDay" bgcolor="#ffffff"><font class="calNonCurrentMonth">' + j++ + '</font></td>' ;
    		}
            else{
    			// Call the method to create the cell contents
    			if (numCols % 7 == 0){
    				tmpString += '<td align="center" class="calWeekendDay" bgcolor="#ffffff"><font class="calNonCurrentMonth">' + j++ + '</font></td>' ;
    			}
    			else{
    				tmpString += '<td align="center" class="cal" bgcolor="#ffffff"><font class="calNonCurrentMonth">' + j++ + '</font></td>' ;
    			}
			}
            /* Display new row after each 7 day block.  */
    	    if (numCols % 7 == 0)
    	    {
    	        tmpString += '</TR>' ;
    	        if(i < 42) tmpString += '<TR>' ;
    	    }
        }
        
        // End of BODY
        
        tmpString += this.calBottomOuter ;
        
        return tmpString ;          
    }   // buildString
    
    CalCount=0


    suycCalendar.prototype.RenderPopup = function(s)
	{
		//alert('render popup')
		CalCount=CalCount+1;
		//alert(CalCount);
		//alert(s);
		this.calHTML = s;
		//alert('x:' + this.x + ' sx:' + window.screenLeft + ' y:' + this.y + ' sy:' + window.screenTop);

		this.popupWindow = window.open(gAppPath + '/WebControls/Calendar/CalPopup.html', 'datePopup','top=' + (this.y) + ',left=' + (this.x) +', width=' + calWidth +' ,height=' + calHeight +', toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,dependent=0',true);
		//this.popupWindow.moveTo(this.x,this.y);
		this.popupWindow.focus();

	}    
    
    // renders string to canvass
    suycCalendar.prototype.writeString = function(s)
    {
    	if (this.popup){
    		this.RenderPopup(s)
    	}
    	else{
			if(browser.isNav4)
			{
				this.canvass.document.open() ;
				this.canvass.document.writeln(s) ;
				this.canvass.document.close() ;
			}
			else if (browser.isIE4 || browser.isDOM)
			{
				//alert("canvass" + this.canvass.innerHTML + ' s=' + s );
				//this.canvass.innerHTML = 'TEST' ;
				this.canvass.innerHTML = s ;
			}    
        }      
    }   // writeString
    
    
    suycCalendar.prototype.formatDate = function(n)
    {
        //return '' + n + '-' + this.months[this.month].substr(0,3) + '-' + this.year ; 
        return '' + n + ' ' + this.months[this.month].substr(0,3) + ' ' + this.year ; 
    }
    
    
    
    // sets the chosen value in the target element
    suycCalendar.prototype.setValue = function()
    {
        try
        {
            targetEnabled = this.target.disabled ;
            this.target.disabled = false ;
            this.target.value = this.getFormattedDate() ;
            this.target.disabled = targetEnabled ;
        }
        catch(e)
        {
            var message ;
            message = '-----------------\n'
                + '\t Calendar error! \n\n'
                + 'An error has occurred.\n'
                + 'The chosen value cannot be \n'
                + 'written to the target field.\n'
                + '-----------------' ;
            alert(message) ;
        }
    }   // setValue
    
    
    
    // overrideable - optional to pass in yy/dd
    // signatureA =  daysInMonth()      // defaults to this.year, this.month
    // signatureB =  daysInMonth(y,m)
    suycCalendar.prototype.daysInMonth = function()
    {
        var oride = (this.daysInMonth.arguments.length == 2) ;
        
        var year = oride ? this.daysInMonth.arguments[0] : this.year ;
        var month = oride ? this.daysInMonth.arguments[1] : this.month ;
        
        if(month == 1 && this.isLeapYear(year))
            return (29) ;
        else
            return(this.monthDays[month]) ;
              
    }   // daysInMonth
    
    
    // used to compare a date to TODAY.  Used to color today.
    suycCalendar.prototype.isToday = function(d,m,y)
    {

	    var now = new Date() ;
	    var today = new Date(now.getFullYear(),now.getMonth(),now.getDate()) ;
	    var date = new Date(y,m,d) ;
	    return (date.toString() == today.toString());

    }   // isToday

	
	// used to compare a date to Current date in textbox
    suycCalendar.prototype.isCurrent = function(d)
    {
		
		if (this.formatDate(d) ==  this.CurrentDate){
			//alert(this.formatDate(d));
			return true;
		}
		return false;
		

    }   // isToday

    
    // used to compare a date a weekend day.  Used to color today.
    suycCalendar.prototype.isWeekendDay = function(d,m,y)
    {

	    var date = new Date(y,m,d) ;
	    
	    return ((date.getDay()==0) || (date.getDay()==6))

    }   // isToday
    
    
    
    // helper function
    suycCalendar.prototype.isLeapYear = function()
    {
        if (this.year % 4 == 0 && (this.year % 100 != 0 || this.year % 400 == 0))
    	    return(true) ; return(false) ;
    }   // isLeapYear
    
    
    function handleDocumentClick(e)
    {
		if (browser.isIE4) e = window.event;

		if (browser.isNav6)
		{
		    var bTest = (e.pageX > parseInt(gCalendar.canvass.style.left) && e.pageX <  (parseInt(gCalendar.canvass.style.left) + 162) && e.pageY < (parseInt(gCalendar.canvass.style.top)+163) && e.pageY > parseInt(gCalendar.canvass.style.top));
			if ((e.target.name != 'imgCalendar' && e.target.name != 'calSelMonth') && !(bTest))
			{
				gCalendar.Hide() ; 
			}
		}
	
		if (browser.isIE4)
		{
			// 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(gCalendar.canvass.style.left) && e.x <  (parseInt(gCalendar.canvass.style.left) + 160) && e.y < (parseInt(gCalendar.canvass.style.top)+141) && e.y > parseInt(gCalendar.canvass.style.top));
			if ((e.srcElement.name != 'imgCalendar' && e.srcElement.name != 'calSelMonth') && !(bTest))
			{
				gCalendar.Hide(); 
			}
		}
		
		if (browser.isNav4) gCalendar.Hide(); 
	}
	
    window.document.onclick=handleDocumentClick;