function CalendarOb()
{
// object properties
// ----------------------------------------------------------------------------------------
	this.m_oDocument = document;



// object methods
// ----------------------------------------------------------------------------------------

	// method to create input box using dom
	function printCalendarControl(seperator, field, startField, endField, value, onChange, imgPath)
	{
		// set global ptr to this calendar document...
		top.DesktopWindow.currentCalendarDoc = this.m_oDocument;
		// set global ptr to this calendar object...
		top.DesktopWindow.currentCalendarOb = this;

		var inputBox = '\
		<input type="text" size="10" maxlength="10" value="'+value+'" name="'+field+'" \
		onKeyUp="top.DesktopWindow.currentCalendarOb.format_date(this, this.value, \'1\',\'/\')"\
		onBlur="top.DesktopWindow.currentCalendarOb.valid_date(\''+seperator+'\',this,\''+startField+'\',\''+endField+'\');"\
		onChange="'+onChange+'"\
		>\
		<img src="'+imgPath+'calendaricon.gif"\
		onClick="top.DesktopWindow.currentCalendarOb.view_calendar(\''+seperator+'\',this.parentElement.firstChild,\''+startField+'\',\''+endField+'\', top.DesktopWindow.currentCalendarOb,\''+imgPath+'\', event);"\
		>\
		';
		return inputBox;
	}

	// function for onkeyup and down - also put it on down coz it stops the alpha characters better so if you hold down a key it wont bypass all the validation anymore
	function format_date(field_object, field_value, date_type, seperator)
	{
		//config
		//seperator = '/';
		// date_type Type 1 is ddmmyyyy
		// date_type Type 2 is mmddyyyy
		var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-!£$%^&*()_+=-][}{#'~@;:/.?>,<";
		var valid_char = " 0 1 2 3 4 5 6 7 8 9 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /";
		var valid_day = "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31";
		var valid_month = "01 02 03 04 05 06 07 08 09 10 11 12";

		// if backspace key used do not run validation code
		if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39)
		{
				last_char = field_object.value.substr((field_object.value.length-1),(field_object.value.length));
				//alert(last_char);
				if (alphaCheck.indexOf(field_value) >= 1) //check no funny characters are typed in 
				{
					field_object.value = field_object.value.substr(0, (field_object.value.length-1)); // if there are, blank the field
					field_object.focus(); // then focus in the box
					return false;
				}

			if (field_value.length == 2)  // when 2 characters are typed in...
			{
				day_value = field_value.substr(0,2); // get value of day
				first_char = field_value.substr(0,1); // get first char typed
				last_char = field_value.substr(1,2); // get last char typed
				if (valid_day.indexOf(day_value) == -1) // check it against the valid days that are allowed
				{
					if (last_char == seperator) // if they typed in only 1 digit number followed by seperator convert it to 2 digit and put seperator
					{
						field_object.value = "0" + first_char + seperator;
						return false;
					}
					else
					{
						field_object.value = ""; // if its not a valid day blank the field
						return false;
					}
				}
				field_object.value = field_value + seperator; // if it is add the seperator
			}

			if (field_value.length == 4) // when 4 characters are typed in...
			{
				seperator_value = field_value.substr(3,1); // check to see if they are typing in the seperator
				if (seperator_value == seperator) // if they are...
				{
					field_object.value = field_object.value.substr(0, 3); // delete it
				}
			}

			if (field_value.length == 5) // when 5 characters are typed in...
			{
				month_value = field_value.substr(3,5); // get value of month
				month_first_char = month_value.substr(0,1); // get first char typed in month
				last_char = field_value.substr(4,5); // get last char typed
				if (valid_month.indexOf(month_value) == -1) // check to see if a valid month
				{
					if (last_char == seperator) // if they typed in only 1 digit number followed by seperator convert it to 2 digit and put seperator
					{
						field_object.value = field_object.value.substr(0, 3) + "0" + month_first_char + seperator;
						return false;
					}
					else
					{
						field_object.value = field_object.value.substr(0, 2) + seperator; // if not delete last 2 characters and add seperator
						return false;
					}
				}
				field_object.value = field_value + seperator; // if valid add another seperator

			}

			if (field_value.length == 7) // when 7 characters are typed in...
			{
				seperator_value = field_value.substr(6,1); // check to see if they are typing in the seperator
				if (seperator_value == seperator) // if they are...
				{
					field_object.value = field_object.value.substr(0, 6); // delete it
				}
			}
		}
		else if (event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 37 || event.keyCode == 39) // if deleting - delete the relevant date section i.e the year
		{
			if (field_value.length == 9) field_object.value = field_object.value.substr(0, 6);
			if (field_value.length == 5) field_object.value = field_object.value.substr(0, 3);
			if (field_value.length == 2) field_object.value = field_object.value.substr(0, 0);
		}

		
	}

	// fucntion to validate date on blur of the input box
	function valid_date(seperator, field_object, start_field, end_field)
	{
		if (field_object.value.length == 8)
		{
			// make 2 digit year conversion to 4 digit use current years fist 2 digits ie. 20
			var calendar = new Date();
			var year = calendar.getFullYear();
			var year = year + '';
			var current_year = year.substr(0, 2);
			var two_digit_year = field_object.value.substr(6, 8);
			field_object.value = field_object.value.substr(0, 6) + current_year + two_digit_year;
		}

		if ((field_object.value.length > 0 && field_object.value.length < 8) || field_object.value.length == 9)
		{
			alert('Invalid Date Format!');
			field_object.focus();
		}
		else
		{
			// Convert into Date() - if the date like 31/02/2004 is converted Date will see it as 02/03/2004 so use this to validate this with original field value
			if (field_object.value != '')
			{
				var check_day = field_object.value.substr(0, 2);
				var check_month = field_object.value.substr(3, 2);
				var check_year = field_object.value.substr(6, 10);
				var calendar_check = new Date(check_year, (check_month-1), check_day);
				// break date up 
				var check_valid_day = calendar_check.getDate() + '';
				if (check_valid_day.length == 1) check_valid_day = '0' + check_valid_day;
				var check_valid_month = calendar_check.getMonth()+1 + '';
				if (check_valid_month.length == 1) check_valid_month = '0' + check_valid_month;
				var check_valid_year = calendar_check.getFullYear();
				check_valid_date = check_valid_day + seperator + check_valid_month + seperator + check_valid_year;
				// alert if dates dont match
				if (field_object.value != check_valid_date)
				{
					alert('The Date is not Valid!');
					field_object.value = "";
					field_object.focus();
				}
			}

			// if start field specified work out year, month, day (this is for start / end date feature
			if (start_field == "" || start_field == undefined || !this.m_oDocument.getElementById(start_field)) 
			{
				if (field_object.value == "") start_value = "01/01/1001";
				else start_value = field_object.value;
			}
			else
			{
				if (this.m_oDocument.getElementById(start_field).value == "") start_value = "01/01/1001";
				else start_value = this.m_oDocument.getElementById(start_field).value;
			}
			start_day = start_value.substr(0, 2);
			start_month = start_value.substr(3, 2);
			start_year = start_value.substr(6, 10);
			calendar_start = new Date(start_year, (start_month-1), start_day);
			start_secs = calendar_start.getTime();

			if (end_field == "" || end_field == undefined || !this.m_oDocument.getElementById(end_field)) 
			{
				if (field_object.value == "") end_value = "01/01/9005";
				else end_value = field_object.value;
			}
			else
			{
				if (this.m_oDocument.getElementById(end_field).value == "") end_value = "01/01/9005";
				else end_value = this.m_oDocument.getElementById(end_field).value;
			}
			end_day = end_value.substr(0, 2);
			end_month = end_value.substr(3, 2);
			end_year = end_value.substr(6, 10);
			calendar_end = new Date(end_year, (end_month-1), end_day);
			end_secs = calendar_end.getTime();

			// get milliseconds since 1970 of each day in the loop
			var selected_day = field_object.value.substr(0, 2);
			var selected_month = field_object.value.substr(3, 2);
			var selected_year = field_object.value.substr(6, 10);
				var selected_full_date = new Date(selected_year,(selected_month-1),selected_day);
				var selected_date_secs = selected_full_date.getTime();

				// if start_field specified then disable relevant boxes
			if ((selected_date_secs < start_secs) && field_object.value != "")
				{
				alert('Date not allowed!');
				field_object.value = start_value;
				field_object.focus();
			}
			else if (selected_date_secs > end_secs)
			{
				alert('Date not allowed!');
				field_object.value = end_value;
				field_object.focus();
			}

			// check for valid inbetween date
			/*if (start_field != "" || end_field != "")
			{
				var current_value = field_object.value.split(seperator);
				var current_day = current_value[0];
				var current_month = current_value[1];
				var current_year = current_value[2];
				var current_full_date = new Date(current_year, (current_month-1), current_day);
				var current_date_secs = current_full_date.getTime();
				if ((current_date_secs < start_secs) && (current_date_secs > end_secs))
				{
					alert('Date not valid');
					this.m_oDocument.getElementById(end_field).value = "";
					field_object.focus();
				}
			}*/
		}
	}

	// Show gui calendar control
	function show_calendar(field_object, seperator, start_field, end_field, the_year, the_month, the_day, img_path)
	{
		if(img_path) top.DesktopWindow.img_path = img_path; 
		else img_path = top.DesktopWindow.img_path;
		// set global ptr to this calendar document...
		top.DesktopWindow.currentCalendarDoc = this.m_oDocument;
		// set global ptr to this calendar object...
		top.DesktopWindow.currentCalendarOb = this;
		top.DesktopWindow.currentCalendarOb.field_object = field_object;
		
		// force day to be 1 - dont need it to increment when flicking through months
		the_day = 1;

		if ((start_field != "" && top.DesktopWindow.currentCalendarDoc.getElementById(start_field).value != "") && field_object.value == "")
		{
			if (the_month == "" || the_year == "") 
			{
				start_field_value = top.DesktopWindow.currentCalendarDoc.getElementById(start_field).value;
				start_field_value = start_field_value.split(seperator);
				start_day = start_field_value[0];
				start_month = parseInt(start_field_value[1],10)-1;
				start_year = start_field_value[2];
			}
			else
			{ 
				start_day = the_day; 
				start_month = the_month; 
				start_year = the_year;
			}
			the_year = start_year;
			the_month = parseInt(start_month,10);
			the_day = parseInt(start_day,10);
		}
		// if a date is already selected then when gui comes up go to that date
		else if (field_object.value != "")
		{
			if (the_month == "" || the_year == "")
			{
				field_value = field_object.value;
				field_value = field_value.split(seperator);
				the_day = parseInt(field_value[0],10);
				the_month = parseInt(field_value[1],10)-1;
				the_year = field_value[2];
			}
		}
		else
		{
			// if no date passed assume current date
			calendar_now = new Date();

			if (the_year == '') the_year = calendar_now.getFullYear();
			if (the_month == '') the_month = calendar_now.getMonth();
			if (the_day == '') the_day = calendar_now.getDay();
		}


		// if start field specified work out year, month, day (this is for start / end date feature 
		if (start_field == "" || start_field == undefined || !top.DesktopWindow.currentCalendarDoc.getElementById(start_field) ) 
		{
			start_field = "";
			start_value = "01/01/1001";
		}
		else
		{
			if (top.DesktopWindow.currentCalendarDoc.getElementById(start_field).value == "") start_value = "01/01/1001";
			else start_value = top.DesktopWindow.currentCalendarDoc.getElementById(start_field).value;
		}
		start_value = start_value.split(seperator);
		start_day = start_value[0];
		start_month = start_value[1];
		start_year = start_value[2];
		calendar_start = new Date(start_year, (start_month-1), start_day);
		start_secs = calendar_start.getTime();

		if (end_field == "" || end_field == undefined || !top.DesktopWindow.currentCalendarDoc.getElementById(end_field)) 
		{
			end_field = "";
			end_value = "01/01/9005";
		}
		else
		{
			if (top.DesktopWindow.currentCalendarDoc.getElementById(end_field).value == "") end_value = "01/01/9005";
			else end_value = top.DesktopWindow.currentCalendarDoc.getElementById(end_field).value;
		}
		end_value = end_value.split(seperator);
		end_day = end_value[0];
		end_month = end_value[1];
		end_year = end_value[2];
		calendar_end = new Date(end_year, (end_month-1), end_day);
		end_secs = calendar_end.getTime();

		// Create array of week days and months in a year
		week_days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
		year_months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

		// Define variables and things
		calendar = new Date(the_year, the_month, the_day);

		year = calendar.getFullYear();
		month = calendar.getMonth();
		day = calendar.getDay();
		today = calendar.getDate();

		// calendar starts at 1
		calendar.setDate(1);
		// set the current month
		calendar.setMonth(month);
		// month drop box
		print_month_box = '\
		<div style="display: none; position: absolute; z-index: 9999999; left: 54px; margin-top: 3px; border: solid; border-width: 1px; border-color: #657485; cursor: default;">\
			<table style="border: solid; border-width: 1px;" width="100" bgcolor="#97aece">';

		for (i=0; i < 12; i++)
		{
			if (year_months[i] == year_months[month]) var backgroundColor = "#ffffff";
			else var backgroundColor = "#97aece"
			print_month_box += '\
				<tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\';" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+year+'\',\''+i+'\',\'\',\''+img_path+'\');">\
				<td style="border: solid; border-width: 1px; border-color: '+backgroundColor+'">\
				<font face="Arial" size="2"><b>'+ year_months[i] +'</b></font>\
							</td>\
				</tr>';
		}

		print_month_box += '\
					</table>\
			</div>';

        // year drop box
        print_year_box = '\
        <div style="display: none; position: absolute; z-index: 9999999; left: 159px; margin-top: 3px; border: solid; border-width: 1px; border-color: #657485; cursor: default;" onmouseover="this.style.display = \'inline\';" onmouseout="this.style.display = \'none\';"><span onmouseover="top.DesktopWindow.currentCalendarOb.listYearsObj = this;">\
                <table style="border: solid; border-width: 1px;" width="40" bgcolor="#97aece">\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmouseup="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollUpforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">/\\</div></td></tr>';

        for (i=0; i < 7; i++)
        {
                if (year == (list_year+i)) var backgroundColor = "#ffffff";
                else var backgroundColor = "#97aece";
                var list_year = (year-3); // minus 3 years off current year. this will show previous years aswell on list
                print_year_box += '\
                        <tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\'" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+(list_year+i)+'\',\''+(month)+'\',\'\',\''+img_path+'\');">\
                        <td style="border: solid; border-width: 1px; border-color: '+backgroundColor+'">\
                        <font face="Arial" size="2"><b>'+ (list_year+i) +'</b></font>\
                        </td>\
                        </tr>';
        }


        print_year_box += '\
        <tr><td><div align="center" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollDownforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">\\/</div></td></tr>\
                </table></span>\
        </div>';

		// Header of Calendar
		print_calendar = '<img src="'+img_path+'calendar_bg_blue.gif"><span style="position:absolute; left: 1px; top:3px; width:245px;><table height="220" width="250" border="0">\
		<tr valign="top">\
		<td>\
			'+ print_month_box  +'\
			'+ print_year_box  +'\
			<table width="100%" border="0">\
			<tr valign="top">\
			<td colspan="7" style="text-align: center;"><strong><font face="Arial" size="2" color="#FFFFFF"><a style="cursor:default" onclick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+year+'\',\''+(month-1)+'\',\'\',\''+img_path+'\');" ondblclick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+year+'\',\''+(month-1)+'\',\'\',\''+img_path+'\');"><span style="position: absolute; left: 8px; height: 18px; width: 20px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffcc00\'" onmouseout="this.style.borderColor=\'#ffffff\'"><img style="" src="'+img_path+'calendar_left.gif" style="margin-top: 2px;"></span></a>&nbsp;<a style="cursor: default" onclick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+year+'\',\''+(month+1)+'\',\'\',\''+img_path+'\');" ondblclick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+year+'\',\''+(month+1)+'\',\'\',\''+img_path+'\');"><span style="position: absolute; left: 32px; height:18px; width: 20px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffcc00\'" onmouseout="this.style.borderColor=\'#ffffff\'"><img src="'+img_path+'calendar_right.gif" style="margin-top: 2px;"></span></a><a style="cursor: default;" onClick="parentElement.parentElement.offsetParent.offsetParent.previousSibling.previousSibling.style.display=\'inline\'; parentElement.parentElement.offsetParent.offsetParent.previousSibling.style.display=\'none\';"><span style="position: absolute; left: 56px; width: 100px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffcc00\'" onmouseout="this.style.borderColor=\'#ffffff\'">'+year_months[month]+'</span></a> <a style="cursor: default;" onClick="parentElement.parentElement.offsetParent.offsetParent.previousSibling.style.display=\'inline\'; parentElement.parentElement.offsetParent.offsetParent.previousSibling.previousSibling.style.display=\'none\';"><span style="position: absolute; left: 160px; width: 40px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffcc00\'" onmouseout="this.style.borderColor=\'#ffffff\'">'+year+'</span></strong></font><img style="position: absolute; right: 4px; cursor: default;" src="'+img_path+'bar_exit.gif" onclick="top.DesktopWindow.doCloseCalendar();""></td>\
			</tr>\
			<tr>';
		// print days of the week
		for (i=0; i < 7; i++)
		{
			// bold the day of the week (optional - well will be when i go back to it and make it)
			if(day == i)
			{
				print_calendar += '<td height="25" width="30" style="cursor: default;"><font face="Arial" size="2"><b>'+week_days[i]+'</b></font></td>';
			}
			else
			{
				print_calendar += '<td height="25" width="30" style="cursor: default;"><strong><font face="Arial" size="2">'+week_days[i]+'</font></strong></td>';
			}
		}
		print_calendar += '</tr>\
		<tr>';
		// Blank out before 1
		for (i=0; i < calendar.getDay(); i++)
		{
			print_calendar += '<td>'+' '+ '</td>';
		}

		for (i=0; i < 31; i++)
		{
			if (calendar.getDate() > i) show_next_day = calendar.getDay();
			if (show_next_day == 0) print_calendar += '<tr>'; // start a new row for first week day
			if (show_next_day != 7) var theday = calendar.getDate(); 
			if((i+1)==theday)
			{
				// convert interger to string and find out if 1 digit, if it is add 0
				theday = theday + '';
				if (theday.length == 1) theday = '0' + theday;

				// get milliseconds since 1970 of each day in the loop
				var selected_full_date = new Date(year,month,theday);
				var selected_date_secs = selected_full_date.getTime();

				// if start_field specified then disable relevant boxes
				if (selected_date_secs < start_secs)
				{
					print_calendar += '<td height="22" width="30" bgcolor="#e6e6e6" style="cursor: default"><font face="Arial" size="2" color="#f7f7f7">'+theday+'</font></td>';
				}

				// if end_field specified then disable relevant boxes
				else if (selected_date_secs > end_secs)
				{
					print_calendar += '<td height="22" width="30" bgcolor="#e6e6e6" style="cursor: default"><font face="Arial" size="2" color="#f7f7f7">'+theday+'</font></td>';
				}


				// bold the day (optional - well will be when i go back to it and make it)
				//else if (calendar.getDate() == calendar_now.getDate() && calendar.getMonth() == calendar_now.getMonth()) 
				//{
				//	print_calendar += '<td height="22" width="30" bgcolor="#eaf1fd" onmouseover="this.bgColor=\'#ffcc00\'" onmouseout="this.bgColor=\'#eaf1fd\'" style="cursor: hand" onClick="top.DesktopWindow.currentCalendarDoc.getElementById(\''+field_object+'\').value = \''+theday + '/' + (month + 1) + '/' + year+'\'; top.DesktopWindow.doCloseCalendar();"><b>'+theday+'</b></td>';
				//}
				else
				{
					// Convert month to string to add 0 if month is single digit
					var the_month = month + 1;
					var the_month = the_month + '';
					if (the_month.length == 1) the_month = '0' + the_month;
					print_calendar += '<td height="22" width="30"  bgcolor="#ffffff" onmouseover="this.bgColor=\'#ffcc00\'" onmouseout="this.bgColor=\'#ffffff\'" style="cursor: default" onClick="top.DesktopWindow.currentCalendarOb.field_object.value = \''+theday + '/' + the_month + '/' + year+'\'; top.DesktopWindow.doCloseCalendar(); top.DesktopWindow.currentCalendarOb.field_object.focus(); top.DesktopWindow.currentCalendarOb.field_object.value = top.DesktopWindow.currentCalendarOb.field_object.value + \'\';"><font face="Arial" size="2" color="#000000">'+theday+'</font></td>';
				}
			}
			if (show_next_day == 7) print_calendar += '</tr>'; // end the row for week
			calendar.setDate(calendar.getDate()+1);
		} 
		print_calendar += '</table>\
			</td>\
			</tr>\
			</table></span>';
			top.DesktopWindow.document.getElementById('cal1').innerHTML = print_calendar;
	}			

	function view_calendar(seperator, fieldname, startfield, endfield, oCalendarObject, sWorkDirPath, e)
	{
		oCalendarObject.show_calendar(fieldname,seperator,startfield,endfield,'','','',sWorkDirPath);
		
		var calDiv = top.DesktopWindow.document.getElementById('cal1');
		if (calDiv)
		{
			calDiv.style.zIndex = top.DesktopWindow.a + 1;
			newXpos = e.clientX + document.documentElement.scrollLeft;
			newYpos = e.clientY + document.documentElement.scrollTop;
			
			if ((top.DesktopWindow.document.body.offsetWidth - newXpos) < 250) newXpos = newXpos - 250;
			if ((top.DesktopWindow.document.body.offsetHeight - newYpos) < 220) newYpos = newYpos - 220;     
			calDiv.style.pixelLeft = newXpos;
			calDiv.style.pixelTop = newYpos;
			top.DesktopWindow.hidedbxs(top.DesktopWindow.currentCalendarDoc);
			calDiv.style.display = 'inline';
		}	
	}

	function doCloseCalendar()
	{
		top.DesktopWindow.document.getElementById('cal1').style.display= 'none';
		top.DesktopWindow.showdbxs(top.DesktopWindow.currentCalendarDoc);
	}

//################### Functions for Scrolling the year Up and Down #####################

function scrollDownforabit(field_object,seperator,start_field,end_field)
{
        scrollDown(field_object,seperator,start_field,end_field);
        if(top.DesktopWindow.scrollagain) setTimeout('top.DesktopWindow.currentCalendarOb.scrollDownforabit(top.DesktopWindow.currentCalendarOb.field_object,"'+seperator+'","'+start_field+'","'+end_field+'")',100);
}
function scrollDown(field_object,seperator,start_field,end_field)
{
        if (year == (year+i)) var backgroundColor = "#ffffff";
        else var backgroundColor = "#97aece";
        year = parseInt(year,10)-2;
        scrolldown = '<table style="border: solid; border-width: 1px;" width="40" bgcolor="#97aece" onmouseup="top.DesktopWindow.scrollagain = false;">\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollUpforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">/\\</div></td></tr>';

        for (i=0; i < 8; i++)
        {
                scrolldown += '\
                        <tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\';" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+(year+i)+'\',\''+(month)+'\');"><td style="border: solid 1px #97aece;"><font face="Arial" size="2"><b>'+ (year+i) +'</b></font></td></tr>';
        
	}

        scrolldown += '\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmouseup="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollDownforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">\\/</div></td></tr>\
                </table>';
        year=year+3;
	top.DesktopWindow.currentCalendarOb.listYearsObj.innerHTML = scrolldown;
}

function scrollUpforabit(field_object,seperator,start_field,end_field)
{
        scrollUp(field_object,seperator,start_field,end_field);
        if(top.DesktopWindow.scrollagain) setTimeout('top.DesktopWindow.currentCalendarOb.scrollUpforabit(top.DesktopWindow.currentCalendarOb.field_object,"'+seperator+'","'+start_field+'","'+end_field+'")',100);
}

function scrollUp(field_object,seperator,start_field,end_field)
{
	if (year == (year+i)) var backgroundColor = "#ffffff";
        else var backgroundColor = "#97aece";
        year = parseInt(year,10)-2;
        scrollup = '<table width="40" style="border: solid; border-width: 1px;" bgcolor="#97aece">\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmouseup="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollUpforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">/\\</div></td></tr>';

        for (i=0; i < 8; i++)
        {
                scrollup += '\
                        <tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\';" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(top.DesktopWindow.currentCalendarOb.field_object,\''+seperator+'\',\''+start_field+'\',\''+end_field+'\',\''+(year+i)+'\',\''+(month)+'\');"><td style="border: solid 1px #97aece;"><font face="Arial" size="2"><b>'+ (year+i) +'</b></font></td></tr>';
        }

        scrollup += '\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmouseup="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollDownforabit(top.DesktopWindow.currentCalendarOb.field_object,\\\''+seperator+'\\\',\\\''+start_field+'\\\',\\\''+end_field+'\\\',\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">\\/</div></td></tr>\
                </table>';
        year=year+1;
	top.DesktopWindow.currentCalendarOb.listYearsObj.innerHTML = scrollup;
}

// public methods
// ----------------------------------------------------------------------------------------
	this.printCalendarControl = printCalendarControl;
	this.format_date = format_date;
	this.valid_date = valid_date;
	this.show_calendar = show_calendar;
	this.scrollDown = scrollDown;
	this.scrollDownforabit = scrollDownforabit;
	this.scrollUpforabit = scrollUpforabit;
	this.scrollUp = scrollUp;
	this.view_calendar = view_calendar;

// this sets a global function to close current calendar();	
	top.DesktopWindow.doCloseCalendar = doCloseCalendar;
}

