
var padDigits=function(n,totalDigits){n=n.toString();var pd='';if(totalDigits>n.length)
for(var i=totalDigits-n.length;i>0;i--)
pd+='0';return pd+n.toString();}
function Calendar(resultInputId_,chooseDateOnclick_,dateFormatRegExp_,calendarDateSeparator_,multipleSelection_,dontCloseIt_){var currentMonth=null;var dates=new Array();var resultInputId=resultInputId_;var chooseDateOnclick=chooseDateOnclick_;var reFormat=dateFormatRegExp_;var calendarDateSeparator=calendarDateSeparator_;var multipleSelection=multipleSelection_;var dontCloseIt=dontCloseIt_;var isCalendarOpen=false;this.nGetFirstDay=function(nMonth,nYear){var dDate=new Date(nYear%100,--nMonth,0);var nFirstDay=dDate.getDay();if(nFirstDay==0)nFirstDay=7;return nFirstDay;};this.bCheckLeapYear=function(nYear){nYear=parseInt(nYear);if(nYear%4==0)
return(nYear%100!=0)?true:(nYear%400==0);return false;};this.nGetMonthDays=function(nMonth,nYear){var bLeapYear=this.bCheckLeapYear(nYear);if(nMonth==2)return bLeapYear?29:28;if((nMonth==4)||(nMonth==6)||(nMonth==9)||(nMonth==11))
return 30
else
return 31;};this.calDateValidation=function(sDate){if(reFormat.test(sDate)){var nDay=sDate.split(calendarDateSeparator)[0];var nMonth=sDate.split(calendarDateSeparator)[1];var nYear=sDate.split(calendarDateSeparator)[2];if(Number(nMonth)==0){nMonth='12';nYear=Number(nYear)-1;}
var dDate=new Date(nYear,nMonth-1,nDay);return((dDate.getMonth()+1==nMonth)&&(dDate.getDate()==nDay)&&(dDate.getFullYear()==nYear));}
return false;};this.sDMYtoDate=function(nDay,nMonth,nYear){var sDate=padDigits(nDay,2);sDate+=calendarDateSeparator+padDigits(nMonth,2);sDate+=calendarDateSeparator+nYear;return sDate;};this.nCorrectLastDay=function(nDay,nMonth,nYear){if(nDay>28){while(nDay>1&&!this.calDateValidation(this.sDMYtoDate(nDay,nMonth,nYear))){nDay--;}}
return nDay;};this.calMonthsDef=["January","February","March","April","May","June","July","August","September","October","November","December"];this.calDaysShortDef=["M","T","W","T","F","S","S"];this.createCalendar=function(){if(this.getCurrentMonth()==null){if(dates!=null&&dates.length>0){this.setCurrentMonth(new Date());this.getCurrentMonth().setDate(1);this.getCurrentMonth().setFullYear(dates[0].getFullYear());this.getCurrentMonth().setMonth(dates[0].getMonth());this.getCurrentMonth().setDate(dates[0].getDate());}else{this.setCurrentMonth(new Date());}}
if($('currentCalendarViewYear')!=null){$('currentCalendarViewYear').value=this.getCurrentMonth().getFullYear();}
var nDay=this.getCurrentMonth().getDate();var nMonth=this.getCurrentMonth().getMonth();var nYear=this.getCurrentMonth().getFullYear();var sMonths=(typeof(calMonths)=="undefined")?calMonthsDef:calMonths;var sDaysShort=(typeof(calDaysShort)=="undefined")?calDaysShortDef:calDaysShort;var refresh="document.getElementById('calendar_"+resultInputId+"').style.display = 'none';document.getElementById('calendar_"+resultInputId+"').style.display = '';";var sEmptyCell='<td class="empty">&nbsp;</td>';var sEmptyCell1='<td class="empty"><a href="javascript:'+resultInputId+'.selectDateAndUpdateCalendarView(';var sEmptyCell2=');selectDateOnClick_'+resultInputId+'(true); '+chooseDateOnclick+'"><font class="empty">';var sEmptyCellClose='</font></a></td>';var sCellOpen1='<td><a href="javascript:'+resultInputId+'.selectDateAndUpdateCalendarView(';var sCellOpen2=');selectDateOnClick_'+resultInputId+'(true); '+chooseDateOnclick+'">';var sCellSelected='<td class="selected"><a style="cursor: default;" href="javascript:selectDateOnClick_'+resultInputId+'(true);">';var sCellClose='</a></td>';var currentFirstDay=this.nGetFirstDay(nMonth+1,nYear);var previousMonthDays=this.nGetMonthDays(nMonth==0?12:nMonth,nMonth==0?nYear-1:nYear);var currentMonthDays=this.nGetMonthDays(nMonth+1,nYear);var sContent='';var nCurrent=1;document.getElementById("calendarTitle_"+resultInputId).innerHTML=sMonths[nMonth]+' '+nYear;sContent+='<table><tr>';for(var i=0;i<=6;i++)
sContent+='<th>'+sDaysShort[i]+'</th>';sContent+='</tr>';sContent+='<tr>';for(var i=currentFirstDay;i>1;i--){var previousMonth=nMonth-1;var previousMonthYear=nYear;if(previousMonth==-1){previousMonth=11;previousMonthYear--;}
if(isDaySelected(new Date(previousMonthYear,previousMonth,(previousMonthDays-i+2)))){sContent+=sCellSelected+(previousMonthDays-i+2)+sCellClose;;}else{sContent+=sEmptyCell1+previousMonthYear+','+previousMonth+','+(previousMonthDays-i+2)+sEmptyCell2+(previousMonthDays-i+2)+sEmptyCellClose;}}
for(nCurrent=1;currentFirstDay+nCurrent<=8;nCurrent++){sContent+=(isDaySelected(new Date(nYear,nMonth,nCurrent))==true?sCellSelected:(sCellOpen1+nYear+','+nMonth+','+nCurrent+sCellOpen2))
+nCurrent+sCellClose;}
sContent+='</tr>';var k__=1;while(nCurrent<=currentMonthDays){sContent+='<tr>';for(var nWeekDay=1;nWeekDay<=7;nWeekDay++){if(nCurrent<=currentMonthDays){sContent+=(isDaySelected(new Date(nYear,nMonth,nCurrent))==true?sCellSelected:(sCellOpen1+nYear+','+nMonth+','+nCurrent+sCellOpen2))
+nCurrent+sCellClose;}else{var nextMonth=nMonth+1;var nextMonthYear=nYear;if(nextMonth==12){nextMonth=0;nextMonthYear++;}
if(isDaySelected(new Date(nextMonthYear,nextMonth,k__))){sContent+=sCellSelected+k__+sCellClose;;}else{sContent+=sEmptyCell1+nextMonthYear+','+nextMonth+','+k__+sEmptyCell2+k__+sEmptyCellClose;}
k__++;}
nCurrent++;}
sContent+='</tr>';}
sContent+='</table>';document.getElementById("calendarLayout_"+resultInputId).innerHTML=sContent;};var isDaySelected=function(date_){for(var i=0;i<dates.length;i++){if(dates[i].getDate()==date_.getDate()&&dates[i].getMonth()==date_.getMonth()&&dates[i].getFullYear()==date_.getFullYear())
{return true;}}
return false;}
this.calSetDay=function(nDay){this.calSetDateFields(nDay);this.createCalendar();};this.calBack=function(){var nMonth=this.getCurrentMonth().getMonth()+1;var nYear=this.getCurrentMonth().getFullYear();nMonth--;if(nMonth==0){nMonth=12;nYear--;}
this.calSetDateFields(null,nMonth-1,nYear);this.createCalendar();};this.calForward=function(){var nMonth=this.getCurrentMonth().getMonth()+1;var nYear=this.getCurrentMonth().getFullYear();nMonth++;if(nMonth==13){nMonth=1;nYear++;}
this.calSetDateFields(null,nMonth-1,nYear);this.createCalendar();};this.calSetDateFields=function(nDay,nMonth,nYear){if(nDay==null)nDay=this.getCurrentMonth().getDate();if(nMonth==null)nMonth=this.getCurrentMonth().getMonth();if(nYear==null)nYear=this.getCurrentMonth().getFullYear();nDay=this.nCorrectLastDay(nDay,nMonth,nYear);this.getCurrentMonth().setDate(1);this.getCurrentMonth().setFullYear(nYear);this.getCurrentMonth().setMonth(nMonth);if(daysPerMonth[nMonth+1]<nDay){nDay=daysPerMonth[nMonth+1];}
this.getCurrentMonth().setDate(nDay);};this.calOpen=function(obj,sFieldId,event,useDateFromElement){if(!((typeof checkCalendarOpening)=="undefined")&&!locationDropdown)return;if(!((typeof checkCalendarOpening)=="undefined")&&$('popup').style.display=='block')return;var sDate="";this.setCurrentMonth(null);if(sFieldId!=null&&sFieldId!=""){sDate=normalizeDateFormat(document.getElementById(sFieldId).value);var d;if(this.calDateValidation(sDate)){d=new Date(sDate.split(calendarDateSeparator)[2],sDate.split(calendarDateSeparator)[1]-1,sDate.split(calendarDateSeparator)[0]);}else{if(useDateFromElement!=null&&document.getElementById(useDateFromElement)!=null&&this.calDateValidation(document.getElementById(useDateFromElement).value))
{sDate=document.getElementById(useDateFromElement).value;d=new Date(sDate.split(calendarDateSeparator)[2],sDate.split(calendarDateSeparator)[1]-1,sDate.split(calendarDateSeparator)[0]);}else{d=new Date();}}
this.setDate(d);}else{this.createCalendar();}
var position=findPos(obj);document.getElementById('calendar_'+resultInputId).style.top=position[1]+endPx();document.getElementById('calendar_'+resultInputId).style.left=position[0]+endPx();if(multipleSelection==true){document.getElementById('calendar_'+resultInputId).style.display="block";}else{if(dontCloseIt){document.getElementById('calendar_'+resultInputId).style.display="block";}else{dropdown(event,'calendar_'+resultInputId,'closeCalendar',function(){hideModal('calendar_overlay');});}}};function findPos(obj){var curleft=curtop=0;if(obj!=null){var originalObj=obj;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}}
if(originalObj.id==$('offerListFragment').id){var pageSize=_getPageSize();curleft=(pageSize.windowWidth-207)/2;}}else{var pageSize=_getPageSize();curleft=(pageSize.windowWidth-207)/2;var pos=_realOffset(document.body);var height=200;curtop=pageSize.windowHeight/2-height/2+pos[1];if(curtop<0){curtop=0;}}
return[curleft,curtop];};this.getValue=function(){if(dates!=null&&dates[0]!=null){return dates[0].getDate()+dateFormatSeparator+(dates[0].getMonth()+1)+dateFormatSeparator+dates[0].getFullYear();}else{return null;}}
this.calClose=function(doNotSetValue){var temp=document.getElementById(resultInputId);if(temp!=null&&doNotSetValue!=true){temp.value=this.getValue();}
document.getElementById('calendar_'+resultInputId).style.display="none";hideModal('calendar_overlay');};this.setDates=function(dates_){dates=dates_;this.createCalendar();}
this.setDate=function(date_){dates=new Array();dates[0]=date_;this.createCalendar();}
this.getDates=function(){return dates;};this.getCurrentMonth=function(){return currentMonth;}
this.setCurrentMonth=function(currentMonth_){currentMonth=currentMonth_;}
this.changeYear=function(year_){this.getCurrentMonth().setFullYear(year_);$('currentCalendarViewYear').value=year_;dropdown('event','periodYearSelect');this.createCalendar();}
this.selectDateAndUpdateCalendarView=function(year_,month_,day_){selectDate(year_,month_,day_);this.createCalendar();}
this.clearDate=function(){dates=new Array();this.createCalendar();}
var selectDate=function(year_,month_,day_){if(multipleSelection==true){dates[dates.length]=new Date(year_,month_,day_);}else{dates[0]=new Date(year_,month_,day_);}}
this.removeDateAndUpdateCalendarView=function(year_,month_,day_){removeDate(year_,month_,day_);this.createCalendar();}
var removeDate=function(year_,month_,day_){var theDate=new Date(year_,month_,day_);for(var i=0;i<dates.length;i++){if(dates[i].getDate()==theDate.getDate()&&dates[i].getMonth()==theDate.getMonth()&&dates[i].getFullYear()==theDate.getFullYear())
{for(var j=i;j<dates.length-1;j++){dates[j]=dates[j+1];}
dates[dates.length-1]=null;dates.length=dates.length-1;break;}}}};