dojo.provide("msos.calendar");
dojo.require("msos.common");
dojo.require("dojo.date.locale");
dojo.require("dojo.cldr.supplemental");
dojo.require("dojo.dnd.Moveable");
dojo.require("dojo.i18n");
msos.calendar.generate_tool=function(_1,_2,_3){
dojo.requireLocalization("msos","calendar",djConfig.locale);
var _4=dojo.i18n.getLocalization("msos","calendar",djConfig.locale);
var _5=new Date();
this.curr_date=_5.getDate();
this.curr_mon=_5.getMonth();
this.curr_year=_5.getFullYear();
this.cal_date=null;
this.cal_year=null;
this.cal_month=null;
this.cal_inp_elm=_1;
this.cal_window=_2;
this.cal_lang=_4;
this.cal_cfg=_3;
this.focus_value="";
this.suppressed_elements=new Array();
this.on_complete_func=function(){
alert(_4.input_complete);
};
this.mon_name=dojo.date.locale.getNames("months","wide","standAlone",djConfig.locale);
this.long_day=dojo.date.locale.getNames("days","wide","standAlone",djConfig.locale);
this.shrt_day=dojo.date.locale.getNames("days","narrow","standAlone",djConfig.locale);
this.abbr_day=dojo.date.locale.getNames("days","abbr","standAlone",djConfig.locale);
this.first_dow=dojo.cldr.supplemental.getFirstDayOfWeek(djConfig.locale);
this.example_date=function(){
var _6=dojo.date.locale.format(new Date(),_3.std_in_out_date_format);
for(var k=0;k<_3.alt_input_date_formats.length;k++){
_6+=" | "+dojo.date.locale.format(new Date(),_3.alt_input_date_formats[k]);
}
return _6;
};
this.generate_date=function(_8,_9,_a){
return dojo.date.locale.format(new Date(_8,_9,_a),_3.std_in_out_date_format);
};
var _b=this;
this.cal_button_onmouseup=function(){
if(_2.style.visibility=="visible"){
_b.hide_cal_window();
_1.focus();
return false;
}
if(!_b.get_input_date(_1.value)){
_1.focus();
_1.select();
return false;
}
_b.create_cal_window(_b.cal_year,_b.cal_month);
return true;
};
this.input_ondblclick=function(){
if(!_b.get_input_date(_1.value)){
_1.focus();
_1.select();
return false;
}
_b.create_cal_window(_b.cal_year,_b.cal_month);
return true;
};
this.body_onclick=function(_c){
if(!_c.target.id.match(/drag_calendar|calendar_window|cal_footer/)){
_b.hide_cal_window();
}
msos.common.event_debug(_c,"\nCalendar body - onclick");
};
this.input_onfocus=function(_d){
_b.focus_value=_1.value;
msos.common.event_debug(_d,"\nCalendar input - onfocus");
};
this.input_onblur=function(_e){
msos.common.event_debug(_e,"\nCalendar input - onblur");
if(_1.value!=_b.focus_value){
if(!_b.get_input_date(_1.value)){
setTimeout(_b.onblur_delay,100);
return false;
}
if(_b.cal_cfg.exec_on_complete){
_b.on_complete_func();
}
}
return true;
};
this.onblur_delay=function(){
_1.focus();
_1.select();
};
dojo.connect(_1,"onfocus",null,_b.input_onfocus);
dojo.connect(_1,"onblur",null,_b.input_onblur);
dojo.connect(dojo.body(),"onclick",null,_b.body_onclick);
dojo.connect(_1,"ondblclick",null,_b.input_ondblclick);
_1.title=this.cal_lang.input_format_msg+" "+_b.example_date();
if(_3.position_below){
_3.adj_top+=_1.offsetHeight||0;
}
msos.common.set_popup_position(_2,_1,_3);
new dojo.dnd.Moveable(_2);
};
msos.calendar.generate_tool.prototype.hide_cal_window=function(){
this.cal_window.style.visibility="hidden";
this.cal_window.innerHTML="";
if(document.all){
this.restore_ie_objects();
}
this.cal_date=null;
this.cal_month=null;
this.cal_year=null;
};
msos.calendar.generate_tool.prototype.display_cal_window=function(){
if(document.all){
this.suppress_ie_objects();
}
this.cal_window.style.visibility="visible";
};
msos.calendar.generate_tool.prototype.create_cal_window=function(y,m){
this.cal_window.innerHTML="";
console.debug("Create calendar: year -> "+y+", month -> "+m);
var _11=this;
var _12=this.first_dow;
var _13=new Date(y,m,1).getDay();
var _14=m-1;
var _15=m+1;
var _16=y-1;
var _17=y+1;
var _18=y;
var _19=y;
if(_14==-1){
_14=11;
_18--;
}
if(_15==12){
_15=0;
_19++;
}
var _1a=new Date(_18,_14,1);
var _1b=dojo.date.getDaysInMonth(_1a);
var _1c=new Date(_19,_15,1);
var _1d=new Date(_18,_14,_1b);
var _1e=new Date(_16,m,1);
var _1f=dojo.date.getDaysInMonth(_1e);
var _20=new Date(_17,m,1);
var _21=new Date(_16,m,_1f);
var _22="no";
var _23="no";
var _24="no";
var _25="no";
if(!this.cal_cfg.cal_top_date||(this.cal_cfg.cal_top_date&&this.cal_cfg.cal_top_date>_1c)){
_22="yes";
}
if(!this.cal_cfg.cal_bot_date||(this.cal_cfg.cal_bot_date&&this.cal_cfg.cal_bot_date<_1d)){
_23="yes";
}
if(_22=="yes"&&(this.cal_cfg.cal_top_date>_20)){
_24="yes";
}
if(_23=="yes"&&(this.cal_cfg.cal_bot_date<_21)){
_25="yes";
}
var _26=document.createElement("table");
_26.className="cal_table";
var _27=document.createElement("tbody");
var _28=document.createElement("tr");
var _29=document.createElement("th");
var _2a=this.mon_name[m]+" "+y;
if(this.cal_cfg.use_prior_next_links){
if(_25=="yes"){
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.create_cal_window(_16,m);
};
var _2d=document.createElement("a");
_2d.href="javascript:void(0)";
_2d.title="<- "+_16;
_2d.innerHTML=this.cal_cfg.prior_month_text;
dojo.connect(_2d,"onclick",null,_2b);
_29.appendChild(_2d);
}else{
var _2e=document.createElement("span");
_2e.innerHTML=this.cal_cfg.prior_next_na;
_29.appendChild(_2e);
}
if(_23=="yes"){
var _2f=this.mon_name[_14];
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.create_cal_window(_18,_14);
};
var _2d=document.createElement("a");
_2d.href="javascript:void(0)";
_2d.title="<- "+_2f;
_2d.innerHTML=this.cal_cfg.prior_month_text;
dojo.connect(_2d,"onclick",null,_2b);
_29.appendChild(_2d);
}else{
var _2e=document.createElement("span");
_2e.innerHTML=this.cal_cfg.prior_next_na;
_29.appendChild(_2e);
}
var _31=document.createElement("span");
_31.innerHTML="<span id=\"drag_calendar\" title=\""+this.cal_lang.calendar_position+"\">"+_2a+"</span>";
_29.appendChild(_31);
if(_22=="yes"){
var _32=this.mon_name[_15];
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.create_cal_window(_19,_15);
};
var _2d=document.createElement("a");
_2d.href="javascript:void(0)";
_2d.title=_32+" ->";
_2d.innerHTML=this.cal_cfg.next_month_text;
dojo.connect(_2d,"onclick",null,_2b);
_29.appendChild(_2d);
}else{
var _2e=document.createElement("span");
_2e.innerHTML=this.cal_cfg.prior_next_na;
_29.appendChild(_2e);
}
if(_24=="yes"){
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.create_cal_window(_17,m);
};
var _2d=document.createElement("a");
_2d.href="javascript:void(0)";
_2d.title=_17+" ->";
_2d.innerHTML=this.cal_cfg.next_month_text;
dojo.connect(_2d,"onclick",null,_2b);
_29.appendChild(_2d);
}else{
var _2e=document.createElement("span");
_2e.innerHTML=this.cal_cfg.prior_next_na;
_29.appendChild(_2e);
}
}else{
_29.innerHTML=_2a;
}
_28.appendChild(_29);
_27.appendChild(_28);
_26.appendChild(_27);
var _35=document.createElement("table");
_35.className="cal_table";
var _36=document.createElement("tbody");
var _37=document.createElement("tr");
for(var i=0;i<7;i++,_12++){
if(_12==7){
_12=0;
}
var _39=document.createElement("th");
_39.title=this.long_day[_12];
switch(this.cal_cfg.day_title_format){
case "shrt_day":
_39.innerHTML=this.shrt_day[_12];
break;
case "abbr":
default:
_39.innerHTML=this.abbr_day[_12];
break;
}
_37.appendChild(_39);
}
_36.appendChild(_37);
var _3a=0;
var row=0;
var _3c=[];
_3c[row]=document.createElement("tr");
_13=_13-this.first_dow;
if(_13<0){
_13=7+_13;
}
for(var i=0;i<_13;i++,_3a++){
var _3d=new Date(_18,_14,1);
var _1b=dojo.date.getDaysInMonth(_3d);
var _3e=this.calendar_td(_18,_14,(_1b-_13+i+1),"prior");
_3c[row].appendChild(_3e);
}
var _3f=new Date(y,m,1);
var _40=dojo.date.getDaysInMonth(_3f);
for(var i=1;i<=_40;i++,_3a++){
var _41=this.calendar_td(y,m,i,"curr");
_3c[row].appendChild(_41);
if(_3a==6){
if(i<_40){
row++;
_3a=-1;
_3c[row]=document.createElement("tr");
}
}
}
var j=0;
if(_3a>0){
for(var j=1;_3a<7;j++,_3a++){
var _43=this.calendar_td(_19,_15,j,"next");
_3c[row].appendChild(_43);
}
}
if(this.cal_cfg.use_six_rows){
for(y=row;y<5;y++){
_3c[++row]=document.createElement("tr");
for(var x=0;x<7;x++,j++){
var _45=this.calendar_td(_19,_15,j,"next");
_3c[row].appendChild(_45);
}
}
}
for(var k=0;k<_3c.length;k++){
_36.appendChild(_3c[k]);
}
_35.appendChild(_36);
var _47=document.createElement("div");
_47.id="cal_footer";
if(this.cal_cfg.use_today_date_link){
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.enter_date(_11.curr_year,_11.curr_mon,_11.curr_date,_11.cal_cfg.close_cal_on_date_pick);
};
var _49=document.createElement("a");
_49.innerHTML=this.cal_lang.today_link_text;
_49.href="javascript:void(0)";
_49.title=this.cal_lang.today_link_title;
dojo.connect(_49,"onclick",null,_2b);
_47.appendChild(_49);
}
if(this.cal_cfg.use_no_date_link){
var _2b=function(evt){
evt.preventDefault();
evt.stopPropagation();
_11.enter_blank();
};
if(this.cal_cfg.use_today_date_link){
var _4b=document.createTextNode("  ");
_47.appendChild(_4b);
}
var _4c=document.createElement("a");
_4c.innerHTML=this.cal_lang.no_date_link_text;
_4c.href="javascript:void(0)";
_4c.title=this.cal_lang.no_date_link_title;
dojo.connect(_4c,"onclick",null,_2b);
_47.appendChild(_4c);
}
this.cal_window.appendChild(_26);
this.cal_window.appendChild(_35);
this.cal_window.appendChild(_47);
this.display_cal_window();
};
msos.calendar.generate_tool.prototype.calendar_td=function(y,m,d,_50){
var _51=this;
var _52=new Date(y,m,d);
var _53=_52.getDay();
var _54="";
var _55=[];
var _56="";
var _57=(_53!=0&&_53!=6);
var _58=dojo.date.locale._getDayOfYear(_52);
var _59=dojo.date.locale._getWeekOfYear(_52,this.first_dow);
var _5a=", "+this.cal_lang.day_of_year_text+" - "+_58;
var _5b=this.cal_lang.week_of_year_text+" - "+_59;
var _5c=(this.cal_year==y&&this.cal_month==m&&this.cal_date==d);
var _5d=(this.curr_year==y&&this.curr_mon==m&&this.curr_date==d);
var _5e=this.generate_date(y,m,d);
_5e+=" - "+this.cal_lang.day_not_allowed_text;
if((_50=="prior")||(_50=="next")){
_55.push("cal_prior");
}
if(_5c&&_5d){
_55.push("cal_both");
}else{
if(_5c){
_55.push("cal_entered");
}else{
if(_5d){
_55.push("cal_current");
}else{
if(_57){
_55.push("cal_weekday");
}else{
_55.push("cal_weekend");
}
}
}
}
var _5f="yes";
var _54=document.createElement("td");
var _60=function(evt){
evt.preventDefault();
evt.stopPropagation();
if(_5f=="yes"){
_51.enter_date(y,m,d,_51.cal_cfg.close_cal_on_date_pick);
}else{
alert(_5e);
}
};
dojo.connect(_54,"onclick",null,_60);
if(_50=="curr"||(_50=="prior"&&this.cal_cfg.display_prior_mon_days)||(_50=="next"&&this.cal_cfg.display_next_mon_days)){
if(_57&&!this.cal_cfg.pick_weekdays){
_5f="no";
}
if(!_57&&!this.cal_cfg.pick_weekends){
_5f="no";
}
if(_50=="prior"&&!this.cal_cfg.pick_prior_mon_days){
_5f="no";
}
if(_50=="next"&&!this.cal_cfg.pick_next_mon_days){
_5f="no";
}
if(this.cal_cfg.cal_top_date&&this.cal_cfg.cal_top_date<_52){
_5f="no";
}
if(this.cal_cfg.cal_bot_date&&this.cal_cfg.cal_bot_date>_52){
_5f="no";
}
if(_5f=="yes"){
_55.push("cal_available");
}else{
_55.push("cal_not_avail");
}
_56=_55.join(" ");
_54.className=_56;
if(_5f=="yes"){
_54.title=_5b+_5a;
_54.innerHTML=d;
}else{
_54.title=_5e;
_54.innerHTML=d;
}
}else{
_55.push("cal_not_avail");
_56=_55.join(" ");
_54.className=_56;
if(_5d){
_54.title=this.cal_lang.current_date;
_54.innerHTML=d;
}else{
if(_5c){
_54.title=this.cal_lang.entered_date;
_54.innerHTML=d;
}else{
_54.title=_50;
_54.innerHTML=" ";
}
}
}
return _54;
};
msos.calendar.generate_tool.prototype.enter_blank=function(){
if(this.cal_inp_elm.value!=this.cal_cfg.blank_date_text){
this.cal_inp_elm.value=this.cal_cfg.blank_date_text;
}
this.hide_cal_window();
};
msos.calendar.generate_tool.prototype.enter_date=function(y,m,d,_65){
this.cal_year=y;
this.cal_month=m;
this.cal_date=d;
var _66=this.cal_inp_elm.value;
var _67=this.generate_date(y,m,d);
if(_66!=_67){
console.debug("Enter date: "+_67);
this.cal_inp_elm.value=_67;
if(this.cal_cfg.exec_on_complete&&_65){
this.on_complete_func();
}
}
if(_65){
this.hide_cal_window();
}
};
msos.calendar.generate_tool.prototype.suppress_ie_objects=function(){
msos.common.set_suppress_ie_objects(this.cal_window,this.cal_cfg.ie_element_suppression,this.suppressed_elements);
for(i=0;i<this.suppressed_elements.length;i++){
this.suppressed_elements[i].style.visibility="hidden";
}
};
msos.calendar.generate_tool.prototype.restore_ie_objects=function(){
for(i=0;i<this.suppressed_elements.length;i++){
this.suppressed_elements[i].style.visibility="";
}
this.suppressed_elements=[];
};
msos.calendar.generate_tool.prototype.get_input_date=function(_68){
if(!_68||_68==this.cal_cfg.blank_date_text){
if(this.cal_month==null||this.cal_year==null){
(this.cal_cfg.initial_date)?this.cal_month=this.cal_cfg.initial_date.getMonth():this.cal_month=this.curr_mon;
(this.cal_cfg.initial_date)?this.cal_year=this.cal_cfg.initial_date.getFullYear():this.cal_year=this.curr_year;
}
return true;
}
_68=dojo.trim(_68);
_68=_68.replace(/\s\s+/g," ");
console.debug("get_input_date -> input value: "+_68);
var _69=dojo.date.locale.parse(_68,this.cal_cfg.std_in_out_date_format)||null;
if(!_69){
var _6a=this.cal_cfg.alt_input_date_formats;
for(var k=0;k<_6a.length;k++){
_69=dojo.date.locale.parse(_68,_6a[k])||null;
if(_69){
console.debug("get_input_date -> dojo format: "+_6a[k].formatLength);
break;
}
}
if(!_69&&this.cal_cfg.lang_specific_date_formats[djConfig.locale]){
var _6c=this.cal_cfg.lang_specific_date_formats[djConfig.locale];
for(var l=0;l<_6c.length;l++){
_69=dojo.date.locale.parse(_68,_6c[l])||null;
if(_69){
console.debug("get_input_date -> alt lang format: "+_6c[l].datePattern);
break;
}
}
}
}
if(!_69){
alert(this.cal_lang.input_format_msg+" "+this.example_date());
return false;
}
var _6e=_69.getFullYear();
var _6f=_69.getMonth();
var _70=_69.getDate();
if(!isNaN(_70)&&!isNaN(_6f)&&!isNaN(_6e)){
var _71=new Date(_6e,_6f,_70);
if(this.cal_cfg.cal_top_date&&this.cal_cfg.cal_top_date<_71){
var _72=dojo.date.locale.format(this.cal_cfg.cal_top_date,this.cal_cfg.std_in_out_date_format);
alert(this.cal_lang.date_allowable_text+" "+this.cal_lang.top_allowable_text+" "+_72);
_70=this.cal_cfg.cal_top_date.getDate();
_6f=this.cal_cfg.cal_top_date.getMonth();
_6e=this.cal_cfg.cal_top_date.getFullYear();
this.enter_date(_6e,_6f,_70);
return false;
}
if(this.cal_cfg.cal_bot_date&&this.cal_cfg.cal_bot_date>_71){
var _72=dojo.date.locale.format(this.cal_cfg.cal_bot_date,this.cal_cfg.std_in_out_date_format);
alert(this.cal_lang.date_allowable_text+" "+this.cal_lang.bot_allowable_text+" "+_72);
_70=this.cal_cfg.cal_bot_date.getDate();
_6f=this.cal_cfg.cal_bot_date.getMonth();
_6e=this.cal_cfg.cal_bot_date.getFullYear();
this.enter_date(_6e,_6f,_70);
return false;
}
this.enter_date(_6e,_6f,_70);
return true;
}else{
return false;
}
};

