
function Telligent_DateTimeSelector(varName,stateId,pattern,yearIndex,monthIndex,dayIndex,hourIndex,minuteIndex,amPmIndex,showPopup,allowBlankValue,onChangedFunction)
{this._variableName=varName;this._initialized=false;this._yearIndex=yearIndex;this._monthIndex=monthIndex;this._dayIndex=dayIndex;this._hourIndex=hourIndex;this._minuteIndex=minuteIndex;this._amPmIndex=amPmIndex;this._showPopup=showPopup;this._allowBlankValue=allowBlankValue;this._patternedTextBox=null;this._onChangedFunction=onChangedFunction;this._popupButton=null;this._stateId=stateId;this._state=document.getElementById(this._stateId);this._pattern=pattern;setTimeout(new Function(this._variableName+'._initialize();'),9);Telligent_Common.RegisterDisposableControl(this._variableName);if(this._state)
this._state.dispose=new Function(this._variableName+'.Dispose();');}
Telligent_DateTimeSelector.prototype.Dispose=function()
{this._state=null;this._patternedTextBox=null;this._popupButton=null;}
Telligent_DateTimeSelector.prototype._changed=function()
{if(this._onChangedFunction)
this._onChangedFunction(this);}
Telligent_DateTimeSelector.prototype._initialize=function()
{this._patternedTextBox=new Telligent_PatternedTextBox(this._variableName+'._patternedTextBox',this._stateId,this._pattern,this._allowBlankValue,'_',new Function('values','type','modifiedIndex','return '+this._variableName+'._validateDate(values, type, modifiedIndex);'),new Function(this._variableName+'._changed();'));if(this._showPopup&&this._state)
{this._popupButton=document.createElement('img');this._popupButton.src=Telligent_DateTimeSelector._calendarImageUrl;this._popupButton.style.borderTopWidth='1px';this._popupButton.style.borderLeftWidth='1px';this._popupButton.style.borderRightWidth='1px';this._popupButton.style.borderBottomWidth='1px';this._popupButton.style.borderTopStyle='solid';this._popupButton.style.borderLeftStyle='solid';this._popupButton.style.borderRightStyle='solid';this._popupButton.style.borderBottomStyle='solid';this._popupButton.style.borderTopColor=Telligent_Common.GetCurrentStyleValue(this._state,'border-top-color','borderTopColor','#999');this._popupButton.style.borderLeftColor=Telligent_Common.GetCurrentStyleValue(this._state,'border-left-color','borderLeftColor','#999');this._popupButton.style.borderRightColor=Telligent_Common.GetCurrentStyleValue(this._state,'border-right-color','borderRightColor','#999');this._popupButton.style.borderBottomColor=Telligent_Common.GetCurrentStyleValue(this._state,'border-bottom-color','borderBottomColor','#999');this._popupButton.style.padding='2px';this._popupButton.align='top';this._popupButton.style.marginLeft='2px';this._popupButton.style.backgroundColor=Telligent_Common.GetCurrentStyleValue(this._state,'background-color','backgroundColor','#fff');var index=-1;for(var i=0;i<this._state.parentNode.childNodes.length&&index==-1;i++)
{if(this._state.parentNode.childNodes[i]==this._state)
index=i;}
if(index>-1&&index+1<this._state.parentNode.childNodes.length)
this._state.parentNode.insertBefore(this._popupButton,this._state.parentNode.childNodes[index+1]);else
this._state.parentNode.appendChild(this._popupButton);}
if(this._patternedTextBox.IsDisabled())
this.Disable();else
this.Enable();this._initialized=true;}
Telligent_DateTimeSelector.prototype._popup=function(element)
{Telligent_DateTimeSelector.Open(element,this,this.GetDate());}
Telligent_DateTimeSelector.prototype._validateDate=function(values,type,modifiedIndex)
{if(!this._initialized||this._monthIndex<0||this._dayIndex<0)
return values;var month=this._getMonthNumber(values[this._monthIndex]);var day=parseInt(values[this._dayIndex],10);var year=-1;if(this._yearIndex>=0)
year=parseInt(values[this._yearIndex],10);if(isNaN(month)||isNaN(day))
return values;var newDay=values[this._dayIndex];if(month==2)
{if(!isNaN(year)&&year>-1&&((year%4==0&&year%100!=0)||year%400==0))
{if(day>29)
{if(modifiedIndex==this._dayIndex&&type=='next')
newDay="01";else
newDay="29";}}
else if(day>28)
{if(modifiedIndex==this._dayIndex&&type=='next')
newDay="01";else
newDay="28";}}
else if((month==4||month==6||month==9||month==11)&&day>30)
{if(modifiedIndex==this._dayIndex&&type=='next')
newDay="01";else
newDay="30";}
values[this._dayIndex]=newDay;return values;}
Telligent_DateTimeSelector.prototype._getMonthNumber=function(value)
{var pattern=this._patternedTextBox._getPatternByIndex(this._monthIndex);if(!pattern)
return parseInt('NaN');if(pattern._patternType=='option')
{value=value.toLowerCase();for(var i=0;i<pattern._options.length;i++)
{if(pattern._options[i].toLowerCase()==value)
return i+1;}
return parseInt('NaN');}
else
return parseInt(value,10);}
Telligent_DateTimeSelector.prototype._get24Hour=function(value,amPmValue)
{var amPmPattern=this._patternedTextBox._getPatternByIndex(this._amPmIndex);var hours=parseInt(value,10);if(isNaN(hours))
return hours;var addHours=0;if(amPmPattern&&amPmPattern._patternType=='option')
{amPmValue=amPmValue.toLowerCase();for(var i=0;i<amPmPattern._options.length;i++)
{if(amPmPattern._options[i].toLowerCase()==amPmValue)
{if(i==0)
{if(hours==12)
hours=0;}
else if(i==1)
{if(hours!=12)
hours+=12;}}}}
return hours;}
Telligent_DateTimeSelector.prototype._getMonthValue=function(number)
{var pattern=this._patternedTextBox._getPatternByIndex(this._monthIndex);if(!pattern)
return parseInt('NaN');if(pattern._patternType=='option'&&number>0&&number<=pattern._options.length)
return pattern._options[number-1];else
return parseInt(number,10);}
Telligent_DateTimeSelector.prototype._getHourValue=function(hour)
{var amPmPattern=this._patternedTextBox._getPatternByIndex(this._amPmIndex);if(amPmPattern&&amPmPattern._patternType=='option'&&hour>12)
return hour-12;else
return hour;}
Telligent_DateTimeSelector.prototype._getAmPmValue=function(hour)
{var amPmPattern=this._patternedTextBox._getPatternByIndex(this._amPmIndex);if(amPmPattern&&amPmPattern._patternType=='option'&&amPmPattern._options.length==2)
{if(hour>=12)
return amPmPattern._options[1];else
return amPmPattern._options[0];}
else
return'';}
Telligent_DateTimeSelector.prototype.GetDate=function()
{var values=this._patternedTextBox.GetPatternValues();var date;var year,month,day;if(this._yearIndex>=0)
{year=parseInt(values[this._yearIndex],10);if(isNaN(year))
return null;}
else
year=(new Date()).getFullYear();if(this._dayIndex>=0)
{day=parseInt(values[this._dayIndex],10);if(isNaN(day))
return null;}
else
day=(new Date()).getDate();if(this._monthIndex>=0)
{month=this._getMonthNumber(values[this._monthIndex])-1;if(isNaN(month))
return null;}
else
month=(new Date()).getMonth();date=new Date(year,month,day);if(this._hourIndex>=0)
{var hour=parseInt(values[this._hourIndex],10);if(!isNaN(hour))
{if(this._amPmIndex>=0)
date.setHours(this._get24Hour(hour,values[this._amPmIndex]));else
date.setHours(this._get24Hour(hour,-1));}
else
return null;}
if(this._minuteIndex>=0)
{var minute=parseInt(values[this._minuteIndex],10);if(!isNaN(minute))
date.setMinutes(minute);else
return null;}
return date;}
Telligent_DateTimeSelector.prototype.SetDate=function(date)
{var values=this._patternedTextBox.GetPatternValues();if(this._yearIndex>=0)
values[this._yearIndex]=date.getFullYear();if(this._monthIndex>=0)
values[this._monthIndex]=this._getMonthValue(date.getMonth()+1);if(this._dayIndex>=0)
values[this._dayIndex]=date.getDate();if(this._hourIndex>=0)
values[this._hourIndex]=this._getHourValue(date.getHours());if(this._minuteIndex>=0)
values[this._minuteIndex]=date.getMinutes();if(this._amPmIndex>=0)
values[this._amPmIndex]=this._getAmPmValue(date.getHours());this._patternedTextBox.SetPatternValues(values);}
Telligent_DateTimeSelector.prototype.Disable=function()
{this._patternedTextBox.Disable();if(this._popupButton)
{this._popupButton.style.cursor='default';this._popupButton.onclick=null;}}
Telligent_DateTimeSelector.prototype.Enable=function()
{this._patternedTextBox.Enable();if(this._popupButton)
{this._popupButton.style.cursor='pointer';this._popupButton.onclick=new Function(this._variableName+'._popup(this);');}}
Telligent_DateTimeSelector.prototype.IsDisabled=function()
{return this._patternedTextBox.IsDisabled();}
Telligent_DateTimeSelector._popupPanel=null;Telligent_DateTimeSelector._currentDateTimeSelector=null;Telligent_DateTimeSelector._currentDate=new Date();Telligent_DateTimeSelector._currentYear=Telligent_DateTimeSelector._currentDate.getFullYear();Telligent_DateTimeSelector._currentMonth=Telligent_DateTimeSelector._currentDate.getMonth()+1;Telligent_DateTimeSelector._monthNames=new Array();Telligent_DateTimeSelector._dayNames=new Array();Telligent_DateTimeSelector._calendarImageUrl=null;Telligent_DateTimeSelector._previousImageUrl=null;Telligent_DateTimeSelector._nextImageUrl=null;Telligent_DateTimeSelector.Initialize=function(monthNames,dayNames,calendarImageUrl,previousImageUrl,nextImageUrl)
{Telligent_DateTimeSelector._monthNames=monthNames;Telligent_DateTimeSelector._dayNames=dayNames;Telligent_DateTimeSelector._calendarImageUrl=calendarImageUrl;Telligent_DateTimeSelector._previousImageUrl=previousImageUrl;Telligent_DateTimeSelector._nextImageUrl=nextImageUrl;Telligent_DateTimeSelector._popupPanel=new Telligent_PopupPanel('Telligent_DateTimeSelector._popupPanel','','updown',1000,null,null,true,'')}
Telligent_DateTimeSelector.Refresh=function()
{if(!Telligent_DateTimeSelector._popupPanel||!Telligent_DateTimeSelector._currentDateTimeSelector)
return;Telligent_DateTimeSelector._popupPanel.ClearPanelContent();var container=document.createElement('div');container.style.borderTopWidth='1px';container.style.borderLeftWidth='1px';container.style.borderRightWidth='1px';container.style.borderBottomWidth='1px';container.style.borderTopStyle='solid';container.style.borderLeftStyle='solid';container.style.borderRightStyle='solid';container.style.borderBottomStyle='solid';container.style.borderTopColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'border-top-color','borderTopColor','#999');container.style.borderLeftColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'border-left-color','borderLeftColor','#999');container.style.borderRightColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'border-right-color','borderRightColor','#999');container.style.borderBottomColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'border-bottom-color','borderBottomColor','#999');container.style.fontFamily=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'font-family','fontFamily','Arial, Helvetica');container.style.backgroundColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'background-color','backgroundColor','#fff');container.style.padding='2px';container.style.fontSize=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'font-size','fontSize','9pt');container.style.color=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000');var table=document.createElement('table');table.cellPadding=0;table.cellSpacing=0;table.style.borderWidth='0px';container.appendChild(table);var tbody=document.createElement('tbody');table.appendChild(tbody);var tr=document.createElement('tr');var td=document.createElement('td');td.style.textAlign='center';td.style.padding='2px';td.onclick=new Function('Telligent_DateTimeSelector._prev();');td.style.cursor='pointer';var img=document.createElement('img');img.width='5';img.height='9';img.src=Telligent_DateTimeSelector._previousImageUrl;img.style.borderWidth='0px';td.appendChild(img);tr.appendChild(td);td=document.createElement('td');td.style.textAlign='center';td.style.padding='2px';td.style.fontWeight='bold';td.style.fontSize='90%';td.colSpan=5;td.innerHTML=Telligent_DateTimeSelector._monthNames[Telligent_DateTimeSelector._currentMonth-1]+' '+Telligent_DateTimeSelector._currentYear;tr.appendChild(td);td=document.createElement('td');td.style.textAlign='center';td.style.padding='2px';td.onclick=new Function('Telligent_DateTimeSelector._next();');td.style.cursor='pointer';img=document.createElement('img');img.width='5';img.height='9';img.src=Telligent_DateTimeSelector._nextImageUrl;img.style.borderWidth='0px';td.appendChild(img);tr.appendChild(td);tbody.appendChild(tr);tr=document.createElement('tr');for(var i=0;i<Telligent_DateTimeSelector._dayNames.length;i++)
{td=document.createElement('td');td.innerHTML=Telligent_DateTimeSelector._dayNames[i];td.style.textAlign='center';td.style.padding='2px';td.style.fontWeight='bold';td.style.borderBottomWidth='1px';td.style.borderBottomStyle='solid';td.style.fontSize='90%';td.style.width='14%';td.style.borderBottomColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'border-bottom-color','borderBottomColor','#999');tr.appendChild(td);}
tbody.appendChild(tr);var tempDate=new Date(Telligent_DateTimeSelector._currentYear,Telligent_DateTimeSelector._currentMonth-1,1);tr=document.createElement('tr');var lastDayOfWeek=0;var rowsLeft=5;while(lastDayOfWeek<tempDate.getDay())
{td=document.createElement('td');td.innerHTML='&nbsp;';td.style.fontSize='90%';td.style.padding='2px';td.style.textAlign='center';td.style.width='14%';tr.appendChild(td);lastDayOfWeek++;}
var daysInMonth=31;if(Telligent_DateTimeSelector._currentMonth==2)
{if(!isNaN(Telligent_DateTimeSelector._currentYear)&&Telligent_DateTimeSelector._currentYear>-1&&((Telligent_DateTimeSelector._currentYear%4==0&&Telligent_DateTimeSelector._currentYear%100!=0)||Telligent_DateTimeSelector._currentYear%400==0))
daysInMonth=29;else
daysInMonth=28;}
else if(Telligent_DateTimeSelector._currentMonth==4||Telligent_DateTimeSelector._currentMonth==6||Telligent_DateTimeSelector._currentMonth==9||Telligent_DateTimeSelector._currentMonth==11)
daysInMonth=30;var currentDay=-1;if(Telligent_DateTimeSelector._currentMonth==Telligent_DateTimeSelector._currentDate.getMonth()+1&&Telligent_DateTimeSelector._currentYear==Telligent_DateTimeSelector._currentDate.getFullYear())
currentDay=Telligent_DateTimeSelector._currentDate.getDate();var mouseOverScript='this.style.color = \''+Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'background-color','backgroundColor','#fff')+'\'; this.style.backgroundColor = \''+Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000')+'\';';var mouseOutScript='this.style.color = \''+Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000')+'\'; this.style.backgroundColor = \''+Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'background-color','backgroundColor','#fff')+'\';';for(var i=1;i<=daysInMonth;i++)
{lastDayOfWeek++;td=document.createElement('td');td.style.textAlign='center';td.style.padding='2px';td.style.fontSize='90%';td.innerHTML=i;td.onclick=new Function('Telligent_DateTimeSelector._click('+i+');');td.onmouseover=new Function(mouseOverScript);td.onmouseout=new Function(mouseOutScript);td.style.cursor='pointer';td.style.width='14%';if(i==currentDay)
{td.style.padding='1px';td.style.borderTopWidth='1px';td.style.borderLeftWidth='1px';td.style.borderRightWidth='1px';td.style.borderBottomWidth='1px';td.style.borderTopStyle='solid';td.style.borderLeftStyle='solid';td.style.borderRightStyle='solid';td.style.borderBottomStyle='solid';td.style.borderTopColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000');td.style.borderLeftColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000');td.style.borderRightColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000');td.style.borderBottomColor=Telligent_Common.GetCurrentStyleValue(Telligent_DateTimeSelector._currentDateTimeSelector._state,'color','color','#000');}
tr.appendChild(td);if(lastDayOfWeek==7)
{lastDayOfWeek=0;tbody.appendChild(tr);tr=document.createElement('tr');rowsLeft--;}}
while(lastDayOfWeek<7)
{td=document.createElement('td');td.innerHTML='&nbsp;';td.style.fontSize='90%';td.style.padding='2px';td.style.textAlign='center';td.style.width='14%';tr.appendChild(td);lastDayOfWeek++;}
tbody.appendChild(tr);while(rowsLeft>0)
{rowsLeft--;tr=document.createElement('tr');for(var i=0;i<7;i++)
{td=document.createElement('td');td.innerHTML='&nbsp;';td.style.fontSize='90%';td.style.padding='2px';td.style.textAlign='center';td.style.width='14%';tr.appendChild(td);}
tbody.appendChild(tr);}
Telligent_DateTimeSelector._popupPanel.AddNodeToPanel(container);}
Telligent_DateTimeSelector._next=function()
{Telligent_DateTimeSelector._currentMonth++;if(Telligent_DateTimeSelector._currentMonth>12)
{Telligent_DateTimeSelector._currentMonth=1;if(Telligent_DateTimeSelector._currentYear<9999)
Telligent_DateTimeSelector._currentYear++;}
Telligent_DateTimeSelector.Refresh();}
Telligent_DateTimeSelector._prev=function()
{Telligent_DateTimeSelector._currentMonth--;if(Telligent_DateTimeSelector._currentMonth<1)
{Telligent_DateTimeSelector._currentMonth=12;if(Telligent_DateTimeSelector._currentYear>0)
Telligent_DateTimeSelector._currentYear--;}
Telligent_DateTimeSelector.Refresh();}
Telligent_DateTimeSelector._click=function(day)
{if(Telligent_DateTimeSelector._currentDateTimeSelector)
{var d=Telligent_DateTimeSelector._currentDateTimeSelector.GetDate();if(d==null)
d=new Date();d=new Date(Telligent_DateTimeSelector._currentYear,Telligent_DateTimeSelector._currentMonth-1,day,d.getHours(),d.getMinutes(),d.getMilliseconds());var d2=Telligent_DateTimeSelector._currentDateTimeSelector.GetDate();if(!d2||d2.getTime()!=d.getTime())
{Telligent_DateTimeSelector._currentDateTimeSelector.SetDate(d);Telligent_DateTimeSelector._currentDateTimeSelector._changed();}
Telligent_DateTimeSelector.Close();}}
Telligent_DateTimeSelector.Open=function(element,dateTimeSelector,currentDate)
{if(dateTimeSelector==Telligent_DateTimeSelector._currentDateTimeSelector)
{Telligent_DateTimeSelector.Close();}
Telligent_DateTimeSelector._currentDateTimeSelector=dateTimeSelector;if(!currentDate)
currentDate=new Date();Telligent_DateTimeSelector._currentDate=currentDate;Telligent_DateTimeSelector._currentMonth=currentDate.getMonth()+1;Telligent_DateTimeSelector._currentYear=currentDate.getFullYear();this.Refresh();Telligent_DateTimeSelector._popupPanel.ShowAtElement(element);}
Telligent_DateTimeSelector.Close=function()
{Telligent_DateTimeSelector._popupPanel.Hide();Telligent_DateTimeSelector._currentDateTimeSelector=null;};