/****************************************************************
*					TDS Date Picker								*
*																*
*	Created By:		Tom Smith	tsmith@tdscode.com			   	*
*	Created Date:	10/25/2000									*
*																*
*	Modified By:	Tom Smith									*
*	Modified Date:	02/06/2003									*
*	Modified Description:										*
*		Updated a problem with the change month.  This occurred	*
*		when the current date was larger than the next months.	*
*		Example: Today 1-31-2003 would fail when going to Feb	*
*		because Feb only had 28 days.  Also fixed the leap year	*
*		problem. Thanks to Bonny Silva for finding these bugs.	*
*****************************************************************
*	For updated releases/changes visit www.tdscode.com			*
*																*
*	This code may be used freely as long as this header is 		*
*	displayed at the top of this file.							*
*																*
*	The calendar was designed for Netscape 4.x - higher	and		*
*	Internet Explorer 4.x - higher.								*
*																*
*	For instructions on using the calendar in visit 			*
*	www.tdscode.com.  Comments and suggestions are welcome.		*
****************************************************************/

// Hide caledar on Esc button press (disable it if causes JS errors)
document.onkeyup = KeyCheck;
function KeyCheck(e){if((window.event) ? event.keyCode : e.keyCode == 27) hideCalendar();}

//User defined Variables *** The values may be changed on the variable below

var INPUT_COPY_TO_ID	= null; // if not null, copy calendar value to this element

var PREV_COLOR 			= "#E6F3FB";			//Color - color the previous arrow
var NEXT_COLOR 			= "#E6F3FB";			//Color - color for the next arrow
var MONTH_BGCOLOR 		= "#79909E";			//Background Color - color for the Month heading			
var WEEK_BGCOLOR 		= "#FFFFFF";			//Background Color - color for the Weekday headings
var DAY_BGCOLOR 		= "#fdfbbe";			//Background Color - color for the Days #ffffff
var DAY_BLANK_BGCOLOR 	= "#ffffff";			//Background Color - color for the blamnk Days #ffffff
var PNI_MOCOLOR 		= "#5D7F9D";			//Background Rollover Color - color to change the previous/next button background when the mouse rolls over
var DAY_MOCOLOR 		= "#CCCCCC";			//Background Rollover Color - color to change the Days background when the mouse rolls over
var HDR_FNT_COLOR 		= "#FFFFFF";			//Font Color - color for the head month and year
var WEEK_BOR_COLOR		= "#FFFFFF";			//Border Color - color for the border around the Weekday headings
var WEEK_NUM_HEAD_COLOR ="#000000";				//The color of the week number head line text
var WEEK_NUM_HEAD_BGCOLOR ="#FFFFFF";			//The color of the week number head line bgcolor
var WEEK_NUM_BOR_COLOR  ="#D4D4D4";				//The color of the week numbers cell border
var WEEK_NUM_BG_COLOR   ="#FFFFFF";				//The color of the week numbers cell bgcolor
var MONTH_SELECT_BGCOLOR  = "#A9A7B4"   		//Background Color of the year and month selectbox
var BOTTOM_ROW_COLOR	="#454545";				//The color of the footer


var IF_CLICK_CLOSE      ="yes";					//If click on the chosen date wiil close the calendar, if no close with X button: YES/NO 
var HOUER_SELECTION		="no";					//If to display the hours selectboxs on the bottom: YES/NO 
var ARROWS_ROW_DISPLAY  ="no";					//The forward and backward date row display: YES/NO
var ARROWS_FOR_SELECT   ="yes";					//The forward and backwaord buttons in the selectbox row: YES/NO
var WEEK_NUMBER	        ="no";					//If to display a week number 1-52: YES/NO
var DISPLAY_TODAY		="no";					//If to display the today date on the bottom row
var DATE_FORMAT			="dd/mm/yyyy" 			//DATE FORMAT FOR FUTURE SUPPORT: "DD/MM/YYYY" / "MM/DD/YYYY"
var CALENDAR_DIV_NAME   = "calendar1";          //The name of the containing calendar div (see above document.write)
var MONTH_SELECTION     = "BUTTONS";            	//If the forward and back month will be with selectbox and not arrows: BUTTONS/ARROWS
var HOUERS_FORMAT       = 24;                   //The oures select format 12/24
var YEARS_TO_DISPLAY    = 11;					//How many years will show in the selectbox
var YEAR_TO_START	    = 2008;                 //The first year in the year selectbox
var CALENDAR_DIR		="ltr";					//the direction and language of the calendar: LTR/RTL

var submitValue = "send";                       //The submit button value
////var CALENDAR_HEIGHT     = "207px";          //THE CALENDAR SIZE FOR THE SHIM IFRAME
var CALENDAR_WIDTH		= ""; 
////CALENDAR_WIDTH	= "191px";
var weekNuberHead ="Wk";						//THE week numbers head content text
var weekDaysArr = new Array(7);
weekDaysArr[0]="Sun";                       //the week days head content
weekDaysArr[1]="Mon";
weekDaysArr[2]="Tue";
weekDaysArr[3]="Wed";
weekDaysArr[4]="Thu";
weekDaysArr[5]="Fri";
weekDaysArr[6]="Sat";
 
//Global Variables
//Define the different browser types that are supported
var NS4 = (navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==4);
var NS6 = (navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==5);
var IE4 = document.all;

//Calendar objects
var calNS4;
var calNS6;
var calIE4;

//Holding Variables
var CALENDAR_HTML = "";
var DISPLAY_DATE = "";
var CURRENT_DATE_FIELD = "";
var CURRENT_DATE_FIELD_ID = "";
var CURRENT_FORM = "";
var OBJECT_TO_ATTACH = "";
var HLD_DIV = "";
var BUILT = "no";
var START_DATE = '';
var END_DATE = '';
 
var theSentDivId = "";
var strBottmRow = "";
var tempWeekVal ="";
var tempWeekFlag = 0;
var currnetDayFlag = 0;
var theDateStr ="";
var theDayStr = "";
var theMounthStr = ""; 
var theYearhStr = "";
var hoursValue ="";
var minutesValue ="";
var tdProperties =""
var selectOpen = 1;
var currentDayStr = "";
//End of Global Variables

//Write out the style sheets
var _headStr = "<style>";
_headStr += ".dragme{position:relative;width:10px;height:10px;}";
_headStr += ".txtDay { font-size: 9px; color:#000000; font-family: arial; text-decoration: none;cursor:default;}";
_headStr += ".weekNuberHead{ font-size: 9px; color: " + WEEK_NUM_HEAD_COLOR + "; font-family: arial; text-decoration: none;}";
if(CALENDAR_DIR=="rtl"){
  _headStr += ".tdWeekNum { padding: 2px; border-left: 1px solid " + WEEK_NUM_BOR_COLOR + ";background-color:"+ WEEK_NUM_BG_COLOR +"}";
}else{
  _headStr += ".tdWeekNum { padding: 2px; border-right: 1px solid " + WEEK_NUM_BOR_COLOR + ";background-color:"+ WEEK_NUM_BG_COLOR +"}";
}
_headStr += ".tdToDay{background-color:#E3F4FB;border: 1px solid #788EA5;font-weight:bold;color:#7E8E9D}";
//_headStr += ".txtToDay{ font-family: arial;font-size:9px;font-weight:bold;color:#7E8E9D;}";
_headStr += ".tdFieldDay{;background-color:#EEEFEE;border: 1px solid #FF0000;padding: 1px;font-family: arial;font-weight:bold;color:#7E8E9D;}";
_headStr += ".tdFieldDay a, .tdFieldDay *{font-weight:bold;color:#7E8E9D;}";
//_headStr += ".txtFieldDay{ font-family: arial;font-size: 9px;font-weight:bold;color:#7E8E9D;}";
_headStr += ".txtMonth { font-size: 11px; color: " + HDR_FNT_COLOR + "; font-family: arial; text-decoration: none;}";
_headStr += ".tblCalendar {border-collapse:collapse;border: 1px solid #A7A1A5;font-family:arial;font-size:10px;}";
_headStr += ".tblCalendar td{text-align:center;vertical-align:middle;awidth:20px;aheight:20px;}";
_headStr += ".tdMonth { padding: 2px;}";
_headStr += ".tdDayW { padding: 2px; border: 1px solid " + WEEK_BOR_COLOR + "; }";
_headStr += ".tdDay{padding: 2px;border:1px solid white;background-color:"+DAY_BGCOLOR+";}";
_headStr += ".tdDay a{color:black;}";
_headStr += ".tdDayBlank{padding: 2px;border:1px solid white;background-color:"+DAY_BLANK_BGCOLOR+";}";
_headStr += ".btnPrev { font-size: 12px; color: " + PREV_COLOR + "; font-family: arial; font-weight:bold; text-decoration: none;}";
_headStr += ".btnNext { font-size: 12px; color: " + NEXT_COLOR + "; font-family: arial; font-weight:bold; text-decoration: none;}";
_headStr += ".selectHours{ font-size: 9px; color: black; font-family: arial; font-weight:normal;}";
_headStr += "a {text-decoration:none;cursor:pointer;}";
_headStr += ".tdDisabledDay{background-color:white;cursor:default;padding: 2px;border:1px solid white;color:#aaaaaa;}";
//_headStr += ".tdDisabledDay *{color:#aaaaaa;}";
_headStr += ".iframeShimCal {position:absolute;z-index:5; width:100%; heigth:100%; top:0px; left:0px;";
_headStr += "</style>";
//Write out metadata and placeholder for calendar
_headStr += "<div id=\"theCalendarWrapDIv\" style=\"display:none;\" class=\"dragme\">";
_headStr += "<div id=\""+CALENDAR_DIV_NAME+"\" style=\"position:absolute;z-index:100;left:0;top:0;\"></div>";
_headStr += "<iframe id=\"DivShimCal\" class=\"iframeShimCal\" src=\"\" scrolling=\"no\" frameborder=\"0\"></iframe>";
_headStr += "</div>";

document.write(_headStr);
_headStr=null;

/**
* This function is used to display the calendar
* field			- input for the date
* xPos, yPos	- position relative to "objToCling" 
* objToCling	- ancror for clicking
* currentDate	- initial date for calendar to show. If not specified, current date is shown
* startDate		- minimal date to choose. If not specified, -infinity is used
* endDate		- maximal date to shoose. If not specified, +infinity is used
*/
function showCalendar(field,xPos,yPos,objToCling, currentDate, startDate, endDate){
//	alert('currentDate = ' + currentDate + ' startDate = '+ startDate + ' endDate = ' + endDate);
	date = CALENDAR_DIV_NAME;
	theSentDivId = date;
	tempWeekFlag = 0;
	OBJECT_TO_ATTACH = objToCling;
	if (HLD_DIV != date && BUILT == "yes"){
		if (NS4)
			calNS4.visibility = 'hidden';
		else if (IE4)
			calIE4.style.visibility = 'hidden';
		else if (NS6)
			calNS6.style.visibility = 'hidden';
		
		BUILT = "no";
		HLD_DIV = date;
	}
		
	if (BUILT == "yes"){
		if (NS4)
			calNS4.visibility = 'visible';
		else if (IE4)
			calIE4.style.visibility = 'visible';
		else if (NS6)
			calNS6.style.visibility = 'visible';
		return;
	}

	//Set the Date field to use
	CURRENT_DATE_FIELD = field;
	CURRENT_DATE_FIELD_ID = document.getElementById(CURRENT_DATE_FIELD)
	CURRENT_FORM = document.getElementById(CURRENT_DATE_FIELD).form.name;
	
	//Set the Display Date to null
	DISPLAY_DATE = "";
	
	if(currentDate.length > 6){ // if we pased initial date
		theDateStr = currentDate.substring(0,10);
		if(DATE_FORMAT=="dd/mm/yyyy"){
			theDayStr = parseInt(theDateStr.substring(0,2));
			theMounthStr = theDateStr.substring(3,5);
		}else{
		    theDayStr = parseInt(theDateStr.substring(3,5));
			theMounthStr = theDateStr.substring(0,2);
		}
		if(theMounthStr.substring(0,0)==0)theMounthStr = theMounthStr *1
		theYearhStr = parseInt(theDateStr.substring(6,10));
		DISPLAY_DATE = theMounthStr + "/" + 1 + "/" + theYearhStr;
	}
	else if(CURRENT_DATE_FIELD_ID.value !="" && CURRENT_DATE_FIELD_ID.value.length>6){//if the field is not empty
      	theDateStr = CURRENT_DATE_FIELD_ID.value.substring(0,10);
		if(DATE_FORMAT=="dd/mm/yyyy"){
			theDayStr = parseInt(theDateStr.substring(0,2));
			theMounthStr = theDateStr.substring(3,5);
		}else{
		    theDayStr = parseInt(theDateStr.substring(3,5));
			theMounthStr = theDateStr.substring(0,2);
		}
		if(theMounthStr.substring(0,0)==0)theMounthStr = theMounthStr *1
		theYearhStr = parseInt(theDateStr.substring(6,10));
		if (HOUER_SELECTION=="yes"){
		  hoursValue = CURRENT_DATE_FIELD_ID.value.substring(11,13);
		  minutesValue = CURRENT_DATE_FIELD_ID.value.substring(14,16);
		}
		DISPLAY_DATE = theMounthStr + "/" + 1 + "/" + theYearhStr
	}

	START_DATE	= formatDate(startDate, DATE_FORMAT);
	END_DATE 	= formatDate(endDate, DATE_FORMAT);
	//Build the Calendar
	buildCalendar();
	
	if (!xPos) xPos = "";
	if (!yPos) yPos = "";

	//Display the Calendar on the Web page
	if (NS4){
		calNS4 = new Layer(50,this);
		calNS4.document.write(CALENDAR_HTML);
		calNS4.document.close();
		if (xPos != "" || yPos != ""){
			this.calNS4.pageX = xPos;
			this.calNS4.pageY = (yPos - 95);
		}
		else{
			this.calNS4.pageX = document.layers[date].pageX;
			this.calNS4.pageY = (document.layers[date].pageY - 95);
		}
		calNS4.visibility = 'visible';
	}
	else if (IE4){
		calIE4 = document.all[date];
		calIE4.innerHTML = CALENDAR_HTML;
		
		if (xPos != "" || yPos != ""){
			calIE4.style.posLeft = xPos;
			calIE4.style.posTop = yPos;
		}
		calIE4.style.visibility = 'visible';
	}
	else if (NS6){
		calNS6 = document.getElementById(date);
		calNS6.innerHTML = CALENDAR_HTML;
		if (xPos != "" || yPos != ""){
			calNS6.style.top = yPos;
			calNS6.style.left = xPos;
		}
		calNS6.style.visibility = 'visible';
	}
	
	BUILT = "yes";

	//displayDivShim(1);

	if(MONTH_SELECTION == "BUTTONS"){
		fillMounth();
		fillYears();
	}
	if(IE4)showHideElements(1);
	if(DISPLAY_TODAY=="yes")drawTodayDate();
	if(HOUER_SELECTION=="yes"){
		houersSelect();
		minutesSelect();
	}
	strBottmRow ="";
	if (HOUER_SELECTION=="yes" && CURRENT_DATE_FIELD_ID.value !=""){
		updateHours();
		updateMinutes();
	}
	var ooo= document.getElementById(OBJECT_TO_ATTACH)
	popupShow(ooo,-100,150);
	getCalendarSize();
}

//This function is used to hide the calendar
function hideCalendar(){
	tempWeekFlag = 0;
	if (BUILT == "no")
		return;
	BUILT = "no";
	if (NS4)
		calNS4.visibility = 'hidden';
	else if (IE4)
		calIE4.style.visibility = 'hidden';
	else if (NS6)
		calNS6.style.visibility = 'hidden';
		
	if(IE4)showHideElements(0);	
	strBottmRow ="";
	popupHide();
}

function callChgCalendarDate(){
  var theStr ="";
  var mounthList = document.getElementById('noHide_mounth');
  var yearsList = document.getElementById('noHide_years');

  theStr = parseInt(mounthList.value)+1 + "/" + 1 + "/" + yearsList.value;
  chgCalendarDate(theStr);
}

//This function is used to change the Calendar Date
function chgCalendarDate(dspDate){
	//Set the Display to the new Date
	DISPLAY_DATE = dspDate;
     
	//Build the Calendar
	tempWeekFlag = 0;
	buildCalendar();
	
	//Display the Calendar on the Web page
	if (NS4){
		calNS4.document.write(CALENDAR_HTML);
		calNS4.document.close();
	}
	else if (IE4)
		calIE4.innerHTML = CALENDAR_HTML;
	else if (NS6)
		calNS6.innerHTML = CALENDAR_HTML;
		
	// *************************************
	if(MONTH_SELECTION == "BUTTONS"){
		fillMounth();
		fillYears();
	}
	if(IE4)showHideElements(1);
	if(DISPLAY_TODAY=="yes")drawTodayDate();
	if(HOUER_SELECTION=="yes"){
	 houersSelect();
	 minutesSelect();
	 }
	 if (HOUER_SELECTION=="yes" && CURRENT_DATE_FIELD_ID.value !=""){
	  updateHours();
	  updateMinutes();
	}
	getCalendarSize();
	strBottmRow ="";
}

//This function is used to change the Date field to the selected calendar date
function chgDate(txtDate){
    var theHours = "";
	if(HOUER_SELECTION=="yes"){
	  theHours = " " + document.getElementById('noHide_hourSelect').value;
	  theHours = theHours + ":"  + document.getElementById('noHide_minuteSelect').value;
	}

	//update the value in the field
	document.forms[CURRENT_FORM][CURRENT_DATE_FIELD].value = txtDate + theHours;
	
	if(INPUT_COPY_TO_ID!=null && document.getElementById(INPUT_COPY_TO_ID)){
		if(document.getElementById(INPUT_COPY_TO_ID).value == ''){
			document.getElementById(INPUT_COPY_TO_ID).value = txtDate;
		}
	}
	
	//Hide the Calendar
	tempWeekFlag = 0;
	if(IF_CLICK_CLOSE == "yes"){
	   hideCalendar();
	}else{
	   getDateFromField();
	   //alert(dspDate)
	   var dspDate = theMounthStr + "/" + 1 + "/" + theYearhStr;
	   //problem is in chgCalendarDate
	   /**/
	   chgCalendarDate(dspDate);
	}
}

//This function is used to Build the Calendar
function buildCalendar(){
	var startDateObj = START_DATE;
	var endDateObj = END_DATE;

	//Define the Month Names and Month Days Array
	if (CALENDAR_DIR=="ltr"){
	    monthNames = new Array("January","Februrary","March","April","May","June","July","August","September","October","November","Decemeber");
	}else{
	    monthNames = new Array("January","Februrary","March","April","May","June","July","August","September","October","November","Decemeber");
	}
	monthDays 		= new Array(12);
	
	//Entry the Total Days for each Month
	monthDays[0]	= 31;
	monthDays[1]	= 28;
	monthDays[2]	= 31;
	monthDays[3]	= 30;
	monthDays[4]	= 31;
	monthDays[5]	= 30;
	monthDays[6]	= 31;
	monthDays[7]	= 31;
	monthDays[8]	= 30;
	monthDays[9]	= 31;
	monthDays[10]	= 30;
	monthDays[11]	= 31;

	//Determine the Date for the Calendar to Display
	if (DISPLAY_DATE == ""){
		calendarDateObj	= new Date();
	}else{
		calendarDateObj = new Date(DISPLAY_DATE);
	}
	
	//Obtain the Calendar Dates
	calendarDate	= calendarDateObj.getDate();
	calendarDay		= calendarDateObj.getDay();
	calendarMonth	= calendarDateObj.getMonth();
	calendarYear	= calendarDateObj.getFullYear();//calendarDateObj.getYear();
	
	//Obtain Todays Dates
	currentDateObj 	= new Date();
	currentDate 	= currentDateObj.getDate();
	currentDay 		= currentDateObj.getDay();
	currentDayStr   = currentDateObj.getDay(); //to send if fiels is empty
	currentMonth 	= currentDateObj.getMonth();
	currentYear		= currentDateObj.getFullYear();//currentDateObj.getYear();
	
	//*** Fix - TDS 2-06-2003 ***
	if ((calendarMonth == currentMonth) && (calendarYear == currentYear))
	{
		calendarDate = currentDate;
		calendarDay = currentDay;
	}
	
	if (LeapYear(calendarYear))
		monthDays[1] = 29;
	//*** End Fix - 2-06-2003 ***
	
	//Make sure the Year is in the correct century
	calendarYear 	= calendarYear % 100;
	calendarYear 	= ((calendarYear < 50) ? (2000 + calendarYear) : (1900 + calendarYear));


	//Calculate the Blank entries before the 1st of the month
	blankEntry = calendarDate;

	while (blankEntry > 7) 
		blankEntry-= 7;

	blankEntry = calendarDay - blankEntry + 1;
	
	if (blankEntry < 0) 
		blankEntry+= 7;
	
	//Calculate Next Months Date
	nextMonth = (calendarMonth + 2);
	
	if (nextMonth == 13)
	{
		nextMonth = 1;
		nextYear = (calendarYear + 1);
	} 
	else
		nextYear = calendarYear;

	//*** Fix - TDS 2-06-2003 ***
	//nextDate = nextMonth + "/" + currentDate + "/" + nextYear;
	nextDate = nextMonth + "/1/" + nextYear;
	//*** End Fix - 2-06-2003 ***
	
	//Calculate Previous Months Date
	prevMonth = calendarMonth;
	
	if (prevMonth == 0)
	{
		prevMonth = 12;
		prevYear = (calendarYear - 1);
	} 
	else{
		prevYear = calendarYear;
	}
	prevDate = prevMonth + "/1/" + prevYear;

	//Build the Header for the Calendar
	CALENDAR_HTML = "<table id=\"tblCalendar\" class=\"tblCalendar\" border=0 cellpadding=0 cellspacing=0 dir='"+CALENDAR_DIR+"'>";
	CALENDAR_HTML += "<tr onmousedown=\"enableDrag()\" onmouseup=\"disableDrag()\" dir=\"rtl\"><td style='text-align:right;'";
	if(WEEK_NUMBER=="yes"){
	  CALENDAR_HTML += "colspan='8'";
	}else{
	  CALENDAR_HTML += "colspan='7'";
	}
    CALENDAR_HTML += " bgcolor='#454545' dir=\"rtl\"><a href='javascript:hideCalendar();'><font class=\"btnPrev\" style='color:#FFFFFF;line-height:15px;'>&nbsp;X&nbsp;</font></a></td></tr>";
	
	if(MONTH_SELECTION == "BUTTONS"){
      CALENDAR_HTML+='<tr bgcolor=' + MONTH_SELECT_BGCOLOR +'>';
	  
	  if(WEEK_NUMBER=="yes"){CALENDAR_HTML += "<td colspan=\"8\" align=\"center\">";}else{CALENDAR_HTML += "<td colspan=\"7\" align=\"center\">";}
	  
	  CALENDAR_HTML+='<table border=0 cellpadding=0 cellspacing=0 align=\"center\"><tr>';
	  if(ARROWS_FOR_SELECT=="yes"){
	    CALENDAR_HTML += "<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" onMouseOver=mOvr(this,'" + PNI_MOCOLOR + "') onMouseOut=mOut(this,'" + MONTH_BGCOLOR + "') onClick=chgCalendarDate('" + prevDate + "')><a href=javascript:chgCalendarDate('" + prevDate + "')><font class=\"btnPrev\"><<</font></a></td>";
	  }
	  CALENDAR_HTML+='<td><select name=\"noHide_years\" id=\"noHide_years\" class=\"selectHours\" onchange=\"callChgCalendarDate();isdrag = false;\"></select></td><td>&nbsp;&nbsp;</td>';
	  CALENDAR_HTML+='<td><select name=\"noHide_mounth\" id=\"noHide_mounth\" class=\"selectHours\" onchange=\"callChgCalendarDate();isdrag = false;\" ></select></td>';
	  if(ARROWS_FOR_SELECT=="yes"){
	    CALENDAR_HTML+="<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" onMouseOver=mOvr(this,'" + PNI_MOCOLOR + "') onMouseOut=mOut(this,'" + MONTH_BGCOLOR + "') onClick=chgCalendarDate('" + nextDate + "')><a href=javascript:chgCalendarDate('" + nextDate + "')><font class=\"btnNext\">>></font></a></td>";
	  }
	  CALENDAR_HTML+='</tr></table></td></tr>';
    }
	
	if(ARROWS_ROW_DISPLAY=="yes"){
		CALENDAR_HTML += "<tr>";
		CALENDAR_HTML += "<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" onMouseOver=mOvr(this,'" + PNI_MOCOLOR + "') onMouseOut=mOut(this,'" + MONTH_BGCOLOR + "') onClick=chgCalendarDate('" + prevDate + "')><a href=javascript:chgCalendarDate('" + prevDate + "')><font class=\"btnPrev\"><<</font></a></td>";
		if(WEEK_NUMBER=="yes"){
		   CALENDAR_HTML += "<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" colspan=6><font class=\"txtMonth\">" + monthNames[calendarMonth] + " " + calendarYear + "</font></td>";
		}else{
		   CALENDAR_HTML += "<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" colspan=5><font class=\"txtMonth\">" + monthNames[calendarMonth] + " " + calendarYear + "</font></td>";
		}
		CALENDAR_HTML += "<td bgcolor=" + MONTH_BGCOLOR + " align=center class=\"tdMonth\" onMouseOver=mOvr(this,'" + PNI_MOCOLOR + "') onMouseOut=mOut(this,'" + MONTH_BGCOLOR + "') onClick=chgCalendarDate('" + nextDate + "')><a href=javascript:chgCalendarDate('" + nextDate + "')><font class=\"btnNext\">>></font></a></td>";
		CALENDAR_HTML += "</tr>";
	}
	
	CALENDAR_HTML += "<tr>";
	if(WEEK_NUMBER=="yes"){CALENDAR_HTML += "<td bgcolor=" +  WEEK_NUM_HEAD_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"weekNuberHead\">"+ weekNuberHead +"</font></td>"}
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[0] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[1] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[2] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[3] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[4] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[5] +"</font></td>";
	CALENDAR_HTML += "<td bgcolor=" + WEEK_BGCOLOR + " align=center class=\"tdDayW\"><font class=\"txtDay\">"+ weekDaysArr[6] +"</font></td>";
	CALENDAR_HTML += "</tr>";
	CALENDAR_HTML += "<tr>";
	
	//Build a blank cell for each Blank Entry before the 1st of the Month
	for (s = 0;s < blankEntry;s++){
		if(WEEK_NUMBER=="yes" && s == 0){
		  tempWeekVal = getWeekNumber((calendarMonth+1) + "/" + 1 + "/" + calendarYear)
		  if(tempWeekVal!=52 && tempWeekVal!=1)tempWeekVal = tempWeekVal-1;
		  CALENDAR_HTML += "<td bgcolor=" + DAY_BLANK_BGCOLOR + " align=center class=\"tdWeekNum\"><font class=\"txtDay\">"+ tempWeekVal+ "</font></td>";
		  CALENDAR_HTML += "<td align=center class=\"tdDayBlank\"><font class=\"txtDay\">&nbsp;</font></td>";
		}else{
		  CALENDAR_HTML += "<td align=center class=\"tdDayBlank\"><font class=\"txtDay\">&nbsp;</font></td>";
		}
	}
	
	if(WEEK_NUMBER=="yes" && s == 0){
		  tempWeekVal = getWeekNumber((calendarMonth+1) + "/" + 1 + "/" + calendarYear)
		  if(tempWeekVal!=52 && tempWeekVal!=1)tempWeekVal = tempWeekVal-1;
		  CALENDAR_HTML += "<td bgcolor=" + DAY_BGCOLOR + " align=center class=\"tdWeekNum\"><font class=\"txtDay\">"+ tempWeekVal+ "</font></td>";
	}
	
	//Start the Day Counter
	dayCount = 1;
	
	getDateFromField();
	
	var dayEnabled;
	
	//Loop through until the total days of calendar month have been reached
	while (dayCount <= monthDays[calendarMonth]){
		//Start a new table row each time through the loop except the first time
		if (dayCount > 1){
			CALENDAR_HTML += "<tr>";
		}
		
		//Start at the next cell after the blank entries and entry the cells across the row.
		if(WEEK_NUMBER=="yes"){
          if(tempWeekFlag>0){
		    tempWeekVal = getWeekNumber((calendarMonth+1) + "/" + dayCount + "/" + calendarYear)
		    CALENDAR_HTML += "<td bgcolor=" + DAY_BGCOLOR + " align=center class=\"tdWeekNum\" id=\"weedkDayTd\"><font class=\"txtDay\">"+ tempWeekVal+ "</font></td>";
		  }
		  tempWeekFlag = 1;
		}
		for (b = blankEntry;b < 7;b++){
			//If the Day Counter is greater than the Month total then add blank entries
			  
			  //alert("currentYear = " currentYear)
			    //alert("calendarMonth = " + calendarMonth)
			if (dayCount <= monthDays[calendarMonth]){
				if(dayCount.toString().length<2){dayCount = "0"+dayCount};
				tempCalendarMonth = calendarMonth + 1;
				if(tempCalendarMonth.toString().length<2){tempCalendarMonth = "0"+tempCalendarMonth};
				
				dayEnabled = isDayEnabled(startDateObj, endDateObj, dayCount, tempCalendarMonth, calendarYear);
				
				if(dayEnabled){
					if(DATE_FORMAT=="dd/mm/yyyy"){
						tdProperties = "id="+dayCount+" onClick=chgDate('" + dayCount + "/" + (tempCalendarMonth) + "/" + calendarYear + "') ";
					    tdData = "<a href=javascript:chgDate('" + dayCount + "/" + (tempCalendarMonth) + "/" + calendarYear + "')>";
					}else{
					    tdProperties = "id="+dayCount+" onClick=chgDate('" + (tempCalendarMonth) + "/" + dayCount + "/" + calendarYear + "') ";
					    tdData = "<a href=javascript:chgDate('" + (tempCalendarMonth) + "/" + dayCount + "/" + calendarYear + "')>";
					}
				}
				else{
					tdData = "";
					tdProperties = " ";
				}
				
				//If the current day is equal to the calendar day and the
				//current month is equal to the calendar month, check the dates
				if ((currentDay == calendarDay) && (currentMonth == calendarMonth) && (currentYear == calendarYear)){
					//If the day counter is equal to the current date then change the color
					if (dayCount == currentDate){
						tdProperties = tdProperties + "class=\"tdToDay\"";
						currentDayStr = dayCount;
					}else{
						if ((dayCount == theDayStr) && (calendarMonth == parseInt(theMounthStr-1)) && (theYearhStr == calendarYear)){
							tdProperties = tdProperties + "class=\"tdFieldDay\"";
						}else{
							if(dayEnabled){
								tdProperties = tdProperties + " class=\"tdDay\" onMouseOver=\"mOvr(this,'" + DAY_MOCOLOR + "');\" onMouseOut=\"mOut(this,'" + DAY_BGCOLOR + "');\" ";
							}
							else{
								tdProperties = tdProperties + " class=\"tdDisabledDay\" ";
							}
						}
					}
				} 
				else{
				     //: if the date in the text field equal the calendar day and month
					 if ((dayCount == theDayStr) && (calendarMonth == parseInt(theMounthStr-1)) && (theYearhStr == calendarYear)){
						tdProperties = tdProperties + "class=\"tdFieldDay\"";
					 }else{
						if(dayEnabled){						 
							tdProperties = tdProperties + "class=\"tdDay\" onMouseOver=mOvr(this,'" + DAY_MOCOLOR + "') onMouseOut=mOut(this,'" + DAY_BGCOLOR + "')";
						}
						else{
							tdProperties = tdProperties + "class=\"tdDisabledDay\"";
						}
					 }
				}


				tdData += dayCount;
				if (dayEnabled){
					tdData += "</a>"
				}
			} 
			else{
				tdProperties = "class=\"tdDayBlank\"";
				tdData = "&nbsp;";
			}
		
			//Build the table cells
			CALENDAR_HTML += "<td " + tdProperties + ">" + tdData + "</td>";
		
			//Add to the Day counter
			dayCount++;
			currnetDayFlag = 0;
		}
	
		//End the table row
		CALENDAR_HTML += "</tr>";
		
		//Set the Blank entries to zero
		blankEntry=0;
	}

	//End the table
	CALENDAR_HTML += "<tr>";
	CALENDAR_HTML += "<td bgcolor=" + BOTTOM_ROW_COLOR + " colspan=4 class=\"tdMonth\" id=\"bottomRow\"></td>";
	if(WEEK_NUMBER=="yes"){CALENDAR_HTML += "<td colspan=4 class=\"tdMonth\" bgcolor=" + BOTTOM_ROW_COLOR + " id=\"bottomRowDate\"></td>";}
	else{CALENDAR_HTML += "<td colspan=3 class=\"tdMonth\" bgcolor=" + BOTTOM_ROW_COLOR + " id=\"bottomRowDate\"></td>";}
	CALENDAR_HTML += "</tr>";

	CALENDAR_HTML += "</table>";
	//CALENDAR_HTML += "<iframe id=DivShimCal src='' scrolling=no frameborder=0 style='position:absolute;z-index:5; width:5px; heigth:5px; top:0px; left:0px; display:none;'></iframe>";
}

//*** Fix - TDS 2-06-2003 ***
//This fuction checks for the Leap Year
function LeapYear(year){
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}
//*** End Fix - 2-06-2003 ***

//This function is used to control the mouse over event.
function mOvr(src,clrOver){ 
	if(src){
	  src.style.cursor = 'pointer'; 
	  src.style.backgroundColor = clrOver;
	}
}

//This function is used to control the mouse out event.
function mOut(src,clrIn){ 
	if(src){
	  src.style.cursor = 'default';
	  src.style.backgroundColor = clrIn;
	}
}

//HIDES AND SHOWS THE SELECTBOX / IFRAMES / FLASH IN THE PAGE
function showHideElements(state){
/*
   if (state==0)h='visible';
   else h='hidden';
	tag=document.getElementsByTagName('select');
	for(i=tag.length-1;i>=0;i--){
	  if(tag[i].id.indexOf('noHide')==-1){
	     tag[i].style.visibility=h;
	   }
	}
	tag=document.getElementsByTagName('iframe');
	for(i=tag.length-1;i>=0;i--){
	  if (tag[i].id!='noHide'){// IFRAME SRC
	    tag[i].style.visibility=h;
		}
	 }
	tag=document.getElementsByTagName('object');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
	*/
}

/*
function displayDivShim(state){
 var divShim = document.getElementById("DivShimCal");
 
 ////var theSentDiv = document.getElementById(theSentDivId);
 var theSentDiv = document.getElementById("tblCalendar");
 //document.getElementById(theSentDivId).style.zIndex = 10;
 //document.getElementById(theSentDivId).style.border = '1px solid green';
//alert(theSentDiv.offsetHeight)
//alert(theSentDiv.style.height)
//alert(theSentDiv.style.top)
//alert(theSentDiv.style.left)
 
  	  divShim.style.display= '';
	 // divShim.style.top =   objId4.style.top;
	 // divShim.style.right =   objId4.style.right;
	 //divShim.style.top = theSentDiv.offsetHeight -122;
	 
	 ///////divShim.style.width = theCalendarWidth;
	 ///////divShim.style.height = theCalendarHeight; 
	 
	 //divShim.style.left = theSentDiv.offsetWidth;
	 
	 divShim.style.border = '1px solid red';
}
*/

function fillMounth(){
	// fill the select
	if (CALENDAR_DIR=="ltr"){
	    monthNames = new Array("January","Februrary","March","April","May","June","July","August","September","October","November","Decemeber");
	}else{
	    monthNames = new Array("January","Februrary","March","April","May","June","July","August","September","October","November","Decemeber");
	}
	
	var mounthList = document.getElementById('noHide_mounth');
	var theValue,theText
	var optionToAdd,listLength 
	var listLength;
	
	 for(i=0;i<monthNames.length;i++){
	  listLength = mounthList.length;
	  theValue = i;
	  theText = monthNames[i];
	  optionToAdd = new Option(theText,theValue);
	  mounthList.options[listLength] = optionToAdd;
	}
	
	if (DISPLAY_DATE == ""){
		calendarDateObj	= new Date();
	}else{
		calendarDateObj = new Date(DISPLAY_DATE);
	}
	///alert(calendarDateObj)
	calendarMonth = calendarDateObj.getMonth();
	mounthList.options[calendarMonth].selected = true;
}

function fillYears(){
	// fill the years select
	monthDays = new Array(12);
	
	//Entry the Total Days for each Month
	monthDays[0]	= 31;
	monthDays[1]	= 28;
	monthDays[2]	= 31;
	monthDays[3]	= 30;
	monthDays[4]	= 31;
	monthDays[5]	= 30;
	monthDays[6]	= 31;
	monthDays[7]	= 31;
	monthDays[8]	= 30;
	monthDays[9]	= 31;
	monthDays[10]	= 30;
	monthDays[11]	= 31;

	
	if (DISPLAY_DATE == ""){
		calendarDateObj	= new Date();
	}else{
		calendarDateObj = new Date(DISPLAY_DATE);
	}
	
	 calendarYear	= calendarDateObj.getYear();
	  if (LeapYear(calendarYear))
		monthDays[1] = 29;
	 calendarYear 	= calendarYear % 100;
	 calendarYear 	= ((calendarYear < 50) ? (2000 + calendarYear) : (1900 + calendarYear));
	 

	var yearsList = document.getElementById('noHide_years');
	var theValue,theText
	var optionToAdd,listLength 
	var listLength;
	
	for(i=0;i<YEARS_TO_DISPLAY;i++){
	  listLength = yearsList.length;
	  theValue = parseInt(YEAR_TO_START) + parseInt(i);
	  theText = parseInt(YEAR_TO_START) + parseInt(i);
	  optionToAdd = new Option(theText,theValue);
	  yearsList.options[listLength] = optionToAdd;
	  if(theValue == calendarYear)yearsList.options[i].selected = true;
	}
}

function houersSelect(){
   strBottmRow = strBottmRow + "<table cellpadding=\"0\" cellspacing=\"0\" dir=\"ltr\"><tr><td><button onclick=\"hoursMinutesToField();\" style=\"height:16px;font-size:10px;line-height:10px;\">"+submitValue+"</button>&nbsp;</td><td><select name=\"noHide_hourSelect\" id=\"noHide_hourSelect\" class=\"selectHours\" onclick=\"isdrag = false;\" onchange=\"hoursMinutesToField()\"></select></td><td>:</td><td><select name=\"noHide_minuteSelect\" id=\"noHide_minuteSelect\" class=\"selectHours\" onclick=\"isdrag = false;\" onchange=\"hoursMinutesToField()\"></select></td></tr></table>"
   document.getElementById('bottomRow').innerHTML = strBottmRow;
   
   var theHoursSelect = document.getElementById('noHide_hourSelect');
   var theValue,theText
   var optionToAdd,listLength,theNum;
   var theFormat;
   if (HOUERS_FORMAT==24){theFormat=24;}else{theFormat=12;}
   
   for(i=0;i<theFormat;i++){
     listLength = theHoursSelect.length;
	 if (i<10){theNum = "0"+i}else{theNum=i};
	 theValue = theNum
	 theText = theNum;
	 optionToAdd = new Option(theText,theValue);
	 theHoursSelect.options[listLength] = optionToAdd;
   } 
}

function minutesSelect(){
   var theMinutesSelect = document.getElementById('noHide_minuteSelect');
   var theValue,theText;
   var optionToAdd,listLength,theNum;
   var theFormat;
   if (HOUERS_FORMAT==24){theFormat=24;}else{theFormat=12;}
   
   for(i=0;i<=50;i=i+10){
   
    listLength = theMinutesSelect.length;
	
	 if (i<10){theNum = "0"+i}else{theNum=i};
	 theValue = theNum;
	 theText = theNum;
	 optionToAdd = new Option(theText,theValue);
	 theMinutesSelect.options[listLength] = optionToAdd;
   } 
}

    var monthNames = new Array(
	"1","2","3","4","5","6","7",
	"8","9","10","11","12");
    var now = new Date();
	var theYear = now.getFullYear();
	var theMonth = monthNames[now.getMonth()]
	var theDay = now.getDate();

function drawTodayDate(){
	theYear = theYear.toString();
	theMonth = theMonth.toString();
	theDay = theDay.toString();

	var theYearArr = new Array();
	var theMonthArr = new Array();
	var theDayArr = new Array();
	
	var strDate = "";
	
	if(CALENDAR_DIR == "ltr"){
	  strDate = "Today is " + theDay+"/"+theMonth+"/"+theYear;
	}else{
	  strDate = "Today is " + theDay+"/"+theMonth+"/"+theYear;
	}

	document.getElementById('bottomRowDate').innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"txtDay\">" + strDate + "</td></tr></table>";
	
}

//to select the  hours value form the field in the select
function updateHours(){
  var theHoursSelect = document.getElementById('noHide_hourSelect');
   hoursValue = CURRENT_DATE_FIELD_ID.value.substring(11,13);	 
  for(i=0;i<theHoursSelect.length;i++){
       if(theHoursSelect.options[i].value.toString() == hoursValue.toString())theHoursSelect.options[i].selected = true;
	}
}


function updateMinutes(){
  var theMinutesSelect = document.getElementById('noHide_minuteSelect');
   minutesValue = CURRENT_DATE_FIELD_ID.value.substring(14,16);
  for(i=0;i<theMinutesSelect.length;i++){
       if(theMinutesSelect.options[i].value.toString() == minutesValue.toString())theMinutesSelect.options[i].selected = true;
	}
}


//send the hours and minutes to the text field when select box is changed
function hoursMinutesToField(){
   if(theDateStr.length<6){
      if(DATE_FORMAT=="dd/mm/yyyy"){
	    theDateStr = currentDayStr+"/"+theMonth+"/"+theYear;
	  }else{
	    theDateStr = currentDayStr+"/"+theDay+"/"+theYear;
	  }
  }
   
   document.forms[CURRENT_FORM][CURRENT_DATE_FIELD].value = "";
   
   if(CURRENT_DATE_FIELD_ID.value.length>6 || CURRENT_DATE_FIELD_ID.value.length == 0 ){
	  theHours = " " + document.getElementById('noHide_hourSelect').value;
	  theHours = theHours + ":"  + document.getElementById('noHide_minuteSelect').value;
	 //Change the Date field
	  document.forms[CURRENT_FORM][CURRENT_DATE_FIELD].value = theDateStr + theHours;
	} 
}


//when called updates the global vars with the current field values
function getDateFromField(){
    theDateStr = CURRENT_DATE_FIELD_ID.value.substring(0,10);
	if(DATE_FORMAT=="dd/mm/yyyy"){
	  theDayStr = theDateStr.substring(0,2);
	  theMounthStr = theDateStr.substring(3,5);
	 }else{
	  theDayStr = theDateStr.substring(3,5);
	  theMounthStr = theDateStr.substring(0,2);
	 }
	 theYearhStr =  parseInt(theDateStr.substring(6,10))
}

function getCalendarSize(){
  if(IE4){
		if(theShim!=null){
		    var theCalendar = document.getElementById(CALENDAR_DIV_NAME);
			var divShim = document.getElementById("DivShimCal")
			divShim.style.width = (theCalendar.offsetWidth) + "px";
			divShim.style.height = (theCalendar.offsetHeight) + "px";
			//divShim.style.top="-"+(theCalendar.offsetHeight) + "px";//TODO
		 }
  }
}

function enableDrag(){
  selectOpen=0;
}

function disableDrag(){
  selectOpen=1;
}

function selectClicked(){
  if(selectOpen ==1 )selectOpen=0;
  else selectOpen = 1;
}

/////////////    WEEK NUMBER FUNCTIONS  /////////////////////////////
function getWeekNumber(theDay) {
	var tempD = new Date(theDay);
	var d = new Date(tempD.getFullYear(), tempD.getMonth(), tempD.getDate(), 0, 0, 0);
	var DoW = d.getDay();
	 d.setDate(d.getDate() - (DoW + 6) % 7 + 3);
	 var ms = d.valueOf();
	 d.setMonth(0);
	 d.setDate(4);
	 var theReturndValue = Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
	 return theReturndValue;
	
        /* var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
         var DoW = d.getDay();
         d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
        var ms = d.valueOf(); // GMT
         d.setMonth(0);
        d.setDate(4); // Thu in Week 1
         return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;*/
}


/////////////    WEEK NUMBER FUNCTIONS  /////////////////////////////


/////////////////////////////  START MENU FUNCTIONS ////////////////////////////////////////
var m_CurrentPopup;
var theShim;
var LeftPos,topPos
////var menuwidth;
////menuwidth = CALENDAR_WIDTH;

var Xoff;
Xoff=3;

function popupHide(e,leftP,topP){
	//evt = e || window.event;
	var desElement;
	var srcElement;
		
	LeftPos = leftP;
	topPos = topP;
	
	if(typeof(m_CurrentPopup) != "undefined"){
	 /*   if (window.event != null)
		{	
			srcElement = e.srcElement;
			desElement = event.toElement
			
		}
		else
		{
			srcElement = e.target;
			desElement = e.relatedTarget;	
		}
		
		if(desElement==null)
		{
			m_CurrentPopup.style.display = 'none';
			return;
		}	
	  
		// ((srcElement.id.indexOf('topMenuTD_')>0) && (desElement.id.indexOf('topMenuPopup_') >0 ))
		  //  return;	
	
	
		p = desElement;
	
	    	while( p != null)
	    	{
	
			if (p.id == m_CurrentPopup.id)
				return;
	
	        	p = p.offsetParent
	    	} 
	
	
		if (m_CurrentPopup == null)
			return;*/
		
		m_CurrentPopup.style.display = 'none';
	  }
	 if(theShim!=null){
	     theShim.style.display = 'none'; // - hide the empty background frame
	 }
}

function popupShow(srcObj,leftP,topP){
	LeftPos = leftP;
	topPos = topP;
	
	var topTD = srcObj; //.offsetParent;
	/*var theObjHeight =  document.getElementById(srcObj.id);
	theObjHeight = theObjHeight.id;
	theObjHeight = theObjHeight.style.height;
	alert(theObjHeight)*/
	//var popTable = topTD.id.replace('b_','menu_');
	
	popTable = document.getElementById('theCalendarWrapDIv');
	theObjHeight = document.getElementById(popTable.id);
	
	if (popTable == null)
		return
	
	if (m_CurrentPopup != null)
		m_CurrentPopup.style.display = 'none'	
	
	var left=0;
    var top = 0;
	var p = topTD
    	while( p != null)
    	{
        	left += p.offsetLeft
        	top += p.offsetTop
        	p = p.offsetParent
    	} 
    
		m_CurrentPopup = popTable;
    	m_CurrentPopup.style.top = ((0) + top + topTD.offsetHeight -parseInt(topPos)) +'px';
    	m_CurrentPopup.style.left = (left + parseInt(LeftPos)) + 'px';
    	m_CurrentPopup.style.display = '';
		m_CurrentPopup.style.zIndex = '1000';
    	m_CurrentPopup.style.position = 'absolute';
		
	
	
	  theShim = document.getElementById("DivShimCal");
	  dropmenuobj = popTable;
      dropmenuobj.x=getposOffset(srcObj, "left")
	  dropmenuobj.y=getposOffset(srcObj, "top")
	
	
	// - THE EMPTY BACKGROUND FRAME FPR SELECT BOX COVER
	  /*
	 if(IE4){
		if(theShim!=null){
		theShim.style.top = (dropmenuobj.y)+"px";
		theShim.style.display = '';
		////theShim.style.width = eval(menuwidth.substring(0,menuwidth.lastIndexOf("px")))+14;
		////theShim.style.height= (menuNum.length)*17+'px';
	    ////theShim.style.height = eval(CALENDAR_HEIGHT.substring(0,CALENDAR_HEIGHT.lastIndexOf("px")));
	    
		theShim.style.left = dropmenuobj.x-Xoff-clearbrowseredge(srcObj, "rightedge")+LeftPos - 4+"px"
		theShim.style.top=(dropmenuobj.y)-clearbrowseredge(srcObj, "bottomedge")+srcObj.offsetHeight-topPos+"px"
		}
	}
	*/
}
/////////////////////////////  END MENU FUNCTIONS ////////////////////////////////////////

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
	
	
function clearbrowseredge(obj, whichedge){
	var edgeoffset=-7
	if (whichedge=="rightedge"){
		var windowedge = window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var windowedge=window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}
	
	

////////////////   DRAG AND DROP /////////////////////
var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e){
  if (isdrag && selectOpen==0) {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
	
	// - MOVE SHIM
    /*
	var theShim = document.getElementById("DivShimCal");
	theShim.style.left = dobj.style.left; 
	theShim.style.top = dobj.style.top;
	*/
    return false;
  }
}

function selectmouse(e){
	var fobj       = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";
	try{
		while (fobj.tagName != topelement && fobj.className != "dragme"){
			fobj = nn6 ? fobj.parentNode : fobj.parentElement;
		}
		if (fobj.className=="dragme"){
			isdrag = true;
			dobj = fobj;
			tx = parseInt(dobj.style.left+0);
			ty = parseInt(dobj.style.top+0);
			x = nn6 ? e.clientX : event.clientX;
			y = nn6 ? e.clientY : event.clientY;
			document.onmousemove=movemouse;
			// - MOVE SHIM
			/*var theShim = document.getElementById("DivShimCal");
			window.status = dobj.x*/
			
			return false;
		}
	}catch(e){}
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
////////////////   DRAG AND DROP /////////////////////


function formatDate(dateString, dateFormat){
	var resDateObj = null;
	var dayStr = '';
	if (typeof(dateString) == 'string' && dateString.length == 10){
		if(dateFormat=="dd/mm/yyyy"){
			dayStr = dateString.substring(0,2);
			if (dayStr == '08')
				dayStr = '8';
			else if (dayStr == '09')
				dayStr = '9';
			theDayStr = parseInt(dayStr);
			theMounthStr = dateString.substring(3,5);
		}else{
		    theDayStr = parseInt(dateString.substring(3,5));
			theMounthStr = dateString.substring(0,2);
		}
		if(theMounthStr.substring(0,0)==0)theMounthStr = theMounthStr *1
		theYearhStr = parseInt(dateString.substring(6,10));
		resDateObj = new Date();
		resDateObj.setDate(theDayStr)
		resDateObj.setMonth(theMounthStr-1)
		resDateObj.setFullYear(theYearhStr)
	}
	return resDateObj
}

/**
* Return true if (day, month, year) is between start end date
* If there is no start and/or end date, it is +/- infinity
*/
function isDayEnabled(startDate, endDate, day, month, year){

//alert (day + ' month = ' + month + ' year = '+ year);
	var res = false;
	var startOk = false;
	var endOk = false;

	if(startDate == null){
		startOk = true;
	}
	else{
		if(year > startDate.getFullYear()){
			startOk = true;
		}
		else{
			if(year == startDate.getFullYear() && month > startDate.getMonth()+1){
				startOk = true;
			}
			else{
				if(year == startDate.getFullYear() && month == startDate.getMonth()+1){
					if(day >= startDate.getDate()){
						startOk = true;
					}
				}
			}
		}
	}
	
	if(endDate == null){
		endOk = true;
	}
	else{
		if(year < endDate.getFullYear()){
			endOk = true;
		}
		else{
			if(year == endDate.getFullYear() && month < ((endDate.getMonth()*1)+1)){
				endOk = true;
			}
			else{
				if(year == endDate.getFullYear() && month == endDate.getMonth()+1){
					if(day <= endDate.getDate()){
						endOk = true;
					}
				}
			}
		}
	}

	//alert(';endD='+ endDate.getDate()+'/'+((endDate.getMonth()*1)+1)+'/'+endDate.getFullYear()+'; orgD='+day+'/'+month+'/'+year+'; startOk='+startOk+'; endOk='+endOk);
	//alert('stD='+startDate+'; endD='+endDate+'; orgD='+day+'/'+month+'/'+year+'; startOk='+startOk+'; endOk='+endOk);
	
	return endOk && startOk;
	return true;
}
