
	/*
		Author:		Jeff Martin (jeff@santasoft.com)
		Copyright:	(c)2004, do not modify this file
		Modified:	1/27/2008
		Version:	3.0
	*/

	var cal_month = -1;
	var cal_year  = -1;
	var cal_day = -1;
	var cal_today = new Date();
	var	calddl_month = -1;
	var	calddl_year = -1;
	var	calddl_day = -1;
	var calddl_date = new Date();
	var cal_field = null;

	var cal_format = 'm/d/yyyy';
	var cal_mode = 'MDYDropDowns';
	var cal_sundayEnabled = true;
	var cal_mondayEnabled = true;
	var cal_tuesdayEnabled = true;
	var cal_wednesdayEnabled = true;
	var cal_thursdayEnabled = true;
	var cal_fridayEnabled = true;
	var cal_saturdayEnabled = true;
	var cal_minDate = null;
	var cal_maxDate = null;
	
	function cal_validate(textField, minDate, maxDate, sundayEnabled,mondayEnabled,tuesdayEnabled,wednesdayEnabled,thursdayEnabled,fridayEnabled,saturdayEnabled)
	{
		if(textField.value.length > 0)
		{
			var dtDate;
			var sError = '';
			var sDefaultError = 'Please enter dates in m/d/yyyy format.';
			try
			{
				dtDate = new Date(textField.value);
				if(dtDate != 'NaN')
				{
					if(minDate != null && minDate.length > 0)
					{
						var dtMinDate = new Date(minDate);
						if(maxDate != null && maxDate.length > 0)
						{
							//both
							var dtMaxDate1 = new Date(maxDate);
							sError = 'Please enter a date between '+minDate+' y '+maxDate+'.';
						}
						else
						{
							//min only
							sError = 'Please enter a date on or after '+minDate+'.';
						}
					}
					else if(maxDate != null && maxDate.length > 0)
					{
						//max only
						var dtMaxDate2 = new Date(maxDate);
						if(dtDate > dtMaxDate2)
						{
							sError = 'Please enter a date on or before '+maxDate+'.';
						}
					}
				}
				else
				{
					sError = sDefaultError;
				}
			}
			catch(e)
			{
				sError = sDefaultError;
			}
			if(sError.length > 0)
			{
				alert(sError);
				textField.value = '';
				textField.focus();
			}
		}
	}

	function calendar_init()
	{
		//initialization functions for calendar
		/************************************************
		this code writes the calendar container (base) to 
		the document, it does not create the calendar
		************************************************/
		//filter:progid:DXImageTransform.Microsoft.shadow(Strength=3,Color=\'#666666\',Direction=\'135\');
		document.write('<DIV STYLE="z-order:0;position:absolute;display:none;" NAME="calendar" ID="calendar"></DIV>');	
	}

	function set_drop_down(dropdown,selection)
	{
		for(x=0;x<dropdown.options.length;x++)
		{
			//iterate through all options
			if(dropdown.options[x].value == selection)
			{
				//if value of option equals selection, make that option selected
				dropdown.options[x].selected = true;
				break;
			}
		}
	}

	function get_drop_down(dropdown)
	{
		var selectedValue = dropdown.options[dropdown.selectedIndex].value;
		if(selectedValue.indexOf('0') == 0)
		{
			selectedValue = selectedValue.replace(/0/,'');
		}
		return selectedValue;
	}
	
	function calendar_date_select(pane)
	{
		var selected_date = new Date(cal_year,cal_month-1,pane.innerHTML); //DO NOT MODIFY THIS LINE
		/************************************
			THIS FUNCTION IS CALLED WHEN A DATE
			IS SELECTED.
			selected_date returns Date() object of selected date
			
			MODIFY ONLY CODE BELOW THIS LINE
		************************************/
		if(cal_mode == 'MDYDropDowns')
		{
			if(calddl_year != -1)
			{
				set_drop_down(calddl_year,selected_date.getYear());
				set_drop_down(calddl_month,selected_date.getMonth()+1);
				set_drop_down(calddl_day,selected_date.getDate());
			}
		}
		else
		{
			cal_field.value = (selected_date.getMonth()+1).toString()+'/'+selected_date.getDate().toString()+'/'+selected_date.getYear().toString();
		}
		document.all.calendar.style.display = 'none';
		//show_calendar(0,0,0,0);
		//alert(selected_date);
	}

	function show_calendar_MDYDropDowns(pane,year,month,day,format,minDate,maxDate,sundayEnabled,mondayEnabled,tuesdayEnabled,wednesdayEnabled,thursdayEnabled,fridayEnabled,saturdayEnabled)
	{
		if(document.all.calendar.style.display == 'none')
		{
			calddl_year = year;
			calddl_month = month;
			calddl_day = day;
			cal_year = get_drop_down(year);
			cal_month = get_drop_down(month);
			cal_day = get_drop_down(day);
			cal_format = format;
			cal_mode = 'MDYDropDowns';
			cal_sundayEnabled = sundayEnabled;
			cal_mondayEnabled = mondayEnabled;
			cal_tuesdayEnabled = tuesdayEnabled;
			cal_wednesdayEnabled = wednesdayEnabled;
			cal_thursdayEnabled = thursdayEnabled;
			cal_fridayEnabled = fridayEnabled;
			cal_saturdayEnabled = saturdayEnabled;
	
			if(minDate != null && minDate.length > 0)
			{
				cal_minDate = new Date(minDate);
			}
			else
			{
				cal_minDate = new Date();
			}
			if(maxDate != null && maxDate.length > 0)
			{
				cal_maxDate = new Date(maxDate);
			}
			else
			{
				cal_maxDate = new Date();
				cal_maxDate.setYear(cal_maxDate.getYear()+2);
			}

			if(cal_year.length == 0 || cal_month.length == 0 || cal_day.length == 0)
			{
				cal_year = calddl_date.getFullYear();
				cal_month = calddl_date.getMonth()+1;
				cal_day = 0;
				calddl_date = new Date();
			}
			else
			{
				calddl_date = new Date(cal_year,cal_month-1,cal_day);
				if(calddl_date == 'NaN')
				{
					calddl_date = new Date();
				}
			}
			pane.style.position = 'relative';

			draw_calendar();

			document.all.calendar.style.display = '';

			position_x = pane.offsetLeft+pane.offsetWidth+2;
			position_y = pane.offsetTop-document.all.calendar.offsetHeight+2;
			document.all.calendar.style.posLeft = position_x;
			document.all.calendar.style.posTop = position_y;
			document.all.calendar.style.zIndex = 100;
		}
		else
		{	
			document.all.calendar.style.display = 'none';
		}
	}
	
	
	function show_calendar_Text(pane,field,format,minDate,maxDate,sundayEnabled,mondayEnabled,tuesdayEnabled,wednesdayEnabled,thursdayEnabled,fridayEnabled,saturdayEnabled)
	{
		if(document.all.calendar.style.display == 'none')
		{
			cal_field = field;
			cal_format = format;
			cal_mode = 'Text';
			cal_sundayEnabled = sundayEnabled;
			cal_mondayEnabled = mondayEnabled;
			cal_tuesdayEnabled = tuesdayEnabled;
			cal_wednesdayEnabled = wednesdayEnabled;
			cal_thursdayEnabled = thursdayEnabled;
			cal_fridayEnabled = fridayEnabled;
			cal_saturdayEnabled = saturdayEnabled;
			
			if(minDate != null && minDate.length > 0)
			{
				cal_minDate = new Date(minDate);
			}
			else
			{
				cal_minDate = new Date();
			}
			if(maxDate != null && maxDate.length > 0)
			{
				cal_maxDate = new Date(maxDate);
			}
			else
			{
				cal_maxDate = new Date();
				cal_maxDate.setYear(cal_maxDate.getYear()+2);
			}
	
			if(field.value.length > 0)
			{
				try
				{
					calddl_date = new Date(field.value);
					if(calddl_date == 'NaN')
					{
						calddl_date = new Date();
					}
				}
				catch(e)
				{
					field.value = '';
					calddl_date = new Date();
				}
				cal_year = calddl_date.getFullYear();
				cal_month = calddl_date.getMonth()+1;
				cal_day = calddl_date.getDate();
			}
			else
			{
				calddl_date = new Date(cal_year,cal_month-1,cal_day);
			}
			pane.style.position = 'relative';

			draw_calendar();

			document.all.calendar.style.display = '';

			position_x = pane.offsetLeft+pane.offsetWidth+2;
			position_y = pane.offsetTop-document.all.calendar.offsetHeight+2;
			document.all.calendar.style.posLeft = position_x;
			document.all.calendar.style.posTop = position_y;
			document.all.calendar.style.zIndex = 100;
		}
		else
		{	
			document.all.calendar.style.display = 'none';
		}
	}
	
	function focus_day(pane)
	{
		pane.className = 'calendar_day_hover';
	}
	
	function blur_day(pane)
	{
		var temp_date = new Date(cal_year,cal_month-1,pane.innerHTML);
		if(temp_date.getYear() == cal_today.getYear() && temp_date.getMonth() == cal_today.getMonth() && temp_date.getDate() == cal_today.getDate())
		{
			//set to today
			pane.className = 'calendar_day_today';
		}
		else
		{
			if(temp_date.getYear() == calddl_date.getYear() && temp_date.getMonth() == calddl_date.getMonth() && temp_date.getDate() == calddl_date.getDate())
			{
				//set to selected day
				pane.className = 'calendar_day_hover';
			}
			else
			{
				//if the day is not the pre-selected day
				pane.className = 'calendar_day';
			}
		}
	}
	
	function get_month(month)
	{
		switch(parseInt(month))
		{
			case 0:
				return 'Diciembre';
				break;
			case 1:
				return 'Enero';
				break;
			case 2:
				return 'Febrero';
				break;
			case 3:
				return 'Marzo';
				break;
			case 4:
				return 'Abril';
				break;
			case 5:
				return 'May';
				break;
			case 6:
				return 'Junio';
				break;
			case 7:
				return 'Julio';
				break;
			case 8:
				return 'Agosto';
				break;
			case 9:
				return 'Septiembre';
				break;
			case 10:
				return 'Octubre';
				break;
			case 11:
				return 'Noviembre';
				break;
			case 12:
				return 'Diciembre';
				break;
			case 13:
				return 'Enero';
				break;
		}
	}
	
	function get_weekday(weekday)
	{
		switch(parseInt(weekday))
		{
			case 0:
				return 'Domingo';
				break;
			case 1:
				return 'Lunes';
				break;
			case 2:
				return 'Martes';
				break;
			case 3:
				return 'Miercoles';
				break;
			case 4:
				return 'Jueves';
				break;
			case 5:
				return 'Viernes';
				break;
			case 6:
				return 'Sabado';
				break;
		}
	}
	
	function change_month(modifier)
	{
		cal_month = parseInt(cal_month)+parseInt(modifier);
		/*if(cal_month<10)
		{
			cal_month = cal_month.toString();
		}*/
		//window.status = cal_month;
		draw_calendar();
	}
	
	function draw_calendar()
	{
		var temp_date;
		temp_date = new Date();
		if(cal_month < 0 || cal_year < 0)
		{
			//set calendar to current date for initial load
			cal_month = temp_date.getMonth()+1;
			cal_year = temp_date.getYear();	 
		}
		else
		{
			if(cal_month == 13)
			{
				//move to january next year
				cal_month = 1;
				cal_year = parseInt(cal_year) + 1;
			}
			if(cal_month == 0)
			{
				//move to december last year
				cal_month = 12;
				cal_year = parseInt(cal_year) - 1;
			}
		}
		//set Month/Year header text
		var cal_month_name = get_month(cal_month);
		var cal_head = cal_month_name+' '+cal_year;

		//build calendar
		var complete = false;
		temp_date = new Date(cal_year,cal_month-1,1);
		var next_date = new Date(cal_year,cal_month-1,2);
		var cal_HTML = '<TABLE CLASS="calendar_base" CELLPADDING=3 CELLSPACING=0>';
		//add month header
		cal_HTML = cal_HTML + '<TR CLASS="calendar_header"><TD CLASS="calendar_header" ALIGN="center" STYLE="cursor:hand;" OnClick="change_month(\'-1\');" CLASS="calendar_header" TITLE="Previous Month">&laquo;</TD><TD COLSPAN=5 CLASS="calendar_header" ID="cal_header" ALIGN="center" TITLE="'+cal_head+'">'+cal_head+'</TD><TD CLASS="calendar_header" ALIGN="center" STYLE="cursor:hand;" OnClick="change_month(\'1\');" CLASS="calendar_header" TITLE="Next Month">&raquo;</TD></TR>';
		//add weekday names header
		cal_HTML = cal_HTML + '<TR CLASS="calendar_weekday"><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(0)+'">Sun</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(1)+'">Mon</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(2)+'">Tue</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(3)+'">Wed</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(4)+'">Thr</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(5)+'">Fri</TD><TD CLASS="calendar_weekday" ALIGN="center" TITLE="'+get_weekday(6)+'">Sat</TD>';
		//pad the extra weekdays at the start of the month
		if(temp_date.getDay() > 0)
		{
			cal_HTML = cal_HTML + '<TR>';
			for(x=0;x<temp_date.getDay();x++)
			{
				cal_HTML = cal_HTML+'<TD CLASS="calendar_day_empty" TITLE="'+get_month(temp_date.getMonth())+'">&nbsp;</TD>';
			}
		}
		var day_style;
		var ToolTip;
			ToolTip =  get_weekday(temp_date.getDay())+', '+cal_month_name+' '+temp_date.getDate()+', '+cal_year;
		while(!complete)
		{
			if(temp_date.getDay() == 0)
			{
				cal_HTML = cal_HTML + '<TR>';
			}
			//set day style
			if(temp_date.getYear() == calddl_date.getYear() && temp_date.getMonth() == calddl_date.getMonth() && temp_date.getDate() == calddl_date.getDate())
			{
				//set selected day
				day_style = 'calendar_day_hover';
			}
			else
			{
				if(temp_date.getYear() == cal_today.getYear() && temp_date.getMonth() == cal_today.getMonth() && temp_date.getDate() == cal_today.getDate())
				{
					//set today
					day_style = 'calendar_day_today';
					ToolTip = 'Today, '+ToolTip;
				}
				else
				{
					day_style = 'calendar_day';
				}
			}
			//add day
			if(((temp_date.getDay() == 0 && cal_sundayEnabled) ||
				(temp_date.getDay() == 1 && cal_mondayEnabled) ||
				(temp_date.getDay() == 2 && cal_tuesdayEnabled) ||
				(temp_date.getDay() == 3 && cal_wednesdayEnabled) ||
				(temp_date.getDay() == 4 && cal_thursdayEnabled) ||
				(temp_date.getDay() == 5 && cal_fridayEnabled) ||
				(temp_date.getDay() == 6 && cal_saturdayEnabled)) &&
				temp_date >= cal_minDate && temp_date <= cal_maxDate
			)
			{
				//weekday enabled
				cal_HTML = cal_HTML+'<td class="'+day_style+'" onmouseover="focus_day(this);" onmouseout="blur_day(this);" onmousedown="calendar_date_select(this);" align="center" title="'+ToolTip+'">'+temp_date.getDate()+'</TD>';
			}
			else
			{
				//weekday disabled
				cal_HTML = cal_HTML+'<td class="calendar_day_disabled" align="center" title="'+ToolTip+'">'+temp_date.getDate()+'</td>';
			}
			if(temp_date.getDay() == 6)
			{
				cal_HTML = cal_HTML+'</tr>\n';
			}
			//decide to continue or end
			next_date = new Date(temp_date.getYear(),temp_date.getMonth(),temp_date.getDate()+1);
			if(next_date.getMonth() == temp_date.getMonth())
			{
				temp_date = next_date;
			}
			else
			{
				complete = true;
			}
		}
		//pad the extra weekdays at the end of the month
		if(temp_date.getDay() != 6)
		{
			for(x=temp_date.getDay();x<6;x++)
			{
				cal_HTML = cal_HTML+'<TD CLASS="calendar_day_empty" TITLE="'+get_month(temp_date.getMonth()+2)+'">&nbsp;</TD>';
			}
			cal_HTML = cal_HTML+'</TR>';
		}
		cal_HTML = cal_HTML+'</TABLE>';
		//write calendar HTML to calendar DIV tag
		document.all.calendar.innerHTML = cal_HTML;
	}
	
	calendar_init();
