//<script language="javascript">
if(typeof(PageDirection)=="undefined")PageDirection='ltr';
if(typeof(Co_Cal_Translations)=="undefined"){Co_Cal_Translations={NextMonth:'Next Month',NextYear:'Next Year',PrevMonth:'Previous Month',PrevYear:'Previous Year'};}
var calendar_header = "<TABLE width=\"<CALENDAR_WIDTH>\" id=\"datePickerTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			"<tr>\n"+"<TD height=\"24\" ALIGN=\"center\">\n"+
			"<TABLE width=\"100%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			"<TR class=\"caldaynames\"<HEADER_ROW_BACKGROUND>>\n<HEAD_PREV_YEAR_LINK>\n"+"<HEAD_PREV_MONTH_LINK>\n"+"	<HEAD_CUR_DATE>\n"+"	<HEAD_NEXT_MONTH_LINK>\n"+"<HEAD_NEXT_YEAR_LINK>\n</tr>\n";
PageDirection=(PageDirection||"ltr").toLowerCase();var string_left=(PageDirection=="rtl"?"right":"left");var string_right=(PageDirection=="rtl"?"left":"right");var prefix_left=(PageDirection=="rtl"?"r":"l");var prefix_right=(PageDirection=="rtl"?"l":"r");
String.prototype.Replace = function(o, n) { return this.split(o).join(n); }

/*
/// New Calendar Functionality, allow for multiple calendars and interaction between them.
var __DEFAULT__=0;
function Calendar() {
	this.isCalShowing=false;this.current=__DEFAULT__;
	this.gDay=this.nDay=this.gMonth=this.nMonth=this.gYear=this.nYear=new Number(-1);
	this.targetElement='';this.form=(targetForm!=''?document.forms[targetForm]:'');this.globalSetHebDate=null;
	this.loaded=false;this.useDropLists=true;this.enList='';this.heList='';this.g_target='';
	this.view='day';
	this.load=load_calendar;
	this.show=display_calendar;
	this.show_calendar=show_calendar;this.show_heb_calendar=show_heb_calendar;this.show_heb_cal_w_e_dates=showHebCal;this.showMonth_Calendar=showMonth_Calendar;
}

function load_calendar() {
		
}
*/

var targetElement='',targetForm='',isCalShowing=false,whichCalShowing='';
var gDay=nDay=gMonth=nMonth=gYear=nYear=new Number(-1);
var globalSetHebDate,loaded=false,useDropLists=true,enList='',heList='',g_target='';
var picker_elm='datePicker',cal_append_mode=false;

function show_calendar(str_datetime, act, curView) {

  if (!isCalShowing || act != null || (g_target != targetElement && (g_target)) || whichCalShowing != 0||!IsPopup()){
  	if (!act){
		  if (g_target.indexOf('/') == -1){
			  if (document.forms[targetForm][g_target].value != ""){
					str_datetime = document.forms[targetForm][g_target].value
			  }
		  }
		}
		targetElement = g_target;
		whichCalShowing = 0;
		
		var n_weekstart = 0; // day week starts from (normally 0 or 1)
	
		var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));
		var dt_prev_month = new Date(dt_datetime);
			dt_prev_month.setMonth(dt_datetime.getMonth()-1);
		var dt_next_month = new Date(dt_datetime);
			dt_next_month.setMonth(dt_datetime.getMonth()+1);
		var dt_firstday = new Date(dt_datetime);
			dt_firstday.setDate(1);
			dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
		var dt_lastday = new Date(dt_next_month);
			dt_lastday.setDate(0);
		var today = new Date()
		
		// html generation (feel free to tune it for your particular application)
		// print calendar header
		var str_buffer = calendar_header.Replace("<HEAD_PREV_MONTH_LINK>", "<a href=\"javascript:void(0);\" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"show_calendar('"+ jsDate(dt_prev_month)+"','prev','" + curView + "');\">&"+prefix_left+"aquo;</a>");
		str_buffer = str_buffer.Replace("<HEAD_PREV_YEAR_LINK>", "");str_buffer = str_buffer.Replace("<HEAD_NEXT_YEAR_LINK>", "");str_buffer = str_buffer.Replace("<HEAD_NEXT_MONTH_LINK>", "<a href=\"javascript:void(0);\" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"show_calendar('"+jsDate(dt_next_month)+"','next','" + curView + "');\">&"+prefix_right+"aquo;</a>");

		str_buffer = str_buffer.Replace("<HEAD_CUR_DATE>", "<A>"+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</A>");
		str_buffer=str_buffer.Replace("<CALENDAR_WIDTH>", calendar_width());
		
		if (IsPopup()) str_buffer=str_buffer.Replace('<HEADER_ROW_BACKGROUND>',' style=\"background-image:url(\'/images/calendar/calbgbt.jpg\')\"'); else str_buffer=str_buffer.Replace('<HEADER_ROW_BACKGROUND>','');
		
		str_buffer += "<TR><TD ALIGN=\"center\" VALIGN=\"top\" NOWRAP colspan=\"7\">"
		str_buffer += "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"offWhtBg\" width=\"100%\">"
		
		var dt_current_day = new Date(dt_firstday);
		// print weekdays titles
		str_buffer += "<tr HEIGHT=\"15\" ALIGN=\"center\" class=\"monthDayWeek\">\n";
		for (var n=0; n<7; n++){
			str_buffer += "	<TD class=\"leftBarBg\">"+week_days[(n_weekstart+n)%7]+"</td>\n";
		}
		// print calendar table
		str_buffer += "</tr>\n";
		while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
			dt_current_day.getMonth() == dt_firstday.getMonth()) {
			// print row heder
			str_buffer += "<tr HEIGHT=\"18\" class=\"small_calendar\""
			if(curView == 'week'){
				str_buffer += " onmouseover=\"doHighlight(this,'selected','class');\" onmouseout=\"doHighlight(this,'default','class');\""
			}
				str_buffer += ">\n";
				
			for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getMonth() != dt_datetime.getMonth()){
					// print dates not in current month
					str_buffer += "<TD class=\"disabled\" ALIGN=\"center\">"
				}
				else if (dt_current_day.getDate() == dt_datetime.getDate() && dt_current_day.getMonth() == dt_datetime.getMonth() && dt_current_day.getFullYear() == dt_datetime.getFullYear() && curView == "add"){
					// print selected date
					str_buffer += "<TD ALIGN=\"center\" class=\"selected\" onclick=\"selectDate('"+jsDate(dt_current_day)+"');return false;\">"
				}
				else if (dt_current_day.getDate() == today.getDate() && dt_current_day.getMonth() == today.getMonth()){
					// print current date
					str_buffer += "<TD ALIGN=\"center\" class=\"today\" style=\"cursor:pointer\" onMouseOver=\"this.className='selected'\" onMouseOut=\"this.className='today'\" onclick=\"selectDate('"+jsDate(dt_current_day)+"','" + curView + "');return false;\">"
				}
				else if (dt_current_day.getDay() == 6){
					// weekend days
					str_buffer += "<TD ALIGN=\"center\" class=\"weekend\" style=\"cursor:pointer\" onMouseOver=\"this.className='selected'\" onMouseOut=\"this.className='weekend'\" onclick=\"selectDate('"+jsDate(dt_current_day)+"','" + curView + "');return false;\">"
				}
				else{
					// print working days of current month
					str_buffer += "<TD ALIGN=\"center\" class=\"default\" onMouseOver=\"this.className='selected'\" onMouseOut=\"this.className='default'\" style=\"cursor:pointer\" onclick=\"selectDate('"+jsDate(dt_current_day)+"','" + curView + "');return false;\">"
				}
				
				str_buffer += "<a href=\"#\" onclick=\"selectDate('"+jsDate(dt_current_day)+"','" + curView + "');return false;\">"
				str_buffer += dt_current_day.getDate()+"</a></TD>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
			}
			// print row footer
			str_buffer += "</tr>\n";
		}
		
		if (IsPopup()) str_buffer += "<TR height=\"18\"><TD colspan=\"7\" align=\"center\"><A href=\"javascript:show_calendar();\" class=\"calClose\">"+CLOSE+"</A></TD></TR>";
		
		str_buffer+="</TABLE></TD></TR>" +
			"</table>\n" +
			"</td>\n</tr>\n</table>\n";
	
		if (IsPopup()) isCalShowing = true;
		display_calendar(str_buffer, true);
	}
	else{
		isCalShowing = false;
		display_calendar(null, false);
	}
}

function showHebCalendar(cMonth, cYear, act){
  if (!isCalShowing||act!=null||(g_target!=targetElement&&(g_target))||whichCalShowing!=1||!IsPopup()){
  	if (!act){
		  if (g_target.indexOf('/')==-1){
			  if (document.forms[targetForm][g_target].value!=""){
					str_datetime=document.forms[targetForm][g_target].value;
					if (isDate(str_datetime)){
						if (str_datetime != null){ cMonth=getDatePart(str_datetime,'m'); cYear=getDatePart(str_datetime,'y'); }
					}
			  }
		  }
		}

	if (cMonth==0){ cMonth=12;cYear--; } //else{ cMonth--; }

	targetElement=g_target;whichCalShowing=1;

	var parms = calendar(new Number(cMonth),new Number(cYear));
	var today=new Date(),hebDate,hebDay;
	var cMonth=nMonth=new Number(parms[3]),cYear=nYear=new Number(parms[4]);
	var monthName=civMonth[cMonth],lastDate=civMonthLength(cMonth, cYear),hm,hMonth;

	hebDate=hebrewCalendar(1,cMonth,cYear);gDay=hebDate[0];gMonth=hebDate[1];gYear=hebDate[2];
	if(gMonth == 0 || gMonth == 14) gMonth = (MonthsInHebYear(gYear));
	
	var result = calendar_header.Replace("<HEAD_PREV_YEAR_LINK>", "<TD height=\"24\" width=\"15\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"left\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCalendar('"+cMonth+"','"+ (new Number(cYear)-1) +"', 'prev');\" title=\""+Co_Cal_Translations.PrevYear+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_left+"2.gif\" width=\"7\" height=\"6\" alt=\""+Co_Cal_Translations.PrevYear+"\" border=\"0\"></td>");
	result = result.Replace("<HEAD_PREV_MONTH_LINK>", "<TD height=\"24\" width=\"10\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"center\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCalendar( '"+prevMonth(new Number(cMonth), cYear)+"', 'prev');\" title=\""+Co_Cal_Translations.PrevMonth+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_left+".gif\" width=\"3\" height=\"6\" alt=\""+Co_Cal_Translations.PrevMonth+"\" border=\"0\"></td>");
	result = result.Replace("<HEAD_CUR_DATE>", "<TD height=\"24\" class=\"h3\" width=\"65%\" ALIGN=\"center\""+(IsPopup()?" class=\"center\"":"")+" style=\"cursor:default;\"><b>"+date_select_headers(cMonth,cYear,false) + "</b></td>");
	result=result.Replace("<CALENDAR_WIDTH>", calendar_width());
	result = result.Replace("<HEAD_NEXT_MONTH_LINK>", "<TD height=\"24\" width=\"10\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"center\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCalendar('"+nextMonth(new Number(cMonth), cYear)+"','next');\" title=\""+Co_Cal_Translations.NextMonth+"\"><img src=\"/images/tools/calendar/cmd_"+string_right+".gif\" width=\"3\" height=\"6\" alt=\""+Co_Cal_Translations.NextMonth+"\" border=\"0\">&nbsp;</td>");
	result = result.Replace("<HEAD_NEXT_YEAR_LINK>", "<TD height=\"24\" width=\"15\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"right\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCalendar('"+cMonth+"','"+ (new Number(cYear)+1) +"','next');\" title=\""+Co_Cal_Translations.NextYear+"\"><img src=\"/images/tools/calendar/cmd_"+string_right+"2.gif\" width=\"7\" height=\"6\" alt=\""+Co_Cal_Translations.NextYear+"\" border=\"0\">&nbsp;</td>");
	
	if (IsPopup()) result=result.Replace('<HEADER_ROW_BACKGROUND>',' style=\"background-image:url(\'/images/calendar/calbgbt.jpg\')\"'); else result=result.Replace('<HEADER_ROW_BACKGROUND>','');

	result += "<TR><TD ALIGN=\"center\" VALIGN=\"top\" NOWRAP colspan=\"7\">"
	result += "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"offWhtBg\" width=\"100%\">"
		
	result += "<tr HEIGHT=\"15\" ALIGN=\"center\" class=\"monthDayWeek\">\n";
	for (var n=1; n<8; n++) result += "	<TD class=\"leftBarBg\">"+weekDay[n]+"</td>\n";
		result += '</TR>';
    var cell = 1
    var cDay = 1
    var row;
		for (row = 1; row <= 6; row++) {
			result += "<tr HEIGHT=\"18\" class=\"small_calendar\">\n";
			for (col = 1; col <= 7; col++)  {
				// convert civil date to hebrew
				hebDate = hebrewCalendar(cDay, cMonth, cYear, true);
				var moed = moadim(cDay, cMonth, cYear, hebDate[0], new Number(hebDate[1]), col, hebDate[2]);
		    if (cell < parms[1]){
					result += '<TD width=\"24\" class=\"disabled\" ALIGN=\"center\"></TD>';
				}
				else if (cDay > lastDate){
					result += '<TD width=\"24\" class=\"disabled\" ALIGN=\"center\"></TD>';
				}
        else {
					if ((new Date(cYear , cMonth-1, cDay).getDay() == 6) || moed != ""){
						result += "<TD ALIGN=\"center\" width=\"24\" height=\"18\" class=\"" + (today.getMonth()+1 == cMonth && today.getDate() == cDay && today.getFullYear() == cYear ? "today" : "weekend" ) + "\" style=\"cursor:pointer\" onMouseOver=\"this.oldClass=this.className;this.className='selected'\" onMouseOut =\"this.className=this.oldClass;\" onclick=\"selectDate('" + cMonth + "/" + cDay + "/" + cYear + "','"+formatHebDate(hebDate[0],hebDate[1],hebDate[2]).Replace('\'', '\\\'')+"');return false;\" title=\""+formatHebDate(hebDate[0],hebDate[1],hebDate[2])+ (moed != "" ? " - " + moed : "") + "\">"
					}
					else{
						result += "<TD ALIGN=\"center\" width=\"24\" class=\"" + (today.getMonth()+1 == cMonth && today.getDate() == cDay && today.getFullYear() == cYear ? "today" : "default" ) + "\" style=\"cursor:pointer\" onMouseOver=\"this.oldClass=this.className;this.className='selected'\" onMouseOut =\"this.className=this.oldClass;\" onclick=\"selectDate('" + cMonth + "/" + cDay + "/" + cYear + "','"+formatHebDate(hebDate[0],hebDate[1],hebDate[2]).Replace('\'', '\\\'')+"');return false;\" title=\""+formatHebDate(hebDate[0],hebDate[1],hebDate[2])+ (moed != "" ? " - " + moed : "") +"\">";
					}
					// assemble the contents of our day cell
					result+=cDay;result+="</TD>";
	        cDay++
				}

				if (cDay <= lastDate || (col < 7))
					cell++;
      	else
					break;
			}
      result += '</TR>'
      if(cDay > parms[2])
			break;
    }
		result += "<TR height=\"18\"><TD colspan=\"2\" align=\"left\" style=\"border-right:0px;\"><A href=\"javascript:void(0);\" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCal('" + act + "');\"><IMG src=\"/images/calendar/cal_english.gif\" width=\"28\" height=\"12\" alt=\"Jewish Calendar\" border=\"0\"></A></TD><TD colspan=\"3\" align=\"center\" style=\"border-right:0px;border-left:0px;\"><a href=\"#\" onclick=\"selectDate('" + (new Number(today.getMonth())+1) + "/" + today.getDate() + "/" + today.getFullYear() + "','"+formatHebDate(today.getDate() , (today.getMonth()-1) , today.getFullYear()).Replace('\'', '\\\'')+"');return false;\">"+TODAY+"</a></TD><TD colspan=\"2\" align=\"right\" style=\"border-right:0px;border-left:0px;\">"+(IsPopup()? "<A href=\"javascript:showHebCalendar();\" class=\"calClose\">"+CLOSE+"</A>":"") +"&nbsp;</TD></TR></TABLE></TD></TR>" +
			"</table>\n" +
			"</td>\n</tr>\n</table>\n";
			
		if (IsPopup()) isCalShowing = true;
		display_calendar(result, true);
	}
	else{
		isCalShowing = false;
		display_calendar(null, false);
	}
}

/* Hebrew Calendar with English date Subtitles */
function showHebCal(act){
  if (!isCalShowing || act != null || (g_target != targetElement && (g_target)) || whichCalShowing != 2||!IsPopup()){
  	if (!act){
	  if (g_target.indexOf('/') == -1){
		  if (document.forms[targetForm][g_target].value != ""){
			str_datetime = document.forms[targetForm][g_target].value
			if (isDate(str_datetime)){
				if (str_datetime != null){
					cDay = new Number(getDatePart(str_datetime,'d'))
					cMonth = new Number(getDatePart(str_datetime,'m'))
					cYear = new Number(getDatePart(str_datetime,'y'))
					
					hebDate = hebrewCalendar(cDay,cMonth,cYear);
					gDay = hebDate[0];gMonth = hebDate[1];gYear = hebDate[2];
					
					//moveDate(+1,'m');
					if (gMonth > 12){
						gMonth--;
					}
				}
			}
		  }
	  }
	}
	targetElement = g_target;whichCalShowing = 2;

	var today = new Date();
	var cDay = gDay;
	var cMonth = gMonth;
	var cYear = gYear;
	
	var hebDate = cDay + ' ' + cMonth + ' ' + cYear;

	var startDate = abs2greg(heb2Abs(cDay,parseInt(cMonth),parseInt(cYear)))
	var startDay = abs2greg(heb2Abs(1,cMonth,parseInt(cYear))).getDay()
	startDay++;

	var hMonthLength = DaysInHebMonth(cMonth,parseInt(cYear));
	
	var hMonth = (cMonth > 11 && HebLeapYear(parseInt(cYear)) ? parseInt(cMonth)+1 : cMonth)
	if (hMonth == 13 && !HebLeapYear(parseInt(cYear))){
		gMonth--;
		hMonth--;
	}
	
	var result = calendar_header.Replace("<HEAD_PREV_YEAR_LINK>", "<TD height=\"24\" width=\"15\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"left\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"moveDate(-1,'y');showHebCal('prevYear');\" title=\""+Co_Cal_Translations.PrevYear+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_left+"2.gif\" width=\"7\" height=\"6\" alt=\""+Co_Cal_Translations.PrevYear+"\" border=\"0\"></td>");
		result = result.Replace("<HEAD_PREV_MONTH_LINK>", "<TD height=\"24\" width=\"10\" style=\"cursor:pointer;\"ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"center\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"moveDate(-1,'m');showHebCal('prev');\" title=\""+Co_Cal_Translations.PrevMonth+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_left+".gif\" width=\"3\" height=\"6\" alt=\""+Co_Cal_Translations.PrevMonth+"\" border=\"0\"></td>");
	
		result = result.Replace("<HEAD_CUR_DATE>", "<TD height=\"24\" width=\"70%\" class=\"h3\" ALIGN=\"center\""+(IsPopup()?" class=\"center\"":"")+" style=\"cursor:default;\"><b>"+date_select_headers(hMonth,cYear,true)+"</b></td>");
		result=result.Replace("<CALENDAR_WIDTH>", calendar_width());
	
		result = result.Replace("<HEAD_NEXT_MONTH_LINK>", "<TD height=\"24\" width=\"10\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"center\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"moveDate(+1,'m');showHebCal('next');\" title=\""+Co_Cal_Translations.NextMonth+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_right+".gif\" width=\"3\" height=\"6\" alt=\""+Co_Cal_Translations.NextMonth+"\" border=\"0\"></td>");
		result = result.Replace("<HEAD_NEXT_YEAR_LINK>", "<TD height=\"24\" width=\"15\" style=\"cursor:pointer;\" ALIGN=\"center\" valign=\"middle\""+(IsPopup()?" class=\"right\"":"")+" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"moveDate(+1,'y');showHebCal('nextYear');\" title=\""+Co_Cal_Translations.NextYear+"\">&nbsp;<img src=\"/images/tools/calendar/cmd_"+string_right+"2.gif\" width=\"7\" height=\"6\" alt=\""+Co_Cal_Translations.NextYear+"\" border=\"0\"></td>");
		
		if (IsPopup()) result=result.Replace('<HEADER_ROW_BACKGROUND>',' style=\"background-image:url(\'/images/calendar/calbgbt.jpg\')\"'); else result=result.Replace('<HEADER_ROW_BACKGROUND>','');
	
		result += "<TR><TD ALIGN=\"center\" VALIGN=\"top\" NOWRAP colspan=\"7\">"
		result += "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"offWhtBg\" width=\"100%\">"
		
		result += "<tr HEIGHT=\"15\" ALIGN=\"center\" class=\"monthDayWeek\">\n";
		for (var n=1; n<8; n++){
			result += "	<TD class=\"leftBarBg\">"+weekDay[n]+"</td>\n";
		}
	result += '</TR>';
	
/* End Header Row */		

	var i = 1;
	var k = 1;
	var cDay = 1;
	
	var curCivDate = '';
	var moed = '';

    while (k <= (hMonthLength + (startDay))) {
			result += "<tr HEIGHT=\"18\" class=\"small_calendar\">\n";
			for (col = 1; col <= 7; col++)  {
				if (k < startDay){
					result += '<TD width=\"24\" class=\"disabled\" ALIGN=\"center\"></TD>';
				}
				else if (k > (hMonthLength + (startDay-1))){
					result += '<TD width=\"24\" class=\"disabled\" ALIGN=\"center\"></TD>';
				}
				else{
					curCivDate = abs2greg(heb2Abs(cDay,cMonth,new Number(cYear)));
					moed = moadim(curCivDate.getDate(), curCivDate.getMonth()+1, curCivDate.getFullYear(), cDay, cMonth, col, cYear);
					if (col == 7 || moed != ""){
						result += "<TD ALIGN=\"center\" width=\"24\" height=\"18\" class=\"" + (today.getMonth() == curCivDate.getMonth() && today.getDate() == curCivDate.getDate() && today.getFullYear() == curCivDate.getFullYear() ? "today" : "weekend" ) + "\" onMouseOver=\"this.oldClass=this.className;this.className='selected'\" onMouseOut =\"this.className=this.oldClass;\" style=\"cursor:pointer\" onclick=\"selectDate('" + (new Number(curCivDate.getMonth())+1) + "/" + curCivDate.getDate() + "/" + curCivDate.getFullYear() + "','"+formatHebDate(cDay ,(cMonth-1) , cYear).Replace('\'', '\\\'')+"');return false;\" title=\""+(new Number(curCivDate.getMonth())+1) + "/" + curCivDate.getDate() + "/" + curCivDate.getFullYear() + (moed != "" ? " - " + moed : "") + "\">";
					}
					else{
						result += "<TD ALIGN=\"center\" width=\"24\" height=\"18\" class=\"" + (today.getMonth() == curCivDate.getMonth() && today.getDate() == curCivDate.getDate() && today.getFullYear() == curCivDate.getFullYear() ? "today" : "default" ) + "\" onMouseOver=\"this.oldClass=this.className;this.className='selected'\" onMouseOut =\"this.className=this.oldClass;\" style=\"cursor:pointer\" onclick=\"selectDate('" + (new Number(curCivDate.getMonth())+1) + "/" + curCivDate.getDate() + "/" + curCivDate.getFullYear() + "','"+formatHebDate(cDay , (cMonth-1) , cYear).Replace('\'', '\\\'')+"');return false;\" title=\""+(new Number(curCivDate.getMonth())+1) + "/" + curCivDate.getDate() + "/" + curCivDate.getFullYear() + (moed != "" ? " - " + moed : "") + "\">";
					}
					result += " " + cDay;
					result += '</TD>';
					cDay++;
        }
				k++;
			}
			if (k > (hMonthLength + (startDay-1))){
				break;
			}
      result += '</TR>'
    }
	
		result += "<TR height=\"18\"><TD colspan=\"2\" align=\"left\" style=\"border-right:0px;\"><A href=\"javascript:void(0);\" onclick=\""+(!IsPopup()?"picker_elm='"+picker_elm+"';":"")+"showHebCalendar('"+(startDate.getMonth()+1)+"','"+startDate.getFullYear()+"', '"+act+"');\"><IMG src=\"/images/calendar/cal_hebrew.gif\" width=\"28\" height=\"12\" alt=\"Gregorian Calendar\" border=\"0\"></A></TD><TD colspan=\"3\" align=\"center\" style=\"border-right:0px;border-left:0px;\"><a href=\"#\" onclick=\"selectDate('" + (new Number(today.getMonth())+1) + "/" + today.getDate() + "/" + today.getFullYear() + "','"+formatHebDate(today.getDate() , (today.getMonth()-1) , today.getFullYear()).Replace('\'', '\\\'')+"');return false;\">"+TODAY+"</a></TD><TD colspan=\"2\" align=\"right\" style=\"border-right:0px;border-left:0px;\">"+(IsPopup()?"<A href=\"javascript:showHebCal();\" class=\"calClose\">"+CLOSE+"</A>":"")+"&nbsp;</TD></TR></TABLE></TD></TR>" +
			"</table>\n" +
			"</td>\n</tr>\n</table>\n";
	
		if (IsPopup()) isCalShowing = true;
		display_calendar(result, true);
	}
	else{
		isCalShowing = false;
		display_calendar(null, false);
	}
}

function showMonth_Calendar(tLocation,tYear,act){

  if (!isCalShowing || (act!=null)){
		var arr_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	
		var today = new Date()
		
		// html generation (feel free to tune it for your particular application)
		// print calendar header
		var str_buffer = new String (
			"<TABLE width=\""+calendar_width()+"\" id=\"datePickerTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			"<tr>\n"+
			"<TD height=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\">\n"+
			"<TABLE width=\"100%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			
			"<TR>\n	<TD height=\"24\" width=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-left:1px solid #C1CDD8;border-top:1px solid #C1CDD8;\">"+
			"<a href=\"javascript:showMonth_Calendar('"+tLocation+"', '" + (new Number(tYear)-1) + "','prev');\">"+
			"&laquo;</a></td>\n"+
			"	<TD height=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-top:1px solid #C1CDD8;\"><A>"+
			tYear+"</A></td>\n"+
			"	<TD height=\"24\" width=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-top:1px solid #C1CDD8;\">"+
			"<a href=\"javascript:showMonth_Calendar('"+tLocation+"', '" + (new Number(tYear)+1) + "','next');\">"+
			"&raquo;</a></td>\n</tr>\n"
		);
	
		
		str_buffer += "<TR><TD ALIGN=\"center\" VALIGN=\"top\" NOWRAP colspan=\"3\">"
		str_buffer += "<TABLE BORDER=\"1\" bordercolor=\"#C1CDD8\" style=\"border-collapse: collapse;\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"offWhtBg\" width=\"100%\">"
		
		var mCount = 0
		
		for (var i = 0; i < 4; i++){
			str_buffer += "<tr HEIGHT=\"18\" class=\"small_calendar\">\n";
			  for (var k = 0; k < 3; k++){
				if (today.getMonth() == (mCount) && today.getFullYear() == tYear){
					str_buffer += "<TD ALIGN=\"center\" class=\"today\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='today'\">"
				}
				else{
					str_buffer += "<TD ALIGN=\"center\" class=\"default\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='default'\">"
				}
				str_buffer += "<A onclick=\"selectDate('" + (mCount+1) + "/1/" + tYear + "','');return false;\" href=\"#\"><B>" + arr_months[mCount] + "</B></A></TD>"
				
				mCount++
			  }
			str_buffer += "</TR>"
		}
		
		str_buffer += "<TR height=\"18\"><TD colspan=\"3\" align=\"center\"><A href=\"javascript:showMonth_Calendar();\" class=\"calClose\">"+CLOSE+"</A></TD></TR></TABLE></TD></TR>" +
			"</table>\n" +
			"</td>\n</tr>\n</table>\n";
	
			display_calendar(str_buffer, true);
		isCalShowing = true;
	}
	else{
		display_calendar(null, false);
		isCalShowing = false;
	}
}

function showHebMonth_Calendar(tLocation,tYear,act){

  if (!isCalShowing || (act!=null)){
		var arr_months = arr_heb_months;
	
		var today = new Date()
		
		// html generation (feel free to tune it for your particular application)
		// print calendar header
		var str_buffer = new String (
			"<TABLE width=\""+calendar_width()+"\" BORDER=\"0\" id=\"datePickerTable\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			"<tr>\n"+
			"<TD height=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\">\n"+
			"<TABLE width=\"100%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"caltable\" borderColor=\"#C1CDD8\">\n"+
			
			"<TR>\n	<TD height=\"24\" width=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-left:1px solid #C1CDD8;border-top:1px solid #C1CDD8;\">"+
			"<a href=\"javascript:showHebMonth_Calendar('"+tLocation+"', '" + (new Number(tYear)-1) + "','prev');\">"+
			"&laquo;</a></td>\n"+
			"	<TD height=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-top:1px solid #C1CDD8;\"><A>"+
			tYear + " - " + (new Number(tYear)+1) +"</A></td>\n"+
			"	<TD height=\"24\" width=\"24\" ALIGN=\"center\" background=\"/images/calendar/calbgbt.jpg\" class=\"caldaynames\" style=\"border-top:1px solid #C1CDD8;\">"+
			"<a href=\"javascript:showHebMonth_Calendar('"+tLocation+"', '" + (new Number(tYear)+1) + "','next');\">"+
			"&raquo;</a></td>\n</tr>\n"
		);
	
		
		str_buffer += "<TR><TD ALIGN=\"center\" VALIGN=\"top\" NOWRAP colspan=\"3\">"
		str_buffer += "<TABLE BORDER=\"1\" bordercolor=\"#C1CDD8\" style=\"border-collapse: collapse;\" CELLPADDING=\"0\" CELLSPACING=\"0\" class=\"offWhtBg\" width=\"100%\">"
		
		var mCount = 0
		
		for (var i = 0; i < 4; i++){
			str_buffer += "<tr HEIGHT=\"18\" class=\"small_calendar\">\n";
			  for (var k = 0; k < 3; k++){
			  	if (mCount == 6){ //TIshrei
					tYear++
				}
				if (greg2heb(today.getDay(),today.getMonth(),today.getFullYear()).split("/")[0] == (mCount) && greg2heb(today.getDay(),today.getMonth(),today.getFullYear()).split("/")[2] == tYear){
					str_buffer += "<TD ALIGN=\"center\" class=\"today\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='today'\">"
				}
				else{
					str_buffer += "<TD ALIGN=\"center\" class=\"default\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='default'\">"
				}
				var nDate = abs2greg(heb2Abs(1,(mCount+2),tYear));
				str_buffer += "<A onclick=\"selectDate('" + (new Number(nDate.getMonth())+1) + "/" + (new Number(nDate.getDay())+1) + "/" + nDate.getFullYear() + "','');return false;\" href=\"#\"><B>" + arr_months[mCount] + "</B></A></TD>"
				
				mCount++
			  }
			str_buffer += "</TR>"
		}
		
		if (HebLeapYear(tYear)){
		  str_buffer += "<tr HEIGHT=\"18\" class=\"small_calendar\">\n";
			if (today.getMonth() == (mCount) && today.getFullYear() == tYear){
				str_buffer += "<TD ALIGN=\"center\" class=\"today\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='today'\">"
			}
			else{
				str_buffer += "<TD ALIGN=\"center\" class=\"default\" onmouseover=\"this.className='selected'\" onmouseout=\"this.className='default'\">"
			}
				var nDate = abs2greg(heb2Abs(1,(new Number(mCount)+2),tYear));
				str_buffer += "<A onclick=\"selectDate('" + ((new Number(nDate.getMonth())+1) + "/" + (new Number(nDate.getDay())+1) + "/" + nDate.getFullYear()) + "','');return false;\" href=\"#\"><B>" + arr_months[12] + "</B></A></TD>"
				str_buffer += "<TD ALIGN=\"center\" bgcolor=\"#FFFAE0\">&nbsp;</TD>"
				str_buffer += "<TD ALIGN=\"center\" bgcolor=\"#FFFAE0\">&nbsp;</TD>"
			str_buffer += "</TR>"
		}
		
		str_buffer += "<TR height=\"18\"><TD colspan=\"3\" align=\"center\"><A href=\"javascript:showHebMonth_Calendar();\" class=\"calClose\">"+CLOSE+"</A></TD></TR></TABLE></TD></TR>" +
			"</table>\n" +
			"</td>\n</tr>\n</table>\n";
	
			display_calendar(str_buffer, true);
		isCalShowing = true;
	}
	else{
		display_calendar(null, false);
		isCalShowing = false;
	}
}

function display_calendar(html, vSwitch) {
  var date_picker=document.getElementById(picker_elm);if (!date_picker) document.getElementById("datePicker");
  if (vSwitch) {
		
  	if (date_picker.nodeName == 'IFRAME') {
			var tFrm = document.frames["datePicker"];
			tFrm.document.body.innerHTML = html;
			if (!tFrm.loaded) init_calFrame(tFrm)
			var tDoc=tFrm.document;date_picker.style.display="";
			date_picker.style.height = (tFrm.document.body.firstChild.clientHeight) + 'px';
		}
		else {
		  var tDoc = document;date_picker.innerHTML=html;date_picker.style.display="";
		}
  }
  else {
		date_picker.style.display = "none";
  }
	picker_elm='datePicker';
}
function IsPopup() {
	return (picker_elm=='datePicker'||picker_elm=='');
}

function init_calFrame(tFrm) {
	tFrm.showHebMonth_Calendar = showHebMonth_Calendar; tFrm.selectDate = selectDate;
	tFrm.showMonth_Calendar = showMonth_Calendar; tFrm.showHebCalendar = showHebCalendar;
	tFrm.showHebCal = showHebCal; tFrm.show_calendar = show_calendar;
	tFrm.doHighlight = doHighlight; tFrm.moveDate = moveDate;
	tFrm.jumpToDate = jumpToDate;
	var sSheet = tFrm.document.createStyleSheet();
	sSheet.addRule('#datePickerTable A','text-decoration: none;	color: #000000');
	sSheet.addRule('.monthDayWeek','font-weight:bold;color:#104A7B;text-align:center;background-color:#ffffff;');
	sSheet.addRule('.leftBarBg','background-color:#DBEAF5;');
	sSheet.addRule('td.caldaynames', 'border-color: #C1CDD8;font-family: Verdana, Arial, Tahoma; font-size: 11px; font-weight: bold; color: #000099;cursor:pointer;');
	sSheet.addRule('.caldaynames td', 'border-color: #C1CDD8;font-family: Verdana, Arial, Tahoma; font-size: 11px; font-weight: bold; color: #000099;cursor:pointer;');
	sSheet.addRule('.caldaynames .left', 'border-left:1px solid #C1CDD8;border-top:1px solid #C1CDD8;');
	sSheet.addRule('.caldaynames .center', 'border-top:1px solid #C1CDD8;');
	sSheet.addRule('.caldaynames .right', 'border-right:1px solid #C1CDD8;border-top:1px solid #C1CDD8;');
	sSheet.addRule('.offWhtBg', 'background-color:#FFFBF7; font-family:Tahoma, Arial; font-size:11px; color:#000000;border-color:#C1CDD8;border-collapse: collapse;');
	sSheet.addRule('.date_select', 'font-size:9px; background-color: #DBEAF5; font-family:tahoma,arial;color: #104A7B;font-weight:normal;');
	sSheet.addRule('.small_calendar td', 'border:1px solid #C1CDD8;font-family: Tahoma, Arial;font-size: 11px;color: #000099;padding: 3px;');
	sSheet.addRule('.small_calendar .today', 'background-color: #FFFAE0;');
	sSheet.addRule('.small_calendar .weekend', 'background-color: #F7F2F7;');
	sSheet.addRule('.small_calendar .default', 'background-color: #FFFCF9;');
	sSheet.addRule('.small_calendar .selected', 'background-color: #E6ECF2;border-color: #C1CDD8;');
	sSheet.addRule('.small_calendar .disabled', 'background-color:#f2f2f2;');
	tFrm.loaded = true;
}

function calendar_width() {
	return (IsPopup() ? 200 : 170);
}

function date_headers(curM, curY, heb) {
  if (heb) {
		return arr_heb_months[hebMonth[curM]] + " " + curY;
	}
	else {
		return arr_months[curM-1] + " " + curY;
	}
}

function date_select_headers(curM, curY, heb) {
	if (!IsPopup()) { return date_headers(curM, curY, heb);}
  if (heb) {
	    var aYear = hebrewCalendar(1,new Date().getMonth(),new Date().getFullYear());
		aYear = aYear[2];
		var hepLeap=HebLeapYear(curY);
//		var arr_months = ['','Nissan', 'Iyar', 'Sivan', 'Tammuz', 'Av', 'Elul','Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Shvat','Adar', 'Adar_I', 'Adar_II'];
		
		var html = '<select name="month_select" id="month_select" class="date_select" onchange="jumpToDate(\'m\', this.value, \'he\', \''+curM+'\',\''+curY+'\');">';
		for (var i=1;i<hebMonth.length;i++) {if (hepLeap && i == 12) { i++ } else if(!hepLeap&&i>12) {break;} html+='<option value="'+i+'"'+(curM==i?' selected':'')+'>'+arr_heb_months[hebMonth[i]]+'</option>'};
		html+='</select>';
		
		html+='<select name="year_select" id="year_select" class="date_select" onchange="jumpToDate(\'y\', this.value, \'he\', \''+curM+'\',\''+curY+'\');">';
		if (curY<5660) html+='<option value="'+curY+'" selected>'+curY+'</option>';
		for (var i=5660;i<(new Number(aYear)+20);i++) html+='<option value="'+i+'"'+(curY==i?' selected':'')+'>'+i+'</option>';
		if (curY>=(new Number(aYear)+20)) html+='<option value="'+curY+'" selected>'+curY+'</option>';
		html+='</select>';
		heList=html;
  }
  else {
//  	if (enList == '') {
	    var aYear = new Date();
		aYear = aYear.getFullYear();
		var html = '<select name="month_select" id="month_select" class="date_select" onchange="jumpToDate(\'m\', this.value, \'en\', \''+curM+'\',\''+curY+'\');">';
		for (var i=1;i<civMonth.length;i++) html+='<option value="'+i+'"'+(curM==i?' selected':'')+'>'+arr_months[i-1]+'</option>';
		html+='</select>';
		
		html+='<select name="year_select" id="year_select" class="date_select" onchange="jumpToDate(\'y\', this.value, \'en\', \''+curM+'\',\''+curY+'\');">';
		for (var i=1900;i<(new Number(aYear)+20);i++) html+='<option value="'+i+'"'+(curY==i?' selected':'')+'>'+i+'</option>';
		html+='</select>';
		enList=html;
/*	}
	else {
		html=enList;
	} */
  }
	return html;
}

// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (tDateTime) {
	var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
	if (!re_date.exec(tDateTime)){
//		return alert("Invalid Datetime format: "+ str_datetime);
		return '';
	}
	return (new Date (RegExp.$3, RegExp.$1-1, RegExp.$2));
}
function jsDate(tDateTime){
	return (new String ((tDateTime.getMonth()+1)+"/"+tDateTime.getDate()+"/"+tDateTime.getFullYear()));
}

function selectDate(tDate,view){
	var act = g_target;
  if (act.indexOf('/') == -1){
	document.forms[targetForm][targetElement].value = tDate
	document.getElementById("datePicker").style.display = "none";
	if (document.forms[targetForm]) if (document.forms[targetForm].calUsed) document.forms[targetForm].calUsed.value = whichCalShowing;
	if (act == 'Birthdate' && view != ""){
		if (document.getElementById("hebBDay")){
			var afterDark = document.getElementById('afterDark') || document.getElementById('after_dark');
			if (afterDark) afterDark = afterDark.checked;
			if (afterDark)
			{
				view = new Date(tDate)/* for some reason adding a day is not necessary */;
				view = hebrewCalendar(view.getDate(), view.getMonth() + 1, view.getFullYear(), true);
				view = formatHebDate(view[0], view[1], view[2]);
			}
			document.getElementById("hebBDay").innerHTML = view;
			vFieldChanged();
		}
	}
	if (globalSetHebDate != null) if (typeof(setDates) == 'function') setDates(document.forms[targetForm][targetElement], tDate, globalSetHebDate);
		isCalShowing = false;
  }
  else{
		if (cal_append_mode&&whichCalShowing==2) tDate+="&mode=j";
  	if (act.indexOf("?") == -1) document.location.href = act + '?tDate=' +tDate; else document.location.href = (act + '&tDate=' + tDate).Replace('?&','?');
  }
}

function jumpToDate(w, dt, lang, curM, curY) {
	dt = new Number(dt);
  if (lang=='he') {
    if (w=='m') gMonth=(dt>12?dt-1:dt); else if(w=='y') gYear=dt;
  	showHebCal('jump');
  }
  else {
    if (w=='m') showHebCalendar(dt,new Number(curY), 'jump'); else if (w=='y') showHebCalendar(curM,dt, 'jump');
  }
}

function doHighlight(oRow,newStyle,changeType){
	for (var i = 0; i < oRow.cells.length; i++){
	  if (changeType == "class"){
			oRow.cells[i].className = newStyle;
	  }
	  else if (changeType == "bgcolor"){
			oRow.cells[i].bgColor = newStyle;
	  }
	}
}

	var posX=0;posY=0;overElemName='';
	
	if (document.all) { // Internet Explorer
		document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
		document.onmousemove = captureMousePosition;
	}
	
	function captureMousePosition(e) {
		if (document.all) {
			overElemName=window.event.srcElement.id;e=window.event;posX=e.x;posY=e.y;
		} else{
			posX = e.pageX;posY = e.pageY;overElemName = e.target.id;
	  }
	}

	function showCalendar(tObj, tDay, tMonth, tYear, tAct, setHebDate, curView, calToShow, do_not_reset_cal_to_show){
		globalSetHebDate = setHebDate;g_target = tObj;
		if (whichCalShowing != 0 && whichCalShowing != '' && tObj != 'Birthdate' && !do_not_reset_cal_to_show){
			calToShow = whichCalShowing
		}
		var posTop = (document.all ? posY+document.body.scrollTop : posY);
		var posLeft = (document.all ? posX+document.body.scrollLeft : posX);
		switch (curView.toLowerCase()) {
			case 'rightnav' : posLeft-=185; posTop+=12;
			break;
			case 'event' : posLeft-=185; posTop-=160;
			break;
			case 'add' : posTop+=5; posLeft+=5;
			break;
			case 'topmiddle': posLeft-=90; posTop-=160;
			break;
			default : posLeft+=5;posTop-=150;
			break;
		}
		if (document.all){
			document.getElementById("datePicker").style.left=posLeft;
			document.getElementById("datePicker").style.top=posTop;
		}
		else{
			document.getElementById("datePicker").style.left=posLeft;
			document.getElementById("datePicker").style.top=posTop;
		}
		if (calToShow == 1){ //Calendar with English Dates, hebrew Titles
			showHebCalendar(new Number(tMonth), new Number(tYear),tAct);
		}
		else if (calToShow == 2){ //Calendar with Hebrew Dates, English Titles
			if (new Number(tYear) < 4500){
				var hebDate = hebrewCalendar(tDay,tMonth,tYear)
				gDay = hebDate[0];gMonth = hebDate[1];gYear = hebDate[2];
			}
			else{
				gDay = new Number(tDay);gMonth = new Number(tMonth);gYear = new Number(tYear);
			}
			showHebCal(tAct);
		}
		else{ //Show Default Calendar english dates, no subtitles
			show_calendar(tMonth + '/' + tDay + '/' + tYear,tAct,curView);
		}
	}

function showMonthCalendar(tObj,tDateTime,tAct, calToShow){
	g_target = tObj;
	globalSetHebDate = null;
   if (document.all){
		document.getElementById("datePicker").style.left = posX+document.body.scrollLeft+5;
		document.getElementById("datePicker").style.top = posY+document.body.scrollTop-100;
	}
	else{
		document.getElementById("datePicker").style.left = posX+5;
		document.getElementById("datePicker").style.top = posY-100;
	}
	if (calToShow == 2) showHebMonth_Calendar(tObj,tDateTime,tAct); else showMonth_Calendar(tObj,tDateTime,tAct);
}
	
/*function weekdayName(day) {
  var weekdays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Shabbat'];
  
  return weekdays[day];
}
*/
function dateOccurenceInMonth(date) {
  var date = new Date(date);
  var dom = date.getDate();
  var year = date.getFullYear();
  var month = date.getMonth();
  var retVal = 0
  
  if (dom >= 1 && dom <=7) { //first
    retVal = 1;
  }
  else if (dom >= 8 && dom <= 14) { //second
    retVal = 2
  }
  else if (dom >= 15 && dom <= 21) { //third
    retVal = 3
  }
  else if (dom >= 22 && dom <= 28) { //fourth
	 retVal = 4
    switch (civMonthLength(month,year)) {
	  case 31:
	    if (dom >= 25) {
		 retVal = 6
		}
	  break;
	  case 30:
	    if (dom >= 24) {
		 retVal = 6
		}
	  break;
	  case 29:
	    if (dom >= 23) {
		 retVal = 6
		}
	  break;
	  case 28:
		 retVal = 6
	  break;
	}
  }
  else { //last
  	retVal = 5
  }
  return retVal
}

function dateAdd(datepart, number, date, return_type){
	/*intval is YYYY, M, D, H, N, S as in VBscript; numb is amount +/-; base is javascript date object*/
	date = new Date(date);
	switch(datepart.toUpperCase()){
		case "M":
			date.setMonth(date.getMonth() + number);
			break;
		case "YYYY":
			date.setFullYear(date.getFullYear() + number);
			break;
		case "D":
			date.setDate(date.getDate() + number);
			break;
		case "H":
			date.setHours(date.getHours() + number);
			break;
		case "N":
			date.setMinutes(date.getMinutes() + number);
			break;
		case "S":
			date.setSeconds(date.getSeconds() + number);
			break;
		default:
	}
	if (typeof(return_type) != "undefined" && return_type == "date")
		return date;
	else
		return (date.getMonth()+1) + '/' + date.getDate() + '/' + date.getFullYear();
}

/* Hebrew Calendar Functions */
function hebrewCalendar(cDay,cMonth,cYear, check_leap) {
	var hebDate = greg2heb(new Number(cDay),new Number(cMonth),new Number(cYear))
	cDay = eval(hebDate.substring(0, hebDate.indexOf(' ')));
	var tHmS = hebDate.substring(hebDate.indexOf(' ')+1, hebDate.length);
	cMonth = new Number(eval(tHmS.substring(0, tHmS.indexOf(' '))));
	cYear = new Number(tHmS.substring(tHmS.indexOf(' ')+1, tHmS.length));
//	if (check_leap) {if (HebLeapYear(parseInt(cYear))&&parseInt(cMonth)>13)cMonth--;}
	var retVal = new Array(Number(cDay), Number(cMonth), Number(cYear));
	//if (retVal[1]==0) retVal[1]=12;
	return (retVal);
}

function formatHebDate(hebDay,hMonth,hYear){
	hMonth = (hMonth>=12&&hMonth<14 ? (HebLeapYear(new Number(hYear)) ? new Number(hMonth)+1 : hMonth) : hMonth)
	
	return hebDay + ' ' + arr_heb_months[hebMonth[hMonth]] + ' ' + hYear;
}
function calendar(selM, selY) {
	var m = selM;
	var y = selY;
	var d = civMonthLength(m, y);
	var firstOfMonth = new Date (y, selM-1, 1);
	var startPos = firstOfMonth.getDay() + 1;
	var retVal = new Object();
	retVal[1] = startPos;
	retVal[2] = d;
	retVal[3] = new Number(m);
	retVal[4] = new Number(y);
	return (retVal);
}

function prevMonth(cMonth, cYear){
	var y = cYear
	var m = cMonth

	if(m > 1)
		m -= 1;
	else {
		m = 12;
		y -= 1;
	}

	return m + "', '" + y
}

function nextMonth(cMonth, cYear){
	var y = cYear
	var m = cMonth

	if(m <= 11)
		m++;
	else {
		m = 1;
		y++;
	}

	return m + "', '" + y
}

function moveDate(x,part){
	switch (part)
	{
		case 'm':
		  if (x < 0)//previous
			{ 
				var tVal = prevHebMonth(gMonth,gYear);
				gMonth = tVal[0];
				gYear = tVal[1];
		  }
		  else
			{ //next
				var tVal = nextHebMonth(gMonth,gYear);
				gMonth = tVal[0];
				gYear = tVal[1];
		  }
			break;
		case 'd'://must be fixed, never used
			gDay = gDay + x;
			break;
		case 'y':
			gYear = gYear + x;
			break;
	}
}

function prevHebMonth(cMonth, cYear)
{
	var y = cYear;
	var m = cMonth;

	if(m == TISHREI)
	{
	  m--;
		y--;
	}
	else if (m == NISAN)
	{
		m = MonthsInHebYear(cYear);
	}
	else
	{
		m--;
	}
	var ret = new Object();
	ret[0] = m;
	ret[1] = y;
	return (ret);
}

function nextHebMonth(cMonth, cYear){
	var y = cYear
	var m = cMonth

	if(m == ELUL){
	    m++;
		y++;
	}
	else if (m == MonthsInHebYear(cYear)){
		m = NISAN;
	}
	else{
		m++;
	}
	var ret = new Object();
	ret[0] = m;
	ret[1] = y;
	return (ret)
}

function getDatePart(dateTime,part){
	dateTime = dateTime.Replace(' ','');
	if (!isDate(dateTime)){
		dateTime = new Date() //.getMonth();
	}
	switch (part){
		case 'm':
			dateTime = dateTime.substring(0,dateTime.indexOf('/'));
		break;
		case 'd':
			dateTime = dateTime.substring(dateTime.indexOf('/')+1,dateTime.indexOf('/',dateTime.indexOf('/')+1));
		break;
		case 'y':
			dateTime = dateTime.substr(dateTime.indexOf('/',dateTime.indexOf('/')+1)+1);
		break;
	}
	return dateTime
}

function getHebDate(tDate, targetElement, check_leap){
  if (!isDate(tDate)){
    if (tDate == ''){
	 targetElement.innerHTML = '&nbsp;'
	}
	else{
	 targetElement.innerHTML = "<span style=\"color:red;\">Invalid Date!</span>"
	}
  }
  else{
		tDate = str2dt(tDate.Replace(' ',''))
		tDate = hebrewCalendar(tDate.getDate(), tDate.getMonth() + 1, tDate.getFullYear(), check_leap)
		targetElement.innerHTML = formatHebDate(tDate[0],tDate[1],tDate[2]);
  }
}

/* Date Validation */
var dtCh= "/";
var minYear=1300;
var maxYear=4000;

function isInteger(s){
	var i;
    if (isNaN(s)){
		return false;
	}
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	dtStr = dtStr.Replace(' ','');
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
//		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
//		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//		alert("Please enter a valid date")
		return false
	}
return true;
}
/* End Date Validation */
//</script>