var standardcalendar=1;var begin_limitedcalendar=2;var begin_end_limitedcalendar=3;function Calendar(name,calendarconfig){this.name=name;this.type=calendarconfig['calendar']['type'];this.today=calendarconfig['calendar']['today'];this.limit=calendarconfig['calendar']['limit'];this.today_ini=this.today;this.limit_ini=this.limit;this.strdaysel=null;this.daysel=null;this.strdayref=null;this.dayref=null;this.onassign=null;this.opened=false;this.container=new Container(name,calendarconfig['cont']);this.select=Calendar_select;this.write=Calendar_write;this.change=Calendar_change;this.assign=Calendar_assign;this.reset=Calendar_reset;this.setassign=Calendar_setassign;this.settype=Calendar_settype;this.getConfigDefault=Calendar_getConfigDefault;this.monthprev=Calendar_monthprev;this.monthnext=Calendar_monthnext;this.firstDay=getWeekStart();this.weekdays=getWeekDays();if(this.firstDay){this.weekdays[7]=this.weekdays[0];}}function Calendar_select(selected,area,date,ref){var year=0;var month=0;if(this.type==standardcalendar){this.today=date[1];month=this.today.getMonth()+6;year=this.today.getFullYear();if(month>11){month=this.today.getMonth()-6;year+=1;}this.limit=new Date(year,month);this.limit=new Date(this.limit.getFullYear(),this.limit.getMonth(),this.limit.getDate()-1);month=this.today.getMonth()-6;year=this.today.getFullYear();if(month<0){month=this.today.getMonth()+6;year-=1;}this.today=new Date(year,month,1);}else if(this.type==begin_limitedcalendar){this.today=date[1];month=this.today.getMonth()-6;year=this.today.getFullYear();if(month<0){month=this.today.getMonth()+6;year-=1;}var tmpDate=new Date(year,month,1);if(tmpDate>=this.today_ini){this.today=tmpDate;}else{this.today=this.today_ini;}month=this.today.getMonth()+1;year=this.today.getFullYear()+1;this.limit=new Date(year,month);this.limit=new Date(this.limit.getFullYear(),this.limit.getMonth(),this.limit.getDate()-1);this.limit_ini=this.limit;}this.strdaysel=date[0];this.daysel=date[1];this.strdayref=ref[0];this.dayref=ref[1];this.selected=selected;this.year=date[1].getFullYear();this.month=date[1].getMonth();this.container.settitle(date[0]);this.container.init(area,this);this.opened=true;return;}function Calendar_reset(){this.onassign.setDatefromCalendar(this.daysel,this.selected);this.today=this.today_ini;this.limit=this.limit_ini;this.opened=false;}function Calendar_monthprev(){var month=this.month;var year=this.year;if(month==0){year=year-1;month=11;}else month=month-1;this.change(year+";"+month);return;}function Calendar_monthnext(){var month=this.month;var year=this.year;if(month==11){year=year+1;month=0;}else month=month+1;this.change(year+";"+month);return;}function Calendar_change(datecoded){this.changing=true;datecoded=datecoded.split(';');var month;var year;if(this.type==standardcalendar){month=parseInt(datecoded[1])+6;year=parseInt(datecoded[0]);if(month>11){month=parseInt(datecoded[1])-6;year+=1;}this.limit=new Date(year,month);this.limit=new Date(this.limit.getFullYear(),this.limit.getMonth(),this.limit.getDate()-1);month=parseInt(datecoded[1])-6;year=parseInt(datecoded[0]);if(month<0){month=parseInt(datecoded[1])+6;year-=1;}this.today=new Date(year,month,1);}else if(this.type==begin_limitedcalendar){month=parseInt(datecoded[1])-6;year=parseInt(datecoded[0]);if(month<0){month=parseInt(datecoded[1])+6;year-=1;}var tmpDate=new Date(year,month,1);if(tmpDate>=this.today_ini){this.today=tmpDate;}else{this.today=this.today_ini;}month=this.today.getMonth()+1;year=this.today.getFullYear()+1;this.limit=new Date(year,month);this.limit=new Date(this.limit.getFullYear(),this.limit.getMonth(),this.limit.getDate()-1);this.limit_ini=this.limit;}this.year=parseInt(datecoded[0]);this.month=parseInt(datecoded[1]);this.write();return true;}function Calendar_assign(year,month,day){var date=new Date(year,month,day);this.onassign.setDatefromCalendar(date,this.selected);if(this.container.content==window_areacontainer&&this.container.areac!=null){this.container.areac.close();this.container.areac=null;}this.opened=false;return;}function Calendar_setassign(assign_object){this.onassign=assign_object;}function Calendar_settype(type){this.type=type;}function Calendar_write(){var year=this.year;var month=this.month;var days=getdaystoshow(year,month,this.firstDay);var start=1;var startok=1;var end=days[0];var endok=end;var ds=-1;var strds=false;var df=-1;var strdf=false;var waitbegin=false;var wait=false;var begin=false;var end=false;days=days[1];var firstdaymonth=new Date(year,month,1);if(days[0]>23){if(month-1<0){var dateini=new Date(year-1,11,days[0]);}else{var dateini=new Date(year,month-1,days[0]);}}else{var dateini=firstdaymonth;}var lastdaymonth=new Date(year,month+1,1);lastdaymonth=new Date(lastdaymonth.getFullYear(),lastdaymonth.getMonth(),lastdaymonth.getDate()-1);if(lastdaymonth.getDate()<days[days.length]){var dateend=new Date(year,month+1,days[days.length]);}else{var dateend=lastdaymonth;}if(this.type==begin_limitedcalendar||this.type==begin_end_limitedcalendar){if(dateini<=this.today){var dateiniok=this.today;}else{var dateiniok=dateini;}}if(this.type==begin_end_limitedcalendar){if(dateend>=this.limit){var dateendok=this.limit;}else{var dateendok=dateend;}}if(this.daysel>=dateini&&this.daysel<=dateend){strds=true;}if(this.dayref>=dateini&&this.dayref<=dateend){strdf=true;}var months=getmonthstoshow(this.today,this.limit);var codearea='<table class="bodycal" cellspacing="1">';codearea+='<thead><tr><th class="hmonths" colspan="7">';if((this.type==begin_limitedcalendar||this.type==begin_end_limitedcalendar)&&!dates_equals(dateiniok,this.today))codearea+='<span style="cursor:pointer;cursor:hand;" onclick="'+this.name+'.monthprev()"><<&nbsp;</span>';codearea+='<select class="cal-sel" id="newmonth" name="newmonth" ';codearea+=' onchange="'+this.name+'.change(this[this.selectedIndex].value)">';for(var pos in months){var string=months[pos][0]+";"+months[pos][1];if(year==months[pos][0]&&month==months[pos][1]){codearea+='<option value="'+string+'" selected="selected">'+months[pos][2]+'</option>';}else{codearea+='<option value="'+string+'">'+months[pos][2]+'</option>';}}codearea+='</select>';if((this.type==begin_end_limitedcalendar&&!dates_equals(dateendok,this.limit))||this.type==begin_limitedcalendar)codearea+='<span style="cursor:pointer;cursor:hand;" onclick="'+this.name+'.monthnext()">&nbsp;>></span>';codearea+='</th></tr></thead>';codearea+='<tbody><tr>';for(var i=this.firstDay;i<(7+this.firstDay);i++){if(isweekend(i)){codearea+='<td class="wendh">'+this.weekdays[i]+'</td>';}else{codearea+='<td class="wdayh">'+this.weekdays[i]+'</td>';}}codearea+='</tr>';var weekday=this.firstDay;var today=dateini;for(var day in days){if((day%7)==0){codearea+='<tr>';}if(today<dateiniok||today>dateendok){codearea+=unselectable_day(this,today);}else{if(today<firstdaymonth||today>lastdaymonth){codearea+=no_day_month(this,today,this.name);}else{codearea+=day_month(this,today,weekday,this.name);}}today=new Date(today.getFullYear(),today.getMonth(),today.getDate()+1);weekday++;}if(strds||strdf){codearea+='</tbody></table><br />';codearea+='<table cellspacing="0" border="0" class="leyenda"><tr>';if(strds){codearea+='<td class="leyenda" style="width:40%">'+this.strdaysel+'</td>';codearea+='<td class="today" style="width:3%">&nbsp;</td>';}if(strdf){codearea+='<td class="leyenda" style="width:40%">'+this.strdayref+'</td>';codearea+='<td class="refday" style="width:3%">&nbsp;</td>';}codearea+='</tr></table>';}else{codearea+='</tbody></table>';}this.container.write(codearea);return true;function unselectable_day(cal,today){return '<th class="nday">'+today.getDate()+'</th>';}function no_day_month(cal,today,name){var year=today.getFullYear();var month=today.getMonth();var day=today.getDate();var onclickhtml='onclick="'+name+'.assign('+year+','+month+','+day+')"';var html='<span '+onclickhtml+'>'+day+'</span>';if(dates_equals(today,cal.daysel)){return '<th class="today" '+onclickhtml+'>'+html+'</th>';}else if(dates_equals(today,cal.dayref)){return '<th class="refday" '+onclickhtml+'>'+html+'</th>';}else{return '<th class="ndaymonth" '+onclickhtml+'>'+html+'</th>';}}function day_month(cal,today,weekday,name){var year=today.getFullYear();var month=today.getMonth();var day=today.getDate();var onclickhtml='onclick="'+name+'.assign('+year+','+month+','+day+')"';var html='<span '+onclickhtml+'>'+day+'</span>';if(dates_equals(today,cal.daysel)){return '<th class="today" '+onclickhtml+'>'+html+'</th>';}else if(dates_equals(today,cal.dayref)){return '<th class="refday" '+onclickhtml+'>'+html+'</th>';}else if(isweekend(weekday)){return '<th class="wend" '+onclickhtml+'>'+html+'</th>';}else{return '<th class="wday" '+onclickhtml+'>'+html+'</th>'}}function dates_equals(date1,date2){if(date1.getFullYear()!=date2.getFullYear())return false;else if(date1.getMonth()!=date2.getMonth())return false;else if(date1.getDate()!=date2.getDate())return false;else return true;}function getdaystoshow(year,month,begin){var date=new Date(year,month,1);var daysb=(date.getDay()+6+(1-begin))%7;date.setDate(date.getDate()-daysb);var start=date.getDate();date=lastday(year,month);var endmonth=date.getDate();var daysa=(7-date.getDay()-(1-begin))%7;date.setDate(date.getDate()+daysa);var end=date.getDate();var days_out=[];var pos=0;for(;pos<daysb;pos++,start++){days_out[pos]=start;}for(start=1;start<=endmonth;start++,pos++){days_out[pos]=start;}for(start=1;start<=daysa;start++,pos++){days_out[pos]=start;}return[endmonth,days_out];}function lastday(year,month){var date=new Date(year,month+1,1);date.setDate(date.getDate()-1);return date;}function isweekend(day){var we=day%7;if(we==0||we==6){return true;}else{return false;}}function getmonthstoshow(today,limit){var tyear=today.getFullYear();var tmonth=today.getMonth();var lyear=limit.getFullYear();var lmonth=limit.getMonth();var months=[];var loop=true;for(var i=0;loop;i++){if(env_language!='3'){months[i]=[tyear,tmonth,getMonth(tmonth)+" - "+tyear];}else{months[i]=[tyear,tmonth,tyear+'年'+getMonth(tmonth)];}if(tmonth==11){tmonth=0;tyear++;}else{tmonth++;}if((tmonth>lmonth&&tyear==lyear)||tyear>lyear){loop=false;}}return months;}}function Calendar_getConfigDefault(){var containerconfig=Container_getConfigDefault();var config={};config['calendar']={};config['calendar']['type']=standardcalendar;config['calendar']['today']=new Date();config['calendar']['limit']=new Date();config['cont']=containerconfig;config['cont']['title']="Calendar";config['cont']['csspr']['cssfile']='/css/calendar.css';config['cont']['csspr']['cssn']['body']='iframe';config['cont']['csspr']['cssn']['skin']='calendarskin';config['cont']['csspr']['cssn']['skinframe']='calendarskinini';config['cont']['csspr']['cssn']['title']='titlePop';config['cont']['csspr']['cssn']['content']='contentsPop';config['cont']['csspr']['cssn']['closeon']='closePopin';config['cont']['csspr']['cssn']['closeoff']='closePop';config['cont']['ifrpr']['width']=50;config['cont']['ifrpr']['height']=50;config['cont']['ifrpr']['width_ie5']=193;config['cont']['ifrpr']['height_ie5']=193;config['cont']['ifrpr']['dif_X']=15;config['cont']['ifrpr']['dif_Y']=3;config['cont']['winpr']['name']="MIJSCAL";return config;}
